![]() |
ImagoEngine
A C++ 2D game engine built on a sparse-set ECS, with scenes, scheduled systems, events, and action-based input
|
Direct all engine-wide requests: switching scenes and quitting the game.
Use this when you need to switch scenes or quit the game: the player starts a level, opens a pause menu, dies, wins, quits, ect.
Include: Imago/Engine/Scene.hpp
Systems can control the game itself through ctx.engine. It currently has two functions:
Neither one happens immediately. Both are requests that the engine carries out at the end of the current frame, after every system has finished. The rest of the frame runs normally, so it is always safe to call them from anywhere in a system, even in the middle of a loop.
Scenes are switched by name, specifically the name you gave to each scene when you registered it (See Scenes).
By default, the scene you are leaving is removed, its on_unload runs, and all its entities, systems, and subscriptions are destroyed. The next time you switch to it, it starts fresh with on_load.
Pass true as the second argument to keep the scene you are leaving in memory. It stops running but keeps everything exactly as it was. When you switch back to it, it picks up where it left off, and on_load does not run again.
true always refers to the scene that you are leaving, not the one that you are going to:
If you switch to the scene that you are currently in it is removed and started fresh with on_load even if you pass true:
quit() ends the game at the end of the frame. Closing the game window does the same thing. Every scene, including any you kept waiting in memory, gets its on_unload called before the game closes:
| Function | What it does | Takes effect |
|---|---|---|
| ctx.engine->switch_scene(name) | Goes to name and removes the current scene | End of frame |
| ctx.engine->switch_scene(name, true) | Goes to name and keeps the current scene waiting | End of frame |
| ctx.engine->quit() | Ends the game | End of frame |