Opt-in scene/state stack — push/pop game scenes without rolling your own state machine. More...
#include <snes/types.h>Go to the source code of this file.
Classes | |
| struct | Scene |
| A single scene's callbacks. More... | |
Macros | |
| #define | SCENE_STACK_MAX 8 |
| Maximum scene stack depth. | |
Functions | |
| u8 | scenePop (void) |
| Pop the top scene. Resumes the scene below. | |
| u8 | scenePush (const Scene *next) |
| Push a scene onto the stack. Suspends the current top. | |
| void | sceneReplace (const Scene *next) |
| Replace the top scene with another, at any depth — the bottom one included. | |
| void | sceneRun (const Scene *initial) |
| Run the scene stack with initial at the bottom. Never returns. | |
Opt-in scene/state stack — push/pop game scenes without rolling your own state machine.
Third "framework opt-in" from PHILOSOPHY.md (alongside gameloop D.1 and the asset bundle convention D.2). This module gives you a tiny stack of Scene callbacks: the topmost scene's update runs every VBlank; pushing a new scene suspends the current one and runs the new scene's init + update; popping restores the suspended scene without re-running its init.
| #define SCENE_STACK_MAX 8 |
Maximum scene stack depth.
scenePush beyond this depth is a silent no-op. 8 is enough for realistic SNES game shapes (title → menu → play → pause → over leaves 3 spare slots).
| u8 scenePop | ( | void | ) |
Pop the top scene. Resumes the scene below.
The popped scene gets no callbacks; the resumed scene's update runs on the next VBlank. The resumed scene's init is NOT re-invoked — it ran once at first push.
Push a scene onto the stack. Suspends the current top.
Does NOT call next->init itself: it records the scene, and sceneRun() calls init (if non-NULL) at the top of the next frame, then update. The caller's currently-executing update finishes its frame first.
| void sceneReplace | ( | const Scene * | next | ) |
Replace the top scene with another, at any depth — the bottom one included.
The scene-swap primitive scenePop(); scenePush(&next); only approximates: that idiom leaks a stack slot per swap when the scene being replaced is the bottom one, until the 8-deep stack silently drops pushes. next->init runs at the top of the next frame, like after a push.
| void sceneRun | ( | const Scene * | initial | ) |
Run the scene stack with initial at the bottom. Never returns.
Pushes initial, calls its init (if non-NULL), and enters the dispatch loop:
| initial | First scene. Must be non-NULL and have a non-NULL update. The pointer is held for the lifetime of the scene's stack residency, so the caller MUST keep the Scene struct alive for at least that long (typically: place it in static const). |