The things in a world that change by themselves each tick — a door closing, a lift waiting, a light flickering, a creature — kept in a fixed order so a world run twice from the same start runs the same.
thinkers = Cauldron2D.Thinkers.new()
{door, thinkers} = Cauldron2D.Thinkers.add(thinkers, %{kind: :door, sector: 12, speed: 2.0})
{thinkers, world} =
Cauldron2D.Thinkers.run(thinkers, world, fn thinker, id, world ->
MyGame.think(thinker, id, world)
end)A thinker is any term, filed under the id add/2 gives it. run/3 calls the function
for each thinker in the order they were added; it answers {:keep, thinker, world} to
carry on or {:done, world} to be removed. A run visits the thinkers that existed when
it began; thinkers to start during a run are added with add/2 to the thinkers it
returns.
Summary
Functions
Add thinker; gives its id and the thinkers.
How many thinkers there are.
Thinker id, or nil.
No thinkers.
Remove thinker id, if it is there.
Run every thinker once, in order. See the moduledoc.
Every thinker with its id, in order.
Replace thinker id with fun.(thinker); nothing if it is not there.
Types
@type id() :: pos_integer()
@type t() :: %Cauldron2D.Thinkers{ entries: :gb_trees.tree(id(), term()), next: pos_integer() }
Functions
Add thinker; gives its id and the thinkers.
@spec count(t()) :: non_neg_integer()
How many thinkers there are.
Thinker id, or nil.
@spec new() :: t()
No thinkers.
Remove thinker id, if it is there.
@spec run(t(), world, (term(), id(), world -> {:keep, term(), world} | {:done, world})) :: {t(), world} when world: term()
Run every thinker once, in order. See the moduledoc.
Every thinker with its id, in order.
Replace thinker id with fun.(thinker); nothing if it is not there.