small optimizations
You use Keyboard.GetState() all over again - for each key actually. Same for Mouse.GetState().
That’s not great, since it doesn’t get cached in the background.
So you should save it to _currentState at the beginning of your update loop and use that value then.
If you want to see for yourself
this will make your program come to a complete halt
for (int i = 0; i<10000;i++)
keyboardState = Keyboard.GetState();
this will not change a thing
KeyboardState keyboardState2 = Keyboard.GetState();
for (int i = 0; i < 10000; i++)
keyboardState = keyboardState2;
If you have a million objects that need to be transformed each frame there is another thing you want to optimize is this:
public Matrix GetWorldViewProjection(WorldSpaceObject worldObject)
{
return worldObject.world * viewSpace * projection;
}
the viewSpace * projection matrix multiplication is always the same, just calculate that when calculating view and use
return worldObject.world * viewSpaceProjection;
instead