From 3d4b106059037829b3f8fa3b4a3d84a3830f9d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Mon, 6 Jan 2025 19:39:44 +0200 Subject: [PATCH 1/6] Ensure ride station queue is not uninitialized, refactor that code --- src/openrct2/actions/RideCreateAction.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/openrct2/actions/RideCreateAction.cpp b/src/openrct2/actions/RideCreateAction.cpp index be4d39e8c6..ff98827b7b 100644 --- a/src/openrct2/actions/RideCreateAction.cpp +++ b/src/openrct2/actions/RideCreateAction.cpp @@ -28,6 +28,8 @@ #include "../scenario/Scenario.h" #include "../world/Park.h" +#include + using namespace OpenRCT2; RideCreateAction::RideCreateAction( @@ -147,18 +149,8 @@ GameActions::Result RideCreateAction::Execute() const ride->overall_view.SetNull(); ride->SetNameToDefault(); - for (auto& station : ride->GetStations()) - { - station.Start.SetNull(); - station.Entrance.SetNull(); - station.Exit.SetNull(); - station.TrainAtStation = RideStation::kNoTrain; - station.QueueTime = 0; - station.SegmentLength = 0; - station.QueueLength = 0; - station.Length = 0; - station.Height = 0; - } + // Default initialize all stations. + std::ranges::fill(ride->GetStations(), RideStation{}); ride->status = RideStatus::Closed; ride->NumTrains = 1; From 1d7bd7ac27ffde0eb0bc7588274b19abe90ab8b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Mon, 6 Jan 2025 19:54:56 +0200 Subject: [PATCH 2/6] Use std::span for GetStations --- src/openrct2/ride/Ride.cpp | 4 ++-- src/openrct2/ride/Ride.h | 5 +++-- src/openrct2/ride/Vehicle.cpp | 2 +- src/openrct2/world/Map.cpp | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 796c6d8abc..333d49c524 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -1046,12 +1046,12 @@ const RideStation& Ride::GetStation(StationIndex stationIndex) const return stations[stationIndex.ToUnderlying()]; } -std::array& Ride::GetStations() +std::span Ride::GetStations() { return stations; } -const std::array& Ride::GetStations() const +std::span Ride::GetStations() const { return stations; } diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index 3db9ed6e76..36b302156b 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -28,6 +28,7 @@ #include #include #include +#include #include struct IObjectManager; @@ -293,8 +294,8 @@ private: public: RideStation& GetStation(StationIndex stationIndex = StationIndex::FromUnderlying(0)); const RideStation& GetStation(StationIndex stationIndex = StationIndex::FromUnderlying(0)) const; - std::array& GetStations(); - const std::array& GetStations() const; + std::span GetStations(); + std::span GetStations() const; StationIndex GetStationIndex(const RideStation* station) const; // Returns the logical station number from the given station. Index 0 = station 1, index 1 = station 2. It accounts for gaps diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 8dfa7c7be1..ad7518d355 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -2308,7 +2308,7 @@ static void test_finish(Ride& ride) ride.lifecycle_flags &= ~RIDE_LIFECYCLE_TEST_IN_PROGRESS; ride.lifecycle_flags |= RIDE_LIFECYCLE_TESTED; - auto& rideStations = ride.GetStations(); + auto rideStations = ride.GetStations(); for (int32_t i = ride.num_stations - 1; i >= 1; i--) { if (rideStations[i - 1].SegmentTime != 0) diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 7ed0c325f3..cc1a0efd54 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -2352,7 +2352,7 @@ void ShiftMap(const TileCoordsXY& amount) // Rides for (auto& ride : GetRideManager()) { - auto& stations = ride.GetStations(); + auto stations = ride.GetStations(); for (auto& station : stations) { shiftIfNotNull(station.Start, amountToMove); From 33782c723d72ad3d52a0e4ec722a67cd693f0e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Mon, 6 Jan 2025 19:55:36 +0200 Subject: [PATCH 3/6] Allow save/load for std::span, simplify ReadWriteArray --- src/openrct2/core/OrcaStream.hpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/openrct2/core/OrcaStream.hpp b/src/openrct2/core/OrcaStream.hpp index a4030e4c40..d59cdb53cc 100644 --- a/src/openrct2/core/OrcaStream.hpp +++ b/src/openrct2/core/OrcaStream.hpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -468,15 +469,8 @@ namespace OpenRCT2 } } - template - void ReadWriteArray(TArr (&arr)[TArrSize], TFunc f) - { - auto& arr2 = *(reinterpret_cast*>(arr)); - ReadWriteArray(arr2, f); - } - - template - void ReadWriteArray(std::array& arr, TFunc f) + template + void ReadWriteArray(std::span arr, TFunc f) { if (_mode == Mode::READING) { @@ -487,7 +481,7 @@ namespace OpenRCT2 } for (size_t i = 0; i < count; i++) { - if (i < TArrSize) + if (i < arr.size()) { f(arr[i]); } @@ -509,6 +503,18 @@ namespace OpenRCT2 } } + template + void ReadWriteArray(TArr (&arr)[TArrSize], TFunc f) + { + ReadWriteArray(std::span{ arr, TArrSize }, f); + } + + template + void ReadWriteArray(std::array& arr, TFunc f) + { + ReadWriteArray(std::span{ arr.begin(), arr.end() }, f); + } + template void Ignore() { From 5261a5c10297fb3fadf261124454a327aaf34e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Mon, 6 Jan 2025 20:04:39 +0200 Subject: [PATCH 4/6] Make sure that GuestNextInQueue is not uninitialized --- src/openrct2/entity/EntityRegistry.cpp | 2 ++ src/openrct2/entity/Guest.cpp | 1 + 2 files changed, 3 insertions(+) diff --git a/src/openrct2/entity/EntityRegistry.cpp b/src/openrct2/entity/EntityRegistry.cpp index de7e54a43d..f4592de1d0 100644 --- a/src/openrct2/entity/EntityRegistry.cpp +++ b/src/openrct2/entity/EntityRegistry.cpp @@ -531,6 +531,8 @@ static void FreeEntity(EntityBase& entity) else if (guest != nullptr) { guest->SetName({}); + guest->GuestNextInQueue = EntityId::GetNull(); + OpenRCT2::RideUse::GetHistory().RemoveHandle(guest->Id); OpenRCT2::RideUse::GetTypeHistory().RemoveHandle(guest->Id); } diff --git a/src/openrct2/entity/Guest.cpp b/src/openrct2/entity/Guest.cpp index 9b14e4b5cc..bec70cc448 100644 --- a/src/openrct2/entity/Guest.cpp +++ b/src/openrct2/entity/Guest.cpp @@ -7280,6 +7280,7 @@ Guest* Guest::Generate(const CoordsXYZ& coords) peep->ResetPathfindGoal(); peep->RemoveAllItems(); peep->GuestHeadingToRideId = RideId::GetNull(); + peep->GuestNextInQueue = EntityId::GetNull(); peep->LitterCount = 0; peep->DisgustingCount = 0; peep->VandalismSeen = 0; From a9cafb37eb413cd930573dbf843ef5dbe853dba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Fri, 10 Jan 2025 01:10:14 +0200 Subject: [PATCH 5/6] Assign Station Start, Entrance, Exit, to null sentinel --- src/openrct2/actions/RideCreateAction.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/openrct2/actions/RideCreateAction.cpp b/src/openrct2/actions/RideCreateAction.cpp index ff98827b7b..235106cf61 100644 --- a/src/openrct2/actions/RideCreateAction.cpp +++ b/src/openrct2/actions/RideCreateAction.cpp @@ -150,7 +150,11 @@ GameActions::Result RideCreateAction::Execute() const ride->SetNameToDefault(); // Default initialize all stations. - std::ranges::fill(ride->GetStations(), RideStation{}); + RideStation station{}; + station.Start.SetNull(); + station.Entrance.SetNull(); + station.Exit.SetNull(); + std::ranges::fill(ride->GetStations(), station); ride->status = RideStatus::Closed; ride->NumTrains = 1; From 7eb8556c606d6f3ed1054afd4e7365224ef15a4c Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Fri, 10 Jan 2025 13:43:14 +0100 Subject: [PATCH 6/6] Update replays to v0.0.86 --- CMakeLists.txt | 4 ++-- openrct2.proj | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 38a7072f10..014a32925c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,9 +81,9 @@ set(OPENMSX_VERSION "1.6") set(OPENMSX_URL "https://github.com/OpenRCT2/OpenMusic/releases/download/v${OPENMSX_VERSION}/openmusic.zip") set(OPENMSX_SHA1 "ba170fa6d777b309c15420f4b6eb3fa25082a9d1") -set(REPLAYS_VERSION "0.0.85") +set(REPLAYS_VERSION "0.0.86") set(REPLAYS_URL "https://github.com/OpenRCT2/replays/releases/download/v${REPLAYS_VERSION}/replays.zip") -set(REPLAYS_SHA1 "2B0939953A41D2CE82809CB7C21FC3883578383F") +set(REPLAYS_SHA1 "637E73F20C03DCD52ACA36FAEE15DADB31797FE0") option(FORCE32 "Force 32-bit build. It will add `-m32` to compiler flags.") option(WITH_TESTS "Build tests") diff --git a/openrct2.proj b/openrct2.proj index 4ec99e95d6..a8e1d0ac7f 100644 --- a/openrct2.proj +++ b/openrct2.proj @@ -51,8 +51,8 @@ b1b1f1b241d2cbff63a1889c4dc5a09bdf769bfb https://github.com/OpenRCT2/OpenMusic/releases/download/v1.6/openmusic.zip ba170fa6d777b309c15420f4b6eb3fa25082a9d1 - https://github.com/OpenRCT2/replays/releases/download/v0.0.85/replays.zip - 2B0939953A41D2CE82809CB7C21FC3883578383F + https://github.com/OpenRCT2/replays/releases/download/v0.0.86/replays.zip + 637E73F20C03DCD52ACA36FAEE15DADB31797FE0