From 65b582afb0b61d2b874c58aebda0478227281e2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 24 May 2023 00:43:23 +0300 Subject: [PATCH] Add a way to invalidate entity tweening --- src/openrct2/entity/EntityBase.h | 10 ++++++++ src/openrct2/entity/EntityRegistry.cpp | 1 + src/openrct2/entity/EntityTweener.cpp | 33 ++++++++++++++++++++------ src/openrct2/entity/EntityTweener.h | 1 + 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/openrct2/entity/EntityBase.h b/src/openrct2/entity/EntityBase.h index 89ba30b514..e8a165d610 100644 --- a/src/openrct2/entity/EntityBase.h +++ b/src/openrct2/entity/EntityBase.h @@ -35,6 +35,14 @@ struct EntitySpriteData ScreenRect SpriteRect; }; +namespace EntityRenderFlags +{ + // Disables tweening for this tick, this is helpful when entities are teleported + // and should not be tweened. + constexpr uint32_t kInvalidateTweening = (1U << 0); + +} // namespace EntityRenderFlags + struct EntityBase { EntityType Type; @@ -42,6 +50,8 @@ struct EntityBase int32_t x; int32_t y; int32_t z; + // Rendering specific flags, this should not be stored in the save file. + uint32_t RenderFlags; EntitySpriteData SpriteData; // Used as direction or rotation depending on the entity. uint8_t Orientation; diff --git a/src/openrct2/entity/EntityRegistry.cpp b/src/openrct2/entity/EntityRegistry.cpp index b123f222f1..1921aa3b82 100644 --- a/src/openrct2/entity/EntityRegistry.cpp +++ b/src/openrct2/entity/EntityRegistry.cpp @@ -273,6 +273,7 @@ static void EntityReset(EntityBase* entity) entity->Id = entityIndex; entity->Type = EntityType::Null; + entity->RenderFlags = 0; } static constexpr uint16_t MAX_MISC_SPRITES = 300; diff --git a/src/openrct2/entity/EntityTweener.cpp b/src/openrct2/entity/EntityTweener.cpp index 64d7bec49b..9c9e1bb1cc 100644 --- a/src/openrct2/entity/EntityTweener.cpp +++ b/src/openrct2/entity/EntityTweener.cpp @@ -15,22 +15,28 @@ #include "EntityRegistry.h" #include + +void EntityTweener::AddEntity(EntityBase* entity) +{ + entity->RenderFlags &= ~EntityRenderFlags::kInvalidateTweening; + + Entities.push_back(entity); + PrePos.emplace_back(entity->GetLocation()); +} + void EntityTweener::PopulateEntities() { for (auto ent : EntityList()) { - Entities.push_back(ent); - PrePos.emplace_back(ent->GetLocation()); + AddEntity(ent); } for (auto ent : EntityList()) { - Entities.push_back(ent); - PrePos.emplace_back(ent->GetLocation()); + AddEntity(ent); } for (auto ent : EntityList()) { - Entities.push_back(ent); - PrePos.emplace_back(ent->GetLocation()); + AddEntity(ent); } } @@ -57,9 +63,16 @@ void EntityTweener::PostTick() } } +static bool CanTweenEntity(EntityBase* ent) +{ + if (ent->Is() || ent->Is() || ent->Is()) + return true; + return false; +} + void EntityTweener::RemoveEntity(EntityBase* entity) { - if (!entity->Is() && !entity->Is()) + if (!CanTweenEntity(entity)) { // Only peeps and vehicles are tweened, bail if type is incorrect. return; @@ -79,6 +92,9 @@ void EntityTweener::Tween(float alpha) if (ent == nullptr) continue; + if (ent->RenderFlags & EntityRenderFlags::kInvalidateTweening) + continue; + auto& posA = PrePos[i]; auto& posB = PostPos[i]; @@ -102,6 +118,9 @@ void EntityTweener::Restore() if (ent == nullptr) continue; + if (ent->RenderFlags & EntityRenderFlags::kInvalidateTweening) + continue; + EntitySetCoordinates(PostPos[i], ent); ent->Invalidate(); } diff --git a/src/openrct2/entity/EntityTweener.h b/src/openrct2/entity/EntityTweener.h index 1759370b37..441e033117 100644 --- a/src/openrct2/entity/EntityTweener.h +++ b/src/openrct2/entity/EntityTweener.h @@ -21,6 +21,7 @@ class EntityTweener private: void PopulateEntities(); + void AddEntity(EntityBase* entity); public: static EntityTweener& Get();