某頁遊erlang服務端廣播演算法效率好差,應該算是一個bug了吧,erlang服務端

來源:互聯網
上載者:User

某頁遊erlang服務端廣播演算法效率好差,應該算是一個bug了吧,erlang服務端
偶然得到一份erlang網頁服務端的代碼
寫的非常優雅,文檔也非常不錯,但我看到他的情境管理中的廣播演算法,寫的很漂亮,但效率非常低。

每次都全域遍曆全部線上玩家在某個情境的玩具ID,這樣的演算法,我不知道一個服能撐起多少人,最佳化一下,情境服務管理在他服務中的玩家,NPC,MON,效率會提升好幾倍,只是代碼會稍微複雜一點,沒他寫的優雅了!!

  AllUser = ets:match(?ETS_ONLINE, #ets_online{id = '$1',x = '$2', y='$3', scene = Q, _='_'}),<span style="color:#ff6666;"> %% 這句代碼效率會很差的,而去執行的次數又多</span>


%%  擷取要廣播的範圍使用者IDget_broadcast_id(Q, X0, Y0) ->    AllUser = ets:match(?ETS_ONLINE, #ets_online{id = '$1',x = '$2', y='$3', scene = Q, _='_'}),<span style="color:#ff6666;"> %% 這句代碼效率會很差的,而去執行的次數又多</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.


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.