Drop non-persistent tracking of generated chunks.
This commit is contained in:
parent
81fc19f0fb
commit
a5df81545a
|
@ -195,48 +195,6 @@ minetest.craftitemdef_default.stack_max = 64
|
|||
-- Set random seed for all other mods (Remember to make sure no other mod calls this function)
|
||||
math.randomseed(os.time())
|
||||
|
||||
local chunks = {} -- intervals of chunks generated
|
||||
|
||||
---@param pos Vector
|
||||
function mcl_vars.add_chunk(pos)
|
||||
local n = mcl_vars.get_chunk_number(pos) -- unsigned int
|
||||
local prev
|
||||
for i, d in pairs(chunks) do
|
||||
if n <= d[2] then -- we've found it
|
||||
if (n == d[2]) or (n >= d[1]) then return end -- already here
|
||||
if n == d[1] - 1 then -- right before:
|
||||
if prev and (prev[2] == n - 1) then
|
||||
prev[2] = d[2]
|
||||
table.remove(chunks, i)
|
||||
return
|
||||
end
|
||||
d[1] = n
|
||||
return
|
||||
end
|
||||
if prev and (prev[2] == n - 1) then --join to previous
|
||||
prev[2] = n
|
||||
return
|
||||
end
|
||||
table.insert(chunks, i, { n, n }) -- insert new interval before i
|
||||
return
|
||||
end
|
||||
prev = d
|
||||
end
|
||||
chunks[#chunks + 1] = { n, n }
|
||||
end
|
||||
|
||||
---@param pos Vector
|
||||
---@return boolean
|
||||
function mcl_vars.is_generated(pos)
|
||||
local n = mcl_vars.get_chunk_number(pos) -- unsigned int
|
||||
for i, d in pairs(chunks) do
|
||||
if n <= d[2] then
|
||||
return (n >= d[1])
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
---"Trivial" (actually NOT) function to just read the node and some stuff to not just return "ignore", like mt 5.4 does.
|
||||
---@param pos Vector Position, if it's wrong, `{name="error"}` node will return.
|
||||
---@param force? boolean Optional (default: `false`), Do the maximum to still read the node within us_timeout.
|
||||
|
@ -253,32 +211,23 @@ function mcl_vars.get_node(pos, force, us_timeout)
|
|||
return node
|
||||
end
|
||||
|
||||
-- copy vector to get sure it won't changed by other threads
|
||||
local pos_copy = vector.copy(pos)
|
||||
|
||||
-- try LVM
|
||||
minetest.get_voxel_manip():read_from_map(pos_copy, pos_copy)
|
||||
node = minetest.get_node(pos_copy)
|
||||
minetest.get_voxel_manip():read_from_map(pos, pos)
|
||||
node = minetest.get_node(pos)
|
||||
if node.name ~= "ignore" or not force then
|
||||
return node
|
||||
end
|
||||
|
||||
-- all ways failed - need to emerge (or forceload if generated)
|
||||
if mcl_vars.is_generated(pos_copy) then
|
||||
minetest.chat_send_all("IMPOSSIBLE! Please report this to MCL2 issue tracker!")
|
||||
minetest.forceload_block(pos_copy)
|
||||
else
|
||||
minetest.emerge_area(pos_copy, pos_copy)
|
||||
end
|
||||
-- try async emerge + BUSY wait (a really BAD idea, you should rather accept failure)
|
||||
minetest.emerge_area(pos, pos) -- runs async!
|
||||
|
||||
local t = minetest.get_us_time()
|
||||
|
||||
node = minetest.get_node(pos_copy)
|
||||
|
||||
node = minetest.get_node(pos)
|
||||
while (not node or node.name == "ignore") and (minetest.get_us_time() - t < (us_timeout or 244)) do
|
||||
node = minetest.get_node(pos_copy)
|
||||
node = minetest.get_node(pos)
|
||||
end
|
||||
|
||||
return node
|
||||
-- it still can return "ignore", LOL, even if force = true, but only after time out
|
||||
end
|
||||
|
||||
|
|
|
@ -90,7 +90,6 @@ minetest.register_on_generated(function(minp, maxp, blockseed)
|
|||
end
|
||||
end
|
||||
|
||||
mcl_vars.add_chunk(minp)
|
||||
if logging then
|
||||
minetest.log("action", string.format("[mcl_mapgen_core] %-20s %s ... %s %8.2fms", "Generating chunk", minetest.pos_to_string(minp), minetest.pos_to_string(maxp), (os.clock() - t1)*1000))
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue