mirror of
https://github.com/appgurueu/modlib.git
synced 2024-08-20 05:14:10 +02:00
Improve globalstep timing
This commit is contained in:
parent
aafba83c26
commit
8b0176341b
@ -12,17 +12,38 @@ function override(function_name, function_builder)
|
|||||||
minetest[function_name] = function_builder(func)
|
minetest[function_name] = function_builder(func)
|
||||||
end
|
end
|
||||||
|
|
||||||
delta_times={}
|
|
||||||
delays={}
|
|
||||||
callbacks={}
|
|
||||||
function register_globalstep(interval, callback)
|
function register_globalstep(interval, callback)
|
||||||
if type(callback) ~= "function" then
|
if type(callback) ~= "function" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
table.insert(delta_times, 0)
|
local time = 0
|
||||||
table.insert(delays, interval)
|
minetest.register_globalstep(function(dtime)
|
||||||
table.insert(callbacks, callback)
|
time = time + dtime
|
||||||
|
if time >= interval then
|
||||||
|
callback(time)
|
||||||
|
-- TODO ensure this breaks nothing
|
||||||
|
time = time % interval
|
||||||
|
end
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
form_listeners = {}
|
||||||
|
|
||||||
|
function register_form_listener(formname, func)
|
||||||
|
local current_listeners = form_listeners[formname] or {}
|
||||||
|
table.insert(current_listeners, func)
|
||||||
|
form_listeners[formname] = current_listeners
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
|
local handlers = form_listeners[formname]
|
||||||
|
if handlers then
|
||||||
|
for _, handler in pairs(handlers) do
|
||||||
|
handler(player, fields)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
function texture_modifier_inventorycube(face_1, face_2, face_3)
|
function texture_modifier_inventorycube(face_1, face_2, face_3)
|
||||||
return "[inventorycube{" .. string.gsub(face_1, "%^", "&")
|
return "[inventorycube{" .. string.gsub(face_1, "%^", "&")
|
||||||
.. "{" .. string.gsub(face_2, "%^", "&")
|
.. "{" .. string.gsub(face_2, "%^", "&")
|
||||||
|
Loading…
Reference in New Issue
Block a user