[SDL] Game event loop and input
Scott Harper
orcein at gmail.com
Sat Feb 9 10:33:34 PST 2008
> The first or second article in `Game Programming Gems 3' is about a
> similar topic to this. He talks about a thing which he calls a Game
> Framework. It has a website - www.gameframework.com - which is
> updated
> reasonably regularly.
This website doesn't show up for me as anything other than a
placeholder website owned by a company wanting to sell it.
> The basic concept is that you have `layers' which can each have
> control.
> The layers are, well, `layered' on top of one another. The top one
> gets
> the first shot at the input, and if it doesn't handle it, the next one
> gets a go, and so on. (There can be exclusive layers which don't give
> anyone else a go at the input.) So the input cascades down the
> chain of
> layers. A menu can be an exclusive layer which tacks onto the front
> of
> the stack. You can have different layers for different parts of the
> interface. It's quite flexible, and works pretty well with SDL.
You probably can do something like this pretty easily without having
to resort to objects, but I've created a GameState class which I
create subclasses of for each game state (menus, intro videos, loading
screens, gameplay, etc...), and I maintain a stack structure of game
states, pushing and popping when necessary for new game states. So in
my render and process threads I just peek at the stack and run that
object's process/render methods each time through the loop, and if at
some point the GameState object at the top of the stack doesn't return
'true' to say 'rendered/processed normally', then I presume it's done
with whatever it wanted or was doing, and I pop the stack and start
working on the next lowest.
So what I came up with is kind of similar, I guess. ^_^ I'm not sure
why or if the layers idea would be better, but either could be easily
done in SDL (on-topic!) and work rather nicely, I think.
-- Scott
More information about the SDL
mailing list