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 MonoGame component integration.
Example
Program.mkProgram init update
|> Program.withSubscription subscribe
|> Program.withRenderer (Batch2DRenderer.create view)
|> Program.withTick Tick
|> Program.withAssets
|> Program.withInput
|> ElmishGame |> _.Run()
Functions and values
| Function or value |
Description
|
Full Usage:
mkProgram init update
Parameters:
GameContext -> 'Model * Cmd<'Msg>
-
Function that receives GameContext and returns initial (Model, Cmd)
update : 'Msg -> 'Model -> 'Model * Cmd<'Msg>
-
Function that receives a message and model, returns (Model, Cmd)
Returns: Program<'Model, 'Msg>
|
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.
Example
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
|
|
Registers the IAssets service for loading and caching game assets. The assets service provides texture, font, sound, and model loading with automatic caching. It also supports custom asset types and JSON deserialization. Assets are automatically disposed when the game exits.
Example
val texture: obj
val font: obj
|
Full Usage:
withComponent factory program
Parameters:
Game -> IGameComponent
program : Program<'Model, 'Msg>
Returns: Program<'Model, 'Msg>
|
Adds a MonoGame component to the program. Components are added before Initialize is called, so they participate in the normal MonoGame lifecycle (Initialize, LoadContent, Update, Draw).
Example
|
Full Usage:
withComponentRef componentRef factory program
Parameters:
ComponentRef<'T>
factory : Game -> 'T
program : Program<'Model, 'Msg>
Returns: Program<'Model, 'Msg>
|
Adds a component with a reference that can be accessed from update/subscribe. This allows Elmish code to interact with MonoGame components in a type-safe way without relying on global state.
Example
val audioRef: obj
union case ValueOption.ValueSome: 'T -> ValueOption<'T>
val audio: obj
union case ValueOption.ValueNone: ValueOption<'T>
|
Full Usage:
withConfig configure program
Parameters:
Game * GraphicsDeviceManager -> unit
program : Program<'Model, 'Msg>
Returns: Program<'Model, 'Msg>
|
Configure MonoGame game settings (resolution, vsync, window, etc). The callback receives the Game instance and GraphicsDeviceManager for configuration. This is called during the game constructor, before Initialize.
Example
|
Full Usage:
withDispatchMode mode program
Parameters:
DispatchMode
program : Program<'Model, 'Msg>
Returns: Program<'Model, 'Msg>
|
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 MonoGame
|
Full Usage:
withFixedStep cfg program
Parameters:
FixedStepConfig<'Msg>
program : Program<'Model, 'Msg>
Returns: Program<'Model, 'Msg>
|
Enables a framework-managed fixed timestep simulation.
When enabled, the runtime will dispatch the mapped message zero or more times per MonoGame
This is complementary to Program.withTick: you can use fixed-step
messages for simulation and keep
|
|
Registers the input polling component for keyboard, mouse, touch, and gamepad. The input service polls hardware each frame and publishes deltas via IInput. This is required for using the Keyboard, Mouse, Touch, and Gamepad subscription modules. This helper is idempotent - calling it multiple times has no effect.
Example
|
|
Configures the game to register an IInputMapper service.
This registers IInput automatically (equivalent to Program.withInput). The mapper is ticked via a MonoGame GameComponent. If you want to stay fully "Elmish" (no service access), consider using InputMapper.subscribe instead and handle a single message.
|
|
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).
Example
|
Full Usage:
withSubscription subscribe program
Parameters:
GameContext -> 'Model -> Sub<'Msg>
program : Program<'Model, 'Msg>
Returns: Program<'Model, 'Msg>
|
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.
Example
val subscribe: ctx: 'a -> model: 'b -> 'c
val ctx: 'a
val model: 'b
|
|
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.
Example
|
Mibo