diff --git a/src/openrct2/entity/EntityBase.cpp b/src/openrct2/entity/EntityBase.cpp index 75e9a07bfa..ac71e56e36 100644 --- a/src/openrct2/entity/EntityBase.cpp +++ b/src/openrct2/entity/EntityBase.cpp @@ -64,7 +64,7 @@ void EntityBase::Invalidate() break; } - ViewportsInvalidate(SpriteData.SpriteRect, maxZoom); + ViewportsInvalidate(GetLocation(), SpriteData.Width, SpriteData.HeightMin, SpriteData.HeightMax, maxZoom); } void EntityBase::Serialise(DataSerialiser& stream) diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index 0ef86b2e50..90b78fbf1c 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -237,6 +237,44 @@ Viewport* ViewportGetMain() return mainWindow->viewport; } +void ViewportsInvalidate(int32_t x, int32_t y, int32_t z0, int32_t z1, ZoomLevel maxZoom) +{ + for (auto& vp : _viewports) + { + if (maxZoom == ZoomLevel{ -1 } || vp.zoom <= ZoomLevel{ maxZoom }) + { + int32_t x1, y1, x2, y2; + + x += 16; + y += 16; + auto screenCoord = Translate3DTo2DWithZ(vp.rotation, CoordsXYZ{ x, y, 0 }); + + x1 = screenCoord.x - 32; + y1 = screenCoord.y - 32 - z1; + x2 = screenCoord.x + 32; + y2 = screenCoord.y + 32 - z0; + + ViewportInvalidate(&vp, ScreenRect{ { x1, y1 }, { x2, y2 } }); + } + } +} + +void ViewportsInvalidate(const CoordsXYZ& pos, int32_t width, int32_t minHeight, int32_t maxHeight, ZoomLevel maxZoom) +{ + for (auto& vp : _viewports) + { + if (maxZoom == ZoomLevel{ -1 } || vp.zoom <= ZoomLevel{ maxZoom }) + { + auto screenCoords = Translate3DTo2DWithZ(vp.rotation, pos); + auto screenPos = ScreenRect( + screenCoords - ScreenCoordsXY{ width, minHeight }, + screenCoords + ScreenCoordsXY{ width, maxHeight }); + + ViewportInvalidate(&vp, screenPos); + } + } +} + void ViewportsInvalidate(const ScreenRect& screenRect, ZoomLevel maxZoom) { for (auto& vp : _viewports) diff --git a/src/openrct2/interface/Viewport.h b/src/openrct2/interface/Viewport.h index 7420fd4fe7..270d5d2fdb 100644 --- a/src/openrct2/interface/Viewport.h +++ b/src/openrct2/interface/Viewport.h @@ -128,6 +128,8 @@ std::optional centre_2d_coordinates(const CoordsXYZ& loc, Viewpo void ViewportCreate(WindowBase* w, const ScreenCoordsXY& screenCoords, int32_t width, int32_t height, const Focus& focus); void ViewportRemove(Viewport* viewport); Viewport* ViewportGetMain(); +void ViewportsInvalidate(int32_t x, int32_t y, int32_t z0, int32_t z1, ZoomLevel maxZoom); +void ViewportsInvalidate(const CoordsXYZ& pos, int32_t width, int32_t minHeight, int32_t maxHeight, ZoomLevel maxZoom); void ViewportsInvalidate(const ScreenRect& screenRect, ZoomLevel maxZoom = ZoomLevel{ -1 }); void ViewportUpdatePosition(WindowBase* window); void ViewportUpdateFollowSprite(WindowBase* window); diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index a5f4066fef..d1b5e81d3e 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -1794,18 +1794,7 @@ static void MapInvalidateTileUnderZoom(int32_t x, int32_t y, int32_t z0, int32_t if (gOpenRCT2Headless) return; - int32_t x1, y1, x2, y2; - - x += 16; - y += 16; - auto screenCoord = Translate3DTo2D(GetCurrentRotation(), { x, y }); - - x1 = screenCoord.x - 32; - y1 = screenCoord.y - 32 - z1; - x2 = screenCoord.x + 32; - y2 = screenCoord.y + 32 - z0; - - ViewportsInvalidate({ { x1, y1 }, { x2, y2 } }, maxZoom); + ViewportsInvalidate(x, y, z0, z1, maxZoom); } /**