package miaou-core

  1. Overview
  2. Docs
Miaou core/widgets (no drivers, no SDL)

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.5.2.tar.gz
md5=60a3b9f181f24572a06a9492532bfdda
sha512=fcc35a275066be2900e6201782faf47503076fa4640f08cf78067835a6f447b74613009e55b2ac799adb7ca46f1bffa261fc5971753f2cc3c6bef327511c7ef6

doc/miaou-core.interfaces/Miaou_interfaces/Clock/index.html

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.