TriEngine  v0.0.16
General-purpose engine in C#/OpenGL
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
TriDevs.TriEngine.StateManagement.GameStateManager Class Reference

Game state manager that keeps track of the active game states and provides methods to control the states. More...

Inheritance diagram for TriDevs.TriEngine.StateManagement.GameStateManager:
[legend]
Collaboration diagram for TriDevs.TriEngine.StateManagement.GameStateManager:
[legend]

Public Member Functions

 GameStateManager ()
 Creates a new GameStateManager with an empty state stack. More...
 
 GameStateManager (IGameState state)
 Creates a new GameStateManager and pushes an initial state onto the stack. More...
 
void Update ()
 Updates the object. More...
 
void Draw ()
 Draw the object to screen. More...
 
IGameState Push (IGameState state)
 Pushes a new game state onto the stack, pausing the current one. More...
 
IGameState Pop ()
 Pops the currently active state from the stack, unpausing the previous one. More...
 
IGameState Peek ()
 Returns the game state at the top of the stack, without popping it. More...
 
IGameState Switch (IGameState state)
 Switches to a new game state, discarding all previous ones in the stack. More...
 

Properties

int StateCount [get]
 
IGameState ActiveState [get, set]
 
- Properties inherited from TriDevs.TriEngine.StateManagement.IGameStateManager
int StateCount [get]
 Gets the number of game states currently in the stack. More...
 
IGameState ActiveState [get]
 Gets the currently active game state. More...
 

Detailed Description

Game state manager that keeps track of the active game states and provides methods to control the states.

Constructor & Destructor Documentation

TriDevs.TriEngine.StateManagement.GameStateManager.GameStateManager ( )

Creates a new GameStateManager with an empty state stack.

52  {
53  _states = new Stack<IGameState>();
54  }
TriDevs.TriEngine.StateManagement.GameStateManager.GameStateManager ( IGameState  state)

Creates a new GameStateManager and pushes an initial state onto the stack.

Parameters
stateThe state to initialize with.
61  : this()
62  {
63  Push(state);
64  }

Member Function Documentation

void TriDevs.TriEngine.StateManagement.GameStateManager.Draw ( )

Draw the object to screen.

Implements TriDevs.TriEngine.Interfaces.IDrawable.

73  {
74  if (ActiveState != null)
75  ActiveState.Draw();
76  }
IGameState TriDevs.TriEngine.StateManagement.GameStateManager.Peek ( )

Returns the game state at the top of the stack, without popping it.

Returns
The state at the top of the stack.

Implements TriDevs.TriEngine.StateManagement.IGameStateManager.

102  {
103  return _states.Peek();
104  }
IGameState TriDevs.TriEngine.StateManagement.GameStateManager.Pop ( )

Pops the currently active state from the stack, unpausing the previous one.

Returns
The state that was popped.

Implements TriDevs.TriEngine.StateManagement.IGameStateManager.

90  {
91  if (_states.Count == 1)
92  throw new InvalidOperationException("Cannot pop the last remaining game state from stack.");
93 
94  var state = _states.Pop();
95  state.Unload();
96  ActiveState = _states.Peek();
98  return state;
99  }
IGameState TriDevs.TriEngine.StateManagement.GameStateManager.Push ( IGameState  state)

Pushes a new game state onto the stack, pausing the current one.

Parameters
stateThe new game state to push onto the stack.
Returns
The game state that was pushed.

Implements TriDevs.TriEngine.StateManagement.IGameStateManager.

79  {
80  if (ActiveState != null)
82 
83  state.Load();
84  _states.Push(state);
85  ActiveState = state;
86  return state;
87  }

Here is the call graph for this function:

IGameState TriDevs.TriEngine.StateManagement.GameStateManager.Switch ( IGameState  state)

Switches to a new game state, discarding all previous ones in the stack.

Parameters
stateThe new state to switch to.
Returns
The state that was switched to.

Implements TriDevs.TriEngine.StateManagement.IGameStateManager.

107  {
108  while (_states.Count > 0)
109  _states.Pop().Unload();
110 
111  _states = new Stack<IGameState>();
112  return Push(state);
113  }

Here is the call graph for this function:

void TriDevs.TriEngine.StateManagement.GameStateManager.Update ( )

Updates the object.

Implements TriDevs.TriEngine.Interfaces.IUpdatable.

67  {
68  if (ActiveState != null)
70  }

Property Documentation

IGameState TriDevs.TriEngine.StateManagement.GameStateManager.ActiveState
getset
int TriDevs.TriEngine.StateManagement.GameStateManager.StateCount
get

The documentation for this class was generated from the following file: