Skip to content

scene

This package implements a lightweight scene manager. It streamlines the game loop by mapping directory names to scene enums.

Features:

  • Auto-generated enums: The SceneName enum from the bonsai:generated package is generated automatically based on directories found in source/game/scenes.
  • Lifecycle management: Standardized hooks for init, update, draw and exit.
  • State persistence: Data is passed between procedures via a rawptr to a state array.
  • Simple navigation: Specific change function to handle transitions, changing on the next frame to allow cleanup within the exit function.

change :: proc (sceneName: generated.SceneName)

Queues a transition to a new scene. The actual transition occurs at the start of the next frame.


draw :: proc ()

Calls the draw procedure of the currently active scene.


init :: proc (sceneName: generated.SceneName)

Bootstraps the Scene Manager with the starting scene. Immediately initializes and sets the current scene. Accepts a SceneName enum as an argument.


update :: proc ()

Main update loop for the active scene. Handles the lifecycle of scene transitions automatically.