Move generator code to functions to aid in profiling
This commit is contained in:
parent
01ac9ad685
commit
31b65bac91
|
@ -11,6 +11,43 @@ local function roundN(n, d)
|
|||
return math.floor(n * m + 0.5) / m
|
||||
end
|
||||
|
||||
local function run_generators (p1, p2, blockseed)
|
||||
if nodes > 0 then
|
||||
for _, rec in ipairs(registered_generators) do
|
||||
if rec.nf then
|
||||
rec.nf(p1, p2, blockseed)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function update_data (vm, data, data2)
|
||||
-- Write stuff
|
||||
vm:set_data(data)
|
||||
if param2 > 0 then
|
||||
vm:set_param2_data(data2)
|
||||
end
|
||||
end
|
||||
|
||||
local function post_generator_processing(vm, minp, maxp, deco_used, deco_table, ore_used, ore_table)
|
||||
if deco_table then
|
||||
minetest.generate_decorations(vm,vector.new(minp.x,deco_table.min,minp.z),vector.new(maxp.x,deco_table.max,maxp.z))
|
||||
elseif deco_used then
|
||||
minetest.generate_decorations(vm)
|
||||
end
|
||||
if ore_table then
|
||||
minetest.generate_ores(vm,vector.new(minp.x,ore_table.min,minp.z),vector.new(maxp.x,ore_table.max,maxp.z))
|
||||
elseif ore_used then
|
||||
minetest.generate_ores(vm)
|
||||
end
|
||||
end
|
||||
|
||||
local function post_generator_processing_2(vm, p1, p2, shadow)
|
||||
vm:calc_lighting(p1, p2, shadow)
|
||||
vm:write_to_map()
|
||||
vm:update_liquids()
|
||||
end
|
||||
|
||||
minetest.register_on_generated(function(minp, maxp, blockseed)
|
||||
local t1 = os.clock()
|
||||
local p1, p2 = {x=minp.x, y=minp.y, z=minp.z}, {x=maxp.x, y=maxp.y, z=maxp.z}
|
||||
|
@ -49,34 +86,13 @@ minetest.register_on_generated(function(minp, maxp, blockseed)
|
|||
end
|
||||
|
||||
if lvm_used then
|
||||
-- Write stuff
|
||||
vm:set_data(data)
|
||||
if param2 > 0 then
|
||||
vm:set_param2_data(data2)
|
||||
end
|
||||
if deco_table then
|
||||
minetest.generate_decorations(vm,vector.new(minp.x,deco_table.min,minp.z),vector.new(maxp.x,deco_table.max,maxp.z))
|
||||
elseif deco_used then
|
||||
minetest.generate_decorations(vm)
|
||||
end
|
||||
if ore_table then
|
||||
minetest.generate_ores(vm,vector.new(minp.x,ore_table.min,minp.z),vector.new(maxp.x,ore_table.max,maxp.z))
|
||||
elseif ore_used then
|
||||
minetest.generate_ores(vm)
|
||||
end
|
||||
vm:calc_lighting(p1, p2, shadow)
|
||||
vm:write_to_map()
|
||||
vm:update_liquids()
|
||||
update_data (vm, data, data2)
|
||||
post_generator_processing(vm, minp, maxp, deco_used, deco_table, ore_used, ore_table)
|
||||
post_generator_processing_2(vm, p1, p2, shadow)
|
||||
end
|
||||
end
|
||||
|
||||
if nodes > 0 then
|
||||
for _, rec in ipairs(registered_generators) do
|
||||
if rec.nf then
|
||||
rec.nf(p1, p2, blockseed)
|
||||
end
|
||||
end
|
||||
end
|
||||
run_generators (p1, p2, blockseed)
|
||||
|
||||
mcl_vars.add_chunk(minp)
|
||||
if logging then
|
||||
|
@ -84,6 +100,8 @@ minetest.register_on_generated(function(minp, maxp, blockseed)
|
|||
end
|
||||
end)
|
||||
|
||||
|
||||
|
||||
function minetest.register_on_generated(node_function)
|
||||
mcl_mapgen_core.register_generator("mod_"..minetest.get_current_modname().."_"..tostring(#registered_generators+1), nil, node_function)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue