added debug level mechanism to reduce debug and timing information which is of no intrest to players

master
Sokomine 2015-01-05 03:15:53 +01:00
parent 9df7f0c80b
commit 030101e135
8 changed files with 34 additions and 13 deletions

View File

@ -275,7 +275,7 @@ mg_villages.add_building = function( building_data )
if( not( is_used )) then
-- do nothing; skip this file
print('SKIPPING '..tostring( building_data.scm )..' due to village type not supported.');
mg_villages.print(mg_villages.DEBUG_LEVEL_INFO, 'SKIPPING '..tostring( building_data.scm )..' due to village type not supported.');
-- building cannot be used
building_data.not_available = 1;
return false;
@ -292,7 +292,7 @@ mg_villages.add_building = function( building_data )
end
if( not( res )) then
print('SKIPPING '..tostring( building_data.scm )..' due to import failure.');
mg_villages.print(mg_villages.DEBUG_LEVEL_WARNING, 'SKIPPING '..tostring( building_data.scm )..' due to import failure.');
building_data.not_available = 1;
return false;
-- provided the file could be analyzed successfully
@ -347,7 +347,7 @@ mg_villages.add_building = function( building_data )
or building_data.sizex == 0 or building_data.sizez==0) then
-- no village will use it
print('[mg_villages] INFO: No schematic found for building \''..tostring( building_data.scm )..'\'. Will not use that building.');
mg_villages.print( mg_villages.DEBUG_LEVEL_INFO, 'No schematic found for building \''..tostring( building_data.scm )..'\'. Will not use that building.');
building_data.weight = {};
building_data.not_available = 1;
return false;
@ -359,7 +359,7 @@ mg_villages.add_building = function( building_data )
if( not( building_data.weight ) or type( building_data.weight ) ~= 'table' ) then
print('SKIPPING '..tostring( building_data.scm )..' due to missing weight information.');
mg_villages.print( mg_villages.DEBUG_LEVEL_WARNING, 'SKIPPING '..tostring( building_data.scm )..' due to missing weight information.');
building_data.not_available = 1;
return false;
end

View File

@ -31,6 +31,9 @@ mg_villages.ENABLE_PROTECTION = true;
-- the first village - the one the player spawns in - will be of this type
mg_villages.FIRST_VILLAGE_TYPE = 'medieval';
-- choose the debug level you want
mg_villages.DEBUG_LEVEL = mg_villages.DEBUG_LEVEL_NORMAL
-- background image for the /vmap command
-- RealTest comes with a diffrent texture
if( minetest.get_modpath('grounds') and minetest.get_modpath('joiner_table')) then

View File

@ -8,6 +8,20 @@ mg_villages.anz_villages = 0;
mg_villages.modpath = minetest.get_modpath( "mg_villages");
mg_villages.DEBUG_LEVEL_NONE = -1 -- -1: disable all printed messages
mg_villages.DEBUG_LEVEL_NORMAL = 0 -- 0: print information about which village spawned where plus important errors
mg_villages.DEBUG_LEVEL_WARNING = 1 -- 1: warnings/errors which may not be particulary helpful for non-developers
mg_villages.DEBUG_LEVEL_INFO = 2 -- 2: print even less important warnings
mg_villages.DEBUG_LEVEL_TIMING = 3 -- 3: detailled performance information
mg_villages.print = function( level, msg )
if( level <= mg_villages.DEBUG_LEVEL ) then
print( "[mg_villages] "..msg );
end
end
dofile(mg_villages.modpath.."/save_restore.lua")
mg_villages.all_villages = save_restore.restore_data( 'mg_all_villages.data' ); -- read mg_villages.all_villages data saved for this world from previous runs
mg_villages.mg_generated_map = save_restore.restore_data( 'mg_generated_map.data' );

View File

@ -8,7 +8,7 @@ mg_villages.init_weights = function()
table.insert( mg_villages.village_types, k );
end
end
print('[mg_villages] Will create villages of the following types: '..minetest.serialize( mg_villages.village_types ));
mg_villages.print(mg_villages.DEBUG_LEVEL_NORMAL,'Will create villages of the following types: '..minetest.serialize( mg_villages.village_types ));

View File

@ -553,7 +553,7 @@ end
mg_villages.change_village_height = function( village, new_height )
print('CHANGING HEIGHT from '..tostring( village.vh )..' to '..tostring( new_height ));
mg_villages.print( mg_villages.DEBUG_LEVEL_TIMING, 'CHANGING HEIGHT from '..tostring( village.vh )..' to '..tostring( new_height ));
for _, pos in ipairs(village.to_add_data.bpos) do
pos.y = new_height;
end
@ -695,7 +695,7 @@ end
time_elapsed = function( t_last, msg )
mg_villages.t_now = minetest.get_us_time();
print( 'TIME ELAPSED: '..tostring( mg_villages.t_now - t_last )..' '..msg );
mg_villages.print( mg_villages.DEBUG_LEVEL_TIMING, 'TIME ELAPSED: '..tostring( mg_villages.t_now - t_last )..' '..msg );
return mg_villages.t_now;
end
@ -940,7 +940,9 @@ mg_villages.place_villages_via_voxelmanip = function( villages, minp, maxp, vm,
mg_villages.anz_villages = count;
mg_villages.all_villages[ village_id ] = minetest.deserialize( minetest.serialize( village ));
print("Village No. "..tostring( count ).." of type \'"..tostring( village.village_type ).."\' of size "..tostring( village.vs ).." spawned at: x = "..village.vx..", z = "..village.vz)
mg_villages.print( mg_villages.DEBUG_LEVEL_NORMAL, "Village No. "..tostring( count ).." of type \'"..
tostring( village.village_type ).."\' of size "..tostring( village.vs )..
" spawned at: x = "..village.vx..", z = "..village.vz)
village_data_updated = true;
end
end

View File

@ -130,7 +130,7 @@ local function generate_building(pos, minp, maxp, data, param2_data, a, extranod
(( binfo.sizex ~= pos.bsizex and binfo.sizex ~= pos.bsizez )
or ( binfo.sizez ~= pos.bsizex and binfo.sizez ~= pos.bsizez )
or not( binfo.scm_data_cache ))) then
print('ERROR: This village was created using diffrent buildings than those known know. Cannot place unknown building.');
mg_villages.print( mg_villages.DEBUG_LEVEL_WARNING, 'ERROR: This village was created using diffrent buildings than those known know. Cannot place unknown building.');
return;
end
@ -276,7 +276,7 @@ local function generate_building(pos, minp, maxp, data, param2_data, a, extranod
end
-- we tried our best, but the replacement node is not defined
elseif (new_node_name ~= 'mg:ignore' ) then
print('[mg_villages] ERROR: Did not find a suitable replacement for '..tostring( new_node_name )..' (suggested but inexistant: '..tostring( replacements.table[ new_node_name ] )..'). Building: '..tostring( binfo.scm )..'.');
mg_villages.print( mg_villages.DEBUG_LEVEL_WARNING, 'ERROR: Did not find a suitable replacement for '..tostring( new_node_name )..' (suggested but inexistant: '..tostring( replacements.table[ new_node_name ] )..'). Building: '..tostring( binfo.scm )..'.');
new_content = cid.c_air;
end

View File

@ -83,7 +83,7 @@ mg_villages.add_village_type = function( type_name, v )
end
if( not( v.only_single ) and (not(v.min) or not(v.max))) then
print('[mg_villages] Error: Village type '..tostring( type_name )..' lacks size information.');
mg_villages.print( mg_villages.DEBUG_LEVEL_NORMAL, 'Error: Village type '..tostring( type_name )..' lacks size information.');
return false;
end

View File

@ -688,7 +688,7 @@ mg_villages.houses_in_one_mapchunk = function( minp, mapchunk_size, villages, vn
-- (i.e. church, forge, wagon, ..)
local btype, rotation, bsizex, bsizez, mirror = choose_building_rot({}, pr, orient1, 'single');
if( not( bsizex )) then
print('FAILURE to generate a building.');
mg_villages.print( mg_villages.DEBUG_LEVEL_INFO, 'FAILURE to generate a building.');
btype, rotation, bsizex, bsizez, mirror = choose_building_rot({}, pr, orient1, 'lumberjack');
end
-- if no building was found, give up
@ -790,7 +790,9 @@ mg_villages.houses_in_one_mapchunk = function( minp, mapchunk_size, villages, vn
village.to_add_data = {};
village.to_add_data.bpos = { {x=bx, y=village.vh, z=bz, btype=btype, bsizex=bsizex, bsizez=bsizez, brotate = rotation, road_nr = 0, side=1, o=orient1, mirror=mirror }}
print('adding SINGLE HOUSE of type '..tostring( village.village_type )..' to map at '..tostring( village.vx )..':'..tostring( village.vz )..'.'); -- TODO
-- there may be quite a lot of single houses added; plus they are less intresting than entire villages. Thus, logfile spam is reduced
mg_villages.print( mg_villages.DEBUG_LEVEL_WARNING, 'adding SINGLE HOUSE of type '..tostring( village.village_type )..
' to map at '..tostring( village.vx )..':'..tostring( village.vz )..'.');
return village;
end