Sign in to follow this  
algorhythmic

decoupled input

Recommended Posts

Hi, I am currently working on an input system amongst other things am in the process of investigating various ways of modeling input in a flexible, extensible and decoupled way. I have performed a search in the GameDev forums and many threads mention the Observer pattern. I am vaguely familiar with this concept but I'm having trouble seeing in what way it can be applied to input. One poster talked about creating interface classes for each input device (IKeyboardSubscriber, etc..) which the interested objects would inherit from. I can see the benefits of such a system but I am still unclear on the manner in which the input would be 'harvested' from the underlying OS in such a system. What would the 'publisher' look like? Any help with this matter would be greatly appreciated. Many Thanks algorhythmic [Edited by - algorhythmic on August 16, 2004 3:23:08 PM]

Share this post


Link to post
Share on other sites
So effectively I wrap the Win32API or DirectInput and upon each loop I publish all the keyboard/mouse events to the input subscribers?

[Edited by - algorhythmic on August 17, 2004 2:55:49 PM]

Share this post


Link to post
Share on other sites
I used DirectInput and I have an InputSystem that creates an InputState object every tick. The InputState object, ideally would store a list of buffers for different devices. Currently I have InputDevice inherited by Keyboard and Mouse. I've hardcoded the InputState to store Keyboard and Mouse buffers, but will change this in due time.

This InputState object is then sent to all InputListeners.

Share this post


Link to post
Share on other sites
It goes beyond simply wrapping up an input API. You want your objects to receive notification of some action that is mapped to a certain key somewhere else. This makes things such as the user changing key assignments and AI a lot easier. For example, an AI control class telling an entity to move forward would look the same to that entity as a player pressing a key to move it forward, even if the player uses a different key to move forward.

Share this post


Link to post
Share on other sites

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

Sign in to follow this