Use the rotation from the Viewport where applicable

This commit is contained in:
ζeh Matt 2024-02-18 03:13:04 +02:00
parent 2661cf8772
commit 98acdf3743
No known key found for this signature in database
GPG Key ID: 18CE582C71A225B0
9 changed files with 39 additions and 32 deletions

View File

@ -111,7 +111,12 @@ namespace OpenRCT2::Scripting
int32_t rotation_get() const
{
return GetCurrentRotation();
auto viewport = GetViewport();
if (viewport != nullptr)
{
return viewport->rotation;
}
return 0;
}
void rotation_set(int32_t value)
{
@ -120,7 +125,7 @@ namespace OpenRCT2::Scripting
auto w = GetWindow();
if (w != nullptr)
{
while (GetCurrentRotation() != value)
while (w->viewport->rotation != value)
{
WindowRotateCamera(*w, 1);
}

View File

@ -2584,7 +2584,7 @@ private:
TileElement tempSideTrackTileElement{ 0x80, 0x8F, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
TileElement tempTrackTileElement{};
TileElement* backupTileElementArrays[5]{};
PaintSession* session = PaintSessionAlloc(dpi, 0);
PaintSession* session = PaintSessionAlloc(dpi, 0, GetCurrentRotation());
trackDirection &= 3;
auto currentRide = GetRide(rideIndex);

View File

@ -305,7 +305,7 @@ void LightFXPrepareLightList()
dpi.zoom_level = _current_view_zoom_front;
dpi.width = 1;
PaintSession* session = PaintSessionAlloc(dpi, w->viewport->flags);
PaintSession* session = PaintSessionAlloc(dpi, w->viewport->flags, w->viewport->rotation);
PaintSessionGenerate(*session);
PaintSessionArrange(*session);
auto info = SetInteractionInfoFromPaintSession(session, w->viewport->flags, ViewportInteractionItemAll);
@ -437,7 +437,7 @@ void LightFXUpdateViewportSettings()
Viewport* viewport = WindowGetViewport(mainWindow);
_current_view_x_back = viewport->viewPos.x;
_current_view_y_back = viewport->viewPos.y;
_current_view_rotation_back = GetCurrentRotation();
_current_view_rotation_back = viewport->rotation;
_current_view_zoom_back = viewport->zoom;
}
}

View File

@ -122,7 +122,7 @@ std::optional<ScreenCoordsXY> centre_2d_coordinates(const CoordsXYZ& loc, Viewpo
return std::nullopt;
}
auto screenCoord = Translate3DTo2DWithZ(GetCurrentRotation(), loc);
auto screenCoord = Translate3DTo2DWithZ(viewport->rotation, loc);
screenCoord.x -= viewport->view_width / 2;
screenCoord.y -= viewport->view_height / 2;
return { screenCoord };
@ -962,7 +962,7 @@ static void ViewportPaint(const Viewport* viewport, DrawPixelInfo& dpi, const Sc
// Generate and sort columns.
for (x = alignedX; x < rightBorder; x += 32)
{
PaintSession* session = PaintSessionAlloc(dpi1, viewFlags);
PaintSession* session = PaintSessionAlloc(dpi1, viewFlags, viewport->rotation);
_paintColumns.push_back(session);
DrawPixelInfo& dpi2 = session->DPI;
@ -1829,31 +1829,31 @@ InteractionInfo GetMapCoordinatesFromPosWindow(WindowBase* window, const ScreenC
return info;
}
Viewport* myviewport = window->viewport;
Viewport* viewport = window->viewport;
auto viewLoc = screenCoords;
viewLoc -= myviewport->pos;
if (viewLoc.x >= 0 && viewLoc.x < static_cast<int32_t>(myviewport->width) && viewLoc.y >= 0
&& viewLoc.y < static_cast<int32_t>(myviewport->height))
viewLoc -= viewport->pos;
if (viewLoc.x >= 0 && viewLoc.x < static_cast<int32_t>(viewport->width) && viewLoc.y >= 0
&& viewLoc.y < static_cast<int32_t>(viewport->height))
{
viewLoc.x = myviewport->zoom.ApplyTo(viewLoc.x);
viewLoc.y = myviewport->zoom.ApplyTo(viewLoc.y);
viewLoc += myviewport->viewPos;
if (myviewport->zoom > ZoomLevel{ 0 })
viewLoc.x = viewport->zoom.ApplyTo(viewLoc.x);
viewLoc.y = viewport->zoom.ApplyTo(viewLoc.y);
viewLoc += viewport->viewPos;
if (viewport->zoom > ZoomLevel{ 0 })
{
viewLoc.x &= myviewport->zoom.ApplyTo(0xFFFFFFFF) & 0xFFFFFFFF;
viewLoc.y &= myviewport->zoom.ApplyTo(0xFFFFFFFF) & 0xFFFFFFFF;
viewLoc.x &= viewport->zoom.ApplyTo(0xFFFFFFFF) & 0xFFFFFFFF;
viewLoc.y &= viewport->zoom.ApplyTo(0xFFFFFFFF) & 0xFFFFFFFF;
}
DrawPixelInfo dpi;
dpi.x = viewLoc.x;
dpi.y = viewLoc.y;
dpi.height = 1;
dpi.zoom_level = myviewport->zoom;
dpi.zoom_level = viewport->zoom;
dpi.width = 1;
PaintSession* session = PaintSessionAlloc(dpi, myviewport->flags);
PaintSession* session = PaintSessionAlloc(dpi, viewport->flags, viewport->rotation);
PaintSessionGenerate(*session);
PaintSessionArrange(*session);
info = SetInteractionInfoFromPaintSession(session, myviewport->flags, flags & 0xFFFF);
info = SetInteractionInfoFromPaintSession(session, viewport->flags, flags & 0xFFFF);
PaintSessionFree(session);
}
return info;
@ -2097,7 +2097,7 @@ void ViewportSetSavedView()
gameState.SavedView = ScreenCoordsXY{ viewport->view_width / 2, viewport->view_height / 2 } + viewport->viewPos;
gameState.SavedViewZoom = viewport->zoom;
gameState.SavedViewRotation = GetCurrentRotation();
gameState.SavedViewRotation = viewport->rotation;
}
}

View File

@ -836,7 +836,7 @@ void WindowScrollToLocation(WindowBase& w, const CoordsXYZ& coords)
}
}
auto screenCoords = Translate3DTo2DWithZ(GetCurrentRotation(), coords);
auto screenCoords = Translate3DTo2DWithZ(w.viewport->rotation, coords);
int32_t i = 0;
if (!(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO))

View File

@ -55,7 +55,7 @@ bool gPaintBoundingBoxes;
bool gPaintBlockedTiles;
static void PaintAttachedPS(DrawPixelInfo& dpi, PaintStruct* ps, uint32_t viewFlags);
static void PaintPSImageWithBoundingBoxes(DrawPixelInfo& dpi, PaintStruct* ps, ImageId imageId, int32_t x, int32_t y);
static void PaintPSImageWithBoundingBoxes(PaintSession& session, PaintStruct* ps, ImageId imageId, int32_t x, int32_t y);
static ImageId PaintPSColourifyImage(const PaintStruct* ps, ImageId imageId, uint32_t viewFlags);
static int32_t RemapPositionToQuadrant(const PaintStruct& ps, uint8_t rotation)
@ -243,7 +243,6 @@ template<uint8_t direction> void PaintSessionGenerateRotate(PaintSession& sessio
*/
void PaintSessionGenerate(PaintSession& session)
{
session.CurrentRotation = GetCurrentRotation();
switch (DirectionFlipXAxis(session.CurrentRotation))
{
case 0:
@ -533,7 +532,7 @@ static void PaintDrawStruct(PaintSession& session, PaintStruct* ps)
auto imageId = PaintPSColourifyImage(ps, ps->image_id, session.ViewFlags);
if (gPaintBoundingBoxes && session.DPI.zoom_level == ZoomLevel{ 0 })
{
PaintPSImageWithBoundingBoxes(session.DPI, ps, imageId, screenPos.x, screenPos.y);
PaintPSImageWithBoundingBoxes(session, ps, imageId, screenPos.x, screenPos.y);
}
else
{
@ -588,10 +587,12 @@ static void PaintAttachedPS(DrawPixelInfo& dpi, PaintStruct* ps, uint32_t viewFl
}
}
static void PaintPSImageWithBoundingBoxes(DrawPixelInfo& dpi, PaintStruct* ps, ImageId imageId, int32_t x, int32_t y)
static void PaintPSImageWithBoundingBoxes(PaintSession& session, PaintStruct* ps, ImageId imageId, int32_t x, int32_t y)
{
auto& dpi = session.DPI;
const uint8_t colour = BoundBoxDebugColours[EnumValue(ps->InteractionItem)];
const uint8_t rotation = GetCurrentRotation();
const uint8_t rotation = session.CurrentRotation;
const CoordsXYZ frontTop = {
ps->Bounds.x_end,
@ -688,9 +689,9 @@ static ImageId PaintPSColourifyImage(const PaintStruct* ps, ImageId imageId, uin
}
}
PaintSession* PaintSessionAlloc(DrawPixelInfo& dpi, uint32_t viewFlags)
PaintSession* PaintSessionAlloc(DrawPixelInfo& dpi, uint32_t viewFlags, uint8_t rotation)
{
return GetContext()->GetPainter()->CreateSession(dpi, viewFlags);
return GetContext()->GetPainter()->CreateSession(dpi, viewFlags, rotation);
}
void PaintSessionFree(PaintSession* session)

View File

@ -338,7 +338,7 @@ void PaintFloatingMoneyEffect(
PaintSession& session, money64 amount, StringId string_id, int32_t y, int32_t z, int8_t y_offsets[], int32_t offset_x,
uint32_t rotation);
PaintSession* PaintSessionAlloc(DrawPixelInfo& dpi, uint32_t viewFlags);
PaintSession* PaintSessionAlloc(DrawPixelInfo& dpi, uint32_t viewFlags, uint8_t rotation);
void PaintSessionFree(PaintSession* session);
void PaintSessionGenerate(PaintSession& session);
void PaintSessionArrange(PaintSessionCore& session);

View File

@ -133,7 +133,7 @@ void Painter::MeasureFPS()
_lastSecond = currentTime;
}
PaintSession* Painter::CreateSession(DrawPixelInfo& dpi, uint32_t viewFlags)
PaintSession* Painter::CreateSession(DrawPixelInfo& dpi, uint32_t viewFlags, uint8_t rotation)
{
PROFILED_FUNCTION();
@ -160,6 +160,7 @@ PaintSession* Painter::CreateSession(DrawPixelInfo& dpi, uint32_t viewFlags)
session->QuadrantFrontIndex = 0;
session->PaintEntryChain = _paintStructPool.Create();
session->Flags = 0;
session->CurrentRotation = rotation;
std::fill(std::begin(session->Quadrants), std::end(session->Quadrants), nullptr);
session->PaintHead = nullptr;

View File

@ -47,7 +47,7 @@ namespace OpenRCT2
explicit Painter(const std::shared_ptr<Ui::IUiContext>& uiContext);
void Paint(Drawing::IDrawingEngine& de);
PaintSession* CreateSession(DrawPixelInfo& dpi, uint32_t viewFlags);
PaintSession* CreateSession(DrawPixelInfo& dpi, uint32_t viewFlags, uint8_t rotation);
void ReleaseSession(PaintSession* session);
~Painter();