HeadBall  1.0
A game
StateMachine.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <stack>
5 
6 #include "State.hpp"
7 
8 namespace HeadBall {
15  typedef std::unique_ptr <State> StateRef;
16 
23  class StateMachine {
24  public:
29  StateMachine ( ) { }
30 
35  ~StateMachine ( ) { }
36 
43  void addState (StateRef newState, bool isReplacing = true);
44 
49  void removeState ( );
50 
55  void processStateChanges ( );
56 
63 
64  private:
65  std::stack <StateRef> _states;
67 
68  bool _isReplacing;
69  bool _isAdding;
70  bool _isRemoving;
71  };
72 }
The class that manages the states in the project.
Definition: StateMachine.hpp:23
bool _isReplacing
Whether the state at the top of stack is being popped or another state is being pushed at the top of ...
Definition: StateMachine.hpp:68
StateMachine()
Construct a new State Machine object.
Definition: StateMachine.hpp:29
StateRef & getActiveState()
Get the Active State object i.e the state at the top of the stack.
Definition: StateMachine.cpp:40
std::stack< StateRef > _states
The stack where the states in the game are kept.
Definition: StateMachine.hpp:65
bool _isRemoving
Whether the state at the top of stack is being popped.
Definition: StateMachine.hpp:70
void processStateChanges()
Process the changes in the state.
Definition: StateMachine.cpp:15
void addState(StateRef newState, bool isReplacing=true)
Add a new state to the state machine.
Definition: StateMachine.cpp:4
~StateMachine()
Destroy the State Machine object.
Definition: StateMachine.hpp:35
bool _isAdding
Whether a new state is being added.
Definition: StateMachine.hpp:69
void removeState()
Remove the state at the top of the stack.
Definition: StateMachine.cpp:11
StateRef _newState
The Unique Pointer to new state that is beong added.
Definition: StateMachine.hpp:66
Custom namespace used throughout the project.
Definition: AboutState.cpp:6
std::unique_ptr< State > StateRef
The Unique Pointer for storing the States.
Definition: StateMachine.hpp:15