# HG changeset patch # User Koen Bussemaker # Date 2024-02-17 19:15:43 # Node ID ee8d01cc7e15765d4e1e6be39871d21d0ab03dbe # Parent 365899ab5941880ae307cb531c25ad6fb170a519 Codechange: Skip non-water water region patches in neigbor search diff --git a/src/pathfinder/water_regions.cpp b/src/pathfinder/water_regions.cpp --- a/src/pathfinder/water_regions.cpp +++ b/src/pathfinder/water_regions.cpp @@ -22,7 +22,6 @@ using TWaterRegionTraversabilityBits = uint16_t; constexpr TWaterRegionPatchLabel FIRST_REGION_LABEL = 1; -constexpr TWaterRegionPatchLabel INVALID_WATER_REGION_PATCH = 0; static_assert(sizeof(TWaterRegionTraversabilityBits) * 8 == WATER_REGION_EDGE_LENGTH); static_assert(sizeof(TWaterRegionPatchLabel) == sizeof(byte)); // Important for the hash calculation. @@ -321,6 +320,8 @@ void InvalidateWaterRegion(TileIndex til */ static inline void VisitAdjacentWaterRegionPatchNeighbors(const WaterRegionPatchDesc &water_region_patch, DiagDirection side, TVisitWaterRegionPatchCallBack &func) { + if (water_region_patch.label == INVALID_WATER_REGION_PATCH) return; + const WaterRegion ¤t_region = GetUpdatedWaterRegion(water_region_patch.x, water_region_patch.y); const TileIndexDiffC offset = TileIndexDiffCByDiagDir(side); @@ -354,6 +355,7 @@ static inline void VisitAdjacentWaterReg const TileIndex neighbor_edge_tile = GetEdgeTileCoordinate(nx, ny, opposite_side, x_or_y); const TWaterRegionPatchLabel neighbor_label = neighboring_region.GetLabel(neighbor_edge_tile); + assert(neighbor_label != INVALID_WATER_REGION_PATCH); if (std::find(unique_labels.begin(), unique_labels.end(), neighbor_label) == unique_labels.end()) unique_labels.push_back(neighbor_label); } for (TWaterRegionPatchLabel unique_label : unique_labels) func(WaterRegionPatchDesc{ nx, ny, unique_label }); @@ -367,6 +369,8 @@ static inline void VisitAdjacentWaterReg */ void VisitWaterRegionPatchNeighbors(const WaterRegionPatchDesc &water_region_patch, TVisitWaterRegionPatchCallBack &callback) { + if (water_region_patch.label == INVALID_WATER_REGION_PATCH) return; + const WaterRegion ¤t_region = GetUpdatedWaterRegion(water_region_patch.x, water_region_patch.y); /* Visit adjacent water region patches in each cardinal direction */ diff --git a/src/pathfinder/water_regions.h b/src/pathfinder/water_regions.h --- a/src/pathfinder/water_regions.h +++ b/src/pathfinder/water_regions.h @@ -18,6 +18,7 @@ using TWaterRegionIndex = uint; constexpr int WATER_REGION_EDGE_LENGTH = 16; constexpr int WATER_REGION_NUMBER_OF_TILES = WATER_REGION_EDGE_LENGTH * WATER_REGION_EDGE_LENGTH; +constexpr TWaterRegionPatchLabel INVALID_WATER_REGION_PATCH = 0; /** * Describes a single interconnected patch of water within a particular water region. diff --git a/src/pathfinder/yapf/yapf_ship_regions.cpp b/src/pathfinder/yapf/yapf_ship_regions.cpp --- a/src/pathfinder/yapf/yapf_ship_regions.cpp +++ b/src/pathfinder/yapf/yapf_ship_regions.cpp @@ -102,6 +102,7 @@ private: public: void AddOrigin(const WaterRegionPatchDesc &water_region_patch) { + if (water_region_patch.label == INVALID_WATER_REGION_PATCH) return; if (!HasOrigin(water_region_patch)) m_origin_keys.push_back(CYapfRegionPatchNodeKey{ water_region_patch }); }