Gamedev Framework (gf)  0.17.0
A C++14 framework for 2D games
SceneManager.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2019 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 
26 #include "ArrayRef.h"
27 #include "Color.h"
28 #include "Easings.h"
29 #include "Portability.h"
30 #include "Ref.h"
31 #include "RenderStates.h"
32 #include "RenderWindow.h"
33 #include "RenderTexture.h"
34 #include "Scene.h"
35 #include "Segue.h"
36 #include "SegueEffect.h"
37 #include "Window.h"
38 
39 namespace gf {
40 #ifndef DOXYGEN_SHOULD_SKIP_THIS
41 inline namespace v1 {
42 #endif
43 
58  class GF_API SceneManager {
59  public:
68 
74  void run(const RenderStates &states = RenderStates());
75 
81  void pushScene(Scene& scene);
82 
88  void pushScenes(ArrayRef<Ref<Scene>> scenes);
89 
93  void popScene();
94 
98  void popAllScenes();
99 
107  void replaceScene(Scene& scene) {
108  popScene();
109  pushScene(scene);
110  }
111 
120  popScene();
121  pushScenes(scenes);
122  }
123 
131  void replaceAllScenes(Scene& scene) {
132  popAllScenes();
133  pushScene(scene);
134  }
135 
144  popAllScenes();
145  pushScenes(scenes);
146  }
147 
156  void replaceScene(Scene& scene, SegueEffect& effect, Time duration, Easing easing = Ease::linear);
157 
166  void replaceScene(ArrayRef<Ref<Scene>> scenes, SegueEffect& effect, Time duration, Easing easing = Ease::linear);
167 
176  void replaceAllScenes(Scene& scene, SegueEffect& effect, Time duration, Easing easing = Ease::linear);
177 
186  void replaceAllScenes(ArrayRef<Ref<Scene>> scenes, SegueEffect& effect, Time duration, Easing easing = Ease::linear);
187 
192  return m_window;
193  }
194 
199  return m_renderer;
200  }
201 
207  Vector2f computeWindowToGameCoordinates(Vector2i coords, const View& view) const;
208 
214  Vector2i computeGameToWindowCoordinates(Vector2f coords, const View& view) const;
215 
216  private:
217  void setupSegue(SegueEffect& effect, Time duration, Easing easing);
218 
219  private:
220  Window m_window;
221  RenderWindow m_renderer;
222  bool m_scenesChanged;
223 
224  std::vector<Ref<Scene>> m_currScenes;
225  std::vector<Ref<Scene>> m_prevScenes;
226 
227  RenderTexture m_targetCurrScenes;
228  RenderTexture m_targetPrevScenes;
229  ScreenView m_view;
230  Segue m_segue;
231 
232  enum class Status {
233  Scene,
234  Segue,
235  };
236 
237  Status m_status;
238  };
239 
240 #ifndef DOXYGEN_SHOULD_SKIP_THIS
241 }
242 #endif
243 }
244 
245 
246 #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
Screen view.
Definition: Views.h:354
void replaceAllScenes(Scene &scene)
Replace all the scenes with a new scene.
Definition: SceneManager.h:131
Base class for all render targets (window, texture, ...)
Definition: RenderTarget.h:90
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:107
constexpr AllType All
Constant to represent "all".
Definition: Types.h:61
Window & getWindow()
Get the window associated to the scene.
Definition: SceneManager.h:191
A segue effect.
Definition: SegueEffect.h:38
Represents a time value.
Definition: Time.h:65
A scene manager.
Definition: SceneManager.h:58
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
A constant reference to an array and its size.
Definition: ArrayRef.h:43
An OS window.
Definition: Window.h:81
void replaceAllScenes(ArrayRef< Ref< Scene >> scenes)
Replace all the scenes with many scenes.
Definition: SceneManager.h:143
float(*)(float) Easing
An easing function.
Definition: Easings.h:48
A constant reference to a string and its size.
Definition: StringRef.h:41
A transition between two scenes.
Definition: Segue.h:45
RenderTarget & getRenderer()
Get the renderer associated to the scene.
Definition: SceneManager.h:198
A scene in the game.
Definition: Scene.h:66
A reference wrapper.
Definition: Ref.h:39
void replaceScene(ArrayRef< Ref< Scene >> scenes)
Replace the top scene with many scenes.
Definition: SceneManager.h:119