Input Handling and Game loop
- by Bob Coder
So, I intercept the WM_KEYDOWN and other messages.
Thing is, my game can't/shouldn't react to these messages just yet, since my game might be currently drawing to the screen or in the middle of updating my game entities.
So the idea is to keep a keyboardstate and mousestate, which is updated by the part of my code that intercepts the windows messages. These states just keep track of which keys/buttons are currently pressed.
Then, at the start of my game's update function, I access these keyboard and mouse states and my game reacts to the user input.
Now, which is the best way to access these states? I assume that windows messages can be sent whenever, so the keyboard/mouse states are constantly being edited. Accessing say a list of currently pressed keys in the keyboard state the same time another part of the code is editing the list would cause problems.
Should I make a deep copy of a state and act on that?
How would I deal with the garbage generated though, this would take place every frame.