Cauldron2D.Replay.Viewer (Cauldron2D v0.1.3)

Copy Markdown View Source

Plays a Cauldron2D.Replay back on a clock, sending a watcher the frames one recorded player saw.

{:ok, viewer} = Cauldron2D.Replay.Viewer.start_link(replay: replay, game: MyGame, game_opts: [seed: 7], hz: 50, as: "alice", watcher: self())

The watcher receives {:cauldron_frame, %{tick: n, view: view, events: events}} for every tick after the player :as has joined, exactly as a Cauldron2D.World sends them, and {:cauldron_replay, viewer, :done, state} with the final state when the record runs out; the viewer then stops. pause/1, resume/1 and step/1 drive it.

Options

  • :replay, :game — the record and the game it was made with. Required
  • :game_opts — the game's options, as recorded. Default []
  • :hz — the rate the world ran at, so the dt of a step. Default 50
  • :speed — how many times faster than that to play. Default 1
  • :as — the recorded player whose view is sent. Required
  • :watcher — the process the frames go to. Default the caller
  • :paused? — start paused. Default false

Summary

Functions

Returns a specification to start this module under a supervisor.

Stop the clock.

Start the clock again.

Start a viewer; see the module documentation for the options.

Run one tick while paused.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

pause(viewer)

@spec pause(GenServer.server()) :: :ok

Stop the clock.

resume(viewer)

@spec resume(GenServer.server()) :: :ok

Start the clock again.

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

Start a viewer; see the module documentation for the options.

step(viewer)

@spec step(GenServer.server()) :: :ok

Run one tick while paused.