Input Management

Started by
1 comment, last by ov3r_dr1v3 15 years, 6 months ago
Hello, I've written a few classes (C++ win32 opengl) that provides a basic framework for some small games I'm working on. Now I need to develop an input manager (dealing with mouse and keyboard). I have a basic windows wrapper class which stores a std::map connecting win32 messages received and a function pointer stating how to deal with that message. Therefore I can register a message handler any time at any time through a basic windows object telling the program how to deal with a certain message. What Id like to do is have all keyboard and mouse messages (WM_KEYDOWN, WM_KEYUP, WM_MOUSEMOVE e.t.c) handled by an input manager class, which can then be queried by any other class (for example if i wanted to move an object forward when pressing the up key) I could query to input manager to see if the up key is being pressed. I'm not really too sure if this a good or efficient way to go about this...I'd interested to hear alternate views, but what I'm looking for is ideas how to implement this since im not too sure at the moment. I'd appreciate any replies thanks
Advertisement
Polling for input is usually suboptimal, because it allows you to miss quick events if you're bottlenecked enough. It's fine to have the ability to query for key state and the like, but in general I have found interrupt/event/callback methods more scalable for input handling.

So have your input manager accept callbacks that are invoked on the appropriate input events.
I'm a little confused as how to tie this in with Win32 messages.

I've been reading a few articles on a common framework used for input managers...Is the basic idea to have a base class 'EVENT', where more specific classes like 'Keyboard event' and 'mouse event' can be derived. A keyboard event object would contain information on whether the key was pressed or released and then the specific key in question...and the mouse event would contain information as to whether the left or right bottom was being pressed released and also the x,y position of the mouse.

From here I get a little stuck when thinking about how to manager the events and to notify the appropriate components of my program. For example, I have a Game State Manager, which will render and update the current game state (the one on top of the game state stack). In each game state I'm thinking I need to have a method 'OnEvent' which will receive an Event from some event manager (could me mouse, keyboard or whatever) and then decide what to do.

I think I'm on the right lines, but not too sure, and and a bit confused as to teh best way to implement something like this.

This topic is closed to new replies.

Advertisement