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.
This commit is contained in:
Aaron Suen 2019-11-10 08:10:34 -05:00
parent decbc96c67
commit 07850123d7
8 changed files with 34 additions and 13 deletions

View File

@ -57,6 +57,7 @@ include("util_facedir")
include("util_sound")
include("util_translate")
include("util_ezschematic")
include("util_gametime")
include("match")
include("fx_digparticles")

View File

@ -27,7 +27,7 @@ local function soaking_core(def, reg, getmeta)
end
def.action = function(...)
local now = minetest.get_gametime()
local now = nodecore.gametime
local meta = getmeta(...)
local total = meta:get_float(def.qtyfield) or 0

View File

@ -0,0 +1,22 @@
-- 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)

View File

@ -18,7 +18,7 @@ end
function nodecore.windiness(y)
if y < 0 then return 0 end
if y > 512 then y = 512 end
return math_sqrt(y) * (1 + 0.5 * math_sin(minetest.get_gametime() / 5))
return math_sqrt(y) * (1 + 0.5 * math_sin(nodecore.gametime / 5))
end
function nodecore.stack_sounds(pos, kind, stack)

View File

@ -16,7 +16,7 @@ local function getduration(_, data)
or not md.start
then return 0 end
return minetest.get_gametime() - md.start
return nodecore.gametime - md.start
end
local function playcookfx(pos, cookfx, sound, smokeqty, smoketime)
@ -45,7 +45,7 @@ local function inprogress(pos, data)
md = {
label = recipe.label,
count = count,
start = minetest.get_gametime()
start = nodecore.gametime
}
meta:set_string(modname, minetest.serialize(md))
end

View File

@ -39,7 +39,7 @@ nodecore.register_limited_abm({
nodenames = {modname .. ":torch_lit"},
action = function(pos)
if nodecore.quenched(pos) or
minetest.get_gametime() > minetest.get_meta(pos):get_float("expire") then
nodecore.gametime > minetest.get_meta(pos):get_float("expire") then
minetest.remove_node(pos)
minetest.add_item(pos, {name = "nc_fire:lump_ash"})
minetest.sound_play("nc_fire_snuff", {gain = 1, pos = pos})
@ -52,7 +52,7 @@ nodecore.register_aism({
itemnames = {modname .. ":torch_lit"},
action = function(stack, data)
local expire = stack:get_meta():get_float("expire") or 0
if expire < minetest.get_gametime() then
if expire < nodecore.gametime then
minetest.sound_play("nc_fire_snuff", {gain = 1, pos = data.pos})
return "nc_fire:lump_ash"
end

View File

@ -30,7 +30,7 @@ minetest.register_node(modname .. ":torch", {
on_ignite = function(pos)
minetest.set_node(pos, {name = modname .. ":torch_lit"})
minetest.sound_play("nc_fire_ignite", {gain = 1, pos = pos})
local expire = minetest.get_gametime() + nodecore.boxmuller() * 5 + 60
local expire = nodecore.gametime + nodecore.boxmuller() * 5 + 60
minetest.get_meta(pos):set_float("expire", expire)
return true
end

View File

@ -1,6 +1,6 @@
-- LUALOCALS < ---------------------------------------------------------
local ItemStack, minetest, pairs, setmetatable, vector
= ItemStack, minetest, pairs, setmetatable, vector
local ItemStack, minetest, nodecore, pairs, setmetatable, vector
= ItemStack, minetest, nodecore, pairs, setmetatable, vector
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
@ -21,12 +21,10 @@ local function wieldlight(pos)
return minetest.get_node_timer(pos):start(0.3)
end
local now
local wltimers = {}
local ambtimers = {}
minetest.register_globalstep(function(dt)
now = now or minetest.get_gametime()
now = now + dt
minetest.register_globalstep(function()
local now = nodecore.gametime
for _, player in pairs(minetest.get_connected_players()) do
local inv = player:get_inventory()
local ppos = player:get_pos()