Jump to content
  • Advertisement
  • entries
  • comments
  • views

DevLog #12 - Engine engineering 2

Sign in to follow this  


The keyboard listener is complete, now with fixed and improved mask for special keys ( Ctrl, Alt, Shift ) to be a bit more flexible. The left Alt was a bit tricky to make it work using window messages. I was slowly going to think about abandoning the idea of callbacks as reaction on messages if it wouldn't be possible to catch messages for left Alt combinations. In the end the Alt + key combination revealed that although it does not send WM_KEYDOWN message as any other combination does, it sends a WM_SYSKEYDOWN message instead. With that the keyboard handling system is completely prepared.

Here you can see the structure.

WndProc sends messages to HandleEvent method of Window wrapper.
HandleEvent directly solves messages like window activation/inactivation, dumps screensaver message, process key press/release messages, etc.
I was thinking at first about allowing game to handle all the messages on its own, but in the end these messages seems to be unlikely handled in different way game from game. Only some messages invoke a call of methods in WindowEventHandler class.

When a Window::HandleEvent() receives a certain message, it calls appropriate method of this class.
The game can inherit from this class ( e.g. GameWindowEventHandler ) and override the methods if it wants to handle some messages by itself.

KeyboardListener & KeyHandler
Game can register a callback function for each key ( + combinations of special keys ).
When KEYDOWN message is received, a KeyPressed function is called. This checks if some callback for the key is registered and calls it.

Ship & Character Controller
Static callback method is called from KeyHandler when key is pressed. The callback takes an instance of controlled object (e.g. ship, character, etc. ) and calls its member method to perform the game operation.
For example if we fly a ship, the game registers the methods from ShipController in keyboard listener and when a key is pressed, the appropriate function from ShipController is called directly. If we get off the ship, the game can unregister the old functions and register functions from CharacterController instead. If the same key is then pressed, a function from CharacterController is called now.
I think this can separate pretty nicely different operations that should be performed on different screens by same key. Operations for different screen or game mode will not mess among each other.

Well, so that's all for now. The mouse and possibly joystick handling will be made in a very similar way as keyboard is, but I will keep them for a later time. In the upcomming days I'd like to look on the Renderer and prepare some usable API for it.
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!