Changeset - r28677:a4506f5caeda
[Not reviewed]
master
0 3 0
Koen Bussemaker - 3 months ago 2024-02-04 14:07:44
koen_bussemaker@hotmail.com
Codechange: Added debug printing for Water Regions
3 files changed with 37 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/misc_gui.cpp
Show inline comments
 
@@ -29,6 +29,7 @@
 
#include "rev.h"
 
#include "timer/timer.h"
 
#include "timer/timer_window.h"
 
#include "pathfinder/water_regions.h"
 

	
 
#include "widgets/misc_widget.h"
 

	
 
@@ -128,6 +129,8 @@ public:
 
		Debug(misc, LANDINFOD_LEVEL, "m6     = 0x{:x}", tile.m6());
 
		Debug(misc, LANDINFOD_LEVEL, "m7     = 0x{:x}", tile.m7());
 
		Debug(misc, LANDINFOD_LEVEL, "m8     = 0x{:x}", tile.m8());
 

	
 
		PrintWaterRegionDebugInfo(tile);
 
#undef LANDINFOD_LEVEL
 
	}
 

	
src/pathfinder/water_regions.cpp
Show inline comments
 
@@ -182,6 +182,33 @@ public:
 
	{
 
		if (!this->initialized) ForceUpdate();
 
	}
 

	
 
	void PrintDebugInfo()
 
	{
 
		Debug(map, 9, "Water region {},{} labels and edge traversability = ...", GetWaterRegionX(tile_area.tile), GetWaterRegionY(tile_area.tile));
 

	
 
		const size_t max_element_width = std::to_string(this->number_of_patches).size();
 

	
 
		std::array<int, 16> traversability_NW{0};
 
		for (auto bitIndex : SetBitIterator(edge_traversability_bits[DIAGDIR_NW])) *(traversability_NW.rbegin() + bitIndex) = 1;
 
		Debug(map, 9, "    {:{}}", fmt::join(traversability_NW, " "), max_element_width);
 
		Debug(map, 9, "  +{:->{}}+", "", WATER_REGION_EDGE_LENGTH * (max_element_width + 1) + 1);
 

	
 
		for (int y = 0; y < WATER_REGION_EDGE_LENGTH; ++y) {
 
			std::string line{};
 
			for (int x = 0; x < WATER_REGION_EDGE_LENGTH; ++x) {
 
				const auto label = this->tile_patch_labels[x + y * WATER_REGION_EDGE_LENGTH];
 
				const std::string label_str = label == INVALID_WATER_REGION_PATCH ? "." : std::to_string(label);
 
				line = fmt::format("{:{}}", label_str, max_element_width) + " " + line;
 
			}
 
			Debug(map, 9, "{} | {}| {}", GB(this->edge_traversability_bits[DIAGDIR_SW], y, 1), line, GB(this->edge_traversability_bits[DIAGDIR_NE], y, 1));
 
		}
 

	
 
		Debug(map, 9, "  +{:->{}}+", "", WATER_REGION_EDGE_LENGTH * (max_element_width + 1) + 1);
 
		std::array<int, 16> traversability_SE{0};
 
		for (auto bitIndex : SetBitIterator(edge_traversability_bits[DIAGDIR_SE])) *(traversability_SE.rbegin() + bitIndex) = 1;
 
		Debug(map, 9, "    {:{}}", fmt::join(traversability_SE, " "), max_element_width);
 
	}
 
};
 

	
 
std::vector<WaterRegion> _water_regions;
 
@@ -372,3 +399,8 @@ void AllocateWaterRegions()
 
		}
 
	}
 
}
 

	
 
void PrintWaterRegionDebugInfo(TileIndex tile)
 
{
 
	GetUpdatedWaterRegion(tile).PrintDebugInfo();
 
}
src/pathfinder/water_regions.h
Show inline comments
 
@@ -64,4 +64,6 @@ void VisitWaterRegionPatchNeighbors(cons
 

	
 
void AllocateWaterRegions();
 

	
 
void PrintWaterRegionDebugInfo(TileIndex tile);
 

	
 
#endif /* WATER_REGIONS_H */
0 comments (0 inline, 0 general)