walkover optimisation part1

This commit is contained in:
AFCMS 2021-03-16 11:07:17 +01:00
parent c1da231f9d
commit 71bb18cd76
1 changed files with 25 additions and 7 deletions

View File

@ -1,4 +1,9 @@
-- register extra flavours of a base nodedef
local get_connected_players = minetest.get_connected_players
local get_node = minetest.get_node
local vector_add = vector.add
walkover = {}
walkover.registered_globals = {}
@ -6,24 +11,37 @@ function walkover.register_global(func)
table.insert(walkover.registered_globals, func)
end
local on_walk = {}
local registered_globals = {}
minetest.register_on_mods_loaded(function()
for name,def in pairs(minetest.registered_nodes) do
if def.on_walk_over then
on_walk[name] = def.on_walk_over
end
end
for _,func in ipairs(walkover.registered_globals) do --cache registered globals
table.insert(registered_globals, value)
end
end)
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer + dtime;
if timer >= 0.3 then
for _,player in pairs(minetest.get_connected_players()) do
for _,player in ipairs(get_connected_players()) do
local pp = player:get_pos()
pp.y = math.ceil(pp.y)
local loc = vector.add(pp, {x=0,y=-1,z=0})
local loc = vector_add(pp, {x=0,y=-1,z=0})
if loc ~= nil then
local nodeiamon = minetest.get_node(loc)
local nodeiamon = get_node(loc)
if nodeiamon ~= nil then
local def = minetest.registered_nodes[nodeiamon.name]
if def ~= nil and def.on_walk_over ~= nil then
def.on_walk_over(loc, nodeiamon, player)
if on_walk[nodeiamon.name] then
on_walk[nodeiamon.name](loc, nodeiamon, player)
end
for _, func in ipairs(walkover.registered_globals) do
for _,func in ipairs(registered_globals) do
func(loc, nodeiamon, player)
end
end