3dveins: use debugfilter

develop
Kelly Kinkade 2023-07-04 11:01:26 -05:00
parent 9a58672190
commit 02a4b7f63f
1 changed files with 37 additions and 32 deletions

@ -7,15 +7,16 @@
#include "Core.h" #include "Core.h"
#include "Console.h" #include "Console.h"
#include "DataDefs.h"
#include "Debug.h"
#include "Export.h" #include "Export.h"
#include "MiscUtils.h"
#include "PluginManager.h" #include "PluginManager.h"
#include "modules/MapCache.h" #include "modules/MapCache.h"
#include "modules/Random.h" #include "modules/Random.h"
#include "modules/World.h" #include "modules/World.h"
#include "MiscUtils.h"
#include "DataDefs.h"
#include "df/world.h" #include "df/world.h"
#include "df/world_data.h" #include "df/world_data.h"
#include "df/world_region_details.h" #include "df/world_region_details.h"
@ -47,6 +48,10 @@ DFHACK_PLUGIN("3dveins");
REQUIRE_GLOBAL(world); REQUIRE_GLOBAL(world);
REQUIRE_GLOBAL(gametype); REQUIRE_GLOBAL(gametype);
namespace DFHack {
DBG_DECLARE(_3dveins, process, DebugCategory::LINFO);
}
command_result cmd_3dveins(color_ostream &out, std::vector <std::string> & parameters); command_result cmd_3dveins(color_ostream &out, std::vector <std::string> & parameters);
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
@ -431,11 +436,13 @@ struct GeoLayer
void print_mineral_stats(color_ostream &out) void print_mineral_stats(color_ostream &out)
{ {
for (auto it = mineral_count.begin(); it != mineral_count.end(); ++it) for (auto it = mineral_count.begin(); it != mineral_count.end(); ++it)
out << " " << MaterialInfo(0,it->first.first).getToken() INFO(process, out).print("3dveins: %s %s: %d (%f)\n",
<< " " << ENUM_KEY_STR(inclusion_type,it->first.second) MaterialInfo(0, it->first.first).getToken(),
<< ": \t\t" << it->second << " (" << (float(it->second)/unmined_tiles) << ")" << std::endl; ENUM_KEY_STR(inclusion_type, it->first.second),
it->second,
(float(it->second) / unmined_tiles));
out.print(" Total tiles: %d (%d unmined)\n", tiles, unmined_tiles); INFO(process, out).print ("3dveins: Total tiles: %d (%d unmined)\n", tiles, unmined_tiles);
} }
bool form_veins(color_ostream &out); bool form_veins(color_ostream &out);
@ -467,12 +474,12 @@ struct GeoBiome
void print_mineral_stats(color_ostream &out) void print_mineral_stats(color_ostream &out)
{ {
out.print("Geological biome %d:\n", info.geo_index); INFO(process,out).print("3dveins: Geological biome %d:\n", info.geo_index);
for (size_t i = 0; i < layers.size(); i++) for (size_t i = 0; i < layers.size(); i++)
if (layers[i]) if (layers[i])
{ {
out << " Layer " << i << std::endl; INFO(process, out).print("3dveins: Layer %d\n", i);
layers[i]->print_mineral_stats(out); layers[i]->print_mineral_stats(out);
} }
} }
@ -586,7 +593,7 @@ bool VeinGenerator::init_biomes()
if (info.geo_index < 0 || !info.geobiome) if (info.geo_index < 0 || !info.geobiome)
{ {
out.printerr("Biome %zd is not defined.\n", i); ERR(process, out).print("Biome %zd is not defined.\n", i);
return false; return false;
} }
@ -797,8 +804,7 @@ bool VeinGenerator::scan_layer_depth(Block *b, df::coord2d column, int z)
{ {
if (z != min_level[idx]-1 && min_level[idx] <= top_solid) if (z != min_level[idx]-1 && min_level[idx] <= top_solid)
{ {
out.printerr( ERR(process, out).print("Discontinuous layer %d at (%d,%d,%d).\n",
"Discontinuous layer %d at (%d,%d,%d).\n",
layer->index, x+column.x*16, y+column.y*16, z layer->index, x+column.x*16, y+column.y*16, z
); );
return false; return false;
@ -848,7 +854,7 @@ bool VeinGenerator::adjust_layer_depth(df::coord2d column)
if (max_level[i+1] != min_level[i]-1) if (max_level[i+1] != min_level[i]-1)
{ {
out.printerr( ERR(process, out).print(
"Gap or overlap with next layer %d at (%d,%d,%d-%d).\n", "Gap or overlap with next layer %d at (%d,%d,%d-%d).\n",
i+1, x+column.x*16, y+column.y*16, max_level[i+1], min_level[i] i+1, x+column.x*16, y+column.y*16, max_level[i+1], min_level[i]
); );
@ -891,7 +897,7 @@ bool VeinGenerator::adjust_layer_depth(df::coord2d column)
} }
} }
out.printerr( ERR(process, out).print(
"Layer height change in layer %d at (%d,%d,%d): %d instead of %d.\n", "Layer height change in layer %d at (%d,%d,%d): %d instead of %d.\n",
i, x+column.x*16, y+column.y*16, max_level[i], i, x+column.x*16, y+column.y*16, max_level[i],
size, biome->layers[i]->thickness size, biome->layers[i]->thickness
@ -933,7 +939,7 @@ bool VeinGenerator::scan_block_tiles(Block *b, df::coord2d column, int z)
if (unsigned(key.first) >= materials.size() || if (unsigned(key.first) >= materials.size() ||
unsigned(key.second) >= NUM_INCLUSIONS) unsigned(key.second) >= NUM_INCLUSIONS)
{ {
out.printerr("Invalid vein code: %d %d - aborting.\n",key.first,key.second); ERR(process, out).print("Invalid vein code: %d %d - aborting.\n",key.first,key.second);
return false; return false;
} }
@ -942,7 +948,7 @@ bool VeinGenerator::scan_block_tiles(Block *b, df::coord2d column, int z)
if (status == -1) if (status == -1)
{ {
// Report first occurence of unreasonable vein spec // Report first occurence of unreasonable vein spec
out.printerr( WARN(process, out).print(
"Unexpected vein %s %s - ", "Unexpected vein %s %s - ",
MaterialInfo(0,key.first).getToken().c_str(), MaterialInfo(0,key.first).getToken().c_str(),
ENUM_KEY_STR(inclusion_type, key.second).c_str() ENUM_KEY_STR(inclusion_type, key.second).c_str()
@ -950,9 +956,9 @@ bool VeinGenerator::scan_block_tiles(Block *b, df::coord2d column, int z)
status = materials[key.first].default_type; status = materials[key.first].default_type;
if (status < 0) if (status < 0)
out.printerr("will be left in place.\n"); WARN(process, out).print("will be left in place.\n");
else else
out.printerr( WARN(process, out).print(
"correcting to %s.\n", "correcting to %s.\n",
ENUM_KEY_STR(inclusion_type, df::inclusion_type(status)).c_str() ENUM_KEY_STR(inclusion_type, df::inclusion_type(status)).c_str()
); );
@ -1091,7 +1097,7 @@ void VeinGenerator::write_block_tiles(Block *b, df::coord2d column, int z)
if (!ok) if (!ok)
{ {
out.printerr( ERR(process, out).print(
"Couldn't write %d vein at (%d,%d,%d)\n", "Couldn't write %d vein at (%d,%d,%d)\n",
mat, x+column.x*16, y+column.y*16, z mat, x+column.x*16, y+column.y*16, z
); );
@ -1282,7 +1288,7 @@ bool GeoLayer::form_veins(color_ostream &out)
if (parent_id >= (int)refs.size()) if (parent_id >= (int)refs.size())
{ {
out.printerr("Forward vein reference in biome %d.\n", biome->info.geo_index); ERR(process, out).print("Forward vein reference in biome %d.\n", biome->info.geo_index);
return false; return false;
} }
@ -1302,7 +1308,7 @@ bool GeoLayer::form_veins(color_ostream &out)
if (vptr->parent) if (vptr->parent)
ctx = "only be in "+MaterialInfo(0,vptr->parent_mat()).getToken(); ctx = "only be in "+MaterialInfo(0,vptr->parent_mat()).getToken();
out.printerr( WARN(process, out).print(
"Duplicate vein %s %s in biome %d layer %d - will %s.\n", "Duplicate vein %s %s in biome %d layer %d - will %s.\n",
MaterialInfo(0,key.first).getToken().c_str(), MaterialInfo(0,key.first).getToken().c_str(),
ENUM_KEY_STR(inclusion_type, key.second).c_str(), ENUM_KEY_STR(inclusion_type, key.second).c_str(),
@ -1358,7 +1364,7 @@ bool VeinGenerator::place_orphan(t_veinkey key, int size, GeoLayer *from)
if (best.empty()) if (best.empty())
{ {
out.printerr( ERR(process,out).print(
"Could not place orphaned vein %s %s anywhere.\n", "Could not place orphaned vein %s %s anywhere.\n",
MaterialInfo(0,key.first).getToken().c_str(), MaterialInfo(0,key.first).getToken().c_str(),
ENUM_KEY_STR(inclusion_type, key.second).c_str() ENUM_KEY_STR(inclusion_type, key.second).c_str()
@ -1392,7 +1398,7 @@ bool VeinGenerator::place_orphan(t_veinkey key, int size, GeoLayer *from)
if (size > 0) if (size > 0)
{ {
out.printerr( WARN(process, out).print(
"Could not place all of orphaned vein %s %s: %d left.\n", "Could not place all of orphaned vein %s %s: %d left.\n",
MaterialInfo(0,key.first).getToken().c_str(), MaterialInfo(0,key.first).getToken().c_str(),
ENUM_KEY_STR(inclusion_type, key.second).c_str(), ENUM_KEY_STR(inclusion_type, key.second).c_str(),
@ -1542,7 +1548,7 @@ bool VeinGenerator::place_veins(bool verbose)
if (!isStoneInorganic(key.first)) if (!isStoneInorganic(key.first))
{ {
out.printerr( ERR(process, out).print(
"Invalid vein material: %s\n", "Invalid vein material: %s\n",
MaterialInfo(0, key.first).getToken().c_str() MaterialInfo(0, key.first).getToken().c_str()
); );
@ -1552,7 +1558,7 @@ bool VeinGenerator::place_veins(bool verbose)
if (!is_valid_enum_item(key.second)) if (!is_valid_enum_item(key.second))
{ {
out.printerr("Invalid vein type: %d\n", key.second); ERR(process, out).print("Invalid vein type: %d\n", key.second);
return false; return false;
} }
@ -1565,13 +1571,13 @@ bool VeinGenerator::place_veins(bool verbose)
sort(queue.begin(), queue.end(), vein_cmp); sort(queue.begin(), queue.end(), vein_cmp);
// Place tiles // Place tiles
out.print("Processing... (%zu)", queue.size()); TRACE(process,out).print("Processing... (%zu)", queue.size());
for (size_t j = 0; j < queue.size(); j++) for (size_t j = 0; j < queue.size(); j++)
{ {
if (queue[j]->parent && !queue[j]->parent->placed) if (queue[j]->parent && !queue[j]->parent->placed)
{ {
out.printerr( ERR(process, out).print(
"\nParent vein not placed for %s %s.\n", "\nParent vein not placed for %s %s.\n",
MaterialInfo(0,queue[j]->vein.first).getToken().c_str(), MaterialInfo(0,queue[j]->vein.first).getToken().c_str(),
ENUM_KEY_STR(inclusion_type, queue[j]->vein.second).c_str() ENUM_KEY_STR(inclusion_type, queue[j]->vein.second).c_str()
@ -1583,9 +1589,9 @@ bool VeinGenerator::place_veins(bool verbose)
if (verbose) if (verbose)
{ {
if (j > 0) if (j > 0)
out.print("done."); TRACE(process, out).print("done.");
out.print( TRACE(process, out).print(
"\nVein layer %zu of %zu: %s %s (%.2f%%)... ", "\nVein layer %zu of %zu: %s %s (%.2f%%)... ",
j+1, queue.size(), j+1, queue.size(),
MaterialInfo(0,queue[j]->vein.first).getToken().c_str(), MaterialInfo(0,queue[j]->vein.first).getToken().c_str(),
@ -1595,14 +1601,13 @@ bool VeinGenerator::place_veins(bool verbose)
} }
else else
{ {
out.print("\rVein layer %zu of %zu... ", j+1, queue.size()); TRACE(process, out).print("\rVein layer %zu of %zu... ", j+1, queue.size());
out.flush();
} }
queue[j]->place_tiles(); queue[j]->place_tiles();
} }
out.print("done.\n"); TRACE(process, out).print("done.\n");
return true; return true;
} }