[SDL] Game event loop and input

David Olofson david at olofson.net
Fri Jan 31 07:15:01 PST 2003


On Friday 31 January 2003 01.57, Stephen Anthony wrote:
[...]
> My solution was to use a handleGameEvents normally, but if in menu
> mode (indicated by some global variable), then to do a
> handleMenuEvents instead.

That's a basic state machine design. I think that's about the only way 
to keep this clean if you have more than one or two menues. As soon 
as you have intro mode, game mode, "get ready" mode and a few dialogs 
such as "end current game?", "quit game?", options etc, anything else 
will be a total mess. Sooner or later, you'll want to use some of the 
dialogs from within more than one game state, which is where you 
realize a state stack is rather handy...


> Something makes me think there should be a cleaner way though. 
> What if I want to add a different menu?  Create another function to
> handle *those* events??

Well, you can't really get around that... You *can* translate the 
events into something that fits your design better, though, if that 
helps.

In Kobo Deluxe, I have rudimentary internal "control events", that are 
IIRC, function call delivered and based on generic control "buttons" 
rather than actual keys, mouse buttons, joystick events etc. The idea 
is that everything goes through the input mapper *first*, so you can 
control the game, menues and all with whatever controller you decide 
to use. (So you can reach the menues at all, even if you don't have a 
keyboard in reach, or don't have one at all.)


> I guess what I'd like to know is how to simulate a multi-event
> paradigm in SDL, like one does in a GUI toolkit.

Same way, really - although dialogs in games are generally modal, 
which is something that GUI toolkits handle for you in the 
background. SDL doesn't even have the concept of "dialogs" and 
"windows", nor the concept of different "objects" as event receivers, 
so you have to this yourself.


//David Olofson - Programmer, Composer, Open Source Advocate

.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`---------------------------> http://olofson.net/audiality -'
   --- http://olofson.net --- http://www.reologica.se ---





More information about the SDL mailing list