nodecore-cd2025/mods/nc_api/util_gametime.lua
Aaron Suen 07850123d7 Standardize high-resolution gametime.
Use high-res version in a few places we were using integer-res
timer before.  This should e.g. smooth time variation of wind
strength for ambient sounds.
2019-11-10 08:10:34 -05:00

23 lines
638 B
Lua

-- LUALOCALS < ---------------------------------------------------------
local math, minetest, nodecore
= math, minetest, nodecore
local math_abs
= math.abs
-- LUALOCALS > ---------------------------------------------------------
minetest.register_globalstep(function(dtime)
local mtt = minetest.get_gametime()
local nct = nodecore.gametime
if not nct then
minetest.log("nodecore.gametime: init to " .. mtt)
nct = mtt
end
nct = nct + dtime
if math_abs(nct - mtt) >= 2 then
minetest.log("nodecore.gametime: excess drift; nct="
.. nct .. ", mtt=" .. mtt)
nct = mtt
end
nodecore.gametime = nct
end)