-
Notifications
You must be signed in to change notification settings - Fork 0
/
StateManager.cpp
61 lines (49 loc) · 945 Bytes
/
StateManager.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
#include "Library.h"
StateManager* StateManager::instance = nullptr;
StateManager* StateManager::GetInstance()
{
if (instance == nullptr)
instance = new StateManager();
return instance;
}
StateManager::StateManager()
{
currentState = nullptr;
nextStateID = STATE_NONE;
stateID = STATE_NONE;
}
void StateManager::SetNextState(const int &newStateID)
{
nextStateID = newStateID;
}
void StateManager::ChangeState()
{
if (nextStateID != STATE_NONE)
{
if (nextStateID != STATE_EXIT)
delete currentState;
switch (nextStateID)
{
case STATE_MENU:
currentState = new MainMenu();
}
stateID = nextStateID;
nextStateID = STATE_NONE;
}
}
int StateManager::GetCurrentStateID()
{
return stateID;
}
void StateManager::HandleEvents()
{
SetNextState(currentState->HandleEvents());
}
void StateManager::DoLogic()
{
currentState->DoLogic();
}
void StateManager::RenderGraphics()
{
currentState->RenderGraphics();
}