diff --git a/src/openrct2-ui/windows/Guest.cpp b/src/openrct2-ui/windows/Guest.cpp index 3bfe9b26c3..54ede4d7d8 100644 --- a/src/openrct2-ui/windows/Guest.cpp +++ b/src/openrct2-ui/windows/Guest.cpp @@ -987,20 +987,13 @@ namespace OpenRCT2::Ui::Windows gMapSelectPositionB = mapCoords; } - gPickupPeepImage = ImageId(); + pickupPeepClear(); auto info = GetMapCoordinatesFromPos(screenCoords, kViewportInteractionItemAll); if (info.interactionType == ViewportInteractionItem::none) return; - gPickupPeepX = screenCoords.x - 1; - gPickupPeepY = screenCoords.y + 16; - - auto* mainWindow = WindowGetMain(); - if (mainWindow != nullptr) - { - gPickupPeepZoom = std::min(mainWindow->viewport->zoom, ZoomLevel{ 0 }); - } + pickupPeepSetPosition({ screenCoords.x - 1, screenCoords.y + 16 }); const auto peep = GetGuest(); if (peep == nullptr) @@ -1013,7 +1006,7 @@ namespace OpenRCT2::Ui::Windows auto baseImageId = animObj->GetPeepAnimation(peep->animationGroup, PeepAnimationType::hanging).baseImage; baseImageId += pickedPeepFrame >> 2; - gPickupPeepImage = ImageId(baseImageId, peep->tShirtColour, peep->trousersColour); + pickupPeepSetImage(baseImageId, peep->tShirtColour, peep->trousersColour); } void onToolDownOverview(WidgetIndex widgetIndex, const ScreenCoordsXY& screenCoords) @@ -1035,7 +1028,7 @@ namespace OpenRCT2::Ui::Windows if (result->error != GameActions::Status::ok) return; ToolCancel(); - gPickupPeepImage = ImageId(); + pickupPeepClear(); }); GameActions::Execute(&pickupAction, getGameState()); } diff --git a/src/openrct2-ui/windows/Staff.cpp b/src/openrct2-ui/windows/Staff.cpp index d9552bff18..f18dd09d1c 100644 --- a/src/openrct2-ui/windows/Staff.cpp +++ b/src/openrct2-ui/windows/Staff.cpp @@ -678,20 +678,13 @@ namespace OpenRCT2::Ui::Windows gMapSelectPositionB = mapCoords; } - gPickupPeepImage = ImageId(); + Drawing::pickupPeepClear(); auto info = GetMapCoordinatesFromPos(screenCoords, kViewportInteractionItemAll); if (info.interactionType == ViewportInteractionItem::none) return; - gPickupPeepX = screenCoords.x - 1; - gPickupPeepY = screenCoords.y + 16; - - auto* mainWindow = WindowGetMain(); - if (mainWindow != nullptr) - { - gPickupPeepZoom = std::min(mainWindow->viewport->zoom, ZoomLevel{ 0 }); - } + Drawing::pickupPeepSetPosition({ screenCoords.x - 1, screenCoords.y + 16 }); auto staff = GetStaff(); if (staff == nullptr) @@ -704,7 +697,7 @@ namespace OpenRCT2::Ui::Windows auto& pickupAnim = animObj->GetPeepAnimation(staff->animationGroup, PeepAnimationType::hanging); auto baseImageId = pickupAnim.baseImage + pickupAnim.frameOffsets[pickedPeepFrame >> 2]; - gPickupPeepImage = ImageId(baseImageId, staff->tShirtColour, staff->trousersColour); + Drawing::pickupPeepSetImage(baseImageId, staff->tShirtColour, staff->trousersColour); } void OverviewToolDown(WidgetIndex widgetIndex, const ScreenCoordsXY& screenCoords) @@ -727,7 +720,7 @@ namespace OpenRCT2::Ui::Windows if (result->error != GameActions::Status::ok) return; ToolCancel(); - gPickupPeepImage = ImageId(); + Drawing::pickupPeepClear(); }); GameActions::Execute(&pickupAction, getGameState()); } diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index dd2b99d578..0c3f9a5ebb 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -520,7 +520,7 @@ namespace OpenRCT2 gInputFlags.clearAll(); InputSetState(InputState::reset); gPressedWidget.windowClassification = WindowClass::null; - gPickupPeepImage = ImageId(); + Drawing::pickupPeepClear(); ResetTooltipNotShown(); gMapSelectFlags.clearAll(); ClearPatrolAreaToRender(); diff --git a/src/openrct2/drawing/PickupPeep.cpp b/src/openrct2/drawing/PickupPeep.cpp index 24cd920857..b4eaa402de 100644 --- a/src/openrct2/drawing/PickupPeep.cpp +++ b/src/openrct2/drawing/PickupPeep.cpp @@ -1,60 +1,85 @@ #include "PickupPeep.h" #include "../interface/ScreenCoords.hpp" +#include "../interface/Viewport.h" +#include "../interface/Window.h" +#include "../interface/WindowBase.h" #include "../interface/ZoomLevel.h" #include "Drawing.Sprite.h" #include "Drawing.h" #include "ImageId.hpp" #include "RenderTarget.h" -ImageId gPickupPeepImage; -int32_t gPickupPeepX; -int32_t gPickupPeepY; -ZoomLevel gPickupPeepZoom; - -constexpr std::array kPickedUpPeepYOffsets = { 0, 16, 48 }; - -using OpenRCT2::Drawing::RenderTarget; - -void GfxInvalidatePickedUpPeep() +namespace OpenRCT2::Drawing { - if (!gPickupPeepImage.HasValue()) - return; + static ImageId _pickupPeepImage{}; + static ScreenCoordsXY _pickupPeepPosition{}; + static ZoomLevel _pickupPeepZoom{}; - auto* g1 = GfxGetG1Element(gPickupPeepImage); - if (g1 == nullptr) - return; + static constexpr std::array kPickedUpPeepYOffsets = { 0, 16, 48 }; - auto zoom = gPickupPeepZoom; - auto xOffset = -int8_t(gPickupPeepZoom); - auto yOffset = kPickedUpPeepYOffsets[xOffset]; + void pickupPeepSetImage(ImageIndex baseImageId, Colour primaryColour, Colour secondaryColour) + { + _pickupPeepImage = ImageId(baseImageId, primaryColour, secondaryColour); + } - int32_t left = gPickupPeepX + zoom.ApplyInversedTo(g1->xOffset) + xOffset; - int32_t top = gPickupPeepY + zoom.ApplyInversedTo(g1->yOffset) + yOffset; - int32_t right = left + zoom.ApplyInversedTo(g1->width); - int32_t bottom = top + zoom.ApplyInversedTo(g1->height); + void pickupPeepSetPosition(ScreenCoordsXY position) + { + _pickupPeepPosition = position; - GfxSetDirtyBlocks({ { left, top }, { right, bottom } }); -} + auto* mainWindow = WindowGetMain(); + if (mainWindow != nullptr) + { + _pickupPeepZoom = std::min(mainWindow->viewport->zoom, ZoomLevel{ 0 }); + } + } -void GfxDrawPickedUpPeep(RenderTarget& rt) -{ - if (!gPickupPeepImage.HasValue()) - return; + void pickupPeepClear() + { + _pickupPeepImage = ImageId(); + } - assert(rt.zoom_level == ZoomLevel{ 0 }); + void pickupPeepInvalidate() + { + if (!_pickupPeepImage.HasValue()) + return; - auto zoom = gPickupPeepZoom; - auto xOffset = -int8_t(gPickupPeepZoom); - auto yOffset = kPickedUpPeepYOffsets[xOffset]; + auto* g1 = GfxGetG1Element(_pickupPeepImage); + if (g1 == nullptr) + return; - auto pos = ScreenCoordsXY{ zoom.ApplyTo(gPickupPeepX + xOffset), zoom.ApplyTo(gPickupPeepY + yOffset) }; + auto zoom = _pickupPeepZoom; + auto xOffset = -int8_t(_pickupPeepZoom); + auto yOffset = kPickedUpPeepYOffsets[xOffset]; - rt.zoom_level = zoom; - rt.pitch = zoom.ApplyTo(rt.pitch); + int32_t left = _pickupPeepPosition.x + zoom.ApplyInversedTo(g1->xOffset) + xOffset; + int32_t top = _pickupPeepPosition.y + zoom.ApplyInversedTo(g1->yOffset) + yOffset; + int32_t right = left + zoom.ApplyInversedTo(g1->width); + int32_t bottom = top + zoom.ApplyInversedTo(g1->height); - GfxDrawSprite(rt, gPickupPeepImage, pos); + GfxSetDirtyBlocks({ { left, top }, { right, bottom } }); + } - rt.pitch = zoom.ApplyInversedTo(rt.pitch); - rt.zoom_level = ZoomLevel{ 0 }; -} + void pickupPeepDraw(RenderTarget& rt) + { + if (!_pickupPeepImage.HasValue()) + return; + + assert(rt.zoom_level == ZoomLevel{ 0 }); + + auto zoom = _pickupPeepZoom; + auto xOffset = -int8_t(_pickupPeepZoom); + auto yOffset = kPickedUpPeepYOffsets[xOffset]; + + auto pos = ScreenCoordsXY{ zoom.ApplyTo(_pickupPeepPosition.x + xOffset), + zoom.ApplyTo(_pickupPeepPosition.y + yOffset) }; + + rt.zoom_level = zoom; + rt.pitch = zoom.ApplyTo(rt.pitch); + + GfxDrawSprite(rt, _pickupPeepImage, pos); + + rt.pitch = zoom.ApplyInversedTo(rt.pitch); + rt.zoom_level = ZoomLevel{ 0 }; + } +} // namespace OpenRCT2::Drawing diff --git a/src/openrct2/drawing/PickupPeep.h b/src/openrct2/drawing/PickupPeep.h index badfa82090..808a888be8 100644 --- a/src/openrct2/drawing/PickupPeep.h +++ b/src/openrct2/drawing/PickupPeep.h @@ -11,18 +11,20 @@ #include +using ImageIndex = uint32_t; + struct ImageId; +struct ScreenCoordsXY; struct ZoomLevel; namespace OpenRCT2::Drawing { + enum class Colour : uint8_t; struct RenderTarget; -} -extern ImageId gPickupPeepImage; -extern int32_t gPickupPeepX; -extern int32_t gPickupPeepY; -extern ZoomLevel gPickupPeepZoom; - -void GfxInvalidatePickedUpPeep(); -void GfxDrawPickedUpPeep(OpenRCT2::Drawing::RenderTarget& rt); + void pickupPeepSetImage(ImageIndex baseImageId, Colour primaryColour, Colour secondaryColour); + void pickupPeepSetPosition(ScreenCoordsXY position); + void pickupPeepClear(); + void pickupPeepInvalidate(); + void pickupPeepDraw(RenderTarget& rt); +} // namespace OpenRCT2::Drawing diff --git a/src/openrct2/entity/Peep.cpp b/src/openrct2/entity/Peep.cpp index 6f3eb02fde..c2d6825a47 100644 --- a/src/openrct2/entity/Peep.cpp +++ b/src/openrct2/entity/Peep.cpp @@ -647,7 +647,7 @@ namespace OpenRCT2 pathCheckOptimisation = 0; } - gPickupPeepImage = ImageId(); + pickupPeepClear(); } // Returns GameActions::Status::ok when a peep can be dropped at the given location. When apply is set to true the peep gets diff --git a/src/openrct2/paint/Painter.cpp b/src/openrct2/paint/Painter.cpp index 8fbe27b2e9..bca9c7b149 100644 --- a/src/openrct2/paint/Painter.cpp +++ b/src/openrct2/paint/Painter.cpp @@ -60,8 +60,8 @@ void Painter::Paint(IDrawingEngine& de) UpdatePaletteEffects(); _uiContext.Draw(*rt); - GfxDrawPickedUpPeep(*rt); - GfxInvalidatePickedUpPeep(); + pickupPeepDraw(*rt); + pickupPeepInvalidate(); de.PaintWeather(); }