From c02b173bf0a30a8b2247bc3f943fc45255b4f2ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Brada?= Date: Thu, 16 Apr 2015 23:03:50 +0200 Subject: [PATCH] Changed api to prepare for mapgen rewrite. --- ign.lua | 21 ++++----------------- mapgen.lua | 34 +++++++++++++++++++++++++++++++--- sed.lua | 15 +++------------ 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/ign.lua b/ign.lua index c81663c..b2b6f1f 100644 --- a/ign.lua +++ b/ign.lua @@ -3,6 +3,7 @@ -- local ign={ + name="ign", top={ offset = -10, scale = 0, spread = {x=80, y=80, z=80}, @@ -17,6 +18,8 @@ local ign={ debugging=nil } +rocks.layer_initialize(ign) + -- Basalt Ex/Mafic hard same as diorite, byt limit=0.5 minetest.register_node( "rocks:basalt", { description = S("Basalt"), @@ -58,10 +61,7 @@ rocks.register_igneous_stratus=reg -- vein stuff ign.veins={} -local regv=function(name,param) - rocksl.register_vein(ign.veins,name,param) -end -rocks.register_vein=regv +local regv=rocks.register_vein rocks.register_vein("default:nyancat",{ wherein={"rocks:granite"}, @@ -76,17 +76,4 @@ rocks.register_vein("default:nyancat",{ }) -minetest.register_on_generated(function(minp, maxp, seed) - rocksl.layergen(ign,minp,maxp,seed) - rocksl.veingen(ign.veins,minp,maxp,seed) -end) - -minetest.register_on_shutdown(function() - if (ign.stats.count==0) then rocksl.print("[rocks](ign) stats not available, no chunks generated") return end - rocksl.print("[rocks](ign) generated total "..ign.stats.count.." chunks in "..ign.stats.total.." seconds ("..(ign.stats.total/ign.stats.count).." seconds per "..ign.stats.side.."^3 chunk)") - for name,total in pairs(ign.stats.node) do - rocksl.print("[rocks](ign) "..name..": "..total.." nodes placed ("..(total*100)/(ign.stats.totalnodes).." %)") - end -end) - -- ~ Tomas Brod \ No newline at end of file diff --git a/mapgen.lua b/mapgen.lua index 0fa4f10..5fb5473 100644 --- a/mapgen.lua +++ b/mapgen.lua @@ -3,7 +3,7 @@ -- local print2=function(text) - minetest.log("verbose","rocks/gen/ "..text) + minetest.log("info","rocks/gen/ "..text) end rocksl.seedseq=0 @@ -13,6 +13,13 @@ rocksl.GetNextSeed=function() return rocksl.seedseq end +local layers={} + +rocks.layer_initialize=function(layer) + layer.stats={ count=0, total=0, node={}, totalnodes=0 } + table.insert(layers,layer) +end + rocksl.register_stratus=function(layer,name,param) table.insert(layer.localized,{ primary=name, @@ -25,7 +32,9 @@ rocksl.register_stratus=function(layer,name,param) layer.stats.node[name]=0 end -rocksl.register_vein=function(col,name,param) +local veins={} + +rocks.register_vein=function(name,param) local d={ primary=name, wherein=param.wherein, @@ -35,7 +44,7 @@ rocksl.register_vein=function(col,name,param) rarity=param.rarity, secondary=(param.ores or {}), } - table.insert(col,d) + table.insert(veins,d) end -- TODO: rewrite above function to register normal minetest ore, with @@ -199,4 +208,23 @@ rocksl.veingen=function(veins,minp,maxp,seed) end end +minetest.register_on_generated(function(minp, maxp, seed) + for _,layer in pairs(layers) do rocksl.layergen(layer,minp,maxp,seed) end + rocksl.veingen(veins,minp,maxp,seed) +end) + +minetest.register_on_shutdown(function() + for _,ign in pairs(layers) do + print("[rocks] Stats for layer "..ign.name) + if (ign.stats.count==0) then + print("[rocks] |- stats not available, no chunks generated") + else + print("[rocks] |- generated total "..ign.stats.count.." chunks in "..ign.stats.total.." seconds ("..(ign.stats.total/ign.stats.count).." seconds per "..ign.stats.side.."^3 chunk)") + for name,total in pairs(ign.stats.node) do + print("[rocks] |- "..name..": "..total.." nodes placed ("..(total*100)/(ign.stats.totalnodes).." %)") + end + end + end +end) + -- ~ Tomas Brod \ No newline at end of file diff --git a/sed.lua b/sed.lua index 354eaae..d65a6af 100644 --- a/sed.lua +++ b/sed.lua @@ -3,6 +3,7 @@ -- local sed={ + name="sed", top={ offset = 20, scale = 0, spread = {x=80, y=80, z=80}, @@ -17,6 +18,8 @@ local sed={ debugging=nil } +rocks.layer_initialize(sed) + -- Mudstone Sed soft Ocean, beach, river, glaciers minetest.register_node( "rocks:mudstone", { description = S("Mudstone"), @@ -53,16 +56,4 @@ rocks.register_sedimentary=reg reg("default:stone_with_coal", { spread=48, height=14, treshold=0.50 }) reg("default:clay",{ spread=48, height=14, treshold=0.50 }) -minetest.register_on_generated(function(minp, maxp, seed) - rocksl.layergen(sed,minp,maxp,seed) -end) - -minetest.register_on_shutdown(function() - if (sed.stats.count==0) then rocksl.print("[rocks](sed) stats not available, no chunks generated") return end - rocksl.print("[rocks](sed) generated total "..sed.stats.count.." chunks in "..sed.stats.total.." seconds ("..(sed.stats.total/sed.stats.count).." seconds per "..sed.stats.side.."^3 chunk)") - for name,total in pairs(sed.stats.node) do - rocksl.print("[rocks](sed) "..name..": "..total.." nodes placed ("..(total*100)/(sed.stats.totalnodes).." %)") - end -end) - -- ~ Tomas Brod \ No newline at end of file