From 755e41de9f026a4d05370bd603e6915a331bd741 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Thu, 26 Jan 2023 22:59:32 +0100 Subject: [PATCH] Codechange: make rounding code clearer -O1 already optimizes it to the original hand optimized magic code --- src/elrail.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/elrail.cpp b/src/elrail.cpp index f284e6fe2f..36c5396f11 100644 --- a/src/elrail.cpp +++ b/src/elrail.cpp @@ -234,7 +234,9 @@ static int GetPCPElevation(TileIndex tile, DiagDirection PCPpos) int z = GetSlopePixelZ(TileX(tile) * TILE_SIZE + std::min(x_pcp_offsets[PCPpos], TILE_SIZE - 1), TileY(tile) * TILE_SIZE + std::min(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; } /**