The Broadcast Algorithm on the erlang server of a browser game is inefficient. It should be a bug. The erlang Server

Source: Internet
Author: User

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.