Skip to content

Commit 68cd4f4

Browse files
committed
Spread out kill list operations across server steps
1 parent b4a4a6e commit 68cd4f4

File tree

1 file changed

+20
-4
lines changed
  • mods/ctf/ctf_combat/ctf_kill_list

1 file changed

+20
-4
lines changed

mods/ctf/ctf_combat/ctf_kill_list/init.lua

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ local KILLSTAT_REMOVAL_TIME = 30
66

77
local MAX_NAME_LENGTH = 19
88
local HUD_LINES = 6
9+
local HUD_UPDATE_INTERVAL = 2
910
local HUD_LINE_HEIGHT = 36
1011
local HUDNAME_FORMAT = "kill_list:%d,%d"
1112

@@ -79,9 +80,19 @@ local function update_hud_line(player, idx, new)
7980
end
8081
end
8182

83+
local hudupdate_queue = {}
8284
local function update_kill_list_hud(player)
83-
for i=1, HUD_LINES, 1 do
84-
update_hud_line(player, i, kill_list[i])
85+
local name = player:get_player_name()
86+
87+
if not hudupdate_queue[name] then
88+
hudupdate_queue[name] = minetest.after(HUD_UPDATE_INTERVAL, function()
89+
if minetest.get_player_by_name(name) then
90+
for i=1, HUD_LINES, 1 do
91+
update_hud_line(player, i, kill_list[i])
92+
end
93+
end
94+
hudupdate_queue[name] = nil
95+
end)
8596
end
8697
end
8798

@@ -108,14 +119,19 @@ minetest.register_globalstep(function(dtime)
108119

109120
table.remove(kill_list)
110121

111-
for _, p in pairs(minetest.get_connected_players()) do
112-
update_kill_list_hud(p)
122+
for i, p in pairs(minetest.get_connected_players()) do
123+
minetest.after(i/40, update_kill_list_hud, p) -- spread out update across server steps
113124
end
114125
end
115126
end)
116127

117128
ctf_api.register_on_match_end(function()
118129
kill_list = {}
130+
131+
for _, job in pairs(hudupdate_queue) do
132+
job:cancel()
133+
end
134+
119135
hud:clear_all()
120136
end)
121137

0 commit comments

Comments
 (0)