HeadBall  1.0
A game
Public Member Functions | Private Attributes | List of all members
HeadBall::StateMachine Class Reference

The class that manages the states in the project. More...

#include <StateMachine.hpp>

Collaboration diagram for HeadBall::StateMachine:
Collaboration graph

Public Member Functions

 StateMachine ()
 Construct a new State Machine object. More...
 
 ~StateMachine ()
 Destroy the State Machine object. More...
 
void addState (StateRef newState, bool isReplacing=true)
 Add a new state to the state machine. More...
 
void removeState ()
 Remove the state at the top of the stack. More...
 
void processStateChanges ()
 Process the changes in the state. More...
 
StateRefgetActiveState ()
 Get the Active State object i.e the state at the top of the stack. More...
 

Private Attributes

std::stack< StateRef_states
 The stack where the states in the game are kept. More...
 
StateRef _newState
 The Unique Pointer to new state that is beong added. More...
 
bool _isReplacing
 Whether the state at the top of stack is being popped or another state is being pushed at the top of it. More...
 
bool _isAdding
 Whether a new state is being added. More...
 
bool _isRemoving
 Whether the state at the top of stack is being popped. More...
 

Detailed Description

The class that manages the states in the project.

This class manages all the states in the game in a stack. In every game loop, the state at the top of the stack is resumed.

Constructor & Destructor Documentation

◆ StateMachine()

HeadBall::StateMachine::StateMachine ( )
inline

Construct a new State Machine object.

◆ ~StateMachine()

HeadBall::StateMachine::~StateMachine ( )
inline

Destroy the State Machine object.

Member Function Documentation

◆ addState()

void HeadBall::StateMachine::addState ( StateRef  newState,
bool  isReplacing = true 
)

Add a new state to the state machine.

Parameters
newStateThe Unique Pointer to new state
isReplacingWhether the top state at the stack is being replaced or another state is being pushed at the top of it

◆ getActiveState()

StateRef & HeadBall::StateMachine::getActiveState ( )

Get the Active State object i.e the state at the top of the stack.

Returns
StateRef& The reference to the state at the top of the stack

◆ processStateChanges()

void HeadBall::StateMachine::processStateChanges ( )

Process the changes in the state.

◆ removeState()

void HeadBall::StateMachine::removeState ( )

Remove the state at the top of the stack.

Member Data Documentation

◆ _isAdding

bool HeadBall::StateMachine::_isAdding
private

Whether a new state is being added.

◆ _isRemoving

bool HeadBall::StateMachine::_isRemoving
private

Whether the state at the top of stack is being popped.

◆ _isReplacing

bool HeadBall::StateMachine::_isReplacing
private

Whether the state at the top of stack is being popped or another state is being pushed at the top of it.

◆ _newState

StateRef HeadBall::StateMachine::_newState
private

The Unique Pointer to new state that is beong added.

◆ _states

std::stack<StateRef> HeadBall::StateMachine::_states
private

The stack where the states in the game are kept.


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