Cauldron2D.Replay (Cauldron2D v0.1.3)

Copy Markdown View Source

A record of everything that was done to a world, and the means to do it again.

Cauldron2D.World started with record: true builds one; Cauldron2D.World.replay/1 returns it. run/4 rebuilds the game from its options and feeds the record back in, tick by tick, giving the same state the world reached.

replay = Cauldron2D.World.replay(world)
state = Cauldron2D.Replay.run(replay, MyGame, [seed: 7], 1 / 50)

Entries are {tick, action} where action is {:join, id, props}, {:leave, id} or {:input, id, input_state}, and tick is how many steps had run when it happened.

Summary

Functions

The entries oldest first.

An empty record.

Add what happened at tick.

Rebuild game from game_opts and apply the record, stepping by dt each tick.

Note that steps steps have run in total.

Types

action()

@type action() ::
  {:join, term(), map()}
  | {:leave, term()}
  | {:input, term(), Cauldron2D.Input.state()}

t()

@type t() :: %Cauldron2D.Replay{
  entries: [{non_neg_integer(), action()}],
  steps: non_neg_integer()
}

Functions

entries(replay)

@spec entries(t()) :: [{non_neg_integer(), action()}]

The entries oldest first.

new()

@spec new() :: t()

An empty record.

record(replay, tick, action)

@spec record(t(), non_neg_integer(), action()) :: t()

Add what happened at tick.

run(replay, game, game_opts, dt)

@spec run(t(), module(), keyword(), float()) :: term()

Rebuild game from game_opts and apply the record, stepping by dt each tick.

stepped(replay, steps)

@spec stepped(t(), non_neg_integer()) :: t()

Note that steps steps have run in total.