Technical Discussion February 25 2008

Topic 1: How do you structure your code, manage entities, and manage states?

Ryan Bujnowicz:

Game states

  • Manged using a stack
  • Has three important functions
    • init - called every time entering the state
    • run - performs one time step of the state; returns previous next or nothing
    • sleep - clears unneeded memory

A kernel object is passed into states which contains the display, sound and other systems that are global to the game.


  • List of entities gets processed each frame
  • Every entity has an update function responsible for updating themselves.
  • Entities draw themselves using the kernel.

Event manager

  • has "events"
  • Each event has run and kill functions
  • Subclasses:
    • move entity
    • chain event - a queue of actions; back-end to scripting system.

Entity classes

  • traditional method leads to having multiple inheritance so instead a component based system is used where an entity is an aggregate of the parts.
  • A factory is used to build entities from components.

Eric Raue

Game loop

  • captures input once per frame
  • updates entities

A state manager switches between game states. Often if a game has only a few states, it is done by a switch statement.

Each game state has

  • init - initialize resources required for the state.
  • run - performs action for state and returns the next state (itself or otherwise)
  • destroy - clean up resources

Entities are managed in the game logic classes that make sense. e.g. falling Tetris piece in game class.


Using meta programming one could write states in a more conceptual way and generate c code at compile time.

Members Present

  • Colin Hume
  • Dave Bregman
  • Eric Raue
  • Ryan Bujnowicz
  • Ted Tate
Add a New Comment
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License