mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-16 04:22:43 +01:00
Move EntityList and EntityRegistry into OpenRCT2 namespace (#25039)
This commit is contained in:
@@ -26,6 +26,8 @@
|
||||
static constexpr size_t kMaximumGameStateSnapshots = 32;
|
||||
static constexpr uint32_t kInvalidTick = 0xFFFFFFFF;
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
||||
#pragma pack(push, 1)
|
||||
union EntitySnapshot
|
||||
{
|
||||
|
||||
@@ -17,22 +17,24 @@
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
const std::list<EntityId>& GetEntityList(const EntityType id);
|
||||
|
||||
uint16_t GetEntityListCount(EntityType list);
|
||||
uint16_t GetMiscEntityCount();
|
||||
uint16_t GetNumFreeEntities();
|
||||
const std::vector<EntityId>& GetEntityTileList(const CoordsXY& spritePos);
|
||||
|
||||
template<typename T>
|
||||
class EntityTileIterator
|
||||
namespace OpenRCT2
|
||||
{
|
||||
private:
|
||||
const std::list<EntityId>& GetEntityList(const EntityType id);
|
||||
|
||||
uint16_t GetEntityListCount(EntityType list);
|
||||
uint16_t GetMiscEntityCount();
|
||||
uint16_t GetNumFreeEntities();
|
||||
const std::vector<EntityId>& GetEntityTileList(const CoordsXY& spritePos);
|
||||
|
||||
template<typename T>
|
||||
class EntityTileIterator
|
||||
{
|
||||
private:
|
||||
std::vector<EntityId>::const_iterator iter;
|
||||
std::vector<EntityId>::const_iterator end;
|
||||
T* Entity = nullptr;
|
||||
|
||||
public:
|
||||
public:
|
||||
EntityTileIterator(std::vector<EntityId>::const_iterator _iter, std::vector<EntityId>::const_iterator _end)
|
||||
: iter(_iter)
|
||||
, end(_end)
|
||||
@@ -74,15 +76,15 @@ public:
|
||||
using pointer = const T*;
|
||||
using reference = const T&;
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
};
|
||||
};
|
||||
|
||||
template<typename T = EntityBase>
|
||||
class EntityTileList
|
||||
{
|
||||
private:
|
||||
template<typename T = EntityBase>
|
||||
class EntityTileList
|
||||
{
|
||||
private:
|
||||
const std::vector<EntityId>& vec;
|
||||
|
||||
public:
|
||||
public:
|
||||
EntityTileList(const CoordsXY& loc)
|
||||
: vec(GetEntityTileList(loc))
|
||||
{
|
||||
@@ -96,17 +98,17 @@ public:
|
||||
{
|
||||
return EntityTileIterator<T>(std::end(vec), std::end(vec));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class EntityListIterator
|
||||
{
|
||||
private:
|
||||
template<typename T>
|
||||
class EntityListIterator
|
||||
{
|
||||
private:
|
||||
std::list<EntityId>::const_iterator iter;
|
||||
std::list<EntityId>::const_iterator end;
|
||||
T* Entity = nullptr;
|
||||
|
||||
public:
|
||||
public:
|
||||
EntityListIterator(std::list<EntityId>::const_iterator _iter, std::list<EntityId>::const_iterator _end)
|
||||
: iter(_iter)
|
||||
, end(_end)
|
||||
@@ -148,16 +150,16 @@ public:
|
||||
using pointer = const T*;
|
||||
using reference = const T&;
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
};
|
||||
};
|
||||
|
||||
template<typename T = EntityBase>
|
||||
class EntityList
|
||||
{
|
||||
private:
|
||||
template<typename T = EntityBase>
|
||||
class EntityList
|
||||
{
|
||||
private:
|
||||
using EntityListIterator_t = EntityListIterator<T>;
|
||||
const std::list<EntityId>& vec;
|
||||
|
||||
public:
|
||||
public:
|
||||
EntityList()
|
||||
: vec(GetEntityList(T::cEntityType))
|
||||
{
|
||||
@@ -171,4 +173,5 @@ public:
|
||||
{
|
||||
return EntityListIterator_t(std::cend(vec), std::cend(vec));
|
||||
}
|
||||
};
|
||||
};
|
||||
} // namespace OpenRCT2
|
||||
|
||||
@@ -39,26 +39,30 @@
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
|
||||
using namespace OpenRCT2;
|
||||
using namespace OpenRCT2::Core;
|
||||
|
||||
static std::array<std::list<EntityId>, EnumValue(EntityType::Count)> gEntityLists;
|
||||
static std::vector<EntityId> _freeIdList;
|
||||
|
||||
static bool _entityFlashingList[kMaxEntities];
|
||||
|
||||
static constexpr const uint32_t kSpatialIndexSize = (kMaximumMapSizeTechnical * kMaximumMapSizeTechnical) + 1;
|
||||
static constexpr uint32_t kSpatialIndexNullBucket = kSpatialIndexSize - 1;
|
||||
|
||||
static constexpr uint32_t kInvalidSpatialIndex = 0xFFFFFFFFu;
|
||||
static constexpr uint32_t kSpatialIndexDirtyMask = 1u << 31;
|
||||
|
||||
static std::array<std::vector<EntityId>, kSpatialIndexSize> gEntitySpatialIndex;
|
||||
|
||||
static void FreeEntity(EntityBase& entity);
|
||||
|
||||
static constexpr uint32_t ComputeSpatialIndex(const CoordsXY& loc)
|
||||
namespace OpenRCT2
|
||||
{
|
||||
using namespace OpenRCT2::Core;
|
||||
|
||||
static constexpr const uint32_t kSpatialIndexSize = (kMaximumMapSizeTechnical * kMaximumMapSizeTechnical) + 1;
|
||||
static constexpr uint32_t kSpatialIndexNullBucket = kSpatialIndexSize - 1;
|
||||
|
||||
static constexpr uint32_t kInvalidSpatialIndex = 0xFFFFFFFFu;
|
||||
static constexpr uint32_t kSpatialIndexDirtyMask = 1u << 31;
|
||||
|
||||
// TODO: move into GameState_t
|
||||
static std::array<std::list<EntityId>, EnumValue(EntityType::Count)> gEntityLists;
|
||||
static std::vector<EntityId> _freeIdList;
|
||||
|
||||
// TODO: move into MapWindow or GameState_t?
|
||||
static bool _entityFlashingList[kMaxEntities];
|
||||
|
||||
// TODO: move into GameState_t
|
||||
static std::array<std::vector<EntityId>, kSpatialIndexSize> gEntitySpatialIndex;
|
||||
|
||||
static void FreeEntity(EntityBase& entity);
|
||||
|
||||
static constexpr uint32_t ComputeSpatialIndex(const CoordsXY& loc)
|
||||
{
|
||||
if (loc.IsNull())
|
||||
return kSpatialIndexNullBucket;
|
||||
|
||||
@@ -70,15 +74,15 @@ static constexpr uint32_t ComputeSpatialIndex(const CoordsXY& loc)
|
||||
return kSpatialIndexNullBucket;
|
||||
|
||||
return tileX * kMaximumMapSizeTechnical + tileY;
|
||||
}
|
||||
}
|
||||
|
||||
static constexpr uint32_t GetSpatialIndex(EntityBase& entity)
|
||||
{
|
||||
static constexpr uint32_t GetSpatialIndex(EntityBase& entity)
|
||||
{
|
||||
return entity.SpatialIndex & ~kSpatialIndexDirtyMask;
|
||||
}
|
||||
}
|
||||
|
||||
constexpr bool EntityTypeIsMiscEntity(const EntityType type)
|
||||
{
|
||||
constexpr bool EntityTypeIsMiscEntity(const EntityType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case EntityType::SteamParticle:
|
||||
@@ -94,55 +98,55 @@ constexpr bool EntityTypeIsMiscEntity(const EntityType type)
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t GetEntityListCount(EntityType type)
|
||||
{
|
||||
uint16_t GetEntityListCount(EntityType type)
|
||||
{
|
||||
return static_cast<uint16_t>(gEntityLists[EnumValue(type)].size());
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t GetNumFreeEntities()
|
||||
{
|
||||
uint16_t GetNumFreeEntities()
|
||||
{
|
||||
return static_cast<uint16_t>(_freeIdList.size());
|
||||
}
|
||||
}
|
||||
|
||||
std::string EntitiesChecksum::ToString() const
|
||||
{
|
||||
std::string EntitiesChecksum::ToString() const
|
||||
{
|
||||
return String::StringFromHex(raw);
|
||||
}
|
||||
}
|
||||
|
||||
EntityBase* TryGetEntity(EntityId entityIndex)
|
||||
{
|
||||
EntityBase* TryGetEntity(EntityId entityIndex)
|
||||
{
|
||||
auto& gameState = getGameState();
|
||||
const auto idx = entityIndex.ToUnderlying();
|
||||
return idx >= kMaxEntities ? nullptr : &gameState.entities[idx].base;
|
||||
}
|
||||
}
|
||||
|
||||
EntityBase* GetEntity(EntityId entityIndex)
|
||||
{
|
||||
EntityBase* GetEntity(EntityId entityIndex)
|
||||
{
|
||||
if (entityIndex.IsNull())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
Guard::Assert(entityIndex.ToUnderlying() < kMaxEntities, "Tried getting entity %u", entityIndex.ToUnderlying());
|
||||
return TryGetEntity(entityIndex);
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<EntityId>& GetEntityTileList(const CoordsXY& spritePos)
|
||||
{
|
||||
const std::vector<EntityId>& GetEntityTileList(const CoordsXY& spritePos)
|
||||
{
|
||||
return gEntitySpatialIndex[ComputeSpatialIndex(spritePos)];
|
||||
}
|
||||
}
|
||||
|
||||
static void ResetEntityLists()
|
||||
{
|
||||
static void ResetEntityLists()
|
||||
{
|
||||
for (auto& list : gEntityLists)
|
||||
{
|
||||
list.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ResetFreeIds()
|
||||
{
|
||||
static void ResetFreeIds()
|
||||
{
|
||||
_freeIdList.clear();
|
||||
_freeIdList.resize(kMaxEntities);
|
||||
|
||||
@@ -152,19 +156,19 @@ static void ResetFreeIds()
|
||||
elem = EntityId::FromUnderlying(nextId);
|
||||
nextId++;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const std::list<EntityId>& GetEntityList(const EntityType id)
|
||||
{
|
||||
const std::list<EntityId>& GetEntityList(const EntityType id)
|
||||
{
|
||||
return gEntityLists[EnumValue(id)];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
*
|
||||
* rct2: 0x0069EB13
|
||||
*/
|
||||
void ResetAllEntities()
|
||||
{
|
||||
void ResetAllEntities()
|
||||
{
|
||||
// Free all associated Entity pointers prior to zeroing memory
|
||||
for (int32_t i = 0; i < kMaxEntities; ++i)
|
||||
{
|
||||
@@ -195,18 +199,18 @@ void ResetAllEntities()
|
||||
ResetEntityLists();
|
||||
ResetFreeIds();
|
||||
ResetEntitySpatialIndices();
|
||||
}
|
||||
}
|
||||
|
||||
static void EntitySpatialInsert(EntityBase& entity, const CoordsXY& newLoc);
|
||||
static void EntitySpatialInsert(EntityBase& entity, const CoordsXY& newLoc);
|
||||
|
||||
/**
|
||||
/**
|
||||
*
|
||||
* rct2: 0x0069EBE4
|
||||
* This function looks as though it sets some sort of order for sprites.
|
||||
* Sprites can share their position if this is the case.
|
||||
*/
|
||||
void ResetEntitySpatialIndices()
|
||||
{
|
||||
void ResetEntitySpatialIndices()
|
||||
{
|
||||
for (auto& vec : gEntitySpatialIndex)
|
||||
{
|
||||
vec.clear();
|
||||
@@ -219,27 +223,27 @@ void ResetEntitySpatialIndices()
|
||||
EntitySpatialInsert(*entity, { entity->x, entity->y });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef DISABLE_NETWORK
|
||||
|
||||
template<typename T>
|
||||
void NetworkSerialseEntityType(DataSerialiser& ds)
|
||||
{
|
||||
template<typename T>
|
||||
void NetworkSerialseEntityType(DataSerialiser& ds)
|
||||
{
|
||||
for (auto* ent : EntityList<T>())
|
||||
{
|
||||
ent->Serialise(ds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename... T>
|
||||
void NetworkSerialiseEntityTypes(DataSerialiser& ds)
|
||||
{
|
||||
template<typename... T>
|
||||
void NetworkSerialiseEntityTypes(DataSerialiser& ds)
|
||||
{
|
||||
(NetworkSerialseEntityType<T>(ds), ...);
|
||||
}
|
||||
}
|
||||
|
||||
EntitiesChecksum GetAllEntitiesChecksum()
|
||||
{
|
||||
EntitiesChecksum GetAllEntitiesChecksum()
|
||||
{
|
||||
EntitiesChecksum checksum{};
|
||||
|
||||
OpenRCT2::ChecksumStream ms(checksum.raw);
|
||||
@@ -247,18 +251,18 @@ EntitiesChecksum GetAllEntitiesChecksum()
|
||||
NetworkSerialiseEntityTypes<Guest, Staff, Vehicle, Litter>(ds);
|
||||
|
||||
return checksum;
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
EntitiesChecksum GetAllEntitiesChecksum()
|
||||
{
|
||||
EntitiesChecksum GetAllEntitiesChecksum()
|
||||
{
|
||||
return EntitiesChecksum{};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // DISABLE_NETWORK
|
||||
|
||||
static void EntityReset(EntityBase& entity)
|
||||
{
|
||||
static void EntityReset(EntityBase& entity)
|
||||
{
|
||||
// Need to retain how the sprite is linked in lists
|
||||
auto entityIndex = entity.Id;
|
||||
_entityFlashingList[entityIndex.ToUnderlying()] = false;
|
||||
@@ -268,36 +272,36 @@ static void EntityReset(EntityBase& entity)
|
||||
|
||||
entity.Id = entityIndex;
|
||||
entity.Type = EntityType::Null;
|
||||
}
|
||||
}
|
||||
|
||||
static constexpr uint16_t kMaxMiscEntities = 3200;
|
||||
static constexpr uint16_t kMaxMiscEntities = 3200;
|
||||
|
||||
static void AddToEntityList(EntityBase& entity)
|
||||
{
|
||||
static void AddToEntityList(EntityBase& entity)
|
||||
{
|
||||
auto& list = gEntityLists[EnumValue(entity.Type)];
|
||||
|
||||
// Entity list is sorted by Id to prevent desyncs.
|
||||
Algorithm::sortedInsert(list, entity.Id);
|
||||
}
|
||||
}
|
||||
|
||||
static void AddToFreeList(EntityId index)
|
||||
{
|
||||
static void AddToFreeList(EntityId index)
|
||||
{
|
||||
// Free list must be in reverse sprite_index order to prevent desync issues
|
||||
_freeIdList.insert(std::upper_bound(std::rbegin(_freeIdList), std::rend(_freeIdList), index).base(), index);
|
||||
}
|
||||
}
|
||||
|
||||
static void RemoveFromEntityList(EntityBase& entity)
|
||||
{
|
||||
static void RemoveFromEntityList(EntityBase& entity)
|
||||
{
|
||||
auto& list = gEntityLists[EnumValue(entity.Type)];
|
||||
auto ptr = Algorithm::binaryFind(std::begin(list), std::end(list), entity.Id);
|
||||
if (ptr != std::end(list))
|
||||
{
|
||||
list.erase(ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t GetMiscEntityCount()
|
||||
{
|
||||
uint16_t GetMiscEntityCount()
|
||||
{
|
||||
uint16_t count = 0;
|
||||
for (auto id : { EntityType::SteamParticle, EntityType::MoneyEffect, EntityType::CrashedVehicleParticle,
|
||||
EntityType::ExplosionCloud, EntityType::CrashSplash, EntityType::ExplosionFlare,
|
||||
@@ -306,10 +310,10 @@ uint16_t GetMiscEntityCount()
|
||||
count += GetEntityListCount(id);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
static void PrepareNewEntity(EntityBase& base, const EntityType type)
|
||||
{
|
||||
static void PrepareNewEntity(EntityBase& base, const EntityType type)
|
||||
{
|
||||
// Need to reset all sprite data, as the uninitialised values
|
||||
// may contain garbage and cause a desync later on.
|
||||
EntityReset(base);
|
||||
@@ -327,10 +331,10 @@ static void PrepareNewEntity(EntityBase& base, const EntityType type)
|
||||
base.SpatialIndex = kInvalidSpatialIndex;
|
||||
|
||||
EntitySpatialInsert(base, { kLocationNull, 0 });
|
||||
}
|
||||
}
|
||||
|
||||
EntityBase* CreateEntity(EntityType type)
|
||||
{
|
||||
EntityBase* CreateEntity(EntityType type)
|
||||
{
|
||||
if (_freeIdList.size() == 0)
|
||||
{
|
||||
// No free sprites.
|
||||
@@ -362,10 +366,10 @@ EntityBase* CreateEntity(EntityType type)
|
||||
PrepareNewEntity(*entity, type);
|
||||
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
||||
EntityBase* CreateEntityAt(const EntityId index, const EntityType type)
|
||||
{
|
||||
EntityBase* CreateEntityAt(const EntityId index, const EntityType type)
|
||||
{
|
||||
auto id = Algorithm::binaryFind(std::rbegin(_freeIdList), std::rend(_freeIdList), index);
|
||||
if (id == std::rend(_freeIdList))
|
||||
{
|
||||
@@ -382,44 +386,44 @@ EntityBase* CreateEntityAt(const EntityId index, const EntityType type)
|
||||
|
||||
PrepareNewEntity(*entity, type);
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void MiscUpdateAllType()
|
||||
{
|
||||
template<typename T>
|
||||
void MiscUpdateAllType()
|
||||
{
|
||||
for (auto misc : EntityList<T>())
|
||||
{
|
||||
misc->Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename... T>
|
||||
void MiscUpdateAllTypes()
|
||||
{
|
||||
template<typename... T>
|
||||
void MiscUpdateAllTypes()
|
||||
{
|
||||
(MiscUpdateAllType<T>(), ...);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
*
|
||||
* rct2: 0x00672AA4
|
||||
*/
|
||||
void UpdateAllMiscEntities()
|
||||
{
|
||||
void UpdateAllMiscEntities()
|
||||
{
|
||||
PROFILED_FUNCTION();
|
||||
|
||||
MiscUpdateAllTypes<
|
||||
SteamParticle, MoneyEffect, VehicleCrashParticle, ExplosionCloud, CrashSplashParticle, ExplosionFlare, JumpingFountain,
|
||||
Balloon, Duck>();
|
||||
}
|
||||
SteamParticle, MoneyEffect, VehicleCrashParticle, ExplosionCloud, CrashSplashParticle, ExplosionFlare,
|
||||
JumpingFountain, Balloon, Duck>();
|
||||
}
|
||||
|
||||
void UpdateMoneyEffect()
|
||||
{
|
||||
void UpdateMoneyEffect()
|
||||
{
|
||||
MiscUpdateAllTypes<MoneyEffect>();
|
||||
}
|
||||
}
|
||||
|
||||
// Performs a search to ensure that insert keeps next_in_quadrant in sprite_index order
|
||||
static void EntitySpatialInsert(EntityBase& entity, const CoordsXY& newLoc)
|
||||
{
|
||||
// Performs a search to ensure that insert keeps next_in_quadrant in sprite_index order
|
||||
static void EntitySpatialInsert(EntityBase& entity, const CoordsXY& newLoc)
|
||||
{
|
||||
const auto newIndex = ComputeSpatialIndex(newLoc);
|
||||
|
||||
auto& spatialVector = gEntitySpatialIndex[newIndex];
|
||||
@@ -427,10 +431,10 @@ static void EntitySpatialInsert(EntityBase& entity, const CoordsXY& newLoc)
|
||||
Algorithm::sortedInsert(spatialVector, entity.Id);
|
||||
|
||||
entity.SpatialIndex = newIndex;
|
||||
}
|
||||
}
|
||||
|
||||
static void EntitySpatialRemove(EntityBase& entity)
|
||||
{
|
||||
static void EntitySpatialRemove(EntityBase& entity)
|
||||
{
|
||||
const auto currentIndex = GetSpatialIndex(entity);
|
||||
|
||||
auto& spatialVector = gEntitySpatialIndex[currentIndex];
|
||||
@@ -446,10 +450,10 @@ static void EntitySpatialRemove(EntityBase& entity)
|
||||
}
|
||||
|
||||
entity.SpatialIndex = kInvalidSpatialIndex;
|
||||
}
|
||||
}
|
||||
|
||||
static void UpdateEntitySpatialIndex(EntityBase& entity)
|
||||
{
|
||||
static void UpdateEntitySpatialIndex(EntityBase& entity)
|
||||
{
|
||||
if (entity.SpatialIndex & kSpatialIndexDirtyMask)
|
||||
{
|
||||
if (entity.SpatialIndex != kInvalidSpatialIndex)
|
||||
@@ -458,10 +462,10 @@ static void UpdateEntitySpatialIndex(EntityBase& entity)
|
||||
}
|
||||
EntitySpatialInsert(entity, { entity.x, entity.y });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateEntitiesSpatialIndex()
|
||||
{
|
||||
void UpdateEntitiesSpatialIndex()
|
||||
{
|
||||
for (auto& entityList : gEntityLists)
|
||||
{
|
||||
for (auto& entityId : entityList)
|
||||
@@ -473,7 +477,10 @@ void UpdateEntitiesSpatialIndex()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace OpenRCT2
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
||||
CoordsXYZ EntityBase::GetLocation() const
|
||||
{
|
||||
@@ -549,11 +556,13 @@ void EntityBase::MoveToAndUpdateSpatialIndex(const CoordsXYZ& newLocation)
|
||||
UpdateEntitySpatialIndex(*this);
|
||||
}
|
||||
|
||||
/**
|
||||
namespace OpenRCT2
|
||||
{
|
||||
/**
|
||||
* Frees any dynamically attached memory to the entity, such as peep name.
|
||||
*/
|
||||
static void FreeEntity(EntityBase& entity)
|
||||
{
|
||||
static void FreeEntity(EntityBase& entity)
|
||||
{
|
||||
auto* guest = entity.As<Guest>();
|
||||
auto* staff = entity.As<Staff>();
|
||||
if (staff != nullptr)
|
||||
@@ -569,14 +578,14 @@ static void FreeEntity(EntityBase& entity)
|
||||
OpenRCT2::RideUse::GetHistory().RemoveHandle(guest->Id);
|
||||
OpenRCT2::RideUse::GetTypeHistory().RemoveHandle(guest->Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
*
|
||||
* rct2: 0x0069EDB6
|
||||
*/
|
||||
void EntityRemove(EntityBase* entity)
|
||||
{
|
||||
void EntityRemove(EntityBase* entity)
|
||||
{
|
||||
FreeEntity(*entity);
|
||||
|
||||
EntityTweener::Get().RemoveEntity(entity);
|
||||
@@ -585,14 +594,14 @@ void EntityRemove(EntityBase* entity)
|
||||
|
||||
EntitySpatialRemove(*entity);
|
||||
EntityReset(*entity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Loops through all floating entities and removes them.
|
||||
* Returns the amount of removed objects as feedback.
|
||||
*/
|
||||
uint16_t RemoveFloatingEntities()
|
||||
{
|
||||
uint16_t RemoveFloatingEntities()
|
||||
{
|
||||
uint16_t removed = 0;
|
||||
for (auto* balloon : EntityList<Balloon>())
|
||||
{
|
||||
@@ -613,16 +622,17 @@ uint16_t RemoveFloatingEntities()
|
||||
removed++;
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
}
|
||||
|
||||
void EntitySetFlashing(EntityBase* entity, bool flashing)
|
||||
{
|
||||
void EntitySetFlashing(EntityBase* entity, bool flashing)
|
||||
{
|
||||
assert(entity->Id.ToUnderlying() < kMaxEntities);
|
||||
_entityFlashingList[entity->Id.ToUnderlying()] = flashing;
|
||||
}
|
||||
}
|
||||
|
||||
bool EntityGetFlashing(EntityBase* entity)
|
||||
{
|
||||
bool EntityGetFlashing(EntityBase* entity)
|
||||
{
|
||||
assert(entity->Id.ToUnderlying() < kMaxEntities);
|
||||
return _entityFlashingList[entity->Id.ToUnderlying()];
|
||||
}
|
||||
}
|
||||
} // namespace OpenRCT2
|
||||
|
||||
@@ -25,15 +25,14 @@ namespace OpenRCT2
|
||||
{
|
||||
}
|
||||
};
|
||||
} // namespace OpenRCT2
|
||||
|
||||
constexpr uint16_t kMaxEntities = 65535;
|
||||
constexpr uint16_t kMaxEntities = 65535;
|
||||
|
||||
EntityBase* GetEntity(EntityId entityId);
|
||||
EntityBase* GetEntity(EntityId entityId);
|
||||
|
||||
template<typename T>
|
||||
T* GetEntity(EntityId entityId)
|
||||
{
|
||||
template<typename T>
|
||||
T* GetEntity(EntityId entityId)
|
||||
{
|
||||
auto* ent = GetEntity(entityId);
|
||||
if (ent == nullptr)
|
||||
{
|
||||
@@ -47,13 +46,13 @@ T* GetEntity(EntityId entityId)
|
||||
{
|
||||
return ent->As<T>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EntityBase* TryGetEntity(EntityId spriteIndex);
|
||||
EntityBase* TryGetEntity(EntityId spriteIndex);
|
||||
|
||||
template<typename T>
|
||||
T* TryGetEntity(EntityId entityId)
|
||||
{
|
||||
template<typename T>
|
||||
T* TryGetEntity(EntityId entityId)
|
||||
{
|
||||
auto* ent = TryGetEntity(entityId);
|
||||
if (ent == nullptr)
|
||||
{
|
||||
@@ -67,42 +66,43 @@ T* TryGetEntity(EntityId entityId)
|
||||
{
|
||||
return ent->As<T>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EntityBase* CreateEntity(EntityType type);
|
||||
EntityBase* CreateEntity(EntityType type);
|
||||
|
||||
template<typename T>
|
||||
T* CreateEntity()
|
||||
{
|
||||
template<typename T>
|
||||
T* CreateEntity()
|
||||
{
|
||||
return static_cast<T*>(CreateEntity(T::cEntityType));
|
||||
}
|
||||
}
|
||||
|
||||
// Use only with imports that must happen at a specified index
|
||||
EntityBase* CreateEntityAt(const EntityId index, const EntityType type);
|
||||
// Use only with imports that must happen at a specified index
|
||||
template<typename T>
|
||||
T* CreateEntityAt(const EntityId index)
|
||||
{
|
||||
// Use only with imports that must happen at a specified index
|
||||
EntityBase* CreateEntityAt(const EntityId index, const EntityType type);
|
||||
// Use only with imports that must happen at a specified index
|
||||
template<typename T>
|
||||
T* CreateEntityAt(const EntityId index)
|
||||
{
|
||||
return static_cast<T*>(CreateEntityAt(index, T::cEntityType));
|
||||
}
|
||||
}
|
||||
|
||||
void ResetAllEntities();
|
||||
void ResetEntitySpatialIndices();
|
||||
void UpdateAllMiscEntities();
|
||||
void UpdateMoneyEffect();
|
||||
void EntityRemove(EntityBase* entity);
|
||||
uint16_t RemoveFloatingEntities();
|
||||
void UpdateEntitiesSpatialIndex();
|
||||
void ResetAllEntities();
|
||||
void ResetEntitySpatialIndices();
|
||||
void UpdateAllMiscEntities();
|
||||
void UpdateMoneyEffect();
|
||||
void EntityRemove(EntityBase* entity);
|
||||
uint16_t RemoveFloatingEntities();
|
||||
void UpdateEntitiesSpatialIndex();
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct EntitiesChecksum
|
||||
{
|
||||
struct EntitiesChecksum
|
||||
{
|
||||
std::array<std::byte, 20> raw;
|
||||
|
||||
std::string ToString() const;
|
||||
};
|
||||
};
|
||||
#pragma pack(pop)
|
||||
EntitiesChecksum GetAllEntitiesChecksum();
|
||||
EntitiesChecksum GetAllEntitiesChecksum();
|
||||
|
||||
void EntitySetFlashing(EntityBase* entity, bool flashing);
|
||||
bool EntityGetFlashing(EntityBase* entity);
|
||||
void EntitySetFlashing(EntityBase* entity, bool flashing);
|
||||
bool EntityGetFlashing(EntityBase* entity);
|
||||
} // namespace OpenRCT2
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
|
||||
#include <iterator>
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
||||
static constexpr uint32_t kVehicleCrashParticleSprites[kCrashedVehicleParticleNumberTypes] = {
|
||||
SPR_VEHICLE_CRASH_PARTICLE_1, SPR_VEHICLE_CRASH_PARTICLE_2, SPR_VEHICLE_CRASH_PARTICLE_3,
|
||||
SPR_VEHICLE_CRASH_PARTICLE_4, SPR_VEHICLE_CRASH_PARTICLE_5,
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace OpenRCT2::Scripting
|
||||
|
||||
Balloon* ScBalloon::GetBalloon() const
|
||||
{
|
||||
return ::GetEntity<Balloon>(_id);
|
||||
return OpenRCT2::GetEntity<Balloon>(_id);
|
||||
}
|
||||
|
||||
uint8_t ScBalloon::colour_get() const
|
||||
|
||||
@@ -192,7 +192,7 @@ namespace OpenRCT2::Scripting
|
||||
|
||||
EntityBase* GetEntity() const
|
||||
{
|
||||
return ::GetEntity(_id);
|
||||
return OpenRCT2::GetEntity(_id);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
@@ -194,7 +194,7 @@ namespace OpenRCT2::Scripting
|
||||
|
||||
Guest* ScGuest::GetGuest() const
|
||||
{
|
||||
return ::GetEntity<Guest>(_id);
|
||||
return OpenRCT2::GetEntity<Guest>(_id);
|
||||
}
|
||||
|
||||
uint8_t ScGuest::tshirtColour_get() const
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace OpenRCT2::Scripting
|
||||
|
||||
Litter* ScLitter::GetLitter() const
|
||||
{
|
||||
return ::GetEntity<Litter>(_id);
|
||||
return OpenRCT2::GetEntity<Litter>(_id);
|
||||
}
|
||||
|
||||
std::string ScLitter::litterType_get() const
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace OpenRCT2::Scripting
|
||||
|
||||
MoneyEffect* ScMoneyEffect::GetMoneyEffect() const
|
||||
{
|
||||
return ::GetEntity<MoneyEffect>(_id);
|
||||
return OpenRCT2::GetEntity<MoneyEffect>(_id);
|
||||
}
|
||||
|
||||
money64 ScMoneyEffect::value_get() const
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace OpenRCT2::Scripting
|
||||
|
||||
VehicleCrashParticle* ScCrashedVehicleParticle::GetCrashedVehicleParticle() const
|
||||
{
|
||||
return ::GetEntity<VehicleCrashParticle>(_id);
|
||||
return OpenRCT2::GetEntity<VehicleCrashParticle>(_id);
|
||||
}
|
||||
|
||||
void ScCrashedVehicleParticle::frame_set(uint8_t value)
|
||||
|
||||
@@ -196,7 +196,7 @@ namespace OpenRCT2::Scripting
|
||||
protected:
|
||||
Peep* GetPeep() const
|
||||
{
|
||||
return ::GetEntity<Peep>(_id);
|
||||
return OpenRCT2::GetEntity<Peep>(_id);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace OpenRCT2::Scripting
|
||||
|
||||
Staff* ScStaff::GetStaff() const
|
||||
{
|
||||
return ::GetEntity<Staff>(_id);
|
||||
return OpenRCT2::GetEntity<Staff>(_id);
|
||||
}
|
||||
|
||||
std::string ScStaff::staffType_get() const
|
||||
@@ -420,7 +420,7 @@ namespace OpenRCT2::Scripting
|
||||
|
||||
Staff* ScHandyman::GetHandyman() const
|
||||
{
|
||||
return ::GetEntity<Staff>(_id);
|
||||
return OpenRCT2::GetEntity<Staff>(_id);
|
||||
}
|
||||
|
||||
DukValue ScHandyman::lawnsMown_get() const
|
||||
@@ -501,7 +501,7 @@ namespace OpenRCT2::Scripting
|
||||
|
||||
Staff* ScMechanic::GetMechanic() const
|
||||
{
|
||||
return ::GetEntity<Staff>(_id);
|
||||
return OpenRCT2::GetEntity<Staff>(_id);
|
||||
}
|
||||
|
||||
DukValue ScMechanic::ridesFixed_get() const
|
||||
@@ -549,7 +549,7 @@ namespace OpenRCT2::Scripting
|
||||
|
||||
Staff* ScSecurity::GetSecurity() const
|
||||
{
|
||||
return ::GetEntity<Staff>(_id);
|
||||
return OpenRCT2::GetEntity<Staff>(_id);
|
||||
}
|
||||
|
||||
DukValue ScSecurity::vandalsStopped_get() const
|
||||
|
||||
Reference in New Issue
Block a user