Skip to main content
GameDev.net gamedev.net
🔒 Locked

Input subsystem, active or passive?

Started by YengaMatiC Jan 4, 2005 at 8:56 AM 4 replies 950+ views
Original Post
YengaMatiC
YengaMatiC
I'm designing the input subsystem and i want to show you both approaches i thought. Active: event driven system that propagates mouse/keyboard events to system that wants some input. -Pros: you can set a priority queue of callbacks which receive the input, so systems that are gathering for input don't overlap others (a menu has more priority over the rest). -Cons: there are so much function calls, one for every event (key pressed, released or still-pressed). Passive: saving old and actual keyboard/mouse state and waiting for other modules to querying it. -Pros: the input system doesn't have to bother about who wants input, it only has to answer questions like 'is left arrow pressed?'. -Cons: you have to control the way other systems have priority over a system that wants input (menu-ingame example). Sure there will be more pros-cons to each system, but that's what i want you to discuss here :) EDIT: it's an input module for a game engine.
YengaMatiC for the people[Pandora's Box project]
antareus
antareus
You don't mention what you're actually making. In an application the additional function call overhead a push-model would incur would be negligable. In a game, it depends.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
YengaMatiC
YengaMatiC
Hmmm, well. Although it's for a game input subsystem, i've thought that there are not many function calls because there aren't that much key events each frame. We only have 10 fingers! :) So that fact wouldn't really be a con.
YengaMatiC for the people[Pandora's Box project]
nimrand
nimrand
I would use your active approach. Almost all the game programming books I've seen that touch on the issue uses similar strategies. I seriously doubt that it will add much overhead, even for a game. Even on an input-intensive game, you will almost never have more than 8 events in a given frame, and most of the time it will be less. Also, given the extra programming that would be required for each input listener to figure out if it has priority, I doubt that the passive model will be all that more efficient, and the implementation would probably be more messy.
dave
dave
I did it the second way, for an active game and it worked fine, i simpley had all input publicly available to the class that wanted it.

ace
jamessharpe
jamessharpe
I would say that you should primarily use the Active system. The number of function calls is really minimal. The way to do this is to have a binding system for each key: have the system register a callback to be called when a particular key is pressed. Then when you receive an input event from the OS, you check if it has a binding - if it has call the callback. Likewise you only generate key released events when the key has a binding - its pointless to tell your engine about release events on keys that do nothing! You don't need to have a still-pressed event - just ignore key repeats from the OS - you can generate your own key repeat system if you want key repeats for text input etc.. - the engine should hold a latched state as to whether the key is down or not. The only problem you will get then is if the app loses focus - you may not receive a corresponding key release event - so if your app loses focus just send a key release event for all keys that are down.

James

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.