2015-03-18 19:52:27 +00:00
|
|
|
/*****************************************************************************
|
2024-12-31 20:30:04 +01:00
|
|
|
* Copyright (c) 2014-2025 OpenRCT2 developers
|
2015-03-18 19:52:27 +00:00
|
|
|
*
|
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
|
2015-03-18 19:52:27 +00:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2015-03-18 19:52:27 +00:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
2018-06-22 23:17:03 +02:00
|
|
|
#include "MapAnimation.h"
|
2018-03-14 12:44:16 +01:00
|
|
|
|
2018-12-05 20:33:45 +00: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"
|
2023-12-28 00:53:43 +02:00
|
|
|
#include "../GameState.h"
|
2025-05-23 15:53:12 +01:00
|
|
|
#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"
|
2023-01-25 19:25:33 +00:00
|
|
|
#include "../object/SmallSceneryEntry.h"
|
2018-12-05 20:33:45 +00:00
|
|
|
#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"
|
2024-10-14 14:26:10 +02:00
|
|
|
#include "tile_element/TrackElement.h"
|
2024-10-03 21:09:30 +01:00
|
|
|
#include "tile_element/WallElement.h"
|
2018-06-22 23:17:03 +02:00
|
|
|
|
2025-05-07 01:40:11 +03:00
|
|
|
#include <algorithm>
|
|
|
|
|
#include <set>
|
|
|
|
|
|
2023-12-28 00:53:43 +02:00
|
|
|
using namespace OpenRCT2;
|
|
|
|
|
|
2025-05-23 04:53:21 +01:00
|
|
|
constexpr ZoomLevel kMaxZoom{ 1 };
|
|
|
|
|
|
2025-05-21 06:48:58 +01:00
|
|
|
struct TemporaryMapAnimation
|
|
|
|
|
{
|
|
|
|
|
CoordsXYZ location{};
|
2025-05-23 22:08:09 +01:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-05-22 23:14:56 +01:00
|
|
|
enum class UpdateType : uint8_t
|
|
|
|
|
{
|
|
|
|
|
invalidate,
|
|
|
|
|
update,
|
|
|
|
|
};
|
|
|
|
|
|
2025-05-07 01:40:11 +03:00
|
|
|
struct TileCoordsXYCmp
|
2019-08-03 21:18:33 +01:00
|
|
|
{
|
2025-05-07 01:40:11 +03:00
|
|
|
constexpr bool operator()(const TileCoordsXY& lhs, const TileCoordsXY& rhs) const noexcept
|
2019-08-03 21:18:33 +01:00
|
|
|
{
|
2025-05-07 01:40:11 +03:00
|
|
|
// NOTE: Ordering should match GetFirstElementAt which is x + (y * size)
|
|
|
|
|
return std::tie(lhs.y, lhs.x) < std::tie(rhs.y, rhs.x);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-05-23 15:53:12 +01:00
|
|
|
static std::set<TileCoordsXY, TileCoordsXYCmp> _mapAnimationsInvalidate;
|
|
|
|
|
static std::set<TileCoordsXY, TileCoordsXYCmp> _mapAnimationsUpdate;
|
2025-05-07 01:40:11 +03:00
|
|
|
|
2025-05-21 06:48:58 +01:00
|
|
|
static std::set<TemporaryMapAnimation> _temporaryMapAnimations;
|
|
|
|
|
|
2025-05-24 05:01:36 +01:00
|
|
|
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)
|
2025-05-07 01:40:11 +03:00
|
|
|
{
|
|
|
|
|
if (entrance.GetEntranceType() == ENTRANCE_TYPE_RIDE_ENTRANCE)
|
|
|
|
|
{
|
|
|
|
|
const auto ride = GetRide(entrance.GetRideIndex());
|
|
|
|
|
if (ride != nullptr)
|
2019-08-03 21:18:33 +01:00
|
|
|
{
|
2025-05-07 01:40:11 +03:00
|
|
|
const auto stationObj = ride->getStationObject();
|
|
|
|
|
if (stationObj != nullptr)
|
|
|
|
|
{
|
2025-05-23 15:53:12 +01:00
|
|
|
if constexpr (invalidate)
|
|
|
|
|
{
|
2025-05-24 05:01:36 +01:00
|
|
|
Invalidate<invalidateAllViewports>(
|
|
|
|
|
viewport, loc.x, loc.y, baseZ + stationObj->Height + 8, baseZ + stationObj->Height + 24);
|
2025-05-23 15:53:12 +01:00
|
|
|
}
|
2025-05-07 01:40:11 +03:00
|
|
|
return true;
|
|
|
|
|
}
|
2019-08-03 21:18:33 +01:00
|
|
|
}
|
|
|
|
|
}
|
2025-05-07 01:40:11 +03:00
|
|
|
else if (entrance.GetEntranceType() == ENTRANCE_TYPE_PARK_ENTRANCE && entrance.GetSequenceIndex() == 0)
|
|
|
|
|
{
|
2025-05-23 15:53:12 +01:00
|
|
|
if constexpr (invalidate)
|
2025-05-07 01:40:11 +03:00
|
|
|
{
|
2025-05-23 15:53:12 +01:00
|
|
|
const int32_t direction = (entrance.GetDirection() + GetCurrentRotation()) & 3;
|
|
|
|
|
if (direction == TILE_ELEMENT_DIRECTION_SOUTH || direction == TILE_ELEMENT_DIRECTION_WEST)
|
|
|
|
|
{
|
2025-05-24 05:01:36 +01:00
|
|
|
Invalidate<invalidateAllViewports>(viewport, loc.x, loc.y, baseZ + 32, baseZ + 64);
|
2025-05-23 15:53:12 +01:00
|
|
|
}
|
2025-05-07 01:40:11 +03:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-24 05:01:36 +01:00
|
|
|
template<bool invalidate, bool invalidateAllViewports>
|
|
|
|
|
static bool UpdatePathAnimation(const PathElement& path, const CoordsXYZ& loc, const int32_t baseZ, const Viewport& viewport)
|
2025-05-07 01:40:11 +03:00
|
|
|
{
|
|
|
|
|
if (path.IsQueue() && path.HasQueueBanner())
|
|
|
|
|
{
|
2025-05-23 15:53:12 +01:00
|
|
|
if constexpr (invalidate)
|
2025-05-07 01:40:11 +03:00
|
|
|
{
|
2025-05-23 15:53:12 +01:00
|
|
|
const int32_t direction = (path.GetQueueBannerDirection() + GetCurrentRotation()) & 3;
|
|
|
|
|
if (direction == TILE_ELEMENT_DIRECTION_NORTH || direction == TILE_ELEMENT_DIRECTION_EAST)
|
|
|
|
|
{
|
2025-05-24 05:01:36 +01:00
|
|
|
Invalidate<invalidateAllViewports>(viewport, loc.x, loc.y, baseZ + 16, baseZ + 30);
|
2025-05-23 15:53:12 +01:00
|
|
|
}
|
2025-05-07 01:40:11 +03:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-08-03 21:18:33 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2015-03-18 19:52:27 +00:00
|
|
|
|
2025-05-24 05:01:36 +01:00
|
|
|
template<bool invalidate, bool invalidateAllViewports>
|
2025-05-22 23:14:56 +01:00
|
|
|
static std::optional<UpdateType> UpdateSmallSceneryAnimation(
|
2025-05-24 05:01:36 +01:00
|
|
|
const SmallSceneryElement& scenery, const CoordsXYZ& loc, const int32_t baseZ, const Viewport& viewport)
|
2015-03-22 01:19:23 +00:00
|
|
|
{
|
2025-05-07 01:40:11 +03:00
|
|
|
const auto entry = scenery.GetEntry();
|
|
|
|
|
if (entry == nullptr)
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
2025-05-22 23:14:56 +01:00
|
|
|
return std::nullopt;
|
2025-05-07 01:40:11 +03:00
|
|
|
}
|
2015-03-18 19:52:27 +00:00
|
|
|
|
2025-05-07 01:40:11 +03:00
|
|
|
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
|
|
|
{
|
2025-05-23 15:53:12 +01:00
|
|
|
auto animationType = UpdateType::invalidate;
|
|
|
|
|
if (entry->HasFlag(SMALL_SCENERY_FLAG_IS_CLOCK))
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
2025-05-23 15:53:12 +01: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
|
|
|
{
|
2025-05-07 01:40:11 +03: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
|
|
|
{
|
2025-05-07 01:40:11 +03:00
|
|
|
if (peep->State != PeepState::Walking || peep->z != baseZ || peep->Action < PeepActionType::Idle)
|
2017-06-06 23:24:18 +02:00
|
|
|
continue;
|
2020-09-30 18:19:10 -03:00
|
|
|
peep->Action = PeepActionType::CheckTime;
|
2024-09-22 16:12:04 +02:00
|
|
|
peep->AnimationFrameNum = 0;
|
2024-09-22 16:13:49 +02:00
|
|
|
peep->AnimationImageIdOffset = 0;
|
2024-09-22 16:08:58 +02:00
|
|
|
peep->UpdateCurrentAnimationType();
|
2025-05-23 15:53:12 +01:00
|
|
|
if constexpr (invalidate)
|
|
|
|
|
{
|
|
|
|
|
peep->Invalidate();
|
|
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2025-05-24 03:57:48 +01:00
|
|
|
if constexpr (invalidate)
|
|
|
|
|
{
|
2025-05-24 05:01:36 +01:00
|
|
|
Invalidate<invalidateAllViewports>(viewport, loc.x, loc.y, baseZ, scenery.GetClearanceZ());
|
2025-05-24 03:57:48 +01:00
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
2025-05-24 03:57:48 +01:00
|
|
|
else if constexpr (invalidate)
|
2025-05-23 15:53:12 +01:00
|
|
|
{
|
2025-05-24 05:01:36 +01:00
|
|
|
Invalidate<invalidateAllViewports>(viewport, loc.x, loc.y, baseZ, scenery.GetClearanceZ());
|
2025-05-23 15:53:12 +01:00
|
|
|
}
|
2025-05-22 23:14:56 +01:00
|
|
|
return std::optional(animationType);
|
2025-05-07 01:40:11 +03:00
|
|
|
}
|
2017-10-15 15:53:16 +02:00
|
|
|
|
2025-05-22 23:14:56 +01:00
|
|
|
return std::nullopt;
|
2015-03-18 19:52:27 +00:00
|
|
|
}
|
|
|
|
|
|
2025-05-24 05:01:36 +01:00
|
|
|
template<bool invalidate, bool invalidateAllViewports>
|
|
|
|
|
static bool UpdateTrackAnimation(TrackElement& track, const CoordsXYZ& loc, const int32_t baseZ, const Viewport& viewport)
|
2015-03-18 19:52:27 +00:00
|
|
|
{
|
2025-05-07 01:40:11 +03:00
|
|
|
switch (track.GetTrackType())
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
2025-05-07 01:40:11 +03:00
|
|
|
case TrackElemType::Waterfall:
|
2025-05-23 15:53:12 +01:00
|
|
|
if constexpr (invalidate)
|
|
|
|
|
{
|
2025-05-24 05:01:36 +01:00
|
|
|
Invalidate<invalidateAllViewports>(viewport, loc.x, loc.y, baseZ + 14, baseZ + 46);
|
2025-05-23 15:53:12 +01:00
|
|
|
}
|
2025-05-07 01:40:11 +03:00
|
|
|
return true;
|
|
|
|
|
case TrackElemType::Rapids:
|
|
|
|
|
case TrackElemType::Whirlpool:
|
2025-05-23 15:53:12 +01:00
|
|
|
if constexpr (invalidate)
|
|
|
|
|
{
|
2025-05-24 05:01:36 +01:00
|
|
|
Invalidate<invalidateAllViewports>(viewport, loc.x, loc.y, baseZ + 14, baseZ + 18);
|
2025-05-23 15:53:12 +01:00
|
|
|
}
|
2025-05-07 01:40:11 +03:00
|
|
|
return true;
|
|
|
|
|
case TrackElemType::SpinningTunnel:
|
2025-05-23 15:53:12 +01:00
|
|
|
if constexpr (invalidate)
|
|
|
|
|
{
|
2025-05-24 05:01:36 +01:00
|
|
|
Invalidate<invalidateAllViewports>(viewport, loc.x, loc.y, baseZ + 14, baseZ + 32);
|
2025-05-23 15:53:12 +01:00
|
|
|
}
|
2025-05-07 01:40:11 +03:00
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-03-18 19:52:27 +00:00
|
|
|
|
2025-05-07 01:40:11 +03:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-24 05:01:36 +01:00
|
|
|
template<bool invalidate, bool invalidateAllViewports>
|
|
|
|
|
static bool UpdateLargeSceneryAnimation(
|
|
|
|
|
const LargeSceneryElement& scenery, const CoordsXYZ& loc, const int32_t baseZ, const Viewport& viewport)
|
2025-05-07 01:40:11 +03:00
|
|
|
{
|
|
|
|
|
const auto entry = scenery.GetEntry();
|
|
|
|
|
if (entry != nullptr && (entry->flags & LARGE_SCENERY_FLAG_ANIMATED))
|
|
|
|
|
{
|
2025-05-23 15:53:12 +01:00
|
|
|
if constexpr (invalidate)
|
|
|
|
|
{
|
2025-05-24 05:01:36 +01:00
|
|
|
Invalidate<invalidateAllViewports>(viewport, loc.x, loc.y, baseZ, baseZ + 16);
|
2025-05-23 15:53:12 +01:00
|
|
|
}
|
2025-05-07 01:40:11 +03:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-24 05:01:36 +01:00
|
|
|
template<bool invalidate, bool invalidateAllViewports>
|
|
|
|
|
static std::optional<UpdateType> UpdateWallAnimation(
|
|
|
|
|
WallElement& wall, const CoordsXYZ& loc, const int32_t baseZ, const Viewport& viewport)
|
2025-05-07 01:40:11 +03:00
|
|
|
{
|
|
|
|
|
const auto entry = wall.GetEntry();
|
|
|
|
|
if (entry == nullptr)
|
|
|
|
|
{
|
2025-05-22 23:14:56 +01:00
|
|
|
return std::nullopt;
|
2025-05-07 01:40:11 +03:00
|
|
|
}
|
2015-03-18 19:52:27 +00:00
|
|
|
|
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
|
|
|
{
|
2025-05-07 01:40:11 +03:00
|
|
|
if (getGameState().currentTicks & 1)
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
2025-05-22 23:14:56 +01:00
|
|
|
return std::optional(UpdateType::update);
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2015-03-22 01:19:23 +00:00
|
|
|
|
2025-05-07 01:40:11 +03:00
|
|
|
bool removeAnim = true;
|
2015-03-22 01:19:23 +00:00
|
|
|
|
2025-05-07 01:40:11 +03:00
|
|
|
const auto currentFrame = wall.GetAnimationFrame();
|
2018-06-22 23:17:03 +02:00
|
|
|
if (currentFrame != 0)
|
|
|
|
|
{
|
2025-05-07 01:40:11 +03:00
|
|
|
auto newFrame = currentFrame;
|
2018-06-22 23:17:03 +02:00
|
|
|
if (currentFrame == 15)
|
|
|
|
|
{
|
2025-05-07 01:40:11 +03:00
|
|
|
newFrame = 0;
|
2025-05-19 16:42:50 +01:00
|
|
|
wall.SetIsAnimating(false);
|
2018-06-22 23:17:03 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-05-07 01:40:11 +03:00
|
|
|
removeAnim = false;
|
2018-06-22 23:17:03 +02:00
|
|
|
if (currentFrame != 5)
|
|
|
|
|
{
|
2025-05-07 01:40:11 +03:00
|
|
|
newFrame++;
|
2017-02-18 08:26:33 +00:00
|
|
|
|
2025-05-07 01:40:11 +03:00
|
|
|
if (newFrame == 13 && !(entry->flags & WALL_SCENERY_LONG_DOOR_ANIMATION))
|
|
|
|
|
newFrame = 15;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
2025-05-07 01:40:11 +03:00
|
|
|
|
|
|
|
|
if (currentFrame != newFrame)
|
|
|
|
|
{
|
|
|
|
|
wall.SetAnimationFrame(newFrame);
|
2025-05-23 15:53:12 +01:00
|
|
|
if constexpr (invalidate)
|
|
|
|
|
{
|
2025-05-24 05:01:36 +01:00
|
|
|
Invalidate<invalidateAllViewports>(viewport, loc.x, loc.y, baseZ, baseZ + 32);
|
2025-05-23 15:53:12 +01:00
|
|
|
}
|
2025-05-07 01:40:11 +03:00
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2015-03-18 19:52:27 +00:00
|
|
|
|
2025-05-22 23:14:56 +01:00
|
|
|
return removeAnim ? std::nullopt : std::optional(UpdateType::update);
|
2019-08-03 21:18:33 +01:00
|
|
|
}
|
2025-05-07 01:40:11 +03:00
|
|
|
else if ((entry->flags2 & WALL_SCENERY_2_ANIMATED) || entry->scrolling_mode != kScrollingModeNone)
|
|
|
|
|
{
|
2025-05-23 15:53:12 +01:00
|
|
|
if constexpr (invalidate)
|
|
|
|
|
{
|
2025-05-24 05:01:36 +01:00
|
|
|
Invalidate<invalidateAllViewports>(viewport, loc.x, loc.y, baseZ, baseZ + 16);
|
2025-05-23 15:53:12 +01:00
|
|
|
}
|
2025-05-22 23:14:56 +01:00
|
|
|
return std::optional(UpdateType::invalidate);
|
2025-05-07 01:40:11 +03:00
|
|
|
}
|
|
|
|
|
|
2025-05-22 23:14:56 +01:00
|
|
|
return std::nullopt;
|
2025-05-07 01:40:11 +03:00
|
|
|
}
|
|
|
|
|
|
2025-05-24 05:01:36 +01:00
|
|
|
template<bool invalidate, bool invalidateAllViewports>
|
|
|
|
|
static bool UpdateBannerAnimation(
|
|
|
|
|
[[maybe_unused]] const BannerElement& banner, const CoordsXYZ& loc, const int32_t baseZ, const Viewport& viewport)
|
2025-05-07 01:40:11 +03:00
|
|
|
{
|
2025-05-23 15:53:12 +01:00
|
|
|
if constexpr (invalidate)
|
|
|
|
|
{
|
2025-05-24 05:01:36 +01:00
|
|
|
Invalidate<invalidateAllViewports>(viewport, loc.x, loc.y, baseZ, baseZ + 16);
|
2025-05-23 15:53:12 +01:00
|
|
|
}
|
2019-08-03 21:18:33 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2018-06-22 23:17:03 +02:00
|
|
|
|
2025-05-24 05:01:36 +01:00
|
|
|
template<bool invalidate, bool invalidateAllViewports>
|
|
|
|
|
static std::optional<UpdateType> UpdateTile(const TileCoordsXY& coords, const Viewport& viewport)
|
2019-08-03 21:18:33 +01:00
|
|
|
{
|
2025-05-07 01:40:11 +03:00
|
|
|
auto tileElement = MapGetFirstElementAt(coords);
|
|
|
|
|
if (tileElement == nullptr)
|
2019-08-03 21:18:33 +01:00
|
|
|
{
|
2025-05-22 23:14:56 +01:00
|
|
|
return std::nullopt;
|
2023-06-05 20:37:16 +02:00
|
|
|
}
|
2025-05-07 01:40:11 +03:00
|
|
|
|
|
|
|
|
bool hasAnimations = false;
|
2025-05-23 15:53:12 +01:00
|
|
|
auto updateType = UpdateType::invalidate;
|
2025-05-07 01:40:11 +03:00
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
const auto baseZ = tileElement->GetBaseZ();
|
|
|
|
|
const CoordsXYZ loc{ coords.ToCoordsXY(), baseZ };
|
|
|
|
|
|
|
|
|
|
switch (tileElement->GetType())
|
|
|
|
|
{
|
|
|
|
|
case TileElementType::Entrance:
|
2025-05-24 05:01:36 +01:00
|
|
|
hasAnimations |= UpdateEntranceAnimation<invalidate, invalidateAllViewports>(
|
|
|
|
|
*tileElement->AsEntrance(), loc, baseZ, viewport);
|
2025-05-07 01:40:11 +03:00
|
|
|
break;
|
|
|
|
|
case TileElementType::Path:
|
2025-05-24 05:01:36 +01:00
|
|
|
hasAnimations |= UpdatePathAnimation<invalidate, invalidateAllViewports>(
|
|
|
|
|
*tileElement->AsPath(), loc, baseZ, viewport);
|
2025-05-07 01:40:11 +03:00
|
|
|
break;
|
|
|
|
|
case TileElementType::SmallScenery:
|
2025-05-22 23:14:56 +01:00
|
|
|
{
|
2025-05-24 05:01:36 +01:00
|
|
|
const auto result = UpdateSmallSceneryAnimation<invalidate, invalidateAllViewports>(
|
|
|
|
|
*tileElement->AsSmallScenery(), loc, baseZ, viewport);
|
2025-05-22 23:14:56 +01:00
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
hasAnimations |= true;
|
|
|
|
|
if (result.value() == UpdateType::update)
|
|
|
|
|
{
|
2025-05-23 15:53:12 +01:00
|
|
|
updateType = UpdateType::update;
|
2025-05-22 23:14:56 +01:00
|
|
|
}
|
|
|
|
|
}
|
2025-05-07 01:40:11 +03:00
|
|
|
break;
|
2025-05-22 23:14:56 +01:00
|
|
|
}
|
2025-05-07 01:40:11 +03:00
|
|
|
case TileElementType::Track:
|
2025-05-24 05:01:36 +01:00
|
|
|
hasAnimations |= UpdateTrackAnimation<invalidate, invalidateAllViewports>(
|
|
|
|
|
*tileElement->AsTrack(), loc, baseZ, viewport);
|
2025-05-07 01:40:11 +03:00
|
|
|
break;
|
|
|
|
|
case TileElementType::Banner:
|
2025-05-24 05:01:36 +01:00
|
|
|
hasAnimations |= UpdateBannerAnimation<invalidate, invalidateAllViewports>(
|
|
|
|
|
*tileElement->AsBanner(), loc, baseZ, viewport);
|
2025-05-07 01:40:11 +03:00
|
|
|
break;
|
|
|
|
|
case TileElementType::LargeScenery:
|
2025-05-24 05:01:36 +01:00
|
|
|
hasAnimations |= UpdateLargeSceneryAnimation<invalidate, invalidateAllViewports>(
|
|
|
|
|
*tileElement->AsLargeScenery(), loc, baseZ, viewport);
|
2025-05-07 01:40:11 +03:00
|
|
|
break;
|
|
|
|
|
case TileElementType::Wall:
|
2025-05-22 23:14:56 +01:00
|
|
|
{
|
2025-05-24 05:01:36 +01:00
|
|
|
const auto result = UpdateWallAnimation<invalidate, invalidateAllViewports>(
|
|
|
|
|
*tileElement->AsWall(), loc, baseZ, viewport);
|
2025-05-22 23:14:56 +01:00
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
hasAnimations |= true;
|
|
|
|
|
if (result.value() == UpdateType::update)
|
|
|
|
|
{
|
2025-05-23 15:53:12 +01:00
|
|
|
updateType = UpdateType::update;
|
2025-05-22 23:14:56 +01:00
|
|
|
}
|
|
|
|
|
}
|
2025-05-07 01:40:11 +03:00
|
|
|
break;
|
2025-05-22 23:14:56 +01:00
|
|
|
}
|
2025-05-07 01:40:11 +03:00
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} while (!(tileElement++)->IsLastForTile());
|
|
|
|
|
|
2025-05-23 15:53:12 +01:00
|
|
|
return hasAnimations ? std::optional(updateType) : std::nullopt;
|
2023-06-05 20:37:16 +02:00
|
|
|
}
|
|
|
|
|
|
2025-05-21 06:48:58 +01:00
|
|
|
static bool UpdateOnRidePhotoAnimation(TrackElement& track, const CoordsXYZ& coords)
|
|
|
|
|
{
|
|
|
|
|
if (track.IsTakingPhoto())
|
|
|
|
|
{
|
|
|
|
|
track.DecrementPhotoTimeout();
|
2025-05-23 04:53:21 +01:00
|
|
|
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);
|
2025-05-23 04:53:21 +01:00
|
|
|
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);
|
2025-05-23 04:53:21 +01:00
|
|
|
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);
|
2025-05-23 04:53:21 +01:00
|
|
|
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);
|
2025-05-23 04:53:21 +01:00
|
|
|
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)
|
|
|
|
|
{
|
2025-05-23 22:08:09 +01:00
|
|
|
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;
|
|
|
|
|
}
|
2025-05-23 22:08:09 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2025-05-22 23:14:56 +01:00
|
|
|
static std::optional<UpdateType> IsElementAnimated(const TileElementBase& element)
|
2023-06-05 20:37:16 +02:00
|
|
|
{
|
2025-05-07 01:40:11 +03:00
|
|
|
switch (element.GetType())
|
2023-06-05 20:37:16 +02:00
|
|
|
{
|
|
|
|
|
case TileElementType::Banner:
|
2025-05-22 23:14:56 +01:00
|
|
|
return std::optional(UpdateType::invalidate);
|
2023-06-05 20:37:16 +02:00
|
|
|
case TileElementType::Wall:
|
2019-08-03 21:18:33 +01:00
|
|
|
{
|
2025-05-07 01:40:11 +03:00
|
|
|
const auto wall = element.AsWall();
|
|
|
|
|
const auto entry = wall->GetEntry();
|
|
|
|
|
if (entry != nullptr)
|
2019-08-03 21:18:33 +01:00
|
|
|
{
|
2025-05-07 01:40:11 +03:00
|
|
|
if ((entry->flags2 & WALL_SCENERY_2_ANIMATED) || entry->scrolling_mode != kScrollingModeNone)
|
|
|
|
|
{
|
2025-05-22 23:14:56 +01:00
|
|
|
return std::optional(UpdateType::invalidate);
|
2025-05-07 01:40:11 +03:00
|
|
|
}
|
2025-05-19 16:42:50 +01:00
|
|
|
if (entry->flags & WALL_SCENERY_IS_DOOR && wall->IsAnimating())
|
2025-05-07 01:40:11 +03:00
|
|
|
{
|
2025-05-22 23:14:56 +01:00
|
|
|
return std::optional(UpdateType::update);
|
2025-05-07 01:40:11 +03:00
|
|
|
}
|
2019-08-03 21:18:33 +01:00
|
|
|
}
|
2023-06-05 20:37:16 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case TileElementType::SmallScenery:
|
|
|
|
|
{
|
2025-05-07 01:40:11 +03:00
|
|
|
const auto scenery = element.AsSmallScenery();
|
|
|
|
|
const auto entry = scenery->GetEntry();
|
|
|
|
|
if (entry != nullptr && entry->HasFlag(SMALL_SCENERY_FLAG_ANIMATED))
|
2019-08-03 21:18:33 +01:00
|
|
|
{
|
2025-05-22 23:14:56 +01:00
|
|
|
if (entry->HasFlag(SMALL_SCENERY_FLAG_IS_CLOCK))
|
|
|
|
|
{
|
|
|
|
|
return std::optional(UpdateType::update);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return std::optional(UpdateType::invalidate);
|
|
|
|
|
}
|
2019-08-03 21:18:33 +01:00
|
|
|
}
|
2023-06-05 20:37:16 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case TileElementType::LargeScenery:
|
|
|
|
|
{
|
2025-05-07 01:40:11 +03:00
|
|
|
const auto scenery = element.AsLargeScenery();
|
|
|
|
|
const auto entry = scenery->GetEntry();
|
2023-06-05 20:37:16 +02:00
|
|
|
if (entry != nullptr && (entry->flags & LARGE_SCENERY_FLAG_ANIMATED))
|
2019-08-03 21:18:33 +01:00
|
|
|
{
|
2025-05-22 23:14:56 +01:00
|
|
|
return std::optional(UpdateType::invalidate);
|
2019-08-03 21:18:33 +01:00
|
|
|
}
|
2023-06-05 20:37:16 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case TileElementType::Path:
|
|
|
|
|
{
|
2025-05-07 01:40:11 +03:00
|
|
|
const auto path = element.AsPath();
|
2023-06-05 20:37:16 +02:00
|
|
|
if (path->HasQueueBanner())
|
2019-08-03 21:18:33 +01:00
|
|
|
{
|
2025-05-22 23:14:56 +01:00
|
|
|
return std::optional(UpdateType::invalidate);
|
2019-08-03 21:18:33 +01:00
|
|
|
}
|
2023-06-05 20:37:16 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case TileElementType::Entrance:
|
|
|
|
|
{
|
2025-05-07 01:40:11 +03:00
|
|
|
const auto entrance = element.AsEntrance();
|
|
|
|
|
if (entrance->GetEntranceType() == ENTRANCE_TYPE_PARK_ENTRANCE && entrance->GetSequenceIndex() == 0)
|
2019-08-03 21:18:33 +01:00
|
|
|
{
|
2025-05-22 23:14:56 +01:00
|
|
|
return std::optional(UpdateType::invalidate);
|
2025-05-07 01:40:11 +03:00
|
|
|
}
|
|
|
|
|
else if (entrance->GetEntranceType() == ENTRANCE_TYPE_RIDE_ENTRANCE)
|
|
|
|
|
{
|
2025-05-22 23:14:56 +01:00
|
|
|
return std::optional(UpdateType::invalidate);
|
2019-08-03 21:18:33 +01:00
|
|
|
}
|
2023-06-05 20:37:16 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case TileElementType::Track:
|
|
|
|
|
{
|
2025-05-07 01:40:11 +03:00
|
|
|
const auto track = element.AsTrack();
|
2023-06-05 20:37:16 +02:00
|
|
|
switch (track->GetTrackType())
|
2019-08-03 21:18:33 +01:00
|
|
|
{
|
2023-06-05 20:37:16 +02:00
|
|
|
case TrackElemType::Waterfall:
|
|
|
|
|
case TrackElemType::Rapids:
|
|
|
|
|
case TrackElemType::Whirlpool:
|
|
|
|
|
case TrackElemType::SpinningTunnel:
|
2025-05-22 23:14:56 +01:00
|
|
|
return std::optional(UpdateType::invalidate);
|
2024-10-11 15:30:27 +02:00
|
|
|
default:
|
|
|
|
|
break;
|
2019-08-03 21:18:33 +01:00
|
|
|
}
|
2023-06-05 20:37:16 +02:00
|
|
|
break;
|
2019-08-03 21:18:33 +01:00
|
|
|
}
|
2025-05-07 01:40:11 +03:00
|
|
|
default:
|
2023-06-05 20:37:16 +02:00
|
|
|
break;
|
2019-08-03 21:18:33 +01:00
|
|
|
}
|
2025-05-07 01:40:11 +03:00
|
|
|
|
2025-05-22 23:14:56 +01:00
|
|
|
return std::nullopt;
|
2025-05-07 01:40:11 +03:00
|
|
|
}
|
|
|
|
|
|
2025-05-23 22:08:09 +01:00
|
|
|
void MapAnimations::MarkTileForInvalidation(const CoordsXY coords)
|
2025-05-07 01:40:11 +03:00
|
|
|
{
|
2025-05-23 15:53:12 +01:00
|
|
|
const TileCoordsXY tileCoords(coords);
|
|
|
|
|
if (!_mapAnimationsUpdate.contains(tileCoords))
|
|
|
|
|
{
|
|
|
|
|
_mapAnimationsInvalidate.insert(tileCoords);
|
|
|
|
|
}
|
2025-05-22 23:14:56 +01:00
|
|
|
}
|
|
|
|
|
|
2025-05-23 22:08:09 +01:00
|
|
|
void MapAnimations::MarkTileForUpdate(const CoordsXY coords)
|
2025-05-22 23:14:56 +01:00
|
|
|
{
|
2025-05-23 15:53:12 +01:00
|
|
|
const TileCoordsXY tileCoords(coords);
|
|
|
|
|
_mapAnimationsInvalidate.erase(tileCoords);
|
|
|
|
|
_mapAnimationsUpdate.insert(tileCoords);
|
2025-05-07 01:40:11 +03:00
|
|
|
}
|
|
|
|
|
|
2025-05-23 22:08:09 +01:00
|
|
|
void MapAnimations::CreateTemporary(const CoordsXYZ& coords, const TemporaryType type)
|
2025-05-21 06:48:58 +01:00
|
|
|
{
|
|
|
|
|
_temporaryMapAnimations.insert(TemporaryMapAnimation{ coords, type });
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-23 22:08:09 +01:00
|
|
|
void MapAnimations::MarkAllTiles()
|
2025-05-07 01:40:11 +03:00
|
|
|
{
|
|
|
|
|
TileElementIterator it;
|
|
|
|
|
TileElementIteratorBegin(&it);
|
|
|
|
|
while (TileElementIteratorNext(&it))
|
|
|
|
|
{
|
2025-05-22 23:14:56 +01:00
|
|
|
const auto isAnimated = IsElementAnimated(*it.element);
|
|
|
|
|
if (isAnimated)
|
2025-05-07 01:40:11 +03:00
|
|
|
{
|
2025-05-22 23:14:56 +01:00
|
|
|
switch (*isAnimated)
|
|
|
|
|
{
|
|
|
|
|
case UpdateType::invalidate:
|
2025-05-23 15:53:12 +01:00
|
|
|
MarkTileForInvalidation(TileCoordsXY(it.x, it.y).ToCoordsXY());
|
2025-05-22 23:14:56 +01:00
|
|
|
break;
|
|
|
|
|
case UpdateType::update:
|
2025-05-23 15:53:12 +01:00
|
|
|
MarkTileForUpdate(TileCoordsXY(it.x, it.y).ToCoordsXY());
|
2025-05-22 23:14:56 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2025-05-07 01:40:11 +03:00
|
|
|
}
|
|
|
|
|
}
|
2018-01-11 10:59:26 +01:00
|
|
|
}
|
2024-03-31 00:32:36 +01:00
|
|
|
|
2025-05-23 15:53:12 +01:00
|
|
|
static void InvalidateAll(const ViewportList& viewports)
|
2025-05-21 06:48:58 +01:00
|
|
|
{
|
2025-05-22 23:14:56 +01:00
|
|
|
for (const auto viewport : viewports)
|
2025-05-21 06:48:58 +01:00
|
|
|
{
|
2025-05-23 15:53:12 +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))
|
|
|
|
|
{
|
2025-05-24 05:01:36 +01:00
|
|
|
if (!UpdateTile<true, false>(tileCoords, *viewport))
|
2025-05-23 15:53:12 +01:00
|
|
|
{
|
|
|
|
|
_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
|
|
|
{
|
2025-05-22 23:14:56 +01:00
|
|
|
return true;
|
2025-05-21 06:48:58 +01:00
|
|
|
}
|
|
|
|
|
}
|
2025-05-22 23:14:56 +01:00
|
|
|
return false;
|
2025-05-21 06:48:58 +01:00
|
|
|
}
|
|
|
|
|
|
2025-05-23 15:53:12 +01:00
|
|
|
static void UpdateAll(const ViewportList& viewports)
|
2025-05-07 01:40:11 +03:00
|
|
|
{
|
2025-05-23 15:53:12 +01:00
|
|
|
auto it = _mapAnimationsUpdate.begin();
|
|
|
|
|
while (it != _mapAnimationsUpdate.end())
|
2025-05-22 23:14:56 +01:00
|
|
|
{
|
2025-05-23 15:53:12 +01:00
|
|
|
const bool isVisible = IsTileVisible(viewports, *it);
|
2025-05-24 05:01:36 +01:00
|
|
|
const auto result = isVisible ? UpdateTile<true, true>(*it, *viewports.front())
|
|
|
|
|
: UpdateTile<false, true>(*it, *viewports.front());
|
2025-05-23 15:53:12 +01:00
|
|
|
if (result)
|
2025-05-22 23:14:56 +01:00
|
|
|
{
|
2025-05-23 15:53:12 +01:00
|
|
|
if (result.value() == UpdateType::invalidate)
|
2025-05-22 23:14:56 +01:00
|
|
|
{
|
2025-05-23 15:53:12 +01:00
|
|
|
_mapAnimationsInvalidate.insert(*it);
|
|
|
|
|
it = _mapAnimationsUpdate.erase(it);
|
2025-05-22 23:14:56 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-05-23 15:53:12 +01:00
|
|
|
++it;
|
2025-05-22 23:14:56 +01:00
|
|
|
}
|
|
|
|
|
}
|
2025-05-23 15:53:12 +01:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
it = _mapAnimationsUpdate.erase(it);
|
|
|
|
|
}
|
2025-05-22 23:14:56 +01:00
|
|
|
}
|
2025-05-23 15:53:12 +01:00
|
|
|
}
|
|
|
|
|
|
2025-05-23 22:09:36 +01:00
|
|
|
static void UpdateAllTemporary()
|
|
|
|
|
{
|
|
|
|
|
auto it = _temporaryMapAnimations.begin();
|
|
|
|
|
while (it != _temporaryMapAnimations.end())
|
|
|
|
|
{
|
|
|
|
|
if (UpdateTemporaryAnimation(*it))
|
|
|
|
|
{
|
|
|
|
|
++it;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
it = _temporaryMapAnimations.erase(it);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-23 22:08:09 +01:00
|
|
|
void MapAnimations::InvalidateAndUpdateAll()
|
2025-05-23 15:53:12 +01:00
|
|
|
{
|
|
|
|
|
PROFILED_FUNCTION();
|
|
|
|
|
|
|
|
|
|
const auto viewports = GetVisibleViewports();
|
|
|
|
|
InvalidateAll(viewports);
|
|
|
|
|
UpdateAll(viewports);
|
2025-05-23 22:09:36 +01:00
|
|
|
UpdateAllTemporary();
|
2025-05-07 01:40:11 +03:00
|
|
|
}
|
|
|
|
|
|
2025-05-23 22:08:09 +01:00
|
|
|
void MapAnimations::ClearAll()
|
2025-05-07 01:40:11 +03:00
|
|
|
{
|
2025-05-23 15:53:12 +01:00
|
|
|
_mapAnimationsInvalidate.clear();
|
|
|
|
|
_mapAnimationsUpdate.clear();
|
2025-05-21 06:48:58 +01:00
|
|
|
_temporaryMapAnimations.clear();
|
2025-05-07 01:40:11 +03:00
|
|
|
}
|
|
|
|
|
|
2025-05-23 22:08:09 +01:00
|
|
|
void MapAnimations::ShiftAll(const CoordsXY amount)
|
2024-03-31 00:32:36 +01:00
|
|
|
{
|
|
|
|
|
if (amount.x == 0 && amount.y == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-05-23 15:53:12 +01:00
|
|
|
std::set<TileCoordsXY, TileCoordsXYCmp> newMapAnimationsInvalidate;
|
|
|
|
|
for (const auto a : _mapAnimationsInvalidate)
|
2024-03-31 00:32:36 +01:00
|
|
|
{
|
2025-05-23 15:53:12 +01:00
|
|
|
newMapAnimationsInvalidate.insert(a + TileCoordsXY(amount));
|
2024-03-31 00:32:36 +01:00
|
|
|
}
|
2025-05-23 15:53:12 +01:00
|
|
|
_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);
|
2024-03-31 00:32:36 +01:00
|
|
|
}
|