Source/Gorgon/Scene.h

Tue, 06 Jul 2021 10:22:49 +0300

author
cemkalyoncu
date
Tue, 06 Jul 2021 10:22:49 +0300
branch
4.x-dev
changeset 1701
b168349a931d
parent 1688
fd16ff398275
permissions
-rwxr-xr-x

* Image/Bitmap rotate

1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
1 #pragma once
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
2
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
3 #include "Utils/Assert.h"
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
4 #include "Event.h"
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
5 #include "ConsumableEvent.h"
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
6 #include "Main.h"
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
7
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
8 #include "Layer.h"
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
9 #include "Input/Layer.h"
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
10 #include "Input/Keyboard.h"
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
11 #include "Graphics/Layer.h"
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
12 #include "Containers/Hashmap.h"
1599
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
13 #include "UI/Window.h"
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
14 #include "Time.h"
1599
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
15 #include "Widgets/Panel.h"
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
16
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
17 #include <stdexcept>
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
18
1070
d52068ce190d * Scene support is ready, waiting for unit tests
cemkalyoncu
parents: 1068
diff changeset
19
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
20 namespace Gorgon {
1077
97d2ec99a868 * Added documentation for Scene system, still needs an example
cemkalyoncu
parents: 1072
diff changeset
21
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
22 /// Can be used to identify scenes
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
23 using SceneID = int;
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
24
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
25 /// Used to denote there is no explicit scene id given to a
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
26 /// scene.
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
27 static constexpr SceneID NoSceneID = -1;
1071
b6769ccdcc17 * Fixed a compile error in GCC
cemkalyoncu
parents: 1070
diff changeset
28
b6769ccdcc17 * Fixed a compile error in GCC
cemkalyoncu
parents: 1070
diff changeset
29 class SceneManager;
b6769ccdcc17 * Fixed a compile error in GCC
cemkalyoncu
parents: 1070
diff changeset
30
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
31 /**
1599
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
32 * This class represents a scene in the game like menu screen
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
33 * in game, post game, pause or different game modes. Scenes
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
34 * can be swapped on the fly and some scenes can be linked to
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
35 * others. Scene class is abstract, it must be derived by
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
36 * other classes in order to work.
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
37 */
1192
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1077
diff changeset
38 class Scene : public Animation::Governor {
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
39 friend class SceneManager;
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
40 public:
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
41
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
42 /// Empty constructor. After this constructor, the scene
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
43 /// cannot be activated.
1599
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
44 explicit Scene(SceneID id = NoSceneID, bool mouseinput = true);
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
45
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
46 /// Sets the parent layer so that the scene can be activated.
1688
fd16ff398275 * Scene ui scale
cemkalyoncu
parents: 1599
diff changeset
47 explicit Scene(SceneManager &parent, SceneID id = NoSceneID, bool mouseinput = true);
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
48
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
49 /// Whether this scene requires keyboard input.
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
50 virtual bool RequiresKeyInput() const = 0;
1192
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1077
diff changeset
51
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1077
diff changeset
52 /// Activates the current scene
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1077
diff changeset
53 virtual void Activate() override;
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
54
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
55 /// Returns the ID of the current scene
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
56 SceneID GetID() const {
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
57 return id;
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
58 }
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
59
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
60 /// Called when the scene receives a key
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
61 virtual void KeyEvent(Gorgon::Input::Key, float) { }
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
62
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
63 /// Fires whenever activation of this layer is completed.
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
64 /// Will not be fired if the layer is already active and
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
65 /// Activate function is called.
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
66 Gorgon::Event<Scene> ActivatedEvent{*this};
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
67
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
68 /// Fires whenever deactivation of this layer is completed.
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
69 /// Will not be fired if the layer is already inactive and
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
70 /// Deactivate function is called.
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
71 Gorgon::Event<Scene> DeactivatedEvent{*this};
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
72
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
73 protected:
1192
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1077
diff changeset
74 /// Called only for the first time this scene is activated.
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1077
diff changeset
75 /// Allocate your resources here.
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1077
diff changeset
76 virtual void first_activation() { }
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1077
diff changeset
77
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1077
diff changeset
78 /// Called after very activation. first_activation will be called
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1077
diff changeset
79 /// before activate.
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1077
diff changeset
80 virtual void activate() { }
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
81
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
82 /// Called *before* deactivation
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
83 virtual void deactivate() { }
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
84
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
85 /// Scene should perform its frame based operations in this
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
86 /// function
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
87 virtual void doframe(unsigned int delta) = 0;
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
88
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
89 /// This is called after doframe to perform rendering operation.
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
90 /// It is possible to receive render without receiving doframe,
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
91 /// thus they should not be co-dependent.
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
92 virtual void render() = 0;
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
93
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
94 /// Changes the boundaries of the main layer
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
95 void setlayerbounds(const Geometry::Bounds &bounds) {
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
96 main.SetBounds(bounds);
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
97 }
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
98
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
99
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
100 /// ID of the current scene
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
101 SceneID id;
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
102
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
103 /// Graphics layer that can be drawn on
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
104 Gorgon::Graphics::Layer graphics;
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
105
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
106 /// Mouse layer that can be used to receive mouse events.
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
107 /// If the mouseinput parameter of the constructor is
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
108 /// set to true, this layer will be attached, otherwise
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
109 /// it will not be functional.
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
110 Gorgon::Input::Layer mouse;
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
111
1599
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
112 /// The parent window for the scene. Unless you are explicitly
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
113 /// requesting a parent, this member could be nullptr.
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
114 SceneManager *parent = nullptr;
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
115
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
116 /// This panel covers the entire area of the window. You may place
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
117 /// your widgets on top of this panel. They will be displayed above
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
118 /// drawing layer
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
119 Widgets::Panel ui;
1070
d52068ce190d * Scene support is ready, waiting for unit tests
cemkalyoncu
parents: 1068
diff changeset
120
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
121 private:
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
122
1070
d52068ce190d * Scene support is ready, waiting for unit tests
cemkalyoncu
parents: 1068
diff changeset
123 void activate_scene();
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
124
1070
d52068ce190d * Scene support is ready, waiting for unit tests
cemkalyoncu
parents: 1068
diff changeset
125 void deactivate_scene();
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
126
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
127 Gorgon::Layer main;
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
128 bool mouseinput = false;
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
129 bool isactive = false;
1192
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1077
diff changeset
130 bool first = true;
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
131 };
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
132
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
133 /**
1599
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
134 * This class is a Window that manages scenes, allowing swapping,
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
135 * handling input and game loop. This runner is most suitable for
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
136 * games where there would be multiple scenes (intro, how to play,
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
137 * game, pause screen, etc...) that compete with each other for
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
138 * input and rendering.
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
139 */
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
140 class SceneManager : public UI::Window {
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
141 public:
1599
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
142 using Window::Window;
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
143
1599
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
144 SceneManager() : Window() {
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
145 }
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
146
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
147 SceneManager(SceneManager &&) = default;
1257
2375635390be * UI::Window to handle UI needs
cemkalyoncu
parents: 1192
diff changeset
148
2375635390be * UI::Window to handle UI needs
cemkalyoncu
parents: 1192
diff changeset
149 SceneManager &operator =(SceneManager &&) = default;
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
150
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
151 ~SceneManager() {
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
152 scenes.Destroy();
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
153 }
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
154
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
155 /// Switches the current scene to the scene with the given id.
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
156 /// Will throw std::runtime_error if scene is not found. If
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
157 /// given id is NoSceneID, all scenes will be deactivated.
1599
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
158 void SwitchScene(SceneID scene);
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
159
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
160 /// Deactivates all scenes
1599
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
161 void Deactivate();
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
162
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
163
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
164 /// Moves keyboard input event to the top if there is a layer
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
165 /// that accepts keyboard input.
1599
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
166 void ActivateKeyboard();
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
167
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
168 /// Runs the application by running the active scene,
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
169 /// progressing OS events and rendering mechanism. This
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
170 /// function will run until Quit is called.
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
171 void Run() override;
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
172
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
173 /// Steps the application by running the active scene,
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
174 /// progressing OS events and rendering mechanism.
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
175 void Step() override {
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
176 if(active) {
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
177 active->doframe(Time::DeltaTime());
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
178 active->render();
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
179 }
1599
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
180
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
181 Gorgon::NextFrame();
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
182 }
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
183
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
184 /// Returns the number of scenes registered
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
185 int GetSceneCount() const {
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
186 return scenes.GetCount();
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
187 }
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
188
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
189 /// Returns if the given scene exists
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
190 bool SceneExists(SceneID id) const {
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
191 return scenes.Exists(id);
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
192 }
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
193
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
194 /// Returns the requested scene. If it does not exist, this
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
195 /// function will throw runtime error.
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
196 Scene &GetScene(SceneID scene) {
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
197 return scenes[scene];
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
198 }
1072
5d8b0d820bb8 * Unit tests for scene system
cemkalyoncu
parents: 1071
diff changeset
199
1599
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
200 /// Deletes the given scene, nothing is done if the scene is
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
201 /// not found
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
202 void DeleteScene(SceneID scene) {
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
203 scenes.Delete(scene);
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
204 }
1072
5d8b0d820bb8 * Unit tests for scene system
cemkalyoncu
parents: 1071
diff changeset
205
1599
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
206 /// Releases the ownership of the scene with the given ID,
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
207 /// removing it from the manager. Using scene while it does
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
208 /// not have parent might cause problems.
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
209 Scene &Release(SceneID id);
1072
5d8b0d820bb8 * Unit tests for scene system
cemkalyoncu
parents: 1071
diff changeset
210
1599
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
211 /// Assumes the ownership of the the given scene, adding it
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
212 /// to the list of scenes.
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
213 void Assume(Scene &scene) {
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
214 scene.parent = this;
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
215 scenes.Add(scene.id, scene);
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
216 }
1072
5d8b0d820bb8 * Unit tests for scene system
cemkalyoncu
parents: 1071
diff changeset
217
1599
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
218 /// Returns iterator to the first scene.
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
219 auto begin() {
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
220 return scenes.begin();
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
221 }
1072
5d8b0d820bb8 * Unit tests for scene system
cemkalyoncu
parents: 1071
diff changeset
222
1599
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
223 /// Returns iterator to the first scene.
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
224 auto begin() const {
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
225 return scenes.begin();
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
226 }
1072
5d8b0d820bb8 * Unit tests for scene system
cemkalyoncu
parents: 1071
diff changeset
227
1599
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
228 /// Returns iterator to the end of scenes.
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
229 auto end() {
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
230 return scenes.end();
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
231 }
1072
5d8b0d820bb8 * Unit tests for scene system
cemkalyoncu
parents: 1071
diff changeset
232
1599
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
233 /// Returns iterator to the end of scenes.
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
234 auto end() const {
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
235 return scenes.end();
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
236 }
1072
5d8b0d820bb8 * Unit tests for scene system
cemkalyoncu
parents: 1071
diff changeset
237
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
238 /// Quits the scene manager, returning the execution to the
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
239 /// point where Run function is called. It allows current
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
240 /// frame to be completed before quiting. It also deactives
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
241 /// the current scene.
1070
d52068ce190d * Scene support is ready, waiting for unit tests
cemkalyoncu
parents: 1068
diff changeset
242 void Quit() override {
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
243 quiting = true;
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
244 }
1599
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
245
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
246 //TODO overload resize to resize panels of all scenes
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
247
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
248 /// Creates a new scene using the given type and parameters.
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
249 /// Scene class should always take parent layer first, then
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
250 /// id and then the other parameters if they exists. When
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
251 /// using this function, only specify the class as template
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
252 /// parameter, the others will be resolved. If a scene with
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
253 /// the same id exists, it will be deleted. It is advisable
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
254 /// to add new scenes at the start without activating any
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
255 /// scene.
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
256 ///
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
257 /// @code
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
258 /// enum SceneIDs {
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
259 /// SCENE_MENU,
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
260 /// SCENE_GAME
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
261 /// };
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
262 ///
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
263 /// //...
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
264 ///
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
265 /// class GameScene : public Scene {
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
266 /// public:
1070
d52068ce190d * Scene support is ready, waiting for unit tests
cemkalyoncu
parents: 1068
diff changeset
267 /// GameScene(Gorgon::SceneManager &parent, SceneID id, int players);
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
268 ///
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
269 /// //...
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
270 /// };
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
271 ///
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
272 /// //...
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
273 ///
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
274 /// //Create the game scene with a single player.
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
275 /// manager.NewScene<GameScene>(SCENE_GAME, 1);
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
276 ///
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
277 /// manager.SwitchScene(SCENE_GAME);
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
278 ///
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
279 /// @endcode
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
280 template<class S_, class ... P_>
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
281 S_ &NewScene(SceneID id, P_ && ... params) {
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
282 auto *s = new S_(*this, id, std::forward<P_>(params)...);
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
283
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
284 scenes.Add(id, s, true);
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
285
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
286 return *s;
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
287 }
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
288
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
289 /// This event will be fired whenever a scene is activated.
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
290 Gorgon::Event<SceneManager, Scene&> ActivatedEvent{*this};
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
291
1599
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
292 protected:
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
293 EventToken init();
1070
d52068ce190d * Scene support is ready, waiting for unit tests
cemkalyoncu
parents: 1068
diff changeset
294
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
295 Gorgon::Containers::Hashmap<SceneID, Scene> scenes;
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
296 Scene *active = nullptr;
1599
ce673feea35d * Scene system now allows UI to be embedded
cemkalyoncu
parents: 1257
diff changeset
297 EventToken inputtoken = init(); //to initialize token after window got constructed
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
298 bool quiting = false;
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
299 };
1070
d52068ce190d * Scene support is ready, waiting for unit tests
cemkalyoncu
parents: 1068
diff changeset
300
d52068ce190d * Scene support is ready, waiting for unit tests
cemkalyoncu
parents: 1068
diff changeset
301
1068
b1580d153add * Initial merging of Scene system. Final system will make scene manager a window
cemkalyoncu
parents:
diff changeset
302 }

mercurial