forked from pcsx-redux/nugget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscene.hh
103 lines (83 loc) · 3.29 KB
/
scene.hh
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
102
103
/*
MIT License
Copyright (c) 2022 PCSX-Redux authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include "psyqo/application.hh"
namespace psyqo {
class GPU;
/**
* @brief The Scene class.
*
* @details This class is the base class for all scenes. Rendering is supposed
* to be done by the scenes. Only one scene can be active at a time. There is
* a helper stack system for managing the scenes. See the `Application` class
* for more information.
*/
class Scene {
public:
enum class StartReason { Create, Resume };
/**
* @brief Starts the scene.
*
* @details This method will be called when the scene is started. It is
* meant to set the environment in a suitable manner. A scene starts when
* it becomes the active scene, either when being pushed or when the
* previous scene is popped. The argument will indicate whether the scene
* is started because it just got pushed, or because another one is getting
* popped.
* @param reason The reason why the scene is started. Create or Resume.
*/
virtual void start(StartReason reason) {}
/**
* @brief Renders a frame.
*
* @details This method will be called when the scene is active, every time
* a new frame is to be rendered.
*/
virtual void frame() {}
enum class TearDownReason { Destroy, Pause };
/**
* @brief Tears down the scene.
*
* @details This method will be called when the scene is no longer the
* active scene. It is meant to clean up the environment, basically
* reversing the effects of `start`. The argument will indicate whether
* the scene is being popped, or if another scene is pushed on the stack.
* @param reason The reason why the scene is being torn down. DESTROY or PAUSE.
*/
virtual void teardown(TearDownReason reason) {}
virtual ~Scene() = default;
protected:
/**
* @brief Alias for `Application::pushScene`.
*/
void pushScene(Scene* scene) { m_parent->pushScene(scene); }
/**
* @brief Alias for `Application::popScene`.
*/
Scene* popScene() { return m_parent->popScene(); }
/**
* @brief Alias for `Application::gpu()`.
*/
psyqo::GPU& gpu() { return m_parent->gpu(); }
private:
Application* m_parent;
friend class Application;
};
} // namespace psyqo