Operating States

Collaboration diagram for Operating States:

Implements a system to switch between the major operating states of the program. More...


Files

file  states.c
 Implements a system to use and switch between the different major game operating states.
file  states.h
 Defines the different major game operating states.

Modules

 Battlefield Error State
 Implements the Battlefield Error state.
 Gameplay State
 Runs the backbone of the gameplay code.
 Menu States
 Implements the Root Menu and Network Options Menu.
 Splash State
 Implements the Splash Screen.

Data Structures

struct  State_t
 A set of function pointers to functions that implement an operating state. More...

Typedefs

typedef int(*) StateFunc ()
 The function prototype for all implementations of the different operating states.

Enumerations

enum  STATE_CODES {
  STATE_ERROR = -2, STATE_QUIT, STATE_SPLASH, STATE_MENUROOT,
  STATE_MENUNAME, STATE_MENUNET, STATE_MENUCONN, STATE_SHOWOPTS,
  STATE_PLAY, STATE_BFLDERR, STATE_DISCONN, STATE_MAX,
  STATE_OK
}
 Enumerates the different operating states of the game. More...

Functions

int GetCurrentState ()
 Returns the program's current operating state as defined in the STATE_CODES enum.
Bool RunState ()
 Runs the state system.
static int Stub ()
 A stub implementation for unimplemented states.

Variables

static int currState = STATE_SPLASH
 Stores the current operating state.
static Bool initalized = 0
 Tracks if the current state has been initalized.
static struct State_t stateImpls [STATE_MAX]
 The list of functions used for the operation state implementations.

Detailed Description

Implements a system to switch between the major operating states of the program.

Each state includes an initialization, uninitialization, and run function. This provides for an intuitive operation, however an implementation with only one function per state would allow a slimmer state machine. In that case, the init and uninit functions would be whole states that normally finish in a single call. I think I'll do it that way next time.


Typedef Documentation

typedef int(*) StateFunc()

The function prototype for all implementations of the different operating states.

Returns:
Varies. See State_t.

Definition at line 116 of file states.h.


Enumeration Type Documentation

enum STATE_CODES

Enumerates the different operating states of the game.

Each has its own input-output loop.

Enumerator:
STATE_ERROR  A state signifying a non-recoverable error has occured.
STATE_QUIT  The state that signifies normal program termination.
STATE_SPLASH  The inital state of the game; a splash screen identifying the game while media loads and a connection to a server is attempted.

The next state is STATE_MENUROOT.

STATE_MENUROOT  A menu allowing the user to chose a team or quit, and informing the user of the network connection status.
STATE_MENUNAME  An item of the root menu for player name entry.

Uses a custom event loop.

STATE_MENUNET  A menu for configuring networking options and, when running as the server, game options.
STATE_MENUCONN  An item of the networking menu for entering the hostname of a server.

Uses a custom event loop.

STATE_SHOWOPTS  Displays game options prior to the start of the game, and loads media needed only for game play.
STATE_PLAY  Game play.

The user may chose to quit the program, or the game in progress. If the user quits the current game, the next state will be STATE_MENU. If the connection to the server is lost, the next state will be STATE_DISCONN.

STATE_BFLDERR  An error occured while loading the battlefield file; this state shows the error to the user.
STATE_DISCONN  A notice that the server is no longer accessible.

The next state is STATE_MENUROOT.

STATE_MAX  The number of defined states.
STATE_OK  A code indicating that initialization was successful.

Definition at line 45 of file states.h.


Function Documentation

int GetCurrentState (  ) 

Returns the program's current operating state as defined in the STATE_CODES enum.

Returns:
The state.
Author:
Jeff Jackowski

Definition at line 80 of file states.c.

References currState.

Bool RunState (  ) 

Runs the state system.

The order of events are:

  1. Check for an uninitalized state (program start condition)
    1. Initialize the state (error possibility)
  2. Run the state
  3. Check for a state change, request to terminate, or error
    1. Uninitalize the state (error possibility)
    2. Set the next state
  4. Check for a request to terminate, or an error, from running the state
    1. Return FALSE
  5. Return TRUE

Returns:
True if the program should continue calling RunSate(). False if the program should terminate.
Author:
Jeff Jackowski

Definition at line 84 of file states.c.

References currState, FALSE, State_t::init, initalized, State_t::run, STATE_MAX, STATE_OK, STATE_QUIT, stateImpls, TRUE, and State_t::uninit.

Referenced by main().

static int Stub (  )  [static]

A stub implementation for unimplemented states.

Moves the system to the next state. If there is no next state, quit.

For internal use only.

Author:
Jeff Jackowski

Definition at line 56 of file states.c.

References currState, state, STATE_MAX, and STATE_QUIT.


Variable Documentation

int currState = STATE_SPLASH [static]

Stores the current operating state.

For internal use only.

Definition at line 40 of file states.c.

Referenced by GetCurrentState(), RunState(), and Stub().

Bool initalized = 0 [static]

Tracks if the current state has been initalized.

For internal use only.

Definition at line 47 of file states.c.

Referenced by RunState().

struct State_t stateImpls[STATE_MAX] [static]

Initial value:

 {
    { SplashInit, SplashRun, SplashUninit },        
    { MenuRootInit, MenuRun, MenuRootUninit },      
    { NULL, Stub, NULL },                           
    { NULL, Stub, NULL },                           
    { NULL, Stub, NULL },                           
    { NULL, Stub, NULL },                           
    { GameInit, GameRun, GameUninit },              
    { BfldErrInit, BfldErrRun, BfldErrUninit },     
    { NULL, Stub, NULL }                            
}
The list of functions used for the operation state implementations.

For internal use only.

Definition at line 68 of file states.c.

Referenced by RunState().


Generated on Mon May 28 04:41:43 2007 for Retro Tank Super Attack by  doxygen 1.5.2