Header menu logo Mibo.Raylib

Program Module

Functions for creating and configuring Elmish game programs.

A program defines the complete architecture of a Mibo game: initialization, update logic, subscriptions, rendering, and service integration.

Example

 Program.mkProgram init update
 |> Program.withSubscription subscribe
 |> Program.withRenderer (fun () -> Renderer2D.create view)
 |> Program.withTick Tick
 |> Program.withAssets
 |> Program.withInput
 |> RaylibGame |> _.Run()

Functions and values

Function or value Description

mkProgram init update

Full Usage: mkProgram init update

Parameters:
    init : GameContext -> 'a * Cmd<'b> - Function that receives GameContext and returns initial (Model, Cmd)
    update : 'b -> 'a -> 'a * Cmd<'b> - Function that receives a message and model, returns (Model, Cmd)

Returns: Program<'a, 'b>

Creates a new program with the given init and update functions.

This is the starting point for building an Elmish game. The init function creates the initial model and startup commands, while update handles messages.

init : GameContext -> 'a * Cmd<'b>

Function that receives GameContext and returns initial (Model, Cmd)

update : 'b -> 'a -> 'a * Cmd<'b>

Function that receives a message and model, returns (Model, Cmd)

Returns: Program<'a, 'b>
Example

 let init ctx = struct (initialModel, Cmd.none)
 let update msg model = struct (model, Cmd.none)
 let program = Program.mkProgram init update
val init: ctx: 'a -> struct ('b * 'c)
val ctx: 'a
val update: msg: 'a -> model: 'b -> struct ('b * 'c)
val msg: 'a
val model: 'b
val program: obj

withAssets program

Full Usage: withAssets program

Parameters:
Returns: Program<'Model, 'Msg>

Ensures the IAssets service is available (always true, included for API parity).

The assets service is automatically created by the runtime. Use Program.withAssetsBasePath to configure a base path.

program : Program<'Model, 'Msg>
Returns: Program<'Model, 'Msg>

withAssetsBasePath basePath program

Full Usage: withAssetsBasePath basePath program

Parameters:
    basePath : string
    program : Program<'Model, 'Msg>

Returns: Program<'Model, 'Msg>

Configures a base path for asset loading.

When set, all relative asset paths are resolved relative to this base path.

basePath : string
program : Program<'Model, 'Msg>
Returns: Program<'Model, 'Msg>
Example

 program |> Program.withAssetsBasePath "assets/"

withConfig configure program

Full Usage: withConfig configure program

Parameters:
Returns: Program<'Model, 'Msg>

Configure game settings (resolution, title, framerate).

The callback receives the current GameConfig and returns a modified copy.

configure : GameConfig -> GameConfig
program : Program<'Model, 'Msg>
Returns: Program<'Model, 'Msg>
Example

 program |> Program.withConfig (fun cfg ->
     { cfg with Width = 1920; Height = 1080; Title = "My Game"; TargetFPS = 60 }
 )

withDispatchMode mode program

Full Usage: withDispatchMode mode program

Parameters:
Returns: Program<'a, 'b>

Configures how the runtime schedules messages dispatched while processing a frame.

Use DispatchMode.Immediate for maximum responsiveness (default), or DispatchMode.FrameBounded to guarantee that messages dispatched during processing are deferred to the next Update call.

mode : DispatchMode
program : Program<'a, 'b>
Returns: Program<'a, 'b>

withFixedStep cfg program

Full Usage: withFixedStep cfg program

Parameters:
Returns: Program<'b, 'a>

Enables a framework-managed fixed timestep simulation.

When enabled, the runtime will dispatch the mapped message zero or more times per Update call to advance simulation in stable increments.

This is complementary to Program.withTick: you can use fixed-step messages for simulation and keep Tick for per-frame tasks (UI, camera smoothing, etc).

cfg : FixedStepConfig<'a>
program : Program<'b, 'a>
Returns: Program<'b, 'a>

withInput program

Full Usage: withInput program

Parameters:
Returns: Program<'Model, 'Msg>

Enables the reactive input polling service.

Registers IInput in the GameContext service container. Required for using Keyboard, Mouse, Touch, and Gamepad subscription modules.

program : Program<'Model, 'Msg>
Returns: Program<'Model, 'Msg>
Example

 program |> Program.withInput

 // Then subscribe to input:
 Keyboard.onPressed KeyPressed ctx
 Mouse.onLeftClick MouseClicked ctx
 Gamepad.listen GamepadInput ctx

withInputMapper initialMap program

Full Usage: withInputMapper initialMap program

Parameters:
Returns: Program<'Model, 'Msg>

Configures the game to register an IInputMapper service.

This registers IInput automatically (equivalent to Program.withInput).

The mapper is ticked each frame via the runtime.

If you want to stay fully "Elmish" (no service access), consider using InputMapper.subscribe instead and handle a single message.

initialMap : InputMap<'Action>
program : Program<'Model, 'Msg>
Returns: Program<'Model, 'Msg>

withRenderer factory program

Full Usage: withRenderer factory program

Parameters:
Returns: Program<'Model, 'Msg>

Adds a renderer to the program.

Renderers are called each frame to draw the current model state. Multiple renderers can be added (e.g., 2D UI on top of 3D scene).

factory : unit -> IRenderer<'Model>
program : Program<'Model, 'Msg>
Returns: Program<'Model, 'Msg>
Example

 program |> Program.withRenderer (fun () -> Renderer2D.create view)

withSubscription subscribe program

Full Usage: withSubscription subscribe program

Parameters:
Returns: Program<'a, 'b>

Adds a subscription function to the program.

The subscription function is called after each model update. It should return subscriptions based on the current model state. The runtime manages subscription lifecycle automatically through SubId diffing.

subscribe : GameContext -> 'a -> Sub<'b>
program : Program<'a, 'b>
Returns: Program<'a, 'b>
Example

 let subscribe ctx model =
     Keyboard.onPressed KeyPressed ctx

 program |> Program.withSubscription subscribe
val subscribe: ctx: 'a -> model: 'b -> 'c
val ctx: 'a
val model: 'b

withTick map program

Full Usage: withTick map program

Parameters:
Returns: Program<'b, 'a>

Adds a per-frame tick message to the program.

The tick function is called once per frame and can dispatch a message containing the GameTime for time-based updates.

map : GameTime -> 'a
program : Program<'b, 'a>
Returns: Program<'b, 'a>
Example

 type Msg = Tick of GameTime | ...
 program |> Program.withTick Tick

Type something to start searching.