ImagoEngine
A C++ 2D game engine built on a sparse-set ECS, with scenes, scheduled systems, events, and action-based input
Loading...
Searching...
No Matches
Scene.hpp
Go to the documentation of this file.
1
6
7#pragma once
8
9#include "Imago/ECS/Nexus.hpp"
13
14namespace Imago::Engine
15{
16
24 class Scene {
25 protected:
26
27 // NOTE: these members are protected because they have to be defined in the children class of Scene but should not be called
28 // directly, instead load and unload should be called directly so that they can force a flush after the user-defined logic
29
33 virtual void on_load() = 0;
34
39 virtual void on_unload() {}
40
41 // protected members of the ECS/Engine objects that a Scene owns, can only be acccessed in children of Scene
46
47 public:
48
54 explicit Scene(const SceneContext& gameCtx);
55
56 // need a default destructor because this scene is abstract
57 virtual ~Scene() = default;
58
59 // explicitly dissalow copy and move behaviour because the context holds pointers into this object
60 Scene(const Scene&) = delete;
61 Scene& operator=(const Scene&) = delete;
62 Scene(Scene&&) = delete;
63 Scene& operator=(Scene&&) = delete;
64
68 void load();
69
73 void unload();
74
79 void update(float dt);
80
81 //TODO: render method
82 };
83
84}
Defines the Broadcaster to emit events for subscribed systems.
Defines the Nexus, the brain of the ECS world.
Defines the SceneContext, how systems reach persistent engine objects.
Defines the SystemScheduler, which runs scheduled systems in order every frame.
the Nexus is the brain of the ECS world. It is the object the user will use to interact with everythi...
Definition Nexus.hpp:84
Broadcaster acts as ImagoEngine's event system. It lets systems communicate without knowing about eac...
Definition Broadcaster.hpp:70
virtual void on_load()=0
Called by load(). Behavior is defined in user definitions of Scenes were the user can create entities...
Scene(const SceneContext &gameCtx)
Construct a new Scene object and copies the game's persistent context and fills the remaining pointer...
Definition Scene.cpp:5
ECS::Nexus _nexus
scene's Nexus
Definition Scene.hpp:42
void update(float dt)
Runs one frame by ticking the scheduler, then flushes the Nexus.
Definition Scene.cpp:25
SystemScheduler _scheduler
runs this scene's scheduled systems
Definition Scene.hpp:45
void unload()
Unloads the scene. Runs the user-defined on_unload() method then flushes everything.
Definition Scene.cpp:18
Broadcaster _broadcaster
scene's event bus
Definition Scene.hpp:44
virtual void on_unload()
Called by unload(). This is optional in user definitions of Scenes because most clean-up is handled a...
Definition Scene.hpp:39
void load()
Loads the scene. Runs the user-defined on_load() method then flushes everything so they actually go t...
Definition Scene.cpp:12
SceneContext _ctx
scene's own copy of the context passed into every system
Definition Scene.hpp:43
Definition SystemScheduler.hpp:22
Gives systems access to the persistent engine objects they could need.
Definition SceneContext.hpp:30