saltysystems / overworld

Open source framework for scalable multiplayer games.
Mozilla Public License 2.0
20 stars 3 forks source link

Refactor zone replies for simple use case and alignment with `gen_server` #40

Closed cmdrk closed 1 month ago

cmdrk commented 1 month ago

Zones currently accept 3 types of replies in a handler:

I propose a 4th, simpler type: reply. Send messages back to the caller.

Right now both (ENet, WebSocket) support this, but it's languishing. in ow_zone for the most part, we just reply with ok.

The second thing to do is reformat the return values from these handlers. Today, the value returned from the callback functions looks like this:

handle_foo(Msg, FromID, State) -> 
  % Your code here
  %
  Reply = {'@', [ID1, ID2,...]}, ReplyMsg},
  % OR
  Reply = {broadcast, ReplyMsg},
  % OR
  Reply = noreply,
  % Then finally:
  {Reply, State}.

Let's make it more like gen_server by instead implementing the simple reply type and also adding the @ and broadcast message types, such that:

handle_foo(Msg, FromID, State) -> 
  % Your code here
  %
  {reply, Msg1, State}.
  % OR
  {broadcast, Msg1, State}.
  % OR
  {{at,  [ID1, ID2,...]}, Msg1, State}.

It occurs to me that at is shorter than '@', since @ isn't an atom by itself! 🤦