[SDL] Game event loop and input

Dave Slutzkin daveslutzkin at fastmail.fm
Thu Jan 30 21:25:01 PST 2003

Slightly OT...

On Thu, 30 Jan 2003 16:42:46 -0800, "Joby Bednar"
<thebigcheese at jobybednar.com> said:
> I'm starting to map out the various stages of my game, intro, tutorial,
> game play, cut scenes, etc.  and it is getting a little ugly when it
> comes to what I envision as user input and the basic event loop.  I'm
> thinking I need to create a global that stores the current game state
> and use a series of case statements within the PollEvent loop.  This
> seems a bit bulky though and could run pages long.
> Has anyone had experience in developing a custom class that you can use
> to wrap around the event to simplify the event structure with respect
> to your game states?  Or perhaps other ways that you have found
> especially effective in keeping code clean and simple?

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.

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.

Hope that helps,

  David Slutzkin, BCS (Hons)
  Melbourne, Australia
  daveslutzkin at fastmail.fm

http://fastmail.fm - Choose from over 50 domains or use your own

More information about the SDL mailing list