From 55add9883f07d49f88b16fe764a897cdc24ba8bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Tue, 24 Aug 2021 13:57:13 -0700 Subject: [PATCH] Implement DirectionFlipXAxis --- src/openrct2/interface/Viewport.cpp | 4 +--- src/openrct2/paint/Paint.cpp | 7 ++----- src/openrct2/world/Location.hpp | 8 ++++++++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index 6aa028ae56..4f68f8ba27 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -1148,11 +1148,9 @@ void rct_viewport::Invalidate() const CoordsXY viewport_coord_to_map_coord(const ScreenCoordsXY& coords, int32_t z) { - constexpr uint8_t inverseRotationMapping[NumOrthogonalDirections] = { 0, 3, 2, 1 }; - // Reverse of translate_3d_to_2d_with_z CoordsXY ret = { coords.y - coords.x / 2 + z, coords.y + coords.x / 2 + z }; - auto inverseRotation = inverseRotationMapping[get_current_rotation()]; + auto inverseRotation = DirectionFlipXAxis(get_current_rotation()); return ret.Rotate(inverseRotation); } diff --git a/src/openrct2/paint/Paint.cpp b/src/openrct2/paint/Paint.cpp index 45b8a63e88..a27565383e 100644 --- a/src/openrct2/paint/Paint.cpp +++ b/src/openrct2/paint/Paint.cpp @@ -145,7 +145,7 @@ static paint_struct* CreateNormalPaintStruct( return nullptr; } - const uint8_t swappedRotation = (session->CurrentRotation * 3) % 4; // swaps 1 and 3 + const auto swappedRotation = DirectionFlipXAxis(session->CurrentRotation); auto swappedRotCoord = CoordsXYZ{ offset.Rotate(swappedRotation), offset.z }; swappedRotCoord += session->SpritePosition; @@ -231,10 +231,7 @@ template void PaintSessionGenerateRotate(paint_session* sessi void PaintSessionGenerate(paint_session* session) { session->CurrentRotation = get_current_rotation(); - - // Extracted from viewport_coord_to_map_coord - constexpr uint8_t inverseRotationMapping[NumOrthogonalDirections] = { 0, 3, 2, 1 }; - switch (inverseRotationMapping[session->CurrentRotation]) + switch (DirectionFlipXAxis(session->CurrentRotation)) { case 0: PaintSessionGenerateRotate<0>(session); diff --git a/src/openrct2/world/Location.hpp b/src/openrct2/world/Location.hpp index 560bcb91e8..120cb502d7 100644 --- a/src/openrct2/world/Location.hpp +++ b/src/openrct2/world/Location.hpp @@ -545,6 +545,14 @@ constexpr Direction ALL_DIRECTIONS[] = { 0, 1, 2, 3 }; } } +/* + * Flips the X axis so 1 and 3 are swapped 0 and 2 will stay the same. + */ +inline constexpr Direction DirectionFlipXAxis(Direction direction) +{ + return (direction * 3) % 4; +} + struct CoordsXYZD : public CoordsXYZ { Direction direction{};