Home Elaboration ISystem and System Classes
ISystem and System Simulator Classes Print
Written by Samuel E. Henley   
Tuesday, 01 July 2008 12:44

The System Class is the interface class for the railroad simulation game and essentially is the game program itself. The class is implemented in the …/src/simulator/system.cpp file. This class is created in main.cpp and includes the entire railroad simulator game. The System class maintains the game state and dispatches the main game loop to the current foreground state. The System class also executes the background state for each state in the system state vector for every pass of the game loop.

Each interface class of the game is a sub-class of ISimulatorComponent abstract class and includes three interfaces startup(), operator() and shutdown(). The System class calls the various interfaces of the ISimulatorComponent sub-classes as it moves from state to state. The last (back) state in the state vector is the current state and its operator() is called. Only the last (back) state can modify the system state vector.

The member System::operator() dispatches the game loop thread to a background or foreground system states. The simulator is shutdown when the system state vector is empty. System: operator() also calls the Ogre messagePump() for the Windows and Linux message processing. The messagePump call is made through the IGraphics interface.

The System state machine is defined in system.cpp as a template. The current game states are: State<STARTUP>, State<GUI>, State<ROUTESTARTUP>, State<ROUTESHUTDOWN>, State<SIMULATION> and State<SHUTDOWN>. Each system state has four members, startup, shutdown, background and operator() (foreground state). The foreground operator() is responsible for moving the train/railroad simulator state machine from state to state by pushing or popping a state from the end of the system state vector.

At this time the ISystem interface supplies platform dependent utilities (so far only getFrameMilliseconds from the IGraphics interface) to the ISimulatorComponent sub-classes making up the railroad simulation. ISystem can supply a pointer to any ISimulatorComponent class used in the game engine for the use of any other interface. ISystem holds a class singleton of each interface and is responsible for creating and destroying each of these interfaces. Every ISimulatorComponent sub-class is initialized with a pointer to the ISystem interface class.

Last Updated on Wednesday, 03 June 2009 08:12