package miaou-core

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Miaou_interfaces.ClockSource

Clock capability — provides elapsed time since the last tick.

Drivers register this capability before entering the main loop. The driver updates the internal state at the start of every tick so that pages and widgets can query timing information without calling Unix.gettimeofday themselves.

Usage in pages / widgets:

  let clock = Clock.require () in
  let dt = clock.dt () in
  (* dt is the seconds elapsed since the previous tick *)

Usage in drivers:

  let clock_state = Clock.create_state () in
  Clock.register clock_state ;
  (* At the top of every tick: *)
  Clock.tick clock_state ;
Sourcetype state

Mutable driver-side state. Drivers create one of these, register it, and call tick at the start of every tick iteration.

Sourcetype t = {
  1. dt : unit -> float;
    (*

    Seconds elapsed since the previous tick. Returns 0. on the first tick.

    *)
  2. now : unit -> float;
    (*

    Wall-clock time at the start of the current tick (equivalent to Unix.gettimeofday () but cached — zero-cost to call multiple times within the same tick).

    *)
  3. elapsed : unit -> float;
    (*

    Seconds elapsed since the clock was created (i.e. since the driver started the main loop).

    *)
}

The read-only view exposed to pages and widgets via the capability registry.

Capability access

Sourceval set : t -> unit
Sourceval get : unit -> t option
Sourceval require : unit -> t

Driver-side API

Sourceval create_state : unit -> state

Create a new clock state, recording the current wall-clock time as the origin.

Sourceval register : state -> unit

Register the clock state as a capability so that pages and widgets can access it via get / require.

Sourceval tick : state -> unit

Advance the clock. Call this at the top of every tick iteration. Updates dt, now, and elapsed atomically.