tiramisu
Tiramisu game engine main module - immutable game loop with effect system.
This module provides the core game loop following the Model-View-Update (MVU) architecture, inspired by Lustre. Your game state is immutable, and updates return new state along with effects.
Types
Game context passed to init and update functions.
Contains timing information, input state, canvas dimensions, and physics world for the current frame.
Fields
delta_time: Time elapsed since the last frame in milliseconds (e.g., 16.0 for 60 FPS). Use this for frame-rate independent movement and animations.input: Current input state (keyboard, mouse, touch, gamepad)canvas_width: Current canvas width in pixelscanvas_height: Current canvas height in pixelsphysics_world: Optional physics world handle (if physics is enabled)
pub type Context(id) {
Context(
delta_time: Float,
input: input.InputState,
canvas_width: Float,
canvas_height: Float,
physics_world: option.Option(physics.PhysicsWorld(id)),
)
}
Constructors
-
Context( delta_time: Float, input: input.InputState, canvas_width: Float, canvas_height: Float, physics_world: option.Option(physics.PhysicsWorld(id)), )Arguments
- delta_time
-
Time elapsed since the last frame in milliseconds (e.g., 16 for 60 FPS)
- input
-
Current input state (keyboard, mouse, touch, gamepad)
- canvas_width
-
Current canvas width in pixels
- canvas_height
-
Current canvas height in pixels
- physics_world
-
Physics world handle (if physics is enabled)
Canvas dimensions for the game window.
Used with tiramisu.run() to specify the size of the game canvas.
If not provided (None), the game will run in fullscreen mode.
pub type Dimensions {
Dimensions(width: Float, height: Float)
}
Constructors
-
Dimensions(width: Float, height: Float)
Values
pub fn run(
dimensions dimensions: option.Option(Dimensions),
background background: background.Background,
init init: fn(Context(id)) -> #(
state,
effect.Effect(msg),
option.Option(physics.PhysicsWorld(id)),
),
update update: fn(state, msg, Context(id)) -> #(
state,
effect.Effect(msg),
option.Option(physics.PhysicsWorld(id)),
),
view view: fn(state, Context(id)) -> List(scene.Node(id)),
) -> Nil
Initialize and run the game loop.
This is the main entry point for your game. It sets up the renderer, initializes your game state,
and starts the game loop. The loop will call your update and view functions each frame.
Parameters
dimensions: Canvas dimensions (width and height). UseNonefor fullscreen mode.background: Background as Color, Texture, or CubeTexture (seeBackgroundtype)init: Function to create initial game state and effectupdate: Function to update state based on messagesview: Function to render your game state as scene nodes