Changeset - r26813:ed6c84a945a0
[Not reviewed]
master
0 1 0
Rubidium - 17 months ago 2023-01-26 21:59:32
rubidium@openttd.org
Codechange: make rounding code clearer

-O1 already optimizes it to the original hand optimized magic code
1 file changed with 3 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/elrail.cpp
Show inline comments
 
@@ -234,7 +234,9 @@ static int GetPCPElevation(TileIndex til
 

	
 
	int z = GetSlopePixelZ(TileX(tile) * TILE_SIZE + std::min<int8>(x_pcp_offsets[PCPpos], TILE_SIZE - 1),
 
	                       TileY(tile) * TILE_SIZE + std::min<int8>(y_pcp_offsets[PCPpos], TILE_SIZE - 1));
 
	return (z + 2) & ~3; // this means z = (z + TILE_HEIGHT / 4) / (TILE_HEIGHT / 2) * (TILE_HEIGHT / 2);
 
	/* Round the Z to the nearest half tile height. */
 
	static const uint HALF_TILE_HEIGHT = TILE_HEIGHT / 2;
 
	return (z + HALF_TILE_HEIGHT / 2) / HALF_TILE_HEIGHT * HALF_TILE_HEIGHT;
 
}
 

	
 
/**
0 comments (0 inline, 0 general)