glen3b/GLib

Glib.Xna.SpriteLib.Sprite checks MouseState for every sprite

Closed this issue · 3 comments

The call to Mouse.GetState() transitions to unmanaged code, and is surprisingly expensive. Furthermore, it is unnecessary for most sprites in most games / projects, and on Xbox360 deployment.

Suggestion:Have the MouseState passed into the Sprite.Update(MouseState mouseState) method; if passed in value is null, do not perform mouse related functions. This will allow for a single call [per Update cycle] to Mouse.GetState(), which can be passed into sprites that need it.

Problems with this suggestion:Unfortunately, this is a base class; therefore, altering the Update() function will cause problems for projects relying on this class. Yet, this class is currently unsuitable as a generic sprite; given that Glib is relatively new, it may be worthwhile to make the modification now [and risk breaking some code] rather than leave this bug in.

There is an update in PGCGame project that demonstrates the issue:
GreatMindsRobotics/PGCGame@47f825c

Fixed for Xbox in 1ae239c and 9a383fc (Xbox has no mouse, simple fix).

Fixed in e6fcc67. I am now using the InputLib's Mouse.MouseManager static class for MouseStates. This causes the breaking change of having to update that class for mouse related information to be up to date. Please reopen the issue if this change did not fix the performance problems. (Don't forget to add an InputManagerComponent to your game).

Github API test, sorry about that