From 6a7fe6a5e29d24680a3732dd85a15dfb561ede1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 8 Sep 2021 23:13:19 +0300 Subject: [PATCH] Fix #15376: Extend the X axis on rotation 0 to cover corners Also make the code branchless --- src/openrct2/paint/Paint.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/openrct2/paint/Paint.cpp b/src/openrct2/paint/Paint.cpp index 1b06b4b002..6d64b750c2 100644 --- a/src/openrct2/paint/Paint.cpp +++ b/src/openrct2/paint/Paint.cpp @@ -56,21 +56,19 @@ static void PaintPSImageWithBoundingBoxes(rct_drawpixelinfo* dpi, paint_struct* static void PaintPSImage(rct_drawpixelinfo* dpi, paint_struct* ps, uint32_t imageId, int32_t x, int32_t y); static uint32_t PaintPSColourifyImage(uint32_t imageId, ViewportInteractionItem spriteType, uint32_t viewFlags); +static constexpr int32_t _PositionHashExtendsX[] = { + -0x2000, + 0x2000, + 0x4000, + 0x2000, +}; + static constexpr uint32_t CalculatePositionHash(const paint_struct& ps, uint8_t rotation) { auto pos = CoordsXY{ ps.bounds.x, ps.bounds.y }.Rotate(rotation); - switch (rotation) - { - case 0: - break; - case 1: - case 3: - pos.x += 0x2000; - break; - case 2: - pos.x += 0x4000; - break; - } + + // For corners to fall into the right buckets this extends the X axis. + pos.x += _PositionHashExtendsX[rotation]; return static_cast(pos.x + pos.y); }