1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-04 13:42:55 +01:00

Add a way to invalidate entity tweening

This commit is contained in:
ζeh Matt
2023-05-24 00:43:23 +03:00
parent 2ca1af9e0c
commit 65b582afb0
4 changed files with 38 additions and 7 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -15,22 +15,28 @@
#include "EntityRegistry.h"
#include <cmath>
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<Guest>())
{
Entities.push_back(ent);
PrePos.emplace_back(ent->GetLocation());
AddEntity(ent);
}
for (auto ent : EntityList<Staff>())
{
Entities.push_back(ent);
PrePos.emplace_back(ent->GetLocation());
AddEntity(ent);
}
for (auto ent : EntityList<Vehicle>())
{
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<Guest>() || ent->Is<Staff>() || ent->Is<Vehicle>())
return true;
return false;
}
void EntityTweener::RemoveEntity(EntityBase* entity)
{
if (!entity->Is<Peep>() && !entity->Is<Vehicle>())
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();
}

View File

@@ -21,6 +21,7 @@ class EntityTweener
private:
void PopulateEntities();
void AddEntity(EntityBase* entity);
public:
static EntityTweener& Get();