mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-11-28 13:53:45 +01:00
walkover optimisation part1
This commit is contained in:
parent
c1da231f9d
commit
71bb18cd76
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user