Gamedev Framework (gf)  0.14.0
A C++14 framework for 2D games
Scene.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_H
22 #define GF_SCENE_H
23 
24 #include "Action.h"
25 #include "EntityContainer.h"
26 #include "Event.h"
27 #include "ModelContainer.h"
28 #include "Portability.h"
29 #include "RenderWindow.h"
30 #include "Time.h"
31 #include "ViewContainer.h"
32 #include "Views.h"
33 #include "Window.h"
34 
35 namespace gf {
36 #ifndef DOXYGEN_SHOULD_SKIP_THIS
37 inline namespace v1 {
38 #endif
39 
65  class GF_API Scene {
66  public:
76  Scene(Vector2i initialSize);
77 
81  virtual ~Scene();
82 
100  void processEvent(Event& event);
101 
114  void handleActions(Window& window);
115 
127  void update(Time time);
128 
143  void render(RenderTarget& target);
144 
161  void setActive(bool active = true);
162 
170  bool isActive() const;
171 
179  void pause();
180 
186  void resume();
187 
195  bool isPaused() const;
196 
204  void hide();
205 
211  void show();
212 
220  bool isHidden() const;
221 
236  void addView(AdaptativeView& view) {
237  m_views.addView(view);
238  }
239 
245  void addAction(Action& action) {
246  m_actions.addAction(action);
247  }
248 
254  void addModel(Model& model) {
255  m_models.addModel(model);
256  }
257 
263  void addWorldEntity(Entity& entity) {
264  m_worldEntities.addEntity(entity);
265  }
266 
272  void addHudEntity(Entity& entity) {
273  m_hudEntities.addEntity(entity);
274  }
275 
290  void setWorldViewCenter(Vector2f center);
291 
297  void setWorldViewSize(Vector2f size);
298 
303  protected:
307  void renderWorldEntities(RenderTarget& target);
308 
312  void renderHudEntities(RenderTarget& target);
313 
318  return m_worldView;
319  }
320 
324  virtual void doProcessEvent(Event& event);
325 
329  virtual void doHandleActions(Window& window);
330 
334  virtual void doUpdate(Time time);
335 
339  virtual void doRender(RenderTarget& target);
340 
344  virtual void doPause();
345 
349  virtual void doResume();
350 
354  virtual void doHide();
355 
359  virtual void doShow();
360 
361  private:
362  bool m_active;
363 
364  enum class Status {
365  Paused,
366  Resumed,
367  };
368 
369  Status m_status;
370 
371  enum class Visibility {
372  Shown,
373  Hidden,
374  };
375 
376  Visibility m_visibility;
377 
378  ActionContainer m_actions;
379  Action m_closeWindowAction;
380 
381  ModelContainer m_models;
382 
383  ExtendView m_worldView;
384  ScreenView m_hudView;
385  ViewContainer m_views;
386 
387  EntityContainer m_worldEntities;
388  EntityContainer m_hudEntities;
389  };
390 
391 #ifndef DOXYGEN_SHOULD_SKIP_THIS
392 }
393 #endif
394 }
395 
396 
397 #endif // GF_SCENE_H
View & getWorldView()
Get the world view.
Definition: Scene.h:317
2D camera that defines what region is shown on screen
Definition: View.h:94
A set of actions.
Definition: Action.h:240
Screen view.
Definition: Views.h:354
Base class for all render targets (window, texture, ...)
Definition: RenderTarget.h:73
void addHudEntity(Entity &entity)
Add a HUD entity to the scene.
Definition: Scene.h:272
A container of views.
Definition: ViewContainer.h:52
Represents a time value.
Definition: Time.h:74
A collection of models.
Definition: ModelContainer.h:54
A game object that can be updated.
Definition: Model.h:46
void addWorldEntity(Entity &entity)
Add a world entity to the scene.
Definition: Scene.h:263
void addModel(Model &model)
Add a model to the scene.
Definition: Scene.h:254
A game entity.
Definition: Entity.h:53
The namespace for gf classes.
Definition: Action.h:35
Extend view.
Definition: Views.h:220
An OS window.
Definition: Window.h:88
void addAction(Action &action)
Add an action to the scene.
Definition: Scene.h:245
An action that can be triggered by different controls.
Definition: Action.h:53
Defines a system event and its parameters.
Definition: Event.h:97
Adaptative view.
Definition: View.h:390
A scene in the game.
Definition: Scene.h:65
void addView(AdaptativeView &view)
Add a view to the scene.
Definition: Scene.h:236
A collection of entities.
Definition: EntityContainer.h:60