From 137099a42963daf1a817324e4f4b23396ec1aec7 Mon Sep 17 00:00:00 2001 From: Karsten Van Fossan <143759020+karstenvanf@users.noreply.github.com> Date: Sat, 20 Apr 2024 19:18:11 -0400 Subject: [PATCH] Close #18305: Move Translate3DTo2DWithZ() from Map.h into Viewport.h Translate3DTo2DWithZ move to Viewport.h as suggested by ducanspumpkin and update references. Remove redundant function Translate3Dto2D. --- contributors.md | 1 + src/openrct2-ui/windows/RideConstruction.cpp | 1 + src/openrct2/interface/Viewport.cpp | 7 +++++++ src/openrct2/interface/Viewport.h | 2 ++ src/openrct2/ride/RideAudio.cpp | 1 + src/openrct2/ride/TrackDesign.cpp | 1 + src/openrct2/world/Map.cpp | 16 ++-------------- src/openrct2/world/Map.h | 2 -- 8 files changed, 15 insertions(+), 16 deletions(-) diff --git a/contributors.md b/contributors.md index 91018072cb..d67e284bf1 100644 --- a/contributors.md +++ b/contributors.md @@ -237,6 +237,7 @@ Appreciation for contributors who have provided substantial work, but are no lon * Harry Hopkinson (Harry-Hopkinson) * Jan Kelemen (jan-kelemen) * Cory Ye (CoryfY) +* Karsten Van Fossan (karstenvanf) ## Toolchain * (Balletie) - macOS diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 8e45943459..1b67f23f35 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index 36d90407f2..a3c02f4d96 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -2156,6 +2156,13 @@ std::optional ScreenGetMapXYSideWithZ(const ScreenCoordsXY& screenCoor return mapCoords->ToTileStart(); } +ScreenCoordsXY Translate3DTo2DWithZ(int32_t rotation, const CoordsXYZ& pos) +{ + auto rotated = pos.Rotate(rotation); + // Use right shift to avoid issues like #9301 + return ScreenCoordsXY{ rotated.y - rotated.x, ((rotated.x + rotated.y) >> 1) - pos.z }; +} + /** * Get current viewport rotation. * diff --git a/src/openrct2/interface/Viewport.h b/src/openrct2/interface/Viewport.h index 5287e2bb4d..117ef53342 100644 --- a/src/openrct2/interface/Viewport.h +++ b/src/openrct2/interface/Viewport.h @@ -172,6 +172,8 @@ std::optional ScreenGetMapXYQuadrantWithZ(const ScreenCoordsXY& screen std::optional ScreenGetMapXYSide(const ScreenCoordsXY& screenCoords, uint8_t* side); std::optional ScreenGetMapXYSideWithZ(const ScreenCoordsXY& screenCoords, int32_t z, uint8_t* side); +ScreenCoordsXY Translate3DTo2DWithZ(int32_t rotation, const CoordsXYZ& pos); + uint8_t GetCurrentRotation(); int32_t GetHeightMarkerOffset(); diff --git a/src/openrct2/ride/RideAudio.cpp b/src/openrct2/ride/RideAudio.cpp index 02f08846f6..62c48faad3 100644 --- a/src/openrct2/ride/RideAudio.cpp +++ b/src/openrct2/ride/RideAudio.cpp @@ -16,6 +16,7 @@ #include "../audio/AudioMixer.h" #include "../audio/audio.h" #include "../config/Config.h" +#include "../interface/Viewport.h" #include "../object/AudioObject.h" #include "../object/MusicObject.h" #include "../object/ObjectManager.h" diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index 5da07840a9..5b562f4cd4 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -35,6 +35,7 @@ #include "../core/Numerics.hpp" #include "../core/String.hpp" #include "../drawing/X8DrawingEngine.h" +#include "../interface/Viewport.h" #include "../localisation/Localisation.h" #include "../localisation/StringIds.h" #include "../management/Finance.h" diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 5fdb731da7..9afde7f703 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -23,6 +23,7 @@ #include "../config/Config.h" #include "../core/Guard.hpp" #include "../interface/Cursors.h" +#include "../interface/Viewport.h" #include "../interface/Window.h" #include "../localisation/Date.h" #include "../localisation/Localisation.h" @@ -287,7 +288,6 @@ bool MapCheckCapacityAndReorganise(const CoordsXY& loc, size_t numElements) } static void ClearElementsAt(const CoordsXY& loc); -static ScreenCoordsXY Translate3DTo2D(int32_t rotation, const CoordsXY& pos); void TileElementIteratorBegin(TileElementIterator* it) { @@ -1102,7 +1102,7 @@ static void MapGetBoundingBox(const MapRange& _range, int32_t* left, int32_t* to for (const auto& corner : corners) { - auto screenCoord = Translate3DTo2D(rotation, corner); + auto screenCoord = Translate3DTo2DWithZ(rotation, CoordsXYZ{ corner, 0 }); if (screenCoord.x < *left) *left = screenCoord.x; if (screenCoord.x > *right) @@ -1771,18 +1771,6 @@ bool MapLargeScenerySignSetColour(const CoordsXYZD& signPos, int32_t sequence, u return true; } -static ScreenCoordsXY Translate3DTo2D(int32_t rotation, const CoordsXY& pos) -{ - return Translate3DTo2DWithZ(rotation, CoordsXYZ{ pos, 0 }); -} - -ScreenCoordsXY Translate3DTo2DWithZ(int32_t rotation, const CoordsXYZ& pos) -{ - auto rotated = pos.Rotate(rotation); - // Use right shift to avoid issues like #9301 - return ScreenCoordsXY{ rotated.y - rotated.x, ((rotated.x + rotated.y) >> 1) - pos.z }; -} - static void MapInvalidateTileUnderZoom(int32_t x, int32_t y, int32_t z0, int32_t z1, ZoomLevel maxZoom) { if (gOpenRCT2Headless) diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index eb19182265..8b4ccafb0e 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -239,8 +239,6 @@ LargeSceneryElement* MapGetLargeScenerySegment(const CoordsXYZD& sceneryPos, int std::optional MapLargeSceneryGetOrigin( const CoordsXYZD& sceneryPos, int32_t sequence, LargeSceneryElement** outElement); -ScreenCoordsXY Translate3DTo2DWithZ(int32_t rotation, const CoordsXYZ& pos); - TrackElement* MapGetTrackElementAt(const CoordsXYZ& trackPos); TileElement* MapGetTrackElementAtOfType(const CoordsXYZ& trackPos, track_type_t trackType); TileElement* MapGetTrackElementAtOfTypeSeq(const CoordsXYZ& trackPos, track_type_t trackType, int32_t sequence);