Files
OpenRCT2-Web/src/openrct2/world/MapAnimation.cpp
T

761 lines
25 KiB
C++
Raw Normal View History

/*****************************************************************************
2024-12-31 20:30:04 +01:00
* Copyright (c) 2014-2025 OpenRCT2 developers
*
2018-06-15 14:07:34 +02:00
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
2018-06-15 14:07:34 +02:00
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
2018-06-22 23:17:03 +02:00
#include "MapAnimation.h"
2018-03-14 12:44:16 +01:00
#include "../Context.h"
2024-07-09 16:23:31 +02:00
#include "../Diagnostic.h"
2017-11-30 18:17:06 +01:00
#include "../Game.h"
#include "../GameState.h"
#include "../core/Numerics.hpp"
2021-11-24 16:48:33 +02:00
#include "../entity/EntityList.h"
2021-11-25 23:47:24 +02:00
#include "../entity/Peep.h"
2018-06-22 23:17:03 +02:00
#include "../interface/Viewport.h"
2023-01-26 18:44:42 +00:00
#include "../object/LargeSceneryEntry.h"
#include "../object/SmallSceneryEntry.h"
#include "../object/StationObject.h"
2023-01-25 19:56:29 +00:00
#include "../object/WallSceneryEntry.h"
2022-01-18 10:21:20 -08:00
#include "../profiling/Profiling.h"
2017-12-31 13:21:34 +01:00
#include "../ride/Ride.h"
2018-01-10 00:00:09 +01:00
#include "../ride/RideData.h"
2017-10-17 13:51:47 +02:00
#include "../ride/Track.h"
2019-02-14 22:41:48 +01:00
#include "Banner.h"
2018-06-22 23:17:03 +02:00
#include "Footpath.h"
2018-01-11 10:59:26 +01:00
#include "Scenery.h"
2024-10-03 12:42:53 +02:00
#include "tile_element/EntranceElement.h"
2024-10-15 22:02:31 +02:00
#include "tile_element/LargeSceneryElement.h"
#include "tile_element/PathElement.h"
#include "tile_element/SmallSceneryElement.h"
#include "tile_element/TileElement.h"
#include "tile_element/TrackElement.h"
#include "tile_element/WallElement.h"
2018-06-22 23:17:03 +02:00
#include <algorithm>
#include <set>
using namespace OpenRCT2;
constexpr ZoomLevel kMaxZoom{ 1 };
2025-05-21 06:48:58 +01:00
struct TemporaryMapAnimation
{
CoordsXYZ location{};
MapAnimations::TemporaryType type{};
2025-05-21 06:48:58 +01:00
bool operator<(const TemporaryMapAnimation& rhs) const
{
return std::tie(location.y, location.x, type, location.z)
< std::tie(rhs.location.y, rhs.location.x, rhs.type, rhs.location.z);
}
};
enum class UpdateType : uint8_t
{
invalidate,
update,
};
struct TileCoordsXYCmp
{
constexpr bool operator()(const TileCoordsXY& lhs, const TileCoordsXY& rhs) const noexcept
{
// NOTE: Ordering should match GetFirstElementAt which is x + (y * size)
return std::tie(lhs.y, lhs.x) < std::tie(rhs.y, rhs.x);
}
};
static std::set<TileCoordsXY, TileCoordsXYCmp> _mapAnimationsInvalidate;
static std::set<TileCoordsXY, TileCoordsXYCmp> _mapAnimationsUpdate;
2025-05-21 06:48:58 +01:00
static std::set<TemporaryMapAnimation> _temporaryMapAnimations;
template<bool invalidateAllViewports>
static void Invalidate(const Viewport& viewport, const int32_t x, const int32_t y, const int32_t z0, const int32_t z1)
{
if constexpr (invalidateAllViewports)
{
ViewportsInvalidate(x, y, z0, z1, kMaxZoom);
}
else
{
viewport.Invalidate(x, y, z0, z1, kMaxZoom);
}
}
template<bool invalidate, bool invalidateAllViewports>
static bool UpdateEntranceAnimation(
const EntranceElement& entrance, const CoordsXYZ& loc, const int32_t baseZ, const Viewport& viewport)
{
if (entrance.GetEntranceType() == ENTRANCE_TYPE_RIDE_ENTRANCE)
{
const auto ride = GetRide(entrance.GetRideIndex());
if (ride != nullptr)
{
const auto stationObj = ride->getStationObject();
if (stationObj != nullptr)
{
if constexpr (invalidate)
{
Invalidate<invalidateAllViewports>(
viewport, loc.x, loc.y, baseZ + stationObj->Height + 8, baseZ + stationObj->Height + 24);
}
return true;
}
}
}
else if (entrance.GetEntranceType() == ENTRANCE_TYPE_PARK_ENTRANCE && entrance.GetSequenceIndex() == 0)
{
if constexpr (invalidate)
{
const int32_t direction = (entrance.GetDirection() + GetCurrentRotation()) & 3;
if (direction == TILE_ELEMENT_DIRECTION_SOUTH || direction == TILE_ELEMENT_DIRECTION_WEST)
{
Invalidate<invalidateAllViewports>(viewport, loc.x, loc.y, baseZ + 32, baseZ + 64);
}
}
return true;
}
return false;
}
template<bool invalidate, bool invalidateAllViewports>
static bool UpdatePathAnimation(const PathElement& path, const CoordsXYZ& loc, const int32_t baseZ, const Viewport& viewport)
{
if (path.IsQueue() && path.HasQueueBanner())
{
if constexpr (invalidate)
{
const int32_t direction = (path.GetQueueBannerDirection() + GetCurrentRotation()) & 3;
if (direction == TILE_ELEMENT_DIRECTION_NORTH || direction == TILE_ELEMENT_DIRECTION_EAST)
{
Invalidate<invalidateAllViewports>(viewport, loc.x, loc.y, baseZ + 16, baseZ + 30);
}
}
return true;
}
return false;
}
template<bool invalidate, bool invalidateAllViewports>
static std::optional<UpdateType> UpdateSmallSceneryAnimation(
const SmallSceneryElement& scenery, const CoordsXYZ& loc, const int32_t baseZ, const Viewport& viewport)
{
const auto entry = scenery.GetEntry();
if (entry == nullptr)
2018-06-22 23:17:03 +02:00
{
return std::nullopt;
}
if (entry->HasFlag(
SMALL_SCENERY_FLAG_FOUNTAIN_SPRAY_1 | SMALL_SCENERY_FLAG_FOUNTAIN_SPRAY_4 | SMALL_SCENERY_FLAG_SWAMP_GOO
| SMALL_SCENERY_FLAG_HAS_FRAME_OFFSETS | SMALL_SCENERY_FLAG_IS_CLOCK))
2018-06-22 23:17:03 +02:00
{
auto animationType = UpdateType::invalidate;
if (entry->HasFlag(SMALL_SCENERY_FLAG_IS_CLOCK))
2018-06-22 23:17:03 +02:00
{
animationType = UpdateType::update;
// Don't apply anything to peeps when the scenery is a ghost.
if (!scenery.IsGhost() && !(getGameState().currentTicks & 0x3FF))
2018-06-22 23:17:03 +02:00
{
const int32_t direction = scenery.GetDirection();
auto quad = EntityTileList<Peep>(CoordsXY{ loc.x, loc.y } - CoordsDirectionDelta[direction]);
2020-06-08 20:13:50 +01:00
for (auto peep : quad)
2018-06-22 23:17:03 +02:00
{
if (peep->State != PeepState::Walking || peep->z != baseZ || peep->Action < PeepActionType::Idle)
2017-06-06 23:24:18 +02:00
continue;
peep->Action = PeepActionType::CheckTime;
2024-09-22 16:12:04 +02:00
peep->AnimationFrameNum = 0;
peep->AnimationImageIdOffset = 0;
peep->UpdateCurrentAnimationType();
if constexpr (invalidate)
{
peep->Invalidate();
}
2017-06-06 23:24:18 +02:00
break;
}
if constexpr (invalidate)
{
Invalidate<invalidateAllViewports>(viewport, loc.x, loc.y, baseZ, scenery.GetClearanceZ());
}
2017-06-06 23:24:18 +02:00
}
}
else if constexpr (invalidate)
{
Invalidate<invalidateAllViewports>(viewport, loc.x, loc.y, baseZ, scenery.GetClearanceZ());
}
return std::optional(animationType);
}
2017-10-15 15:53:16 +02:00
return std::nullopt;
}
template<bool invalidate, bool invalidateAllViewports>
static bool UpdateTrackAnimation(TrackElement& track, const CoordsXYZ& loc, const int32_t baseZ, const Viewport& viewport)
{
switch (track.GetTrackType())
2018-06-22 23:17:03 +02:00
{
case TrackElemType::Waterfall:
if constexpr (invalidate)
{
Invalidate<invalidateAllViewports>(viewport, loc.x, loc.y, baseZ + 14, baseZ + 46);
}
return true;
case TrackElemType::Rapids:
case TrackElemType::Whirlpool:
if constexpr (invalidate)
{
Invalidate<invalidateAllViewports>(viewport, loc.x, loc.y, baseZ + 14, baseZ + 18);
}
return true;
case TrackElemType::SpinningTunnel:
if constexpr (invalidate)
{
Invalidate<invalidateAllViewports>(viewport, loc.x, loc.y, baseZ + 14, baseZ + 32);
}
return true;
default:
break;
}
return false;
}
template<bool invalidate, bool invalidateAllViewports>
static bool UpdateLargeSceneryAnimation(
const LargeSceneryElement& scenery, const CoordsXYZ& loc, const int32_t baseZ, const Viewport& viewport)
{
const auto entry = scenery.GetEntry();
if (entry != nullptr && (entry->flags & LARGE_SCENERY_FLAG_ANIMATED))
{
if constexpr (invalidate)
{
Invalidate<invalidateAllViewports>(viewport, loc.x, loc.y, baseZ, baseZ + 16);
}
return true;
}
return false;
}
template<bool invalidate, bool invalidateAllViewports>
static std::optional<UpdateType> UpdateWallAnimation(
WallElement& wall, const CoordsXYZ& loc, const int32_t baseZ, const Viewport& viewport)
{
const auto entry = wall.GetEntry();
if (entry == nullptr)
{
return std::nullopt;
}
2025-05-19 16:42:50 +01:00
if (entry->flags & WALL_SCENERY_IS_DOOR && wall.IsAnimating())
2018-06-22 23:17:03 +02:00
{
if (getGameState().currentTicks & 1)
2018-06-22 23:17:03 +02:00
{
return std::optional(UpdateType::update);
2017-06-06 23:24:18 +02:00
}
bool removeAnim = true;
const auto currentFrame = wall.GetAnimationFrame();
2018-06-22 23:17:03 +02:00
if (currentFrame != 0)
{
auto newFrame = currentFrame;
2018-06-22 23:17:03 +02:00
if (currentFrame == 15)
{
newFrame = 0;
2025-05-19 16:42:50 +01:00
wall.SetIsAnimating(false);
2018-06-22 23:17:03 +02:00
}
else
{
removeAnim = false;
2018-06-22 23:17:03 +02:00
if (currentFrame != 5)
{
newFrame++;
2017-02-18 08:26:33 +00:00
if (newFrame == 13 && !(entry->flags & WALL_SCENERY_LONG_DOOR_ANIMATION))
newFrame = 15;
2017-06-06 23:24:18 +02:00
}
}
if (currentFrame != newFrame)
{
wall.SetAnimationFrame(newFrame);
if constexpr (invalidate)
{
Invalidate<invalidateAllViewports>(viewport, loc.x, loc.y, baseZ, baseZ + 32);
}
}
2017-06-06 23:24:18 +02:00
}
return removeAnim ? std::nullopt : std::optional(UpdateType::update);
}
else if ((entry->flags2 & WALL_SCENERY_2_ANIMATED) || entry->scrolling_mode != kScrollingModeNone)
{
if constexpr (invalidate)
{
Invalidate<invalidateAllViewports>(viewport, loc.x, loc.y, baseZ, baseZ + 16);
}
return std::optional(UpdateType::invalidate);
}
return std::nullopt;
}
template<bool invalidate, bool invalidateAllViewports>
static bool UpdateBannerAnimation(
[[maybe_unused]] const BannerElement& banner, const CoordsXYZ& loc, const int32_t baseZ, const Viewport& viewport)
{
if constexpr (invalidate)
{
Invalidate<invalidateAllViewports>(viewport, loc.x, loc.y, baseZ, baseZ + 16);
}
return true;
}
2018-06-22 23:17:03 +02:00
template<bool invalidate, bool invalidateAllViewports>
static std::optional<UpdateType> UpdateTile(const TileCoordsXY& coords, const Viewport& viewport)
{
auto tileElement = MapGetFirstElementAt(coords);
if (tileElement == nullptr)
{
return std::nullopt;
}
bool hasAnimations = false;
auto updateType = UpdateType::invalidate;
do
{
const auto baseZ = tileElement->GetBaseZ();
const CoordsXYZ loc{ coords.ToCoordsXY(), baseZ };
switch (tileElement->GetType())
{
case TileElementType::Entrance:
hasAnimations |= UpdateEntranceAnimation<invalidate, invalidateAllViewports>(
*tileElement->AsEntrance(), loc, baseZ, viewport);
break;
case TileElementType::Path:
hasAnimations |= UpdatePathAnimation<invalidate, invalidateAllViewports>(
*tileElement->AsPath(), loc, baseZ, viewport);
break;
case TileElementType::SmallScenery:
{
const auto result = UpdateSmallSceneryAnimation<invalidate, invalidateAllViewports>(
*tileElement->AsSmallScenery(), loc, baseZ, viewport);
if (result)
{
hasAnimations |= true;
if (result.value() == UpdateType::update)
{
updateType = UpdateType::update;
}
}
break;
}
case TileElementType::Track:
hasAnimations |= UpdateTrackAnimation<invalidate, invalidateAllViewports>(
*tileElement->AsTrack(), loc, baseZ, viewport);
break;
case TileElementType::Banner:
hasAnimations |= UpdateBannerAnimation<invalidate, invalidateAllViewports>(
*tileElement->AsBanner(), loc, baseZ, viewport);
break;
case TileElementType::LargeScenery:
hasAnimations |= UpdateLargeSceneryAnimation<invalidate, invalidateAllViewports>(
*tileElement->AsLargeScenery(), loc, baseZ, viewport);
break;
case TileElementType::Wall:
{
const auto result = UpdateWallAnimation<invalidate, invalidateAllViewports>(
*tileElement->AsWall(), loc, baseZ, viewport);
if (result)
{
hasAnimations |= true;
if (result.value() == UpdateType::update)
{
updateType = UpdateType::update;
}
}
break;
}
default:
break;
}
} while (!(tileElement++)->IsLastForTile());
return hasAnimations ? std::optional(updateType) : std::nullopt;
}
2025-05-21 06:48:58 +01:00
static bool UpdateOnRidePhotoAnimation(TrackElement& track, const CoordsXYZ& coords)
{
if (track.IsTakingPhoto())
{
track.DecrementPhotoTimeout();
ViewportsInvalidate(coords.x, coords.y, coords.z, track.GetClearanceZ(), kMaxZoom);
2025-05-21 06:48:58 +01:00
return true;
}
return false;
}
2025-05-19 23:07:34 +01:00
static bool UpdateLandEdgeDoorsAnimation(TrackElement& track, const CoordsXYZ& coords)
{
if (getGameState().currentTicks & 3)
{
return true;
}
bool isAnimating = false;
const auto doorAState = track.GetDoorAState();
if (doorAState >= kLandEdgeDoorFrameEnd)
{
track.SetDoorAState(kLandEdgeDoorFrameClosed);
ViewportsInvalidate(coords.x, coords.y, coords.z, coords.z + 32, kMaxZoom);
2025-05-19 23:07:34 +01:00
}
else if (doorAState != kLandEdgeDoorFrameClosed && doorAState != kLandEdgeDoorFrameOpen)
{
track.SetDoorAState(doorAState + 1);
ViewportsInvalidate(coords.x, coords.y, coords.z, coords.z + 32, kMaxZoom);
2025-05-19 23:07:34 +01:00
isAnimating = true;
}
const auto doorBState = track.GetDoorBState();
if (doorBState >= kLandEdgeDoorFrameEnd)
{
track.SetDoorBState(kLandEdgeDoorFrameClosed);
ViewportsInvalidate(coords.x, coords.y, coords.z, coords.z + 32, kMaxZoom);
2025-05-19 23:07:34 +01:00
}
else if (doorBState != kLandEdgeDoorFrameClosed && doorBState != kLandEdgeDoorFrameOpen)
{
track.SetDoorBState(doorBState + 1);
ViewportsInvalidate(coords.x, coords.y, coords.z, coords.z + 32, kMaxZoom);
2025-05-19 23:07:34 +01:00
isAnimating = true;
}
return isAnimating;
}
2025-05-21 06:48:58 +01:00
static bool UpdateTemporaryAnimation(const TemporaryMapAnimation& animation)
{
const TileCoordsXYZ tileCoords{ animation.location };
TileElement* tileElement = MapGetFirstElementAt(tileCoords);
if (tileElement == nullptr)
{
return true;
}
2025-05-19 23:07:34 +01:00
bool isAnimating = false;
2025-05-21 06:48:58 +01:00
do
{
switch (animation.type)
{
case MapAnimations::TemporaryType::onRidePhoto:
2025-05-21 06:48:58 +01:00
{
if (tileElement->GetType() == TileElementType::Track && tileElement->BaseHeight == tileCoords.z
&& tileElement->AsTrack()->GetTrackType() == TrackElemType::OnRidePhoto)
{
2025-05-19 23:07:34 +01:00
isAnimating |= UpdateOnRidePhotoAnimation(*tileElement->AsTrack(), animation.location);
2025-05-21 06:48:58 +01:00
}
break;
}
case MapAnimations::TemporaryType::landEdgeDoor:
2025-05-19 23:07:34 +01:00
{
if (tileElement->GetType() == TileElementType::Track && tileElement->BaseHeight == tileCoords.z)
{
isAnimating |= UpdateLandEdgeDoorsAnimation(*tileElement->AsTrack(), animation.location);
}
}
2025-05-21 06:48:58 +01:00
}
} while (!(tileElement++)->IsLastForTile());
2025-05-19 23:07:34 +01:00
return isAnimating;
2025-05-21 06:48:58 +01:00
}
static std::optional<UpdateType> IsElementAnimated(const TileElementBase& element)
{
switch (element.GetType())
{
case TileElementType::Banner:
return std::optional(UpdateType::invalidate);
case TileElementType::Wall:
{
const auto wall = element.AsWall();
const auto entry = wall->GetEntry();
if (entry != nullptr)
{
if ((entry->flags2 & WALL_SCENERY_2_ANIMATED) || entry->scrolling_mode != kScrollingModeNone)
{
return std::optional(UpdateType::invalidate);
}
2025-05-19 16:42:50 +01:00
if (entry->flags & WALL_SCENERY_IS_DOOR && wall->IsAnimating())
{
return std::optional(UpdateType::update);
}
}
break;
}
case TileElementType::SmallScenery:
{
const auto scenery = element.AsSmallScenery();
const auto entry = scenery->GetEntry();
if (entry != nullptr && entry->HasFlag(SMALL_SCENERY_FLAG_ANIMATED))
{
if (entry->HasFlag(SMALL_SCENERY_FLAG_IS_CLOCK))
{
return std::optional(UpdateType::update);
}
else
{
return std::optional(UpdateType::invalidate);
}
}
break;
}
case TileElementType::LargeScenery:
{
const auto scenery = element.AsLargeScenery();
const auto entry = scenery->GetEntry();
if (entry != nullptr && (entry->flags & LARGE_SCENERY_FLAG_ANIMATED))
{
return std::optional(UpdateType::invalidate);
}
break;
}
case TileElementType::Path:
{
const auto path = element.AsPath();
if (path->HasQueueBanner())
{
return std::optional(UpdateType::invalidate);
}
break;
}
case TileElementType::Entrance:
{
const auto entrance = element.AsEntrance();
if (entrance->GetEntranceType() == ENTRANCE_TYPE_PARK_ENTRANCE && entrance->GetSequenceIndex() == 0)
{
return std::optional(UpdateType::invalidate);
}
else if (entrance->GetEntranceType() == ENTRANCE_TYPE_RIDE_ENTRANCE)
{
return std::optional(UpdateType::invalidate);
}
break;
}
case TileElementType::Track:
{
const auto track = element.AsTrack();
switch (track->GetTrackType())
{
case TrackElemType::Waterfall:
case TrackElemType::Rapids:
case TrackElemType::Whirlpool:
case TrackElemType::SpinningTunnel:
return std::optional(UpdateType::invalidate);
2024-10-11 15:30:27 +02:00
default:
break;
}
break;
}
default:
break;
}
return std::nullopt;
}
void MapAnimations::MarkTileForInvalidation(const CoordsXY coords)
{
const TileCoordsXY tileCoords(coords);
if (!_mapAnimationsUpdate.contains(tileCoords))
{
_mapAnimationsInvalidate.insert(tileCoords);
}
}
void MapAnimations::MarkTileForUpdate(const CoordsXY coords)
{
const TileCoordsXY tileCoords(coords);
_mapAnimationsInvalidate.erase(tileCoords);
_mapAnimationsUpdate.insert(tileCoords);
}
void MapAnimations::CreateTemporary(const CoordsXYZ& coords, const TemporaryType type)
2025-05-21 06:48:58 +01:00
{
_temporaryMapAnimations.insert(TemporaryMapAnimation{ coords, type });
}
void MapAnimations::MarkAllTiles()
{
TileElementIterator it;
TileElementIteratorBegin(&it);
while (TileElementIteratorNext(&it))
{
const auto isAnimated = IsElementAnimated(*it.element);
if (isAnimated)
{
switch (*isAnimated)
{
case UpdateType::invalidate:
MarkTileForInvalidation(TileCoordsXY(it.x, it.y).ToCoordsXY());
break;
case UpdateType::update:
MarkTileForUpdate(TileCoordsXY(it.x, it.y).ToCoordsXY());
break;
}
}
}
2018-01-11 10:59:26 +01:00
}
static void InvalidateAll(const ViewportList& viewports)
2025-05-21 06:48:58 +01:00
{
for (const auto viewport : viewports)
2025-05-21 06:48:58 +01:00
{
// Code adapted from PaintSessionGenerateRotate.
// Ideally this would iterate over tiles in memory order.
constexpr const int32_t kTileWidth = 64;
constexpr const int32_t kTileWidthHalf = kTileWidth / 2;
constexpr const int32_t kTileHeightHalf = 16;
constexpr const int32_t maxTileHeightModifier = 88; // from magic value in PaintSessionGenerateRotate
constexpr const int32_t maxTileHeight = (kMaxTileElementHeight * kCoordsZStep) + maxTileHeightModifier;
const auto direction = DirectionFlipXAxis(viewport->rotation);
const int32_t numVerticalTiles = (viewport->ViewHeight() + maxTileHeight) >> 5;
const TileCoordsXY nextVerticalTile = TileCoordsXY{ 1, 1 }.Rotate(direction);
const int32_t screenCoordY = Numerics::floor2((viewport->viewPos.y - kTileHeightHalf), kTileWidthHalf);
for (int32_t x = viewport->viewPos.x; x < viewport->viewPos.x + viewport->ViewWidth() + kTileWidth; x += kTileWidthHalf)
{
const ScreenCoordsXY screenCoord = { Numerics::floor2(x, kTileWidthHalf), screenCoordY };
CoordsXY mapTile = { screenCoord.y - screenCoord.x / 2, screenCoord.y + screenCoord.x / 2 };
mapTile = mapTile.Rotate(direction);
if (direction & 1)
{
mapTile.y -= 16;
}
mapTile = mapTile.ToTileStart();
TileCoordsXY tileCoords(mapTile);
for (int32_t i = 0; i < numVerticalTiles; ++i)
{
if (_mapAnimationsInvalidate.contains(tileCoords))
{
if (!UpdateTile<true, false>(tileCoords, *viewport))
{
_mapAnimationsInvalidate.erase(tileCoords);
}
}
tileCoords += nextVerticalTile;
}
}
}
}
static bool IsTileVisible(const ViewportList& viewports, const TileCoordsXY tileCoords)
{
for (const auto viewport : viewports)
{
if (viewport->ContainsTile(tileCoords))
2025-05-21 06:48:58 +01:00
{
return true;
2025-05-21 06:48:58 +01:00
}
}
return false;
2025-05-21 06:48:58 +01:00
}
static void UpdateAll(const ViewportList& viewports)
{
auto it = _mapAnimationsUpdate.begin();
while (it != _mapAnimationsUpdate.end())
{
const bool isVisible = IsTileVisible(viewports, *it);
const auto result = isVisible ? UpdateTile<true, true>(*it, *viewports.front())
: UpdateTile<false, true>(*it, *viewports.front());
if (result)
{
if (result.value() == UpdateType::invalidate)
{
_mapAnimationsInvalidate.insert(*it);
it = _mapAnimationsUpdate.erase(it);
}
else
{
++it;
}
}
else
{
it = _mapAnimationsUpdate.erase(it);
}
}
}
static void UpdateAllTemporary()
{
auto it = _temporaryMapAnimations.begin();
while (it != _temporaryMapAnimations.end())
{
if (UpdateTemporaryAnimation(*it))
{
++it;
}
else
{
it = _temporaryMapAnimations.erase(it);
}
}
}
void MapAnimations::InvalidateAndUpdateAll()
{
PROFILED_FUNCTION();
const auto viewports = GetVisibleViewports();
InvalidateAll(viewports);
UpdateAll(viewports);
UpdateAllTemporary();
}
void MapAnimations::ClearAll()
{
_mapAnimationsInvalidate.clear();
_mapAnimationsUpdate.clear();
2025-05-21 06:48:58 +01:00
_temporaryMapAnimations.clear();
}
void MapAnimations::ShiftAll(const CoordsXY amount)
{
if (amount.x == 0 && amount.y == 0)
return;
std::set<TileCoordsXY, TileCoordsXYCmp> newMapAnimationsInvalidate;
for (const auto a : _mapAnimationsInvalidate)
{
newMapAnimationsInvalidate.insert(a + TileCoordsXY(amount));
}
_mapAnimationsInvalidate = std::move(newMapAnimationsInvalidate);
std::set<TileCoordsXY, TileCoordsXYCmp> newMapAnimationsUpdate;
for (const auto a : _mapAnimationsUpdate)
{
newMapAnimationsUpdate.insert(a + TileCoordsXY(amount));
}
_mapAnimationsUpdate = std::move(newMapAnimationsUpdate);
2025-05-21 06:48:58 +01:00
std::set<TemporaryMapAnimation> newTemporaryMapAnimations;
for (const auto& a : _temporaryMapAnimations)
{
newTemporaryMapAnimations.insert(TemporaryMapAnimation{ a.location + CoordsXYZ(amount, 0), a.type });
}
_temporaryMapAnimations = std::move(newTemporaryMapAnimations);
}