From daf8c186d3baba3cdd200f9f10dffaedf5f957d7 Mon Sep 17 00:00:00 2001 From: mix Date: Mon, 19 May 2025 16:42:50 +0100 Subject: [PATCH] Add is animating state to scenery doors --- src/openrct2/ride/Vehicle.cpp | 2 ++ src/openrct2/world/MapAnimation.cpp | 9 +++++---- src/openrct2/world/tile_element/WallElement.cpp | 13 +++++++++++++ src/openrct2/world/tile_element/WallElement.h | 9 +++++++-- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index f29e6ecc3b..d9ea227f68 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -6313,6 +6313,7 @@ static void AnimateSceneryDoor(const CoordsXYZD& doorLocation, const CoordsXYZ& { door->SetAnimationIsBackwards(isBackwards); door->SetAnimationFrame(1); + door->SetIsAnimating(true); play_scenery_door_open_sound(trackLocation, door); MapAnimation::Create(doorLocation); @@ -6322,6 +6323,7 @@ static void AnimateSceneryDoor(const CoordsXYZD& doorLocation, const CoordsXYZ& { door->SetAnimationIsBackwards(isBackwards); door->SetAnimationFrame(6); + door->SetIsAnimating(true); play_scenery_door_close_sound(trackLocation, door); MapAnimation::Create(doorLocation); diff --git a/src/openrct2/world/MapAnimation.cpp b/src/openrct2/world/MapAnimation.cpp index cb02737820..147274b539 100644 --- a/src/openrct2/world/MapAnimation.cpp +++ b/src/openrct2/world/MapAnimation.cpp @@ -189,7 +189,7 @@ static bool UpdateWallAnimation(WallElement& wall, const CoordsXYZ& loc, const i return false; } - if (entry->flags & WALL_SCENERY_IS_DOOR) + if (entry->flags & WALL_SCENERY_IS_DOOR && wall.IsAnimating()) { if (getGameState().currentTicks & 1) { @@ -205,6 +205,7 @@ static bool UpdateWallAnimation(WallElement& wall, const CoordsXYZ& loc, const i if (currentFrame == 15) { newFrame = 0; + wall.SetIsAnimating(false); } else { @@ -327,7 +328,7 @@ static bool UpdateTemporaryAnimation(const TemporaryMapAnimation& animation) return hasAnimations; } -static bool IsElementAnimated(const TileElementBase& element, const bool skipDoors) +static bool IsElementAnimated(const TileElementBase& element) { switch (element.GetType()) { @@ -343,7 +344,7 @@ static bool IsElementAnimated(const TileElementBase& element, const bool skipDoo { return true; } - if (!skipDoors && (entry->flags & WALL_SCENERY_IS_DOOR)) + if (entry->flags & WALL_SCENERY_IS_DOOR && wall->IsAnimating()) { return true; } @@ -432,7 +433,7 @@ void MapAnimation::CreateAll() TileElementIteratorBegin(&it); while (TileElementIteratorNext(&it)) { - if (IsElementAnimated(*it.element, true)) + if (IsElementAnimated(*it.element)) { _mapAnimations.insert(TileCoordsXY(it.x, it.y)); } diff --git a/src/openrct2/world/tile_element/WallElement.cpp b/src/openrct2/world/tile_element/WallElement.cpp index 779c9b85b2..ac01477888 100644 --- a/src/openrct2/world/tile_element/WallElement.cpp +++ b/src/openrct2/world/tile_element/WallElement.cpp @@ -64,6 +64,19 @@ void WallElement::SetAnimationFrame(uint8_t frameNum) animation |= (frameNum & 0xF) << 3; } +bool WallElement::IsAnimating() const +{ + return (animation & WALL_ANIMATION_FLAG_IS_ANIMATING) != 0; +} + +void WallElement::SetIsAnimating(const bool isAnimating) +{ + if (isAnimating) + animation |= WALL_ANIMATION_FLAG_IS_ANIMATING; + else + animation &= ~WALL_ANIMATION_FLAG_IS_ANIMATING; +} + uint16_t WallElement::GetEntryIndex() const { return entryIndex; diff --git a/src/openrct2/world/tile_element/WallElement.h b/src/openrct2/world/tile_element/WallElement.h index 6ddec0568f..717a882c37 100644 --- a/src/openrct2/world/tile_element/WallElement.h +++ b/src/openrct2/world/tile_element/WallElement.h @@ -20,10 +20,12 @@ enum { + WALL_ANIMATION_FLAG_IS_ANIMATING = (1 << 1), WALL_ANIMATION_FLAG_ACROSS_TRACK = (1 << 2), // 3 - 6 animation frame number WALL_ANIMATION_FLAG_DIRECTION_BACKWARD = (1 << 7), - WALL_ANIMATION_FLAG_ALL_FLAGS = WALL_ANIMATION_FLAG_ACROSS_TRACK | WALL_ANIMATION_FLAG_DIRECTION_BACKWARD + WALL_ANIMATION_FLAG_ALL_FLAGS = WALL_ANIMATION_FLAG_IS_ANIMATING | WALL_ANIMATION_FLAG_ACROSS_TRACK + | WALL_ANIMATION_FLAG_DIRECTION_BACKWARD }; #pragma pack(push, 1) @@ -37,7 +39,7 @@ private: colour_t colour_2; // 08 colour_t colour_3; // 09 BannerIndex banner_index; // 0A - uint8_t animation; // 0C 0b_dfff_ft00 d = direction, f = frame num, t = across track flag (not used) + uint8_t animation; // 0C 0b_dfff_fta0 d = direction, f = frame num, t = across track flag (not used), a = animating #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-private-field" uint8_t Pad0D[3]; @@ -61,6 +63,9 @@ public: uint8_t GetAnimationFrame() const; void SetAnimationFrame(uint8_t frameNum); + bool IsAnimating() const; + void SetIsAnimating(const bool isAnimating); + Banner* GetBanner() const; BannerIndex GetBannerIndex() const; void SetBannerIndex(BannerIndex newIndex);