 |
Gorgon Game Engine
|
Go to the documentation of this file.
5 #include "ConsumableEvent.h"
49 static constexpr
SceneID NoSceneID = -1;
66 explicit Scene(
SceneID id = NoSceneID,
bool mouseinput =
true) :
id(
id), mouseinput(mouseinput) {
146 void activate_scene();
148 void deactivate_scene();
151 bool mouseinput =
false;
152 bool isactive =
false;
187 if(scene == NoSceneID) {
192 throw std::runtime_error(
"Scene does not exist");
207 active->deactivate_scene();
281 scene.parent =
nullptr;
353 template<
class S_,
class ... P_>
355 auto *s =
new S_(*
this,
id, std::forward<P_>(params)...);
386 inline void Scene::activate_scene() {
390 throw std::runtime_error(
"This scene has no parent");
409 inline void Scene::deactivate_scene() {
410 if(!isactive)
return;
Gorgon::Event< Scene > ActivatedEvent
Fires whenever activation of this layer is completed.
Definition: Scene.h:94
This class represents boundaries of 2D objects.
Definition: Bounds.h:27
Scene(SceneManager &parent, SceneID id=NoSceneID, bool mouseinput=true)
Sets the parent layer so that the scene can be activated.
Definition: Scene.h:73
This class represents a window.
Definition: Window.h:31
Gorgon::Containers::Hashmap< SceneID, Scene > scenes
Definition: Scene.h:379
SceneManager(SceneManager &&)=default
SceneID id
ID of the current scene.
Definition: Scene.h:129
decltype(KeyEvent) ::Token init()
Definition: Scene.h:366
This class provides event mechanism.
Definition: Event.h:134
void Add(Layer &layer)
Adds the given layer as a child.
Definition: Layer.cpp:23
int GetSceneCount() const
Returns the number of scenes registered.
Definition: Scene.h:253
void Step() override
Steps the application by running the active scene, progressing OS events and rendering mechanism.
Definition: Scene.h:243
void ActivateKeyboard()
Moves keyboard input event to the top if there is a layer that accepts keyboard input.
Definition: Scene.h:218
This class is a reference based hashmap.
Definition: Hashmap.h:35
Gorgon::Event< SceneManager, Scene & > ActivatedEvent
This event will be fired whenever a scene is activated.
Definition: Scene.h:363
Window()
Empty constructor creates a non-initialized window.
Definition: Window.h:45
virtual void activate()
Called after very activation.
Definition: Scene.h:108
void NextFrame()
This function marks the end of current frame and starts the next one.
Definition: Main.cpp:115
void Run() override
Runs the application by running the active scene, progressing OS events and rendering mechanism.
Definition: Scene.h:228
void Assume(Scene &scene)
Assumes the ownership of the the given scene, adding it to the list of scenes.
Definition: Scene.h:288
Gorgon::Event< Scene > DeactivatedEvent
Fires whenever deactivation of this layer is completed.
Definition: Scene.h:99
void Quit() override
Quits the scene manager, returning the execution to the point where Run function is called.
Definition: Scene.h:317
auto end()
Returns iterator to the end of scenes.
Definition: Scene.h:304
This class represents a scene in the game like menu screen in game, post game, pause or different gam...
Definition: Scene.h:60
contains Hashmap, a map of references
unsigned long DeltaTime()
Returns the time passed since the last frame.
Definition: Time.h:258
auto begin() const
Returns iterator to the first scene.
Definition: Scene.h:299
This layer allows drawing texture images on.
Definition: Layer.h:169
Defines the abstract class of Runner.
Definition: Main.h:21
SceneManager & operator=(SceneManager &&)=default
auto end() const
Returns iterator to the end of scenes.
Definition: Scene.h:309
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
S_ & NewScene(SceneID id, P_ &&... params)
Creates a new scene using the given type and parameters.
Definition: Scene.h:354
Gorgon::Input::Layer mouse
Mouse layer that can be used to receive mouse events.
Definition: Scene.h:138
virtual Layer & GetParent() const
Returns the parent of this layer.
Definition: Layer.h:226
This class is a Window that manages scenes, allowing swapping, handling input and game loop.
Definition: Scene.h:163
Scene & Release(SceneID id)
Releases the ownership of the scene with the given ID, removing it from the manager.
Definition: Scene.h:277
SceneManager()
Definition: Scene.h:167
virtual void first_activation()
Called only for the first time this scene is activated.
Definition: Scene.h:104
int SceneID
Can be used to identify scenes.
Definition: Scene.h:45
virtual void render()=0
This is called after doframe to perform rendering operation.
virtual void Activate() override
Activates the current scene.
Definition: Scene.h:424
Gorgon::Graphics::Layer graphics
Graphics layer that can be drawn on.
Definition: Scene.h:132
This class governs the progress of animations.
Definition: Animation.h:26
void SetBounds(const Geometry::Bounds &bounds)
Sets the boundaries of this layer.
Definition: Layer.h:357
void Remove(Layer &layer)
Removes the given layer.
Definition: Layer.h:203
This class is the base class for all layer types.
Definition: Layer.h:79
virtual void doframe(unsigned int delta)=0
Scene should perform its frame based operations in this function.
bool SceneExists(SceneID id) const
Returns if the given scene exists.
Definition: Scene.h:258
virtual void Activate()
Activates this governor, replacing current one.
Definition: Animation.h:34
decltype(KeyEvent) ::Token inputtoken
Definition: Scene.h:381
Scene & GetScene(SceneID scene)
Returns the requested scene.
Definition: Scene.h:264
bool quiting
Definition: Scene.h:382
contains event distribution mechanism
void SwitchScene(SceneID scene)
Switches the current scene to the scene with the given id.
Definition: Scene.h:181
void setlayerbounds(const Geometry::Bounds &bounds)
Changes the boundaries of the main layer.
Definition: Scene.h:123
void DeleteScene(SceneID scene)
Deletes the given scene, nothing is done if the scene is not found.
Definition: Scene.h:270
contains time related functions and classes
virtual void KeyEvent(Gorgon::Input::Key, float)
Called when the scene receives a key.
Definition: Scene.h:89
static Governor & Default()
Returns the default governor.
Definition: Animation.h:44
Scene * active
Definition: Scene.h:380
Scene(SceneID id=NoSceneID, bool mouseinput=true)
Empty constructor.
Definition: Scene.h:66
virtual bool RequiresKeyInput() const =0
Whether this scene requires keyboard input.
void Deactivate()
Deactivates all scenes.
Definition: Scene.h:205
bool HasParent() const
Returns whether this layer has a parent.
Definition: Layer.h:219
SceneManager * parent
The parent window for the scene.
Definition: Scene.h:142
virtual void deactivate()
Called before deactivation.
Definition: Scene.h:111
ConsumableEvent< Window, Input::Key, float > KeyEvent
Called when a key is pressed or released.
Definition: Window.h:392
~SceneManager()
Definition: Scene.h:174
SceneID GetID() const
Returns the ID of the current scene.
Definition: Scene.h:84
auto begin()
Returns iterator to the first scene.
Definition: Scene.h:294