Codechange: Skip non-water water region patches in neigbor search
(cherry picked from commit 8a1cea2ab6)
			
			
This commit is contained in:
		
				
					committed by
					
						
						Jonathan G Rennison
					
				
			
			
				
	
			
			
			
						parent
						
							a98a56669b
						
					
				
				
					commit
					69af0e8f26
				
			@@ -25,7 +25,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.
 | 
			
		||||
@@ -427,6 +426,8 @@ void InvalidateWaterRegion(TileIndex tile)
 | 
			
		||||
 */
 | 
			
		||||
static inline void VisitAdjacentWaterRegionPatchNeighbors(const WaterRegionPatchDesc &water_region_patch, DiagDirection side, TVisitWaterRegionPatchCallBack &func)
 | 
			
		||||
{
 | 
			
		||||
	if (water_region_patch.label == INVALID_WATER_REGION_PATCH) return;
 | 
			
		||||
 | 
			
		||||
	const WaterRegionReference current_region = GetUpdatedWaterRegion(water_region_patch.x, water_region_patch.y);
 | 
			
		||||
 | 
			
		||||
	const TileIndexDiffC offset = TileIndexDiffCByDiagDir(side);
 | 
			
		||||
@@ -461,6 +462,7 @@ static inline void VisitAdjacentWaterRegionPatchNeighbors(const WaterRegionPatch
 | 
			
		||||
 | 
			
		||||
		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 });
 | 
			
		||||
@@ -474,6 +476,8 @@ static inline void VisitAdjacentWaterRegionPatchNeighbors(const WaterRegionPatch
 | 
			
		||||
 */
 | 
			
		||||
void VisitWaterRegionPatchNeighbors(const WaterRegionPatchDesc &water_region_patch, TVisitWaterRegionPatchCallBack &callback)
 | 
			
		||||
{
 | 
			
		||||
	if (water_region_patch.label == INVALID_WATER_REGION_PATCH) return;
 | 
			
		||||
 | 
			
		||||
	const WaterRegionReference current_region = GetUpdatedWaterRegion(water_region_patch.x, water_region_patch.y);
 | 
			
		||||
 | 
			
		||||
	/* Visit adjacent water region patches in each cardinal direction */
 | 
			
		||||
 
 | 
			
		||||
@@ -27,6 +27,8 @@ static_assert((WATER_REGION_EDGE_LENGTH & WATER_REGION_EDGE_MASK) == 0);
 | 
			
		||||
 | 
			
		||||
constexpr uint32_t 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.
 | 
			
		||||
 */
 | 
			
		||||
 
 | 
			
		||||
@@ -103,6 +103,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 });
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user