Merge pull request #25081 from AaronVanGeffen/entity-registry

Rework EntityRegistry into class
This commit is contained in:
Aaron van Geffen authored and GitHub committed 2025-09-06 21:22:02 +02:00
commit f75c4e0e3a
92 files changed
+786 -687

No files matched your search

+2 -2
View File
@@ -73,7 +73,7 @@ namespace OpenRCT2::Audio
}
iterator& operator++()
{
Current = GetEntity<Vehicle>(NextVehicleId);
Current = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(EntityId::FromUnderlying(vehicleSoundParams.id));
Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(EntityId::FromUnderlying(vehicleSoundParams.id));
if (vehicle != nullptr)
{
UpdateSound<SoundType::TrackNoises>(
@@ -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();
@@ -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
@@ -267,7 +267,7 @@ namespace OpenRCT2::Ui::Windows
break;
}
auto peep = TryGetEntity<Peep>(EntityId::FromUnderlying(newsItem->assoc));
auto peep = getGameState().entities.TryGetEntity<Peep>(EntityId::FromUnderlying(newsItem->assoc));
if (peep == nullptr)
return;
+1 -1
View File
@@ -427,7 +427,7 @@ namespace OpenRCT2::Ui::Windows
private:
Guest* GetGuest()
{
auto guest = GetEntity<Guest>(EntityId::FromUnderlying(number));
auto guest = getGameState().entities.GetEntity<Guest>(EntityId::FromUnderlying(number));
if (guest == nullptr)
{
Close();
+6 -6
View File
@@ -541,7 +541,7 @@ namespace OpenRCT2::Ui::Windows
{
if (i == 0)
{
auto guest = GetEntity<Guest>(guestItem.Id);
auto guest = getGameState().entities.GetEntity<Guest>(guestItem.Id);
if (guest != nullptr)
{
GuestOpen(guest);
@@ -600,14 +600,14 @@ namespace OpenRCT2::Ui::Windows
for (auto peep : EntityList<Guest>())
{
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<Guest>(guestItem.Id);
auto peep = getGameState().entities.GetEntity<Guest>(guestItem.Id);
if (peep == nullptr)
{
continue;
@@ -916,8 +916,8 @@ namespace OpenRCT2::Ui::Windows
template<bool TRealNames>
static bool CompareGuestItem(const GuestItem& a, const GuestItem& b)
{
const auto* peepA = GetEntity<Peep>(a.Id);
const auto* peepB = GetEntity<Peep>(b.Id);
const auto* peepA = getGameState().entities.GetEntity<Peep>(a.Id);
const auto* peepB = getGameState().entities.GetEntity<Peep>(b.Id);
if (peepA != nullptr && peepB != nullptr)
{
// Compare types
+3 -2
View File
@@ -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>(vehicle->next_vehicle_on_train))
for (Vehicle* vehicle = train; vehicle != nullptr;
vehicle = getGameState().entities.GetEntity<Vehicle>(vehicle->next_vehicle_on_train))
{
if (vehicle->x == kLocationNull)
continue;
+1 -1
View File
@@ -504,7 +504,7 @@ namespace OpenRCT2::Ui::Windows
break;
}
auto peep = TryGetEntity<Peep>(EntityId::FromUnderlying(newsItem.assoc));
auto peep = getGameState().entities.TryGetEntity<Peep>(EntityId::FromUnderlying(newsItem.assoc));
if (peep == nullptr)
{
break;
+3 -2
View File
@@ -15,6 +15,7 @@
#include <openrct2-ui/windows/Windows.h>
#include <openrct2/Context.h>
#include <openrct2/Game.h>
#include <openrct2/GameState.h>
#include <openrct2/Input.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/StaffSetPatrolAreaAction.h>
@@ -204,7 +205,7 @@ namespace OpenRCT2::Ui::Windows
auto mapTile = GetBestCoordsFromPos(screenCoords);
if (mapTile)
{
auto staff = GetEntity<Staff>(_staffId);
auto staff = getGameState().entities.GetEntity<Staff>(_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<Staff>(_staffId);
auto staff = getGameState().entities.GetEntity<Staff>(_staffId);
if (staff != nullptr)
{
MapRange range(gMapSelectPositionA, gMapSelectPositionB);
+11 -10
View File
@@ -1518,7 +1518,7 @@ namespace OpenRCT2::Ui::Windows
const auto* rideEntry = ride->getRideEntry();
if (rideEntry != nullptr && rideEntry->TabCar != 0)
{
Vehicle* vehicle = GetEntity<Vehicle>(vehId);
Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(vehId);
if (vehicle == nullptr)
{
vehId = EntityId::GetNull();
@@ -1978,7 +1978,7 @@ namespace OpenRCT2::Ui::Windows
{
if (_viewIndex <= ride->numTrains)
{
Vehicle* vehicle = GetEntity<Vehicle>(ride->vehicles[_viewIndex - 1]);
Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(ride->vehicles[_viewIndex - 1]);
Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(ride->vehicles[_viewIndex - 1]);
auto vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(ride->vehicles[i]); vehicle != nullptr;
vehicle = GetEntity<Vehicle>(vehicle->next_vehicle_on_train))
for (vehicle = getGameState().entities.GetEntity<Vehicle>(ride->vehicles[i]);
vehicle != nullptr;
vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(ride->vehicles[ride->brokenTrain]);
vehicle = getGameState().entities.GetEntity<Vehicle>(ride->vehicles[ride->brokenTrain]);
if (vehicle != nullptr)
{
vehicle->ClearFlag(VehicleFlags::CarIsBroken);
}
break;
case BREAKDOWN_VEHICLE_MALFUNCTION:
vehicle = GetEntity<Vehicle>(ride->vehicles[ride->brokenTrain]);
vehicle = getGameState().entities.GetEntity<Vehicle>(ride->vehicles[ride->brokenTrain]);
if (vehicle != nullptr)
{
vehicle->ClearFlag(VehicleFlags::TrainIsBroken);
@@ -4127,7 +4128,7 @@ namespace OpenRCT2::Ui::Windows
}
else
{
auto staff = GetEntity<Staff>(ride->mechanic);
auto staff = getGameState().entities.GetEntity<Staff>(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<Guest>(vehicle->peep[i]);
Peep* peep = getGameState().entities.GetEntity<Guest>(vehicle->peep[i]);
if (peep == nullptr)
continue;
+1 -1
View File
@@ -1209,7 +1209,7 @@ namespace OpenRCT2::Ui::Windows
Staff* GetStaff()
{
return GetEntity<Staff>(EntityId::FromUnderlying(number));
return getGameState().entities.GetEntity<Staff>(EntityId::FromUnderlying(number));
}
static constexpr int32_t TabAnimationDivisor[] = {
+2 -1
View File
@@ -10,6 +10,7 @@
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Windows.h>
#include <openrct2/Game.h>
#include <openrct2/GameState.h>
#include <openrct2/actions/StaffFireAction.h>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/entity/EntityRegistry.h>
@@ -76,7 +77,7 @@ namespace OpenRCT2::Ui::Windows
{
DrawWidgets(rt);
Peep* peep = GetEntity<Staff>(EntityId::FromUnderlying(number));
Peep* peep = getGameState().entities.GetEntity<Staff>(EntityId::FromUnderlying(number));
// The staff member may have been fired in the meantime.
if (peep == nullptr)
{
+8 -8
View File
@@ -185,10 +185,10 @@ namespace OpenRCT2::Ui::Windows
{
for (auto peep : EntityList<Staff>())
{
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<Staff>(entry.Id);
auto peep = getGameState().entities.GetEntity<Staff>(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<Staff>(entry.Id);
const auto* peep = getGameState().entities.GetEntity<Staff>(entry.Id);
if (peep == nullptr)
{
continue;
@@ -485,10 +485,10 @@ namespace OpenRCT2::Ui::Windows
for (auto* peep : EntityList<Staff>())
{
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<GameActions::StaffHireNewActionResult>();
auto* staff = GetEntity<Staff>(actionResult.StaffEntityId);
auto* staff = getGameState().entities.GetEntity<Staff>(actionResult.StaffEntityId);
if (staff == nullptr)
return;
@@ -560,7 +560,7 @@ namespace OpenRCT2::Ui::Windows
if (result->Error != GameActions::Status::Ok)
return;
auto* staff2 = GetEntity<Staff>(staffId);
auto* staff2 = getGameState().entities.GetEntity<Staff>(staffId);
auto intent = Intent(WindowClass::Peep);
intent.PutExtra(INTENT_EXTRA_PEEP, staff2);
auto* wind = ContextOpenIntent(&intent);
+1 -1
View File
@@ -302,7 +302,7 @@ namespace OpenRCT2::Editor
staff->SetName({});
}
ResetAllEntities();
getGameState().entities.ResetAllEntities();
UpdateConsolidatedPatrolAreas();
auto& gameState = getGameState();
+4 -4
View File
@@ -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;
}
+5 -5
View File
@@ -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)
+3 -2
View File
@@ -62,7 +62,9 @@ namespace OpenRCT2
std::string scenarioFileName;
std::vector<Banner> 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<Ride, Limits::kMaxRidesInPark> rides{};
size_t ridesEndOfUsedRange{};
@@ -86,7 +88,6 @@ namespace OpenRCT2
uint8_t researchExpectedDay;
std::optional<ResearchItem> researchLastItem;
std::optional<ResearchItem> researchNextItem;
std::vector<ResearchItem> researchItemsUninvented;
std::vector<ResearchItem> researchItemsInvented;
uint8_t researchUncompletedCategories;
+2 -1
View File
@@ -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<EntitySnapshot*>(GetEntity(index)); }, kMaxEntities, true);
[](const EntityId index) { return reinterpret_cast<EntitySnapshot*>(getGameState().entities.GetEntity(index)); },
kMaxEntities, true);
// LOG_INFO("Snapshot size: %u bytes", static_cast<uint32_t>(snapshot.storedSprites.GetLength()));
}
+3 -3
View File
@@ -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;
+5 -2
View File
@@ -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<Balloon>(_spriteIndex);
auto& gameState = getGameState();
auto balloon = gameState.entities.TryGetEntity<Balloon>(_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<Balloon>(_spriteIndex);
auto& gameState = getGameState();
auto balloon = gameState.entities.TryGetEntity<Balloon>(_spriteIndex);
if (balloon == nullptr)
{
LOG_ERROR("Balloon not found for spriteIndex %u", _spriteIndex);
+4 -4
View File
@@ -498,7 +498,7 @@ namespace OpenRCT2::GameActions
{
for (auto litter : EntityList<Litter>())
{
EntityRemove(litter);
getGameState().entities.EntityRemove(litter);
}
TileElementIterator it{};
@@ -732,8 +732,8 @@ namespace OpenRCT2::GameActions
for (auto trainIndex : ride.vehicles)
{
for (Vehicle* vehicle = TryGetEntity<Vehicle>(trainIndex); vehicle != nullptr;
vehicle = TryGetEntity<Vehicle>(vehicle->next_vehicle_on_train))
for (Vehicle* vehicle = getGameState().entities.TryGetEntity<Vehicle>(trainIndex); vehicle != nullptr;
vehicle = getGameState().entities.TryGetEntity<Vehicle>(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<Guest>(peepInTrainIndex);
auto peep = getGameState().entities.TryGetEntity<Guest>(peepInTrainIndex);
if (peep != nullptr && peep->CurrentRide == ride.id)
{
if ((peep->State == PeepState::OnRide && peep->RideSubState == PeepRideSubState::OnRide)
+5 -2
View File
@@ -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<Guest>(_peepId);
auto& gameState = getGameState();
auto* peep = gameState.entities.TryGetEntity<Guest>(_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<Guest>(_peepId);
auto& gameState = getGameState();
auto* peep = gameState.entities.TryGetEntity<Guest>(_peepId);
if (peep == nullptr)
{
LOG_ERROR("Guest entity not found for peepID %u", _peepId.ToUnderlying());
+3 -2
View File
@@ -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<Guest>(_spriteIndex);
auto guest = getGameState().entities.TryGetEntity<Guest>(_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<Guest>(_spriteIndex);
auto guest = getGameState().entities.TryGetEntity<Guest>(_spriteIndex);
if (guest == nullptr)
{
LOG_ERROR("Guest entity not found for spriteIndex %u", _spriteIndex);
+3 -2
View File
@@ -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<Peep>(_entityId);
auto* const peep = getGameState().entities.TryGetEntity<Peep>(_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<Peep>(_entityId);
Peep* const peep = getGameState().entities.TryGetEntity<Peep>(_entityId);
if (peep == nullptr)
{
LOG_ERROR("Failed to pick up peep for sprite %d", _entityId);
+3 -2
View File
@@ -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<Staff>(_spriteId);
auto staff = getGameState().entities.TryGetEntity<Staff>(_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<Staff>(_spriteId);
auto staff = getGameState().entities.TryGetEntity<Staff>(_spriteId);
if (staff == nullptr)
{
LOG_ERROR("Staff entity not found for spriteId %u", _spriteId);
+3 -3
View File
@@ -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>();
Staff* newPeep = getGameState().entities.CreateEntity<Staff>();
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() });
}
@@ -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<Staff>(_spriteIndex);
auto* staff = getGameState().entities.TryGetEntity<Staff>(_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<Staff>(_spriteIndex);
auto* staff = getGameState().entities.TryGetEntity<Staff>(_spriteIndex);
if (staff == nullptr)
{
LOG_ERROR("Staff entity not found for spriteIndex %u", _spriteIndex);
+3 -2
View File
@@ -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<Staff>(_spriteIndex);
auto staff = getGameState().entities.TryGetEntity<Staff>(_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<Staff>(_spriteIndex);
auto staff = getGameState().entities.TryGetEntity<Staff>(_spriteIndex);
if (staff == nullptr)
{
LOG_ERROR("Staff entity not found for spriteIndex %u", _spriteIndex);
@@ -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<Staff>(_spriteIndex);
auto* staff = getGameState().entities.TryGetEntity<Staff>(_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<Staff>(_spriteIndex);
auto* staff = getGameState().entities.TryGetEntity<Staff>(_spriteIndex);
if (staff == nullptr)
{
LOG_ERROR("Staff entity not found for spriteIndex %u", _spriteIndex);
@@ -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<Staff>(_spriteId);
auto staff = getGameState().entities.TryGetEntity<Staff>(_spriteId);
if (staff == nullptr)
{
LOG_ERROR("Staff entity not found for spriteID %u", _spriteId.ToUnderlying());
@@ -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
{
+1 -1
View File
@@ -728,7 +728,7 @@ namespace OpenRCT2::Drawing::LightFx
void AddLightsMagicVehicle_BoatHire(const Vehicle* vehicle)
{
Vehicle* vehicle_draw = vehicle->TrainHead();
auto* nextVeh = GetEntity<Vehicle>(vehicle_draw->next_vehicle_on_train);
auto* nextVeh = getGameState().entities.GetEntity<Vehicle>(vehicle_draw->next_vehicle_on_train);
if (nextVeh != nullptr)
{
vehicle_draw = nextVeh;
+3 -2
View File
@@ -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<Balloon>();
auto* balloon = getGameState().entities.CreateEntity<Balloon>();
if (balloon == nullptr)
return;
+2 -2
View File
@@ -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<Duck>();
auto* duck = getGameState().entities.CreateEntity<Duck>();
if (duck == nullptr)
return;
+11 -11
View File
@@ -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<EntityId>& GetEntityList(const EntityType id);
uint16_t GetEntityListCount(EntityType list);
uint16_t GetMiscEntityCount();
uint16_t GetNumFreeEntities();
const std::vector<EntityId>& GetEntityTileList(const CoordsXY& spritePos);
template<typename T>
class EntityTileIterator
{
@@ -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<T>(*iter++);
Entity = gameState.entities.TryGetEntity<T>(*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<T>(*iter++);
Entity = gameState.entities.TryGetEntity<T>(*iter++);
}
return *this;
}
@@ -161,7 +161,7 @@ namespace OpenRCT2
public:
EntityList()
: vec(GetEntityList(T::cEntityType))
: vec(getGameState().entities.GetEntityList(T::cEntityType))
{
}
+117 -171
View File
@@ -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<std::list<EntityId>, EnumValue(EntityType::Count)> gEntityLists;
static std::vector<EntityId> _freeIdList;
// TODO: move into MapWindow or GameState_t?
static bool _entityFlashingList[kMaxEntities];
// TODO: move into GameState_t
static std::array<std::vector<EntityId>, kSpatialIndexSize> gEntitySpatialIndex;
static void FreeEntity(EntityBase& entity);
static constexpr uint32_t ComputeSpatialIndex(const CoordsXY& loc)
{
if (loc.IsNull())
@@ -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<uint16_t>(gEntityLists[EnumValue(type)].size());
}
uint16_t GetNumFreeEntities()
// TODO: make part of EntityList unit?
uint16_t EntityRegistry::GetNumFreeEntities()
{
return static_cast<uint16_t>(_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<EntityId>& GetEntityTileList(const CoordsXY& spritePos)
const std::vector<EntityId>& 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<EntityId>& GetEntityList(const EntityType id)
const std::list<EntityId>& 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<typename T>
void NetworkSerialseEntityType(DataSerialiser& ds)
{
for (auto* ent : EntityList<T>())
{
ent->Serialise(ds);
}
}
template<typename... T>
void NetworkSerialiseEntityTypes(DataSerialiser& ds)
{
(NetworkSerialseEntityType<T>(ds), ...);
}
EntitiesChecksum GetAllEntitiesChecksum()
EntitiesChecksum EntityRegistry::GetAllEntitiesChecksum()
{
EntitiesChecksum checksum{};
OpenRCT2::ChecksumStream ms(checksum.raw);
ChecksumStream ms(checksum.raw);
DataSerialiser ds(true, ms);
NetworkSerialiseEntityTypes<Guest, Staff, Vehicle, Litter>(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<typename T>
void MiscUpdateAllType()
{
for (auto misc : EntityList<T>())
{
misc->Update();
}
}
template<typename... T>
void MiscUpdateAllTypes()
{
(MiscUpdateAllType<T>(), ...);
}
/**
*
* rct2: 0x00672AA4
*/
void UpdateAllMiscEntities()
void EntityRegistry::UpdateAllMiscEntities()
{
PROFILED_FUNCTION();
@@ -417,13 +362,13 @@ namespace OpenRCT2
JumpingFountain, Balloon, Duck>();
}
void UpdateMoneyEffect()
void EntityRegistry::UpdateMoneyEffect()
{
MiscUpdateAllTypes<MoneyEffect>();
}
// Performs a search to ensure that insert keeps next_in_quadrant in sprite_index order
static void EntitySpatialInsert(EntityBase& entity, const CoordsXY& newLoc)
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<Guest>();
auto* staff = entity.As<Staff>();
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<Balloon>())
{
EntityRemove(balloon);
removed++;
}
for (auto* duck : EntityList<Duck>())
{
if (duck->IsFlying())
{
EntityRemove(duck);
removed++;
}
}
for (auto* money : EntityList<MoneyEffect>())
{
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<Guest>();
auto* staff = entity.As<Staff>();
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<Balloon>())
{
EntityRemove(balloon);
removed++;
}
for (auto* duck : EntityList<Duck>())
{
if (duck->IsFlying())
{
EntityRemove(duck);
removed++;
}
}
for (auto* money : EntityList<MoneyEffect>())
{
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
+155 -70
View File
@@ -9,13 +9,26 @@
#pragma once
#include "../core/EnumUtils.hpp"
#include "../world/MapLimits.h"
#include "EntityBase.h"
#include <array>
#include <list>
#include <string>
#include <vector>
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<typename T>
T* GetEntity(EntityId entityId)
{
auto* ent = GetEntity(entityId);
if (ent == nullptr)
{
return nullptr;
}
if constexpr (std::is_same_v<T, EntityBase>)
{
return ent;
}
else
{
return ent->As<T>();
}
}
EntityBase* TryGetEntity(EntityId spriteIndex);
template<typename T>
T* TryGetEntity(EntityId entityId)
{
auto* ent = TryGetEntity(entityId);
if (ent == nullptr)
{
return nullptr;
}
if constexpr (std::is_same_v<T, EntityBase>)
{
return ent;
}
else
{
return ent->As<T>();
}
}
EntityBase* CreateEntity(EntityType type);
template<typename T>
T* CreateEntity()
{
return static_cast<T*>(CreateEntity(T::cEntityType));
}
// Use only with imports that must happen at a specified index
EntityBase* CreateEntityAt(const EntityId index, const EntityType type);
// Use only with imports that must happen at a specified index
template<typename T>
T* CreateEntityAt(const EntityId index)
{
return static_cast<T*>(CreateEntityAt(index, T::cEntityType));
}
void ResetAllEntities();
void ResetEntitySpatialIndices();
void UpdateAllMiscEntities();
void UpdateMoneyEffect();
void EntityRemove(EntityBase* entity);
uint16_t RemoveFloatingEntities();
void UpdateEntitiesSpatialIndex();
#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<typename T>
class EntityList;
class EntityRegistry
{
private:
Entity_t entities[kMaxEntities]{};
std::array<std::list<EntityId>, EnumValue(EntityType::Count)> gEntityLists;
std::vector<EntityId> _freeIdList;
bool _entityFlashingList[kMaxEntities];
std::array<std::vector<EntityId>, kSpatialIndexSize> gEntitySpatialIndex;
public:
uint16_t GetEntityListCount(EntityType type);
uint16_t GetNumFreeEntities();
EntityBase* GetEntity(EntityId entityId);
template<typename T>
T* GetEntity(EntityId entityId)
{
auto* ent = GetEntity(entityId);
if (ent == nullptr)
{
return nullptr;
}
if constexpr (std::is_same_v<T, EntityBase>)
{
return ent;
}
else
{
return ent->As<T>();
}
}
EntityBase* TryGetEntity(EntityId spriteIndex);
template<typename T>
T* TryGetEntity(EntityId entityId)
{
auto* ent = TryGetEntity(entityId);
if (ent == nullptr)
{
return nullptr;
}
if constexpr (std::is_same_v<T, EntityBase>)
{
return ent;
}
else
{
return ent->As<T>();
}
}
const std::vector<EntityId>& GetEntityTileList(const CoordsXY& spritePos);
EntityBase* CreateEntity(EntityType type);
template<typename T>
T* CreateEntity()
{
return static_cast<T*>(CreateEntity(T::cEntityType));
}
// Use only with imports that must happen at a specified index
EntityBase* CreateEntityAt(const EntityId index, const EntityType type);
// Use only with imports that must happen at a specified index
template<typename T>
T* CreateEntityAt(const EntityId index)
{
return static_cast<T*>(CreateEntityAt(index, T::cEntityType));
}
const std::list<EntityId>& GetEntityList(const EntityType id);
uint16_t GetMiscEntityCount();
void ResetAllEntities();
void ResetEntitySpatialIndices();
#ifndef DISABLE_NETWORK
template<typename T>
void NetworkSerialseEntityType(DataSerialiser& ds)
{
for (auto* ent : EntityList<T>())
{
ent->Serialise(ds);
}
}
template<typename... T>
void NetworkSerialiseEntityTypes(DataSerialiser& ds)
{
(NetworkSerialseEntityType<T>(ds), ...);
}
#endif // DISABLE_NETWORK
EntitiesChecksum GetAllEntitiesChecksum();
template<typename T>
void MiscUpdateAllType()
{
for (auto misc : EntityList<T>())
{
misc->Update();
}
}
template<typename... T>
void MiscUpdateAllTypes()
{
(MiscUpdateAllType<T>(), ...);
}
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
+2 -2
View File
@@ -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<JumpingFountain>();
auto* jumpingFountain = getGameState().entities.CreateEntity<JumpingFountain>();
if (jumpingFountain != nullptr)
{
jumpingFountain->Iteration = iteration;
@@ -199,7 +199,7 @@ void JumpingFountain::Update()
if (frame == 16)
{
EntityRemove(this);
getGameState().entities.EntityRemove(this);
}
}
+34 -29
View File
@@ -1617,7 +1617,7 @@ static bool GuestDecideAndBuyItem(Guest& guest, Ride& ride, const ShopItem shopI
if (guest.Happiness >= 180)
itemValue /= 2;
}
if (itemValue > (static_cast<money64>(ScenarioRand() & 0x07)) && !(getGameState().cheats.ignorePrice))
if (itemValue > (static_cast<money64>(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<Guest>(station.LastPeepInQueue);
Guest* lastPeepInQueue = getGameState().entities.GetEntity<Guest>(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<Vehicle>(ride.vehicles[guest.CurrentTrain]);
Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(ride.vehicles[i]);
Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(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>(vehicle_id); vehicle != nullptr;
vehicle = GetEntity<Vehicle>(vehicle->next_vehicle_on_train), ++i)
for (Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(vehicle_id); vehicle != nullptr;
vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(ride.vehicles[CurrentTrain]);
auto vehicle = getGameState().entities.GetEntity<Vehicle>(ride.vehicles[CurrentTrain]);
if (vehicle == nullptr)
{
// TODO: Goto ride exit on failure.
@@ -3760,7 +3760,7 @@ void Guest::UpdateRideAdvanceThroughEntrance()
return;
}
Vehicle* vehicle = GetEntity<Vehicle>(ride->vehicles[CurrentTrain]);
Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(ride->vehicles[CurrentTrain]);
if (vehicle == nullptr)
{
return;
@@ -3995,7 +3995,8 @@ void Guest::UpdateRideFreeVehicleCheck()
return;
}
Vehicle* vehicle = GetEntity<Vehicle>(ride->vehicles[CurrentTrain]);
auto& gameState = getGameState();
Vehicle* vehicle = gameState.entities.GetEntity<Vehicle>(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<Vehicle>(ride->vehicles[i]);
Vehicle* train = gameState.entities.GetEntity<Vehicle>(ride->vehicles[i]);
if (train == nullptr)
continue;
Vehicle* second_vehicle = GetEntity<Vehicle>(train->next_vehicle_on_train);
Vehicle* second_vehicle = gameState.entities.GetEntity<Vehicle>(train->next_vehicle_on_train);
if (second_vehicle == nullptr)
continue;
@@ -4059,7 +4060,7 @@ void Guest::UpdateRideFreeVehicleCheck()
}
}
Vehicle* currentTrain = GetEntity<Vehicle>(ride->vehicles[CurrentTrain]);
Vehicle* currentTrain = gameState.entities.GetEntity<Vehicle>(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<Vehicle>(ride->vehicles[CurrentTrain]);
auto* vehicle = gameState.entities.GetEntity<Vehicle>(ride->vehicles[CurrentTrain]);
if (vehicle != nullptr)
{
vehicle = vehicle->GetCar(CurrentCar);
@@ -4113,7 +4115,7 @@ void Guest::UpdateRideEnterVehicle()
if (vehicle->IsUsedInPairs())
{
auto* seatedGuest = GetEntity<Guest>(vehicle->peep[CurrentSeat ^ 1]);
auto* seatedGuest = gameState.entities.GetEntity<Guest>(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<Vehicle>(ride->vehicles[CurrentTrain]);
Vehicle* vehicle = gameState.entities.GetEntity<Vehicle>(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>(vehicle->prev_vehicle_on_ride))
for (; vehicle != nullptr && !vehicle->IsHead();
vehicle = gameState.entities.GetEntity<Vehicle>(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<Vehicle>(ride->vehicles[CurrentTrain]);
vehicle = gameState.entities.GetEntity<Vehicle>(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<Vehicle>(ride->vehicles[CurrentTrain]);
Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(ride->vehicles[CurrentTrain]);
if (vehicle == nullptr)
{
return;
@@ -4615,7 +4619,7 @@ void Guest::UpdateRideApproachExitWaypoints()
}
Var37--;
Vehicle* vehicle = GetEntity<Vehicle>(ride->vehicles[CurrentTrain]);
Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(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<Guest>(GuestNextInQueue);
Peep* nextGuest = getGameState().entities.GetEntity<Guest>(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>();
Guest* peep = gameState.entities.CreateEntity<Guest>();
peep->AnimationObjectIndex = findPeepAnimationsIndexForType(AnimationPeepType::Guest);
peep->AnimationGroup = PeepAnimationGroup::Normal;
@@ -7563,7 +7567,7 @@ bool Guest::UpdateQueuePosition(PeepActionType previous_action)
{
TimeInQueue++;
auto* guestNext = GetEntity<Guest>(GuestNextInQueue);
auto* guestNext = getGameState().entities.GetEntity<Guest>(GuestNextInQueue);
if (guestNext == nullptr)
{
return false;
@@ -7653,13 +7657,14 @@ void Guest::RemoveFromQueue()
return;
}
auto* otherGuest = GetEntity<Guest>(station.LastPeepInQueue);
auto& gameState = getGameState();
auto* otherGuest = gameState.entities.GetEntity<Guest>(station.LastPeepInQueue);
if (otherGuest == nullptr)
{
LOG_ERROR("Invalid Guest Queue list!");
return;
}
for (; otherGuest != nullptr; otherGuest = GetEntity<Guest>(otherGuest->GuestNextInQueue))
for (; otherGuest != nullptr; otherGuest = gameState.entities.GetEntity<Guest>(otherGuest->GuestNextInQueue))
{
if (Id == otherGuest->GuestNextInQueue)
{
+4 -4
View File
@@ -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* litter = gameState.entities.CreateEntity<Litter>();
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);
}
}
+3 -2
View File
@@ -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* moneyEffect = getGameState().entities.CreateEntity<MoneyEffect>();
if (moneyEffect == nullptr)
return;
@@ -151,7 +152,7 @@ void MoneyEffect::Update()
return;
}
EntityRemove(this);
getGameState().entities.EntityRemove(this);
}
std::pair<StringId, money64> MoneyEffect::GetStringId() const
+12 -11
View File
@@ -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>();
VehicleCrashParticle* sprite = getGameState().entities.CreateEntity<VehicleCrashParticle>();
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<CrashSplashParticle>();
auto* sprite = getGameState().entities.CreateEntity<CrashSplashParticle>();
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>();
SteamParticle* steam = getGameState().entities.CreateEntity<SteamParticle>();
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<ExplosionCloud>();
auto* entity = getGameState().entities.CreateEntity<ExplosionCloud>();
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<ExplosionFlare>();
auto* entity = getGameState().entities.CreateEntity<ExplosionFlare>();
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);
}
}
+4 -4
View File
@@ -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<Peep>(sprite_index_a);
Peep const* peep_b = GetEntity<Peep>(sprite_index_b);
Peep const* peep_a = getGameState().entities.GetEntity<Peep>(sprite_index_a);
Peep const* peep_b = getGameState().entities.GetEntity<Peep>(sprite_index_b);
if (peep_a == nullptr || peep_b == nullptr)
{
return 0;
+1 -1
View File
@@ -2111,7 +2111,7 @@ bool Staff::UpdateFixingMoveToBrokenDownVehicle(bool firstRun, const Ride& ride)
break;
}
vehicle = GetEntity<Vehicle>(vehicle->prev_vehicle_on_ride);
vehicle = getGameState().entities.GetEntity<Vehicle>(vehicle->prev_vehicle_on_ride);
if (vehicle == nullptr)
{
return true;
+17 -13
View File
@@ -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<Vehicle>(ride->vehicles[i]); vehicle != nullptr;
vehicle = GetEntity<Vehicle>(vehicle->next_vehicle_on_train))
for (Vehicle* vehicle = gameState.entities.GetEntity<Vehicle>(ride->vehicles[i]);
vehicle != nullptr;
vehicle = gameState.entities.GetEntity<Vehicle>(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<Peep>(EntityId::FromUnderlying(int_val[0]));
Peep* peep = gameState.entities.GetEntity<Peep>(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<Staff>(EntityId::FromUnderlying(int_val[0]));
auto staff = gameState.entities.GetEntity<Staff>(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<GameActions::CheatSetAction>(
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<GameActions::CheatSetAction>(
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<GameActions::CheatSetAction>(
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<uint8_t>(EntityType::Count); ++i)
{
spriteCount += GetEntityListCount(EntityType(i));
auto& gameState = getGameState();
spriteCount += gameState.entities.GetEntityListCount(EntityType(i));
}
auto bannerCount = GetNumBanners();
+4 -4
View File
@@ -148,7 +148,7 @@ namespace OpenRCT2
return arg;
else if constexpr (std::is_same_v<T, Focus::EntityFocus>)
{
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<Vehicle>(ride->vehicles[peep.CurrentTrain]);
auto train = getGameState().entities.GetEntity<Vehicle>(ride->vehicles[peep.CurrentTrain]);
if (train != nullptr)
{
const auto car = train->GetCar(peep.CurrentCar);
+3 -2
View File
@@ -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);
}
+7 -5
View File
@@ -213,6 +213,8 @@ std::optional<CoordsXYZ> News::GetSubjectLocation(News::ItemType type, int32_t s
{
std::optional<CoordsXYZ> subjectLoc{ std::nullopt };
auto& gameState = getGameState();
switch (type)
{
case News::ItemType::ride:
@@ -228,7 +230,7 @@ std::optional<CoordsXYZ> News::GetSubjectLocation(News::ItemType type, int32_t s
}
case News::ItemType::peepOnRide:
{
auto peep = TryGetEntity<Peep>(EntityId::FromUnderlying(subject));
auto peep = gameState.entities.TryGetEntity<Peep>(EntityId::FromUnderlying(subject));
if (peep == nullptr)
break;
@@ -251,11 +253,11 @@ std::optional<CoordsXYZ> News::GetSubjectLocation(News::ItemType type, int32_t s
}
// Find the first car of the train peep is on
auto sprite = TryGetEntity<Vehicle>(ride->vehicles[peep->CurrentTrain]);
auto sprite = gameState.entities.TryGetEntity<Vehicle>(ride->vehicles[peep->CurrentTrain]);
// Find the actual car peep is on
for (int32_t i = 0; i < peep->CurrentCar && sprite != nullptr; i++)
{
sprite = TryGetEntity<Vehicle>(sprite->next_vehicle_on_train);
sprite = gameState.entities.TryGetEntity<Vehicle>(sprite->next_vehicle_on_train);
}
if (sprite != nullptr)
{
@@ -265,7 +267,7 @@ std::optional<CoordsXYZ> News::GetSubjectLocation(News::ItemType type, int32_t s
}
case News::ItemType::peep:
{
auto peep = TryGetEntity<Peep>(EntityId::FromUnderlying(subject));
auto peep = gameState.entities.TryGetEntity<Peep>(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<Peep>(EntityId::FromUnderlying(subject));
auto peep = getGameState().entities.TryGetEntity<Peep>(EntityId::FromUnderlying(subject));
if (peep != nullptr)
{
auto intent = Intent(WindowClass::Peep);
+2 -2
View File
@@ -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());
}
@@ -881,7 +881,7 @@ std::optional<colour_t> GetPatrolAreaTileColour(const CoordsXY& pos)
else
{
auto& staffId = std::get<EntityId>(patrolAreaToRender);
auto* staff = GetEntity<Staff>(staffId);
auto* staff = getGameState().entities.GetEntity<Staff>(staffId);
if (staff != nullptr)
{
if (staff->IsPatrolAreaSet(pos))
+2 -1
View File
@@ -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<Vehicle>(ride.vehicles[0]);
auto vehicle = getGameState().entities.GetEntity<Vehicle>(ride.vehicles[0]);
if (ride.lifecycleFlags & RIDE_LIFECYCLE_ON_TRACK && vehicle != nullptr)
{
session.InteractionType = ViewportInteractionItem::Entity;
@@ -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<Vehicle>(ride->vehicles[0]);
auto vehicle = getGameState().entities.GetEntity<Vehicle>(ride->vehicles[0]);
if (vehicle != nullptr)
{
session.InteractionType = ViewportInteractionItem::Entity;
@@ -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<Guest>(vehicle.peep[i]);
auto* peep = getGameState().entities.GetEntity<Guest>(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<Vehicle>(ride.vehicles[0]);
auto vehicle = getGameState().entities.GetEntity<Vehicle>(ride.vehicles[0]);
if (ride.lifecycleFlags & RIDE_LIFECYCLE_ON_TRACK && vehicle != nullptr)
{
session.InteractionType = ViewportInteractionItem::Entity;
@@ -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<Vehicle>(ride.vehicles[0]);
auto vehicle = getGameState().entities.GetEntity<Vehicle>(ride.vehicles[0]);
if (ride.lifecycleFlags & RIDE_LIFECYCLE_ON_TRACK && vehicle != nullptr)
{
session.InteractionType = ViewportInteractionItem::Entity;
@@ -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<Vehicle>(ride.vehicles[0]);
auto vehicle = getGameState().entities.GetEntity<Vehicle>(ride.vehicles[0]);
if (ride.lifecycleFlags & RIDE_LIFECYCLE_ON_TRACK && vehicle != nullptr)
{
session.InteractionType = ViewportInteractionItem::Entity;
@@ -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<Vehicle>(ride.vehicles[vehicleIndex]);
auto vehicle = getGameState().entities.GetEntity<Vehicle>(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<Guest>(vehicle->peep[0]);
auto* rider = getGameState().entities.GetEntity<Guest>(vehicle->peep[0]);
if (rider != nullptr)
{
stationColour = ImageId(0, rider->TshirtColour, rider->TrousersColour);
+2 -1
View File
@@ -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<Vehicle>(ride.vehicles[0]);
session.CurrentlyDrawnEntity = getGameState().entities.GetEntity<Vehicle>(ride.vehicles[0]);
}
auto imageTemplate = ImageId(0, ride.vehicleColours[0].Body, ride.vehicleColours[0].Trim);
@@ -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<Vehicle>(ride.vehicles[0]);
vehicle = getGameState().entities.GetEntity<Vehicle>(ride.vehicles[0]);
if (vehicle != nullptr)
{
session.InteractionType = ViewportInteractionItem::Entity;
@@ -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<Vehicle>(ride.vehicles[0]);
return getGameState().entities.GetEntity<Vehicle>(ride.vehicles[0]);
}
return nullptr;
}
@@ -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<Vehicle>(ride.vehicles[0]);
vehicle = getGameState().entities.GetEntity<Vehicle>(ride.vehicles[0]);
if (vehicle != nullptr)
{
session.InteractionType = ViewportInteractionItem::Entity;
@@ -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<Vehicle>(ride.vehicles[0]);
vehicle = getGameState().entities.GetEntity<Vehicle>(ride.vehicles[0]);
if (vehicle != nullptr)
{
session.InteractionType = ViewportInteractionItem::Entity;
@@ -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<Vehicle>(ride.vehicles[0]);
vehicle = getGameState().entities.GetEntity<Vehicle>(ride.vehicles[0]);
session.InteractionType = ViewportInteractionItem::Entity;
session.CurrentlyDrawnEntity = vehicle;
}
+2 -1
View File
@@ -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<Vehicle>(ride.vehicles[0]);
auto* vehicle = getGameState().entities.GetEntity<Vehicle>(ride.vehicles[0]);
if (ride.lifecycleFlags & RIDE_LIFECYCLE_ON_TRACK && vehicle != nullptr)
{
session.InteractionType = ViewportInteractionItem::Entity;
+2 -1
View File
@@ -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<Vehicle>(ride.vehicles[0]);
vehicle = getGameState().entities.GetEntity<Vehicle>(ride.vehicles[0]);
session.InteractionType = ViewportInteractionItem::Entity;
session.CurrentlyDrawnEntity = vehicle;
@@ -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<Guest>(vehicle->peep[0]);
auto* peep = getGameState().entities.GetEntity<Guest>(vehicle->peep[0]);
if (peep == nullptr)
return;
@@ -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>(vehicle->prev_vehicle_on_ride);
Vehicle* v2 = GetEntity<Vehicle>(vehicle->next_vehicle_on_ride);
Vehicle* v1 = getGameState().entities.GetEntity<Vehicle>(vehicle->prev_vehicle_on_ride);
Vehicle* v2 = getGameState().entities.GetEntity<Vehicle>(vehicle->next_vehicle_on_ride);
if (v1 == nullptr || v2 == nullptr)
{
return;
@@ -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>(vehicle->next_vehicle_on_ride)
: GetEntity<Vehicle>(vehicle->prev_vehicle_on_ride);
// TODO: pass as parameter?
auto& entityRegistry = getGameState().entities;
auto* vehicleToPaint = vehicle->IsHead() ? entityRegistry.GetEntity<Vehicle>(vehicle->next_vehicle_on_ride)
: entityRegistry.GetEntity<Vehicle>(vehicle->prev_vehicle_on_ride);
if (vehicleToPaint == nullptr)
{
return;
+2 -2
View File
@@ -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>(vehicle->prev_vehicle_on_ride);
Vehicle* vehicle2 = getGameState().entities.GetEntity<Vehicle>(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>(vehicle->prev_vehicle_on_ride);
Vehicle* vehicle2 = getGameState().entities.GetEntity<Vehicle>(vehicle->prev_vehicle_on_ride);
if (vehicle2 == nullptr)
{
return;
+15 -15
View File
@@ -2155,15 +2155,15 @@ namespace OpenRCT2
}
template<typename T>
void WriteEntitiesOfType(OrcaStream& os, OrcaStream::ChunkStream& cs);
void WriteEntitiesOfType(GameState_t& gameState, OrcaStream& os, OrcaStream::ChunkStream& cs);
template<typename... T>
void WriteEntitiesOfTypes(OrcaStream& os, OrcaStream::ChunkStream& cs);
void WriteEntitiesOfTypes(GameState_t& gameState, OrcaStream& os, OrcaStream::ChunkStream& cs);
template<typename T>
void ReadEntitiesOfType(OrcaStream& os, OrcaStream::ChunkStream& cs);
void ReadEntitiesOfType(GameState_t& gameState, OrcaStream& os, OrcaStream::ChunkStream& cs);
template<typename... T>
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<typename T>
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<T>())
@@ -2650,13 +2650,13 @@ namespace OpenRCT2
}
template<typename... T>
void ParkFile::WriteEntitiesOfTypes(OrcaStream& os, OrcaStream::ChunkStream& cs)
void ParkFile::WriteEntitiesOfTypes(GameState_t& gameState, OrcaStream& os, OrcaStream::ChunkStream& cs)
{
(WriteEntitiesOfType<T>(os, cs), ...);
(WriteEntitiesOfType<T>(gameState, os, cs), ...);
}
template<typename T>
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<EntityType>();
assert(t == T::cEntityType);
@@ -2666,7 +2666,7 @@ namespace OpenRCT2
T placeholder{};
auto index = cs.read<EntityId>();
auto* ent = CreateEntityAt<T>(index);
auto* ent = getGameState().entities.CreateEntityAt<T>(index);
if (ent == nullptr)
{
// Unable to allocate entity
@@ -2677,9 +2677,9 @@ namespace OpenRCT2
}
template<typename... T>
void ParkFile::ReadEntitiesOfTypes(OrcaStream& os, OrcaStream::ChunkStream& cs)
void ParkFile::ReadEntitiesOfTypes(GameState_t& gameState, OrcaStream& os, OrcaStream::ChunkStream& cs)
{
(ReadEntitiesOfType<T>(os, cs), ...);
(ReadEntitiesOfType<T>(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<uint16_t> 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);
}
});
}
+45 -45
View File
@@ -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<typename T>
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<const RCT1::Vehicle*>(&srcBase);
const auto* ride = GetRide(RideId::FromUnderlying(src->Ride));
if (ride == nullptr)
@@ -2905,9 +2905,9 @@ namespace OpenRCT2::RCT1
}
template<>
void S4Importer::ImportEntity<Guest>(const RCT12EntityBase& srcBase)
void S4Importer::ImportEntity<Guest>(GameState_t& gameState, const RCT12EntityBase& srcBase)
{
auto* dst = CreateEntityAt<Guest>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* dst = getGameState().entities.CreateEntityAt<Guest>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* src = static_cast<const RCT1::Peep*>(&srcBase);
ImportPeep(dst, src);
@@ -2997,9 +2997,9 @@ namespace OpenRCT2::RCT1
}
template<>
void S4Importer::ImportEntity<Staff>(const RCT12EntityBase& srcBase)
void S4Importer::ImportEntity<Staff>(GameState_t& gameState, const RCT12EntityBase& srcBase)
{
auto* dst = CreateEntityAt<Staff>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* dst = getGameState().entities.CreateEntityAt<Staff>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* src = static_cast<const RCT1::Peep*>(&srcBase);
ImportPeep(dst, src);
dst->AssignedStaffType = StaffType(src->StaffType);
@@ -3016,9 +3016,9 @@ namespace OpenRCT2::RCT1
}
template<>
void S4Importer::ImportEntity<Litter>(const RCT12EntityBase& srcBase)
void S4Importer::ImportEntity<Litter>(GameState_t& gameState, const RCT12EntityBase& srcBase)
{
auto* dst = CreateEntityAt<Litter>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* dst = getGameState().entities.CreateEntityAt<Litter>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* src = static_cast<const RCT12EntityLitter*>(&srcBase);
ImportEntityCommonProperties(dst, src);
@@ -3027,9 +3027,9 @@ namespace OpenRCT2::RCT1
}
template<>
void S4Importer::ImportEntity<SteamParticle>(const RCT12EntityBase& srcBase)
void S4Importer::ImportEntity<SteamParticle>(GameState_t& gameState, const RCT12EntityBase& srcBase)
{
auto* dst = CreateEntityAt<SteamParticle>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* dst = getGameState().entities.CreateEntityAt<SteamParticle>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* src = static_cast<const RCT12EntitySteamParticle*>(&srcBase);
ImportEntityCommonProperties(dst, src);
@@ -3038,9 +3038,9 @@ namespace OpenRCT2::RCT1
}
template<>
void S4Importer::ImportEntity<MoneyEffect>(const RCT12EntityBase& srcBase)
void S4Importer::ImportEntity<MoneyEffect>(GameState_t& gameState, const RCT12EntityBase& srcBase)
{
auto* dst = CreateEntityAt<MoneyEffect>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* dst = getGameState().entities.CreateEntityAt<MoneyEffect>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* src = static_cast<const RCT12EntityMoneyEffect*>(&srcBase);
ImportEntityCommonProperties(dst, src);
@@ -3053,9 +3053,9 @@ namespace OpenRCT2::RCT1
}
template<>
void S4Importer::ImportEntity<VehicleCrashParticle>(const RCT12EntityBase& srcBase)
void S4Importer::ImportEntity<VehicleCrashParticle>(GameState_t& gameState, const RCT12EntityBase& srcBase)
{
auto* dst = CreateEntityAt<VehicleCrashParticle>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* dst = getGameState().entities.CreateEntityAt<VehicleCrashParticle>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* src = static_cast<const RCT12EntityCrashedVehicleParticle*>(&srcBase);
ImportEntityCommonProperties(dst, src);
dst->frame = src->Frame;
@@ -3072,36 +3072,36 @@ namespace OpenRCT2::RCT1
}
template<>
void S4Importer::ImportEntity<ExplosionCloud>(const RCT12EntityBase& srcBase)
void S4Importer::ImportEntity<ExplosionCloud>(GameState_t& gameState, const RCT12EntityBase& srcBase)
{
auto* dst = CreateEntityAt<ExplosionCloud>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* dst = getGameState().entities.CreateEntityAt<ExplosionCloud>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* src = static_cast<const RCT12EntityParticle*>(&srcBase);
ImportEntityCommonProperties(dst, src);
dst->frame = src->Frame;
}
template<>
void S4Importer::ImportEntity<ExplosionFlare>(const RCT12EntityBase& srcBase)
void S4Importer::ImportEntity<ExplosionFlare>(GameState_t& gameState, const RCT12EntityBase& srcBase)
{
auto* dst = CreateEntityAt<ExplosionFlare>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* dst = getGameState().entities.CreateEntityAt<ExplosionFlare>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* src = static_cast<const RCT12EntityParticle*>(&srcBase);
ImportEntityCommonProperties(dst, src);
dst->frame = src->Frame;
}
template<>
void S4Importer::ImportEntity<CrashSplashParticle>(const RCT12EntityBase& srcBase)
void S4Importer::ImportEntity<CrashSplashParticle>(GameState_t& gameState, const RCT12EntityBase& srcBase)
{
auto* dst = CreateEntityAt<CrashSplashParticle>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* dst = getGameState().entities.CreateEntityAt<CrashSplashParticle>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* src = static_cast<const RCT12EntityParticle*>(&srcBase);
ImportEntityCommonProperties(dst, src);
dst->frame = src->Frame;
}
template<>
void S4Importer::ImportEntity<JumpingFountain>(const RCT12EntityBase& srcBase)
void S4Importer::ImportEntity<JumpingFountain>(GameState_t& gameState, const RCT12EntityBase& srcBase)
{
auto* dst = CreateEntityAt<JumpingFountain>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* dst = getGameState().entities.CreateEntityAt<JumpingFountain>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* src = static_cast<const RCT12EntityJumpingFountain*>(&srcBase);
auto fountainType = JumpingFountainType::Water;
@@ -3119,9 +3119,9 @@ namespace OpenRCT2::RCT1
}
template<>
void S4Importer::ImportEntity<Balloon>(const RCT12EntityBase& srcBase)
void S4Importer::ImportEntity<Balloon>(GameState_t& gameState, const RCT12EntityBase& srcBase)
{
auto* dst = CreateEntityAt<Balloon>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* dst = getGameState().entities.CreateEntityAt<Balloon>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* src = static_cast<const RCT12EntityBalloon*>(&srcBase);
ImportEntityCommonProperties(dst, src);
@@ -3140,9 +3140,9 @@ namespace OpenRCT2::RCT1
}
template<>
void S4Importer::ImportEntity<Duck>(const RCT12EntityBase& srcBase)
void S4Importer::ImportEntity<Duck>(GameState_t& gameState, const RCT12EntityBase& srcBase)
{
auto* dst = CreateEntityAt<Duck>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* dst = getGameState().entities.CreateEntityAt<Duck>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* src = static_cast<const RCT12EntityDuck*>(&srcBase);
ImportEntityCommonProperties(dst, src);
@@ -3152,48 +3152,48 @@ namespace OpenRCT2::RCT1
dst->state = static_cast<Duck::DuckState>(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<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
+46 -45
View File
@@ -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<typename OpenRCT2_T>
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<const RCT2::Vehicle*>(&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<const Peep*>(&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<const Peep*>(&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<const RCT12EntitySteamParticle*>(&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<const RCT12EntityMoneyEffect*>(&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<const RCT12EntityCrashedVehicleParticle*>(&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<const RCT12EntityParticle*>(&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<const RCT12EntityParticle*>(&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<const RCT12EntityParticle*>(&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<const RCT12EntityJumpingFountain*>(&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<const RCT12EntityBalloon*>(&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<const RCT12EntityDuck*>(&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<const RCT12EntityLitter*>(&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
+9 -9
View File
@@ -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>();
Vehicle* current = getGameState().entities.CreateEntity<Vehicle>();
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<Vehicle>(cable_lift_target);
Vehicle* cableLiftSecondPart = GetEntity<Vehicle>(prev_vehicle_on_ride);
Vehicle* passengerVehicle = getGameState().entities.GetEntity<Vehicle>(cable_lift_target);
Vehicle* cableLiftSecondPart = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(cable_lift_target);
Vehicle* passengerVehicle = getGameState().entities.GetEntity<Vehicle>(cable_lift_target);
if (passengerVehicle == nullptr)
{
return;
@@ -201,7 +201,7 @@ void Vehicle::CableLiftUpdateDeparting()
*/
void Vehicle::CableLiftUpdateTravelling()
{
Vehicle* passengerVehicle = GetEntity<Vehicle>(cable_lift_target);
Vehicle* passengerVehicle = getGameState().entities.GetEntity<Vehicle>(cable_lift_target);
if (passengerVehicle == nullptr)
{
return;
@@ -436,13 +436,13 @@ int32_t Vehicle::CableLiftUpdateTrackMotion()
vehicle->acceleration /= _vehicleUnkF64E10;
if (_vehicleVelocityF64E08 >= 0)
{
vehicle = GetEntity<Vehicle>(vehicle->next_vehicle_on_train);
vehicle = getGameState().entities.GetEntity<Vehicle>(vehicle->next_vehicle_on_train);
}
else
{
if (vehicle == this)
break;
vehicle = GetEntity<Vehicle>(vehicle->prev_vehicle_on_ride);
vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(Id); vehicle != nullptr;
vehicle = GetEntity<Vehicle>(vehicle->next_vehicle_on_train))
for (Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(Id); vehicle != nullptr;
vehicle = getGameState().entities.GetEntity<Vehicle>(vehicle->next_vehicle_on_train))
{
vehicleCount++;
+29 -27
View File
@@ -319,7 +319,7 @@ Guest* Ride::getQueueHeadGuest(StationIndex stationIndex) const
Guest* peep;
Guest* result = nullptr;
auto spriteIndex = getStation(stationIndex).LastPeepInQueue;
while ((peep = TryGetEntity<Guest>(spriteIndex)) != nullptr)
while ((peep = getGameState().entities.TryGetEntity<Guest>(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<Guest>(spriteIndex)) != nullptr)
while ((peep = getGameState().entities.TryGetEntity<Guest>(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<Guest>(raceWinner);
auto peep = getGameState().entities.GetEntity<Guest>(raceWinner);
if (peep != nullptr)
{
ft.Add<StringId>(STR_RACE_WON_BY);
@@ -1250,7 +1250,7 @@ void updateSpiralSlide(Ride& ride)
{
ride.slideInUse--;
auto* peep = GetEntity<Guest>(ride.slidePeep);
auto* peep = getGameState().entities.GetEntity<Guest>(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<Vehicle>(ride.vehicles[ride.brokenTrain]);
vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(ride.vehicles[ride.brokenTrain]);
vehicle = getGameState().entities.GetEntity<Vehicle>(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<Staff>(ride.mechanic);
auto staff = getGameState().entities.GetEntity<Staff>(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<Vehicle>(ride.vehicles[0]);
Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(ride.vehicles[measurement.vehicle_index]);
auto vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(vehicleSpriteIdx);
auto vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>();
auto* vehicle = getGameState().entities.CreateEntity<Vehicle>();
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<Vehicle>(ride.vehicles[0]);
Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(vehicles[i]);
Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(vehicles[i]);
auto train = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(car->next_vehicle_on_train))
for (Vehicle* car = train; car != nullptr;
car = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(car->next_vehicle_on_train))
for (Vehicle* car = train; car != nullptr; car = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(ride.vehicles[i]);
Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(ride.vehicles[i]); vehicle != nullptr;
vehicle = GetEntity<Vehicle>(vehicle->next_vehicle_on_train))
for (Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(ride.vehicles[i]); vehicle != nullptr;
vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(ride.vehicles[i]); vehicle != nullptr;
vehicle = GetEntity<Vehicle>(vehicle->next_vehicle_on_train))
for (Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(ride.vehicles[i]); vehicle != nullptr;
vehicle = getGameState().entities.GetEntity<Vehicle>(vehicle->next_vehicle_on_train))
{
switch (ride.vehicleColourSettings)
{
@@ -5265,7 +5267,7 @@ void Ride::setToDefaultInspectionInterval()
*/
void Ride::crash(uint8_t vehicleIndex)
{
Vehicle* vehicle = GetEntity<Vehicle>(vehicles[vehicleIndex]);
Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(vehicleIndex);
Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(vehicleIndex);
if (vehicle != nullptr)
{
return vehicle->GetCar(ride.brokenCar);
@@ -5481,8 +5483,8 @@ void FixInvalidVehicleSpriteSizes()
{
for (auto entityIndex : ride.vehicles)
{
for (Vehicle* vehicle = TryGetEntity<Vehicle>(entityIndex); vehicle != nullptr;
vehicle = TryGetEntity<Vehicle>(vehicle->next_vehicle_on_train))
for (Vehicle* vehicle = getGameState().entities.TryGetEntity<Vehicle>(entityIndex); vehicle != nullptr;
vehicle = getGameState().entities.TryGetEntity<Vehicle>(vehicle->next_vehicle_on_train))
{
auto carEntry = vehicle->Entry();
if (carEntry == nullptr)
+5 -5
View File
@@ -157,14 +157,14 @@ static void ride_remove_cable_lift(Ride& ride)
auto spriteIndex = ride.cableLift;
do
{
Vehicle* vehicle = GetEntity<Vehicle>(spriteIndex);
Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(spriteIndex);
Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(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);
}
}
}
+7 -7
View File
@@ -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<Vehicle>(ride.vehicles[i]);
Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(ride.vehicles[i]);
Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(ride.vehicles[i]);
Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(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<Guest>(vehicle->peep[0]);
auto* peep = getGameState().entities.GetEntity<Guest>(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<Vehicle>(ride.vehicles[i]);
Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(ride.vehicles[i]);
Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(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<Guest>(vehicle->peep[0]);
auto* guest = getGameState().entities.GetEntity<Guest>(vehicle->peep[0]);
// Easter egg names should only work on guests
if (guest != nullptr)
+2 -2
View File
@@ -21,7 +21,7 @@ namespace OpenRCT2::TrainManager
while (iter != end && Entity == nullptr)
{
Entity = GetEntity<Vehicle>(*iter++);
Entity = getGameState().entities.GetEntity<Vehicle>(*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
+71 -67
View File
@@ -606,7 +606,7 @@ void Vehicle::UpdateTrackChange()
Vehicle* TryGetVehicle(EntityId spriteIndex)
{
return TryGetEntity<Vehicle>(spriteIndex);
return getGameState().entities.TryGetEntity<Vehicle>(spriteIndex);
}
void VehicleSoundsUpdate()
@@ -647,8 +647,8 @@ bool Vehicle::CloseRestraints()
return true;
bool restraintsClosed = true;
for (Vehicle* vehicle = GetEntity<Vehicle>(Id); vehicle != nullptr;
vehicle = GetEntity<Vehicle>(vehicle->next_vehicle_on_train))
for (Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(Id); vehicle != nullptr;
vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(curRide->vehicles[curRide->brokenTrain]);
Vehicle* broken_vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(Id); vehicle != nullptr;
vehicle = GetEntity<Vehicle>(vehicle->next_vehicle_on_train))
for (Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(Id); vehicle != nullptr;
vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(curRide->vehicles[curRide->brokenTrain]);
Vehicle* broken_vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(Id); trainCar != nullptr;
trainCar = GetEntity<Vehicle>(trainCar->next_vehicle_on_train))
for (const Vehicle* trainCar = getGameState().entities.GetEntity<Vehicle>(Id); trainCar != nullptr;
trainCar = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(train_id);
Vehicle* train = getGameState().entities.GetEntity<Vehicle>(train_id);
if (train == nullptr)
continue;
@@ -1810,8 +1810,8 @@ void Vehicle::UpdateWaitingToDepart()
}
else
{
for (const Vehicle* trainCar = GetEntity<Vehicle>(Id); trainCar != nullptr;
trainCar = GetEntity<Vehicle>(trainCar->next_vehicle_on_train))
for (const Vehicle* trainCar = getGameState().entities.GetEntity<Vehicle>(Id); trainCar != nullptr;
trainCar = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(ride->vehicles[i]);
auto* vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(curRide->vehicles[i]);
Vehicle* v = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(sv_ride->vehicles[i]);
auto* otherVehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(sv->vehicle_id);
auto v = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(Id); vehicle != nullptr;
vehicle = GetEntity<Vehicle>(vehicle->next_vehicle_on_train))
for (Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(Id); vehicle != nullptr;
vehicle = getGameState().entities.GetEntity<Vehicle>(vehicle->next_vehicle_on_train))
{
for (int32_t i = 0; i < vehicle->num_peeps; ++i)
{
auto* curPeep = GetEntity<Guest>(vehicle->peep[i]);
auto* curPeep = getGameState().entities.GetEntity<Guest>(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<Vehicle>(Id); train != nullptr; train = GetEntity<Vehicle>(train->next_vehicle_on_train))
for (Vehicle* train = getGameState().entities.GetEntity<Vehicle>(Id); train != nullptr;
train = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(prev_vehicle_on_ride);
auto nextTrain = GetEntity<Vehicle>(lastVehicle->next_vehicle_on_ride);
auto prevTrain = getGameState().entities.GetEntity<Vehicle>(prev_vehicle_on_ride);
auto nextTrain = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(spriteId);
trainVehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(prev_vehicle_on_ride);
auto nextTrain = GetEntity<Vehicle>(lastVehicle->next_vehicle_on_ride);
auto prevTrain = getGameState().entities.GetEntity<Vehicle>(prev_vehicle_on_ride);
auto nextTrain = getGameState().entities.GetEntity<Vehicle>(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<Guest>(peep[seat * 2]);
auto firstGuest = getGameState().entities.GetEntity<Guest>(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<Guest>(peep[seat * 2 + 1]);
auto secondGuest = getGameState().entities.GetEntity<Guest>(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<Vehicle>(Id); train != nullptr;
train = GetEntity<Vehicle>(train->next_vehicle_on_train))
for (Vehicle* train = getGameState().entities.GetEntity<Vehicle>(Id); train != nullptr;
train = getGameState().entities.GetEntity<Vehicle>(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<Guest>(train->peep[peepIndex]);
Peep* curPeep = getGameState().entities.GetEntity<Guest>(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<Vehicle>(Id); train != nullptr; train = GetEntity<Vehicle>(train->next_vehicle_on_train))
for (Vehicle* train = getGameState().entities.GetEntity<Vehicle>(Id); train != nullptr;
train = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(curRide->cableLift);
Vehicle* cableLift = getGameState().entities.GetEntity<Vehicle>(curRide->cableLift);
if (cableLift == nullptr)
return;
@@ -4592,8 +4594,8 @@ void Vehicle::KillAllPassengersInTrain()
ride_train_crash(*curRide, NumPeepsUntilTrainTail());
for (Vehicle* trainCar = GetEntity<Vehicle>(Id); trainCar != nullptr;
trainCar = GetEntity<Vehicle>(trainCar->next_vehicle_on_train))
for (Vehicle* trainCar = getGameState().entities.GetEntity<Vehicle>(Id); trainCar != nullptr;
trainCar = getGameState().entities.GetEntity<Vehicle>(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<Guest>(peep[i]);
auto* curPeep = getGameState().entities.GetEntity<Guest>(peep[i]);
if (curPeep == nullptr)
continue;
@@ -4769,8 +4771,8 @@ void Vehicle::CrashOnWater()
*/
void Vehicle::UpdateCrash()
{
for (Vehicle* curVehicle = GetEntity<Vehicle>(Id); curVehicle != nullptr;
curVehicle = GetEntity<Vehicle>(curVehicle->next_vehicle_on_train))
for (Vehicle* curVehicle = getGameState().entities.GetEntity<Vehicle>(Id); curVehicle != nullptr;
curVehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(Id); vehicle2 != nullptr;
vehicle2 = GetEntity<Vehicle>(vehicle2->next_vehicle_on_train))
for (Vehicle* vehicle2 = getGameState().entities.GetEntity<Vehicle>(Id); vehicle2 != nullptr;
vehicle2 = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(Id); vehicle2 != nullptr;
vehicle2 = GetEntity<Vehicle>(vehicle2->next_vehicle_on_train))
for (Vehicle* vehicle2 = getGameState().entities.GetEntity<Vehicle>(Id); vehicle2 != nullptr;
vehicle2 = getGameState().entities.GetEntity<Vehicle>(vehicle2->next_vehicle_on_train))
{
if (vehicle2->Pitch < 5)
continue;
@@ -5127,7 +5129,7 @@ Vehicle* Vehicle::TrainHead() const
for (;;)
{
prevVehicle = GetEntity<Vehicle>(vehicle->prev_vehicle_on_ride);
prevVehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(spriteIndex);
vehicle = getGameState().entities.GetEntity<Vehicle>(spriteIndex);
if (vehicle == nullptr)
{
return const_cast<Vehicle*>(this);
@@ -5276,7 +5278,7 @@ int32_t Vehicle::UpdateMotionDodgems()
velocity = 0;
uint8_t direction = Orientation | 1;
Vehicle* collideVehicle = GetEntity<Vehicle>(collideSprite.value());
Vehicle* collideVehicle = getGameState().entities.GetEntity<Vehicle>(collideSprite.value());
if (collideVehicle != nullptr)
{
var_34 = (ScenarioRand() & 1) ? 1 : -1;
@@ -6507,11 +6509,11 @@ void Vehicle::UpdateHandleWaterSplash() const
{
if (IsOnCoveredTrack())
{
Vehicle* nextVehicle = GetEntity<Vehicle>(next_vehicle_on_ride);
Vehicle* nextVehicle = getGameState().entities.GetEntity<Vehicle>(next_vehicle_on_ride);
if (nextVehicle == nullptr)
return;
Vehicle* nextNextVehicle = GetEntity<Vehicle>(nextVehicle->next_vehicle_on_ride);
Vehicle* nextNextVehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(*otherVehicleIndex);
Vehicle* collideVehicle = getGameState().entities.GetEntity<Vehicle>(*otherVehicleIndex);
if (collideVehicle == nullptr)
return false;
@@ -6781,8 +6783,8 @@ bool Vehicle::UpdateMotionCollisionDetection(const CoordsXYZ& loc, EntityId* oth
*/
void Vehicle::ReverseReverserCar()
{
Vehicle* previousVehicle = GetEntity<Vehicle>(prev_vehicle_on_ride);
Vehicle* nextVehicle = GetEntity<Vehicle>(next_vehicle_on_ride);
Vehicle* previousVehicle = getGameState().entities.GetEntity<Vehicle>(prev_vehicle_on_ride);
Vehicle* nextVehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(otherVehicleIndex);
auto otherVeh = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(otherVehicleIndex);
Vehicle* v3 = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(vehicleIdx);
Vehicle* vEDI = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(vehicleIdx);
Vehicle* vEDI = getGameState().entities.GetEntity<Vehicle>(vehicleIdx);
if (vEDI == nullptr)
{
return Vehicle::UpdateMiniGolfSubroutineStatus::stop;
@@ -7839,7 +7841,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c
for (;;)
{
vEDI = GetEntity<Vehicle>(vEDI->prev_vehicle_on_ride);
vEDI = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(prev_vehicle_on_ride);
Vehicle* prevVehicle = getGameState().entities.GetEntity<Vehicle>(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<Guest>(peep[0]);
auto* curPeep = getGameState().entities.TryGetEntity<Guest>(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<Vehicle>(otherVehicleIndex);
Vehicle* vEBP = getGameState().entities.GetEntity<Vehicle>(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>(vehicle->next_vehicle_on_train))
for (Vehicle* vehicle = this; vehicle != nullptr;
vehicle = getGameState().entities.GetEntity<Vehicle>(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>(vehicle->next_vehicle_on_train);
vehicle = getGameState().entities.GetEntity<Vehicle>(vehicle->next_vehicle_on_train);
}
else
{
@@ -8391,7 +8394,7 @@ int32_t Vehicle::UpdateTrackMotionMiniGolf(int32_t* outStation)
{
break;
}
vehicle = GetEntity<Vehicle>(vehicle->prev_vehicle_on_ride);
vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(spriteId);
Vehicle* car = getGameState().entities.GetEntity<Vehicle>(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>(vehicle->next_vehicle_on_train))
for (; vehicle != nullptr; vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(Id); vehicle != nullptr;
vehicle = GetEntity<Vehicle>(vehicle->next_vehicle_on_train))
for (const Vehicle* vehicle = getGameState().entities.GetEntity<Vehicle>(Id); vehicle != nullptr;
vehicle = getGameState().entities.GetEntity<Vehicle>(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<Vehicle>(v->prev_vehicle_on_ride);
v = getGameState().entities.GetEntity<Vehicle>(v->prev_vehicle_on_ride);
}
return v;
}
@@ -8954,7 +8957,7 @@ Vehicle* Vehicle::GetCar(size_t carIndex) const
auto car = const_cast<Vehicle*>(this);
for (; carIndex != 0; carIndex--)
{
car = GetEntity<Vehicle>(car->next_vehicle_on_train);
car = getGameState().entities.GetEntity<Vehicle>(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>(vehicle->next_vehicle_on_train))
for (auto vehicle = this; vehicle != nullptr;
vehicle = getGameState().entities.GetEntity<Vehicle>(vehicle->next_vehicle_on_train))
{
vehicle->ClearFlag(VehicleFlags::CollisionDisabled);
}
+2 -1
View File
@@ -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<Vehicle>(prev_vehicle_on_ride);
Vehicle* prevVehicle = getGameState().entities.GetEntity<Vehicle>(prev_vehicle_on_ride);
if (prevVehicle != nullptr && this != prevVehicle && _vehicleVelocityF64E08 > minFollowVelocity)
{
int32_t followDistance = std::max(minFollowDistance, (riderSettings.followDistance * _vehicleVelocityF64E08) >> 15);
@@ -28,7 +28,7 @@ namespace OpenRCT2::Scripting
Balloon* ScBalloon::GetBalloon() const
{
return OpenRCT2::GetEntity<Balloon>(_id);
return OpenRCT2::getGameState().entities.GetEntity<Balloon>(_id);
}
uint8_t ScBalloon::colour_get() const
@@ -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:
@@ -194,7 +194,7 @@ namespace OpenRCT2::Scripting
Guest* ScGuest::GetGuest() const
{
return OpenRCT2::GetEntity<Guest>(_id);
return OpenRCT2::getGameState().entities.GetEntity<Guest>(_id);
}
uint8_t ScGuest::tshirtColour_get() const
@@ -45,7 +45,7 @@ namespace OpenRCT2::Scripting
Litter* ScLitter::GetLitter() const
{
return OpenRCT2::GetEntity<Litter>(_id);
return OpenRCT2::getGameState().entities.GetEntity<Litter>(_id);
}
std::string ScLitter::litterType_get() const
@@ -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<MoneyEffect>(_id);
return OpenRCT2::getGameState().entities.GetEntity<MoneyEffect>(_id);
}
money64 ScMoneyEffect::value_get() const
@@ -49,7 +49,7 @@ namespace OpenRCT2::Scripting
VehicleCrashParticle* ScCrashedVehicleParticle::GetCrashedVehicleParticle() const
{
return OpenRCT2::GetEntity<VehicleCrashParticle>(_id);
return OpenRCT2::getGameState().entities.GetEntity<VehicleCrashParticle>(_id);
}
void ScCrashedVehicleParticle::frame_set(uint8_t value)
@@ -196,7 +196,7 @@ namespace OpenRCT2::Scripting
protected:
Peep* GetPeep() const
{
return OpenRCT2::GetEntity<Peep>(_id);
return OpenRCT2::getGameState().entities.GetEntity<Peep>(_id);
}
};
@@ -44,7 +44,7 @@ namespace OpenRCT2::Scripting
Staff* ScStaff::GetStaff() const
{
return OpenRCT2::GetEntity<Staff>(_id);
return OpenRCT2::getGameState().entities.GetEntity<Staff>(_id);
}
std::string ScStaff::staffType_get() const
@@ -421,7 +421,7 @@ namespace OpenRCT2::Scripting
Staff* ScHandyman::GetHandyman() const
{
return OpenRCT2::GetEntity<Staff>(_id);
return OpenRCT2::getGameState().entities.GetEntity<Staff>(_id);
}
DukValue ScHandyman::lawnsMown_get() const
@@ -502,7 +502,7 @@ namespace OpenRCT2::Scripting
Staff* ScMechanic::GetMechanic() const
{
return OpenRCT2::GetEntity<Staff>(_id);
return OpenRCT2::getGameState().entities.GetEntity<Staff>(_id);
}
DukValue ScMechanic::ridesFixed_get() const
@@ -550,7 +550,7 @@ namespace OpenRCT2::Scripting
Staff* ScSecurity::GetSecurity() const
{
return OpenRCT2::GetEntity<Staff>(_id);
return OpenRCT2::getGameState().entities.GetEntity<Staff>(_id);
}
DukValue ScSecurity::vandalsStopped_get() const
@@ -585,7 +585,7 @@ namespace OpenRCT2::Scripting
Staff* ScPatrolArea::GetStaff() const
{
return GetEntity<Staff>(_staffId);
return getGameState().entities.GetEntity<Staff>(_staffId);
}
void ScPatrolArea::ModifyArea(const DukValue& coordsOrRange, bool value) const
@@ -102,7 +102,7 @@ namespace OpenRCT2::Scripting
Vehicle* ScVehicle::GetVehicle() const
{
return ::GetEntity<Vehicle>(_id);
return ::getGameState().entities.GetEntity<Vehicle>(_id);
}
ObjectEntryIndex ScVehicle::rideObject_get() const
@@ -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<Vehicle>(carId);
auto car = getGameState().entities.GetEntity<Vehicle>(carId);
if (car == nullptr)
{
@@ -181,7 +181,7 @@ namespace OpenRCT2::Scripting
{
for (auto sprite : EntityList<Staff>())
{
auto staff = GetEntity<Staff>(sprite->Id);
auto staff = getGameState().entities.GetEntity<Staff>(sprite->Id);
if (staff != nullptr)
{
switch (staff->AssignedStaffType)
@@ -277,7 +277,7 @@ namespace OpenRCT2::Scripting
{
for (auto sprite : EntityTileList<Staff>(pos))
{
auto staff = GetEntity<Staff>(sprite->Id);
auto staff = getGameState().entities.GetEntity<Staff>(sprite->Id);
if (staff != nullptr)
{
switch (staff->AssignedStaffType)
@@ -321,7 +321,7 @@ namespace OpenRCT2::Scripting
template<typename TEntityType, typename TScriptType>
DukValue createEntityType(duk_context* ctx, const DukValue& initializer)
{
TEntityType* entity = CreateEntity<TEntityType>();
TEntityType* entity = getGameState().entities.CreateEntity<TEntityType>();
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>();
Vehicle* entity = getGameState().entities.CreateEntity<Vehicle>();
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<ScVehicle>(spriteId));
case EntityType::Staff:
{
auto staff = GetEntity<Staff>(spriteId);
auto staff = getGameState().entities.GetEntity<Staff>(spriteId);
if (staff != nullptr)
{
switch (staff->AssignedStaffType)
+1 -1
View File
@@ -141,7 +141,7 @@ void FootpathRemoveLitter(const CoordsXYZ& footpathPos)
for (auto* litter : removals)
{
litter->Invalidate();
EntityRemove(litter);
getGameState().entities.EntityRemove(litter);
}
}
+2 -2
View File
@@ -2268,10 +2268,10 @@ void ShiftMap(const TileCoordsXY& amount)
for (auto i = 0; i < EnumValue(EntityType::Count); i++)
{
auto entityType = static_cast<EntityType>(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);
+1 -1
View File
@@ -56,7 +56,7 @@ static std::unique_ptr<IContext> localStartGame(const std::string& parkPath)
auto& gameState = getGameState();
importer->Import(gameState);
ResetEntitySpatialIndices();
gameState.entities.ResetEntitySpatialIndices();
ResetAllSpriteQuadrantPlacements();
LoadPalette();
+2 -1
View File
@@ -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();