-
Notifications
You must be signed in to change notification settings - Fork 0
/
StateMachine.cpp
58 lines (48 loc) · 1017 Bytes
/
StateMachine.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
#include "stdafx.h"
#include "StateMachine.h"
namespace EnglishEducator
{
void StateMachine::AddState(StateRef newState, bool isReplacing)
{
this->_isAdding = true;
this->_isReplacing = isReplacing;
this->_newState = std::move(newState);
}
void StateMachine::RemoveState()
{
this->_isRemoving = true;
}
void StateMachine::ProcessStateChanges()
{
if (this->_isRemoving && !this->_states.empty())
{
this->_states.pop();
if (!this->_states.empty())
{
this->_states.top()->Resume();
}
this->_isRemoving = false;
}
if (this->_isAdding)
{
if (!this->_states.empty())
{
if (this->_isReplacing)
{
this->_states.pop();
}
else
{
this->_states.top()->Pause();
}
}
this->_states.push(std::move(this->_newState));
this->_states.top()->Init();
this->_isAdding = false;
}
}
StateRef &StateMachine::GetActiveState()
{
return this->_states.top();
}
}