Cauldron2D.World.Events (Cauldron2D v0.1.3)

Copy Markdown View Source

A world's events, told each tick to processes that are not its players — a recorder, a referee, a bot that reads the game without playing it.

Cauldron2D.World.Events.subscribe(world)
receive do
  {:cauldron_events, world, tick, events} -> ...
end

A subscriber gets one message per tick that had events, with the same list the players get in their frames, until it unsubscribes or exits; world is the world's pid, and subscribe/1 takes a pid or a registered name.

Summary

Functions

Tell world's subscribers the tick's events; nothing is sent for an empty list.

Receive world's events in the calling process.

Stop receiving them.

Functions

broadcast(world, tick, events)

@spec broadcast(pid(), non_neg_integer(), list()) :: :ok

Tell world's subscribers the tick's events; nothing is sent for an empty list.

subscribe(world)

@spec subscribe(GenServer.server()) :: :ok | {:error, :no_such_world}

Receive world's events in the calling process.

unsubscribe(world)

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

Stop receiving them.