From f02a668c22e4795c8834409ea10cbc5d55952106 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Brada?= Date: Fri, 3 Apr 2015 15:48:49 +0200 Subject: [PATCH] Better logging system. --- ign.lua | 6 +++--- init.lua | 6 +++++- mapgen.lua | 14 +++++++++----- sed.lua | 6 +++--- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/ign.lua b/ign.lua index 0476382..c83f71a 100644 --- a/ign.lua +++ b/ign.lua @@ -60,10 +60,10 @@ minetest.register_on_generated(function(minp, maxp, seed) end) minetest.register_on_shutdown(function() - if (ign.stats.count==0) then print("[rocks](ign) stats not available, no chunks generated") return end - 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)") + 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 - print("[rocks](ign) "..name..": "..total.." nodes placed ("..(total*100)/(ign.stats.totalnodes).." %)") + rocksl.print("[rocks](ign) "..name..": "..total.." nodes placed ("..(total*100)/(ign.stats.totalnodes).." %)") end end) diff --git a/init.lua b/init.lua index 7523f51..b780a51 100644 --- a/init.lua +++ b/init.lua @@ -1,4 +1,4 @@ -print("[rocks] mod initializing") +minetest.log("info","[rocks] mod initializing") -- Load translation library if intllib is installed @@ -12,6 +12,10 @@ end rocks={} rocksl={} +rocksl.print=function(text) + print("[rocks] "..text) +end + local modpath=minetest.get_modpath(minetest.get_current_modname()) dofile(modpath.."/mapgen.lua") diff --git a/mapgen.lua b/mapgen.lua index 43a0743..a7e1c8e 100644 --- a/mapgen.lua +++ b/mapgen.lua @@ -2,10 +2,14 @@ -- layer generator -- +local print2=function(text) + minetest.log("verbose","rocks/gen/ "..text) +end + rocksl.seedseq=0 rocksl.GetNextSeed=function() rocksl.seedseq=rocksl.seedseq+20 - print("seed "..rocksl.seedseq) + print2("seed "..rocksl.seedseq) return rocksl.seedseq end @@ -56,13 +60,13 @@ rocksl.layergen=function(layer, minp, maxp, seed) end local noise2d_ix = 1 local noise3d_ix = 1 - print("after noise: "..(os.clock()-timebefore)) + print2("after noise: "..(os.clock()-timebefore)) for z=minp.z,maxp.z,1 do for y=minp.y,maxp.y,1 do for x=minp.x,maxp.x,1 do local pos = area:index(x, y, z) if (y>bottom[noise2d_ix]) - and ((nodes[pos]==stone_ctx) or (nodes[pos]==dirt_ctx)) + and (nodes[pos]~=air_ctx) then layer.stats.totalnodes=layer.stats.totalnodes+1 if nodes[pos]==stone_ctx then nodes[pos] = layer.primary.ctx end @@ -81,7 +85,7 @@ rocksl.layergen=function(layer, minp, maxp, seed) end noise2d_ix=noise2d_ix+side_length end - print("after loop: "..(os.clock()-timebefore)) + print2("after loop: "..(os.clock()-timebefore)) manipulator:set_data(nodes) --manipulator:calc_lighting() --manipulator:update_liquids() @@ -89,7 +93,7 @@ rocksl.layergen=function(layer, minp, maxp, seed) manipulator:set_lighting({day=15,night=15}) end manipulator:write_to_map() - print("after commit: "..(os.clock()-timebefore)) + print2("after commit: "..(os.clock()-timebefore)) layer.stats.count=layer.stats.count+1 layer.stats.total=layer.stats.total+(os.clock()-timebefore) layer.stats.side=side_length diff --git a/sed.lua b/sed.lua index bcd7e6e..11e7a7b 100644 --- a/sed.lua +++ b/sed.lua @@ -58,10 +58,10 @@ minetest.register_on_generated(function(minp, maxp, seed) end) minetest.register_on_shutdown(function() - if (sed.stats.count==0) then print("[rocks](sed) stats not available, no chunks generated") return end - 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)") + 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 - print("[rocks](sed) "..name..": "..total.." nodes placed ("..(total*100)/(sed.stats.totalnodes).." %)") + rocksl.print("[rocks](sed) "..name..": "..total.." nodes placed ("..(total*100)/(sed.stats.totalnodes).." %)") end end)