mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-29 10:43:43 +01:00
Add minetest.override and minetest.get_gametime
This commit is contained in:
parent
934ab6b128
commit
3c91dbdeb8
40
minetest.lua
40
minetest.lua
@ -1,4 +1,42 @@
|
||||
-- MT extension
|
||||
function override(function_name, function_builder)
|
||||
local func = minetest[function_name]
|
||||
minetest["original_" .. function_name] = func
|
||||
minetest[function_name] = function_builder(func)
|
||||
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
|
||||
assert(dtime == 0)
|
||||
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
|
||||
table.remove(minetest.registered_globalsteps, index)
|
||||
break
|
||||
end
|
||||
end
|
||||
-- globalsteps of mods which depend on modlib will execute after this
|
||||
minetest.register_globalstep(function(dtime)
|
||||
gametime = gametime + dtime
|
||||
end)
|
||||
end
|
||||
minetest.register_globalstep(get_gametime_init)
|
||||
|
||||
delta_times={}
|
||||
delays={}
|
||||
callbacks={}
|
||||
|
Loading…
Reference in New Issue
Block a user