From 0efbf7f5ea3c5520a2829b5d1be961217da78c7d Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Sat, 29 Jun 2024 15:25:40 +0200 Subject: [PATCH] Split off Update{Action,Walking}Animation and use for frozen peeps --- src/openrct2/entity/Peep.cpp | 42 +++++++++++++++++++++++++++++------- src/openrct2/entity/Peep.h | 2 ++ 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/openrct2/entity/Peep.cpp b/src/openrct2/entity/Peep.cpp index 53868dc28e..cbbd245525 100644 --- a/src/openrct2/entity/Peep.cpp +++ b/src/openrct2/entity/Peep.cpp @@ -428,18 +428,13 @@ std::optional Peep::UpdateAction(int16_t& xy_distance) return UpdateWalkingAction(differenceLoc, xy_distance); } - const PeepAnimation& peepAnimation = GetPeepAnimation(SpriteType, ActionSpriteType); - ActionFrame++; - - // If last frame of action - if (ActionFrame >= peepAnimation.frame_offsets.size()) + if (!UpdateActionAnimation()) { ActionSpriteImageOffset = 0; Action = PeepActionType::Walking; UpdateCurrentActionSpriteType(); return { { x, y } }; } - ActionSpriteImageOffset = peepAnimation.frame_offsets[ActionFrame]; // Should we throw up, and are we at the frame where sick appears? auto* guest = As(); @@ -451,6 +446,21 @@ std::optional Peep::UpdateAction(int16_t& xy_distance) return { { x, y } }; } +bool Peep::UpdateActionAnimation() +{ + const PeepAnimation& peepAnimation = GetPeepAnimation(SpriteType, ActionSpriteType); + ActionFrame++; + + // If last frame of action + if (ActionFrame >= peepAnimation.frame_offsets.size()) + { + return false; + } + + ActionSpriteImageOffset = peepAnimation.frame_offsets[ActionFrame]; + return true; +} + std::optional Peep::UpdateWalkingAction(const CoordsXY& differenceLoc, int16_t& xy_distance) { if (!IsActionWalking()) @@ -489,6 +499,13 @@ std::optional Peep::UpdateWalkingAction(const CoordsXY& differenceLoc, CoordsXY loc = { x, y }; loc += walkingOffsetByDirection[nextDirection]; + UpdateWalkingAnimation(); + + return loc; +} + +void Peep::UpdateWalkingAnimation() +{ WalkingFrameNum++; const PeepAnimation& peepAnimation = GetPeepAnimation(SpriteType, ActionSpriteType); if (WalkingFrameNum >= peepAnimation.frame_offsets.size()) @@ -496,8 +513,6 @@ std::optional Peep::UpdateWalkingAction(const CoordsXY& differenceLoc, WalkingFrameNum = 0; } ActionSpriteImageOffset = peepAnimation.frame_offsets[WalkingFrameNum]; - - return loc; } void Peep::ThrowUp() @@ -958,6 +973,17 @@ void Peep::Update() { if (PeepFlags & PEEP_FLAGS_POSITION_FROZEN) { + if (!(PeepFlags & PEEP_FLAGS_ANIMATION_FROZEN)) + { + // This is circumventing other logic, so only update every few ticks + if ((GetGameState().CurrentTicks & 3) == 0) + { + if (IsActionWalking()) + UpdateWalkingAnimation(); + else + UpdateActionAnimation(); + } + } return; } diff --git a/src/openrct2/entity/Peep.h b/src/openrct2/entity/Peep.h index b559ae7be5..7aaa2ba79d 100644 --- a/src/openrct2/entity/Peep.h +++ b/src/openrct2/entity/Peep.h @@ -377,7 +377,9 @@ public: // Peep void Update(); std::optional UpdateAction(int16_t& xy_distance); std::optional UpdateAction(); + bool UpdateActionAnimation(); std::optional UpdateWalkingAction(const CoordsXY& differenceLoc, int16_t& xy_distance); + void UpdateWalkingAnimation(); void ThrowUp(); void SetState(PeepState new_state); void Remove();