mirror of
https://git.minetest.land/Mineclonia/Mineclonia.git
synced 2024-11-24 16:35:10 +00:00
Refactor mcl_mapgen_core and improve mg performace
This commit is contained in:
parent
9a67b90538
commit
b88ae2f1e4
1 changed files with 92 additions and 77 deletions
|
@ -1287,28 +1287,60 @@ minetest.register_on_generated(function(minp, maxp)
|
||||||
local area = VoxelArea:new({MinEdge=emin, MaxEdge=emax})
|
local area = VoxelArea:new({MinEdge=emin, MaxEdge=emax})
|
||||||
local lvm_used = false
|
local lvm_used = false
|
||||||
|
|
||||||
|
local ymin, ymax
|
||||||
|
|
||||||
-- Generate basic layer-based nodes: void, bedrock, realm barrier, lava seas, etc.
|
-- Generate basic layer-based nodes: void, bedrock, realm barrier, lava seas, etc.
|
||||||
-- Also perform some basic node replacements.
|
-- Also perform some basic node replacements.
|
||||||
if maxp.y <= GEN_MAX then
|
|
||||||
for y = minp.y, math.min(maxp.y, GEN_MAX) do
|
-- Helper function to set all nodes in the layers between min and max.
|
||||||
|
-- content_id: Node to set
|
||||||
|
-- check: optional.
|
||||||
|
-- If content_id, node will be set only if it is equal to check.
|
||||||
|
-- If function(pos_to_check, content_id_at_this_pos), will set node only if returns true.
|
||||||
|
-- min, max: Minimum and maximum Y levels of the layers to set
|
||||||
|
-- minp, maxp: minp, maxp of the on_generated
|
||||||
|
-- lvm_used: Set to true if any node in this on_generated has been set before.
|
||||||
|
--
|
||||||
|
-- returns true if any node was set and lvm_used otherwise
|
||||||
|
local function set_layers(content_id, check, min, max, minp, maxp, lvm_used)
|
||||||
|
if (maxp.y >= min and minp.y <= max) then
|
||||||
|
for y = math.max(min, minp.y), math.min(max, maxp.y) do
|
||||||
for x = minp.x, maxp.x do
|
for x = minp.x, maxp.x do
|
||||||
for z = minp.z, maxp.z do
|
for z = minp.z, maxp.z do
|
||||||
local p_pos = area:index(x, y, z)
|
local p_pos = area:index(x, y, z)
|
||||||
|
if check then
|
||||||
-- The void
|
if type(check) == "function" and check({x=x,y=y,z=z}, data[p_pos]) then
|
||||||
if mcl_util.is_in_void({x=x,y=y,z=z}) then
|
data[p_pos] = content_id
|
||||||
data[p_pos] = c_void
|
|
||||||
lvm_used = true
|
lvm_used = true
|
||||||
-- Realm barrier between the Overworld void and the End
|
elseif check == data[p_pos] then
|
||||||
elseif y >= mcl_vars.mg_realm_barrier_overworld_end_min and y <= mcl_vars.mg_realm_barrier_overworld_end_max then
|
data[p_pos] = content_id
|
||||||
data[p_pos] = c_realm_barrier
|
|
||||||
lvm_used = true
|
lvm_used = true
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
data[p_pos] = content_id
|
||||||
|
lvm_used = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return lvm_used
|
||||||
|
end
|
||||||
|
|
||||||
-- Bedrock layer checking (skip in singlenode)
|
-- The Void
|
||||||
local bedrock = false
|
lvm_used = set_layers(c_void, nil, -31000, mcl_vars.mg_nether_min-1, minp, maxp, lvm_used)
|
||||||
if mg_name ~= "singlenode" and mcl_vars.mg_bedrock_is_rough then
|
lvm_used = set_layers(c_void, nil, mcl_vars.mg_nether_max+1, mcl_vars.mg_end_min-1, minp, maxp, lvm_used)
|
||||||
local is_bedrock = function(y)
|
lvm_used = set_layers(c_void, nil, mcl_vars.mg_end_max+1, mcl_vars.mg_realm_barrier_overworld_end_min-1, minp, maxp, lvm_used)
|
||||||
|
lvm_used = set_layers(c_void, nil, mcl_vars.mg_realm_barrier_overworld_end_max+1, mcl_vars.mg_overworld_min-1, minp, maxp, lvm_used)
|
||||||
|
|
||||||
|
-- Realm barrier between the Overworld void and the End
|
||||||
|
lvm_used = set_layers(c_realm_barrier, nil, mcl_vars.mg_realm_barrier_overworld_end_min, mcl_vars.mg_realm_barrier_overworld_end_max, minp, maxp, lvm_used)
|
||||||
|
|
||||||
|
-- Bedrock
|
||||||
|
local bedrock_check
|
||||||
|
if mcl_vars.mg_bedrock_is_rough then
|
||||||
|
bedrock_check = function(pos)
|
||||||
|
local y = pos.y
|
||||||
-- Bedrock layers with increasing levels of roughness, until a perfecly flat bedrock later at the bottom layer
|
-- Bedrock layers with increasing levels of roughness, until a perfecly flat bedrock later at the bottom layer
|
||||||
-- This code assumes a bedrock height of 5 layers.
|
-- This code assumes a bedrock height of 5 layers.
|
||||||
|
|
||||||
|
@ -1339,40 +1371,23 @@ minetest.register_on_generated(function(minp, maxp)
|
||||||
|
|
||||||
return math.random(1, top) <= top-1
|
return math.random(1, top) <= top-1
|
||||||
end
|
end
|
||||||
if is_bedrock(y) then
|
else
|
||||||
bedrock = true
|
bedrock_check = nil
|
||||||
end
|
|
||||||
elseif mg_name ~= "singlenode" then
|
|
||||||
-- Perfectly flat bedrock layer(s)
|
|
||||||
if (y >= mcl_vars.mg_bedrock_overworld_min and y <= mcl_vars.mg_bedrock_overworld_max) or
|
|
||||||
(y >= mcl_vars.mg_bedrock_nether_bottom_min and y <= mcl_vars.mg_bedrock_nether_bottom_max) or
|
|
||||||
(y >= mcl_vars.mg_bedrock_nether_top_min and y <= mcl_vars.mg_bedrock_nether_top_max) then
|
|
||||||
bedrock = true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- No more transformations in singlenode
|
lvm_used = set_layers(c_bedrock, bedrock_check, mcl_vars.mg_bedrock_overworld_min, mcl_vars.mg_bedrock_overworld_max, minp, maxp, lvm_used)
|
||||||
if mg_name == "singlenode" then
|
lvm_used = set_layers(c_bedrock, bedrock_check, mcl_vars.mg_bedrock_nether_bottom_min, mcl_vars.mg_bedrock_nether_bottom_max, minp, maxp, lvm_used)
|
||||||
-- do nothing
|
lvm_used = set_layers(c_bedrock, bedrock_check, mcl_vars.mg_bedrock_nether_top_min, mcl_vars.mg_bedrock_nether_top_max, minp, maxp, lvm_used)
|
||||||
-- Bedrock, defined above
|
|
||||||
elseif bedrock then
|
|
||||||
data[p_pos] = c_bedrock
|
|
||||||
lvm_used = true
|
|
||||||
-- Flat Nether
|
-- Flat Nether
|
||||||
elseif mg_name == "flat" and y >= mcl_vars.mg_bedrock_nether_bottom_max + 4 and y <= mcl_vars.mg_bedrock_nether_bottom_max + 52 then
|
if mg_name == "flat" then
|
||||||
data[p_pos] = c_air
|
lvm_used = set_layers(c_air, nil, mcl_vars.mg_bedrock_nether_bottom_max + 4, mcl_vars.mg_bedrock_nether_bottom_max + 52, minp, maxp, lvm_used)
|
||||||
lvm_used = true
|
end
|
||||||
|
|
||||||
-- Big lava seas by replacing air below a certain height
|
-- Big lava seas by replacing air below a certain height
|
||||||
elseif mcl_vars.mg_lava and data[p_pos] == c_air and y <= mcl_vars.mg_lava_overworld_max and y >= mcl_vars.mg_overworld_min then
|
if mcl_vars.mg_lava then
|
||||||
data[p_pos] = c_lava
|
lvm_used = set_layers(c_lava, c_air, mcl_vars.mg_overworld_min, mcl_vars.mg_lava_overworld_max, minp, maxp, lvm_used)
|
||||||
lvm_used = true
|
lvm_used = set_layers(c_nether_lava, c_air, mcl_vars.mg_nether_min, mcl_vars.mg_lava_nether_max, minp, maxp, lvm_used)
|
||||||
elseif mcl_vars.mg_lava and data[p_pos] == c_air and y <= mcl_vars.mg_lava_nether_max and y >= mcl_vars.mg_nether_min then
|
|
||||||
data[p_pos] = c_nether_lava
|
|
||||||
lvm_used = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
----- Interactive block fixing section -----
|
----- Interactive block fixing section -----
|
||||||
|
|
Loading…
Reference in a new issue