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 | |
| void | scenePop (void) |
| Pop the top scene. Resumes the scene below. | |
| void | scenePush (const Scene *next) |
| Push a scene onto the stack. Suspends the current top. | |
| 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).
| void 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.
Silently ignored when the stack contains only the bottom scene (i.e. depth 1) — the stack is never empty after sceneRun is called.
| void scenePush | ( | const Scene * | next | ) |
Push a scene onto the stack. Suspends the current top.
Calls next->init if non-NULL. The caller's currently-executing update finishes its frame; the next VBlank dispatches to next.
Silently ignored when the stack is already at SCENE_STACK_MAX.
| 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). |