Skip to content

Commit

Permalink
Fix OpenRCT2#18305 Move Functions to Viewport
Browse files Browse the repository at this point in the history
Move functions to viewport as suggested by duncanspumpkin
  • Loading branch information
733737 committed Apr 17, 2024
1 parent b64ec76 commit e855c43
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
14 changes: 14 additions & 0 deletions src/openrct2/interface/Viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@ std::optional<ScreenCoordsXY> 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(
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/openrct2/interface/Viewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<CoordsXY> ScreenGetMapXY(const ScreenCoordsXY& screenCoords, Viewport** viewport);
Expand Down
12 changes: 0 additions & 12 deletions src/openrct2/world/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions src/openrct2/world/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,6 @@ LargeSceneryElement* MapGetLargeScenerySegment(const CoordsXYZD& sceneryPos, int
std::optional<CoordsXYZ> 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);
Expand Down

0 comments on commit e855c43

Please sign in to comment.