-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSceneRegistry.hpp
More file actions
42 lines (31 loc) · 1.19 KB
/
SceneRegistry.hpp
File metadata and controls
42 lines (31 loc) · 1.19 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
//
// Created by Yury Rakhuba on 24/04/15.
//
#pragma once
#include "IScene.hpp"
#include <functional>
#include <memory>
#include <string>
class SceneRegistry
{
public:
SceneRegistry(SceneRegistry const & other) = delete;
SceneRegistry(SceneRegistry && other) = delete;
SceneRegistry & operator=(SceneRegistry const & other) = delete;
SceneRegistry & operator=(SceneRegistry && other) = delete;
using TSceneCreator = std::function<std::unique_ptr<IScene> ()>;
SceneRegistry(std::string && title, TSceneCreator && creator);
using TSceneEnumeratorCallback = std::function<void (std::string const & title, TSceneCreator const & creatorFn)>;
static void EnumerateScenes(TSceneEnumeratorCallback const & callback);
private:
static void RegisterScene(SceneRegistry * scene);
static SceneRegistry * m_firstScene;
private:
SceneRegistry * m_nextScene = nullptr;
std::string m_title;
TSceneCreator m_creatorFn;
};
#define REGISTER_SCENE(title, className) \
std::unique_ptr<IScene> Create##className();\
static SceneRegistry SceneRegistry##className(title, std::bind(&Create##className));\
std::unique_ptr<IScene> Create##className() { return std::unique_ptr<IScene>(new className()); }