-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSceneManager.cpp
More file actions
48 lines (39 loc) · 1.34 KB
/
SceneManager.cpp
File metadata and controls
48 lines (39 loc) · 1.34 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
// =================
// SCENEMANAGER.CPP
// implements scene stack management and forwards game loop calls to the active scene
// =================
#include "header/SceneManager.h"
// constructor initializes the scene change flags to false
SceneManager::SceneManager() : isAdding(false), isReplacing(false), isRemoving(false) {}
// requests a scene change by setting the appropriate flags and storing the new scene
void SceneManager::pushScene(std::unique_ptr<Scene> scene, bool replace) {
isAdding = true;
isReplacing = replace;
newScene = std::move(scene);
}
void SceneManager::popScene() {
isRemoving = true;
}
void SceneManager::processSceneChanges() {
if (isRemoving && !sceneStack.empty()) {
sceneStack.pop();
isRemoving = false;
}
if (isAdding) {
if (isReplacing && !sceneStack.empty()) {
sceneStack.pop();
}
sceneStack.push(std::move(newScene));
sceneStack.top()->init();
isAdding = false;
}
}
void SceneManager::handleInput(sf::RenderWindow& window) {
if (!sceneStack.empty()) sceneStack.top()->handleInput(window);
}
void SceneManager::update(float deltaTime) {
if (!sceneStack.empty()) sceneStack.top()->update(deltaTime);
}
void SceneManager::render(sf::RenderWindow& window) {
if (!sceneStack.empty()) sceneStack.top()->render(window);
}