mirror of
https://gitlab.com/4w/mtimer.git
synced 2025-03-13 12:22:34 +01:00
33 lines
872 B
Lua
33 lines
872 B
Lua
local m = mtimer
|
|
local update_timer = m.update_timer
|
|
local manual_gc = m.config.manual_gc
|
|
local connected_players = minetest.get_connected_players
|
|
local timer = 0
|
|
|
|
|
|
-- The globalstep iterates over all players every second and updates the timers
|
|
-- by invoking the `mtimer.update_timer` function that has ben localized to
|
|
-- `update_timer` for faster access.
|
|
minetest.register_globalstep(function(dtime)
|
|
timer = timer + dtime;
|
|
if timer < 1 then return end
|
|
|
|
for _,player in pairs(connected_players()) do
|
|
update_timer(player:get_player_name())
|
|
end
|
|
|
|
timer = 0
|
|
end)
|
|
|
|
|
|
-- @see https://gitlab.com/4w/mtimer/issues/7
|
|
if manual_gc == true then
|
|
local gc_timer = 0
|
|
minetest.register_globalstep(function(dtime)
|
|
gc_timer = gc_timer + dtime;
|
|
if gc_timer < 10 then return end
|
|
collectgarbage()
|
|
gc_timer = 0
|
|
end)
|
|
end
|