diff --git a/src/openrct2/GameState.h b/src/openrct2/GameState.h index ee9a81fb7c..eeda3497c0 100644 --- a/src/openrct2/GameState.h +++ b/src/openrct2/GameState.h @@ -95,6 +95,7 @@ namespace OpenRCT2 std::string ScenarioCompletedBy; std::vector Banners; + Entity_t Entities[MAX_ENTITIES]{}; // Ride storage for all the rides in the park, rides with RideId::Null are considered free. std::array Rides{}; ::RideRatingUpdateStates RideRatingUpdateStates; diff --git a/src/openrct2/entity/EntityRegistry.cpp b/src/openrct2/entity/EntityRegistry.cpp index 9737faef72..47f50f8afe 100644 --- a/src/openrct2/entity/EntityRegistry.cpp +++ b/src/openrct2/entity/EntityRegistry.cpp @@ -10,6 +10,7 @@ #include "EntityRegistry.h" #include "../Game.h" +#include "../GameState.h" #include "../core/Algorithm.hpp" #include "../core/ChecksumStream.h" #include "../core/Crypt.h" @@ -36,17 +37,8 @@ #include #include -union Entity -{ - uint8_t Pad00[0x200]; - EntityBase base; - Entity() - : Pad00() - { - } -}; +using namespace OpenRCT2; -static Entity _entities[MAX_ENTITIES]{}; static std::array, EnumValue(EntityType::Count)> gEntityLists; static std::vector _freeIdList; @@ -120,8 +112,9 @@ std::string EntitiesChecksum::ToString() const EntityBase* TryGetEntity(EntityId entityIndex) { + auto& gameState = GetGameState(); const auto idx = entityIndex.ToUnderlying(); - return idx >= MAX_ENTITIES ? nullptr : &_entities[idx].base; + return idx >= MAX_ENTITIES ? nullptr : &gameState.Entities[idx].base; } EntityBase* GetEntity(EntityId entityIndex) @@ -182,7 +175,8 @@ void ResetAllEntities() FreeEntity(*spr); } - std::fill(std::begin(_entities), std::end(_entities), Entity()); + auto& gameState = GetGameState(); + std::fill(std::begin(gameState.Entities), std::end(gameState.Entities), Entity_t()); OpenRCT2::RideUse::GetHistory().Clear(); OpenRCT2::RideUse::GetTypeHistory().Clear(); for (int32_t i = 0; i < MAX_ENTITIES; ++i) @@ -266,8 +260,8 @@ static void EntityReset(EntityBase* entity) auto entityIndex = entity->Id; _entityFlashingList[entityIndex.ToUnderlying()] = false; - Entity* spr = reinterpret_cast(entity); - *spr = Entity(); + Entity_t* tempEntity = reinterpret_cast(entity); + *tempEntity = Entity_t(); entity->Id = entityIndex; entity->Type = EntityType::Null; diff --git a/src/openrct2/entity/EntityRegistry.h b/src/openrct2/entity/EntityRegistry.h index af5477c334..e17c08be8f 100644 --- a/src/openrct2/entity/EntityRegistry.h +++ b/src/openrct2/entity/EntityRegistry.h @@ -14,6 +14,19 @@ #include +namespace OpenRCT2 +{ + union Entity_t + { + uint8_t Pad00[0x200]; + EntityBase base; + Entity_t() + : Pad00() + { + } + }; +} // namespace OpenRCT2 + constexpr uint16_t MAX_ENTITIES = 65535; EntityBase* GetEntity(EntityId sprite_idx);