tiramisu
Tiramisu - A type-safe 3D game engine for Gleam.
This is the main entry point for creating Tiramisu applications. The engine follows the Model-View-Update (MVU) architecture inspired by Elm and Lustre, where your game state is immutable and updates return new state along with effects.
Quick Start
import tiramisu
import tiramisu/effect
import tiramisu/scene
pub fn main() {
tiramisu.application(init, update, view)
|> tiramisu.start("#game", tiramisu.FullScreen, option.None)
}
fn init(ctx) { #(Model(0.0), effect.dispatch(Tick), option.None) }
fn update(model, msg, ctx) { ... }
fn view(model, ctx) -> scene.Node { ... }
Application Types
element- Static scene with no state or updatesapplication- Full MVU with state, effects, and optional physics
Integration
Tiramisu can integrate with Lustre for HTML UI overlays through the bridge system.
See tiramisu/ui for details.
Types
A constructed Tiramisu game application ready to be started.
Create with element for static scenes or application for full MVU.
Then call start to run the game.
pub opaque type App(model, msg)
Game context provided to init, update, and view functions each frame.
Contains timing information, input state, canvas dimensions, physics world, and renderer references needed for game logic and rendering.
pub type Context {
Context(
delta_time: duration.Duration,
input: input.InputState,
canvas_size: vec2.Vec2(Float),
physics_world: option.Option(physics.PhysicsWorld),
scene: savoiardi.Scene,
renderer: savoiardi.Renderer,
)
}
Constructors
-
Context( delta_time: duration.Duration, input: input.InputState, canvas_size: vec2.Vec2(Float), physics_world: option.Option(physics.PhysicsWorld), scene: savoiardi.Scene, renderer: savoiardi.Renderer, )
Values
pub fn application(
init init: fn(Context) -> #(
model,
effect.Effect(msg),
option.Option(physics.PhysicsWorld),
),
update update: fn(model, msg, Context) -> #(
model,
effect.Effect(msg),
option.Option(physics.PhysicsWorld),
),
view view: fn(model, Context) -> scene.Node,
) -> App(model, msg)
Creates a full MVU application with state, effects, and optional physics.
The init function initializes state and returns an initial effect (typically effect.dispatch(Tick)
for a game loop). The update function handles messages and returns new state with effects.
The view function renders the current state as a scene graph.
pub fn element(view: scene.Node) -> App(Nil, msg)
Creates a static scene application with no state or update logic.
Useful for demos, visualizations, or learning the basics before moving to application.
pub fn start(
app: App(model, msg),
selector: String,
dimensions: Dimensions,
bridge: option.Option(
#(ui.Bridge(bridge_msg), fn(bridge_msg) -> msg),
),
) -> Result(Nil, Nil)
Starts a game application, setting up the renderer and game loop.
The selector is a CSS selector for the container element. Use option.None for the
bridge in standalone games, or option.Some(#(bridge, wrapper)) for Lustre integration.