diff options
author | Christopher Head <chead@chead.ca> | 2016-08-20 21:48:18 -0700 |
---|---|---|
committer | Christopher Head <chead@chead.ca> | 2016-08-24 00:41:47 -0700 |
commit | 564cee346afcf94339472e75995394f0363a5543 (patch) | |
tree | 301c17b1796a00cc50d7e04faa4e8ecc687410a0 | |
parent | 912f17f33590df4ad76775a3511881ad4bbf4853 (diff) | |
download | mesecons-564cee346afcf94339472e75995394f0363a5543.tar mesecons-564cee346afcf94339472e75995394f0363a5543.tar.gz mesecons-564cee346afcf94339472e75995394f0363a5543.tar.bz2 mesecons-564cee346afcf94339472e75995394f0363a5543.tar.xz mesecons-564cee346afcf94339472e75995394f0363a5543.zip |
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.
-rw-r--r-- | mesecons/util.lua | 46 |
1 files changed, 14 insertions, 32 deletions
diff --git a/mesecons/util.lua b/mesecons/util.lua index d95f216..502b269 100644 --- a/mesecons/util.lua +++ b/mesecons/util.lua @@ -236,43 +236,25 @@ local function unhash_blockpos(hash) return vector.multiply(minetest.get_position_from_hash(hash), BLOCKSIZE) end -mesecon.forceloaded_blocks = {} - -- get node and force-load area function mesecon.get_node_force(pos) - local hash = hash_blockpos(pos) - - if mesecon.forceloaded_blocks[hash] == nil then - -- if no more forceload spaces are available, try again next time - if minetest.forceload_block(pos) then - mesecon.forceloaded_blocks[hash] = 0 - end - else - mesecon.forceloaded_blocks[hash] = 0 + local node = minetest.get_node_or_nil(pos) + if node == nil then + -- Node is not currently loaded; use a VoxelManipulator to prime + -- the mapblock cache and try again. + minetest.get_voxel_manip(pos, pos) + node = minetest.get_node_or_nil(pos) end - - return minetest.get_node_or_nil(pos) + return node end -minetest.register_globalstep(function (dtime) - 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)) - mesecon.forceloaded_blocks[hash] = nil - else - mesecon.forceloaded_blocks[hash] = time + dtime - end - end -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) +-- Un-forceload any forceloaded mapblocks from older versions of Mesecons which +-- used forceloading instead of VoxelManipulators. +local old_forceloaded_blocks = mesecon.file2table("mesecon_forceloaded") +for hash, _ in pairs(old_forceloaded_blocks) do + minetest.forceload_free_block(unhash_blockpos(hash)) +end +os.remove(wpath..DIR_DELIM.."mesecon_forceloaded") -- Autoconnect Hooks -- Nodes like conductors may change their appearance and their connection rules |