From e855c43c897bddc9a46b39c9b307866eeda20efe Mon Sep 17 00:00:00 2001 From: 73 <94884086+733737@users.noreply.github.com> Date: Tue, 16 Apr 2024 23:11:28 -0400 Subject: [PATCH] Fix #18305 Move Functions to Viewport Move functions to viewport as suggested by duncanspumpkin --- src/openrct2/interface/Viewport.cpp | 14 ++++++++++++++ src/openrct2/interface/Viewport.h | 2 ++ src/openrct2/world/Map.cpp | 12 ------------ src/openrct2/world/Map.h | 2 -- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index 36d90407f28e..2bcb44fd2bb5 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -133,6 +133,19 @@ std::optional centre_2d_coordinates(const CoordsXYZ& loc, Viewpo return { screenCoord }; } + +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 }; +} + CoordsXYZ Focus::GetPos() const { return std::visit( @@ -157,6 +170,7 @@ CoordsXYZ Focus::GetPos() const data); } + /** * Viewport will look at sprite or at coordinates as specified in flags 0b_1X * for sprite 0b_0X for coordinates diff --git a/src/openrct2/interface/Viewport.h b/src/openrct2/interface/Viewport.h index 5287e2bb4d82..820478118818 100644 --- a/src/openrct2/interface/Viewport.h +++ b/src/openrct2/interface/Viewport.h @@ -163,6 +163,8 @@ bool ViewportInteractionLeftClick(const ScreenCoordsXY& screenCoords); bool ViewportInteractionRightOver(const ScreenCoordsXY& screenCoords); bool ViewportInteractionRightClick(const ScreenCoordsXY& screenCoords); + +ScreenCoordsXY Translate3DTo2DWithZ(int32_t rotation, const CoordsXYZ& pos); CoordsXY ViewportInteractionGetTileStartAtCursor(const ScreenCoordsXY& screenCoords); std::optional ScreenGetMapXY(const ScreenCoordsXY& screenCoords, Viewport** viewport); diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 5fdb731da75e..c5ad0b5486b8 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -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 eb1918226557..8b4ccafb0e91 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);