Gamedev Framework (gf) 0.21.0
A C++17 framework for 2D games
Scene.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_H
22#define GF_SCENE_H
23
24#include "Action.h"
25#include "EntityContainer.h"
26#include "Event.h"
27#include "GraphicsApi.h"
28#include "ModelContainer.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
36namespace gf {
37#ifndef DOXYGEN_SHOULD_SKIP_THIS
38inline namespace v1 {
39#endif
40
66 class GF_GRAPHICS_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
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
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
340
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
An action that can be triggered by different controls.
Definition: Action.h:53
Adaptative view.
Definition: View.h:390
A game entity.
Definition: Entity.h:53
A game object that can be updated.
Definition: Model.h:46
Base class for all render targets (window, texture, ...)
Definition: RenderTarget.h:102
A scene in the game.
Definition: Scene.h:66
virtual void doHandleActions(Window &window)
Customization point for handleActions()
void hide()
Hide the scene.
void processEvent(Event &event)
Process an event.
void addAction(Action &action)
Add an action to the scene.
Definition: Scene.h:276
virtual void doHide()
Customization point for hide()
void render(RenderTarget &target, const RenderStates &states=RenderStates())
Render the scene.
virtual void doProcessEvent(Event &event)
Customization point for processEvent()
View & getWorldView()
Get the world view.
Definition: Scene.h:366
virtual void doUpdate(Time time)
Customization point for update()
void setWorldViewSize(Vector2f size)
Set the size of the world view.
void setFramebufferSize(gf::Vector2i size)
Update the framebuffer size.
virtual ~Scene()
Destructor.
void setClearColor(gf::Color4f color)
Set the new clear color.
Definition: Scene.h:162
void addWorldEntity(Entity &entity)
Add a world entity to the scene.
Definition: Scene.h:294
void setActive(bool active=true)
Change the active state of the scene.
Entity * removeHudEntity(Entity *entity)
Remove a HUD entity from the scene.
Definition: Scene.h:321
bool isHidden() const
Check if the scene is hidden.
Entity * removeWorldEntity(Entity *entity)
Remove a world entity from the scene.
Definition: Scene.h:303
void show()
Show the scene.
void addModel(Model &model)
Add a model to the scene.
Definition: Scene.h:285
void addHudEntity(Entity &entity)
Add a HUD entity to the scene.
Definition: Scene.h:312
void resume()
Resume the scene.
void pause()
Pause the scene.
virtual void doResume()
Customization point for resume()
virtual void onActivityChange(bool active)
Callback when the scene becomes active or inactive.
virtual void doRender(RenderTarget &target, const RenderStates &states)
Customization point for render()
bool isActive() const
Check if the scene is active.
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
void handleActions(Window &window)
Handle actions.
virtual void doShow()
Customization point for show()
View & getHudView()
Get the HUD view.
Definition: Scene.h:373
virtual void doPause()
Customization point for pause()
void setWorldViewCenter(Vector2f center)
Set the center of the world view.
bool isPaused() const
Check if the scene is paused.
void renderWorldEntities(RenderTarget &target, const RenderStates &states)
Render the world entities.
void renderHudEntities(RenderTarget &target, const RenderStates &states)
Render the HUD entities.
Scene(Vector2i initialSize)
Constructor.
void update(Time time)
Update the scene.
virtual bool doEarlyProcessEvent(Event &event)
Customization point for processEvent()
A scene manager.
Definition: SceneManager.h:61
Represents a time value.
Definition: Time.h:65
2D camera that defines what region is shown on framebuffer
Definition: View.h:94
An OS window.
Definition: Window.h:82
Color4< float > Color4f
A float color vector with 4 components.
Definition: Vector.h:1287
@ Hidden
The window is hidden (data in event.window)
@ Shown
The window is shown (data in event.window)
The namespace for gf classes.
Definition: Action.h:35
Defines a system event and its parameters.
Definition: Event.h:224
Define the states used for drawing to a RenderTarget.
Definition: RenderStates.h:82
A 4D vector.
Definition: Vector.h:852