-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGEStateManager.cpp
82 lines (68 loc) · 1.41 KB
/
GEStateManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//////////////////////////////////////////////////////////////////
//
// Arturo Cepeda Pérez
// Game Engine
//
// Core
//
// --- GEStateManager.cpp ---
//
//////////////////////////////////////////////////////////////////
#include "GEStateManager.h"
using namespace GE;
using namespace GE::Core;
StateManager::StateManager()
: mStatePopRequests(0u)
{
}
StateManager::~StateManager()
{
}
void StateManager::setActiveState(const ObjectName& pStateName)
{
State* state = mStatesRegistry.get(pStateName);
GEAssert(state);
mActiveStates.clear();
mActiveStates.push_back(state);
}
State* StateManager::getActiveState()
{
return mActiveStates.empty() ? 0 : mActiveStates.back();
}
void StateManager::pushState(const ObjectName& pStateName)
{
State* state = mStatesRegistry.get(pStateName);
GEAssert(state);
mActiveStates.push_back(state);
}
void StateManager::popState()
{
mActiveStates.pop_back();
}
void StateManager::requestPopStates(uint32_t pStatesCount)
{
mStatePopRequests += pStatesCount;
}
bool StateManager::isOnTheStack(State* pState) const
{
for(size_t i = 0u; i < mActiveStates.size(); i++)
{
if(mActiveStates[i] == pState)
{
return true;
}
}
return false;
}
void StateManager::update()
{
if(mStatePopRequests > 0u)
{
popState();
mStatePopRequests--;
}
}
void StateManager::releaseStates()
{
mStatesRegistry.clear();
}