-
Notifications
You must be signed in to change notification settings - Fork 0
/
SceneManager.h
38 lines (30 loc) · 987 Bytes
/
SceneManager.h
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
#pragma once
#include<vector>
#include<unordered_map>
#include"SharedContext.h"
#include"Scenes/BaseScene.h"
#include"Scenes/SceneType.h"
#include<memory>
class SceneManager {
public:
explicit SceneManager(const SharedContext& context);
void update() const;
void render() const;
void removeScene();
void createScene(const SceneType sceneType);
void removeAllScenes();
bool isSceneStackEmpty() const;
const SharedContext& getSharedContext() const;
private:
using SceneStack = std::vector<std::pair<SceneType, std::unique_ptr<BaseScene>>>;
using SceneFactory = std::unordered_map<SceneType, std::function<std::unique_ptr<BaseScene>(void)>>;
SceneStack m_sceneStack;
SceneFactory m_sceneFactory;
SharedContext m_sharedContext;
template <typename T>
void registerScene(const SceneType sceneType) {
m_sceneFactory[sceneType] = [this]() {
return std::make_unique<T>(*this);
};
}
};