forked from minetest-mods/mesecons
Use VoxelManipulators for get_node_force.
A VoxelManipulator, when asked to read a mapblock, in addition to making that mapblock available to the caller, also pulls it into the server’s map cache, thus making get_node calls in the immediate future succeed. This has the dual advantages that not every mapblock containing a Mesecons circuit need remain loaded at all times (rather mapblocks can be loaded on demand as signals are sent), and that the server need not bother running ABMs and ticking entities within those mapblocks that are loaded due to Mesecons signalling.
This commit is contained in:
parent
912f17f335
commit
564cee346a
@ -236,43 +236,25 @@ local function unhash_blockpos(hash)
|
|||||||
return vector.multiply(minetest.get_position_from_hash(hash), BLOCKSIZE)
|
return vector.multiply(minetest.get_position_from_hash(hash), BLOCKSIZE)
|
||||||
end
|
end
|
||||||
|
|
||||||
mesecon.forceloaded_blocks = {}
|
|
||||||
|
|
||||||
-- get node and force-load area
|
-- get node and force-load area
|
||||||
function mesecon.get_node_force(pos)
|
function mesecon.get_node_force(pos)
|
||||||
local hash = hash_blockpos(pos)
|
local node = minetest.get_node_or_nil(pos)
|
||||||
|
if node == nil then
|
||||||
if mesecon.forceloaded_blocks[hash] == nil then
|
-- Node is not currently loaded; use a VoxelManipulator to prime
|
||||||
-- if no more forceload spaces are available, try again next time
|
-- the mapblock cache and try again.
|
||||||
if minetest.forceload_block(pos) then
|
minetest.get_voxel_manip(pos, pos)
|
||||||
mesecon.forceloaded_blocks[hash] = 0
|
node = minetest.get_node_or_nil(pos)
|
||||||
end
|
end
|
||||||
else
|
return node
|
||||||
mesecon.forceloaded_blocks[hash] = 0
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return minetest.get_node_or_nil(pos)
|
-- Un-forceload any forceloaded mapblocks from older versions of Mesecons which
|
||||||
end
|
-- used forceloading instead of VoxelManipulators.
|
||||||
|
local old_forceloaded_blocks = mesecon.file2table("mesecon_forceloaded")
|
||||||
minetest.register_globalstep(function (dtime)
|
for hash, _ in pairs(old_forceloaded_blocks) do
|
||||||
for hash, time in pairs(mesecon.forceloaded_blocks) do
|
|
||||||
-- unload forceloaded blocks after 10 minutes without usage
|
|
||||||
if (time > mesecon.setting("forceload_timeout", 600)) then
|
|
||||||
minetest.forceload_free_block(unhash_blockpos(hash))
|
minetest.forceload_free_block(unhash_blockpos(hash))
|
||||||
mesecon.forceloaded_blocks[hash] = nil
|
|
||||||
else
|
|
||||||
mesecon.forceloaded_blocks[hash] = time + dtime
|
|
||||||
end
|
end
|
||||||
end
|
os.remove(wpath..DIR_DELIM.."mesecon_forceloaded")
|
||||||
end)
|
|
||||||
|
|
||||||
-- Store and read the forceloaded blocks to / from a file
|
|
||||||
-- so that those blocks are remembered when the game
|
|
||||||
-- is restarted
|
|
||||||
mesecon.forceloaded_blocks = mesecon.file2table("mesecon_forceloaded")
|
|
||||||
minetest.register_on_shutdown(function()
|
|
||||||
mesecon.table2file("mesecon_forceloaded", mesecon.forceloaded_blocks)
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Autoconnect Hooks
|
-- Autoconnect Hooks
|
||||||
-- Nodes like conductors may change their appearance and their connection rules
|
-- Nodes like conductors may change their appearance and their connection rules
|
||||||
|
Loading…
Reference in New Issue
Block a user