Gamedev Framework (gf)  0.19.0
A C++17 framework for 2D games
SceneManager.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2021 Julien Bernard
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 #ifndef GF_SCENE_MANAGER_H
22 #define GF_SCENE_MANAGER_H
23 
24 #include <vector>
25 #include <string>
26 
27 #include "Color.h"
28 #include "Easings.h"
29 #include "Event.h"
30 #include "GraphicsApi.h"
31 #include "Ref.h"
32 #include "RenderStates.h"
33 #include "RenderWindow.h"
34 #include "RenderTexture.h"
35 #include "Scene.h"
36 #include "Segue.h"
37 #include "SegueEffect.h"
38 #include "Span.h"
39 #include "Window.h"
40 
41 namespace gf {
42 #ifndef DOXYGEN_SHOULD_SKIP_THIS
43 inline namespace v1 {
44 #endif
45 
46 
61  class GF_GRAPHICS_API SceneManager {
62  public:
70  SceneManager(const std::string& title, Vector2i size, Flags<WindowHints> hints = All);
71 
77  void run(const RenderStates &states = RenderStates());
78 
84  void pushScene(Scene& scene);
85 
91  void pushScenes(Span<const Ref<Scene>> scenes);
92 
96  void popScene();
97 
101  void popAllScenes();
102 
110  void replaceScene(Scene& scene) {
111  popScene();
112  pushScene(scene);
113  }
114 
122  void replaceScene(Span<const Ref<Scene>> scenes) {
123  popScene();
124  pushScenes(scenes);
125  }
126 
134  void replaceAllScenes(Scene& scene) {
135  popAllScenes();
136  pushScene(scene);
137  }
138 
146  void replaceAllScenes(Span<const Ref<Scene>> scenes) {
147  popAllScenes();
148  pushScenes(scenes);
149  }
150 
159  void replaceScene(Scene& scene, SegueEffect& effect, Time duration, Easing easing = Ease::linear);
160 
169  void replaceScene(Span<const Ref<Scene>> scenes, SegueEffect& effect, Time duration, Easing easing = Ease::linear);
170 
179  void replaceAllScenes(Scene& scene, SegueEffect& effect, Time duration, Easing easing = Ease::linear);
180 
189  void replaceAllScenes(Span<const Ref<Scene>> scenes, SegueEffect& effect, Time duration, Easing easing = Ease::linear);
190 
195  return m_window;
196  }
197 
202  return m_renderer;
203  }
204 
210  Vector2f computeWindowToGameCoordinates(Vector2i coords, const View& view) const;
211 
217  Vector2i computeGameToWindowCoordinates(Vector2f coords, const View& view) const;
218 
219  private:
220  virtual void doGlobalProcessEvent(const Event& event);
221 
222  private:
223  void setupSegue(SegueEffect& effect, Time duration, Easing easing);
224 
225  private:
226  Window m_window;
227  RenderWindow m_renderer;
228  bool m_scenesChanged;
229 
230  std::vector<Ref<Scene>> m_currScenes;
231  std::vector<Ref<Scene>> m_prevScenes;
232 
233  RenderTexture m_targetCurrScenes;
234  RenderTexture m_targetPrevScenes;
235  ScreenView m_view;
236  Segue m_segue;
237 
238  enum class Status {
239  Scene,
240  Segue,
241  };
242 
243  Status m_status;
244  };
245 
246 #ifndef DOXYGEN_SHOULD_SKIP_THIS
247 }
248 #endif
249 }
250 
251 
252 #endif // GF_SCENE_MANAGER_H
2D camera that defines what region is shown on framebuffer
Definition: View.h:94
Target for off-screen 2D rendering into a texture.
Definition: RenderTexture.h:98
float(*)(float) Easing
An easing function.
Definition: Easings.h:48
Screen view.
Definition: Views.h:354
void replaceAllScenes(Scene &scene)
Replace all the scenes with a new scene.
Definition: SceneManager.h:134
Base class for all render targets (window, texture, ...)
Definition: RenderTarget.h:102
Define the states used for drawing to a RenderTarget.
Definition: RenderStates.h:82
Bitfield relying on an enumeration.
Definition: Flags.h:46
void replaceScene(Scene &scene)
Replace the top scene with a new scene.
Definition: SceneManager.h:110
A span.
Definition: Span.h:36
Window & getWindow()
Get the window associated to the scene.
Definition: SceneManager.h:194
A segue effect.
Definition: SegueEffect.h:38
Represents a time value.
Definition: Time.h:65
A scene manager.
Definition: SceneManager.h:61
The namespace for gf classes.
Definition: Action.h:35
static float linear(float t)
Linear easing.
A window that can serve as a target for 2D drawing.
Definition: RenderWindow.h:80
void replaceAllScenes(Span< const Ref< Scene >> scenes)
Replace all the scenes with many scenes.
Definition: SceneManager.h:146
An OS window.
Definition: Window.h:82
If all of the activities ends.
A transition between two scenes.
Definition: Segue.h:45
RenderTarget & getRenderer()
Get the renderer associated to the scene.
Definition: SceneManager.h:201
void replaceScene(Span< const Ref< Scene >> scenes)
Replace the top scene with many scenes.
Definition: SceneManager.h:122
Defines a system event and its parameters.
Definition: Event.h:224
A scene in the game.
Definition: Scene.h:66
A reference wrapper.
Definition: Ref.h:39