-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStateMachine.cpp
More file actions
42 lines (34 loc) · 998 Bytes
/
Copy pathStateMachine.cpp
File metadata and controls
42 lines (34 loc) · 998 Bytes
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
#include "StateMachine.hpp"
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::GetAtciveState() {
return this->_states.top();
}