asobi_zone (asobi v0.35.4)

View Source

One spatial partition of an asobi_world_server. A gen_server that owns the entities in its cell of the grid, ticks their simulation, applies player input, manages interest (subscribers), and answers spatial queries via asobi_spatial. Zones are created and reaped lazily as players move.

Summary

Functions

add_entity(Pid, EntityId, EntityState)

-spec add_entity(pid(), binary(), map()) -> ok.

cancel_entity_timer(Pid, EntityId, TimerId)

-spec cancel_entity_timer(pid(), binary(), binary()) -> ok.

despawn_entity(Pid, EntityId)

-spec despawn_entity(pid(), binary()) -> ok.

get_entities(Pid)

-spec get_entities(pid()) -> map().

get_subscriber_count(Pid)

-spec get_subscriber_count(pid()) -> non_neg_integer().

handle_call/3

-spec handle_call(term(), gen_server:from(), map()) -> {reply, term(), map()}.

handle_cast/2

-spec handle_cast(term(), map()) ->
                     {noreply, map()} | {noreply, map(), hibernate} | {stop, normal, map()}.

handle_continue/2

-spec handle_continue(init_zone_state, map()) -> {noreply, map()}.

handle_info/2

-spec handle_info(term(), map()) -> {noreply, map()}.

init(Config)

-spec init(map()) -> {ok, map(), {continue, init_zone_state}}.

player_input(Pid, PlayerId, Input)

-spec player_input(pid(), binary(), map()) -> ok.

query_radius(Pid, Center, Radius)

-spec query_radius(pid(), {number(), number()}, number()) -> [{binary(), {number(), number()}}].

query_rect(Pid, TopLeft, BottomRight)

-spec query_rect(pid(), {number(), number()}, {number(), number()}) ->
                    [{binary(), {number(), number()}}].

reap(Pid)

-spec reap(pid()) -> ok.

remove_entity(Pid, EntityId)

-spec remove_entity(pid(), binary()) -> ok.

spawn_entities(Pid, Spawns)

-spec spawn_entities(pid(), [{binary(), {number(), number()}, map()}]) -> ok.

spawn_entity(Pid, TemplateId, Pos)

-spec spawn_entity(pid(), binary(), {number(), number()}) -> ok.

spawn_entity(Pid, TemplateId, Pos, Overrides)

-spec spawn_entity(pid(), binary(), {number(), number()}, map()) -> ok.

start_entity_timer(Pid, Config)

-spec start_entity_timer(pid(), map()) -> ok.

start_link(Config)

-spec start_link(map()) -> gen_server:start_ret().

subscribe/2

-spec subscribe(pid(), {binary(), pid()}) -> ok.

terminate/2

-spec terminate(term(), map()) -> ok.

tick(Pid, TickN)

-spec tick(pid(), non_neg_integer()) -> ok.

unsubscribe(Pid, PlayerId)

-spec unsubscribe(pid(), binary()) -> ok.