The Broadcast Algorithm on the erlang server of a browser game is inefficient. It should be a bug. The erlang Server
An error occurred while obtaining the erlang webpage server code.
The documentation is very elegant, but I can see that the Broadcast Algorithm in the scenario management is very beautiful, but the efficiency is very low.
Every time a game traverses all the online player's toy IDs in a specific scenario globally, I do not know how many people can support this algorithm, and I want to optimize it. The scenario service management is used by the players in his service, NPC, MON, efficiency will be improved several times, but the code will be a little more complex, no more elegant !!
AllUser = ets: match (? ETS_ONLINE, # ets_online {id = '$ 1', x =' $ 2', y = '$ 3', scene = Q, _ = '_'}), <span style = "color: # ff6666;"> % The code is very inefficient, with more executions </span>
% Get the range user IDget_broadcast_id (Q, X0, Y0) to broadcast-> AllUser = ets: match (? ETS_ONLINE, # ets_online {id = '$ 1', x =' $ 2', y = '$ 3', scene = Q, _ = '_'}), <span style = "color: # ff6666;"> % The code is very inefficient, and the number of executions is large. </span> XY2 = lib_scene: get_xy (X0, Y0), get_broadcast_id_loop (AllUser, XY2, []). get_broadcast_id_loop ([], _ XY2, D)-> D; get_broadcast_id_loop ([[Id, X, Y] | T], XY2, D)-> XY = lib_scene: get_xy (X, Y ), if XY = XY2 orelse XY = XY2 + 1 orelse XY = XY2-1 orelse XY = XY2-8 orelse XY = XY2 + 8 orelse XY = XY2-9 orelse XY = XY2 + 9 orelse XY = XY2-7 orelse XY = XY2 + 7-> get_broadcast_id_loop (T, XY2, D ++ [Id]); true-> get_broadcast_id_loop (T, XY2, D) end.