Accidentally get a copy of the code on the Erlang Web page Server
I have to say it is very elegant, the document is very good, but I see his scene management in the broadcast algorithm, have to say that the writing is very beautiful, but very low efficiency.
Each time the global traversal of all online players in a scene of the toy ID, such an algorithm, I do not know how much a service can prop up the number of people, optimization, scene services management in his service players, npc,mon, efficiency will increase several times, but the code will be a little more complex, not his elegant writing!!
Percent gain to broadcast the range of users idget_broadcast_id (Q, X0, Y0), AllUser = Ets:match (? Ets_online, #ets_online {id = ' $ ', x = ' $ ', y= ' $ ', scene = Q, _= ' _ '}), <span style= "color: #ff6666;" > Percent This code efficiency will be very poor, and to execute more times </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.
A page tour Erlang service-side broadcast algorithm is very inefficient, it should be considered a bug.