From 35c89d57f8dc2ab6f3237301f8deb36665e4f65b Mon Sep 17 00:00:00 2001 From: Koen Bussemaker Date: Sun, 4 Feb 2024 15:07:44 +0100 Subject: [PATCH] Codechange: Added debug printing for Water Regions --- src/misc_gui.cpp | 3 +++ src/pathfinder/water_regions.cpp | 32 ++++++++++++++++++++++++++++++++ src/pathfinder/water_regions.h | 2 ++ 3 files changed, 37 insertions(+) diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 2e9928e793..adea0e237f 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -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 } diff --git a/src/pathfinder/water_regions.cpp b/src/pathfinder/water_regions.cpp index 557b588d42..115213491a 100644 --- a/src/pathfinder/water_regions.cpp +++ b/src/pathfinder/water_regions.cpp @@ -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 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 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 _water_regions; @@ -372,3 +399,8 @@ void AllocateWaterRegions() } } } + +void PrintWaterRegionDebugInfo(TileIndex tile) +{ + GetUpdatedWaterRegion(tile).PrintDebugInfo(); +} diff --git a/src/pathfinder/water_regions.h b/src/pathfinder/water_regions.h index 0ecb94cd8a..88a9df8ef3 100644 --- a/src/pathfinder/water_regions.h +++ b/src/pathfinder/water_regions.h @@ -64,4 +64,6 @@ void VisitWaterRegionPatchNeighbors(const WaterRegionPatchDesc &water_region_pat void AllocateWaterRegions(); +void PrintWaterRegionDebugInfo(TileIndex tile); + #endif /* WATER_REGIONS_H */