-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameStateManager.cpp
More file actions
101 lines (85 loc) · 1.76 KB
/
Copy pathGameStateManager.cpp
File metadata and controls
101 lines (85 loc) · 1.76 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "GameStateManager.h"
#include <iostream>
#include "GameState.h"
GameStateManager::GameStateManager(GameState* state)
{
m_NextUID = 0;
if(state)
{
state->onLoad();
m_CurrentState = state;
m_States.push_back(state);
}
else
{
std::cerr << "Error loading gamestate, improper opening state passed to GSM" << std::endl;
}
}
GameStateManager::~GameStateManager()
{
for(size_t i = 0; i < m_States.size(); i++)
{
if(m_States[i])
{
m_States[i]->onDestroy();
delete m_States[i];
}
else
{
std::cerr << "Error: attempted to delete invalid state pointer in GSM dtor!" << std::endl;
}
}
}
GameState* GameStateManager::getCurrentState()
{
if(!m_CurrentState)
{
std::cerr << "Warning, invalid current state requested from GSM" << std::endl;
}
return m_CurrentState;
}
bool GameStateManager::switchCurrentState(GameState* state)
{
if(state == NULL)
{
std::cerr << "Error, invalid state passed into GSM's switchCurrentState" << std::endl;
return false;
}
// Check this state against the ones we already know about,
// and if we don't already know about it, store it for later use.
bool found = false;
for(size_t i = 0; i < m_States.size(); i++)
{
if(state == m_States[i])
{
found = true;
break;
}
}
if(found == false)
{
state->onLoad();
m_States.push_back(state);
}
m_CurrentState = state;
return true;
}
GameState* GameStateManager::createState(GameStateType::Type type)
{
GameState* state = NULL;
/*
switch(type)
{
default:
{
state = NULL;
break;
}
}
*/
if(state == NULL)
{
std::cerr << "No valid state type provided to GSM for createState, invalid state returned" << std::endl;
}
return state;
}