A player's side of a Cauldron2D.World: join, send input, receive frames, leave.
Anything that runs in a process can be a player — a terminal session, a computer player, a test.
:ok = Cauldron2D.Player.join(world, :alice, %{username: "alice"})
Cauldron2D.Player.input(world, :alice, Cauldron2D.Input.state(input))
receive do
{:cauldron_frame, %{tick: tick, view: view, events: events}} -> ...
endFrames arrive once per tick for as long as the player is joined, or as often as the
player asked with join/4's frames: or frames/3, each carrying the events since
the one before. Leaving, or the process exiting, stops them.
Summary
Functions
Change how often the player is sent frames: true, a number a second, or false.
Send what the player is doing now; applied before the next tick.
Join world as id from the calling process; frames: is how often it is sent
frames — true every tick, a number a second, false none, for a player that only
sends input (Cauldron2D.World.join/4). {:error, :taken} when
another process already plays as id.
Leave world.
Functions
@spec frames(GenServer.server(), Cauldron2D.World.player_id(), boolean() | number()) :: :ok
Change how often the player is sent frames: true, a number a second, or false.
@spec input( GenServer.server(), Cauldron2D.World.player_id(), Cauldron2D.Input.state() ) :: :ok
Send what the player is doing now; applied before the next tick.
@spec join(GenServer.server(), Cauldron2D.World.player_id(), map(), keyword()) :: :ok | {:error, term()}
Join world as id from the calling process; frames: is how often it is sent
frames — true every tick, a number a second, false none, for a player that only
sends input (Cauldron2D.World.join/4). {:error, :taken} when
another process already plays as id.
@spec leave(GenServer.server(), Cauldron2D.World.player_id()) :: :ok
Leave world.