Skip to content

Commit

Permalink
不必使用sort_ipairs_byk 来保证遍历string key的顺序了
Browse files Browse the repository at this point in the history
  • Loading branch information
huahua132 committed Dec 21, 2024
1 parent e278861 commit 5897396
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 27 deletions.
9 changes: 4 additions & 5 deletions lualib/skynet-fly/client/contriner_client.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local skynet = require "skynet"
local module_info = require "skynet-fly.etc.module_info"
local skynet_util = require "skynet-fly.utils.skynet_util"
local table_util = require "skynet-fly.utils.table_util"
local wait = require "skynet-fly.time_extend.wait"
local setmetatable = setmetatable
local assert = assert
Expand Down Expand Up @@ -90,12 +89,12 @@ end

--切换常驻实例的地址引用
local function switch_all_intance()
for _,v in table_util.sort_ipairs_byk(g_instance_map) do
for _,v in pairs(g_instance_map) do
if v.obj then
switch_svr(v.obj)
end

for _,vv in table_util.sort_ipairs_byk(v.name_map) do
for _,vv in pairs(v.name_map) do
switch_svr(vv)
end
end
Expand Down Expand Up @@ -159,7 +158,7 @@ local function monitor_all()
local mod_version_map = nil
while not IS_CLOSE do
mod_version_map = skynet.call(get_contriner_mgr_addr(),'lua', 'monitor_new', SELF_ADDRESS, mod_version_map)
for mod_name,_ in table_util.sort_ipairs_byk(mod_version_map) do
for mod_name,_ in pairs(mod_version_map) do
g_register_map[mod_name] = true
local _ = g_mod_svr_ids_map[mod_name]
end
Expand Down Expand Up @@ -246,7 +245,7 @@ end)
--模块必须全部启动好了才能查询访问其他服务
function M:open_ready()
skynet.fork(function()
for mod_name,_ in table_util.sort_ipairs_byk(g_register_map) do
for mod_name,_ in pairs(g_register_map) do
local _ = g_mod_svr_ids_map[mod_name]
end
end)
Expand Down
5 changes: 2 additions & 3 deletions lualib/skynet-fly/client/frpc_client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ local skynet = require "skynet"
local contriner_client = require "skynet-fly.client.contriner_client"
local FRPC_PACK_ID = require "skynet-fly.enum.FRPC_PACK_ID"
local watch_syn = require "skynet-fly.watch.watch_syn"
local table_util = require "skynet-fly.utils.table_util"
local watch_interface = require "skynet-fly.watch.interface.contriner_watch_interface"
local frpcpack = require "frpcpack.core"
local log = require "skynet-fly.log"
Expand Down Expand Up @@ -34,8 +33,8 @@ local function syn_active_map()
g_watch_client:watch("active")
while g_watch_client:is_watch("active") do
local new_active_map = g_watch_client:await_update("active")
for svr_name, map in table_util.sort_ipairs_byk(new_active_map) do
for svr_id, id in table_util.sort_ipairs_byk(map) do
for svr_name, map in pairs(new_active_map) do
for svr_id, id in pairs(map) do
local old_id = nil
if g_active_map[svr_name] and g_active_map[svr_name][svr_id] then
old_id = g_active_map[svr_name][svr_id]
Expand Down
3 changes: 1 addition & 2 deletions lualib/skynet-fly/logrotate.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local contriner_client = require "skynet-fly.client.contriner_client"
local skynet_util = require "skynet-fly.utils.skynet_util"
local contriner_interface = require "skynet-fly.contriner.contriner_interface"
local table_util = require "skynet-fly.utils.table_util"
local skynet = require "skynet"

local setmetatable = setmetatable
Expand All @@ -22,7 +21,7 @@ contriner_client:register("logrotate_m")

--logrotate的服务更新之后需要重新发送切割任务
contriner_client:add_updated_cb("logrotate_m", function()
for id, obj in table_util.sort_ipairs_byk(g_rotate_map) do
for id, obj in pairs(g_rotate_map) do
obj.is_builder = false
obj:builder()
end
Expand Down
6 changes: 3 additions & 3 deletions lualib/skynet-fly/rpc/watch_client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ local tti = require "skynet-fly.cache.tti"
local timer = require "skynet-fly.timer"
local contriner_interface = require "skynet-fly.contriner.contriner_interface"
local SERVER_STATE_TYPE = require "skynet-fly.enum.SERVER_STATE_TYPE"
local table_util = require "skynet-fly.utils.table_util"
local queue = require "skynet.queue"()

local x_pcall = x_pcall
Expand All @@ -19,6 +18,7 @@ local tpack = table.pack
local tunpack = table.unpack
local tinsert = table.insert
local tremove = table.remove
local pairs = pairs

local M = {}

Expand Down Expand Up @@ -155,14 +155,14 @@ end
local function queue_up_cluster_server(svr_name, svr_id)
local watch_channel_map = g_watch_channel_name_map[svr_name]
if watch_channel_map then
for channel_name in table_util.sort_ipairs_byk(watch_channel_map) do
for channel_name in pairs(watch_channel_map) do
watch_channel_name(svr_name, svr_id, channel_name)
end
end

if g_watch_channel_svr_id_map[svr_name] and g_watch_channel_svr_id_map[svr_name][svr_id] then
local watch_svr_map = g_watch_channel_svr_id_map[svr_name][svr_id]
for channel_name in table_util.sort_ipairs_byk(watch_svr_map) do
for channel_name in pairs(watch_svr_map) do
watch_channel_name(svr_name, svr_id, channel_name)
end
end
Expand Down
6 changes: 3 additions & 3 deletions lualib/skynet-fly/rpc/watch_syn_client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ local skynet_util = require "skynet-fly.utils.skynet_util"
local contriner_interface = require "skynet-fly.contriner.contriner_interface"
local SERVER_STATE_TYPE = require "skynet-fly.enum.SERVER_STATE_TYPE"
local WATCH_SYN_RET = require "skynet-fly.enum.WATCH_SYN_RET"
local table_util = require "skynet-fly.utils.table_util"

local next = next
local assert = assert
Expand All @@ -15,6 +14,7 @@ local tpack = table.pack
local tunpack = table.unpack
local tremove = table.remove
local x_pcall = x_pcall
local pairs = pairs

local M = {}

Expand Down Expand Up @@ -165,14 +165,14 @@ end
local function up_cluster_server(svr_name, svr_id)
local watch_channel_map = g_watch_channel_name_map[svr_name]
if watch_channel_map then
for channel_name in table_util.sort_ipairs_byk(watch_channel_map) do
for channel_name in pairs(watch_channel_map) do
watch_channel_name(svr_name, svr_id, channel_name)
end
end

if g_watch_channel_svr_id_map[svr_name] and g_watch_channel_svr_id_map[svr_name][svr_id] then
local watch_svr_map = g_watch_channel_svr_id_map[svr_name][svr_id]
for channel_name in table_util.sort_ipairs_byk(watch_svr_map) do
for channel_name in pairs(watch_svr_map) do
watch_channel_name(svr_name, svr_id, channel_name)
end
end
Expand Down
3 changes: 1 addition & 2 deletions module/room_game_alloc_m.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ local queue = require "skynet.queue"()
local timer = require "skynet-fly.timer"
local time_util = require "skynet-fly.utils.time_util"
local skynet_util = require "skynet-fly.utils.skynet_util"
local table_util = require "skynet-fly.utils.table_util"

contriner_client:register("room_game_table_m")

Expand Down Expand Up @@ -223,7 +222,7 @@ end

local function check_dismisstable()
local cur_time = time_util.time()
for table_id,empty_time in table_util.sort_ipairs_byk(g_empty_map) do
for table_id,empty_time in pairs(g_empty_map) do
local sub_time = cur_time - empty_time
local t_info = g_table_map[table_id]
if t_info and sub_time >= g_max_empty_time then
Expand Down
4 changes: 2 additions & 2 deletions module/room_game_hall_m.lua
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ function CMD.start(config)
--检查掉线超时,掉线超时还没有重新连接的需要清理
local timer_obj = timer:new(timer.minute,timer.loop,function()
local cur_time = time_util.skynet_int_time()
for player_id,agent in table_util.sort_ipairs_byk(g_player_map) do
for player_id,agent in pairs(g_player_map) do
if g_player_map[player_id] and not interface:is_online(agent.player_id) and cur_time - agent.dis_conn_time > hall_plug.disconn_time_out then
local isok,errorcode,errormsg = interface:goout(agent.player_id, "disconnect time out")
if not isok then
Expand Down Expand Up @@ -826,7 +826,7 @@ end
--安全关服处理
skynet_util.reg_shutdown_func(function()
log.warn("-------------shutdown save begin---------------")
for player_id,agent in table_util.sort_ipairs_byk(g_player_map) do
for player_id,agent in pairs(g_player_map) do
if g_player_map[player_id] then
local isok,errorcode,errormsg = interface:goout(agent.player_id, "shutdown")
if not isok then
Expand Down
12 changes: 6 additions & 6 deletions module/room_game_table_m.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ local function kick_out_all(table_id, reason)
local t_info = g_table_map[table_id]
local player_map = t_info.player_map

for player_id,player in table_util.sort_ipairs_byk(player_map) do
for player_id,player in pairs(player_map) do
if player_map[player_id] then
local isok,err,errmsg = skynet.call(player.hall_server_id,'lua','leave_table',player_id, reason)
if not isok then
Expand Down Expand Up @@ -590,7 +590,7 @@ end

function CMD.check_exit()
local is_check_ok = true
for k,t_info in table_util.sort_ipairs_byk(g_table_map) do
for k,t_info in pairs(g_table_map) do
if g_table_map[k] and t_info.game_table.check_exit then
is_check_ok = t_info.game_table.check_exit()
if not is_check_ok then return false end
Expand All @@ -608,7 +608,7 @@ end

--预告退出
function CMD.herald_exit()
for k,t_info in table_util.sort_ipairs_byk(g_table_map) do
for k,t_info in pairs(g_table_map) do
if g_table_map[k] and t_info.game_table.herald_exit then
t_info.game_table.herald_exit()
end
Expand All @@ -617,7 +617,7 @@ end

--取消退出
function CMD.cancel_exit()
for k,t_info in table_util.sort_ipairs_byk(g_table_map) do
for k,t_info in pairs(g_table_map) do
if g_table_map[k] and t_info.game_table.cancel_exit then
t_info.game_table.cancel_exit()
end
Expand All @@ -627,7 +627,7 @@ end

--确认退出
function CMD.fix_exit()
for k,t_info in table_util.sort_ipairs_byk(g_table_map) do
for k,t_info in pairs(g_table_map) do
if g_table_map[k] and t_info.game_table.fix_exit then
t_info.game_table.fix_exit()
end
Expand All @@ -637,7 +637,7 @@ end
--退出
function CMD.exit()
local is_exit = true
for k,t_info in table_util.sort_ipairs_byk(g_table_map) do
for k,t_info in pairs(g_table_map) do
if g_table_map[k] and t_info.game_table.exit then
is_exit = t_info.game_table.exit()
if not is_exit then return false end
Expand Down
2 changes: 1 addition & 1 deletion service/hot_container.lua
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ local function check_exit()
end
log.info("check_exit:",is_fix_check_exit,g_source_map)
if is_fix_check_exit then
for source,_ in table_util.sort_ipairs_byk(g_source_map) do
for source,_ in pairs(g_source_map) do
--问对方是否还需要访问自己
if skynet.call(source, 'lua', 'is_not_need_visitor', SELF_ADDRESS, MODULE_NAME) then
g_source_map[source] = nil
Expand Down

0 comments on commit 5897396

Please sign in to comment.