diff --git a/src/openrct2-ui/ride/VehicleSounds.cpp b/src/openrct2-ui/ride/VehicleSounds.cpp index 33d3ee30f7..34b876d0de 100644 --- a/src/openrct2-ui/ride/VehicleSounds.cpp +++ b/src/openrct2-ui/ride/VehicleSounds.cpp @@ -73,7 +73,7 @@ namespace OpenRCT2::Audio } iterator& operator++() { - Current = GetEntity(NextVehicleId); + Current = getGameState().entities.GetEntity(NextVehicleId); if (Current != nullptr) { NextVehicleId = Current->next_vehicle_on_train; @@ -603,7 +603,7 @@ namespace OpenRCT2::Audio vehicleSound->volume = tempvolume; panVol = std::max(0, panVol - tempvolume); - Vehicle* vehicle = GetEntity(EntityId::FromUnderlying(vehicleSoundParams.id)); + Vehicle* vehicle = getGameState().entities.GetEntity(EntityId::FromUnderlying(vehicleSoundParams.id)); if (vehicle != nullptr) { UpdateSound( diff --git a/src/openrct2-ui/title/TitleSequencePlayer.cpp b/src/openrct2-ui/title/TitleSequencePlayer.cpp index 226027641b..c4e40cd440 100644 --- a/src/openrct2-ui/title/TitleSequencePlayer.cpp +++ b/src/openrct2-ui/title/TitleSequencePlayer.cpp @@ -432,8 +432,9 @@ namespace OpenRCT2::Title auto windowManager = Ui::GetWindowManager(); auto& gameState = getGameState(); windowManager->SetMainView(gameState.savedView, gameState.savedViewZoom, gameState.savedViewRotation); - ResetEntitySpatialIndices(); + gameState.entities.ResetEntitySpatialIndices(); ResetAllSpriteQuadrantPlacements(); + auto intent = Intent(INTENT_ACTION_REFRESH_NEW_RIDES); ContextBroadcastIntent(&intent); Ui::Windows::WindowScenerySetDefaultPlacementConfiguration(); diff --git a/src/openrct2-ui/windows/EditorBottomToolbar.cpp b/src/openrct2-ui/windows/EditorBottomToolbar.cpp index 232f9e4674..2fc4619c4f 100644 --- a/src/openrct2-ui/windows/EditorBottomToolbar.cpp +++ b/src/openrct2-ui/windows/EditorBottomToolbar.cpp @@ -79,7 +79,9 @@ namespace OpenRCT2::Ui::Windows bool GameHasEntities() const { - return GetNumFreeEntities() != kMaxEntities || getGameState().park.flags & PARK_FLAGS_SPRITES_INITIALISED; + auto& gameState = getGameState(); + return gameState.entities.GetNumFreeEntities() != kMaxEntities + || gameState.park.flags & PARK_FLAGS_SPRITES_INITIALISED; } void OnPrepareDraw() override diff --git a/src/openrct2-ui/windows/GameBottomToolbar.cpp b/src/openrct2-ui/windows/GameBottomToolbar.cpp index aa830a4c52..e24b98ee60 100644 --- a/src/openrct2-ui/windows/GameBottomToolbar.cpp +++ b/src/openrct2-ui/windows/GameBottomToolbar.cpp @@ -267,7 +267,7 @@ namespace OpenRCT2::Ui::Windows break; } - auto peep = TryGetEntity(EntityId::FromUnderlying(newsItem->assoc)); + auto peep = getGameState().entities.TryGetEntity(EntityId::FromUnderlying(newsItem->assoc)); if (peep == nullptr) return; diff --git a/src/openrct2-ui/windows/Guest.cpp b/src/openrct2-ui/windows/Guest.cpp index 991a8a8624..3f0f36bfe1 100644 --- a/src/openrct2-ui/windows/Guest.cpp +++ b/src/openrct2-ui/windows/Guest.cpp @@ -427,7 +427,7 @@ namespace OpenRCT2::Ui::Windows private: Guest* GetGuest() { - auto guest = GetEntity(EntityId::FromUnderlying(number)); + auto guest = getGameState().entities.GetEntity(EntityId::FromUnderlying(number)); if (guest == nullptr) { Close(); diff --git a/src/openrct2-ui/windows/GuestList.cpp b/src/openrct2-ui/windows/GuestList.cpp index 0ea291922c..7b095c3cec 100644 --- a/src/openrct2-ui/windows/GuestList.cpp +++ b/src/openrct2-ui/windows/GuestList.cpp @@ -541,7 +541,7 @@ namespace OpenRCT2::Ui::Windows { if (i == 0) { - auto guest = GetEntity(guestItem.Id); + auto guest = getGameState().entities.GetEntity(guestItem.Id); if (guest != nullptr) { GuestOpen(guest); @@ -600,14 +600,14 @@ namespace OpenRCT2::Ui::Windows for (auto peep : EntityList()) { - EntitySetFlashing(peep, false); + getGameState().entities.EntitySetFlashing(peep, false); if (peep->OutsideOfPark) continue; if (_selectedFilter) { if (!IsPeepInFilter(*peep)) continue; - EntitySetFlashing(peep, true); + getGameState().entities.EntitySetFlashing(peep, true); } if (!GuestShouldBeVisible(*peep)) continue; @@ -661,7 +661,7 @@ namespace OpenRCT2::Ui::Windows } // Guest name - auto peep = GetEntity(guestItem.Id); + auto peep = getGameState().entities.GetEntity(guestItem.Id); if (peep == nullptr) { continue; @@ -916,8 +916,8 @@ namespace OpenRCT2::Ui::Windows template static bool CompareGuestItem(const GuestItem& a, const GuestItem& b) { - const auto* peepA = GetEntity(a.Id); - const auto* peepB = GetEntity(b.Id); + const auto* peepA = getGameState().entities.GetEntity(a.Id); + const auto* peepB = getGameState().entities.GetEntity(b.Id); if (peepA != nullptr && peepB != nullptr) { // Compare types diff --git a/src/openrct2-ui/windows/Map.cpp b/src/openrct2-ui/windows/Map.cpp index 97434c6d05..18c681abf9 100644 --- a/src/openrct2-ui/windows/Map.cpp +++ b/src/openrct2-ui/windows/Map.cpp @@ -971,7 +971,7 @@ namespace OpenRCT2::Ui::Windows auto leftTop = ScreenCoordsXY{ c.x, c.y } + offset; auto rightBottom = leftTop; uint8_t colour = DefaultPeepMapColour; - if (EntityGetFlashing(peep)) + if (getGameState().entities.EntityGetFlashing(peep)) { colour = flashColour; // If flashing then map peep pixel size is increased (by moving left top downwards) @@ -1012,7 +1012,8 @@ namespace OpenRCT2::Ui::Windows { for (auto train : TrainManager::View()) { - for (Vehicle* vehicle = train; vehicle != nullptr; vehicle = GetEntity(vehicle->next_vehicle_on_train)) + for (Vehicle* vehicle = train; vehicle != nullptr; + vehicle = getGameState().entities.GetEntity(vehicle->next_vehicle_on_train)) { if (vehicle->x == kLocationNull) continue; diff --git a/src/openrct2-ui/windows/News.cpp b/src/openrct2-ui/windows/News.cpp index 0c6020c6d2..c2288426a8 100644 --- a/src/openrct2-ui/windows/News.cpp +++ b/src/openrct2-ui/windows/News.cpp @@ -504,7 +504,7 @@ namespace OpenRCT2::Ui::Windows break; } - auto peep = TryGetEntity(EntityId::FromUnderlying(newsItem.assoc)); + auto peep = getGameState().entities.TryGetEntity(EntityId::FromUnderlying(newsItem.assoc)); if (peep == nullptr) { break; diff --git a/src/openrct2-ui/windows/PatrolArea.cpp b/src/openrct2-ui/windows/PatrolArea.cpp index 2e61d0e47b..a97c9aa9c5 100644 --- a/src/openrct2-ui/windows/PatrolArea.cpp +++ b/src/openrct2-ui/windows/PatrolArea.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -204,7 +205,7 @@ namespace OpenRCT2::Ui::Windows auto mapTile = GetBestCoordsFromPos(screenCoords); if (mapTile) { - auto staff = GetEntity(_staffId); + auto staff = getGameState().entities.GetEntity(_staffId); if (staff != nullptr) { _mode = staff->IsPatrolAreaSet(*mapTile) ? GameActions::StaffSetPatrolAreaMode::Unset @@ -217,7 +218,7 @@ namespace OpenRCT2::Ui::Windows void OnToolDrag(WidgetIndex widgetIndex, const ScreenCoordsXY& screenCoords) override { - auto staff = GetEntity(_staffId); + auto staff = getGameState().entities.GetEntity(_staffId); if (staff != nullptr) { MapRange range(gMapSelectPositionA, gMapSelectPositionB); diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index ea7992f816..d1aa01970d 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -1518,7 +1518,7 @@ namespace OpenRCT2::Ui::Windows const auto* rideEntry = ride->getRideEntry(); if (rideEntry != nullptr && rideEntry->TabCar != 0) { - Vehicle* vehicle = GetEntity(vehId); + Vehicle* vehicle = getGameState().entities.GetEntity(vehId); if (vehicle == nullptr) { vehId = EntityId::GetNull(); @@ -1978,7 +1978,7 @@ namespace OpenRCT2::Ui::Windows { if (_viewIndex <= ride->numTrains) { - Vehicle* vehicle = GetEntity(ride->vehicles[_viewIndex - 1]); + Vehicle* vehicle = getGameState().entities.GetEntity(ride->vehicles[_viewIndex - 1]); if (vehicle != nullptr) { auto headVehicleSpriteIndex = vehicle->Id; @@ -2275,7 +2275,7 @@ namespace OpenRCT2::Ui::Windows if (_viewIndex <= ride->numTrains) { - Vehicle* vehicle = GetEntity(ride->vehicles[_viewIndex - 1]); + Vehicle* vehicle = getGameState().entities.GetEntity(ride->vehicles[_viewIndex - 1]); if (vehicle == nullptr || (vehicle->status != Vehicle::Status::Travelling && vehicle->status != Vehicle::Status::TravellingCableLift @@ -2469,7 +2469,7 @@ namespace OpenRCT2::Ui::Windows if (ride == nullptr) return kStringIdEmpty; - auto vehicle = GetEntity(ride->vehicles[_viewIndex - 1]); + auto vehicle = getGameState().entities.GetEntity(ride->vehicles[_viewIndex - 1]); if (vehicle == nullptr) return kStringIdEmpty; @@ -3899,8 +3899,9 @@ namespace OpenRCT2::Ui::Windows break; for (int32_t i = 0; i < ride->numTrains; ++i) { - for (vehicle = GetEntity(ride->vehicles[i]); vehicle != nullptr; - vehicle = GetEntity(vehicle->next_vehicle_on_train)) + for (vehicle = getGameState().entities.GetEntity(ride->vehicles[i]); + vehicle != nullptr; + vehicle = getGameState().entities.GetEntity(vehicle->next_vehicle_on_train)) { vehicle->ClearFlag( VehicleFlags::CarIsBroken | VehicleFlags::StoppedOnLift @@ -3912,14 +3913,14 @@ namespace OpenRCT2::Ui::Windows case BREAKDOWN_RESTRAINTS_STUCK_OPEN: case BREAKDOWN_DOORS_STUCK_CLOSED: case BREAKDOWN_DOORS_STUCK_OPEN: - vehicle = GetEntity(ride->vehicles[ride->brokenTrain]); + vehicle = getGameState().entities.GetEntity(ride->vehicles[ride->brokenTrain]); if (vehicle != nullptr) { vehicle->ClearFlag(VehicleFlags::CarIsBroken); } break; case BREAKDOWN_VEHICLE_MALFUNCTION: - vehicle = GetEntity(ride->vehicles[ride->brokenTrain]); + vehicle = getGameState().entities.GetEntity(ride->vehicles[ride->brokenTrain]); if (vehicle != nullptr) { vehicle->ClearFlag(VehicleFlags::TrainIsBroken); @@ -4127,7 +4128,7 @@ namespace OpenRCT2::Ui::Windows } else { - auto staff = GetEntity(ride->mechanic); + auto staff = getGameState().entities.GetEntity(ride->mechanic); if (staff != nullptr && staff->IsMechanic()) { ft = Formatter(); @@ -7100,7 +7101,7 @@ namespace OpenRCT2::Ui::Windows int32_t numPeepsLeft = vehicle->num_peeps; for (int32_t i = 0; i < 32 && numPeepsLeft > 0; i++) { - Peep* peep = GetEntity(vehicle->peep[i]); + Peep* peep = getGameState().entities.GetEntity(vehicle->peep[i]); if (peep == nullptr) continue; diff --git a/src/openrct2-ui/windows/Staff.cpp b/src/openrct2-ui/windows/Staff.cpp index fa7d234036..bed04dd4cd 100644 --- a/src/openrct2-ui/windows/Staff.cpp +++ b/src/openrct2-ui/windows/Staff.cpp @@ -1209,7 +1209,7 @@ namespace OpenRCT2::Ui::Windows Staff* GetStaff() { - return GetEntity(EntityId::FromUnderlying(number)); + return getGameState().entities.GetEntity(EntityId::FromUnderlying(number)); } static constexpr int32_t TabAnimationDivisor[] = { diff --git a/src/openrct2-ui/windows/StaffFirePrompt.cpp b/src/openrct2-ui/windows/StaffFirePrompt.cpp index 192f779d37..54370f52ce 100644 --- a/src/openrct2-ui/windows/StaffFirePrompt.cpp +++ b/src/openrct2-ui/windows/StaffFirePrompt.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -76,7 +77,7 @@ namespace OpenRCT2::Ui::Windows { DrawWidgets(rt); - Peep* peep = GetEntity(EntityId::FromUnderlying(number)); + Peep* peep = getGameState().entities.GetEntity(EntityId::FromUnderlying(number)); // The staff member may have been fired in the meantime. if (peep == nullptr) { diff --git a/src/openrct2-ui/windows/StaffList.cpp b/src/openrct2-ui/windows/StaffList.cpp index aee30dfe17..c32c1b9a5d 100644 --- a/src/openrct2-ui/windows/StaffList.cpp +++ b/src/openrct2-ui/windows/StaffList.cpp @@ -185,10 +185,10 @@ namespace OpenRCT2::Ui::Windows { for (auto peep : EntityList()) { - EntitySetFlashing(peep, false); + getGameState().entities.EntitySetFlashing(peep, false); if (peep->AssignedStaffType == GetSelectedStaffType()) { - EntitySetFlashing(peep, true); + getGameState().entities.EntitySetFlashing(peep, true); } } } @@ -347,7 +347,7 @@ namespace OpenRCT2::Ui::Windows } else { - auto peep = GetEntity(entry.Id); + auto peep = getGameState().entities.GetEntity(entry.Id); if (peep != nullptr) { auto intent = Intent(WindowClass::Peep); @@ -386,7 +386,7 @@ namespace OpenRCT2::Ui::Windows if (y + 11 >= rt.y) { - const auto* peep = GetEntity(entry.Id); + const auto* peep = getGameState().entities.GetEntity(entry.Id); if (peep == nullptr) { continue; @@ -485,10 +485,10 @@ namespace OpenRCT2::Ui::Windows for (auto* peep : EntityList()) { - EntitySetFlashing(peep, false); + getGameState().entities.EntitySetFlashing(peep, false); if (peep->AssignedStaffType == GetSelectedStaffType()) { - EntitySetFlashing(peep, true); + getGameState().entities.EntitySetFlashing(peep, true); StaffEntry entry; entry.Id = peep->Id; @@ -543,7 +543,7 @@ namespace OpenRCT2::Ui::Windows return; auto actionResult = res->GetData(); - auto* staff = GetEntity(actionResult.StaffEntityId); + auto* staff = getGameState().entities.GetEntity(actionResult.StaffEntityId); if (staff == nullptr) return; @@ -560,7 +560,7 @@ namespace OpenRCT2::Ui::Windows if (result->Error != GameActions::Status::Ok) return; - auto* staff2 = GetEntity(staffId); + auto* staff2 = getGameState().entities.GetEntity(staffId); auto intent = Intent(WindowClass::Peep); intent.PutExtra(INTENT_EXTRA_PEEP, staff2); auto* wind = ContextOpenIntent(&intent); diff --git a/src/openrct2/Editor.cpp b/src/openrct2/Editor.cpp index 079cd7e5ec..8c8fcbf5fd 100644 --- a/src/openrct2/Editor.cpp +++ b/src/openrct2/Editor.cpp @@ -302,7 +302,7 @@ namespace OpenRCT2::Editor staff->SetName({}); } - ResetAllEntities(); + getGameState().entities.ResetAllEntities(); UpdateConsolidatedPatrolAreas(); auto& gameState = getGameState(); diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 1966249527..14bd313b33 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -270,7 +270,7 @@ static void FixPeepsWithInvalidRideReference() if (!peepsToRemove.empty()) { // Some broken saves have broken spatial indexes - ResetEntitySpatialIndices(); + getGameState().entities.ResetEntitySpatialIndices(); } for (auto ptr : peepsToRemove) @@ -374,7 +374,7 @@ void GameLoadInit() { GameActions::ClearQueue(); } - ResetEntitySpatialIndices(); + getGameState().entities.ResetEntitySpatialIndices(); ResetAllSpriteQuadrantPlacements(); gWindowUpdateTicks = 0; @@ -443,7 +443,7 @@ void ResetAllSpriteQuadrantPlacements() { for (EntityId::UnderlyingType i = 0; i < kMaxEntities; i++) { - auto* spr = GetEntity(EntityId::FromUnderlying(i)); + auto* spr = getGameState().entities.GetEntity(EntityId::FromUnderlying(i)); if (spr != nullptr && spr->Type != EntityType::Null) { spr->MoveTo(spr->GetLocation()); @@ -702,7 +702,7 @@ void GameLoadOrQuitNoSavePrompt() } default: GameUnloadScripts(); - ResetAllEntities(); + getGameState().entities.ResetAllEntities(); OpenRCT2Finish(); break; } diff --git a/src/openrct2/GameState.cpp b/src/openrct2/GameState.cpp index 276af360b5..bc2a00652b 100644 --- a/src/openrct2/GameState.cpp +++ b/src/openrct2/GameState.cpp @@ -64,7 +64,7 @@ namespace OpenRCT2 FinanceInit(); BannerInit(gameState); RideInitAll(); - ResetAllEntities(); + gameState.entities.ResetAllEntities(); UpdateConsolidatedPatrolAreas(); ResetDate(); ClimateReset(); @@ -170,14 +170,14 @@ namespace OpenRCT2 } // Keep updating the money effect even when paused. - UpdateMoneyEffect(); + getGameState().entities.UpdateMoneyEffect(); // Post-tick network update NetworkProcessPending(); // Post-tick game actions. GameActions::ProcessQueue(); - UpdateEntitiesSpatialIndex(); + getGameState().entities.UpdateEntitiesSpatialIndex(); } } @@ -311,7 +311,7 @@ namespace OpenRCT2 auto restoreProvisionalIntent = Intent(INTENT_ACTION_RESTORE_PROVISIONAL_ELEMENTS); ContextBroadcastIntent(&restoreProvisionalIntent); VehicleUpdateAll(); - UpdateAllMiscEntities(); + gameState.entities.UpdateAllMiscEntities(); Ride::updateAll(); if (!isInEditorMode()) @@ -333,7 +333,7 @@ namespace OpenRCT2 // Update windows // WindowDispatchUpdateAll(); - UpdateEntitiesSpatialIndex(); + gameState.entities.UpdateEntitiesSpatialIndex(); // Start autosave timer after update if (gLastAutoSaveUpdate == kAutosavePause) diff --git a/src/openrct2/GameState.h b/src/openrct2/GameState.h index f78e5fba78..7370c08f3d 100644 --- a/src/openrct2/GameState.h +++ b/src/openrct2/GameState.h @@ -62,7 +62,9 @@ namespace OpenRCT2 std::string scenarioFileName; std::vector banners; - Entity_t entities[kMaxEntities]{}; + + EntityRegistry entities; + // Ride storage for all the rides in the park, rides with RideId::Null are considered free. std::array rides{}; size_t ridesEndOfUsedRange{}; @@ -86,7 +88,6 @@ namespace OpenRCT2 uint8_t researchExpectedDay; std::optional researchLastItem; std::optional researchNextItem; - std::vector researchItemsUninvented; std::vector researchItemsInvented; uint8_t researchUncompletedCategories; diff --git a/src/openrct2/GameStateSnapshots.cpp b/src/openrct2/GameStateSnapshots.cpp index c104cfbad5..1a03b2d39e 100644 --- a/src/openrct2/GameStateSnapshots.cpp +++ b/src/openrct2/GameStateSnapshots.cpp @@ -189,7 +189,8 @@ struct GameStateSnapshots final : public IGameStateSnapshots virtual void Capture(GameStateSnapshot_t& snapshot) override final { snapshot.SerialiseSprites( - [](const EntityId index) { return reinterpret_cast(GetEntity(index)); }, kMaxEntities, true); + [](const EntityId index) { return reinterpret_cast(getGameState().entities.GetEntity(index)); }, + kMaxEntities, true); // LOG_INFO("Snapshot size: %u bytes", static_cast(snapshot.storedSprites.GetLength())); } diff --git a/src/openrct2/ReplayManager.cpp b/src/openrct2/ReplayManager.cpp index 6b4b06f985..7c781ac618 100644 --- a/src/openrct2/ReplayManager.cpp +++ b/src/openrct2/ReplayManager.cpp @@ -171,7 +171,7 @@ namespace OpenRCT2 if ((_mode == ReplayMode::RECORDING || _mode == ReplayMode::NORMALISATION) && currentTicks == _nextChecksumTick) { - EntitiesChecksum checksum = GetAllEntitiesChecksum(); + EntitiesChecksum checksum = getGameState().entities.GetAllEntitiesChecksum(); AddChecksum(currentTicks, std::move(checksum)); _nextChecksumTick = currentTicks + ChecksumTicksDelta(); @@ -304,7 +304,7 @@ namespace OpenRCT2 _currentRecording->tickEnd = currentTicks; { - EntitiesChecksum checksum = GetAllEntitiesChecksum(); + EntitiesChecksum checksum = getGameState().entities.GetAllEntitiesChecksum(); AddChecksum(currentTicks, std::move(checksum)); } @@ -785,7 +785,7 @@ namespace OpenRCT2 { _currentReplay->checksumIndex++; - EntitiesChecksum checksum = GetAllEntitiesChecksum(); + EntitiesChecksum checksum = getGameState().entities.GetAllEntitiesChecksum(); if (savedChecksum.second.raw != checksum.raw) { uint32_t replayTick = currentTicks - _currentReplay->tickStart; diff --git a/src/openrct2/actions/BalloonPressAction.cpp b/src/openrct2/actions/BalloonPressAction.cpp index c8a30f8b9d..8eb42d817a 100644 --- a/src/openrct2/actions/BalloonPressAction.cpp +++ b/src/openrct2/actions/BalloonPressAction.cpp @@ -10,6 +10,7 @@ #include "BalloonPressAction.h" #include "../Diagnostic.h" +#include "../GameState.h" #include "../entity/Balloon.h" #include "../entity/EntityRegistry.h" #include "GameAction.h" @@ -39,7 +40,8 @@ namespace OpenRCT2::GameActions Result BalloonPressAction::Query() const { - auto balloon = TryGetEntity(_spriteIndex); + auto& gameState = getGameState(); + auto balloon = gameState.entities.TryGetEntity(_spriteIndex); if (balloon == nullptr) { LOG_ERROR("Balloon not found for spriteIndex %u", _spriteIndex); @@ -50,7 +52,8 @@ namespace OpenRCT2::GameActions Result BalloonPressAction::Execute() const { - auto balloon = TryGetEntity(_spriteIndex); + auto& gameState = getGameState(); + auto balloon = gameState.entities.TryGetEntity(_spriteIndex); if (balloon == nullptr) { LOG_ERROR("Balloon not found for spriteIndex %u", _spriteIndex); diff --git a/src/openrct2/actions/CheatSetAction.cpp b/src/openrct2/actions/CheatSetAction.cpp index 3147d11d64..629539564a 100644 --- a/src/openrct2/actions/CheatSetAction.cpp +++ b/src/openrct2/actions/CheatSetAction.cpp @@ -498,7 +498,7 @@ namespace OpenRCT2::GameActions { for (auto litter : EntityList()) { - EntityRemove(litter); + getGameState().entities.EntityRemove(litter); } TileElementIterator it{}; @@ -732,8 +732,8 @@ namespace OpenRCT2::GameActions for (auto trainIndex : ride.vehicles) { - for (Vehicle* vehicle = TryGetEntity(trainIndex); vehicle != nullptr; - vehicle = TryGetEntity(vehicle->next_vehicle_on_train)) + for (Vehicle* vehicle = getGameState().entities.TryGetEntity(trainIndex); vehicle != nullptr; + vehicle = getGameState().entities.TryGetEntity(vehicle->next_vehicle_on_train)) { auto i = 0; for (auto& peepInTrainIndex : vehicle->peep) @@ -741,7 +741,7 @@ namespace OpenRCT2::GameActions if (i >= vehicle->num_peeps) break; - auto peep = TryGetEntity(peepInTrainIndex); + auto peep = getGameState().entities.TryGetEntity(peepInTrainIndex); if (peep != nullptr && peep->CurrentRide == ride.id) { if ((peep->State == PeepState::OnRide && peep->RideSubState == PeepRideSubState::OnRide) diff --git a/src/openrct2/actions/GuestSetFlagsAction.cpp b/src/openrct2/actions/GuestSetFlagsAction.cpp index 1a9069bafc..c8142eb94b 100644 --- a/src/openrct2/actions/GuestSetFlagsAction.cpp +++ b/src/openrct2/actions/GuestSetFlagsAction.cpp @@ -11,6 +11,7 @@ #include "../Context.h" #include "../Diagnostic.h" +#include "../GameState.h" #include "../OpenRCT2.h" #include "../entity/EntityRegistry.h" @@ -42,7 +43,8 @@ namespace OpenRCT2::GameActions Result GuestSetFlagsAction::Query() const { - auto* peep = TryGetEntity(_peepId); + auto& gameState = getGameState(); + auto* peep = gameState.entities.TryGetEntity(_peepId); if (peep == nullptr) { LOG_ERROR("Guest entity not found for peepID %u", _peepId.ToUnderlying()); @@ -53,7 +55,8 @@ namespace OpenRCT2::GameActions Result GuestSetFlagsAction::Execute() const { - auto* peep = TryGetEntity(_peepId); + auto& gameState = getGameState(); + auto* peep = gameState.entities.TryGetEntity(_peepId); if (peep == nullptr) { LOG_ERROR("Guest entity not found for peepID %u", _peepId.ToUnderlying()); diff --git a/src/openrct2/actions/GuestSetNameAction.cpp b/src/openrct2/actions/GuestSetNameAction.cpp index eeace67360..85cee44ac2 100644 --- a/src/openrct2/actions/GuestSetNameAction.cpp +++ b/src/openrct2/actions/GuestSetNameAction.cpp @@ -12,6 +12,7 @@ #include "../Cheats.h" #include "../Context.h" #include "../Diagnostic.h" +#include "../GameState.h" #include "../core/MemoryStream.h" #include "../drawing/Drawing.h" #include "../entity/EntityRegistry.h" @@ -62,7 +63,7 @@ namespace OpenRCT2::GameActions return Result(Status::InvalidParameters, STR_CANT_NAME_GUEST, STR_ERR_VALUE_OUT_OF_RANGE); } - auto guest = TryGetEntity(_spriteIndex); + auto guest = getGameState().entities.TryGetEntity(_spriteIndex); if (guest == nullptr) { LOG_ERROR("Guest entity not found for spriteIndex %u", _spriteIndex); @@ -74,7 +75,7 @@ namespace OpenRCT2::GameActions Result GuestSetNameAction::Execute() const { - auto guest = TryGetEntity(_spriteIndex); + auto guest = getGameState().entities.TryGetEntity(_spriteIndex); if (guest == nullptr) { LOG_ERROR("Guest entity not found for spriteIndex %u", _spriteIndex); diff --git a/src/openrct2/actions/PeepPickupAction.cpp b/src/openrct2/actions/PeepPickupAction.cpp index e4f0c2a308..84fcd200f7 100644 --- a/src/openrct2/actions/PeepPickupAction.cpp +++ b/src/openrct2/actions/PeepPickupAction.cpp @@ -10,6 +10,7 @@ #include "PeepPickupAction.h" #include "../Diagnostic.h" +#include "../GameState.h" #include "../Input.h" #include "../entity/EntityRegistry.h" #include "../entity/Peep.h" @@ -58,7 +59,7 @@ namespace OpenRCT2::GameActions return Result(Status::InvalidParameters, STR_ERR_CANT_PLACE_PERSON_HERE, kStringIdNone); } - auto* const peep = TryGetEntity(_entityId); + auto* const peep = getGameState().entities.TryGetEntity(_entityId); if (peep == nullptr) { LOG_ERROR("Failed to pick up peep for sprite %d", _entityId); @@ -116,7 +117,7 @@ namespace OpenRCT2::GameActions Result PeepPickupAction::Execute() const { - Peep* const peep = TryGetEntity(_entityId); + Peep* const peep = getGameState().entities.TryGetEntity(_entityId); if (peep == nullptr) { LOG_ERROR("Failed to pick up peep for sprite %d", _entityId); diff --git a/src/openrct2/actions/StaffFireAction.cpp b/src/openrct2/actions/StaffFireAction.cpp index 5cc4830379..ddf9f7b7f0 100644 --- a/src/openrct2/actions/StaffFireAction.cpp +++ b/src/openrct2/actions/StaffFireAction.cpp @@ -10,6 +10,7 @@ #include "StaffFireAction.h" #include "../Diagnostic.h" +#include "../GameState.h" #include "../entity/EntityRegistry.h" #include "../entity/Staff.h" #include "../ui/WindowManager.h" @@ -45,7 +46,7 @@ namespace OpenRCT2::GameActions return Result(Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE); } - auto staff = TryGetEntity(_spriteId); + auto staff = getGameState().entities.TryGetEntity(_spriteId); if (staff == nullptr) { LOG_ERROR("Staff entity not found for spriteId %u", _spriteId); @@ -66,7 +67,7 @@ namespace OpenRCT2::GameActions Result StaffFireAction::Execute() const { - auto staff = TryGetEntity(_spriteId); + auto staff = getGameState().entities.TryGetEntity(_spriteId); if (staff == nullptr) { LOG_ERROR("Staff entity not found for spriteId %u", _spriteId); diff --git a/src/openrct2/actions/StaffHireNewAction.cpp b/src/openrct2/actions/StaffHireNewAction.cpp index 23a2649206..cad7bdbaa7 100644 --- a/src/openrct2/actions/StaffHireNewAction.cpp +++ b/src/openrct2/actions/StaffHireNewAction.cpp @@ -83,7 +83,7 @@ namespace OpenRCT2::GameActions return Result(Status::InvalidParameters, STR_CANT_HIRE_NEW_STAFF, STR_ERR_VALUE_OUT_OF_RANGE); } - if (GetNumFreeEntities() < 400) + if (getGameState().entities.GetNumFreeEntities() < 400) { return Result(Status::NoFreeElements, STR_CANT_HIRE_NEW_STAFF, STR_TOO_MANY_PEOPLE_IN_GAME); } @@ -98,7 +98,7 @@ namespace OpenRCT2::GameActions } } - Staff* newPeep = CreateEntity(); + Staff* newPeep = getGameState().entities.CreateEntity(); if (newPeep == nullptr) { // Too many peeps exist already. @@ -108,7 +108,7 @@ namespace OpenRCT2::GameActions if (execute == false) { // In query we just want to see if we can obtain a sprite slot. - EntityRemove(newPeep); + getGameState().entities.EntityRemove(newPeep); res.SetData(StaffHireNewActionResult{ EntityId::GetNull() }); } diff --git a/src/openrct2/actions/StaffSetCostumeAction.cpp b/src/openrct2/actions/StaffSetCostumeAction.cpp index 281fd34e49..ff3b73553e 100644 --- a/src/openrct2/actions/StaffSetCostumeAction.cpp +++ b/src/openrct2/actions/StaffSetCostumeAction.cpp @@ -11,6 +11,7 @@ #include "../Context.h" #include "../Diagnostic.h" +#include "../GameState.h" #include "../entity/EntityRegistry.h" #include "../localisation/StringIds.h" #include "../object/ObjectManager.h" @@ -52,7 +53,7 @@ namespace OpenRCT2::GameActions return Result(Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE); } - auto* staff = TryGetEntity(_spriteIndex); + auto* staff = getGameState().entities.TryGetEntity(_spriteIndex); if (staff == nullptr) { LOG_ERROR("Staff entity not found for spriteIndex %u", _spriteIndex); @@ -73,7 +74,7 @@ namespace OpenRCT2::GameActions Result StaffSetCostumeAction::Execute() const { - auto* staff = TryGetEntity(_spriteIndex); + auto* staff = getGameState().entities.TryGetEntity(_spriteIndex); if (staff == nullptr) { LOG_ERROR("Staff entity not found for spriteIndex %u", _spriteIndex); diff --git a/src/openrct2/actions/StaffSetNameAction.cpp b/src/openrct2/actions/StaffSetNameAction.cpp index 09596c3f31..a44e75ea33 100644 --- a/src/openrct2/actions/StaffSetNameAction.cpp +++ b/src/openrct2/actions/StaffSetNameAction.cpp @@ -12,6 +12,7 @@ #include "../Cheats.h" #include "../Context.h" #include "../Diagnostic.h" +#include "../GameState.h" #include "../core/MemoryStream.h" #include "../drawing/Drawing.h" #include "../entity/EntityRegistry.h" @@ -54,7 +55,7 @@ namespace OpenRCT2::GameActions return Result(Status::InvalidParameters, STR_STAFF_ERROR_CANT_NAME_STAFF_MEMBER, STR_ERR_VALUE_OUT_OF_RANGE); } - auto staff = TryGetEntity(_spriteIndex); + auto staff = getGameState().entities.TryGetEntity(_spriteIndex); if (staff == nullptr) { LOG_ERROR("Staff entity not found for spriteIndex %u", _spriteIndex); @@ -66,7 +67,7 @@ namespace OpenRCT2::GameActions Result StaffSetNameAction::Execute() const { - auto staff = TryGetEntity(_spriteIndex); + auto staff = getGameState().entities.TryGetEntity(_spriteIndex); if (staff == nullptr) { LOG_ERROR("Staff entity not found for spriteIndex %u", _spriteIndex); diff --git a/src/openrct2/actions/StaffSetOrdersAction.cpp b/src/openrct2/actions/StaffSetOrdersAction.cpp index 1f5f3f6a3e..a6761bd853 100644 --- a/src/openrct2/actions/StaffSetOrdersAction.cpp +++ b/src/openrct2/actions/StaffSetOrdersAction.cpp @@ -11,6 +11,7 @@ #include "../Context.h" #include "../Diagnostic.h" +#include "../GameState.h" #include "../entity/EntityRegistry.h" #include "../entity/Staff.h" #include "../localisation/StringIds.h" @@ -51,7 +52,7 @@ namespace OpenRCT2::GameActions return Result(Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE); } - auto* staff = TryGetEntity(_spriteIndex); + auto* staff = getGameState().entities.TryGetEntity(_spriteIndex); if (staff == nullptr || (staff->AssignedStaffType != StaffType::Handyman && staff->AssignedStaffType != StaffType::Mechanic)) { @@ -64,7 +65,7 @@ namespace OpenRCT2::GameActions Result StaffSetOrdersAction::Execute() const { - auto* staff = TryGetEntity(_spriteIndex); + auto* staff = getGameState().entities.TryGetEntity(_spriteIndex); if (staff == nullptr) { LOG_ERROR("Staff entity not found for spriteIndex %u", _spriteIndex); diff --git a/src/openrct2/actions/StaffSetPatrolAreaAction.cpp b/src/openrct2/actions/StaffSetPatrolAreaAction.cpp index cb4d0ffb68..d1de929fc2 100644 --- a/src/openrct2/actions/StaffSetPatrolAreaAction.cpp +++ b/src/openrct2/actions/StaffSetPatrolAreaAction.cpp @@ -10,6 +10,7 @@ #include "StaffSetPatrolAreaAction.h" #include "../Diagnostic.h" +#include "../GameState.h" #include "../entity/EntityRegistry.h" #include "../entity/PatrolArea.h" #include "../entity/Peep.h" @@ -61,7 +62,7 @@ namespace OpenRCT2::GameActions Result StaffSetPatrolAreaAction::QueryExecute(bool executing) const { - auto staff = TryGetEntity(_spriteId); + auto staff = getGameState().entities.TryGetEntity(_spriteId); if (staff == nullptr) { LOG_ERROR("Staff entity not found for spriteID %u", _spriteId.ToUnderlying()); diff --git a/src/openrct2/command_line/SimulateCommands.cpp b/src/openrct2/command_line/SimulateCommands.cpp index b8b5dff716..622feb811c 100644 --- a/src/openrct2/command_line/SimulateCommands.cpp +++ b/src/openrct2/command_line/SimulateCommands.cpp @@ -73,7 +73,7 @@ static exitcode_t HandleSimulate(CommandLineArgEnumerator* argEnumerator) { gameStateUpdateLogic(); } - Console::WriteLine("Completed: %s", GetAllEntitiesChecksum().ToString().c_str()); + Console::WriteLine("Completed: %s", getGameState().entities.GetAllEntitiesChecksum().ToString().c_str()); } else { diff --git a/src/openrct2/drawing/LightFX.cpp b/src/openrct2/drawing/LightFX.cpp index 25b4dc4753..943f7a7e24 100644 --- a/src/openrct2/drawing/LightFX.cpp +++ b/src/openrct2/drawing/LightFX.cpp @@ -728,7 +728,7 @@ namespace OpenRCT2::Drawing::LightFx void AddLightsMagicVehicle_BoatHire(const Vehicle* vehicle) { Vehicle* vehicle_draw = vehicle->TrainHead(); - auto* nextVeh = GetEntity(vehicle_draw->next_vehicle_on_train); + auto* nextVeh = getGameState().entities.GetEntity(vehicle_draw->next_vehicle_on_train); if (nextVeh != nullptr) { vehicle_draw = nextVeh; diff --git a/src/openrct2/entity/Balloon.cpp b/src/openrct2/entity/Balloon.cpp index 15ce86e22b..4170e72f72 100644 --- a/src/openrct2/entity/Balloon.cpp +++ b/src/openrct2/entity/Balloon.cpp @@ -10,6 +10,7 @@ #include "Balloon.h" #include "../Game.h" +#include "../GameState.h" #include "../audio/Audio.h" #include "../core/DataSerialiser.h" #include "../network/Network.h" @@ -36,7 +37,7 @@ void Balloon::Update() frame++; if (frame >= 5) { - EntityRemove(this); + getGameState().entities.EntityRemove(this); } } else @@ -100,7 +101,7 @@ void Balloon::Pop(bool playSound) void Balloon::Create(const CoordsXYZ& balloonPos, int32_t colour, bool isPopped) { - auto* balloon = CreateEntity(); + auto* balloon = getGameState().entities.CreateEntity(); if (balloon == nullptr) return; diff --git a/src/openrct2/entity/Duck.cpp b/src/openrct2/entity/Duck.cpp index adba2e3cd2..6aa299f523 100644 --- a/src/openrct2/entity/Duck.cpp +++ b/src/openrct2/entity/Duck.cpp @@ -87,7 +87,7 @@ bool Duck::IsFlying() void Duck::Remove() { Invalidate(); - EntityRemove(this); + getGameState().entities.EntityRemove(this); } void Duck::UpdateFlyToWater() @@ -292,7 +292,7 @@ uint32_t Duck::GetFrameImage(int32_t direction) const void Duck::Create(const CoordsXY& pos) { - auto* duck = CreateEntity(); + auto* duck = getGameState().entities.CreateEntity(); if (duck == nullptr) return; diff --git a/src/openrct2/entity/EntityList.h b/src/openrct2/entity/EntityList.h index 93a943d00d..05eb0269ba 100644 --- a/src/openrct2/entity/EntityList.h +++ b/src/openrct2/entity/EntityList.h @@ -9,6 +9,7 @@ #pragma once +#include "../GameState.h" #include "../rct12/RCT12.h" #include "../world/Location.hpp" #include "EntityBase.h" @@ -19,13 +20,6 @@ namespace OpenRCT2 { - const std::list& GetEntityList(const EntityType id); - - uint16_t GetEntityListCount(EntityType list); - uint16_t GetMiscEntityCount(); - uint16_t GetNumFreeEntities(); - const std::vector& GetEntityTileList(const CoordsXY& spritePos); - template class EntityTileIterator { @@ -45,9 +39,12 @@ namespace OpenRCT2 { Entity = nullptr; + // TODO: don't use global game state! + auto& gameState = getGameState(); + while (iter != end && Entity == nullptr) { - Entity = TryGetEntity(*iter++); + Entity = gameState.entities.TryGetEntity(*iter++); } return *this; } @@ -86,7 +83,7 @@ namespace OpenRCT2 public: EntityTileList(const CoordsXY& loc) - : vec(GetEntityTileList(loc)) + : vec(getGameState().entities.GetEntityTileList(loc)) { } @@ -119,9 +116,12 @@ namespace OpenRCT2 { Entity = nullptr; + // TODO: don't use global game state! + auto& gameState = getGameState(); + while (iter != end && Entity == nullptr) { - Entity = TryGetEntity(*iter++); + Entity = gameState.entities.TryGetEntity(*iter++); } return *this; } @@ -161,7 +161,7 @@ namespace OpenRCT2 public: EntityList() - : vec(GetEntityList(T::cEntityType)) + : vec(getGameState().entities.GetEntityList(T::cEntityType)) { } diff --git a/src/openrct2/entity/EntityRegistry.cpp b/src/openrct2/entity/EntityRegistry.cpp index 89e51e100e..46c78f03ab 100644 --- a/src/openrct2/entity/EntityRegistry.cpp +++ b/src/openrct2/entity/EntityRegistry.cpp @@ -44,24 +44,6 @@ 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, EnumValue(EntityType::Count)> gEntityLists; - static std::vector _freeIdList; - - // TODO: move into MapWindow or GameState_t? - static bool _entityFlashingList[kMaxEntities]; - - // TODO: move into GameState_t - static std::array, kSpatialIndexSize> gEntitySpatialIndex; - - static void FreeEntity(EntityBase& entity); - static constexpr uint32_t ComputeSpatialIndex(const CoordsXY& loc) { if (loc.IsNull()) @@ -82,7 +64,7 @@ namespace OpenRCT2 return entity.SpatialIndex & ~kSpatialIndexDirtyMask; } - constexpr bool EntityTypeIsMiscEntity(const EntityType type) + static constexpr bool EntityTypeIsMiscEntity(const EntityType type) { switch (type) { @@ -101,12 +83,14 @@ namespace OpenRCT2 } } - uint16_t GetEntityListCount(EntityType type) + // TODO: make part of EntityList unit? + uint16_t EntityRegistry::GetEntityListCount(EntityType type) { return static_cast(gEntityLists[EnumValue(type)].size()); } - uint16_t GetNumFreeEntities() + // TODO: make part of EntityList unit? + uint16_t EntityRegistry::GetNumFreeEntities() { return static_cast(_freeIdList.size()); } @@ -116,14 +100,13 @@ namespace OpenRCT2 return String::StringFromHex(raw); } - EntityBase* TryGetEntity(EntityId entityIndex) + EntityBase* EntityRegistry::TryGetEntity(EntityId entityIndex) { - auto& gameState = getGameState(); const auto idx = entityIndex.ToUnderlying(); - return idx >= kMaxEntities ? nullptr : &gameState.entities[idx].base; + return idx >= kMaxEntities ? nullptr : &entities[idx].base; } - EntityBase* GetEntity(EntityId entityIndex) + EntityBase* EntityRegistry::GetEntity(EntityId entityIndex) { if (entityIndex.IsNull()) { @@ -133,12 +116,12 @@ namespace OpenRCT2 return TryGetEntity(entityIndex); } - const std::vector& GetEntityTileList(const CoordsXY& spritePos) + const std::vector& EntityRegistry::GetEntityTileList(const CoordsXY& spritePos) { return gEntitySpatialIndex[ComputeSpatialIndex(spritePos)]; } - static void ResetEntityLists() + void EntityRegistry::ResetEntityLists() { for (auto& list : gEntityLists) { @@ -146,7 +129,7 @@ namespace OpenRCT2 } } - static void ResetFreeIds() + void EntityRegistry::ResetFreeIds() { _freeIdList.clear(); _freeIdList.resize(kMaxEntities); @@ -159,7 +142,7 @@ namespace OpenRCT2 }); } - const std::list& GetEntityList(const EntityType id) + const std::list& EntityRegistry::GetEntityList(const EntityType id) { return gEntityLists[EnumValue(id)]; } @@ -168,7 +151,7 @@ namespace OpenRCT2 * * rct2: 0x0069EB13 */ - void ResetAllEntities() + void EntityRegistry::ResetAllEntities() { // Free all associated Entity pointers prior to zeroing memory for (int32_t i = 0; i < kMaxEntities; ++i) @@ -181,10 +164,9 @@ namespace OpenRCT2 FreeEntity(*spr); } - auto& gameState = getGameState(); - std::fill(std::begin(gameState.entities), std::end(gameState.entities), Entity_t()); - OpenRCT2::RideUse::GetHistory().Clear(); - OpenRCT2::RideUse::GetTypeHistory().Clear(); + std::fill(std::begin(entities), std::end(entities), Entity_t()); + RideUse::GetHistory().Clear(); + RideUse::GetTypeHistory().Clear(); for (int32_t i = 0; i < kMaxEntities; ++i) { auto* spr = GetEntity(EntityId::FromUnderlying(i)); @@ -202,15 +184,13 @@ namespace OpenRCT2 ResetEntitySpatialIndices(); } - 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 EntityRegistry::ResetEntitySpatialIndices() { for (auto& vec : gEntitySpatialIndex) { @@ -227,42 +207,24 @@ namespace OpenRCT2 } #ifndef DISABLE_NETWORK - - template - void NetworkSerialseEntityType(DataSerialiser& ds) - { - for (auto* ent : EntityList()) - { - ent->Serialise(ds); - } - } - - template - void NetworkSerialiseEntityTypes(DataSerialiser& ds) - { - (NetworkSerialseEntityType(ds), ...); - } - - EntitiesChecksum GetAllEntitiesChecksum() + EntitiesChecksum EntityRegistry::GetAllEntitiesChecksum() { EntitiesChecksum checksum{}; - OpenRCT2::ChecksumStream ms(checksum.raw); + ChecksumStream ms(checksum.raw); DataSerialiser ds(true, ms); NetworkSerialiseEntityTypes(ds); return checksum; } #else - - EntitiesChecksum GetAllEntitiesChecksum() + EntitiesChecksum EntityRegistry::GetAllEntitiesChecksum() { return EntitiesChecksum{}; } - #endif // DISABLE_NETWORK - static void EntityReset(EntityBase& entity) + void EntityRegistry::EntityReset(EntityBase& entity) { // Need to retain how the sprite is linked in lists auto entityIndex = entity.Id; @@ -275,9 +237,7 @@ namespace OpenRCT2 entity.Type = EntityType::Null; } - static constexpr uint16_t kMaxMiscEntities = 3200; - - static void AddToEntityList(EntityBase& entity) + void EntityRegistry::AddToEntityList(EntityBase& entity) { auto& list = gEntityLists[EnumValue(entity.Type)]; @@ -285,13 +245,13 @@ namespace OpenRCT2 Algorithm::sortedInsert(list, entity.Id); } - static void AddToFreeList(EntityId index) + void EntityRegistry::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) + void EntityRegistry::RemoveFromEntityList(EntityBase& entity) { auto& list = gEntityLists[EnumValue(entity.Type)]; auto ptr = Algorithm::binaryFind(std::begin(list), std::end(list), entity.Id); @@ -301,7 +261,7 @@ namespace OpenRCT2 } } - uint16_t GetMiscEntityCount() + uint16_t EntityRegistry::GetMiscEntityCount() { uint16_t count = 0; for (auto id : { EntityType::SteamParticle, EntityType::MoneyEffect, EntityType::CrashedVehicleParticle, @@ -313,7 +273,7 @@ namespace OpenRCT2 return count; } - static void PrepareNewEntity(EntityBase& base, const EntityType type) + void EntityRegistry::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. @@ -334,7 +294,7 @@ namespace OpenRCT2 EntitySpatialInsert(base, { kLocationNull, 0 }); } - EntityBase* CreateEntity(EntityType type) + EntityBase* EntityRegistry::CreateEntity(EntityType type) { if (_freeIdList.size() == 0) { @@ -369,7 +329,7 @@ namespace OpenRCT2 return entity; } - EntityBase* CreateEntityAt(const EntityId index, const EntityType type) + EntityBase* EntityRegistry::CreateEntityAt(const EntityId index, const EntityType type) { auto id = Algorithm::binaryFind(std::rbegin(_freeIdList), std::rend(_freeIdList), index); if (id == std::rend(_freeIdList)) @@ -389,26 +349,11 @@ namespace OpenRCT2 return entity; } - template - void MiscUpdateAllType() - { - for (auto misc : EntityList()) - { - misc->Update(); - } - } - - template - void MiscUpdateAllTypes() - { - (MiscUpdateAllType(), ...); - } - /** * * rct2: 0x00672AA4 */ - void UpdateAllMiscEntities() + void EntityRegistry::UpdateAllMiscEntities() { PROFILED_FUNCTION(); @@ -417,13 +362,13 @@ namespace OpenRCT2 JumpingFountain, Balloon, Duck>(); } - void UpdateMoneyEffect() + void EntityRegistry::UpdateMoneyEffect() { MiscUpdateAllTypes(); } // Performs a search to ensure that insert keeps next_in_quadrant in sprite_index order - static void EntitySpatialInsert(EntityBase& entity, const CoordsXY& newLoc) + void EntityRegistry::EntitySpatialInsert(EntityBase& entity, const CoordsXY& newLoc) { const auto newIndex = ComputeSpatialIndex(newLoc); @@ -434,7 +379,7 @@ namespace OpenRCT2 entity.SpatialIndex = newIndex; } - static void EntitySpatialRemove(EntityBase& entity) + void EntityRegistry::EntitySpatialRemove(EntityBase& entity) { const auto currentIndex = GetSpatialIndex(entity); @@ -453,7 +398,7 @@ namespace OpenRCT2 entity.SpatialIndex = kInvalidSpatialIndex; } - static void UpdateEntitySpatialIndex(EntityBase& entity) + void EntityRegistry::UpdateEntitySpatialIndex(EntityBase& entity) { if (entity.SpatialIndex & kSpatialIndexDirtyMask) { @@ -465,7 +410,7 @@ namespace OpenRCT2 } } - void UpdateEntitiesSpatialIndex() + void EntityRegistry::UpdateEntitiesSpatialIndex() { for (auto& entityList : gEntityLists) { @@ -479,6 +424,84 @@ namespace OpenRCT2 } } } + + /** + * Frees any dynamically attached memory to the entity, such as peep name. + */ + void EntityRegistry::FreeEntity(EntityBase& entity) + { + auto* guest = entity.As(); + auto* staff = entity.As(); + if (staff != nullptr) + { + staff->SetName({}); + staff->ClearPatrolArea(); + } + else if (guest != nullptr) + { + guest->SetName({}); + guest->GuestNextInQueue = EntityId::GetNull(); + + RideUse::GetHistory().RemoveHandle(guest->Id); + RideUse::GetTypeHistory().RemoveHandle(guest->Id); + } + } + + /** + * + * rct2: 0x0069EDB6 + */ + void EntityRegistry::EntityRemove(EntityBase* entity) + { + FreeEntity(*entity); + + EntityTweener::Get().RemoveEntity(entity); + RemoveFromEntityList(*entity); // remove from existing list + AddToFreeList(entity->Id); + + EntitySpatialRemove(*entity); + EntityReset(*entity); + } + + /** + * Loops through all floating entities and removes them. + * Returns the amount of removed objects as feedback. + */ + uint16_t EntityRegistry::RemoveFloatingEntities() + { + uint16_t removed = 0; + for (auto* balloon : EntityList()) + { + EntityRemove(balloon); + removed++; + } + for (auto* duck : EntityList()) + { + if (duck->IsFlying()) + { + EntityRemove(duck); + removed++; + } + } + for (auto* money : EntityList()) + { + EntityRemove(money); + removed++; + } + return removed; + } + + void EntityRegistry::EntitySetFlashing(EntityBase* entity, bool flashing) + { + assert(entity->Id.ToUnderlying() < kMaxEntities); + _entityFlashingList[entity->Id.ToUnderlying()] = flashing; + } + + bool EntityRegistry::EntityGetFlashing(EntityBase* entity) + { + assert(entity->Id.ToUnderlying() < kMaxEntities); + return _entityFlashingList[entity->Id.ToUnderlying()]; + } } // namespace OpenRCT2 using namespace OpenRCT2; @@ -554,86 +577,9 @@ void EntityBase::MoveTo(const CoordsXYZ& newLocation) void EntityBase::MoveToAndUpdateSpatialIndex(const CoordsXYZ& newLocation) { MoveTo(newLocation); - UpdateEntitySpatialIndex(*this); + + // TODO: pass as param instead of relying on global game state + auto& gameState = getGameState(); + + gameState.entities.UpdateEntitySpatialIndex(*this); } - -namespace OpenRCT2 -{ - /** - * Frees any dynamically attached memory to the entity, such as peep name. - */ - static void FreeEntity(EntityBase& entity) - { - auto* guest = entity.As(); - auto* staff = entity.As(); - if (staff != nullptr) - { - staff->SetName({}); - staff->ClearPatrolArea(); - } - else if (guest != nullptr) - { - guest->SetName({}); - guest->GuestNextInQueue = EntityId::GetNull(); - - OpenRCT2::RideUse::GetHistory().RemoveHandle(guest->Id); - OpenRCT2::RideUse::GetTypeHistory().RemoveHandle(guest->Id); - } - } - - /** - * - * rct2: 0x0069EDB6 - */ - void EntityRemove(EntityBase* entity) - { - FreeEntity(*entity); - - EntityTweener::Get().RemoveEntity(entity); - RemoveFromEntityList(*entity); // remove from existing list - AddToFreeList(entity->Id); - - 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 removed = 0; - for (auto* balloon : EntityList()) - { - EntityRemove(balloon); - removed++; - } - for (auto* duck : EntityList()) - { - if (duck->IsFlying()) - { - EntityRemove(duck); - removed++; - } - } - for (auto* money : EntityList()) - { - EntityRemove(money); - removed++; - } - return removed; - } - - void EntitySetFlashing(EntityBase* entity, bool flashing) - { - assert(entity->Id.ToUnderlying() < kMaxEntities); - _entityFlashingList[entity->Id.ToUnderlying()] = flashing; - } - - bool EntityGetFlashing(EntityBase* entity) - { - assert(entity->Id.ToUnderlying() < kMaxEntities); - return _entityFlashingList[entity->Id.ToUnderlying()]; - } -} // namespace OpenRCT2 diff --git a/src/openrct2/entity/EntityRegistry.h b/src/openrct2/entity/EntityRegistry.h index 6d9cb5c06f..136d271dd9 100644 --- a/src/openrct2/entity/EntityRegistry.h +++ b/src/openrct2/entity/EntityRegistry.h @@ -9,13 +9,26 @@ #pragma once +#include "../core/EnumUtils.hpp" +#include "../world/MapLimits.h" #include "EntityBase.h" #include +#include #include +#include namespace OpenRCT2 { + constexpr uint16_t kMaxEntities = 65535; + constexpr uint16_t kMaxMiscEntities = 3200; + + constexpr const uint32_t kSpatialIndexSize = (kMaximumMapSizeTechnical * kMaximumMapSizeTechnical) + 1; + constexpr uint32_t kSpatialIndexNullBucket = kSpatialIndexSize - 1; + + constexpr uint32_t kInvalidSpatialIndex = 0xFFFFFFFFu; + constexpr uint32_t kSpatialIndexDirtyMask = 1u << 31; + union Entity_t { uint8_t Pad00[0x200]; @@ -26,73 +39,6 @@ namespace OpenRCT2 } }; - constexpr uint16_t kMaxEntities = 65535; - - EntityBase* GetEntity(EntityId entityId); - - template - T* GetEntity(EntityId entityId) - { - auto* ent = GetEntity(entityId); - if (ent == nullptr) - { - return nullptr; - } - if constexpr (std::is_same_v) - { - return ent; - } - else - { - return ent->As(); - } - } - - EntityBase* TryGetEntity(EntityId spriteIndex); - - template - T* TryGetEntity(EntityId entityId) - { - auto* ent = TryGetEntity(entityId); - if (ent == nullptr) - { - return nullptr; - } - if constexpr (std::is_same_v) - { - return ent; - } - else - { - return ent->As(); - } - } - - EntityBase* CreateEntity(EntityType type); - - template - T* CreateEntity() - { - return static_cast(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 - T* CreateEntityAt(const EntityId index) - { - return static_cast(CreateEntityAt(index, T::cEntityType)); - } - - void ResetAllEntities(); - void ResetEntitySpatialIndices(); - void UpdateAllMiscEntities(); - void UpdateMoneyEffect(); - void EntityRemove(EntityBase* entity); - uint16_t RemoveFloatingEntities(); - void UpdateEntitiesSpatialIndex(); - #pragma pack(push, 1) struct EntitiesChecksum { @@ -101,8 +47,147 @@ namespace OpenRCT2 std::string ToString() const; }; #pragma pack(pop) - EntitiesChecksum GetAllEntitiesChecksum(); - void EntitySetFlashing(EntityBase* entity, bool flashing); - bool EntityGetFlashing(EntityBase* entity); + template + class EntityList; + + class EntityRegistry + { + private: + Entity_t entities[kMaxEntities]{}; + std::array, EnumValue(EntityType::Count)> gEntityLists; + std::vector _freeIdList; + + bool _entityFlashingList[kMaxEntities]; + + std::array, kSpatialIndexSize> gEntitySpatialIndex; + + public: + uint16_t GetEntityListCount(EntityType type); + uint16_t GetNumFreeEntities(); + + EntityBase* GetEntity(EntityId entityId); + + template + T* GetEntity(EntityId entityId) + { + auto* ent = GetEntity(entityId); + if (ent == nullptr) + { + return nullptr; + } + if constexpr (std::is_same_v) + { + return ent; + } + else + { + return ent->As(); + } + } + + EntityBase* TryGetEntity(EntityId spriteIndex); + + template + T* TryGetEntity(EntityId entityId) + { + auto* ent = TryGetEntity(entityId); + if (ent == nullptr) + { + return nullptr; + } + if constexpr (std::is_same_v) + { + return ent; + } + else + { + return ent->As(); + } + } + + const std::vector& GetEntityTileList(const CoordsXY& spritePos); + + EntityBase* CreateEntity(EntityType type); + + template + T* CreateEntity() + { + return static_cast(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 + T* CreateEntityAt(const EntityId index) + { + return static_cast(CreateEntityAt(index, T::cEntityType)); + } + + const std::list& GetEntityList(const EntityType id); + uint16_t GetMiscEntityCount(); + + void ResetAllEntities(); + void ResetEntitySpatialIndices(); + +#ifndef DISABLE_NETWORK + + template + void NetworkSerialseEntityType(DataSerialiser& ds) + { + for (auto* ent : EntityList()) + { + ent->Serialise(ds); + } + } + + template + void NetworkSerialiseEntityTypes(DataSerialiser& ds) + { + (NetworkSerialseEntityType(ds), ...); + } + +#endif // DISABLE_NETWORK + + EntitiesChecksum GetAllEntitiesChecksum(); + + template + void MiscUpdateAllType() + { + for (auto misc : EntityList()) + { + misc->Update(); + } + } + + template + void MiscUpdateAllTypes() + { + (MiscUpdateAllType(), ...); + } + + void UpdateAllMiscEntities(); + void UpdateMoneyEffect(); + void EntityRemove(EntityBase* entity); + uint16_t RemoveFloatingEntities(); + void UpdateEntitiesSpatialIndex(); + void UpdateEntitySpatialIndex(EntityBase& entity); + + void EntitySetFlashing(EntityBase* entity, bool flashing); + bool EntityGetFlashing(EntityBase* entity); + + private: + void ResetEntityLists(); + void ResetFreeIds(); + void EntityReset(EntityBase& entity); + void AddToEntityList(EntityBase& entity); + void AddToFreeList(EntityId index); + void RemoveFromEntityList(EntityBase& entity); + void PrepareNewEntity(EntityBase& base, const EntityType type); + void EntitySpatialInsert(EntityBase& entity, const CoordsXY& newLoc); + void EntitySpatialRemove(EntityBase& entity); + void FreeEntity(EntityBase& entity); + }; + } // namespace OpenRCT2 diff --git a/src/openrct2/entity/Fountain.cpp b/src/openrct2/entity/Fountain.cpp index 6dc5ed9861..71337d4c7c 100644 --- a/src/openrct2/entity/Fountain.cpp +++ b/src/openrct2/entity/Fountain.cpp @@ -144,7 +144,7 @@ void JumpingFountain::Create( const JumpingFountainType newType, const CoordsXYZ& newLoc, const int32_t direction, const OpenRCT2::FountainFlags newFlags, const int32_t iteration) { - auto* jumpingFountain = CreateEntity(); + auto* jumpingFountain = getGameState().entities.CreateEntity(); if (jumpingFountain != nullptr) { jumpingFountain->Iteration = iteration; @@ -199,7 +199,7 @@ void JumpingFountain::Update() if (frame == 16) { - EntityRemove(this); + getGameState().entities.EntityRemove(this); } } diff --git a/src/openrct2/entity/Guest.cpp b/src/openrct2/entity/Guest.cpp index 9e5f5ff6b6..8fa04c5836 100644 --- a/src/openrct2/entity/Guest.cpp +++ b/src/openrct2/entity/Guest.cpp @@ -1617,7 +1617,7 @@ static bool GuestDecideAndBuyItem(Guest& guest, Ride& ride, const ShopItem shopI if (guest.Happiness >= 180) itemValue /= 2; } - if (itemValue > (static_cast(ScenarioRand() & 0x07)) && !(getGameState().cheats.ignorePrice)) + if (itemValue > (static_cast(ScenarioRand() & 0x07)) && !(gameState.cheats.ignorePrice)) { // "I'm not paying that much for x" guest.InsertNewThought(shopItemDescriptor.TooMuchThought, ride.id); @@ -2003,7 +2003,7 @@ bool Guest::ShouldGoOnRide(Ride& ride, StationIndex entranceNum, bool atQueue, b else { // Check if there's room in the queue for the peep to enter. - Guest* lastPeepInQueue = GetEntity(station.LastPeepInQueue); + Guest* lastPeepInQueue = getGameState().entities.GetEntity(station.LastPeepInQueue); if (lastPeepInQueue != nullptr && (abs(lastPeepInQueue->z - z) <= 6)) { int32_t dx = abs(lastPeepInQueue->x - x); @@ -2084,7 +2084,7 @@ bool Guest::ShouldGoOnRide(Ride& ride, StationIndex entranceNum, bool atQueue, b // excitement check and will only do a basic intensity check when they arrive at the ride itself. if (ride.id == GuestHeadingToRideId) { - if (ride.ratings.intensity > RideRating::make(10, 00) && !getGameState().cheats.ignoreRideIntensity) + if (ride.ratings.intensity > RideRating::make(10, 00) && !gameState.cheats.ignoreRideIntensity) { GuestRideIsTooIntense(*this, ride, peepAtRide); return false; @@ -2111,7 +2111,7 @@ bool Guest::ShouldGoOnRide(Ride& ride, StationIndex entranceNum, bool atQueue, b // ride intensity check and get me on a sheltered ride! if (!isPrecipitating || !GuestShouldRideWhileRaining(*this, ride)) { - if (!getGameState().cheats.ignoreRideIntensity) + if (!gameState.cheats.ignoreRideIntensity) { // Intensity calculations. Even though the max intensity can go up to 15, it's capped // at 10.0 (before happiness calculations). A full happiness bar will increase the max @@ -2177,7 +2177,7 @@ bool Guest::ShouldGoOnRide(Ride& ride, StationIndex entranceNum, bool atQueue, b return false; } - if (!getGameState().cheats.ignoreRideIntensity) + if (!gameState.cheats.ignoreRideIntensity) { if (ride.maxPositiveVerticalG > MakeFixed16_2dp(5, 00) || ride.maxNegativeVerticalG < MakeFixed16_2dp(-4, 00) || ride.maxLateralG > MakeFixed16_2dp(4, 00)) @@ -2490,7 +2490,7 @@ static Vehicle* PeepChooseCarFromRide(Guest& guest, const Ride& ride, std::span< guest.CurrentCar = carArray[chosen_car]; - Vehicle* vehicle = GetEntity(ride.vehicles[guest.CurrentTrain]); + Vehicle* vehicle = getGameState().entities.GetEntity(ride.vehicles[guest.CurrentTrain]); if (vehicle == nullptr) { return nullptr; @@ -2581,7 +2581,7 @@ static bool FindVehicleToEnter( for (int32_t i = 0; i < ride.numTrains; ++i) { - Vehicle* vehicle = GetEntity(ride.vehicles[i]); + Vehicle* vehicle = getGameState().entities.GetEntity(ride.vehicles[i]); if (vehicle == nullptr) continue; @@ -2608,8 +2608,8 @@ static bool FindVehicleToEnter( int32_t i = 0; auto vehicle_id = ride.vehicles[chosen_train]; - for (Vehicle* vehicle = GetEntity(vehicle_id); vehicle != nullptr; - vehicle = GetEntity(vehicle->next_vehicle_on_train), ++i) + for (Vehicle* vehicle = getGameState().entities.GetEntity(vehicle_id); vehicle != nullptr; + vehicle = getGameState().entities.GetEntity(vehicle->next_vehicle_on_train), ++i) { uint8_t num_seats = vehicle->num_seats; if (vehicle->IsUsedInPairs()) @@ -3670,7 +3670,7 @@ void Guest::UpdateRideLeaveEntranceWaypoints(const Ride& ride) uint8_t direction_track = (tile_element == nullptr ? 0 : tile_element->GetDirection()); - auto vehicle = GetEntity(ride.vehicles[CurrentTrain]); + auto vehicle = getGameState().entities.GetEntity(ride.vehicles[CurrentTrain]); if (vehicle == nullptr) { // TODO: Goto ride exit on failure. @@ -3760,7 +3760,7 @@ void Guest::UpdateRideAdvanceThroughEntrance() return; } - Vehicle* vehicle = GetEntity(ride->vehicles[CurrentTrain]); + Vehicle* vehicle = getGameState().entities.GetEntity(ride->vehicles[CurrentTrain]); if (vehicle == nullptr) { return; @@ -3995,7 +3995,8 @@ void Guest::UpdateRideFreeVehicleCheck() return; } - Vehicle* vehicle = GetEntity(ride->vehicles[CurrentTrain]); + auto& gameState = getGameState(); + Vehicle* vehicle = gameState.entities.GetEntity(ride->vehicles[CurrentTrain]); if (vehicle == nullptr) { // TODO: Leave ride on failure goes for all returns on nullptr in this function @@ -4017,11 +4018,11 @@ void Guest::UpdateRideFreeVehicleCheck() for (size_t i = 0; i < ride->numTrains; ++i) { - Vehicle* train = GetEntity(ride->vehicles[i]); + Vehicle* train = gameState.entities.GetEntity(ride->vehicles[i]); if (train == nullptr) continue; - Vehicle* second_vehicle = GetEntity(train->next_vehicle_on_train); + Vehicle* second_vehicle = gameState.entities.GetEntity(train->next_vehicle_on_train); if (second_vehicle == nullptr) continue; @@ -4059,7 +4060,7 @@ void Guest::UpdateRideFreeVehicleCheck() } } - Vehicle* currentTrain = GetEntity(ride->vehicles[CurrentTrain]); + Vehicle* currentTrain = gameState.entities.GetEntity(ride->vehicles[CurrentTrain]); if (currentTrain == nullptr) { return; @@ -4093,10 +4094,11 @@ void Guest::UpdateRideApproachVehicle() void Guest::UpdateRideEnterVehicle() { + auto& gameState = getGameState(); auto* ride = GetRide(CurrentRide); if (ride != nullptr) { - auto* vehicle = GetEntity(ride->vehicles[CurrentTrain]); + auto* vehicle = gameState.entities.GetEntity(ride->vehicles[CurrentTrain]); if (vehicle != nullptr) { vehicle = vehicle->GetCar(CurrentCar); @@ -4113,7 +4115,7 @@ void Guest::UpdateRideEnterVehicle() if (vehicle->IsUsedInPairs()) { - auto* seatedGuest = GetEntity(vehicle->peep[CurrentSeat ^ 1]); + auto* seatedGuest = gameState.entities.GetEntity(vehicle->peep[CurrentSeat ^ 1]); if (seatedGuest != nullptr) { if (seatedGuest->RideSubState != PeepRideSubState::EnterVehicle) @@ -4154,11 +4156,12 @@ void Guest::UpdateRideEnterVehicle() */ void Guest::UpdateRideLeaveVehicle() { + auto& gameState = getGameState(); auto ride = GetRide(CurrentRide); if (ride == nullptr) return; - Vehicle* vehicle = GetEntity(ride->vehicles[CurrentTrain]); + Vehicle* vehicle = gameState.entities.GetEntity(ride->vehicles[CurrentTrain]); if (vehicle == nullptr) return; @@ -4218,7 +4221,8 @@ void Guest::UpdateRideLeaveVehicle() if (!ride->getRideTypeDescriptor().HasFlag(RtdFlag::vehicleIsIntegral)) { - for (; vehicle != nullptr && !vehicle->IsHead(); vehicle = GetEntity(vehicle->prev_vehicle_on_ride)) + for (; vehicle != nullptr && !vehicle->IsHead(); + vehicle = gameState.entities.GetEntity(vehicle->prev_vehicle_on_ride)) { auto trackType = vehicle->GetTrackType(); if (trackType == TrackElemType::Flat || trackType > TrackElemType::MiddleStation) @@ -4335,7 +4339,7 @@ void Guest::UpdateRideLeaveVehicle() Direction station_direction = (trackElement == nullptr ? 0 : trackElement->GetDirection()); - vehicle = GetEntity(ride->vehicles[CurrentTrain]); + vehicle = gameState.entities.GetEntity(ride->vehicles[CurrentTrain]); if (vehicle == nullptr) { return; @@ -4517,7 +4521,7 @@ void Guest::UpdateRideApproachVehicleWaypoints() // This is incrementing the actual peep waypoint Var37++; - Vehicle* vehicle = GetEntity(ride->vehicles[CurrentTrain]); + Vehicle* vehicle = getGameState().entities.GetEntity(ride->vehicles[CurrentTrain]); if (vehicle == nullptr) { return; @@ -4615,7 +4619,7 @@ void Guest::UpdateRideApproachExitWaypoints() } Var37--; - Vehicle* vehicle = GetEntity(ride->vehicles[CurrentTrain]); + Vehicle* vehicle = getGameState().entities.GetEntity(ride->vehicles[CurrentTrain]); if (vehicle == nullptr) { return; @@ -5762,7 +5766,7 @@ void Guest::UpdateQueuing() // first check if the next in queue is actually nearby // if they are not then it's safe to assume that this is // the front of the queue. - Peep* nextGuest = GetEntity(GuestNextInQueue); + Peep* nextGuest = getGameState().entities.GetEntity(GuestNextInQueue); if (nextGuest != nullptr) { if (abs(nextGuest->x - x) < 32 && abs(nextGuest->y - y) < 32) @@ -7264,11 +7268,11 @@ static constexpr uint8_t kTshirtColours[] = { */ Guest* Guest::Generate(const CoordsXYZ& coords) { - if (GetNumFreeEntities() < 400) + auto& gameState = getGameState(); + if (gameState.entities.GetNumFreeEntities() < 400) return nullptr; - auto& gameState = getGameState(); - Guest* peep = CreateEntity(); + Guest* peep = gameState.entities.CreateEntity(); peep->AnimationObjectIndex = findPeepAnimationsIndexForType(AnimationPeepType::Guest); peep->AnimationGroup = PeepAnimationGroup::Normal; @@ -7563,7 +7567,7 @@ bool Guest::UpdateQueuePosition(PeepActionType previous_action) { TimeInQueue++; - auto* guestNext = GetEntity(GuestNextInQueue); + auto* guestNext = getGameState().entities.GetEntity(GuestNextInQueue); if (guestNext == nullptr) { return false; @@ -7653,13 +7657,14 @@ void Guest::RemoveFromQueue() return; } - auto* otherGuest = GetEntity(station.LastPeepInQueue); + auto& gameState = getGameState(); + auto* otherGuest = gameState.entities.GetEntity(station.LastPeepInQueue); if (otherGuest == nullptr) { LOG_ERROR("Invalid Guest Queue list!"); return; } - for (; otherGuest != nullptr; otherGuest = GetEntity(otherGuest->GuestNextInQueue)) + for (; otherGuest != nullptr; otherGuest = gameState.entities.GetEntity(otherGuest->GuestNextInQueue)) { if (Id == otherGuest->GuestNextInQueue) { diff --git a/src/openrct2/entity/Litter.cpp b/src/openrct2/entity/Litter.cpp index 5eacec99ce..7e6f50f51b 100644 --- a/src/openrct2/entity/Litter.cpp +++ b/src/openrct2/entity/Litter.cpp @@ -64,7 +64,7 @@ void Litter::Create(const CoordsXYZD& litterPos, Type type) if (!IsLocationLitterable(offsetLitterPos)) return; - if (GetEntityListCount(EntityType::Litter) >= 500) + if (gameState.entities.GetEntityListCount(EntityType::Litter) >= 500) { Litter* newestLitter = nullptr; uint32_t newestLitterCreationTick = 0; @@ -80,11 +80,11 @@ void Litter::Create(const CoordsXYZD& litterPos, Type type) if (newestLitter != nullptr) { newestLitter->Invalidate(); - EntityRemove(newestLitter); + gameState.entities.EntityRemove(newestLitter); } } - Litter* litter = CreateEntity(); + Litter* litter = gameState.entities.CreateEntity(); if (litter == nullptr) return; @@ -119,7 +119,7 @@ void Litter::RemoveAt(const CoordsXYZ& litterPos) for (auto* litter : removals) { litter->Invalidate(); - EntityRemove(litter); + getGameState().entities.EntityRemove(litter); } } diff --git a/src/openrct2/entity/MoneyEffect.cpp b/src/openrct2/entity/MoneyEffect.cpp index 2d0b98593f..001565a852 100644 --- a/src/openrct2/entity/MoneyEffect.cpp +++ b/src/openrct2/entity/MoneyEffect.cpp @@ -10,6 +10,7 @@ #include "MoneyEffect.h" #include "../Diagnostic.h" +#include "../GameState.h" #include "../OpenRCT2.h" #include "../config/Config.h" #include "../core/DataSerialiser.h" @@ -47,7 +48,7 @@ void MoneyEffect::CreateAt(money64 value, const CoordsXYZ& effectPos, bool guest if (value == 0.00_GBP) return; - MoneyEffect* moneyEffect = CreateEntity(); + MoneyEffect* moneyEffect = getGameState().entities.CreateEntity(); if (moneyEffect == nullptr) return; @@ -151,7 +152,7 @@ void MoneyEffect::Update() return; } - EntityRemove(this); + getGameState().entities.EntityRemove(this); } std::pair MoneyEffect::GetStringId() const diff --git a/src/openrct2/entity/Particle.cpp b/src/openrct2/entity/Particle.cpp index f0cc4cbe7a..f8c5f368f6 100644 --- a/src/openrct2/entity/Particle.cpp +++ b/src/openrct2/entity/Particle.cpp @@ -8,6 +8,7 @@ *****************************************************************************/ #include "Particle.h" +#include "../GameState.h" #include "../SpriteIds.h" #include "../audio/Audio.h" #include "../core/DataSerialiser.h" @@ -84,7 +85,7 @@ void VehicleCrashParticle::Launch() */ void VehicleCrashParticle::Create(VehicleColour& colours, const CoordsXYZ& vehiclePos) { - VehicleCrashParticle* sprite = CreateEntity(); + VehicleCrashParticle* sprite = getGameState().entities.CreateEntity(); if (sprite != nullptr) { sprite->MoveTo(vehiclePos); @@ -105,7 +106,7 @@ void VehicleCrashParticle::Update() time_to_live--; if (time_to_live == 0) { - EntityRemove(this); + getGameState().entities.EntityRemove(this); return; } @@ -137,7 +138,7 @@ void VehicleCrashParticle::Update() // Splash OpenRCT2::Audio::Play3D(OpenRCT2::Audio::SoundId::Water2, { x, y, waterZ }); CrashSplashParticle::Create({ x, y, waterZ }); - EntityRemove(this); + getGameState().entities.EntityRemove(this); return; } @@ -192,7 +193,7 @@ void VehicleCrashParticle::Paint(PaintSession& session, int32_t imageDirection) */ void CrashSplashParticle::Create(const CoordsXYZ& splashPos) { - auto* sprite = CreateEntity(); + auto* sprite = getGameState().entities.CreateEntity(); if (sprite != nullptr) { sprite->SpriteData.Width = 33; @@ -213,7 +214,7 @@ void CrashSplashParticle::Update() frame += 85; if (frame >= 7168) { - EntityRemove(this); + getGameState().entities.EntityRemove(this); } } @@ -240,7 +241,7 @@ void SteamParticle::Create(const CoordsXYZ& coords) auto surfaceElement = MapGetSurfaceElementAt(coords); if (surfaceElement != nullptr && coords.z > surfaceElement->GetBaseZ()) { - SteamParticle* steam = CreateEntity(); + SteamParticle* steam = getGameState().entities.CreateEntity(); if (steam == nullptr) return; @@ -270,7 +271,7 @@ void SteamParticle::Update() frame += 64; if (frame >= (56 * 64)) { - EntityRemove(this); + getGameState().entities.EntityRemove(this); } } @@ -295,7 +296,7 @@ void SteamParticle::Paint(PaintSession& session, int32_t imageDirection) const */ void ExplosionCloud::Create(const CoordsXYZ& cloudPos) { - auto* entity = CreateEntity(); + auto* entity = getGameState().entities.CreateEntity(); if (entity != nullptr) { entity->SpriteData.Width = 44; @@ -316,7 +317,7 @@ void ExplosionCloud::Update() frame += 128; if (frame >= (36 * 128)) { - EntityRemove(this); + getGameState().entities.EntityRemove(this); } } @@ -340,7 +341,7 @@ void ExplosionCloud::Paint(PaintSession& session, int32_t imageDirection) const */ void ExplosionFlare::Create(const CoordsXYZ& flarePos) { - auto* entity = CreateEntity(); + auto* entity = getGameState().entities.CreateEntity(); if (entity != nullptr) { entity->SpriteData.Width = 25; @@ -361,7 +362,7 @@ void ExplosionFlare::Update() frame += 64; if (frame >= (124 * 64)) { - EntityRemove(this); + getGameState().entities.EntityRemove(this); } } diff --git a/src/openrct2/entity/Peep.cpp b/src/openrct2/entity/Peep.cpp index 1724715138..3f8bed2d19 100644 --- a/src/openrct2/entity/Peep.cpp +++ b/src/openrct2/entity/Peep.cpp @@ -191,7 +191,7 @@ bool Peep::CanBePickedUp() const int32_t PeepGetStaffCount() { - return GetEntityListCount(EntityType::Staff); + return getGameState().entities.GetEntityListCount(EntityType::Staff); } /** @@ -744,7 +744,7 @@ void PeepEntityRemove(Peep* peep) News::DisableNewsItems(News::ItemType::peep, staff->Id.ToUnderlying()); } - EntityRemove(peep); + getGameState().entities.EntityRemove(peep); auto intent = Intent(wasGuest ? INTENT_ACTION_REFRESH_GUEST_LIST : INTENT_ACTION_REFRESH_STAFF_LIST); ContextBroadcastIntent(&intent); @@ -2531,8 +2531,8 @@ StringId GetRealNameStringIDFromPeepID(uint32_t id) int32_t PeepCompare(const EntityId sprite_index_a, const EntityId sprite_index_b) { - Peep const* peep_a = GetEntity(sprite_index_a); - Peep const* peep_b = GetEntity(sprite_index_b); + Peep const* peep_a = getGameState().entities.GetEntity(sprite_index_a); + Peep const* peep_b = getGameState().entities.GetEntity(sprite_index_b); if (peep_a == nullptr || peep_b == nullptr) { return 0; diff --git a/src/openrct2/entity/Staff.cpp b/src/openrct2/entity/Staff.cpp index 70336f09a0..0764208cd6 100644 --- a/src/openrct2/entity/Staff.cpp +++ b/src/openrct2/entity/Staff.cpp @@ -2111,7 +2111,7 @@ bool Staff::UpdateFixingMoveToBrokenDownVehicle(bool firstRun, const Ride& ride) break; } - vehicle = GetEntity(vehicle->prev_vehicle_on_ride); + vehicle = getGameState().entities.GetEntity(vehicle->prev_vehicle_on_ride); if (vehicle == nullptr) { return true; diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index 8ffb06aab3..92d3b6e31d 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -147,6 +147,7 @@ static void ConsoleCommandEcho(InteractiveConsole& console, const arguments_t& a static void ConsoleCommandRides(InteractiveConsole& console, const arguments_t& argv) { + auto& gameState = getGameState(); if (!argv.empty()) { if (argv[0] == "list") @@ -205,7 +206,7 @@ static void ConsoleCommandRides(InteractiveConsole& console, const arguments_t& RideId::FromUnderlying(ride_index), GameActions::RideSetSetting::RideType, type); if (res == kMoney64Undefined) { - if (!getGameState().cheats.allowArbitraryRideTypeChanges) + if (!gameState.cheats.allowArbitraryRideTypeChanges) { console.WriteFormatLine( "That didn't work. Try enabling the 'Allow arbitrary ride type changes' cheat"); @@ -277,8 +278,9 @@ static void ConsoleCommandRides(InteractiveConsole& console, const arguments_t& { for (int32_t i = 0; i < ride->numTrains; ++i) { - for (Vehicle* vehicle = GetEntity(ride->vehicles[i]); vehicle != nullptr; - vehicle = GetEntity(vehicle->next_vehicle_on_train)) + for (Vehicle* vehicle = gameState.entities.GetEntity(ride->vehicles[i]); + vehicle != nullptr; + vehicle = gameState.entities.GetEntity(vehicle->next_vehicle_on_train)) { vehicle->mass = mass; } @@ -458,6 +460,7 @@ static void ConsoleCommandRides(InteractiveConsole& console, const arguments_t& static void ConsoleCommandStaff(InteractiveConsole& console, const arguments_t& argv) { + auto& gameState = getGameState(); if (!argv.empty()) { if (argv[0] == "list") @@ -497,7 +500,7 @@ static void ConsoleCommandStaff(InteractiveConsole& console, const arguments_t& if (int_valid[0] && int_valid[1]) { - Peep* peep = GetEntity(EntityId::FromUnderlying(int_val[0])); + Peep* peep = gameState.entities.GetEntity(EntityId::FromUnderlying(int_val[0])); if (peep != nullptr) { peep->Energy = int_val[1]; @@ -516,7 +519,7 @@ static void ConsoleCommandStaff(InteractiveConsole& console, const arguments_t& console.WriteLineError("Invalid staff ID"); return; } - auto staff = GetEntity(EntityId::FromUnderlying(int_val[0])); + auto staff = gameState.entities.GetEntity(EntityId::FromUnderlying(int_val[0])); if (staff == nullptr) { console.WriteLineError("Invalid staff ID"); @@ -712,15 +715,15 @@ static void ConsoleCommandGet(InteractiveConsole& console, const arguments_t& ar } else if (argv[0] == "cheat_sandbox_mode") { - console.WriteFormatLine("cheat_sandbox_mode %d", getGameState().cheats.sandboxMode); + console.WriteFormatLine("cheat_sandbox_mode %d", gameState.cheats.sandboxMode); } else if (argv[0] == "cheat_disable_clearance_checks") { - console.WriteFormatLine("cheat_disable_clearance_checks %d", getGameState().cheats.disableClearanceChecks); + console.WriteFormatLine("cheat_disable_clearance_checks %d", gameState.cheats.disableClearanceChecks); } else if (argv[0] == "cheat_disable_support_limits") { - console.WriteFormatLine("cheat_disable_support_limits %d", getGameState().cheats.disableSupportLimits); + console.WriteFormatLine("cheat_disable_support_limits %d", gameState.cheats.disableSupportLimits); } else if (argv[0] == "current_rotation") { @@ -962,7 +965,7 @@ static void ConsoleCommandSet(InteractiveConsole& console, const arguments_t& ar } else if (varName == "cheat_sandbox_mode" && InvalidArguments(&invalidArgs, int_valid[0])) { - if (getGameState().cheats.sandboxMode != (int_val[0] != 0)) + if (gameState.cheats.sandboxMode != (int_val[0] != 0)) { ConsoleSetVariableAction( console, varName, CheatType::SandboxMode, int_val[0] != 0); @@ -974,7 +977,7 @@ static void ConsoleCommandSet(InteractiveConsole& console, const arguments_t& ar } else if (varName == "cheat_disable_clearance_checks" && InvalidArguments(&invalidArgs, int_valid[0])) { - if (getGameState().cheats.disableClearanceChecks != (int_val[0] != 0)) + if (gameState.cheats.disableClearanceChecks != (int_val[0] != 0)) { ConsoleSetVariableAction( console, varName, CheatType::DisableClearanceChecks, int_val[0] != 0); @@ -986,7 +989,7 @@ static void ConsoleCommandSet(InteractiveConsole& console, const arguments_t& ar } else if (varName == "cheat_disable_support_limits" && InvalidArguments(&invalidArgs, int_valid[0])) { - if (getGameState().cheats.disableSupportLimits != (int_val[0] != 0)) + if (gameState.cheats.disableSupportLimits != (int_val[0] != 0)) { ConsoleSetVariableAction( console, varName, CheatType::DisableSupportLimits, int_val[0] != 0); @@ -1227,7 +1230,7 @@ static void ConsoleCommandRemoveUnusedObjects(InteractiveConsole& console, [[may static void ConsoleCommandRemoveFloatingObjects(InteractiveConsole& console, const arguments_t& argv) { - uint16_t result = RemoveFloatingEntities(); + uint16_t result = getGameState().entities.RemoveFloatingEntities(); console.WriteFormatLine("Removed %d flying objects", result); } @@ -1240,7 +1243,8 @@ static void ConsoleCommandShowLimits(InteractiveConsole& console, [[maybe_unused int32_t spriteCount = 0; for (int32_t i = 0; i < static_cast(EntityType::Count); ++i) { - spriteCount += GetEntityListCount(EntityType(i)); + auto& gameState = getGameState(); + spriteCount += gameState.entities.GetEntityListCount(EntityType(i)); } auto bannerCount = GetNumBanners(); diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index 23ade513bd..860a16f176 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -148,7 +148,7 @@ namespace OpenRCT2 return arg; else if constexpr (std::is_same_v) { - auto* centreEntity = GetEntity(arg); + auto* centreEntity = getGameState().entities.GetEntity(arg); if (centreEntity != nullptr) { return CoordsXYZ{ centreEntity->x, centreEntity->y, centreEntity->z }; @@ -663,7 +663,7 @@ namespace OpenRCT2 { if (!window->viewport_target_sprite.IsNull() && window->viewport != nullptr) { - auto* sprite = GetEntity(window->viewport_target_sprite); + auto* sprite = getGameState().entities.GetEntity(window->viewport_target_sprite); if (sprite == nullptr) { return; @@ -687,7 +687,7 @@ namespace OpenRCT2 void ViewportUpdateSmartFollowEntity(WindowBase* window) { - auto entity = TryGetEntity(window->viewport_smart_follow_sprite); + auto entity = getGameState().entities.TryGetEntity(window->viewport_smart_follow_sprite); if (entity == nullptr || entity->Type == EntityType::Null) { window->viewport_smart_follow_sprite = EntityId::GetNull(); @@ -748,7 +748,7 @@ namespace OpenRCT2 auto ride = GetRide(peep.CurrentRide); if (ride != nullptr && (ride->lifecycleFlags & RIDE_LIFECYCLE_ON_TRACK)) { - auto train = GetEntity(ride->vehicles[peep.CurrentTrain]); + auto train = getGameState().entities.GetEntity(ride->vehicles[peep.CurrentTrain]); if (train != nullptr) { const auto car = train->GetCar(peep.CurrentCar); diff --git a/src/openrct2/management/Award.cpp b/src/openrct2/management/Award.cpp index 1936353e27..64522342d5 100644 --- a/src/openrct2/management/Award.cpp +++ b/src/openrct2/management/Award.cpp @@ -280,8 +280,9 @@ static bool AwardIsDeservedBestStaff(int32_t activeAwardTypes) if (activeAwardTypes & EnumToFlag(AwardType::MostUntidy)) return false; - auto staffCount = GetEntityListCount(EntityType::Staff); - auto peepCount = GetEntityListCount(EntityType::Guest); + auto& gameState = getGameState(); + auto staffCount = gameState.entities.GetEntityListCount(EntityType::Staff); + auto peepCount = gameState.entities.GetEntityListCount(EntityType::Guest); return ((staffCount != 0) && staffCount >= 20 && staffCount >= peepCount / 32); } diff --git a/src/openrct2/management/NewsItem.cpp b/src/openrct2/management/NewsItem.cpp index b71110b203..b2973d6378 100644 --- a/src/openrct2/management/NewsItem.cpp +++ b/src/openrct2/management/NewsItem.cpp @@ -213,6 +213,8 @@ std::optional News::GetSubjectLocation(News::ItemType type, int32_t s { std::optional subjectLoc{ std::nullopt }; + auto& gameState = getGameState(); + switch (type) { case News::ItemType::ride: @@ -228,7 +230,7 @@ std::optional News::GetSubjectLocation(News::ItemType type, int32_t s } case News::ItemType::peepOnRide: { - auto peep = TryGetEntity(EntityId::FromUnderlying(subject)); + auto peep = gameState.entities.TryGetEntity(EntityId::FromUnderlying(subject)); if (peep == nullptr) break; @@ -251,11 +253,11 @@ std::optional News::GetSubjectLocation(News::ItemType type, int32_t s } // Find the first car of the train peep is on - auto sprite = TryGetEntity(ride->vehicles[peep->CurrentTrain]); + auto sprite = gameState.entities.TryGetEntity(ride->vehicles[peep->CurrentTrain]); // Find the actual car peep is on for (int32_t i = 0; i < peep->CurrentCar && sprite != nullptr; i++) { - sprite = TryGetEntity(sprite->next_vehicle_on_train); + sprite = gameState.entities.TryGetEntity(sprite->next_vehicle_on_train); } if (sprite != nullptr) { @@ -265,7 +267,7 @@ std::optional News::GetSubjectLocation(News::ItemType type, int32_t s } case News::ItemType::peep: { - auto peep = TryGetEntity(EntityId::FromUnderlying(subject)); + auto peep = gameState.entities.TryGetEntity(EntityId::FromUnderlying(subject)); if (peep != nullptr) { subjectLoc = peep->GetLocation(); @@ -378,7 +380,7 @@ void News::OpenSubject(News::ItemType type, int32_t subject) case News::ItemType::peepOnRide: case News::ItemType::peep: { - auto peep = TryGetEntity(EntityId::FromUnderlying(subject)); + auto peep = getGameState().entities.TryGetEntity(EntityId::FromUnderlying(subject)); if (peep != nullptr) { auto intent = Intent(WindowClass::Peep); diff --git a/src/openrct2/network/NetworkBase.cpp b/src/openrct2/network/NetworkBase.cpp index 3903011e52..443e0ff733 100644 --- a/src/openrct2/network/NetworkBase.cpp +++ b/src/openrct2/network/NetworkBase.cpp @@ -822,7 +822,7 @@ bool NetworkBase::CheckSRAND(uint32_t tick, uint32_t srand0) if (!storedTick.spriteHash.empty()) { - EntitiesChecksum checksum = GetAllEntitiesChecksum(); + EntitiesChecksum checksum = getGameState().entities.GetAllEntitiesChecksum(); std::string clientSpriteHash = checksum.ToString(); if (clientSpriteHash != storedTick.spriteHash) { @@ -1592,7 +1592,7 @@ void NetworkBase::ServerSendTick() packet << flags; if (flags & NETWORK_TICK_FLAG_CHECKSUMS) { - EntitiesChecksum checksum = GetAllEntitiesChecksum(); + EntitiesChecksum checksum = getGameState().entities.GetAllEntitiesChecksum(); packet.WriteString(checksum.ToString()); } diff --git a/src/openrct2/paint/tile_element/Paint.Surface.cpp b/src/openrct2/paint/tile_element/Paint.Surface.cpp index 7022ae1572..c39242309e 100644 --- a/src/openrct2/paint/tile_element/Paint.Surface.cpp +++ b/src/openrct2/paint/tile_element/Paint.Surface.cpp @@ -881,7 +881,7 @@ std::optional GetPatrolAreaTileColour(const CoordsXY& pos) else { auto& staffId = std::get(patrolAreaToRender); - auto* staff = GetEntity(staffId); + auto* staff = getGameState().entities.GetEntity(staffId); if (staff != nullptr) { if (staff->IsPatrolAreaSet(pos)) diff --git a/src/openrct2/paint/track/gentle/Circus.cpp b/src/openrct2/paint/track/gentle/Circus.cpp index eb4f3eaaac..eac97bd5b7 100644 --- a/src/openrct2/paint/track/gentle/Circus.cpp +++ b/src/openrct2/paint/track/gentle/Circus.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include "../../../GameState.h" #include "../../../entity/EntityRegistry.h" #include "../../../interface/Viewport.h" #include "../../../ride/Ride.h" @@ -29,7 +30,7 @@ static void PaintCircusTent( if (rideEntry == nullptr) return; - auto vehicle = GetEntity(ride.vehicles[0]); + auto vehicle = getGameState().entities.GetEntity(ride.vehicles[0]); if (ride.lifecycleFlags & RIDE_LIFECYCLE_ON_TRACK && vehicle != nullptr) { session.InteractionType = ViewportInteractionItem::Entity; diff --git a/src/openrct2/paint/track/gentle/CrookedHouse.cpp b/src/openrct2/paint/track/gentle/CrookedHouse.cpp index 302c236ffb..7ac4621be1 100644 --- a/src/openrct2/paint/track/gentle/CrookedHouse.cpp +++ b/src/openrct2/paint/track/gentle/CrookedHouse.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include "../../../GameState.h" #include "../../../entity/EntityRegistry.h" #include "../../../interface/Viewport.h" #include "../../../ride/Ride.h" @@ -69,7 +70,7 @@ static void PaintCrookedHouseStructure( if (ride->lifecycleFlags & RIDE_LIFECYCLE_ON_TRACK) { - auto vehicle = GetEntity(ride->vehicles[0]); + auto vehicle = getGameState().entities.GetEntity(ride->vehicles[0]); if (vehicle != nullptr) { session.InteractionType = ViewportInteractionItem::Entity; diff --git a/src/openrct2/paint/track/gentle/FerrisWheel.cpp b/src/openrct2/paint/track/gentle/FerrisWheel.cpp index 0703eea7ce..70e73dd6d8 100644 --- a/src/openrct2/paint/track/gentle/FerrisWheel.cpp +++ b/src/openrct2/paint/track/gentle/FerrisWheel.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include "../../../GameState.h" #include "../../../entity/EntityRegistry.h" #include "../../../entity/Guest.h" #include "../../../interface/Viewport.h" @@ -51,7 +52,7 @@ static void PaintFerrisWheelRiders( { for (int32_t i = 0; i < 32; i += 2) { - auto* peep = GetEntity(vehicle.peep[i]); + auto* peep = getGameState().entities.GetEntity(vehicle.peep[i]); if (peep == nullptr || peep->State != PeepState::OnRide) continue; @@ -69,7 +70,7 @@ static void PaintFerrisWheelStructure( if (rideEntry == nullptr) return; - auto vehicle = GetEntity(ride.vehicles[0]); + auto vehicle = getGameState().entities.GetEntity(ride.vehicles[0]); if (ride.lifecycleFlags & RIDE_LIFECYCLE_ON_TRACK && vehicle != nullptr) { session.InteractionType = ViewportInteractionItem::Entity; diff --git a/src/openrct2/paint/track/gentle/HauntedHouse.cpp b/src/openrct2/paint/track/gentle/HauntedHouse.cpp index db2f1a7fae..80098440f4 100644 --- a/src/openrct2/paint/track/gentle/HauntedHouse.cpp +++ b/src/openrct2/paint/track/gentle/HauntedHouse.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include "../../../GameState.h" #include "../../../entity/EntityRegistry.h" #include "../../../interface/Viewport.h" #include "../../../ride/Ride.h" @@ -38,7 +39,7 @@ static void PaintHauntedHouseStructure( if (rideEntry == nullptr) return; - auto vehicle = GetEntity(ride.vehicles[0]); + auto vehicle = getGameState().entities.GetEntity(ride.vehicles[0]); if (ride.lifecycleFlags & RIDE_LIFECYCLE_ON_TRACK && vehicle != nullptr) { session.InteractionType = ViewportInteractionItem::Entity; diff --git a/src/openrct2/paint/track/gentle/MerryGoRound.cpp b/src/openrct2/paint/track/gentle/MerryGoRound.cpp index 7de5f6c9e9..fbd6e31916 100644 --- a/src/openrct2/paint/track/gentle/MerryGoRound.cpp +++ b/src/openrct2/paint/track/gentle/MerryGoRound.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include "../../../GameState.h" #include "../../../entity/EntityRegistry.h" #include "../../../interface/Viewport.h" #include "../../../ride/Ride.h" @@ -64,7 +65,7 @@ static void PaintCarousel( if (rideEntry == nullptr) return; - auto vehicle = GetEntity(ride.vehicles[0]); + auto vehicle = getGameState().entities.GetEntity(ride.vehicles[0]); if (ride.lifecycleFlags & RIDE_LIFECYCLE_ON_TRACK && vehicle != nullptr) { session.InteractionType = ViewportInteractionItem::Entity; diff --git a/src/openrct2/paint/track/gentle/SpaceRings.cpp b/src/openrct2/paint/track/gentle/SpaceRings.cpp index 1ea7f5a3da..ae8f42feb0 100644 --- a/src/openrct2/paint/track/gentle/SpaceRings.cpp +++ b/src/openrct2/paint/track/gentle/SpaceRings.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include "../../../GameState.h" #include "../../../entity/EntityRegistry.h" #include "../../../entity/Guest.h" #include "../../../interface/Viewport.h" @@ -52,7 +53,7 @@ static void PaintSpaceRingsStructure( int32_t frameNum = direction; uint32_t baseImageId = rideEntry->Cars[0].base_image_id; - auto vehicle = GetEntity(ride.vehicles[vehicleIndex]); + auto vehicle = getGameState().entities.GetEntity(ride.vehicles[vehicleIndex]); if (ride.lifecycleFlags & RIDE_LIFECYCLE_ON_TRACK && vehicle != nullptr) { session.InteractionType = ViewportInteractionItem::Entity; @@ -75,7 +76,7 @@ static void PaintSpaceRingsStructure( if (vehicle != nullptr && vehicle->num_peeps > 0) { - auto* rider = GetEntity(vehicle->peep[0]); + auto* rider = getGameState().entities.GetEntity(vehicle->peep[0]); if (rider != nullptr) { stationColour = ImageId(0, rider->TshirtColour, rider->TrousersColour); diff --git a/src/openrct2/paint/track/thrill/3dCinema.cpp b/src/openrct2/paint/track/thrill/3dCinema.cpp index f749505ae3..8e87748987 100644 --- a/src/openrct2/paint/track/thrill/3dCinema.cpp +++ b/src/openrct2/paint/track/thrill/3dCinema.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include "../../../GameState.h" #include "../../../entity/EntityRegistry.h" #include "../../../interface/Viewport.h" #include "../../../ride/Ride.h" @@ -32,7 +33,7 @@ static void Paint3dCinemaDome( if (ride.lifecycleFlags & RIDE_LIFECYCLE_ON_TRACK && !ride.vehicles[0].IsNull()) { session.InteractionType = ViewportInteractionItem::Entity; - session.CurrentlyDrawnEntity = GetEntity(ride.vehicles[0]); + session.CurrentlyDrawnEntity = getGameState().entities.GetEntity(ride.vehicles[0]); } auto imageTemplate = ImageId(0, ride.vehicleColours[0].Body, ride.vehicleColours[0].Trim); diff --git a/src/openrct2/paint/track/thrill/Enterprise.cpp b/src/openrct2/paint/track/thrill/Enterprise.cpp index e05cf75a0d..a89477c5e1 100644 --- a/src/openrct2/paint/track/thrill/Enterprise.cpp +++ b/src/openrct2/paint/track/thrill/Enterprise.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include "../../../GameState.h" #include "../../../entity/EntityRegistry.h" #include "../../../interface/Viewport.h" #include "../../../ride/Ride.h" @@ -57,7 +58,7 @@ static void PaintEnterpriseStructure( Vehicle* vehicle = nullptr; if (ride.lifecycleFlags & RIDE_LIFECYCLE_ON_TRACK) { - vehicle = GetEntity(ride.vehicles[0]); + vehicle = getGameState().entities.GetEntity(ride.vehicles[0]); if (vehicle != nullptr) { session.InteractionType = ViewportInteractionItem::Entity; diff --git a/src/openrct2/paint/track/thrill/MagicCarpet.cpp b/src/openrct2/paint/track/thrill/MagicCarpet.cpp index 5863884942..3275b299e8 100644 --- a/src/openrct2/paint/track/thrill/MagicCarpet.cpp +++ b/src/openrct2/paint/track/thrill/MagicCarpet.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include "../../../GameState.h" #include "../../../entity/EntityRegistry.h" #include "../../../interface/Viewport.h" #include "../../../object/StationObject.h" @@ -95,7 +96,7 @@ static Vehicle* GetFirstVehicle(const Ride& ride) { if (ride.lifecycleFlags & RIDE_LIFECYCLE_ON_TRACK) { - return GetEntity(ride.vehicles[0]); + return getGameState().entities.GetEntity(ride.vehicles[0]); } return nullptr; } diff --git a/src/openrct2/paint/track/thrill/MotionSimulator.cpp b/src/openrct2/paint/track/thrill/MotionSimulator.cpp index 72d5751ec8..5c56abc527 100644 --- a/src/openrct2/paint/track/thrill/MotionSimulator.cpp +++ b/src/openrct2/paint/track/thrill/MotionSimulator.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include "../../../GameState.h" #include "../../../entity/EntityRegistry.h" #include "../../../interface/Viewport.h" #include "../../../ride/Ride.h" @@ -47,7 +48,7 @@ static void PaintMotionSimulatorVehicle( Vehicle* vehicle = nullptr; if (ride.lifecycleFlags & RIDE_LIFECYCLE_ON_TRACK) { - vehicle = GetEntity(ride.vehicles[0]); + vehicle = getGameState().entities.GetEntity(ride.vehicles[0]); if (vehicle != nullptr) { session.InteractionType = ViewportInteractionItem::Entity; diff --git a/src/openrct2/paint/track/thrill/SwingingInverterShip.cpp b/src/openrct2/paint/track/thrill/SwingingInverterShip.cpp index 3c0707942d..0334135a1c 100644 --- a/src/openrct2/paint/track/thrill/SwingingInverterShip.cpp +++ b/src/openrct2/paint/track/thrill/SwingingInverterShip.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include "../../../GameState.h" #include "../../../entity/EntityRegistry.h" #include "../../../interface/Viewport.h" #include "../../../object/StationObject.h" @@ -76,7 +77,7 @@ static void PaintSwingingInverterShipStructure( Vehicle* vehicle = nullptr; if (ride.lifecycleFlags & RIDE_LIFECYCLE_ON_TRACK) { - vehicle = GetEntity(ride.vehicles[0]); + vehicle = getGameState().entities.GetEntity(ride.vehicles[0]); if (vehicle != nullptr) { session.InteractionType = ViewportInteractionItem::Entity; diff --git a/src/openrct2/paint/track/thrill/SwingingShip.cpp b/src/openrct2/paint/track/thrill/SwingingShip.cpp index 4236261e58..2d4e0b3f71 100644 --- a/src/openrct2/paint/track/thrill/SwingingShip.cpp +++ b/src/openrct2/paint/track/thrill/SwingingShip.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include "../../../GameState.h" #include "../../../entity/EntityRegistry.h" #include "../../../interface/Viewport.h" #include "../../../object/StationObject.h" @@ -97,7 +98,7 @@ static void PaintSwingingShipStructure( Vehicle* vehicle = nullptr; if (ride.lifecycleFlags & RIDE_LIFECYCLE_ON_TRACK && !ride.vehicles[0].IsNull()) { - vehicle = GetEntity(ride.vehicles[0]); + vehicle = getGameState().entities.GetEntity(ride.vehicles[0]); session.InteractionType = ViewportInteractionItem::Entity; session.CurrentlyDrawnEntity = vehicle; } diff --git a/src/openrct2/paint/track/thrill/TopSpin.cpp b/src/openrct2/paint/track/thrill/TopSpin.cpp index 6fde8a9fd8..0061b4aaeb 100644 --- a/src/openrct2/paint/track/thrill/TopSpin.cpp +++ b/src/openrct2/paint/track/thrill/TopSpin.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include "../../../GameState.h" #include "../../../SpriteIds.h" #include "../../../entity/EntityRegistry.h" #include "../../../interface/Viewport.h" @@ -128,7 +129,7 @@ static void PaintTopSpinVehicle( height += 3; uint8_t seatRotation = 0; uint8_t armRotation = 0; - auto* vehicle = GetEntity(ride.vehicles[0]); + auto* vehicle = getGameState().entities.GetEntity(ride.vehicles[0]); if (ride.lifecycleFlags & RIDE_LIFECYCLE_ON_TRACK && vehicle != nullptr) { session.InteractionType = ViewportInteractionItem::Entity; diff --git a/src/openrct2/paint/track/thrill/Twist.cpp b/src/openrct2/paint/track/thrill/Twist.cpp index c5152a65f6..96b0b68425 100644 --- a/src/openrct2/paint/track/thrill/Twist.cpp +++ b/src/openrct2/paint/track/thrill/Twist.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include "../../../GameState.h" #include "../../../entity/EntityRegistry.h" #include "../../../interface/Viewport.h" #include "../../../ride/Ride.h" @@ -39,7 +40,7 @@ static void PaintTwistStructure( if (ride.lifecycleFlags & RIDE_LIFECYCLE_ON_TRACK && !ride.vehicles[0].IsNull()) { - vehicle = GetEntity(ride.vehicles[0]); + vehicle = getGameState().entities.GetEntity(ride.vehicles[0]); session.InteractionType = ViewportInteractionItem::Entity; session.CurrentlyDrawnEntity = vehicle; diff --git a/src/openrct2/paint/vehicle/Vehicle.MiniGolf.cpp b/src/openrct2/paint/vehicle/Vehicle.MiniGolf.cpp index 6a2388f624..3a6c0206b5 100644 --- a/src/openrct2/paint/vehicle/Vehicle.MiniGolf.cpp +++ b/src/openrct2/paint/vehicle/Vehicle.MiniGolf.cpp @@ -9,6 +9,7 @@ #include "Vehicle.MiniGolf.h" +#include "../../GameState.h" #include "../../entity/EntityRegistry.h" #include "../../entity/Guest.h" #include "../../ride/Ride.h" @@ -117,7 +118,7 @@ namespace OpenRCT2 if (rideEntry == nullptr) return; - auto* peep = GetEntity(vehicle->peep[0]); + auto* peep = getGameState().entities.GetEntity(vehicle->peep[0]); if (peep == nullptr) return; diff --git a/src/openrct2/paint/vehicle/Vehicle.ReverserRollerCoaster.cpp b/src/openrct2/paint/vehicle/Vehicle.ReverserRollerCoaster.cpp index 541e463093..30f6e29dfd 100644 --- a/src/openrct2/paint/vehicle/Vehicle.ReverserRollerCoaster.cpp +++ b/src/openrct2/paint/vehicle/Vehicle.ReverserRollerCoaster.cpp @@ -9,6 +9,7 @@ #include "../../ride/Vehicle.h" +#include "../../GameState.h" #include "../../entity/EntityRegistry.h" #include "../Paint.h" #include "VehiclePaint.h" @@ -25,8 +26,8 @@ namespace OpenRCT2 PaintSession& session, int32_t x, int32_t imageDirection, int32_t y, int32_t z, const Vehicle* vehicle, const CarEntry* carEntry) { - Vehicle* v1 = GetEntity(vehicle->prev_vehicle_on_ride); - Vehicle* v2 = GetEntity(vehicle->next_vehicle_on_ride); + Vehicle* v1 = getGameState().entities.GetEntity(vehicle->prev_vehicle_on_ride); + Vehicle* v2 = getGameState().entities.GetEntity(vehicle->next_vehicle_on_ride); if (v1 == nullptr || v2 == nullptr) { return; diff --git a/src/openrct2/paint/vehicle/Vehicle.SplashBoats.cpp b/src/openrct2/paint/vehicle/Vehicle.SplashBoats.cpp index 0f03640157..48df702b0d 100644 --- a/src/openrct2/paint/vehicle/Vehicle.SplashBoats.cpp +++ b/src/openrct2/paint/vehicle/Vehicle.SplashBoats.cpp @@ -9,6 +9,7 @@ #include "../../ride/Vehicle.h" +#include "../../GameState.h" #include "../../entity/EntityRegistry.h" #include "../../ride/Ride.h" #include "../Paint.h" @@ -26,8 +27,11 @@ namespace OpenRCT2 PaintSession& session, int32_t x, int32_t imageDirection, int32_t y, int32_t z, const Vehicle* vehicle, const CarEntry* carEntry) { - auto* vehicleToPaint = vehicle->IsHead() ? GetEntity(vehicle->next_vehicle_on_ride) - : GetEntity(vehicle->prev_vehicle_on_ride); + // TODO: pass as parameter? + auto& entityRegistry = getGameState().entities; + + auto* vehicleToPaint = vehicle->IsHead() ? entityRegistry.GetEntity(vehicle->next_vehicle_on_ride) + : entityRegistry.GetEntity(vehicle->prev_vehicle_on_ride); if (vehicleToPaint == nullptr) { return; diff --git a/src/openrct2/paint/vehicle/VehiclePaint.cpp b/src/openrct2/paint/vehicle/VehiclePaint.cpp index 6dacace3a9..754c4a2687 100644 --- a/src/openrct2/paint/vehicle/VehiclePaint.cpp +++ b/src/openrct2/paint/vehicle/VehiclePaint.cpp @@ -4505,7 +4505,7 @@ static void vehicle_visual_splash3_effect(PaintSession& session, const int32_t z */ static void vehicle_visual_splash4_effect(PaintSession& session, const int32_t z, const Vehicle* vehicle) { - Vehicle* vehicle2 = GetEntity(vehicle->prev_vehicle_on_ride); + Vehicle* vehicle2 = getGameState().entities.GetEntity(vehicle->prev_vehicle_on_ride); if (vehicle2 == nullptr) { return; @@ -4533,7 +4533,7 @@ static void vehicle_visual_splash4_effect(PaintSession& session, const int32_t z */ static void vehicle_visual_splash5_effect(PaintSession& session, const int32_t z, const Vehicle* vehicle) { - Vehicle* vehicle2 = GetEntity(vehicle->prev_vehicle_on_ride); + Vehicle* vehicle2 = getGameState().entities.GetEntity(vehicle->prev_vehicle_on_ride); if (vehicle2 == nullptr) { return; diff --git a/src/openrct2/park/ParkFile.cpp b/src/openrct2/park/ParkFile.cpp index 5dffbd4459..4a6a9e40cf 100644 --- a/src/openrct2/park/ParkFile.cpp +++ b/src/openrct2/park/ParkFile.cpp @@ -2155,15 +2155,15 @@ namespace OpenRCT2 } template - void WriteEntitiesOfType(OrcaStream& os, OrcaStream::ChunkStream& cs); + void WriteEntitiesOfType(GameState_t& gameState, OrcaStream& os, OrcaStream::ChunkStream& cs); template - void WriteEntitiesOfTypes(OrcaStream& os, OrcaStream::ChunkStream& cs); + void WriteEntitiesOfTypes(GameState_t& gameState, OrcaStream& os, OrcaStream::ChunkStream& cs); template - void ReadEntitiesOfType(OrcaStream& os, OrcaStream::ChunkStream& cs); + void ReadEntitiesOfType(GameState_t& gameState, OrcaStream& os, OrcaStream::ChunkStream& cs); template - void ReadEntitiesOfTypes(OrcaStream& os, OrcaStream::ChunkStream& cs); + void ReadEntitiesOfTypes(GameState_t& gameState, OrcaStream& os, OrcaStream::ChunkStream& cs); void ReadWriteEntitiesChunk(GameState_t& gameState, OrcaStream& os); @@ -2637,9 +2637,9 @@ namespace OpenRCT2 } template - void ParkFile::WriteEntitiesOfType(OrcaStream& os, OrcaStream::ChunkStream& cs) + void ParkFile::WriteEntitiesOfType(GameState_t& gameState, OrcaStream& os, OrcaStream::ChunkStream& cs) { - uint16_t count = GetEntityListCount(T::cEntityType); + uint16_t count = gameState.entities.GetEntityListCount(T::cEntityType); cs.write(T::cEntityType); cs.write(count); for (auto* ent : EntityList()) @@ -2650,13 +2650,13 @@ namespace OpenRCT2 } template - void ParkFile::WriteEntitiesOfTypes(OrcaStream& os, OrcaStream::ChunkStream& cs) + void ParkFile::WriteEntitiesOfTypes(GameState_t& gameState, OrcaStream& os, OrcaStream::ChunkStream& cs) { - (WriteEntitiesOfType(os, cs), ...); + (WriteEntitiesOfType(gameState, os, cs), ...); } template - void ParkFile::ReadEntitiesOfType(OrcaStream& os, OrcaStream::ChunkStream& cs) + void ParkFile::ReadEntitiesOfType(GameState_t& gameState, OrcaStream& os, OrcaStream::ChunkStream& cs) { [[maybe_unused]] auto t = cs.read(); assert(t == T::cEntityType); @@ -2666,7 +2666,7 @@ namespace OpenRCT2 T placeholder{}; auto index = cs.read(); - auto* ent = CreateEntityAt(index); + auto* ent = getGameState().entities.CreateEntityAt(index); if (ent == nullptr) { // Unable to allocate entity @@ -2677,9 +2677,9 @@ namespace OpenRCT2 } template - void ParkFile::ReadEntitiesOfTypes(OrcaStream& os, OrcaStream::ChunkStream& cs) + void ParkFile::ReadEntitiesOfTypes(GameState_t& gameState, OrcaStream& os, OrcaStream::ChunkStream& cs) { - (ReadEntitiesOfType(os, cs), ...); + (ReadEntitiesOfType(gameState, os, cs), ...); } void ParkFile::ReadWriteEntitiesChunk(GameState_t& gameState, OrcaStream& os) @@ -2687,7 +2687,7 @@ namespace OpenRCT2 os.readWriteChunk(ParkFileChunkType::ENTITIES, [this, &gameState, &os](OrcaStream::ChunkStream& cs) { if (cs.getMode() == OrcaStream::Mode::reading) { - ResetAllEntities(); + getGameState().entities.ResetAllEntities(); } std::vector entityIndices; @@ -2695,7 +2695,7 @@ namespace OpenRCT2 { ReadEntitiesOfTypes< Vehicle, Guest, Staff, Litter, SteamParticle, MoneyEffect, VehicleCrashParticle, ExplosionCloud, - CrashSplashParticle, ExplosionFlare, JumpingFountain, Balloon, Duck>(os, cs); + CrashSplashParticle, ExplosionFlare, JumpingFountain, Balloon, Duck>(gameState, os, cs); auto version = os.getHeader().targetVersion; if (version < kPeepAnimationObjectsVersion) @@ -2707,7 +2707,7 @@ namespace OpenRCT2 { WriteEntitiesOfTypes< Vehicle, Guest, Staff, Litter, SteamParticle, MoneyEffect, VehicleCrashParticle, ExplosionCloud, - CrashSplashParticle, ExplosionFlare, JumpingFountain, Balloon, Duck>(os, cs); + CrashSplashParticle, ExplosionFlare, JumpingFountain, Balloon, Duck>(gameState, os, cs); } }); } diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 8469953740..f0ea1cb1ae 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -189,7 +189,7 @@ namespace OpenRCT2::RCT1 ImportRides(); ImportRideMeasurements(); - ImportEntities(); + ImportEntities(gameState); ImportTileElements(gameState); ImportMapAnimations(); ImportPeepSpawns(gameState); @@ -1259,15 +1259,15 @@ namespace OpenRCT2::RCT1 } } - void ImportEntity(const RCT12EntityBase& src); + void ImportEntity(GameState_t& gameState, const RCT12EntityBase& src); template - void ImportEntity(const RCT12EntityBase& src); + void ImportEntity(GameState_t& gameState, const RCT12EntityBase& src); - void ImportEntities() + void ImportEntities(GameState_t& gameState) { for (int i = 0; i < Limits::kMaxEntities; i++) { - ImportEntity(_s4.Entities[i].Unknown); + ImportEntity(gameState, _s4.Entities[i].Unknown); } } @@ -2782,9 +2782,9 @@ namespace OpenRCT2::RCT1 } template<> - void S4Importer::ImportEntity<::Vehicle>(const RCT12EntityBase& srcBase) + void S4Importer::ImportEntity<::Vehicle>(GameState_t& gameState, const RCT12EntityBase& srcBase) { - auto* dst = CreateEntityAt<::Vehicle>(EntityId::FromUnderlying(srcBase.EntityIndex)); + auto* dst = getGameState().entities.CreateEntityAt<::Vehicle>(EntityId::FromUnderlying(srcBase.EntityIndex)); auto* src = static_cast(&srcBase); const auto* ride = GetRide(RideId::FromUnderlying(src->Ride)); if (ride == nullptr) @@ -2905,9 +2905,9 @@ namespace OpenRCT2::RCT1 } template<> - void S4Importer::ImportEntity(const RCT12EntityBase& srcBase) + void S4Importer::ImportEntity(GameState_t& gameState, const RCT12EntityBase& srcBase) { - auto* dst = CreateEntityAt(EntityId::FromUnderlying(srcBase.EntityIndex)); + auto* dst = getGameState().entities.CreateEntityAt(EntityId::FromUnderlying(srcBase.EntityIndex)); auto* src = static_cast(&srcBase); ImportPeep(dst, src); @@ -2997,9 +2997,9 @@ namespace OpenRCT2::RCT1 } template<> - void S4Importer::ImportEntity(const RCT12EntityBase& srcBase) + void S4Importer::ImportEntity(GameState_t& gameState, const RCT12EntityBase& srcBase) { - auto* dst = CreateEntityAt(EntityId::FromUnderlying(srcBase.EntityIndex)); + auto* dst = getGameState().entities.CreateEntityAt(EntityId::FromUnderlying(srcBase.EntityIndex)); auto* src = static_cast(&srcBase); ImportPeep(dst, src); dst->AssignedStaffType = StaffType(src->StaffType); @@ -3016,9 +3016,9 @@ namespace OpenRCT2::RCT1 } template<> - void S4Importer::ImportEntity(const RCT12EntityBase& srcBase) + void S4Importer::ImportEntity(GameState_t& gameState, const RCT12EntityBase& srcBase) { - auto* dst = CreateEntityAt(EntityId::FromUnderlying(srcBase.EntityIndex)); + auto* dst = getGameState().entities.CreateEntityAt(EntityId::FromUnderlying(srcBase.EntityIndex)); auto* src = static_cast(&srcBase); ImportEntityCommonProperties(dst, src); @@ -3027,9 +3027,9 @@ namespace OpenRCT2::RCT1 } template<> - void S4Importer::ImportEntity(const RCT12EntityBase& srcBase) + void S4Importer::ImportEntity(GameState_t& gameState, const RCT12EntityBase& srcBase) { - auto* dst = CreateEntityAt(EntityId::FromUnderlying(srcBase.EntityIndex)); + auto* dst = getGameState().entities.CreateEntityAt(EntityId::FromUnderlying(srcBase.EntityIndex)); auto* src = static_cast(&srcBase); ImportEntityCommonProperties(dst, src); @@ -3038,9 +3038,9 @@ namespace OpenRCT2::RCT1 } template<> - void S4Importer::ImportEntity(const RCT12EntityBase& srcBase) + void S4Importer::ImportEntity(GameState_t& gameState, const RCT12EntityBase& srcBase) { - auto* dst = CreateEntityAt(EntityId::FromUnderlying(srcBase.EntityIndex)); + auto* dst = getGameState().entities.CreateEntityAt(EntityId::FromUnderlying(srcBase.EntityIndex)); auto* src = static_cast(&srcBase); ImportEntityCommonProperties(dst, src); @@ -3053,9 +3053,9 @@ namespace OpenRCT2::RCT1 } template<> - void S4Importer::ImportEntity(const RCT12EntityBase& srcBase) + void S4Importer::ImportEntity(GameState_t& gameState, const RCT12EntityBase& srcBase) { - auto* dst = CreateEntityAt(EntityId::FromUnderlying(srcBase.EntityIndex)); + auto* dst = getGameState().entities.CreateEntityAt(EntityId::FromUnderlying(srcBase.EntityIndex)); auto* src = static_cast(&srcBase); ImportEntityCommonProperties(dst, src); dst->frame = src->Frame; @@ -3072,36 +3072,36 @@ namespace OpenRCT2::RCT1 } template<> - void S4Importer::ImportEntity(const RCT12EntityBase& srcBase) + void S4Importer::ImportEntity(GameState_t& gameState, const RCT12EntityBase& srcBase) { - auto* dst = CreateEntityAt(EntityId::FromUnderlying(srcBase.EntityIndex)); + auto* dst = getGameState().entities.CreateEntityAt(EntityId::FromUnderlying(srcBase.EntityIndex)); auto* src = static_cast(&srcBase); ImportEntityCommonProperties(dst, src); dst->frame = src->Frame; } template<> - void S4Importer::ImportEntity(const RCT12EntityBase& srcBase) + void S4Importer::ImportEntity(GameState_t& gameState, const RCT12EntityBase& srcBase) { - auto* dst = CreateEntityAt(EntityId::FromUnderlying(srcBase.EntityIndex)); + auto* dst = getGameState().entities.CreateEntityAt(EntityId::FromUnderlying(srcBase.EntityIndex)); auto* src = static_cast(&srcBase); ImportEntityCommonProperties(dst, src); dst->frame = src->Frame; } template<> - void S4Importer::ImportEntity(const RCT12EntityBase& srcBase) + void S4Importer::ImportEntity(GameState_t& gameState, const RCT12EntityBase& srcBase) { - auto* dst = CreateEntityAt(EntityId::FromUnderlying(srcBase.EntityIndex)); + auto* dst = getGameState().entities.CreateEntityAt(EntityId::FromUnderlying(srcBase.EntityIndex)); auto* src = static_cast(&srcBase); ImportEntityCommonProperties(dst, src); dst->frame = src->Frame; } template<> - void S4Importer::ImportEntity(const RCT12EntityBase& srcBase) + void S4Importer::ImportEntity(GameState_t& gameState, const RCT12EntityBase& srcBase) { - auto* dst = CreateEntityAt(EntityId::FromUnderlying(srcBase.EntityIndex)); + auto* dst = getGameState().entities.CreateEntityAt(EntityId::FromUnderlying(srcBase.EntityIndex)); auto* src = static_cast(&srcBase); auto fountainType = JumpingFountainType::Water; @@ -3119,9 +3119,9 @@ namespace OpenRCT2::RCT1 } template<> - void S4Importer::ImportEntity(const RCT12EntityBase& srcBase) + void S4Importer::ImportEntity(GameState_t& gameState, const RCT12EntityBase& srcBase) { - auto* dst = CreateEntityAt(EntityId::FromUnderlying(srcBase.EntityIndex)); + auto* dst = getGameState().entities.CreateEntityAt(EntityId::FromUnderlying(srcBase.EntityIndex)); auto* src = static_cast(&srcBase); ImportEntityCommonProperties(dst, src); @@ -3140,9 +3140,9 @@ namespace OpenRCT2::RCT1 } template<> - void S4Importer::ImportEntity(const RCT12EntityBase& srcBase) + void S4Importer::ImportEntity(GameState_t& gameState, const RCT12EntityBase& srcBase) { - auto* dst = CreateEntityAt(EntityId::FromUnderlying(srcBase.EntityIndex)); + auto* dst = getGameState().entities.CreateEntityAt(EntityId::FromUnderlying(srcBase.EntityIndex)); auto* src = static_cast(&srcBase); ImportEntityCommonProperties(dst, src); @@ -3152,48 +3152,48 @@ namespace OpenRCT2::RCT1 dst->state = static_cast(src->State); } - void S4Importer::ImportEntity(const RCT12EntityBase& src) + void S4Importer::ImportEntity(GameState_t& gameState, const RCT12EntityBase& src) { switch (GetEntityTypeFromRCT1Sprite(src)) { case EntityType::Vehicle: - ImportEntity<::Vehicle>(src); + ImportEntity<::Vehicle>(gameState, src); break; case EntityType::Guest: - ImportEntity(src); + ImportEntity(gameState, src); break; case EntityType::Staff: - ImportEntity(src); + ImportEntity(gameState, src); break; case EntityType::SteamParticle: - ImportEntity(src); + ImportEntity(gameState, src); break; case EntityType::MoneyEffect: - ImportEntity(src); + ImportEntity(gameState, src); break; case EntityType::CrashedVehicleParticle: - ImportEntity(src); + ImportEntity(gameState, src); break; case EntityType::ExplosionCloud: - ImportEntity(src); + ImportEntity(gameState, src); break; case EntityType::ExplosionFlare: - ImportEntity(src); + ImportEntity(gameState, src); break; case EntityType::CrashSplash: - ImportEntity(src); + ImportEntity(gameState, src); break; case EntityType::JumpingFountain: - ImportEntity(src); + ImportEntity(gameState, src); break; case EntityType::Balloon: - ImportEntity(src); + ImportEntity(gameState, src); break; case EntityType::Duck: - ImportEntity(src); + ImportEntity(gameState, src); break; case EntityType::Litter: - ImportEntity(src); + ImportEntity(gameState, src); break; default: // Null elements do not need imported diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index b2a7eceb89..b510718b2d 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -351,7 +351,7 @@ namespace OpenRCT2::RCT2 DetermineFlatRideStatus(); ImportTileElements(gameState); - ImportEntities(); + ImportEntities(gameState); ConvertPeepAnimationTypeToObjects(gameState); auto& park = gameState.park; @@ -1645,11 +1645,11 @@ namespace OpenRCT2::RCT2 } } - void ImportEntities() + void ImportEntities(GameState_t& gameState) { for (int32_t i = 0; i < GetMaxEntities(); i++) { - ImportEntity(_s6.Entities[i].Unknown); + ImportEntity(gameState, _s6.Entities[i].Unknown); } } @@ -1659,7 +1659,7 @@ namespace OpenRCT2::RCT2 } template - void ImportEntity(const RCT12EntityBase& src); + void ImportEntity(GameState_t& gameState, const RCT12EntityBase& src); void ImportEntityPeep(::Peep* dst, const Peep* src) { @@ -1813,7 +1813,7 @@ namespace OpenRCT2::RCT2 dst->Orientation = src->EntityDirection; } - void ImportEntity(const RCT12EntityBase& src); + void ImportEntity(GameState_t& gameState, const RCT12EntityBase& src); std::string GetUserString(StringId stringId) { @@ -1944,9 +1944,9 @@ namespace OpenRCT2::RCT2 }; template<> - void S6Importer::ImportEntity<::Vehicle>(const RCT12EntityBase& baseSrc) + void S6Importer::ImportEntity<::Vehicle>(GameState_t& gameState, const RCT12EntityBase& baseSrc) { - auto dst = CreateEntityAt<::Vehicle>(EntityId::FromUnderlying(baseSrc.EntityIndex)); + auto dst = getGameState().entities.CreateEntityAt<::Vehicle>(EntityId::FromUnderlying(baseSrc.EntityIndex)); auto src = static_cast(&baseSrc); const auto& ride = _s6.Rides[src->Ride]; @@ -2070,9 +2070,9 @@ namespace OpenRCT2::RCT2 } template<> - void S6Importer::ImportEntity<::Guest>(const RCT12EntityBase& baseSrc) + void S6Importer::ImportEntity<::Guest>(GameState_t& gameState, const RCT12EntityBase& baseSrc) { - auto dst = CreateEntityAt<::Guest>(EntityId::FromUnderlying(baseSrc.EntityIndex)); + auto dst = getGameState().entities.CreateEntityAt<::Guest>(EntityId::FromUnderlying(baseSrc.EntityIndex)); auto src = static_cast(&baseSrc); ImportEntityPeep(dst, src); @@ -2145,9 +2145,9 @@ namespace OpenRCT2::RCT2 } template<> - void S6Importer::ImportEntity<::Staff>(const RCT12EntityBase& baseSrc) + void S6Importer::ImportEntity<::Staff>(GameState_t& gameState, const RCT12EntityBase& baseSrc) { - auto dst = CreateEntityAt<::Staff>(EntityId::FromUnderlying(baseSrc.EntityIndex)); + auto dst = getGameState().entities.CreateEntityAt<::Staff>(EntityId::FromUnderlying(baseSrc.EntityIndex)); auto src = static_cast(&baseSrc); ImportEntityPeep(dst, src); @@ -2166,9 +2166,9 @@ namespace OpenRCT2::RCT2 } template<> - void S6Importer::ImportEntity<::SteamParticle>(const RCT12EntityBase& baseSrc) + void S6Importer::ImportEntity<::SteamParticle>(GameState_t& gameState, const RCT12EntityBase& baseSrc) { - auto dst = CreateEntityAt<::SteamParticle>(EntityId::FromUnderlying(baseSrc.EntityIndex)); + auto dst = getGameState().entities.CreateEntityAt<::SteamParticle>(EntityId::FromUnderlying(baseSrc.EntityIndex)); auto src = static_cast(&baseSrc); ImportEntityCommonProperties(dst, src); dst->time_to_move = src->TimeToMove; @@ -2176,9 +2176,9 @@ namespace OpenRCT2::RCT2 } template<> - void S6Importer::ImportEntity<::MoneyEffect>(const RCT12EntityBase& baseSrc) + void S6Importer::ImportEntity<::MoneyEffect>(GameState_t& gameState, const RCT12EntityBase& baseSrc) { - auto dst = CreateEntityAt<::MoneyEffect>(EntityId::FromUnderlying(baseSrc.EntityIndex)); + auto dst = getGameState().entities.CreateEntityAt<::MoneyEffect>(EntityId::FromUnderlying(baseSrc.EntityIndex)); auto src = static_cast(&baseSrc); ImportEntityCommonProperties(dst, src); dst->MoveDelay = src->MoveDelay; @@ -2190,9 +2190,10 @@ namespace OpenRCT2::RCT2 } template<> - void S6Importer::ImportEntity<::VehicleCrashParticle>(const RCT12EntityBase& baseSrc) + void S6Importer::ImportEntity<::VehicleCrashParticle>(GameState_t& gameState, const RCT12EntityBase& baseSrc) { - auto dst = CreateEntityAt<::VehicleCrashParticle>(EntityId::FromUnderlying(baseSrc.EntityIndex)); + auto dst = getGameState().entities.CreateEntityAt<::VehicleCrashParticle>( + EntityId::FromUnderlying(baseSrc.EntityIndex)); auto src = static_cast(&baseSrc); ImportEntityCommonProperties(dst, src); dst->frame = src->Frame; @@ -2210,36 +2211,36 @@ namespace OpenRCT2::RCT2 } template<> - void S6Importer::ImportEntity<::ExplosionCloud>(const RCT12EntityBase& baseSrc) + void S6Importer::ImportEntity<::ExplosionCloud>(GameState_t& gameState, const RCT12EntityBase& baseSrc) { - auto dst = CreateEntityAt<::ExplosionCloud>(EntityId::FromUnderlying(baseSrc.EntityIndex)); + auto dst = getGameState().entities.CreateEntityAt<::ExplosionCloud>(EntityId::FromUnderlying(baseSrc.EntityIndex)); auto src = static_cast(&baseSrc); ImportEntityCommonProperties(dst, src); dst->frame = src->Frame; } template<> - void S6Importer::ImportEntity<::ExplosionFlare>(const RCT12EntityBase& baseSrc) + void S6Importer::ImportEntity<::ExplosionFlare>(GameState_t& gameState, const RCT12EntityBase& baseSrc) { - auto dst = CreateEntityAt<::ExplosionFlare>(EntityId::FromUnderlying(baseSrc.EntityIndex)); + auto dst = getGameState().entities.CreateEntityAt<::ExplosionFlare>(EntityId::FromUnderlying(baseSrc.EntityIndex)); auto src = static_cast(&baseSrc); ImportEntityCommonProperties(dst, src); dst->frame = src->Frame; } template<> - void S6Importer::ImportEntity<::CrashSplashParticle>(const RCT12EntityBase& baseSrc) + void S6Importer::ImportEntity<::CrashSplashParticle>(GameState_t& gameState, const RCT12EntityBase& baseSrc) { - auto dst = CreateEntityAt<::CrashSplashParticle>(EntityId::FromUnderlying(baseSrc.EntityIndex)); + auto dst = getGameState().entities.CreateEntityAt<::CrashSplashParticle>(EntityId::FromUnderlying(baseSrc.EntityIndex)); auto src = static_cast(&baseSrc); ImportEntityCommonProperties(dst, src); dst->frame = src->Frame; } template<> - void S6Importer::ImportEntity<::JumpingFountain>(const RCT12EntityBase& baseSrc) + void S6Importer::ImportEntity<::JumpingFountain>(GameState_t& gameState, const RCT12EntityBase& baseSrc) { - auto dst = CreateEntityAt<::JumpingFountain>(EntityId::FromUnderlying(baseSrc.EntityIndex)); + auto dst = getGameState().entities.CreateEntityAt<::JumpingFountain>(EntityId::FromUnderlying(baseSrc.EntityIndex)); auto src = static_cast(&baseSrc); ImportEntityCommonProperties(dst, src); dst->NumTicksAlive = src->NumTicksAlive; @@ -2254,9 +2255,9 @@ namespace OpenRCT2::RCT2 } template<> - void S6Importer::ImportEntity<::Balloon>(const RCT12EntityBase& baseSrc) + void S6Importer::ImportEntity<::Balloon>(GameState_t& gameState, const RCT12EntityBase& baseSrc) { - auto dst = CreateEntityAt<::Balloon>(EntityId::FromUnderlying(baseSrc.EntityIndex)); + auto dst = getGameState().entities.CreateEntityAt<::Balloon>(EntityId::FromUnderlying(baseSrc.EntityIndex)); auto src = static_cast(&baseSrc); ImportEntityCommonProperties(dst, src); dst->popped = src->Popped; @@ -2266,9 +2267,9 @@ namespace OpenRCT2::RCT2 } template<> - void S6Importer::ImportEntity<::Duck>(const RCT12EntityBase& baseSrc) + void S6Importer::ImportEntity<::Duck>(GameState_t& gameState, const RCT12EntityBase& baseSrc) { - auto dst = CreateEntityAt<::Duck>(EntityId::FromUnderlying(baseSrc.EntityIndex)); + auto dst = getGameState().entities.CreateEntityAt<::Duck>(EntityId::FromUnderlying(baseSrc.EntityIndex)); auto src = static_cast(&baseSrc); ImportEntityCommonProperties(dst, src); dst->frame = src->Frame; @@ -2278,57 +2279,57 @@ namespace OpenRCT2::RCT2 } template<> - void S6Importer::ImportEntity<::Litter>(const RCT12EntityBase& baseSrc) + void S6Importer::ImportEntity<::Litter>(GameState_t& gameState, const RCT12EntityBase& baseSrc) { - auto dst = CreateEntityAt<::Litter>(EntityId::FromUnderlying(baseSrc.EntityIndex)); + auto dst = getGameState().entities.CreateEntityAt<::Litter>(EntityId::FromUnderlying(baseSrc.EntityIndex)); auto src = static_cast(&baseSrc); ImportEntityCommonProperties(dst, src); dst->SubType = ::Litter::Type(src->Type); dst->creationTick = AdjustScenarioToCurrentTicks(_s6, src->CreationTick); } - void S6Importer::ImportEntity(const RCT12EntityBase& src) + void S6Importer::ImportEntity(GameState_t& gameState, const RCT12EntityBase& src) { switch (GetEntityTypeFromRCT2Sprite(&src)) { case EntityType::Vehicle: - ImportEntity<::Vehicle>(src); + ImportEntity<::Vehicle>(gameState, src); break; case EntityType::Guest: - ImportEntity<::Guest>(src); + ImportEntity<::Guest>(gameState, src); break; case EntityType::Staff: - ImportEntity<::Staff>(src); + ImportEntity<::Staff>(gameState, src); break; case EntityType::SteamParticle: - ImportEntity<::SteamParticle>(src); + ImportEntity<::SteamParticle>(gameState, src); break; case EntityType::MoneyEffect: - ImportEntity<::MoneyEffect>(src); + ImportEntity<::MoneyEffect>(gameState, src); break; case EntityType::CrashedVehicleParticle: - ImportEntity<::VehicleCrashParticle>(src); + ImportEntity<::VehicleCrashParticle>(gameState, src); break; case EntityType::ExplosionCloud: - ImportEntity<::ExplosionCloud>(src); + ImportEntity<::ExplosionCloud>(gameState, src); break; case EntityType::ExplosionFlare: - ImportEntity<::ExplosionFlare>(src); + ImportEntity<::ExplosionFlare>(gameState, src); break; case EntityType::CrashSplash: - ImportEntity<::CrashSplashParticle>(src); + ImportEntity<::CrashSplashParticle>(gameState, src); break; case EntityType::JumpingFountain: - ImportEntity<::JumpingFountain>(src); + ImportEntity<::JumpingFountain>(gameState, src); break; case EntityType::Balloon: - ImportEntity<::Balloon>(src); + ImportEntity<::Balloon>(gameState, src); break; case EntityType::Duck: - ImportEntity<::Duck>(src); + ImportEntity<::Duck>(gameState, src); break; case EntityType::Litter: - ImportEntity<::Litter>(src); + ImportEntity<::Litter>(gameState, src); break; default: // Null elements do not need imported diff --git a/src/openrct2/ride/CableLift.cpp b/src/openrct2/ride/CableLift.cpp index ad977d4d81..9813326bab 100644 --- a/src/openrct2/ride/CableLift.cpp +++ b/src/openrct2/ride/CableLift.cpp @@ -27,7 +27,7 @@ using namespace OpenRCT2; Vehicle* CableLiftSegmentCreate( Ride& ride, int32_t x, int32_t y, int32_t z, int32_t direction, uint16_t var_44, int32_t remaining_distance, bool head) { - Vehicle* current = CreateEntity(); + Vehicle* current = getGameState().entities.CreateEntity(); current->ride = ride.id; current->ride_subtype = kObjectEntryIndexNull; if (head) @@ -158,8 +158,8 @@ void Vehicle::CableLiftUpdateWaitingToDepart() // Next check to see if the second part of the cable lift // is at the front of the passenger vehicle to simulate the // cable being attached underneath the train. - Vehicle* passengerVehicle = GetEntity(cable_lift_target); - Vehicle* cableLiftSecondPart = GetEntity(prev_vehicle_on_ride); + Vehicle* passengerVehicle = getGameState().entities.GetEntity(cable_lift_target); + Vehicle* cableLiftSecondPart = getGameState().entities.GetEntity(prev_vehicle_on_ride); if (passengerVehicle == nullptr || cableLiftSecondPart == nullptr) { return; @@ -186,7 +186,7 @@ void Vehicle::CableLiftUpdateDeparting() if (sub_state < 16) return; - Vehicle* passengerVehicle = GetEntity(cable_lift_target); + Vehicle* passengerVehicle = getGameState().entities.GetEntity(cable_lift_target); if (passengerVehicle == nullptr) { return; @@ -201,7 +201,7 @@ void Vehicle::CableLiftUpdateDeparting() */ void Vehicle::CableLiftUpdateTravelling() { - Vehicle* passengerVehicle = GetEntity(cable_lift_target); + Vehicle* passengerVehicle = getGameState().entities.GetEntity(cable_lift_target); if (passengerVehicle == nullptr) { return; @@ -436,13 +436,13 @@ int32_t Vehicle::CableLiftUpdateTrackMotion() vehicle->acceleration /= _vehicleUnkF64E10; if (_vehicleVelocityF64E08 >= 0) { - vehicle = GetEntity(vehicle->next_vehicle_on_train); + vehicle = getGameState().entities.GetEntity(vehicle->next_vehicle_on_train); } else { if (vehicle == this) break; - vehicle = GetEntity(vehicle->prev_vehicle_on_ride); + vehicle = getGameState().entities.GetEntity(vehicle->prev_vehicle_on_ride); } } @@ -450,8 +450,8 @@ int32_t Vehicle::CableLiftUpdateTrackMotion() uint16_t massTotal = 0; int32_t accelerationTotal = 0; - for (Vehicle* vehicle = GetEntity(Id); vehicle != nullptr; - vehicle = GetEntity(vehicle->next_vehicle_on_train)) + for (Vehicle* vehicle = getGameState().entities.GetEntity(Id); vehicle != nullptr; + vehicle = getGameState().entities.GetEntity(vehicle->next_vehicle_on_train)) { vehicleCount++; diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 75d8231296..1ba62fa0a6 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -319,7 +319,7 @@ Guest* Ride::getQueueHeadGuest(StationIndex stationIndex) const Guest* peep; Guest* result = nullptr; auto spriteIndex = getStation(stationIndex).LastPeepInQueue; - while ((peep = TryGetEntity(spriteIndex)) != nullptr) + while ((peep = getGameState().entities.TryGetEntity(spriteIndex)) != nullptr) { spriteIndex = peep->GuestNextInQueue; result = peep; @@ -333,7 +333,7 @@ void Ride::updateQueueLength(StationIndex stationIndex) Guest* peep; auto& station = getStation(stationIndex); auto spriteIndex = station.LastPeepInQueue; - while ((peep = TryGetEntity(spriteIndex)) != nullptr) + while ((peep = getGameState().entities.TryGetEntity(spriteIndex)) != nullptr) { spriteIndex = peep->GuestNextInQueue; count++; @@ -841,7 +841,7 @@ void Ride::formatStatusTo(Formatter& ft) const } else if (mode == RideMode::race && !(lifecycleFlags & RIDE_LIFECYCLE_PASS_STATION_NO_STOPPING) && !raceWinner.IsNull()) { - auto peep = GetEntity(raceWinner); + auto peep = getGameState().entities.GetEntity(raceWinner); if (peep != nullptr) { ft.Add(STR_RACE_WON_BY); @@ -1250,7 +1250,7 @@ void updateSpiralSlide(Ride& ride) { ride.slideInUse--; - auto* peep = GetEntity(ride.slidePeep); + auto* peep = getGameState().entities.GetEntity(ride.slidePeep); if (peep != nullptr) { auto destination = peep->GetDestination(); @@ -1556,7 +1556,7 @@ void RidePrepareBreakdown(Ride& ride, int32_t breakdownReason) ride.brokenCar = ScenarioRand() % ride.numCarsPerTrain; // Set flag on broken car - vehicle = GetEntity(ride.vehicles[ride.brokenTrain]); + vehicle = getGameState().entities.GetEntity(ride.vehicles[ride.brokenTrain]); if (vehicle != nullptr) { vehicle = vehicle->GetCar(ride.brokenCar); @@ -1573,7 +1573,7 @@ void RidePrepareBreakdown(Ride& ride, int32_t breakdownReason) ride.brokenCar = 0; // Set flag on broken train, first car - vehicle = GetEntity(ride.vehicles[ride.brokenTrain]); + vehicle = getGameState().entities.GetEntity(ride.vehicles[ride.brokenTrain]); if (vehicle != nullptr) { vehicle->SetFlag(VehicleFlags::TrainIsBroken); @@ -1820,7 +1820,7 @@ Staff* FindClosestMechanic(const CoordsXY& entrancePosition, int32_t forInspecti Staff* RideGetMechanic(const Ride& ride) { - auto staff = GetEntity(ride.mechanic); + auto staff = getGameState().entities.GetEntity(ride.mechanic); if (staff != nullptr && staff->IsMechanic()) { return staff; @@ -1906,7 +1906,7 @@ static bool RideMusicBreakdownEffect(Ride& ride) */ void CircusMusicUpdate(Ride& ride) { - Vehicle* vehicle = GetEntity(ride.vehicles[0]); + Vehicle* vehicle = getGameState().entities.GetEntity(ride.vehicles[0]); if (vehicle == nullptr || vehicle->status != Vehicle::Status::DoingCircusShow) { ride.musicPosition = 0; @@ -1986,7 +1986,7 @@ static void RideMeasurementUpdate(Ride& ride, RideMeasurement& measurement) if (measurement.vehicle_index >= std::size(ride.vehicles)) return; - auto vehicle = GetEntity(ride.vehicles[measurement.vehicle_index]); + auto vehicle = getGameState().entities.GetEntity(ride.vehicles[measurement.vehicle_index]); if (vehicle == nullptr) return; @@ -2081,7 +2081,7 @@ void RideMeasurementsUpdate() for (int32_t j = 0; j < ride.numTrains; j++) { auto vehicleSpriteIdx = ride.vehicles[j]; - auto vehicle = GetEntity(vehicleSpriteIdx); + auto vehicle = getGameState().entities.GetEntity(vehicleSpriteIdx); if (vehicle != nullptr) { if (vehicle->status == Vehicle::Status::Departing @@ -3178,8 +3178,9 @@ static void RideSetStartFinishPoints(RideId rideIndex, const CoordsXYE& startEle */ static int32_t count_free_misc_sprite_slots() { - int32_t miscSpriteCount = GetMiscEntityCount(); - int32_t remainingSpriteCount = GetNumFreeEntities(); + auto& gameState = getGameState(); + int32_t miscSpriteCount = gameState.entities.GetMiscEntityCount(); + int32_t remainingSpriteCount = gameState.entities.GetNumFreeEntities(); return std::max(0, miscSpriteCount + remainingSpriteCount - 300); } @@ -3221,7 +3222,7 @@ static Vehicle* VehicleCreateCar( auto& carEntry = rideEntry->Cars[carEntryIndex]; - auto* vehicle = CreateEntity(); + auto* vehicle = getGameState().entities.CreateEntity(); if (vehicle == nullptr) return nullptr; @@ -3506,7 +3507,7 @@ static bool VehicleCreateTrains(Ride& ride, const CoordsXYZ& trainsPos, TrackEle */ static void RidecreateVehiclesFindFirstBlock(const Ride& ride, CoordsXYE* outXYElement) { - Vehicle* vehicle = GetEntity(ride.vehicles[0]); + Vehicle* vehicle = getGameState().entities.GetEntity(ride.vehicles[0]); if (vehicle == nullptr) return; @@ -3646,7 +3647,7 @@ ResultWithMessage Ride::createVehicles(const CoordsXYE& element, bool isApplying { for (int32_t i = 0; i < numTrains; i++) { - Vehicle* vehicle = GetEntity(vehicles[i]); + Vehicle* vehicle = getGameState().entities.GetEntity(vehicles[i]); if (vehicle == nullptr) { continue; @@ -3690,7 +3691,7 @@ void Ride::moveTrainsToBlockBrakes(const CoordsXYZ& firstBlockPosition, TrackEle for (int32_t i = 0; i < numTrains; i++) { - auto train = GetEntity(vehicles[i]); + auto train = getGameState().entities.GetEntity(vehicles[i]); if (train == nullptr) continue; @@ -3726,7 +3727,8 @@ void Ride::moveTrainsToBlockBrakes(const CoordsXYZ& firstBlockPosition, TrackEle cableLiftPreviousBlock->SetBrakeClosed(cableLiftTileElement->IsBrakeClosed()); } firstBlock.SetBrakeClosed(true); - for (Vehicle* car = train; car != nullptr; car = GetEntity(car->next_vehicle_on_train)) + for (Vehicle* car = train; car != nullptr; + car = getGameState().entities.GetEntity(car->next_vehicle_on_train)) { car->velocity = 0; car->acceleration = 0; @@ -3742,7 +3744,7 @@ void Ride::moveTrainsToBlockBrakes(const CoordsXYZ& firstBlockPosition, TrackEle { BlockBrakeSetLinkedBrakesClosed(firstBlockPosition, firstBlock, true); } - for (Vehicle* car = train; car != nullptr; car = GetEntity(car->next_vehicle_on_train)) + for (Vehicle* car = train; car != nullptr; car = getGameState().entities.GetEntity(car->next_vehicle_on_train)) { car->ClearFlag(VehicleFlags::CollisionDisabled); car->SetState(Vehicle::Status::Travelling, car->sub_state); @@ -4638,7 +4640,7 @@ void InvalidateTestResults(Ride& ride) { for (int32_t i = 0; i < ride.numTrains; i++) { - Vehicle* vehicle = GetEntity(ride.vehicles[i]); + Vehicle* vehicle = getGameState().entities.GetEntity(ride.vehicles[i]); if (vehicle != nullptr) { vehicle->ClearFlag(VehicleFlags::Testing); @@ -4668,8 +4670,8 @@ void RideFixBreakdown(Ride& ride, int32_t reliabilityIncreaseFactor) { for (int32_t i = 0; i < ride.numTrains; i++) { - for (Vehicle* vehicle = GetEntity(ride.vehicles[i]); vehicle != nullptr; - vehicle = GetEntity(vehicle->next_vehicle_on_train)) + for (Vehicle* vehicle = getGameState().entities.GetEntity(ride.vehicles[i]); vehicle != nullptr; + vehicle = getGameState().entities.GetEntity(vehicle->next_vehicle_on_train)) { vehicle->ClearFlag(VehicleFlags::StoppedOnLift); vehicle->ClearFlag(VehicleFlags::CarIsBroken); @@ -4698,8 +4700,8 @@ void RideUpdateVehicleColours(const Ride& ride) int32_t carIndex = 0; VehicleColour colours = {}; - for (Vehicle* vehicle = GetEntity(ride.vehicles[i]); vehicle != nullptr; - vehicle = GetEntity(vehicle->next_vehicle_on_train)) + for (Vehicle* vehicle = getGameState().entities.GetEntity(ride.vehicles[i]); vehicle != nullptr; + vehicle = getGameState().entities.GetEntity(vehicle->next_vehicle_on_train)) { switch (ride.vehicleColourSettings) { @@ -5265,7 +5267,7 @@ void Ride::setToDefaultInspectionInterval() */ void Ride::crash(uint8_t vehicleIndex) { - Vehicle* vehicle = GetEntity(vehicles[vehicleIndex]); + Vehicle* vehicle = getGameState().entities.GetEntity(vehicles[vehicleIndex]); if (gLegacyScene != LegacyScene::titleSequence && vehicle != nullptr) { @@ -5311,7 +5313,7 @@ uint32_t RideCustomersInLast5Minutes(const Ride& ride) Vehicle* RideGetBrokenVehicle(const Ride& ride) { auto vehicleIndex = ride.vehicles[ride.brokenTrain]; - Vehicle* vehicle = GetEntity(vehicleIndex); + Vehicle* vehicle = getGameState().entities.GetEntity(vehicleIndex); if (vehicle != nullptr) { return vehicle->GetCar(ride.brokenCar); @@ -5481,8 +5483,8 @@ void FixInvalidVehicleSpriteSizes() { for (auto entityIndex : ride.vehicles) { - for (Vehicle* vehicle = TryGetEntity(entityIndex); vehicle != nullptr; - vehicle = TryGetEntity(vehicle->next_vehicle_on_train)) + for (Vehicle* vehicle = getGameState().entities.TryGetEntity(entityIndex); vehicle != nullptr; + vehicle = getGameState().entities.TryGetEntity(vehicle->next_vehicle_on_train)) { auto carEntry = vehicle->Entry(); if (carEntry == nullptr) diff --git a/src/openrct2/ride/RideConstruction.cpp b/src/openrct2/ride/RideConstruction.cpp index 94c8d32e4e..2828b4ac5f 100644 --- a/src/openrct2/ride/RideConstruction.cpp +++ b/src/openrct2/ride/RideConstruction.cpp @@ -157,14 +157,14 @@ static void ride_remove_cable_lift(Ride& ride) auto spriteIndex = ride.cableLift; do { - Vehicle* vehicle = GetEntity(spriteIndex); + Vehicle* vehicle = getGameState().entities.GetEntity(spriteIndex); if (vehicle == nullptr) { return; } vehicle->Invalidate(); spriteIndex = vehicle->next_vehicle_on_train; - EntityRemove(vehicle); + getGameState().entities.EntityRemove(vehicle); } while (!spriteIndex.IsNull()); } } @@ -185,14 +185,14 @@ void Ride::removeVehicles() auto spriteIndex = vehicles[i]; while (!spriteIndex.IsNull()) { - Vehicle* vehicle = GetEntity(spriteIndex); + Vehicle* vehicle = getGameState().entities.GetEntity(spriteIndex); if (vehicle == nullptr) { break; } vehicle->Invalidate(); spriteIndex = vehicle->next_vehicle_on_train; - EntityRemove(vehicle); + getGameState().entities.EntityRemove(vehicle); } vehicles[i] = EntityId::GetNull(); @@ -207,7 +207,7 @@ void Ride::removeVehicles() if (vehicle->ride == id) { vehicle->Invalidate(); - EntityRemove(vehicle); + getGameState().entities.EntityRemove(vehicle); } } } diff --git a/src/openrct2/ride/Station.cpp b/src/openrct2/ride/Station.cpp index 782c8b4723..512ca6a13b 100644 --- a/src/openrct2/ride/Station.cpp +++ b/src/openrct2/ride/Station.cpp @@ -110,7 +110,7 @@ static void RideUpdateStationDodgems(Ride& ride, StationIndex stationIndex) int32_t dh = (dx >> 8) & 0xFF; for (size_t i = 0; i < ride.numTrains; i++) { - Vehicle* vehicle = GetEntity(ride.vehicles[i]); + Vehicle* vehicle = getGameState().entities.GetEntity(ride.vehicles[i]); if (vehicle == nullptr) continue; @@ -131,7 +131,7 @@ static void RideUpdateStationDodgems(Ride& ride, StationIndex stationIndex) // Check if all vehicles are ready to go for (size_t i = 0; i < ride.numTrains; i++) { - Vehicle* vehicle = GetEntity(ride.vehicles[i]); + Vehicle* vehicle = getGameState().entities.GetEntity(ride.vehicles[i]); if (vehicle == nullptr) continue; @@ -208,7 +208,7 @@ static void RideUpdateStationRace(Ride& ride, StationIndex stationIndex) for (size_t i = 0; i < ride.numTrains; i++) { - Vehicle* vehicle = GetEntity(ride.vehicles[i]); + Vehicle* vehicle = getGameState().entities.GetEntity(ride.vehicles[i]); if (vehicle == nullptr) continue; @@ -217,7 +217,7 @@ static void RideUpdateStationRace(Ride& ride, StationIndex stationIndex) // Found a winner if (vehicle->num_peeps != 0) { - auto* peep = GetEntity(vehicle->peep[0]); + auto* peep = getGameState().entities.GetEntity(vehicle->peep[0]); if (peep != nullptr) { ride.raceWinner = peep->Id; @@ -244,7 +244,7 @@ static void RideUpdateStationRace(Ride& ride, StationIndex stationIndex) // Check if all vehicles are ready to go for (size_t i = 0; i < ride.numTrains; i++) { - Vehicle* vehicle = GetEntity(ride.vehicles[i]); + Vehicle* vehicle = getGameState().entities.GetEntity(ride.vehicles[i]); if (vehicle == nullptr) continue; @@ -281,7 +281,7 @@ static void RideRaceInitVehicleSpeeds(const Ride& ride) { for (size_t i = 0; i < ride.numTrains; i++) { - Vehicle* vehicle = GetEntity(ride.vehicles[i]); + Vehicle* vehicle = getGameState().entities.GetEntity(ride.vehicles[i]); if (vehicle == nullptr) continue; @@ -293,7 +293,7 @@ static void RideRaceInitVehicleSpeeds(const Ride& ride) if (vehicle->num_peeps != 0) { - auto* guest = GetEntity(vehicle->peep[0]); + auto* guest = getGameState().entities.GetEntity(vehicle->peep[0]); // Easter egg names should only work on guests if (guest != nullptr) diff --git a/src/openrct2/ride/TrainManager.cpp b/src/openrct2/ride/TrainManager.cpp index ea4d04af3a..00a5773fff 100644 --- a/src/openrct2/ride/TrainManager.cpp +++ b/src/openrct2/ride/TrainManager.cpp @@ -21,7 +21,7 @@ namespace OpenRCT2::TrainManager while (iter != end && Entity == nullptr) { - Entity = GetEntity(*iter++); + Entity = getGameState().entities.GetEntity(*iter++); if (Entity != nullptr && !Entity->IsHead()) { Entity = nullptr; @@ -32,6 +32,6 @@ namespace OpenRCT2::TrainManager View::View() { - vec = &GetEntityList(EntityType::Vehicle); + vec = &getGameState().entities.GetEntityList(EntityType::Vehicle); } } // namespace OpenRCT2::TrainManager diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index f7758929ca..0075fda41b 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -606,7 +606,7 @@ void Vehicle::UpdateTrackChange() Vehicle* TryGetVehicle(EntityId spriteIndex) { - return TryGetEntity(spriteIndex); + return getGameState().entities.TryGetEntity(spriteIndex); } void VehicleSoundsUpdate() @@ -647,8 +647,8 @@ bool Vehicle::CloseRestraints() return true; bool restraintsClosed = true; - for (Vehicle* vehicle = GetEntity(Id); vehicle != nullptr; - vehicle = GetEntity(vehicle->next_vehicle_on_train)) + for (Vehicle* vehicle = getGameState().entities.GetEntity(Id); vehicle != nullptr; + vehicle = getGameState().entities.GetEntity(vehicle->next_vehicle_on_train)) { if (vehicle->HasFlag(VehicleFlags::CarIsBroken) && vehicle->restraints_position != 0 && (curRide->breakdownReasonPending == BREAKDOWN_RESTRAINTS_STUCK_OPEN @@ -665,7 +665,7 @@ bool Vehicle::CloseRestraints() curRide->mechanicStatus = RIDE_MECHANIC_STATUS_CALLING; - Vehicle* broken_vehicle = GetEntity(curRide->vehicles[curRide->brokenTrain]); + Vehicle* broken_vehicle = getGameState().entities.GetEntity(curRide->vehicles[curRide->brokenTrain]); if (broken_vehicle != nullptr) { curRide->inspectionStation = broken_vehicle->current_station; @@ -696,8 +696,8 @@ bool Vehicle::CloseRestraints() bool Vehicle::OpenRestraints() { int32_t restraintsOpen = true; - for (Vehicle* vehicle = GetEntity(Id); vehicle != nullptr; - vehicle = GetEntity(vehicle->next_vehicle_on_train)) + for (Vehicle* vehicle = getGameState().entities.GetEntity(Id); vehicle != nullptr; + vehicle = getGameState().entities.GetEntity(vehicle->next_vehicle_on_train)) { vehicle->SwingPosition = 0; vehicle->SwingSpeed = 0; @@ -781,7 +781,7 @@ bool Vehicle::OpenRestraints() curRide->mechanicStatus = RIDE_MECHANIC_STATUS_CALLING; - Vehicle* broken_vehicle = GetEntity(curRide->vehicles[curRide->brokenTrain]); + Vehicle* broken_vehicle = getGameState().entities.GetEntity(curRide->vehicles[curRide->brokenTrain]); if (broken_vehicle != nullptr) { curRide->inspectionStation = broken_vehicle->current_station; @@ -1596,8 +1596,8 @@ void Vehicle::UpdateWaitingForPassengers() // 0xF64E31, 0xF64E32, 0xF64E33 uint8_t num_peeps_on_train = 0, num_used_seats_on_train = 0, num_seats_on_train = 0; - for (const Vehicle* trainCar = GetEntity(Id); trainCar != nullptr; - trainCar = GetEntity(trainCar->next_vehicle_on_train)) + for (const Vehicle* trainCar = getGameState().entities.GetEntity(Id); trainCar != nullptr; + trainCar = getGameState().entities.GetEntity(trainCar->next_vehicle_on_train)) { num_peeps_on_train += trainCar->num_peeps; num_used_seats_on_train += trainCar->next_free_seat; @@ -1651,7 +1651,7 @@ void Vehicle::UpdateWaitingForPassengers() if (train_id == Id) continue; - Vehicle* train = GetEntity(train_id); + Vehicle* train = getGameState().entities.GetEntity(train_id); if (train == nullptr) continue; @@ -1810,8 +1810,8 @@ void Vehicle::UpdateWaitingToDepart() } else { - for (const Vehicle* trainCar = GetEntity(Id); trainCar != nullptr; - trainCar = GetEntity(trainCar->next_vehicle_on_train)) + for (const Vehicle* trainCar = getGameState().entities.GetEntity(Id); trainCar != nullptr; + trainCar = getGameState().entities.GetEntity(trainCar->next_vehicle_on_train)) { if (trainCar->num_peeps != 0) { @@ -2056,7 +2056,7 @@ static bool try_add_synchronised_station(const CoordsXYZ& coords) // Look for a vehicle on this station waiting to depart. for (int32_t i = 0; i < ride->numTrains; i++) { - auto* vehicle = GetEntity(ride->vehicles[i]); + auto* vehicle = getGameState().entities.GetEntity(ride->vehicles[i]); if (vehicle == nullptr) { continue; @@ -2194,7 +2194,7 @@ static bool ride_station_can_depart_synchronised(const Ride& ride, StationIndex { for (int32_t i = 0; i < curRide->numTrains; i++) { - Vehicle* v = GetEntity(curRide->vehicles[i]); + Vehicle* v = getGameState().entities.GetEntity(curRide->vehicles[i]); if (v == nullptr) { continue; @@ -2232,7 +2232,7 @@ static bool ride_station_can_depart_synchronised(const Ride& ride, StationIndex auto currentStation = sv->stationIndex; for (int32_t i = 0; i < sv_ride->numTrains; i++) { - auto* otherVehicle = GetEntity(sv_ride->vehicles[i]); + auto* otherVehicle = getGameState().entities.GetEntity(sv_ride->vehicles[i]); if (otherVehicle == nullptr) { continue; @@ -2277,7 +2277,7 @@ static bool ride_station_can_depart_synchronised(const Ride& ride, StationIndex // At this point all vehicles in _snychronisedVehicles can depart. for (SynchronisedVehicle* sv = _synchronisedVehicles; sv < _lastSynchronisedVehicle; sv++) { - auto v = GetEntity(sv->vehicle_id); + auto v = getGameState().entities.GetEntity(sv->vehicle_id); if (v != nullptr) { v->ClearFlag(VehicleFlags::WaitingOnAdjacentStation); @@ -2301,12 +2301,12 @@ bool Vehicle::CanDepartSynchronised() const */ void Vehicle::PeepEasterEggHereWeAre() const { - for (Vehicle* vehicle = GetEntity(Id); vehicle != nullptr; - vehicle = GetEntity(vehicle->next_vehicle_on_train)) + for (Vehicle* vehicle = getGameState().entities.GetEntity(Id); vehicle != nullptr; + vehicle = getGameState().entities.GetEntity(vehicle->next_vehicle_on_train)) { for (int32_t i = 0; i < vehicle->num_peeps; ++i) { - auto* curPeep = GetEntity(vehicle->peep[i]); + auto* curPeep = getGameState().entities.GetEntity(vehicle->peep[i]); if (curPeep != nullptr && curPeep->PeepFlags & PEEP_FLAGS_HERE_WE_ARE) { curPeep->InsertNewThought(PeepThoughtType::HereWeAre, curPeep->CurrentRide); @@ -2875,7 +2875,8 @@ void Vehicle::UpdateCollisionSetup() KillAllPassengersInTrain(); Vehicle* lastVehicle = this; - for (Vehicle* train = GetEntity(Id); train != nullptr; train = GetEntity(train->next_vehicle_on_train)) + for (Vehicle* train = getGameState().entities.GetEntity(Id); train != nullptr; + train = getGameState().entities.GetEntity(train->next_vehicle_on_train)) { lastVehicle = train; @@ -2909,8 +2910,8 @@ void Vehicle::UpdateCollisionSetup() } // Remove the current train from the ride linked list of trains - auto prevTrain = GetEntity(prev_vehicle_on_ride); - auto nextTrain = GetEntity(lastVehicle->next_vehicle_on_ride); + auto prevTrain = getGameState().entities.GetEntity(prev_vehicle_on_ride); + auto nextTrain = getGameState().entities.GetEntity(lastVehicle->next_vehicle_on_ride); if (prevTrain == nullptr || nextTrain == nullptr) { LOG_ERROR("Corrupted vehicle list for ride!"); @@ -2955,7 +2956,7 @@ void Vehicle::UpdateCrashSetup() auto spriteId = Id; for (Vehicle* trainVehicle; !spriteId.IsNull(); spriteId = trainVehicle->next_vehicle_on_train) { - trainVehicle = GetEntity(spriteId); + trainVehicle = getGameState().entities.GetEntity(spriteId); if (trainVehicle == nullptr) { break; @@ -2990,8 +2991,8 @@ void Vehicle::UpdateCrashSetup() } // Remove the current train from the ride linked list of trains - auto prevTrain = GetEntity(prev_vehicle_on_ride); - auto nextTrain = GetEntity(lastVehicle->next_vehicle_on_ride); + auto prevTrain = getGameState().entities.GetEntity(prev_vehicle_on_ride); + auto nextTrain = getGameState().entities.GetEntity(lastVehicle->next_vehicle_on_ride); if (prevTrain == nullptr || nextTrain == nullptr) { LOG_ERROR("Corrupted vehicle list for ride!"); @@ -3429,7 +3430,7 @@ void Vehicle::UpdateUnloadingPassengers() { next_free_seat -= 2; - auto firstGuest = GetEntity(peep[seat * 2]); + auto firstGuest = getGameState().entities.GetEntity(peep[seat * 2]); peep[seat * 2] = EntityId::GetNull(); if (firstGuest != nullptr) @@ -3438,7 +3439,7 @@ void Vehicle::UpdateUnloadingPassengers() firstGuest->RideSubState = PeepRideSubState::LeaveVehicle; } - auto secondGuest = GetEntity(peep[seat * 2 + 1]); + auto secondGuest = getGameState().entities.GetEntity(peep[seat * 2 + 1]); peep[seat * 2 + 1] = EntityId::GetNull(); if (secondGuest != nullptr) @@ -3464,8 +3465,8 @@ void Vehicle::UpdateUnloadingPassengers() return; } - for (Vehicle* train = GetEntity(Id); train != nullptr; - train = GetEntity(train->next_vehicle_on_train)) + for (Vehicle* train = getGameState().entities.GetEntity(Id); train != nullptr; + train = getGameState().entities.GetEntity(train->next_vehicle_on_train)) { if (train->restraints_position != 255) continue; @@ -3476,7 +3477,7 @@ void Vehicle::UpdateUnloadingPassengers() train->next_free_seat = 0; for (uint8_t peepIndex = 0; peepIndex < train->num_peeps; peepIndex++) { - Peep* curPeep = GetEntity(train->peep[peepIndex]); + Peep* curPeep = getGameState().entities.GetEntity(train->peep[peepIndex]); if (curPeep != nullptr) { curPeep->SetState(PeepState::LeavingRide); @@ -3489,7 +3490,8 @@ void Vehicle::UpdateUnloadingPassengers() if (sub_state != 1) return; - for (Vehicle* train = GetEntity(Id); train != nullptr; train = GetEntity(train->next_vehicle_on_train)) + for (Vehicle* train = getGameState().entities.GetEntity(Id); train != nullptr; + train = getGameState().entities.GetEntity(train->next_vehicle_on_train)) { if (train->num_peeps != train->next_free_seat) return; @@ -3513,7 +3515,7 @@ void Vehicle::UpdateWaitingForCableLift() if (curRide == nullptr) return; - Vehicle* cableLift = GetEntity(curRide->cableLift); + Vehicle* cableLift = getGameState().entities.GetEntity(curRide->cableLift); if (cableLift == nullptr) return; @@ -4592,8 +4594,8 @@ void Vehicle::KillAllPassengersInTrain() ride_train_crash(*curRide, NumPeepsUntilTrainTail()); - for (Vehicle* trainCar = GetEntity(Id); trainCar != nullptr; - trainCar = GetEntity(trainCar->next_vehicle_on_train)) + for (Vehicle* trainCar = getGameState().entities.GetEntity(Id); trainCar != nullptr; + trainCar = getGameState().entities.GetEntity(trainCar->next_vehicle_on_train)) { trainCar->KillPassengers(*curRide); } @@ -4609,7 +4611,7 @@ void Vehicle::KillPassengers(const Ride& curRide) for (auto i = 0; i < num_peeps; i++) { - auto* curPeep = GetEntity(peep[i]); + auto* curPeep = getGameState().entities.GetEntity(peep[i]); if (curPeep == nullptr) continue; @@ -4769,8 +4771,8 @@ void Vehicle::CrashOnWater() */ void Vehicle::UpdateCrash() { - for (Vehicle* curVehicle = GetEntity(Id); curVehicle != nullptr; - curVehicle = GetEntity(curVehicle->next_vehicle_on_train)) + for (Vehicle* curVehicle = getGameState().entities.GetEntity(Id); curVehicle != nullptr; + curVehicle = getGameState().entities.GetEntity(curVehicle->next_vehicle_on_train)) { CoordsXYZ curPos = curVehicle->GetLocation(); @@ -4982,8 +4984,8 @@ OpenRCT2::Audio::SoundId Vehicle::UpdateScreamSound() if (velocity > -2.75_mph) return OpenRCT2::Audio::SoundId::Null; - for (Vehicle* vehicle2 = GetEntity(Id); vehicle2 != nullptr; - vehicle2 = GetEntity(vehicle2->next_vehicle_on_train)) + for (Vehicle* vehicle2 = getGameState().entities.GetEntity(Id); vehicle2 != nullptr; + vehicle2 = getGameState().entities.GetEntity(vehicle2->next_vehicle_on_train)) { if (vehicle2->Pitch < 1) continue; @@ -5004,8 +5006,8 @@ OpenRCT2::Audio::SoundId Vehicle::UpdateScreamSound() if (velocity < 2.75_mph) return OpenRCT2::Audio::SoundId::Null; - for (Vehicle* vehicle2 = GetEntity(Id); vehicle2 != nullptr; - vehicle2 = GetEntity(vehicle2->next_vehicle_on_train)) + for (Vehicle* vehicle2 = getGameState().entities.GetEntity(Id); vehicle2 != nullptr; + vehicle2 = getGameState().entities.GetEntity(vehicle2->next_vehicle_on_train)) { if (vehicle2->Pitch < 5) continue; @@ -5127,7 +5129,7 @@ Vehicle* Vehicle::TrainHead() const for (;;) { - prevVehicle = GetEntity(vehicle->prev_vehicle_on_ride); + prevVehicle = getGameState().entities.GetEntity(vehicle->prev_vehicle_on_ride); if (prevVehicle == nullptr) return nullptr; if (prevVehicle->next_vehicle_on_train.IsNull()) @@ -5146,7 +5148,7 @@ Vehicle* Vehicle::TrainTail() const EntityId spriteIndex = vehicle->next_vehicle_on_train; while (!spriteIndex.IsNull()) { - vehicle = GetEntity(spriteIndex); + vehicle = getGameState().entities.GetEntity(spriteIndex); if (vehicle == nullptr) { return const_cast(this); @@ -5276,7 +5278,7 @@ int32_t Vehicle::UpdateMotionDodgems() velocity = 0; uint8_t direction = Orientation | 1; - Vehicle* collideVehicle = GetEntity(collideSprite.value()); + Vehicle* collideVehicle = getGameState().entities.GetEntity(collideSprite.value()); if (collideVehicle != nullptr) { var_34 = (ScenarioRand() & 1) ? 1 : -1; @@ -6507,11 +6509,11 @@ void Vehicle::UpdateHandleWaterSplash() const { if (IsOnCoveredTrack()) { - Vehicle* nextVehicle = GetEntity(next_vehicle_on_ride); + Vehicle* nextVehicle = getGameState().entities.GetEntity(next_vehicle_on_ride); if (nextVehicle == nullptr) return; - Vehicle* nextNextVehicle = GetEntity(nextVehicle->next_vehicle_on_ride); + Vehicle* nextNextVehicle = getGameState().entities.GetEntity(nextVehicle->next_vehicle_on_ride); if (nextNextVehicle == nullptr) return; if (!nextNextVehicle->IsOnCoveredTrack()) @@ -6590,7 +6592,7 @@ bool Vehicle::UpdateMotionCollisionDetection(const CoordsXYZ& loc, EntityId* oth if (otherVehicleIndex == nullptr) return false; - Vehicle* collideVehicle = GetEntity(*otherVehicleIndex); + Vehicle* collideVehicle = getGameState().entities.GetEntity(*otherVehicleIndex); if (collideVehicle == nullptr) return false; @@ -6781,8 +6783,8 @@ bool Vehicle::UpdateMotionCollisionDetection(const CoordsXYZ& loc, EntityId* oth */ void Vehicle::ReverseReverserCar() { - Vehicle* previousVehicle = GetEntity(prev_vehicle_on_ride); - Vehicle* nextVehicle = GetEntity(next_vehicle_on_ride); + Vehicle* previousVehicle = getGameState().entities.GetEntity(prev_vehicle_on_ride); + Vehicle* nextVehicle = getGameState().entities.GetEntity(next_vehicle_on_ride); if (previousVehicle == nullptr || nextVehicle == nullptr) { return; @@ -7338,7 +7340,7 @@ bool Vehicle::UpdateTrackMotionForwards(const CarEntry* carEntry, const Ride& cu remaining_distance = -1; // Might need to be bp rather than this, but hopefully not - auto otherVeh = GetEntity(otherVehicleIndex); + auto otherVeh = getGameState().entities.GetEntity(otherVehicleIndex); if (otherVeh == nullptr) { // This can never happen as prev_vehicle_on_ride will always be set to a vehicle @@ -7649,7 +7651,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c _vehicleVelocityF64E0C -= remaining_distance - 0x368A; remaining_distance = 0x368A; - Vehicle* v3 = GetEntity(otherVehicleIndex); + Vehicle* v3 = getGameState().entities.GetEntity(otherVehicleIndex); Vehicle* v4 = gCurrentVehicle; if (v3 == nullptr) { @@ -7744,7 +7746,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c if (mini_golf_flags & MiniGolfFlag::Flag0) { auto vehicleIdx = IsHead() ? next_vehicle_on_ride : prev_vehicle_on_ride; - Vehicle* vEDI = GetEntity(vehicleIdx); + Vehicle* vEDI = getGameState().entities.GetEntity(vehicleIdx); if (vEDI == nullptr) { return Vehicle::UpdateMiniGolfSubroutineStatus::stop; @@ -7790,7 +7792,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c if (mini_golf_flags & MiniGolfFlag::Flag1) { auto vehicleIdx = IsHead() ? next_vehicle_on_ride : prev_vehicle_on_ride; - Vehicle* vEDI = GetEntity(vehicleIdx); + Vehicle* vEDI = getGameState().entities.GetEntity(vehicleIdx); if (vEDI == nullptr) { return Vehicle::UpdateMiniGolfSubroutineStatus::stop; @@ -7839,7 +7841,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c for (;;) { - vEDI = GetEntity(vEDI->prev_vehicle_on_ride); + vEDI = getGameState().entities.GetEntity(vEDI->prev_vehicle_on_ride); if (vEDI == this || vEDI == nullptr) { break; @@ -7926,7 +7928,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c if (!IsHead()) { - Vehicle* prevVehicle = GetEntity(prev_vehicle_on_ride); + Vehicle* prevVehicle = getGameState().entities.GetEntity(prev_vehicle_on_ride); if (prevVehicle != nullptr) { TrackSubposition = prevVehicle->TrackSubposition; @@ -8008,7 +8010,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c // When the ride is closed occasionally the peep is removed // but the vehicle is still on the track. This will prevent // it from crashing in that situation. - auto* curPeep = TryGetEntity(peep[0]); + auto* curPeep = getGameState().entities.TryGetEntity(peep[0]); if (curPeep != nullptr) { if (animation == MiniGolfAnimation::SwingLeft) @@ -8162,7 +8164,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c _vehicleVelocityF64E0C -= remaining_distance - 0x368A; remaining_distance = 0x368A; { - Vehicle* vEBP = GetEntity(otherVehicleIndex); + Vehicle* vEBP = getGameState().entities.GetEntity(otherVehicleIndex); if (vEBP == nullptr) { return UpdateMiniGolfSubroutineStatus::stop; @@ -8316,7 +8318,8 @@ int32_t Vehicle::UpdateTrackMotionMiniGolfCalculateAcceleration(const CarEntry& int32_t numVehicles = 0; uint16_t totalMass = 0; - for (Vehicle* vehicle = this; vehicle != nullptr; vehicle = GetEntity(vehicle->next_vehicle_on_train)) + for (Vehicle* vehicle = this; vehicle != nullptr; + vehicle = getGameState().entities.GetEntity(vehicle->next_vehicle_on_train)) { numVehicles++; totalMass += vehicle->mass; @@ -8383,7 +8386,7 @@ int32_t Vehicle::UpdateTrackMotionMiniGolf(int32_t* outStation) } if (_vehicleVelocityF64E08 >= 0) { - vehicle = GetEntity(vehicle->next_vehicle_on_train); + vehicle = getGameState().entities.GetEntity(vehicle->next_vehicle_on_train); } else { @@ -8391,7 +8394,7 @@ int32_t Vehicle::UpdateTrackMotionMiniGolf(int32_t* outStation) { break; } - vehicle = GetEntity(vehicle->prev_vehicle_on_ride); + vehicle = getGameState().entities.GetEntity(vehicle->prev_vehicle_on_ride); } } @@ -8625,7 +8628,7 @@ int32_t Vehicle::UpdateTrackMotion(int32_t* outStation) auto spriteId = vehicle->Id; while (!spriteId.IsNull()) { - Vehicle* car = GetEntity(spriteId); + Vehicle* car = getGameState().entities.GetEntity(spriteId); if (car == nullptr) { break; @@ -8673,7 +8676,7 @@ int32_t Vehicle::UpdateTrackMotion(int32_t* outStation) // ebx int32_t numVehicles = 0; - for (; vehicle != nullptr; vehicle = GetEntity(vehicle->next_vehicle_on_train)) + for (; vehicle != nullptr; vehicle = getGameState().entities.GetEntity(vehicle->next_vehicle_on_train)) { numVehicles++; totalMass += vehicle->mass; @@ -8760,8 +8763,8 @@ Ride* Vehicle::GetRide() const int32_t Vehicle::NumPeepsUntilTrainTail() const { int32_t numPeeps = 0; - for (const Vehicle* vehicle = GetEntity(Id); vehicle != nullptr; - vehicle = GetEntity(vehicle->next_vehicle_on_train)) + for (const Vehicle* vehicle = getGameState().entities.GetEntity(Id); vehicle != nullptr; + vehicle = getGameState().entities.GetEntity(vehicle->next_vehicle_on_train)) { numPeeps += vehicle->num_peeps; } @@ -8939,7 +8942,7 @@ Vehicle* Vehicle::GetHead() auto v = this; while (v != nullptr && !v->IsHead()) { - v = GetEntity(v->prev_vehicle_on_ride); + v = getGameState().entities.GetEntity(v->prev_vehicle_on_ride); } return v; } @@ -8954,7 +8957,7 @@ Vehicle* Vehicle::GetCar(size_t carIndex) const auto car = const_cast(this); for (; carIndex != 0; carIndex--) { - car = GetEntity(car->next_vehicle_on_train); + car = getGameState().entities.GetEntity(car->next_vehicle_on_train); if (car == nullptr) { LOG_ERROR("Tried to get non-existent car from index!"); @@ -8980,7 +8983,8 @@ bool Vehicle::IsGhost() const void Vehicle::EnableCollisionsForTrain() { assert(this->IsHead()); - for (auto vehicle = this; vehicle != nullptr; vehicle = GetEntity(vehicle->next_vehicle_on_train)) + for (auto vehicle = this; vehicle != nullptr; + vehicle = getGameState().entities.GetEntity(vehicle->next_vehicle_on_train)) { vehicle->ClearFlag(VehicleFlags::CollisionDisabled); } diff --git a/src/openrct2/ride/VehicleRiderControl.cpp b/src/openrct2/ride/VehicleRiderControl.cpp index da83a10319..9e0224f314 100644 --- a/src/openrct2/ride/VehicleRiderControl.cpp +++ b/src/openrct2/ride/VehicleRiderControl.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include "../GameState.h" #include "../core/Speed.hpp" #include "../entity/EntityRegistry.h" #include "Vehicle.h" @@ -137,7 +138,7 @@ int32_t Vehicle::CalculateRiderBraking() const RiderControlSettings riderSettings = riderTable[peep[0].ToUnderlying() & 0xFF]; // Brake if close to the vehicle in front - Vehicle* prevVehicle = GetEntity(prev_vehicle_on_ride); + Vehicle* prevVehicle = getGameState().entities.GetEntity(prev_vehicle_on_ride); if (prevVehicle != nullptr && this != prevVehicle && _vehicleVelocityF64E08 > minFollowVelocity) { int32_t followDistance = std::max(minFollowDistance, (riderSettings.followDistance * _vehicleVelocityF64E08) >> 15); diff --git a/src/openrct2/scripting/bindings/entity/ScBalloon.cpp b/src/openrct2/scripting/bindings/entity/ScBalloon.cpp index ad573a6642..bfb17a94c6 100644 --- a/src/openrct2/scripting/bindings/entity/ScBalloon.cpp +++ b/src/openrct2/scripting/bindings/entity/ScBalloon.cpp @@ -28,7 +28,7 @@ namespace OpenRCT2::Scripting Balloon* ScBalloon::GetBalloon() const { - return OpenRCT2::GetEntity(_id); + return OpenRCT2::getGameState().entities.GetEntity(_id); } uint8_t ScBalloon::colour_get() const diff --git a/src/openrct2/scripting/bindings/entity/ScEntity.hpp b/src/openrct2/scripting/bindings/entity/ScEntity.hpp index da17875eb5..d54fd7aa0a 100644 --- a/src/openrct2/scripting/bindings/entity/ScEntity.hpp +++ b/src/openrct2/scripting/bindings/entity/ScEntity.hpp @@ -12,6 +12,7 @@ #ifdef ENABLE_SCRIPTING #include "../../../Context.h" + #include "../../../GameState.h" #include "../../../entity/EntityList.h" #include "../../../entity/EntityRegistry.h" #include "../../../entity/Peep.h" @@ -180,7 +181,7 @@ namespace OpenRCT2::Scripting case EntityType::Balloon: case EntityType::Duck: case EntityType::Litter: - EntityRemove(entity); + getGameState().entities.EntityRemove(entity); break; case EntityType::Null: break; @@ -192,7 +193,7 @@ namespace OpenRCT2::Scripting EntityBase* GetEntity() const { - return OpenRCT2::GetEntity(_id); + return OpenRCT2::getGameState().entities.GetEntity(_id); } public: diff --git a/src/openrct2/scripting/bindings/entity/ScGuest.cpp b/src/openrct2/scripting/bindings/entity/ScGuest.cpp index 0f304ef717..3ae2e1d4b4 100644 --- a/src/openrct2/scripting/bindings/entity/ScGuest.cpp +++ b/src/openrct2/scripting/bindings/entity/ScGuest.cpp @@ -194,7 +194,7 @@ namespace OpenRCT2::Scripting Guest* ScGuest::GetGuest() const { - return OpenRCT2::GetEntity(_id); + return OpenRCT2::getGameState().entities.GetEntity(_id); } uint8_t ScGuest::tshirtColour_get() const diff --git a/src/openrct2/scripting/bindings/entity/ScLitter.cpp b/src/openrct2/scripting/bindings/entity/ScLitter.cpp index 0da245b12d..5fa023aa1b 100644 --- a/src/openrct2/scripting/bindings/entity/ScLitter.cpp +++ b/src/openrct2/scripting/bindings/entity/ScLitter.cpp @@ -45,7 +45,7 @@ namespace OpenRCT2::Scripting Litter* ScLitter::GetLitter() const { - return OpenRCT2::GetEntity(_id); + return OpenRCT2::getGameState().entities.GetEntity(_id); } std::string ScLitter::litterType_get() const diff --git a/src/openrct2/scripting/bindings/entity/ScMoneyEffect.cpp b/src/openrct2/scripting/bindings/entity/ScMoneyEffect.cpp index 35a27c85dd..0def2f9b9c 100644 --- a/src/openrct2/scripting/bindings/entity/ScMoneyEffect.cpp +++ b/src/openrct2/scripting/bindings/entity/ScMoneyEffect.cpp @@ -11,6 +11,7 @@ #include "ScMoneyEffect.hpp" + #include "../../../GameState.h" #include "../../../entity/MoneyEffect.h" namespace OpenRCT2::Scripting @@ -28,7 +29,7 @@ namespace OpenRCT2::Scripting MoneyEffect* ScMoneyEffect::GetMoneyEffect() const { - return OpenRCT2::GetEntity(_id); + return OpenRCT2::getGameState().entities.GetEntity(_id); } money64 ScMoneyEffect::value_get() const diff --git a/src/openrct2/scripting/bindings/entity/ScParticle.cpp b/src/openrct2/scripting/bindings/entity/ScParticle.cpp index e5f6a187d8..c876122cff 100644 --- a/src/openrct2/scripting/bindings/entity/ScParticle.cpp +++ b/src/openrct2/scripting/bindings/entity/ScParticle.cpp @@ -49,7 +49,7 @@ namespace OpenRCT2::Scripting VehicleCrashParticle* ScCrashedVehicleParticle::GetCrashedVehicleParticle() const { - return OpenRCT2::GetEntity(_id); + return OpenRCT2::getGameState().entities.GetEntity(_id); } void ScCrashedVehicleParticle::frame_set(uint8_t value) diff --git a/src/openrct2/scripting/bindings/entity/ScPeep.hpp b/src/openrct2/scripting/bindings/entity/ScPeep.hpp index ed46421120..2d098c978b 100644 --- a/src/openrct2/scripting/bindings/entity/ScPeep.hpp +++ b/src/openrct2/scripting/bindings/entity/ScPeep.hpp @@ -196,7 +196,7 @@ namespace OpenRCT2::Scripting protected: Peep* GetPeep() const { - return OpenRCT2::GetEntity(_id); + return OpenRCT2::getGameState().entities.GetEntity(_id); } }; diff --git a/src/openrct2/scripting/bindings/entity/ScStaff.cpp b/src/openrct2/scripting/bindings/entity/ScStaff.cpp index c24019b3a2..5f4a2902b8 100644 --- a/src/openrct2/scripting/bindings/entity/ScStaff.cpp +++ b/src/openrct2/scripting/bindings/entity/ScStaff.cpp @@ -44,7 +44,7 @@ namespace OpenRCT2::Scripting Staff* ScStaff::GetStaff() const { - return OpenRCT2::GetEntity(_id); + return OpenRCT2::getGameState().entities.GetEntity(_id); } std::string ScStaff::staffType_get() const @@ -421,7 +421,7 @@ namespace OpenRCT2::Scripting Staff* ScHandyman::GetHandyman() const { - return OpenRCT2::GetEntity(_id); + return OpenRCT2::getGameState().entities.GetEntity(_id); } DukValue ScHandyman::lawnsMown_get() const @@ -502,7 +502,7 @@ namespace OpenRCT2::Scripting Staff* ScMechanic::GetMechanic() const { - return OpenRCT2::GetEntity(_id); + return OpenRCT2::getGameState().entities.GetEntity(_id); } DukValue ScMechanic::ridesFixed_get() const @@ -550,7 +550,7 @@ namespace OpenRCT2::Scripting Staff* ScSecurity::GetSecurity() const { - return OpenRCT2::GetEntity(_id); + return OpenRCT2::getGameState().entities.GetEntity(_id); } DukValue ScSecurity::vandalsStopped_get() const @@ -585,7 +585,7 @@ namespace OpenRCT2::Scripting Staff* ScPatrolArea::GetStaff() const { - return GetEntity(_staffId); + return getGameState().entities.GetEntity(_staffId); } void ScPatrolArea::ModifyArea(const DukValue& coordsOrRange, bool value) const diff --git a/src/openrct2/scripting/bindings/entity/ScVehicle.cpp b/src/openrct2/scripting/bindings/entity/ScVehicle.cpp index 47785d899e..af1f159991 100644 --- a/src/openrct2/scripting/bindings/entity/ScVehicle.cpp +++ b/src/openrct2/scripting/bindings/entity/ScVehicle.cpp @@ -102,7 +102,7 @@ namespace OpenRCT2::Scripting Vehicle* ScVehicle::GetVehicle() const { - return ::GetEntity(_id); + return ::getGameState().entities.GetEntity(_id); } ObjectEntryIndex ScVehicle::rideObject_get() const diff --git a/src/openrct2/scripting/bindings/world/ScMap.cpp b/src/openrct2/scripting/bindings/world/ScMap.cpp index a747969cdd..437febd6e4 100644 --- a/src/openrct2/scripting/bindings/world/ScMap.cpp +++ b/src/openrct2/scripting/bindings/world/ScMap.cpp @@ -92,7 +92,7 @@ namespace OpenRCT2::Scripting if (id >= 0 && id < kMaxEntities) { auto spriteId = EntityId::FromUnderlying(id); - auto sprite = GetEntity(spriteId); + auto sprite = getGameState().entities.GetEntity(spriteId); if (sprite != nullptr && sprite->Type != EntityType::Null) { return GetEntityAsDukValue(sprite); @@ -118,7 +118,7 @@ namespace OpenRCT2::Scripting { for (auto carId = trainHead->Id; !carId.IsNull();) { - auto car = GetEntity(carId); + auto car = getGameState().entities.GetEntity(carId); if (car == nullptr) { @@ -181,7 +181,7 @@ namespace OpenRCT2::Scripting { for (auto sprite : EntityList()) { - auto staff = GetEntity(sprite->Id); + auto staff = getGameState().entities.GetEntity(sprite->Id); if (staff != nullptr) { switch (staff->AssignedStaffType) @@ -277,7 +277,7 @@ namespace OpenRCT2::Scripting { for (auto sprite : EntityTileList(pos)) { - auto staff = GetEntity(sprite->Id); + auto staff = getGameState().entities.GetEntity(sprite->Id); if (staff != nullptr) { switch (staff->AssignedStaffType) @@ -321,7 +321,7 @@ namespace OpenRCT2::Scripting template DukValue createEntityType(duk_context* ctx, const DukValue& initializer) { - TEntityType* entity = CreateEntity(); + TEntityType* entity = getGameState().entities.CreateEntity(); if (entity == nullptr) { // Probably no more space for entities for this specified entity type. @@ -340,7 +340,7 @@ namespace OpenRCT2::Scripting DukValue res; if (type == "car") { - Vehicle* entity = CreateEntity(); + Vehicle* entity = getGameState().entities.CreateEntity(); if (entity == nullptr) { // Probably no more space for entities for this specified entity type. @@ -456,7 +456,7 @@ namespace OpenRCT2::Scripting return GetObjectAsDukValue(_context, std::make_shared(spriteId)); case EntityType::Staff: { - auto staff = GetEntity(spriteId); + auto staff = getGameState().entities.GetEntity(spriteId); if (staff != nullptr) { switch (staff->AssignedStaffType) diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 53cd14c228..92bdab00d2 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -141,7 +141,7 @@ void FootpathRemoveLitter(const CoordsXYZ& footpathPos) for (auto* litter : removals) { litter->Invalidate(); - EntityRemove(litter); + getGameState().entities.EntityRemove(litter); } } diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index e75404c0e1..c2b1ac5954 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -2268,10 +2268,10 @@ void ShiftMap(const TileCoordsXY& amount) for (auto i = 0; i < EnumValue(EntityType::Count); i++) { auto entityType = static_cast(i); - auto& list = GetEntityList(entityType); + auto& list = getGameState().entities.GetEntityList(entityType); for (const auto& entityId : list) { - auto entity = GetEntity(entityId); + auto entity = getGameState().entities.GetEntity(entityId); // Do not tween the entity entityTweener.RemoveEntity(entity); diff --git a/test/tests/PlayTests.cpp b/test/tests/PlayTests.cpp index 2dd6f13c62..4892963312 100644 --- a/test/tests/PlayTests.cpp +++ b/test/tests/PlayTests.cpp @@ -56,7 +56,7 @@ static std::unique_ptr localStartGame(const std::string& parkPath) auto& gameState = getGameState(); importer->Import(gameState); - ResetEntitySpatialIndices(); + gameState.entities.ResetEntitySpatialIndices(); ResetAllSpriteQuadrantPlacements(); LoadPalette(); diff --git a/test/tests/S6ImportExportTests.cpp b/test/tests/S6ImportExportTests.cpp index cccee12051..fdf9281406 100644 --- a/test/tests/S6ImportExportTests.cpp +++ b/test/tests/S6ImportExportTests.cpp @@ -61,8 +61,9 @@ static bool LoadFileToBuffer(MemoryStream& stream, const std::string& filePath) static void GameInit(bool retainSpatialIndices) { + auto& gameState = getGameState(); if (!retainSpatialIndices) - ResetEntitySpatialIndices(); + gameState.entities.ResetEntitySpatialIndices(); ResetAllSpriteQuadrantPlacements(); LoadPalette();