rmp::Scene
A screen of the game — a main menu, a level, a pause overlay — with its own objects, map and camera. Derive from it and override the hooks you need.
The app keeps scenes on a stack: the top one runs, and the ones below it run, draw and hear input as far as updates_below, draws_below and input_below let them. The static functions — change(), push(), replace(), pop(), current(), depth() — are that stack, and work from anywhere.
What you override
_ready
Once, when the scene enters the stack. The window exists by now, so this is where assets load.
_end
Once, when it leaves for good. Not called for a suspend — see _suspend.
It is _end and not _exit because exit() is a POSIX function, and a member called exit() in a class the user writes is a name that shadows it in a way nobody enjoys debugging.
_suspend, _resume
The scene stops being updated for a while, and later starts again: a scene was pushed on top of it and came off again, or — for the scene on top, under [window] pause_unfocused — the window lost its focus and got it back. The scene is still alive and still owns everything it owned.
_update
Every frame, bottom of the stack upwards, skipping whatever the scene above freezes. delta is seconds since the last frame.
_draw
Every frame, in SCREEN SPACE. The app closes the camera before calling this, so rmp::ui inside it cannot drift with the view — a pause menu stays where it is while the player moves. To draw in world coordinates, open the camera yourself for the few lines that need it.
What this scene lets through to whatever is underneath it
The defaults ARE a pause menu: push a scene with none of these touched and the world below freezes, stays visible, and stops receiving input. That is why a pause scene in this framework writes no policy at all.
updates_below
The scene below keeps running
draws_below
The scene below stays on screen
input_below
The scene below still sees input
background
The colour the frame is cleared with. BLANK means "the theme's", which is what almost every scene wants. Only the LOWEST drawing scene's choice is used: the ones above it are drawn over what is already there.
gravity
The world's gravity, in units per second squared, pointing down the way everyone expects. It belongs to the scene and not to each object because direction and magnitude are a property of the world; each object then says how much of it applies to it, through Object::gravity_scale, which is 0 by default. Nothing falls until something asks to.
map
The level, designed in LDtk or in Tiled (rmp/tilemap.h says which reads what). A field and not something you draw:
map = rmp::assets::load_map("world.ldtk");and the scene draws it underneath everything, stops a solid object that moves at its solid cells, and object.bounds left empty comes to mean THE MAP'S bounds rather than the view's. An empty map costs nothing, and a menu scene simply never touches it.
That is what turns the editor from a file format into the place you design the level: you put the enemies in it and they turn up in the game.
camera
The framing. See rmp::Camera above; a scene that never touches it draws in screen units, exactly as before it existed.
Objects
spawn<T>() default-constructs T, applies the options, puts it in this scene and calls its _ready(). T only has to be default-constructible — there is no using Object::Object; and no forwarding constructor to write, which is the usual toll for this pattern. Whatever your type needs goes in its fields or in its _ready().
It returns T&, and that reference is good for the whole frame you got it in, because destruction is deferred to the end of the frame:
auto &bullet = spawn({ .position = muzzle });
bullet.velocity = aim * 900;Kept across frames it can dangle. That is what rmp::Handle is for.
spawn
destroy
Same as object.destroy(). Deferred: it stops updating and drawing at once, and the memory goes after the frame. Twice is harmless.
object_count
How many live objects this scene has. Objects destroyed earlier in this frame are already not counted.
Raycasting
See the block above RayQuery in rmp/object.h for what it is for and why it walks the collision grid instead of the object list.
if (auto hit = raycast(muzzle, muzzle + aim * 400)) { ... }
auto hit = raycast({ .from = muzzle, .to = target,
.mask = layer::ENEMY, .ignore = self.handle() });raycast
raycast_all
Every hit along the ray, nearest first, as many as out holds. Returns how many were written. Everything the ray passes through, for a piercing shot or a line of sight that has to know what is in the way:
std::array<rmp::RayHit, 8> hits;
const int n = raycast_all({ .from = a, .to = b }, hits);Navigation
change
Clear the stack and go. Everything on it gets _end(), top down.
push
Put one on top. What was there is suspended, not ended.
replace
Swap the top one only. What is underneath is untouched and stays suspended — this is level 3 becoming level 4 without disturbing the pause menu that put you there.
pop
Take the top one off and resume what was under it. Popping the last scene is refused with a warning rather than leaving the app with nothing to draw: on desktop that is a black window, and on iOS there is no way to get back. Call rmp::app::quit() if leaving is what you meant.
current
The top of the stack. Never null while the app is running.
depth
How many scenes are on the stack.