Gamedev Framework (gf)  0.17.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 "RenderStates.h"
31 #include "Time.h"
32 #include "ViewContainer.h"
33 #include "Views.h"
34 #include "Window.h"
35 
36 namespace gf {
37 #ifndef DOXYGEN_SHOULD_SKIP_THIS
38 inline namespace v1 {
39 #endif
40 
66  class GF_API Scene {
67  public:
77  Scene(Vector2i initialSize);
78 
82  virtual ~Scene();
83 
101  void processEvent(Event& event);
102 
115  void handleActions(Window& window);
116 
128  void update(Time time);
129 
145  void render(RenderTarget& target, const RenderStates &states = RenderStates());
146 
154  void setFramebufferSize(gf::Vector2i size);
155 
163  m_clear = color;
164  }
165 
173  return m_clear;
174  }
175 
192  void setActive(bool active = true);
193 
201  bool isActive() const;
202 
210  void pause();
211 
217  void resume();
218 
226  bool isPaused() const;
227 
235  void hide();
236 
242  void show();
243 
251  bool isHidden() const;
252 
267  void addView(AdaptativeView& view) {
268  m_views.addView(view);
269  }
270 
276  void addAction(Action& action) {
277  m_actions.addAction(action);
278  }
279 
285  void addModel(Model& model) {
286  m_models.addModel(model);
287  }
288 
294  void addWorldEntity(Entity& entity) {
295  m_worldEntities.addEntity(entity);
296  }
297 
304  return m_worldEntities.removeEntity(entity);
305  }
306 
312  void addHudEntity(Entity& entity) {
313  m_hudEntities.addEntity(entity);
314  }
315 
322  return m_hudEntities.removeEntity(entity);
323  }
324 
339  void setWorldViewCenter(Vector2f center);
340 
346  void setWorldViewSize(Vector2f size);
347 
352  protected:
356  void renderWorldEntities(RenderTarget& target, const RenderStates &states);
357 
361  void renderHudEntities(RenderTarget& target, const RenderStates &states);
362 
367  return m_worldView;
368  }
369 
374  return m_hudView;
375  }
376 
382  virtual bool doEarlyProcessEvent(Event& event);
383 
387  virtual void doProcessEvent(Event& event);
388 
392  virtual void doHandleActions(Window& window);
393 
397  virtual void doUpdate(Time time);
398 
402  virtual void doRender(RenderTarget& target, const RenderStates &states);
403 
407  virtual void doPause();
408 
412  virtual void doResume();
413 
417  virtual void doHide();
418 
422  virtual void doShow();
423 
429  virtual void onActivityChange(bool active);
430 
431  private:
432  friend class SceneManager;
433 
434  bool m_active;
435 
436  enum class Status {
437  Paused,
438  Resumed,
439  };
440 
441  Status m_status;
442 
443  enum class Visibility {
444  Shown,
445  Hidden,
446  };
447 
448  Visibility m_visibility;
449 
450  ActionContainer m_actions;
451  Action m_closeWindowAction;
452 
453  ModelContainer m_models;
454 
455  ExtendView m_worldView;
456  ScreenView m_hudView;
457  ViewContainer m_views;
458 
459  EntityContainer m_worldEntities;
460  EntityContainer m_hudEntities;
461 
462  Color4f m_clear;
463  };
464 
465 #ifndef DOXYGEN_SHOULD_SKIP_THIS
466 }
467 #endif
468 }
469 
470 
471 #endif // GF_SCENE_H
View & getWorldView()
Get the world view.
Definition: Scene.h:366
2D camera that defines what region is shown on framebuffer
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:90
Define the states used for drawing to a RenderTarget.
Definition: RenderStates.h:82
void addHudEntity(Entity &entity)
Add a HUD entity to the scene.
Definition: Scene.h:312
View & getHudView()
Get the HUD view.
Definition: Scene.h:373
A container of views.
Definition: ViewContainer.h:52
void setClearColor(gf::Color4f color)
Set the new clear color.
Definition: Scene.h:162
Represents a time value.
Definition: Time.h:65
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:294
void addModel(Model &model)
Add a model to the scene.
Definition: Scene.h:285
A game entity.
Definition: Entity.h:53
Entity * removeWorldEntity(Entity *entity)
Remove a world entity from the scene.
Definition: Scene.h:303
A scene manager.
Definition: SceneManager.h:58
The namespace for gf classes.
Definition: Action.h:35
Extend view.
Definition: Views.h:220
An OS window.
Definition: Window.h:81
A 4D vector.
Definition: Vector.h:852
Entity * removeHudEntity(Entity *entity)
Remove a HUD entity from the scene.
Definition: Scene.h:321
void addAction(Action &action)
Add an action to the scene.
Definition: Scene.h:276
An action that can be triggered by different controls.
Definition: Action.h:53
Defines a system event and its parameters.
Definition: Event.h:101
Adaptative view.
Definition: View.h:390
A scene in the game.
Definition: Scene.h:66
void addView(AdaptativeView &view)
Add a view to the scene.
Definition: Scene.h:267
gf::Color4f getClearColor() const
Get the current clear color.
Definition: Scene.h:172
A collection of entities.
Definition: EntityContainer.h:60