-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSceneManager.cpp
More file actions
91 lines (79 loc) · 1.72 KB
/
Copy pathSceneManager.cpp
File metadata and controls
91 lines (79 loc) · 1.72 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
/**
* The SceneManager facilitates the changing of scenes.
*
* Author: Skylar Payne
* Date: 6/30/2013
* File: SceneManager.cpp
**/
#include "SceneManager.h"
/**
* @brief SceneManager::~SceneManager RAII
*/
SceneManager::~SceneManager()
{
Quit();
}
/**
* @brief SceneManager::Init initializes the SceneManager with a starting scene
* @param startScene the scene to start with
* @return true if not already initialized, startScene is not nullptr, AND loaded successfully. False otherwise.
*/
bool SceneManager::Init(IScene* startScene)
{
if(startScene && !_CurrentScene)
{
_CurrentScene = startScene;
return _CurrentScene->Load();
}
return false;
}
/**
* @brief SceneManager::Update Updates the current scene. Also handles changing scenes if necessary.
*/
void SceneManager::Update()
{
if(_NextScene)
{
this->ChangeScene();
}
if(_CurrentScene)
{
_CurrentScene->Update();
}
}
/**
* @brief SceneManager::Quit Handles the unloading of current scene when the program ends
*/
void SceneManager::Quit()
{
if(_CurrentScene)
{
_CurrentScene->Unload();
delete _CurrentScene;
_CurrentScene = nullptr;
}
if(_NextScene)
{
delete _NextScene;
_NextScene = nullptr;
}
}
/**
* @brief SceneManager::ChangeScene changes scenes when there's a new scene
*/
void SceneManager::ChangeScene()
{
if(_CurrentScene)
{
_CurrentScene->Unload();
delete _CurrentScene;
_CurrentScene = nullptr;
}
_CurrentScene = _NextScene;
_NextScene = nullptr;
_CurrentScene->Load();
}
void SceneManager::OnMessage(ChangeSceneMessage& msg)
{
_NextScene = msg.NextScene;
}