mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-22 07:13:45 +01:00
Remove buggy hacks from get_gametime
This commit is contained in:
parent
fa88e4d201
commit
aafba83c26
5
init.lua
5
init.lua
@ -131,6 +131,11 @@ modlib = setmetatable({
|
|||||||
|
|
||||||
modlib.mod = minetest and dofile(get_resource(modlib.modname, "mod.lua"))
|
modlib.mod = minetest and dofile(get_resource(modlib.modname, "mod.lua"))
|
||||||
|
|
||||||
|
-- HACK force load minetest/gametime.lua to ensure that the globalstep is registered earlier than globalsteps of mods depending on modlib
|
||||||
|
if minetest then
|
||||||
|
dofile(get_resource(modlib.modname, "minetest", "gametime.lua"))
|
||||||
|
end
|
||||||
|
|
||||||
if minetest then
|
if minetest then
|
||||||
local ie = minetest.request_insecure_environment()
|
local ie = minetest.request_insecure_environment()
|
||||||
if ie then
|
if ie then
|
||||||
|
@ -2,6 +2,7 @@ local _ENV = setmetatable({}, {__index = _G})
|
|||||||
local function load(filename)
|
local function load(filename)
|
||||||
assert(loadfile(modlib.mod.get_resource(modlib.modname, "minetest", filename .. ".lua")))(_ENV)
|
assert(loadfile(modlib.mod.get_resource(modlib.modname, "minetest", filename .. ".lua")))(_ENV)
|
||||||
end
|
end
|
||||||
|
-- minetest/gametime.lua is forceloaded in init.lua
|
||||||
load"misc"
|
load"misc"
|
||||||
load"collisionboxes"
|
load"collisionboxes"
|
||||||
load"liquid"
|
load"liquid"
|
||||||
|
16
minetest/gametime.lua
Normal file
16
minetest/gametime.lua
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
local gametime
|
||||||
|
minetest.register_globalstep(function(dtime)
|
||||||
|
if gametime then
|
||||||
|
gametime = gametime + dtime
|
||||||
|
return
|
||||||
|
end
|
||||||
|
gametime = assert(minetest.get_gametime())
|
||||||
|
function modlib.minetest.get_gametime()
|
||||||
|
local imprecise_gametime = minetest.get_gametime()
|
||||||
|
if imprecise_gametime > gametime then
|
||||||
|
minetest.log("warning", "modlib.minetest.get_gametime(): Called after increment and before first globalstep")
|
||||||
|
return imprecise_gametime
|
||||||
|
end
|
||||||
|
return gametime
|
||||||
|
end
|
||||||
|
end)
|
@ -12,37 +12,6 @@ function override(function_name, function_builder)
|
|||||||
minetest[function_name] = function_builder(func)
|
minetest[function_name] = function_builder(func)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO fix modlib.minetest.get_gametime() messing up responsible "mod" determined by engine on crash
|
|
||||||
get_gametime = minetest.get_gametime
|
|
||||||
local get_gametime_initialized
|
|
||||||
local function get_gametime_init(dtime)
|
|
||||||
if get_gametime_initialized then
|
|
||||||
-- if the profiler is being used, the globalstep can't be unregistered
|
|
||||||
return
|
|
||||||
end
|
|
||||||
get_gametime_initialized = true
|
|
||||||
local gametime = minetest.get_gametime()
|
|
||||||
assert(gametime)
|
|
||||||
function modlib.minetest.get_gametime()
|
|
||||||
local imprecise_gametime = minetest.get_gametime()
|
|
||||||
if imprecise_gametime > gametime then
|
|
||||||
minetest.log("warning", "modlib.minetest.get_gametime(): Called after increment and before first globalstep")
|
|
||||||
return imprecise_gametime
|
|
||||||
end
|
|
||||||
return gametime
|
|
||||||
end
|
|
||||||
for index, globalstep in pairs(minetest.registered_globalsteps) do
|
|
||||||
if globalstep == get_gametime_init then
|
|
||||||
-- globalsteps of mods which depend on modlib will execute after this
|
|
||||||
minetest.registered_globalsteps[index] = function(dtime)
|
|
||||||
gametime = gametime + dtime
|
|
||||||
end
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
minetest.register_globalstep(get_gametime_init)
|
|
||||||
|
|
||||||
delta_times={}
|
delta_times={}
|
||||||
delays={}
|
delays={}
|
||||||
callbacks={}
|
callbacks={}
|
||||||
|
Loading…
Reference in New Issue
Block a user