From 6f5bd14895bfd5a3b8c0f6e0ea04e689f3042c14 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sat, 10 Oct 2026 16:03:17 +0200 Subject: [PATCH 01/33] Start v0.5.6+1 --- distribution/changelog.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index d90c64ccc8..12bdfb6893 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -1,3 +1,6 @@ +0.5.7 (in development) +------------------------------------------------------------------------ + 0.5.6 (2026-10-10) ------------------------------------------------------------------------ - Feature: [#16014] Land surfaces and edges can now be recoloured. From c40737c839f9f2eafb9b8f594f7cea815f083101 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek <1478678+Gymnasiast@users.noreply.github.com> Date: Sat, 10 Oct 2026 18:09:41 +0200 Subject: [PATCH 02/33] Fix #27264: Headless server crashes when loading a recolourable terrain surface (#27265) --- src/openrct2/object/TerrainSurfaceObject.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/openrct2/object/TerrainSurfaceObject.cpp b/src/openrct2/object/TerrainSurfaceObject.cpp index 64085ddb16..0ed634e840 100644 --- a/src/openrct2/object/TerrainSurfaceObject.cpp +++ b/src/openrct2/object/TerrainSurfaceObject.cpp @@ -10,6 +10,7 @@ #include "TerrainSurfaceObject.h" #include "../Context.h" +#include "../OpenRCT2.h" #include "../core/Guard.hpp" #include "../core/Json.hpp" #include "../drawing/ColourMap.h" @@ -34,6 +35,9 @@ namespace OpenRCT2 void TerrainSurfaceObject::precolourPatternImages() { + if (gOpenRCT2NoGraphics) + return; + for (size_t colourNum = 0; colourNum < Drawing::kColourNumTotal; colourNum++) { for (uint8_t patternOffset = 0; patternOffset < kNumSmoothingPatternImages; patternOffset++) @@ -76,6 +80,9 @@ namespace OpenRCT2 void TerrainSurfaceObject::unloadPrecolouredPatternImages() { + if (gOpenRCT2NoGraphics) + return; + GfxObjectFreeImages(precolouredPatternImageId, precolouredPatternImages.GetCount()); precolouredPatternImageId = 0; } From 6e42a9fe4c99f4ad1f2f59621621c0c9bb44a1bf Mon Sep 17 00:00:00 2001 From: Michael Steenbeek <1478678+Gymnasiast@users.noreply.github.com> Date: Sat, 10 Oct 2026 23:34:12 +0200 Subject: [PATCH 03/33] Add #27264 to changelog --- distribution/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 12bdfb6893..55ab16b444 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -1,5 +1,6 @@ 0.5.7 (in development) ------------------------------------------------------------------------ +- Fix: [#27264] Headless server crashes when loading a recolourable terrain surface. 0.5.6 (2026-10-10) ------------------------------------------------------------------------ From d28122de9325dfd4bc71c6f50d244355bba9a0d8 Mon Sep 17 00:00:00 2001 From: Dylan Date: Sun, 11 Oct 2026 04:14:22 -0500 Subject: [PATCH 04/33] Fix missing commit hash in container-built binaries (#27271) Git refuses to read the repo inside the container jobs because the workspace is owned by a different user, so CMake silently gets no branch or commit hash. Mark the workspace as a safe directory, as check-code-formatting already does. --- .github/workflows/ci.yml | 6 ++++++ distribution/changelog.txt | 1 + 2 files changed, 7 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29271e8895..d6cc8742de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -345,6 +345,7 @@ jobs: steps: - name: Checkout uses: actions/checkout@v7 + - run: git config --global --add safe.directory $PWD - name: ccache uses: hendrikmuhs/ccache-action@v1.2.21 with: @@ -490,6 +491,7 @@ jobs: steps: - name: Checkout uses: actions/checkout@v7 + - run: git config --global --add safe.directory $PWD - name: ccache uses: hendrikmuhs/ccache-action@v1.2.21 with: @@ -519,6 +521,7 @@ jobs: steps: - name: Checkout uses: actions/checkout@v7 + - run: git config --global --add safe.directory $PWD - name: ccache uses: hendrikmuhs/ccache-action@v1.2.21 with: @@ -574,6 +577,7 @@ jobs: steps: - name: Checkout uses: actions/checkout@v7 + - run: git config --global --add safe.directory $PWD - name: ccache uses: hendrikmuhs/ccache-action@v1.2.21 with: @@ -590,6 +594,7 @@ jobs: steps: - name: Checkout uses: actions/checkout@v7 + - run: git config --global --add safe.directory $PWD - name: ccache uses: hendrikmuhs/ccache-action@v1.2.21 with: @@ -738,6 +743,7 @@ jobs: steps: - name: Checkout uses: actions/checkout@v7 + - run: git config --global --add safe.directory $PWD - name: ccache uses: hendrikmuhs/ccache-action@v1.2.21 with: diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 55ab16b444..6d668ed984 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -1,5 +1,6 @@ 0.5.7 (in development) ------------------------------------------------------------------------ +- Fix: [#24524] Some build types (like AppImage) lack information about their specific build. - Fix: [#27264] Headless server crashes when loading a recolourable terrain surface. 0.5.6 (2026-10-10) From 41b1cd01bc266f00bd5786d805fd5a72510e1ad6 Mon Sep 17 00:00:00 2001 From: Richard Fine Date: Sun, 11 Oct 2026 05:26:19 -0400 Subject: [PATCH 05/33] Refactor: more use of the `Direction` type and helpers (#27237) Advance adoption of the 'Direction' type for cardinal directions: * Split `Direction` and its helpers out to their own header (`Direction.h`) * Replace loops that iterate all four directions with range-based loops * Replace some math with calls to helper functions. I also introduced a new `DirectionRotate()` function, a generalisation of `DirectionNext()`/`DirectionPrev()`. * Replace `uint8_t`/`int32_t` with `Direction` in some function signatures and field types, if the thing being passed/stored is supposed to be a cardinal direction In the process I also fixed two defects in the code: * The bitmask used to select the direction from a TD6EntranceElement was too wide - it was grabbing the low 4 bits, but only needs the low 2. * `CoordsXYZD.toTileCentre()` was taking the tile corner and adding a `CoordsXYZD` value to it, to add half-tile offsets to X and Y. So, it's more correct to add a `CoordsXY` value instead, and skip the unnecessary Z and D dimensions. --- src/openrct2-ui/windows/RideConstruction.cpp | 4 +- .../actions/park/ParkEntrancePlaceAction.cpp | 20 ++-- .../actions/park/ParkEntranceRemoveAction.cpp | 2 +- .../actions/peep/StaffHireNewAction.cpp | 6 +- .../actions/scenery/WallPlaceAction.cpp | 2 +- .../actions/track/TrackPlaceAction.cpp | 2 +- src/openrct2/entity/Guest.cpp | 2 +- src/openrct2/entity/JumpingFountain.cpp | 2 +- src/openrct2/paint/VirtualFloor.cpp | 4 +- .../paint/tile_element/Paint.Tunnel.cpp | 2 +- .../paint/tile_element/Paint.Tunnel.h | 4 +- src/openrct2/paint/track/TrackPaintGeneric.h | 2 +- src/openrct2/rct2/RCT2.h | 2 +- src/openrct2/ride/TrackDesign.cpp | 2 +- src/openrct2/ride/TrackIteration.cpp | 2 +- src/openrct2/ride/Vehicle.Station.cpp | 2 +- .../scenes/editor/EditorController.cpp | 2 +- .../bindings/world/ScPathNavigator.cpp | 2 +- src/openrct2/world/Direction.hpp | 85 ++++++++++++++ src/openrct2/world/Entrance.cpp | 4 +- src/openrct2/world/Footpath.cpp | 10 +- src/openrct2/world/Footpath.h | 2 +- src/openrct2/world/Location.hpp | 107 ++++-------------- src/openrct2/world/Map.cpp | 6 +- src/openrct2/world/Map.h | 4 +- src/openrct2/world/MapAnimation.cpp | 2 +- src/openrct2/world/QuarterTile.cpp | 2 +- src/openrct2/world/QuarterTile.h | 3 +- src/openrct2/world/TileInspector.cpp | 2 +- src/openrct2/world/Wall.cpp | 2 +- src/openrct2/world/Wall.h | 2 +- .../world/tile_element/BannerElement.cpp | 4 +- .../world/tile_element/BannerElement.h | 6 +- src/openrct2/world/tile_element/PathElement.h | 2 +- .../world/tile_element/TileElementBase.cpp | 2 +- 35 files changed, 163 insertions(+), 146 deletions(-) create mode 100644 src/openrct2/world/Direction.hpp diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 7d02a74e30..1d6a54ecb7 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -3467,7 +3467,7 @@ namespace OpenRCT2::Ui::Windows PathElement* pathsByDir[kNumOrthogonalDirections]; bool keepOrientation = false; - for (int8_t i = 0; i < kNumOrthogonalDirections; i++) + for (Direction i : kAllDirections) { const auto testLoc = CoordsXYZ{ *mapCoords + CoordsDirectionDelta[i], z }; if (!MapIsLocationOwned(testLoc)) @@ -3509,7 +3509,7 @@ namespace OpenRCT2::Ui::Windows if (!keepOrientation) { - for (int8_t i = 0; i < kNumOrthogonalDirections; i++) + for (Direction i : kAllDirections) { if (pathsByDir[i] != nullptr) { diff --git a/src/openrct2/actions/park/ParkEntrancePlaceAction.cpp b/src/openrct2/actions/park/ParkEntrancePlaceAction.cpp index a3292a3e4f..45f9979cd1 100644 --- a/src/openrct2/actions/park/ParkEntrancePlaceAction.cpp +++ b/src/openrct2/actions/park/ParkEntrancePlaceAction.cpp @@ -94,12 +94,12 @@ namespace OpenRCT2::GameActions { if (index == 1) { - entranceLoc += CoordsDirectionDelta[(_loc.direction - 1) & 0x3]; + entranceLoc += CoordsDirectionDelta[DirectionPrev(_loc.direction)]; } else if (index == 2) { - entranceLoc.x += CoordsDirectionDelta[(_loc.direction + 1) & 0x3].x * 2; - entranceLoc.y += CoordsDirectionDelta[(_loc.direction + 1) & 0x3].y * 2; + entranceLoc.x += CoordsDirectionDelta[DirectionNext(_loc.direction)].x * 2; + entranceLoc.y += CoordsDirectionDelta[DirectionNext(_loc.direction)].y * 2; } if (auto res2 = MapCanConstructAt({ entranceLoc, zLow, zHigh }, { 0b1111, 0 }); res2.error != Status::ok) @@ -143,13 +143,13 @@ namespace OpenRCT2::GameActions { if (index == ParkEntranceSequence::left) { - entranceLoc.x += CoordsDirectionDelta[(_loc.direction - 1) & 0x3].x; - entranceLoc.y += CoordsDirectionDelta[(_loc.direction - 1) & 0x3].y; + entranceLoc.x += CoordsDirectionDelta[DirectionPrev(_loc.direction)].x; + entranceLoc.y += CoordsDirectionDelta[DirectionPrev(_loc.direction)].y; } else if (index == ParkEntranceSequence::right) { - entranceLoc.x += CoordsDirectionDelta[(_loc.direction + 1) & 0x3].x * 2; - entranceLoc.y += CoordsDirectionDelta[(_loc.direction + 1) & 0x3].y * 2; + entranceLoc.x += CoordsDirectionDelta[DirectionNext(_loc.direction)].x * 2; + entranceLoc.y += CoordsDirectionDelta[DirectionNext(_loc.direction)].y * 2; } if (!flags.has(CommandFlag::ghost)) @@ -208,12 +208,12 @@ namespace OpenRCT2::GameActions { if (index == 1) { - entranceLoc += CoordsDirectionDelta[(_loc.direction - 1) & 0x3]; + entranceLoc += CoordsDirectionDelta[DirectionPrev(_loc.direction)]; } else if (index == 2) { - entranceLoc.x += CoordsDirectionDelta[(_loc.direction + 1) & 0x3].x * 2; - entranceLoc.y += CoordsDirectionDelta[(_loc.direction + 1) & 0x3].y * 2; + entranceLoc.x += CoordsDirectionDelta[DirectionNext(_loc.direction)].x * 2; + entranceLoc.y += CoordsDirectionDelta[DirectionNext(_loc.direction)].y * 2; } if (!MapCheckCapacityAndReorganise(entranceLoc, numTiles)) { diff --git a/src/openrct2/actions/park/ParkEntranceRemoveAction.cpp b/src/openrct2/actions/park/ParkEntranceRemoveAction.cpp index bb6ffcf2ae..fc26b7d9f7 100644 --- a/src/openrct2/actions/park/ParkEntranceRemoveAction.cpp +++ b/src/openrct2/actions/park/ParkEntranceRemoveAction.cpp @@ -80,7 +80,7 @@ namespace OpenRCT2::GameActions return Result(Status::invalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone); } - auto direction = (park.entrances[entranceIndex].direction - 1) & 3; + auto direction = DirectionPrev(park.entrances[entranceIndex].direction); // Centre (sign) ParkEntranceRemoveSegment(_loc); diff --git a/src/openrct2/actions/peep/StaffHireNewAction.cpp b/src/openrct2/actions/peep/StaffHireNewAction.cpp index 820f7de0a5..b601188b9a 100644 --- a/src/openrct2/actions/peep/StaffHireNewAction.cpp +++ b/src/openrct2/actions/peep/StaffHireNewAction.cpp @@ -279,11 +279,7 @@ namespace OpenRCT2::GameActions { auto rand = ScenarioRandMax(static_cast(park.entrances.size())); const auto& entrance = park.entrances[rand]; - auto dir = entrance.direction; - newLocation = entrance; - // TODO: Replace with CoordsDirectionDelta - newLocation.x += 16 + ((dir & 1) == 0 ? ((dir & 2) ? 32 : -32) : 0); - newLocation.y += 16 + ((dir & 1) == 1 ? ((dir & 2) ? -32 : 32) : 0); + newLocation = entrance + CoordsDirectionDelta[entrance.direction] + CoordsXY{ 16, 16 }; } else { diff --git a/src/openrct2/actions/scenery/WallPlaceAction.cpp b/src/openrct2/actions/scenery/WallPlaceAction.cpp index b115245cf3..6500438972 100644 --- a/src/openrct2/actions/scenery/WallPlaceAction.cpp +++ b/src/openrct2/actions/scenery/WallPlaceAction.cpp @@ -513,7 +513,7 @@ namespace OpenRCT2::GameActions continue; if (elementType == TileElementType::wall) { - int32_t direction = tileElement->getDirection(); + Direction direction = tileElement->getDirection(); if (_edge == direction) { auto res = Result(Status::noClearance, STR_CANT_BUILD_THIS_HERE, kStringIdNone); diff --git a/src/openrct2/actions/track/TrackPlaceAction.cpp b/src/openrct2/actions/track/TrackPlaceAction.cpp index 74762378d5..923da9531e 100644 --- a/src/openrct2/actions/track/TrackPlaceAction.cpp +++ b/src/openrct2/actions/track/TrackPlaceAction.cpp @@ -513,7 +513,7 @@ namespace OpenRCT2::GameActions uint8_t intersectingDirections = ted.sequenceData.sequences[blockIndex].allowedWallEdges; intersectingDirections ^= 0x0F; intersectingDirections = rol4(intersectingDirections, _origin.direction); - for (int32_t i = 0; i < kNumOrthogonalDirections; i++) + for (Direction i : kAllDirections) { if (intersectingDirections & (1 << i)) { diff --git a/src/openrct2/entity/Guest.cpp b/src/openrct2/entity/Guest.cpp index 295d8a5e15..fd89d06d3c 100644 --- a/src/openrct2/entity/Guest.cpp +++ b/src/openrct2/entity/Guest.cpp @@ -4908,7 +4908,7 @@ namespace OpenRCT2 uint8_t hedges[4]{ 0xFF, 0xFF, 0xFF, 0xFF }; uint8_t openCount = 0; uint8_t mazeReverseLastEdge = DirectionReverse(mazeLastEdge); - for (uint8_t i = 0; i < kNumOrthogonalDirections; ++i) + for (Direction i : kAllDirections) { if (!(mazeEntry & (1 << kMazeCurrentDirectionToOpenHedge[var37 / 4][i])) && i != mazeReverseLastEdge) { diff --git a/src/openrct2/entity/JumpingFountain.cpp b/src/openrct2/entity/JumpingFountain.cpp index 43fbf85cd2..580ef0b77d 100644 --- a/src/openrct2/entity/JumpingFountain.cpp +++ b/src/openrct2/entity/JumpingFountain.cpp @@ -98,7 +98,7 @@ namespace OpenRCT2 { case Pattern::cyclicSquares: // 0, 1, 2, 3 - for (int32_t i = 0; i < kNumOrthogonalDirections; i++) + for (Direction i : kAllDirections) { create( newType, { newLoc + _fountainDirectionsPositive[i], newZ }, _fountainDirections[i], diff --git a/src/openrct2/paint/VirtualFloor.cpp b/src/openrct2/paint/VirtualFloor.cpp index d796f9dee4..dfc0d42eed 100644 --- a/src/openrct2/paint/VirtualFloor.cpp +++ b/src/openrct2/paint/VirtualFloor.cpp @@ -316,9 +316,9 @@ void VirtualFloorPaint(PaintSession& session) // Try the four tiles next to us for the same parameters as above, // if our parameters differ we set an edge towards that tile - for (uint8_t i = 0; i < kNumOrthogonalDirections; i++) + for (Direction i : kAllDirections) { - uint8_t effectiveRotation = (kNumOrthogonalDirections + i - direction) % kNumOrthogonalDirections; + Direction effectiveRotation = (kNumOrthogonalDirections + i - direction) % kNumOrthogonalDirections; CoordsXY theirLocation = session.MapPosition + scenery_half_tile_offsets[effectiveRotation]; bool theyAreOccupied; diff --git a/src/openrct2/paint/tile_element/Paint.Tunnel.cpp b/src/openrct2/paint/tile_element/Paint.Tunnel.cpp index 38e12f95d8..2352e0e62a 100644 --- a/src/openrct2/paint/tile_element/Paint.Tunnel.cpp +++ b/src/openrct2/paint/tile_element/Paint.Tunnel.cpp @@ -39,7 +39,7 @@ void PaintUtilSetVerticalTunnel(PaintSession& session, uint16_t height) session.VerticalTunnelHeight = height / 16; } -void PaintUtilPushTunnelRotated(PaintSession& session, uint8_t direction, uint16_t height, TunnelType type) +void PaintUtilPushTunnelRotated(PaintSession& session, Direction direction, uint16_t height, TunnelType type) { if (direction & 1) { diff --git a/src/openrct2/paint/tile_element/Paint.Tunnel.h b/src/openrct2/paint/tile_element/Paint.Tunnel.h index 3d869f8635..5a73d9746d 100644 --- a/src/openrct2/paint/tile_element/Paint.Tunnel.h +++ b/src/openrct2/paint/tile_element/Paint.Tunnel.h @@ -83,7 +83,7 @@ TunnelType GetTunnelType(TunnelGroup tunnelGroup, TunnelSubType tunnelSubType); void PaintUtilPushTunnelLeft(PaintSession& session, uint16_t height, TunnelType type); void PaintUtilPushTunnelRight(PaintSession& session, uint16_t height, TunnelType type); void PaintUtilSetVerticalTunnel(PaintSession& session, uint16_t height); -void PaintUtilPushTunnelRotated(PaintSession& session, uint8_t direction, uint16_t height, TunnelType type); +void PaintUtilPushTunnelRotated(PaintSession& session, Direction direction, uint16_t height, TunnelType type); inline void PaintUtilPushTunnelLeft( PaintSession& session, uint16_t height, TunnelGroup tunnelGroup, TunnelSubType tunnelSubType) @@ -98,7 +98,7 @@ inline void PaintUtilPushTunnelRight( } inline void PaintUtilPushTunnelRotated( - PaintSession& session, uint8_t direction, uint16_t height, TunnelGroup tunnelGroup, TunnelSubType tunnelSubType) + PaintSession& session, Direction direction, uint16_t height, TunnelGroup tunnelGroup, TunnelSubType tunnelSubType) { PaintUtilPushTunnelRotated(session, direction, height, GetTunnelType(tunnelGroup, tunnelSubType)); } diff --git a/src/openrct2/paint/track/TrackPaintGeneric.h b/src/openrct2/paint/track/TrackPaintGeneric.h index 5ee1a888e5..a57e31e028 100644 --- a/src/openrct2/paint/track/TrackPaintGeneric.h +++ b/src/openrct2/paint/track/TrackPaintGeneric.h @@ -27,7 +27,7 @@ namespace OpenRCT2 { const size_t directionOffset = sequenceCount * spriteCount; uint64_t spriteMap = 0; - for (size_t direction = 0; direction < kNumOrthogonalDirections; direction++) + for (Direction direction : kAllDirections) { for (size_t sequence = 0; sequence < sequenceCount; sequence++) { diff --git a/src/openrct2/rct2/RCT2.h b/src/openrct2/rct2/RCT2.h index 5d1a5db7c2..294b22e839 100644 --- a/src/openrct2/rct2/RCT2.h +++ b/src/openrct2/rct2/RCT2.h @@ -324,7 +324,7 @@ namespace OpenRCT2::RCT2 constexpr Direction GetDirection() const { - return (direction & 0b00001111); + return direction & 0b00000011; } constexpr bool IsExit() const diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index 1c5eccfb78..1f8d15b2ff 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -2162,7 +2162,7 @@ void TrackDesignDrawPreview(TrackDesign& td, TrackDesignPreviewBuffer& pixels, b drawingEngine->BeginDraw(); const ScreenCoordsXY offset = { size_x / 2, size_y / 2 }; - for (Direction direction = 0; direction < kNumOrthogonalDirections; direction++) + for (Direction direction : kAllDirections) { view.viewPos = Translate3DTo2DWithZ(direction, centre) - offset; view.rotation = direction; diff --git a/src/openrct2/ride/TrackIteration.cpp b/src/openrct2/ride/TrackIteration.cpp index cff59f5c88..4a27facff2 100644 --- a/src/openrct2/ride/TrackIteration.cpp +++ b/src/openrct2/ride/TrackIteration.cpp @@ -284,7 +284,7 @@ namespace OpenRCT2 int32_t y = input->y; int32_t OriginZ = inputElement->getBaseZ(); - uint8_t rotation = inputElement->getDirection(); + Direction rotation = inputElement->getDirection(); CoordsXY coords = { x, y }; CoordsXY trackCoordOffset = { trackCoordinate.x, trackCoordinate.y }; diff --git a/src/openrct2/ride/Vehicle.Station.cpp b/src/openrct2/ride/Vehicle.Station.cpp index abe93d2084..09a8a51a3d 100644 --- a/src/openrct2/ride/Vehicle.Station.cpp +++ b/src/openrct2/ride/Vehicle.Station.cpp @@ -165,7 +165,7 @@ static bool ride_station_can_depart_synchronised(const Ride& ride, StationIndex * is found we allow for space between that and the next. */ - int32_t direction = tileElement->getDirectionWithOffset(1); + Direction direction = tileElement->getDirectionWithOffset(1); constexpr uint8_t maxCheckDistance = kRideAdjacencyCheckDistance; uint8_t spaceBetween = maxCheckDistance; diff --git a/src/openrct2/scenes/editor/EditorController.cpp b/src/openrct2/scenes/editor/EditorController.cpp index 3e601e451c..8d02f9314c 100644 --- a/src/openrct2/scenes/editor/EditorController.cpp +++ b/src/openrct2/scenes/editor/EditorController.cpp @@ -183,7 +183,7 @@ namespace OpenRCT2::Editor for (const auto& parkEntrance : gameState.park.entrances) { - int32_t direction = DirectionReverse(parkEntrance.direction); + Direction direction = DirectionReverse(parkEntrance.direction); switch (FootpathIsConnectedToMapEdge(parkEntrance, direction, 0)) { diff --git a/src/openrct2/scripting/bindings/world/ScPathNavigator.cpp b/src/openrct2/scripting/bindings/world/ScPathNavigator.cpp index 6de0cdd8a5..40ee40cd58 100644 --- a/src/openrct2/scripting/bindings/world/ScPathNavigator.cpp +++ b/src/openrct2/scripting/bindings/world/ScPathNavigator.cpp @@ -208,7 +208,7 @@ namespace OpenRCT2::Scripting JSValue result = JS_NewArray(ctx); int32_t resultIndex = 0; - for (int32_t direction = 0; direction < 4; direction++) + for (Direction direction : kAllDirections) { if (!(edges & (1 << direction))) continue; diff --git a/src/openrct2/world/Direction.hpp b/src/openrct2/world/Direction.hpp new file mode 100644 index 0000000000..a99257b2aa --- /dev/null +++ b/src/openrct2/world/Direction.hpp @@ -0,0 +1,85 @@ +/***************************************************************************** + * Copyright (c) 2014-2026 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#pragma once + +#include + +constexpr auto kNumOrthogonalDirections = 4; + +/** + * Cardinal directions are represented by the Direction type. It has four + * possible values: + * 0 is X-decreasing (West) + * 1 is Y-increasing (North) + * 2 is X-increasing (East) + * 3 is Y-decreasing (South) + * Direction is not used to model up/down, or diagonal directions. + */ +using Direction = uint8_t; + +const Direction kInvalidDirection = 0xFF; + +/** + * Array of all valid cardinal directions, to make it easy to write range-based for loops like: + * for (Direction d : kAllDirections) + */ +constexpr Direction kAllDirections[] = { + 0, + 1, + 2, + 3, +}; + +/** + * Given a direction, return the direction that points the other way, + * on the same axis. + */ +inline constexpr Direction DirectionReverse(Direction dir) +{ + return dir ^ 2; +} + +inline constexpr bool DirectionValid(Direction dir) +{ + return dir < kNumOrthogonalDirections; +} + +/** + * Rotate a direction by the given number of 90-degree increments. Positive values + * rotate clockwise, negative values rotate counterclockwise. + */ +inline constexpr Direction DirectionRotate(Direction dir, int rotations) +{ + return (dir + rotations) & 0x03; +} + +/** + * Given a direction, return the next clockwise cardinal direction, wrapping around if necessary. + */ +inline constexpr Direction DirectionNext(Direction dir) +{ + return DirectionRotate(dir, 1); +} + +/** + * Given a direction, return the next counter-clockwise cardinal direction, wrapping around if necessary. + */ +inline constexpr Direction DirectionPrev(Direction dir) +{ + return DirectionRotate(dir, -1); +} + +/* + * Flips the X axis so 1 and 3 are swapped 0 and 2 will stay the same. + */ +inline constexpr Direction DirectionFlipXAxis(Direction direction) +{ + return (direction * 3) % 4; +} diff --git a/src/openrct2/world/Entrance.cpp b/src/openrct2/world/Entrance.cpp index e5aa5b2d31..fd52ac078e 100644 --- a/src/openrct2/world/Entrance.cpp +++ b/src/openrct2/world/Entrance.cpp @@ -123,7 +123,7 @@ money64 OpenRCT2::RideEntranceExitPlaceGhost( */ void MazeEntranceHedgeReplacement(const CoordsXYE& entrance) { - int32_t direction = entrance.element->getDirection(); + Direction direction = entrance.element->getDirection(); auto hedgePos = entrance + CoordsDirectionDelta[direction]; int32_t z = entrance.element->getBaseZ(); RideId rideIndex = entrance.element->asEntrance()->getRideIndex(); @@ -160,7 +160,7 @@ void MazeEntranceHedgeReplacement(const CoordsXYE& entrance) */ void MazeEntranceHedgeRemoval(const CoordsXYE& entrance) { - int32_t direction = entrance.element->getDirection(); + Direction direction = entrance.element->getDirection(); auto hedgePos = entrance + CoordsDirectionDelta[direction]; int32_t z = entrance.element->getBaseZ(); RideId rideIndex = entrance.element->asEntrance()->getRideIndex(); diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index e80953be6c..cc43899da0 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -219,9 +219,9 @@ namespace OpenRCT2 std::get<0>(tileElements) = { initialTileElement, footpathPos }; int32_t z = initialTileElement->getBaseZ(); - for (int32_t initialDirection = 0; initialDirection < kNumOrthogonalDirections; initialDirection++) + for (Direction initialDirection : kAllDirections) { - int32_t direction = initialDirection; + Direction direction = initialDirection; auto currentPos = footpathPos + CoordsDirectionDelta[direction]; std::get<1>(tileElements) = { @@ -1552,7 +1552,7 @@ namespace OpenRCT2 if (tileElement->asPath()->isQueue()) { FootpathQueueChainPush(tileElement->asPath()->getRideIndex()); - for (int32_t direction = 0; direction < kNumOrthogonalDirections; direction++) + for (Direction direction : kAllDirections) { if (tileElement->asPath()->getEdges() & (1 << direction)) { @@ -1764,7 +1764,7 @@ namespace OpenRCT2 FootpathUpdateQueueEntranceBanner(footpathPos, tileElement); - for (uint8_t direction = 0; direction < kNumOrthogonalDirections; direction++) + for (Direction direction : kAllDirections) { int32_t z1 = tileElement->baseHeight; if (tileElement->getType() == TileElementType::path) @@ -1890,7 +1890,7 @@ namespace OpenRCT2 return ride->getRideTypeDescriptor().flags.has(RtdFlag::supportsLevelCrossings); } - bool FootpathIsZAndDirectionValid(const PathElement& pathElement, int32_t currentZ, int32_t currentDirection) + bool FootpathIsZAndDirectionValid(const PathElement& pathElement, int32_t currentZ, Direction currentDirection) { if (pathElement.isSloped()) { diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index a1bde622ab..3e0d21fb76 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -200,7 +200,7 @@ namespace OpenRCT2 void FootpathQueueChainReset(); void FootpathQueueChainPush(RideId rideIndex); int32_t FootpathQueueCountConnections(const CoordsXY& position, const PathElement& pathElement); - bool FootpathIsZAndDirectionValid(const PathElement& tileElement, int32_t currentZ, int32_t currentDirection); + bool FootpathIsZAndDirectionValid(const PathElement& tileElement, int32_t currentZ, Direction currentDirection); FootpathPlacementResult FootpathGetOnTerrainPlacement(const TileCoordsXY& location); FootpathPlacementResult FootpathGetOnTerrainPlacement(const SurfaceElement& surfaceElement); diff --git a/src/openrct2/world/Location.hpp b/src/openrct2/world/Location.hpp index ff86e54e27..7f366f7a9d 100644 --- a/src/openrct2/world/Location.hpp +++ b/src/openrct2/world/Location.hpp @@ -11,6 +11,7 @@ #include "../core/CoordsRange.hpp" #include "../core/Numerics.hpp" +#include "../world/Direction.hpp" #include "../world/MapLimits.h" #include @@ -18,8 +19,6 @@ constexpr int16_t kLocationNull = -32768; constexpr int32_t kCoordsNull = 0xFFFF8000; -constexpr auto kNumOrthogonalDirections = 4; - /** * Tile coordinates use 1 x/y increment per tile and 1 z increment per step. * Regular ('big', 'sprite') coordinates use 32 x/y increments per tile and 8 z increments per step. @@ -453,89 +452,6 @@ struct TileCoordsXYRangedZ : public TileCoordsXY } }; -/** - * Cardinal directions are represented by the Direction type. It has four - * possible values: - * 0 is X-decreasing - * 1 is Y-increasing - * 2 is X-increasing - * 3 is Y-decreasing - * Direction is not used to model up/down, or diagonal directions. - */ -using Direction = uint8_t; - -const Direction kInvalidDirection = 0xFF; - -/** - * Array of all valid cardinal directions, to make it easy to write range-based for loops like: - * for (Direction d : kAllDirections) - */ -constexpr Direction kAllDirections[] = { - 0, - 1, - 2, - 3, -}; - -/** - * Given a direction, return the direction that points the other way, - * on the same axis. - */ -inline constexpr Direction DirectionReverse(Direction dir) -{ - return dir ^ 2; -} - -inline constexpr bool DirectionValid(Direction dir) -{ - return dir < kNumOrthogonalDirections; -} - -/** - * Given a direction, return the next cardinal direction, wrapping around if necessary. - * (TODO: Figure out if this is CW or CCW) - */ -inline constexpr Direction DirectionNext(Direction dir) -{ - return (dir + 1) & 0x03; -} - -/** - * Given a direction, return the previous cardinal direction, wrapping around if necessary. - * (TODO: Figure out if this is CW or CCW) - */ -inline constexpr Direction DirectionPrev(Direction dir) -{ - return (dir - 1) & 0x03; -} - -/** - * Given two positions, return the cardinal direction which is closest to the direction from 'from' to 'to'. - */ -inline constexpr Direction DirectionFromTo(const CoordsXY& from, const CoordsXY& to) -{ - int16_t x_diff = to.x - from.x; - int16_t y_diff = to.y - from.y; - - int16_t abs_x = x_diff < 0 ? -x_diff : x_diff; - int16_t abs_y = y_diff < 0 ? -y_diff : y_diff; - - if (abs_x <= abs_y) - { - return y_diff < 0 ? 3 : 1; - } - - return x_diff < 0 ? 0 : 2; -} - -/* - * Flips the X axis so 1 and 3 are swapped 0 and 2 will stay the same. - */ -inline constexpr Direction DirectionFlipXAxis(Direction direction) -{ - return (direction * 3) % 4; -} - struct CoordsXYZD : public CoordsXYZ { Direction direction{}; @@ -605,7 +521,7 @@ struct CoordsXYZD : public CoordsXYZ constexpr CoordsXYZD toTileCentre() const { - return toTileStart() + CoordsXYZD{ kCoordsXYHalfTile, kCoordsXYHalfTile, 0, 0 }; + return toTileStart() + CoordsXY{ kCoordsXYHalfTile, kCoordsXYHalfTile }; } }; @@ -668,6 +584,25 @@ struct TileCoordsXYZD : public TileCoordsXYZ } }; +/** + * Given two positions, return the cardinal direction which is closest to the direction from 'from' to 'to'. + */ +inline constexpr Direction DirectionFromTo(const CoordsXY& from, const CoordsXY& to) +{ + int16_t x_diff = to.x - from.x; + int16_t y_diff = to.y - from.y; + + int16_t abs_x = x_diff < 0 ? -x_diff : x_diff; + int16_t abs_y = y_diff < 0 ? -y_diff : y_diff; + + if (abs_x <= abs_y) + { + return y_diff < 0 ? 3 : 1; + } + + return x_diff < 0 ? 0 : 2; +} + /** * Represents a rectangular range of the map using regular coordinates (32 per tile). */ diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index df3676501b..ee4f5b2275 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -418,7 +418,7 @@ namespace OpenRCT2 return nullptr; } - BannerElement* MapGetBannerElementAt(const CoordsXYZ& bannerPos, uint8_t position) + BannerElement* MapGetBannerElementAt(const CoordsXYZ& bannerPos, Direction position) { const auto bannerTilePos = TileCoordsXYZ{ bannerPos }; for (auto* element : TileElementsView(bannerPos)) @@ -688,7 +688,7 @@ namespace OpenRCT2 * Checks if the tile at coordinate at height counts as connected. * @return 1 if connected, 0 otherwise */ - bool MapCoordIsConnected(const TileCoordsXYZ& loc, uint8_t faceDirection) + bool MapCoordIsConnected(const TileCoordsXYZ& loc, Direction faceDirection) { TileElement* tileElement = MapGetFirstElementAt(loc); @@ -700,7 +700,7 @@ namespace OpenRCT2 if (tileElement->getType() != TileElementType::path) continue; - uint8_t slopeDirection = tileElement->asPath()->getSlopeDirection(); + Direction slopeDirection = tileElement->asPath()->getSlopeDirection(); if (tileElement->asPath()->isSloped()) { diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index 95782aca19..1585a6eda1 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -74,7 +74,7 @@ namespace OpenRCT2 TileElement* MapGetFirstTileElementWithBaseHeightBetween(const TileCoordsXYRangedZ& loc, TileElementType type); void MapSetTileElement(const TileCoordsXY& tilePos, TileElement* elements); int32_t MapHeightFromSlope(const CoordsXY& coords, int32_t slopeDirection, bool isSloped); - BannerElement* MapGetBannerElementAt(const CoordsXYZ& bannerPos, uint8_t position); + BannerElement* MapGetBannerElementAt(const CoordsXYZ& bannerPos, Direction position); SurfaceElement* MapGetSurfaceElementAt(const TileCoordsXY& coords); SurfaceElement* MapGetSurfaceElementAt(const CoordsXY& coords); PathElement* MapGetPathElementAt(const TileCoordsXYZ& loc); @@ -86,7 +86,7 @@ namespace OpenRCT2 EntranceElement* MapGetRideExitElementAt(const CoordsXYZ& exitCoords, bool ghost); uint8_t MapGetHighestLandHeight(const MapRange& range); uint8_t MapGetLowestLandHeight(const MapRange& range); - bool MapCoordIsConnected(const TileCoordsXYZ& loc, uint8_t faceDirection); + bool MapCoordIsConnected(const TileCoordsXYZ& loc, Direction faceDirection); void MapUpdatePathWideFlags(); bool MapIsLocationValid(const CoordsXY& coords); bool MapIsEdge(const CoordsXY& coords); diff --git a/src/openrct2/world/MapAnimation.cpp b/src/openrct2/world/MapAnimation.cpp index 42716a01fc..5561a17ba5 100644 --- a/src/openrct2/world/MapAnimation.cpp +++ b/src/openrct2/world/MapAnimation.cpp @@ -166,7 +166,7 @@ static std::optional UpdateSmallSceneryAnimation( // Don't apply anything to peeps when the scenery is a ghost. if (!scenery.isGhost() && !(getGameState().currentTicks & 0x3FF)) { - const int32_t direction = scenery.getDirection(); + const Direction direction = scenery.getDirection(); auto quad = EntityTileList(CoordsXY{ loc.x, loc.y } - CoordsDirectionDelta[direction]); for (auto peep : quad) { diff --git a/src/openrct2/world/QuarterTile.cpp b/src/openrct2/world/QuarterTile.cpp index d2fcf9ea98..5efc785d62 100644 --- a/src/openrct2/world/QuarterTile.cpp +++ b/src/openrct2/world/QuarterTile.cpp @@ -13,7 +13,7 @@ #include "Location.hpp" // Rotate both of the values amount -const QuarterTile QuarterTile::Rotate(uint8_t amount) const +const QuarterTile QuarterTile::Rotate(Direction amount) const { switch (amount) { diff --git a/src/openrct2/world/QuarterTile.h b/src/openrct2/world/QuarterTile.h index 7f05aa39ae..eb041e29a3 100644 --- a/src/openrct2/world/QuarterTile.h +++ b/src/openrct2/world/QuarterTile.h @@ -11,6 +11,7 @@ #include +using Direction = uint8_t; struct TileCornersZ; class QuarterTile @@ -30,7 +31,7 @@ public: } // Rotate both of the values amount. Returns new RValue QuarterTile - const QuarterTile Rotate(uint8_t amount) const; + const QuarterTile Rotate(Direction amount) const; uint8_t GetBaseQuarterOccupied() const; uint8_t GetZQuarterOccupied() const; TileCornersZ GetQuarterHeights(int32_t height) const; diff --git a/src/openrct2/world/TileInspector.cpp b/src/openrct2/world/TileInspector.cpp index 05a4ce84eb..75079b2ece 100644 --- a/src/openrct2/world/TileInspector.cpp +++ b/src/openrct2/world/TileInspector.cpp @@ -219,7 +219,7 @@ namespace OpenRCT2::TileInspector case TileElementType::path: if (tileElement->asPath()->isSloped()) { - newRotation = (tileElement->asPath()->getSlopeDirection() + 1) & kTileElementDirectionMask; + newRotation = DirectionNext(tileElement->asPath()->getSlopeDirection()); tileElement->asPath()->setSlopeDirection(newRotation); } pathEdges = tileElement->asPath()->getEdges(); diff --git a/src/openrct2/world/Wall.cpp b/src/openrct2/world/Wall.cpp index 87b3a9c6f4..fe6a1282a6 100644 --- a/src/openrct2/world/Wall.cpp +++ b/src/openrct2/world/Wall.cpp @@ -121,7 +121,7 @@ uint8_t GetWallSlopeFromEdgeSlope(uint8_t Slope, uint8_t Edge) * * rct2: 0x006E59DC */ -bool WallInTheWay(const CoordsXYRangedZ& fencePos, int32_t direction) +bool WallInTheWay(const CoordsXYRangedZ& fencePos, Direction direction) { TileElement* tileElement = MapGetFirstElementAt(fencePos); if (tileElement == nullptr) diff --git a/src/openrct2/world/Wall.h b/src/openrct2/world/Wall.h index 2c07af2046..df93a56bad 100644 --- a/src/openrct2/world/Wall.h +++ b/src/openrct2/world/Wall.h @@ -31,4 +31,4 @@ void WallRemoveIntersectingWalls(const CoordsXYRangedZ& wallPos, Direction direc uint8_t GetWallSlopeFromEdgeSlope(uint8_t Slope, uint8_t Edge); -bool WallInTheWay(const CoordsXYRangedZ& fencePos, int32_t direction); +bool WallInTheWay(const CoordsXYRangedZ& fencePos, Direction direction); diff --git a/src/openrct2/world/tile_element/BannerElement.cpp b/src/openrct2/world/tile_element/BannerElement.cpp index 04be2cd5c2..f79e0c4343 100644 --- a/src/openrct2/world/tile_element/BannerElement.cpp +++ b/src/openrct2/world/tile_element/BannerElement.cpp @@ -31,12 +31,12 @@ namespace OpenRCT2 index = newIndex; } - uint8_t BannerElement::getPosition() const + Direction BannerElement::getPosition() const { return position; } - void BannerElement::setPosition(uint8_t newPosition) + void BannerElement::setPosition(Direction newPosition) { position = newPosition; } diff --git a/src/openrct2/world/tile_element/BannerElement.h b/src/openrct2/world/tile_element/BannerElement.h index 24c71c1d48..c312cf548e 100644 --- a/src/openrct2/world/tile_element/BannerElement.h +++ b/src/openrct2/world/tile_element/BannerElement.h @@ -23,7 +23,7 @@ namespace OpenRCT2 private: BannerIndex index; // 5 - uint8_t position; // 7 + Direction position; // 7 uint8_t allowedEdges; // 8 #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-private-field" @@ -36,8 +36,8 @@ namespace OpenRCT2 BannerIndex getIndex() const; void setIndex(BannerIndex newIndex); - uint8_t getPosition() const; - void setPosition(uint8_t newPosition); + Direction getPosition() const; + void setPosition(Direction newPosition); uint8_t getAllowedEdges() const; void setAllowedEdges(uint8_t newEdges); diff --git a/src/openrct2/world/tile_element/PathElement.h b/src/openrct2/world/tile_element/PathElement.h index 33455651f4..58bd4711c9 100644 --- a/src/openrct2/world/tile_element/PathElement.h +++ b/src/openrct2/world/tile_element/PathElement.h @@ -62,7 +62,7 @@ namespace OpenRCT2 uint8_t additions; // 9 (0 means no addition) uint8_t edgesAndCorners; // 10 (edges in lower 4 bits, corners in upper 4) FootpathElementFlags flags2; // 11 - uint8_t slopeDirection; // 12 + Direction slopeDirection; // 12 union { uint8_t additionStatus; // 13, only used for litter bins diff --git a/src/openrct2/world/tile_element/TileElementBase.cpp b/src/openrct2/world/tile_element/TileElementBase.cpp index de8ac7d27a..1c791a12db 100644 --- a/src/openrct2/world/tile_element/TileElementBase.cpp +++ b/src/openrct2/world/tile_element/TileElementBase.cpp @@ -47,7 +47,7 @@ namespace OpenRCT2 Direction TileElementBase::getDirectionWithOffset(uint8_t offset) const { - return ((this->type & kTileElementDirectionMask) + offset) & kTileElementDirectionMask; + return DirectionRotate(getDirection(), offset); } bool TileElementBase::isLastForTile() const From e87de0579252e556cf135b11dd3f3a729fd9fcf7 Mon Sep 17 00:00:00 2001 From: Paul Harley Date: Sun, 11 Oct 2026 10:44:42 +0100 Subject: [PATCH 06/33] Fix #16807: Log and skip invalid object JSON files (#27117) --- distribution/changelog.txt | 1 + src/openrct2/object/ObjectFactory.cpp | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 6d668ed984..c38bde4002 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -1,5 +1,6 @@ 0.5.7 (in development) ------------------------------------------------------------------------ +- Fix: [#16807] Error messages when trying to load regular JSON files as custom objects. - Fix: [#24524] Some build types (like AppImage) lack information about their specific build. - Fix: [#27264] Headless server crashes when loading a recolourable terrain surface. diff --git a/src/openrct2/object/ObjectFactory.cpp b/src/openrct2/object/ObjectFactory.cpp index 4c076389fb..ee26068eb8 100644 --- a/src/openrct2/object/ObjectFactory.cpp +++ b/src/openrct2/object/ObjectFactory.cpp @@ -529,9 +529,15 @@ namespace OpenRCT2::ObjectFactory std::unique_ptr CreateObjectFromJson( json_t& jRoot, const IFileDataRetriever* fileRetriever, bool loadImageTable, const std::string_view path) { - if (!jRoot.is_object()) + if (!jRoot.is_object() || !jRoot.contains("objectType")) { - throw std::runtime_error("Object JSON root was not an object"); + LOG_VERBOSE("Ignoring JSON file (%.*s): not an object file", static_cast(path.length()), path.data()); + return nullptr; + } + if (!jRoot["objectType"].is_string()) + { + LOG_VERBOSE("Ignoring JSON file (%.*s): objectType is not a string", static_cast(path.length()), path.data()); + return nullptr; } LOG_VERBOSE("CreateObjectFromJson(...)"); From 9c0a1eb8fdc5886ca5b823f406628854131e6015 Mon Sep 17 00:00:00 2001 From: Ryan Brue Date: Wed, 9 Sep 2026 12:29:31 -0500 Subject: [PATCH 07/33] Do not query metadata for files that cannot match a search pattern FileScannerUnix stats every entry it lists in order to read its size and modified time, but files whose name does not match the search pattern are never returned by next(). Skipping them before that call cuts the repository freshness scans at startup from 10832 stat calls to 345 for a RollerCoaster Tycoon Classic installation, and lets the load/save window list a directory's sub directories without querying every file in it. This matters on file systems where metadata operations are expensive: a stat costs ~60us on the FUSE file system Flatpak's document portal provides, against ~1.4us on local disk. Entries whose type readdir did not report are still queried, as they may be a directory that has to be recursed into. Used an LLM to find the issue, and generate the patch. Performed my own testing. Assisted-by: LLM Signed-off-by: Ryan Brue --- src/openrct2/core/FileScanner.cpp | 45 ++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/src/openrct2/core/FileScanner.cpp b/src/openrct2/core/FileScanner.cpp index 4532dc9748..cb91839ab4 100644 --- a/src/openrct2/core/FileScanner.cpp +++ b/src/openrct2/core/FileScanner.cpp @@ -24,6 +24,7 @@ #include "String.hpp" #include +#include #include #include #include @@ -148,17 +149,8 @@ public: virtual void getDirectoryChildren(std::vector& children, const std::string& path) = 0; -private: - void pushState(const std::string& directory) - { - DirectoryState newState; - newState.path = directory; - newState.index = -1; - getDirectoryChildren(newState.listing, directory); - _directoryStack.push(newState); - } - - bool patternMatch(const std::string& fileName) +protected: + bool patternMatch(const std::string& fileName) const { for (const auto& pattern : _patterns) { @@ -170,6 +162,16 @@ private: return false; } +private: + void pushState(const std::string& directory) + { + DirectoryState newState; + newState.path = directory; + newState.index = -1; + getDirectoryChildren(newState.listing, directory); + _directoryStack.push(newState); + } + static std::vector getPatterns(const std::string& delimitedPatterns) { std::vector patterns; @@ -328,7 +330,11 @@ public: const struct dirent* node = namelist[i]; if (!String::equals(node->d_name, ".") && !String::equals(node->d_name, "..")) { - children.push_back(createChild(path.c_str(), node)); + auto child = createChild(path.c_str(), node); + if (child.has_value()) + { + children.push_back(std::move(child.value())); + } } free(namelist[i]); } @@ -342,7 +348,7 @@ private: return 1; } - static DirectoryChild createChild(const utf8* directory, const struct dirent* node) + std::optional createChild(const utf8* directory, const struct dirent* node) const { DirectoryChild result; result.name = std::string(node->d_name); @@ -358,6 +364,19 @@ private: } else { + #ifndef __HAIKU__ + // Reading the size and modified time of a file costs a stat call each, which is + // expensive on file systems with a high per-operation cost, such as network shares or + // the FUSE file system that Flatpak's document portal provides. Files that cannot match + // the search pattern are never returned, so skip them before paying for that. Entries of + // an unknown type still have to be queried to find out whether they are a directory + // which has to be recursed into. + if (node->d_type == DT_REG && !patternMatch(result.name)) + { + return std::nullopt; + } + #endif + result.type = DirectoryChildType::file; // Get the full path of the file From 6e4431451f999f309d28a53961af5fb953a90aab Mon Sep 17 00:00:00 2001 From: Ryan Brue Date: Wed, 9 Sep 2026 12:29:44 -0500 Subject: [PATCH 08/33] Fix #21030, #26981: Resolve original game files from a cached listing Every image source of the form `$RCT2:OBJDATA/NAME.DAT` was resolved by probing that exact name, then the `.POB` name, and on failure by scanning the object directory recursively. Scanning it stats every entry, so on an RCT Classic installation -- a single flat `Assets` folder of 2708 lower case files, which never match the upper case names the shipped JSON objects ask for -- both probes missed and each object cost a scan of the whole folder. A park needs hundreds of those, and the cache holding the results is thread_local on threads that are destroyed together with the job pool, so the work was repeated on every park load and title sequence transition. Stat and open are ~45x more expensive on the FUSE file system Flatpak's document portal provides than on local disk, which is why this became unbearable there in particular. The RCT1/RCT2 data directories are now listed once into a case insensitive name index that IPlatformEnvironment::FindFile answers from, so resolving a name costs no file system operations at all. Reading a listing only needs the names, not the metadata, and the index is dropped when a base path changes. Loading test/tests/testdata/parks/bpb.sv6 with RCT Classic game data, measured with `openrct2-cli screenshot` (byte identical output before and after): before after document portal 54.5 s 0.45 s local disk 2.58 s 0.34 s Used an LLM to find the problem and generate the patch, and verified the speedup on my own. Assisted-by: LLM Signed-off-by: Ryan Brue --- src/openrct2/PlatformEnvironment.cpp | 139 ++++++++++++++++++++++++++- src/openrct2/object/ImageTable.cpp | 45 ++++----- 2 files changed, 155 insertions(+), 29 deletions(-) diff --git a/src/openrct2/PlatformEnvironment.cpp b/src/openrct2/PlatformEnvironment.cpp index 89d4243f6e..b0722537c7 100644 --- a/src/openrct2/PlatformEnvironment.cpp +++ b/src/openrct2/PlatformEnvironment.cpp @@ -14,10 +14,16 @@ #include "config/Config.h" #include "core/EnumUtils.hpp" #include "core/File.h" +#include "core/FileSystem.hpp" #include "core/Path.hpp" #include "core/String.hpp" #include "platform/Platform.h" +#include +#include +#include +#include + using namespace OpenRCT2; static constexpr const char* kDirectoryNamesRCT2[] = { @@ -80,11 +86,125 @@ static constexpr u8string_view kFileNames[] = { u8"contributors.md", // CONTRIBUTORS }; +/** + * Lower cases ASCII characters only, which matches how String::iequals compares strings. + */ +static u8string ToLowerAscii(u8string_view str) +{ + u8string result(str); + for (auto& c : result) + { + if (c >= 'A' && c <= 'Z') + c += 'a' - 'A'; + } + return result; +} + +/** + * Caches the file names of the original game data directories so that they can be looked up case + * insensitively without hitting the file system. + * + * The game refers to the original files by their MS-DOS era upper case names, while an actual + * installation may use any casing, so every look up has to consider all the names in a directory. + * Doing that per look up means listing a directory of a few thousand files hundreds of times while + * loading a park, which is ruinously slow on file systems with a high per-operation cost, such as + * the FUSE file system Flatpak's document portal provides. The original game data does not change + * while the game is running, so each directory only has to be listed once. + */ +class OriginalGameDataIndex +{ +private: + struct Entry + { + u8string path; + int32_t depth{}; + }; + + // Maps the lower cased name of a file to the file it was found as. + using Listing = std::unordered_map>; + + std::mutex _mutex; + std::map, std::less<>> _listings; + +public: + /** + * Returns the real path of the file with the given name inside the given directory or one of its + * sub directories, matching the name case insensitively. Returns an empty string if there is no + * such file. + */ + u8string FindFile(const u8string& directory, u8string_view fileName) + { + std::lock_guard guard(_mutex); + + const auto& listing = GetListing(directory); + if (!listing.has_value()) + { + // The directory could not be listed, fall back to querying the file system. + return Path::ResolveCasing(Path::Combine(directory, fileName)); + } + + auto it = listing->find(ToLowerAscii(fileName)); + if (it == listing->end()) + return {}; + + return it->second.path; + } + + void Clear() + { + std::lock_guard guard(_mutex); + _listings.clear(); + } + +private: + const std::optional& GetListing(const u8string& directory) + { + auto it = _listings.find(directory); + if (it != _listings.end()) + return it->second; + + return _listings.emplace(directory, ReadListing(directory)).first->second; + } + + static std::optional ReadListing(const u8string& directory) + { + std::error_code ec; + auto it = fs::recursive_directory_iterator(fs::u8path(directory), fs::directory_options::skip_permission_denied, ec); + if (ec) + return std::nullopt; + + Listing listing; + const auto end = fs::recursive_directory_iterator(); + for (; it != end; it.increment(ec)) + { + if (ec) + break; + + // Asks the directory entry rather than the file system, as the entry already knows the + // type of the file on the platforms that report it while listing a directory. + std::error_code typeEc; + if (it->is_directory(typeEc) || typeEc) + continue; + + const auto depth = it.depth(); + auto entry = Entry{ it->path().u8string(), depth }; + auto [entryIt, inserted] = listing.try_emplace(ToLowerAscii(it->path().filename().u8string()), entry); + + // Prefer the files closest to the root of the directory, files in sub directories are + // only meant to be used when there is none of that name next to the other game files. + if (!inserted && depth < entryIt->second.depth) + entryIt->second = std::move(entry); + } + return listing; + } +}; + class PlatformEnvironment final : public IPlatformEnvironment { private: u8string _basePath[kDirBaseCount]; RCT2Variant _rct2Variant = RCT2Variant::rct2Original; + mutable OriginalGameDataIndex _originalGameDataIndex; public: explicit PlatformEnvironment(DirBaseValues basePaths) @@ -175,7 +295,7 @@ public: } } - auto path = Path::ResolveCasing(Path::Combine(dataPath, fileName)); + auto path = ResolveOriginalGameDataPath(base, dataPath, fileName); if (base == DirBase::rct1 && did == DirId::data && !File::Exists(path)) { // Special case, handle RCT1 steam layout where some data files are under a CD root @@ -193,6 +313,7 @@ public: void SetBasePath(DirBase base, u8string_view path) override { _basePath[EnumValue(base)] = path; + _originalGameDataIndex.Clear(); if (base == DirBase::rct2) { @@ -209,6 +330,22 @@ public: } private: + /** + * Resolves the casing of a file inside one of the original game data directories, using the + * cached directory listings where possible. + */ + u8string ResolveOriginalGameDataPath(DirBase base, const u8string& dataPath, u8string_view fileName) const + { + const auto isOriginalGameData = base == DirBase::rct1 || base == DirBase::rct2; + const auto isPlainFileName = fileName.find_first_of("/\\") == u8string_view::npos; + if (!isOriginalGameData || !isPlainFileName || dataPath.empty()) + { + return Path::ResolveCasing(Path::Combine(dataPath, fileName)); + } + + return _originalGameDataIndex.FindFile(dataPath, fileName); + } + static DirBase GetDefaultBaseDirectory(PathId pathid) { switch (pathid) diff --git a/src/openrct2/object/ImageTable.cpp b/src/openrct2/object/ImageTable.cpp index 7742d19dad..f6a488cf28 100644 --- a/src/openrct2/object/ImageTable.cpp +++ b/src/openrct2/object/ImageTable.cpp @@ -14,8 +14,6 @@ #include "../OpenRCT2.h" #include "../PlatformEnvironment.h" #include "../SpriteIds.h" -#include "../core/File.h" -#include "../core/FileScanner.h" #include "../core/Guard.hpp" #include "../core/IStream.hpp" #include "../core/Json.hpp" @@ -381,42 +379,33 @@ namespace OpenRCT2 std::string ImageTable::FindLegacyObject(const std::string& name) { + // The original object files are looked up through the platform environment, which resolves + // their name case insensitively from a cached directory listing. Scanning the directory per + // look up instead is very slow on file systems with a high per-operation cost, and the game + // asks for hundreds of these files whenever it loads a park. const auto& env = GetContext()->GetPlatformEnvironment(); - auto objectsPath = env.GetDirectoryPath(DirBase::rct2, DirId::objects); - auto objectPath = Path::Combine(objectsPath, name); - if (File::Exists(objectPath)) + auto objectPath = env.FindFile(DirBase::rct2, DirId::objects, name); + if (!objectPath.empty()) { return objectPath; } - std::string altName = name; - auto rangeStart = name.find(".DAT"); - if (rangeStart != std::string::npos) + // RCT Classic ships the same objects with a .POB extension + auto extensionStart = name.find(".DAT"); + if (extensionStart != std::string::npos) { - altName.replace(rangeStart, 4, ".POB"); - } - objectPath = Path::Combine(objectsPath, altName); - if (File::Exists(objectPath)) - { - return objectPath; - } + auto altName = name; + altName.replace(extensionStart, 4, ".POB"); - if (!File::Exists(objectPath)) - { - // Search recursively for any file with the target name (case insensitive) - auto filter = Path::Combine(objectsPath, u8"*.dat;*.pob"); - auto scanner = Path::scanDirectory(filter, true); - while (scanner->next()) + objectPath = env.FindFile(DirBase::rct2, DirId::objects, altName); + if (!objectPath.empty()) { - auto currentName = Path::GetFileName(scanner->getPathRelative()); - if (String::iequals(currentName, name) || String::iequals(currentName, altName)) - { - objectPath = scanner->getPath(); - break; - } + return objectPath; } } - return objectPath; + + // Return the path the object was expected at, so that failing to open it can be reported + return Path::Combine(env.GetDirectoryPath(DirBase::rct2, DirId::objects), name); } ImageTable::~ImageTable() From 70f11d3b00b37b6cff18909aab08edd0333cd998 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 11 Oct 2026 12:10:02 +0200 Subject: [PATCH 09/33] Use `tolower` in ToLowerAscii() --- src/openrct2/PlatformEnvironment.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/openrct2/PlatformEnvironment.cpp b/src/openrct2/PlatformEnvironment.cpp index b0722537c7..d7cf732f1e 100644 --- a/src/openrct2/PlatformEnvironment.cpp +++ b/src/openrct2/PlatformEnvironment.cpp @@ -94,8 +94,7 @@ static u8string ToLowerAscii(u8string_view str) u8string result(str); for (auto& c : result) { - if (c >= 'A' && c <= 'Z') - c += 'a' - 'A'; + c = tolower(c); } return result; } From 96be799e24958187032e247330eecc5ce70f42ad Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 11 Oct 2026 12:16:34 +0200 Subject: [PATCH 10/33] Fix code style --- src/openrct2/PlatformEnvironment.cpp | 22 +++++++++++----------- src/openrct2/object/ImageTable.cpp | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/openrct2/PlatformEnvironment.cpp b/src/openrct2/PlatformEnvironment.cpp index d7cf732f1e..b06fca4284 100644 --- a/src/openrct2/PlatformEnvironment.cpp +++ b/src/openrct2/PlatformEnvironment.cpp @@ -89,7 +89,7 @@ static constexpr u8string_view kFileNames[] = { /** * Lower cases ASCII characters only, which matches how String::iequals compares strings. */ -static u8string ToLowerAscii(u8string_view str) +static u8string toLowerAscii(const u8string_view str) { u8string result(str); for (auto& c : result) @@ -131,41 +131,41 @@ public: * sub directories, matching the name case insensitively. Returns an empty string if there is no * such file. */ - u8string FindFile(const u8string& directory, u8string_view fileName) + u8string findFile(const u8string& directory, u8string_view fileName) { std::lock_guard guard(_mutex); - const auto& listing = GetListing(directory); + const auto& listing = getListing(directory); if (!listing.has_value()) { // The directory could not be listed, fall back to querying the file system. return Path::ResolveCasing(Path::Combine(directory, fileName)); } - auto it = listing->find(ToLowerAscii(fileName)); + auto it = listing->find(toLowerAscii(fileName)); if (it == listing->end()) return {}; return it->second.path; } - void Clear() + void clear() { std::lock_guard guard(_mutex); _listings.clear(); } private: - const std::optional& GetListing(const u8string& directory) + const std::optional& getListing(const u8string& directory) { auto it = _listings.find(directory); if (it != _listings.end()) return it->second; - return _listings.emplace(directory, ReadListing(directory)).first->second; + return _listings.emplace(directory, readListing(directory)).first->second; } - static std::optional ReadListing(const u8string& directory) + static std::optional readListing(const u8string& directory) { std::error_code ec; auto it = fs::recursive_directory_iterator(fs::u8path(directory), fs::directory_options::skip_permission_denied, ec); @@ -187,7 +187,7 @@ private: const auto depth = it.depth(); auto entry = Entry{ it->path().u8string(), depth }; - auto [entryIt, inserted] = listing.try_emplace(ToLowerAscii(it->path().filename().u8string()), entry); + auto [entryIt, inserted] = listing.try_emplace(toLowerAscii(it->path().filename().u8string()), entry); // Prefer the files closest to the root of the directory, files in sub directories are // only meant to be used when there is none of that name next to the other game files. @@ -312,7 +312,7 @@ public: void SetBasePath(DirBase base, u8string_view path) override { _basePath[EnumValue(base)] = path; - _originalGameDataIndex.Clear(); + _originalGameDataIndex.clear(); if (base == DirBase::rct2) { @@ -342,7 +342,7 @@ private: return Path::ResolveCasing(Path::Combine(dataPath, fileName)); } - return _originalGameDataIndex.FindFile(dataPath, fileName); + return _originalGameDataIndex.findFile(dataPath, fileName); } static DirBase GetDefaultBaseDirectory(PathId pathid) diff --git a/src/openrct2/object/ImageTable.cpp b/src/openrct2/object/ImageTable.cpp index f6a488cf28..7291b63f55 100644 --- a/src/openrct2/object/ImageTable.cpp +++ b/src/openrct2/object/ImageTable.cpp @@ -395,7 +395,7 @@ namespace OpenRCT2 if (extensionStart != std::string::npos) { auto altName = name; - altName.replace(extensionStart, 4, ".POB"); + altName.replace(extensionStart + 1, 3, "POB"); objectPath = env.FindFile(DirBase::rct2, DirId::objects, altName); if (!objectPath.empty()) From 99c2f79898da57619e46b5116d05348c38f7748f Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 11 Oct 2026 12:21:28 +0200 Subject: [PATCH 11/33] Update changelog --- distribution/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index c38bde4002..be41bc258e 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -1,6 +1,7 @@ 0.5.7 (in development) ------------------------------------------------------------------------ - Fix: [#16807] Error messages when trying to load regular JSON files as custom objects. +- Fix: [#21030, #26981] Slow object loading and index building when using RCT Classic or running from a Flatpak. - Fix: [#24524] Some build types (like AppImage) lack information about their specific build. - Fix: [#27264] Headless server crashes when loading a recolourable terrain surface. From 42184adf10878b088f9bc0f8a7e82b171c707684 Mon Sep 17 00:00:00 2001 From: csunday95 Date: Sun, 11 Oct 2026 09:38:30 -0700 Subject: [PATCH 12/33] Close #27199: Move ObjectAsset to its own file (#27205) Perform the refactor described in #27199, move ObjectAsset to its own cpp file. I also added a brief docstring for the class based on my understanding of its function. --- src/openrct2/libopenrct2.vcxproj | 1 + src/openrct2/object/Object.cpp | 91 --------------------- src/openrct2/object/ObjectAsset.cpp | 110 ++++++++++++++++++++++++++ src/openrct2/object/ObjectAsset.h | 9 +++ src/openrct2/object/ObjectFactory.cpp | 1 + 5 files changed, 121 insertions(+), 91 deletions(-) create mode 100644 src/openrct2/object/ObjectAsset.cpp diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index 60b10e0631..d3140f3abf 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -1000,6 +1000,7 @@ + diff --git a/src/openrct2/object/Object.cpp b/src/openrct2/object/Object.cpp index 821eb7afa1..19235dbf1f 100644 --- a/src/openrct2/object/Object.cpp +++ b/src/openrct2/object/Object.cpp @@ -308,97 +308,6 @@ namespace OpenRCT2 return !(*this == rhs); } - bool ObjectAsset::IsAvailable() const - { - if (_zipPath.empty()) - { - return File::Exists(_path); - } - - auto zipArchive = Zip::TryOpen(_zipPath, ZipAccess::read); - return zipArchive != nullptr && zipArchive->Exists(_path); - } - - uint64_t ObjectAsset::GetSize() const - { - if (_zipPath.empty()) - { - return File::GetSize(_path); - } - - auto zipArchive = Zip::TryOpen(_zipPath, ZipAccess::read); - if (zipArchive != nullptr) - { - auto index = zipArchive->GetIndexFromPath(_path); - if (index.has_value()) - { - auto size = zipArchive->GetFileSize(index.value()); - return size; - } - } - return 0; - } - - std::vector ObjectAsset::GetData() const - { - if (_zipPath.empty()) - { - return File::ReadAllBytes(_path); - } - - auto zipArchive = Zip::TryOpen(_zipPath, ZipAccess::read); - if (zipArchive != nullptr) - { - return zipArchive->GetFileData(_path); - } - return {}; - } - - std::unique_ptr ObjectAsset::GetStream() const - { - try - { - if (_zipPath.empty()) - { - return std::make_unique(_path, FileMode::open); - } - - auto zipArchive = Zip::TryOpen(_zipPath, ZipAccess::read); - if (zipArchive != nullptr) - { - auto stream = zipArchive->GetFileStream(_path); - if (stream != nullptr) - { - return std::make_unique(std::move(zipArchive), std::move(stream)); - } - } - } - catch (...) - { - } - return {}; - } - - const std::string& ObjectAsset::GetZipPath() const - { - return _zipPath; - } - - const std::string& ObjectAsset::GetPath() const - { - return _path; - } - - size_t ObjectAsset::GetHash() const - { - // Combine hashes of zipPath and path - std::hash hasher; - auto h1 = hasher(_zipPath); - auto h2 = hasher(_path); - // Combine the hashes based on example from https://en.cppreference.com/w/cpp/utility/hash.html - return h1 ^ (h2 << 1); - } - u8string VersionString(const ObjectVersion& version) { return std::to_string(std::get<0>(version)) + "." + std::to_string(std::get<1>(version)) + "." diff --git a/src/openrct2/object/ObjectAsset.cpp b/src/openrct2/object/ObjectAsset.cpp new file mode 100644 index 0000000000..6a7e758470 --- /dev/null +++ b/src/openrct2/object/ObjectAsset.cpp @@ -0,0 +1,110 @@ + +/***************************************************************************** + * Copyright (c) 2014-2026 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#include "ObjectAsset.h" + +#include "../core/File.h" +#include "../core/FileStream.h" +#include "../core/Zip.h" +#include "../core/ZipStream.hpp" + +namespace OpenRCT2 +{ + bool ObjectAsset::IsAvailable() const + { + if (_zipPath.empty()) + { + return File::Exists(_path); + } + + auto zipArchive = Zip::TryOpen(_zipPath, ZipAccess::read); + return zipArchive != nullptr && zipArchive->Exists(_path); + } + + uint64_t ObjectAsset::GetSize() const + { + if (_zipPath.empty()) + { + return File::GetSize(_path); + } + + auto zipArchive = Zip::TryOpen(_zipPath, ZipAccess::read); + if (zipArchive != nullptr) + { + auto index = zipArchive->GetIndexFromPath(_path); + if (index.has_value()) + { + auto size = zipArchive->GetFileSize(index.value()); + return size; + } + } + return 0; + } + + std::vector ObjectAsset::GetData() const + { + if (_zipPath.empty()) + { + return File::ReadAllBytes(_path); + } + + auto zipArchive = Zip::TryOpen(_zipPath, ZipAccess::read); + if (zipArchive != nullptr) + { + return zipArchive->GetFileData(_path); + } + return {}; + } + + std::unique_ptr ObjectAsset::GetStream() const + { + try + { + if (_zipPath.empty()) + { + return std::make_unique(_path, FileMode::open); + } + + auto zipArchive = Zip::TryOpen(_zipPath, ZipAccess::read); + if (zipArchive != nullptr) + { + auto stream = zipArchive->GetFileStream(_path); + if (stream != nullptr) + { + return std::make_unique(std::move(zipArchive), std::move(stream)); + } + } + } + catch (...) + { + } + return {}; + } + + const std::string& ObjectAsset::GetZipPath() const + { + return _zipPath; + } + + const std::string& ObjectAsset::GetPath() const + { + return _path; + } + + size_t ObjectAsset::GetHash() const + { + // Combine hashes of zipPath and path + std::hash hasher; + auto h1 = hasher(_zipPath); + auto h2 = hasher(_path); + // Combine the hashes based on example from https://en.cppreference.com/w/cpp/utility/hash.html + return h1 ^ (h2 << 1); + } +} // namespace OpenRCT2 diff --git a/src/openrct2/object/ObjectAsset.h b/src/openrct2/object/ObjectAsset.h index 2bda3de114..bb7e4a2572 100644 --- a/src/openrct2/object/ObjectAsset.h +++ b/src/openrct2/object/ObjectAsset.h @@ -17,6 +17,15 @@ namespace OpenRCT2 { struct IStream; + /** + * A wrapper for an object held in a file or as a file within a zip + * archive. + * + * If only a `path` is provided, GetStream() and GetData() will return the + * content of the file directly. If a `zipPath` and `path` are provided, + * GetStream() and GetData() will return the content of the file at `path` + * within the zip archive at `zipPath`. + */ class ObjectAsset { private: diff --git a/src/openrct2/object/ObjectFactory.cpp b/src/openrct2/object/ObjectFactory.cpp index ee26068eb8..1a145aaa72 100644 --- a/src/openrct2/object/ObjectFactory.cpp +++ b/src/openrct2/object/ObjectFactory.cpp @@ -35,6 +35,7 @@ #include "LargeSceneryObject.h" #include "MusicObject.h" #include "Object.h" +#include "ObjectAsset.h" #include "ObjectLimits.h" #include "PathAdditionObject.h" #include "PeepAnimationsObject.h" From 44de4bf07ee70a4cd668d23919529e095211c857 Mon Sep 17 00:00:00 2001 From: OpenRCT2 git bot Date: Mon, 12 Oct 2026 04:13:34 +0000 Subject: [PATCH 13/33] Merge Localisation/master into OpenRCT2/develop --- data/language/fr-FR.txt | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/data/language/fr-FR.txt b/data/language/fr-FR.txt index 2693ed9a61..03b1b6922f 100644 --- a/data/language/fr-FR.txt +++ b/data/language/fr-FR.txt @@ -2685,8 +2685,8 @@ STR_5582 :Toujours garder le curseur dans la fenêtre STR_5583 :{COMMA1DP16}m/s STR_5584 :SI STR_5585 :Débloque les limites d’exploitation des attractions, permettant par exemple une remontée à {VELOCITY} -STR_5586 :Ouvrir les magasins et boutiques automatiquement -STR_5587 :Ouvre automatiquement les magasins et boutiques après leur construction +STR_5586 :Ouvrir/fermer les magasins et boutiques automatiquement +STR_5587 :Ouvre automatiquement les magasins et boutiques après leur construction, et les ferme automatiquement avant leur démolition STR_5588 :Jouer avec d’autres joueurs STR_5589 :Paramètres de notifications STR_5590 :Prix du parc @@ -3851,3 +3851,21 @@ STR_7060 :Visiteurs regardant la construction de {STRINGID} STR_7061 :Visiteurs regardant le décor STR_7062 :Visiteurs quittant le parc STR_7063 :Visiteurs regardant la construction d’une nouvelle attraction +STR_7064 :Or +STR_7065 :Ambre +STR_7066 :Améthyste +STR_7067 :Asperge +STR_7068 :Marron +STR_7069 :Rose brûlé +STR_7070 :Cactus +STR_7071 :Caramel +STR_7072 :Cuivre +STR_7073 :Pourpre +STR_7074 :Eau sombre +STR_7075 :Émeraude +STR_7076 :Indigo +STR_7077 :Pesto +STR_7078 :Vert sapin +STR_7079 :Rubis +STR_7080 :Bleu profond +STR_7081 :Argent From 2107821cbe89eef0fbd66019ae87cb0a889b2b7e Mon Sep 17 00:00:00 2001 From: Sjoerd de Bruin Date: Wed, 14 Oct 2026 18:00:42 +0200 Subject: [PATCH 14/33] Fix #27286: Headless servers do not write chat logs (#27287) --- distribution/changelog.txt | 1 + src/openrct2-ui/interface/Chat.cpp | 3 --- src/openrct2/network/NetworkBase.cpp | 2 ++ 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index c38bde4002..9d9a212a30 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -3,6 +3,7 @@ - Fix: [#16807] Error messages when trying to load regular JSON files as custom objects. - Fix: [#24524] Some build types (like AppImage) lack information about their specific build. - Fix: [#27264] Headless server crashes when loading a recolourable terrain surface. +- Fix: [#27286] Headless servers no longer write chat logs. 0.5.6 (2026-10-10) ------------------------------------------------------------------------ diff --git a/src/openrct2-ui/interface/Chat.cpp b/src/openrct2-ui/interface/Chat.cpp index 5f085c56d8..335b8739e7 100644 --- a/src/openrct2-ui/interface/Chat.cpp +++ b/src/openrct2-ui/interface/Chat.cpp @@ -245,9 +245,6 @@ namespace OpenRCT2 _chatHistory.push_front(buffer); _chatHistoryTime.push_front(Platform::GetTicks()); - // Log to file (src only as logging does its own timestamp) - Network::AppendChatLog(s); - CreateAudioChannel(SoundId::newsItem, false, kMixerVolumeMax, 0.5f, 1.5f, true); } diff --git a/src/openrct2/network/NetworkBase.cpp b/src/openrct2/network/NetworkBase.cpp index 71cac9e7d7..de263f5c63 100644 --- a/src/openrct2/network/NetworkBase.cpp +++ b/src/openrct2/network/NetworkBase.cpp @@ -105,6 +105,8 @@ namespace OpenRCT2::Network static void ChatAddHistory(const u8string& text) { + AppendChatLog(text); + auto intent = Intent(INTENT_ACTION_CHAT_ADD_HISTORY); intent.PutExtra(INTENT_EXTRA_MESSAGE, text); ContextBroadcastIntent(&intent); From 9f086624910b679498f83e6ce94f6335b756b21e Mon Sep 17 00:00:00 2001 From: tbarford <68566618+tbarford@users.noreply.github.com> Date: Sat, 17 Oct 2026 03:02:12 -0500 Subject: [PATCH 15/33] Disable building tiny turns after banked pieces (#27288) --- src/openrct2-ui/windows/RideConstruction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 1d6a54ecb7..fd48c45c03 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -725,7 +725,7 @@ namespace OpenRCT2::Ui::Windows if (_currentTrackRollEnd != TrackRoll::none || _previousTrackRollEnd != TrackRoll::none) { newDisabledWidgets |= (1uLL << WIDX_SLOPE_DOWN_STEEP) | (1uLL << WIDX_SLOPE_UP_STEEP) - | (1uLL << WIDX_CHAIN_LIFT); + | (1uLL << WIDX_CHAIN_LIFT) | (1uLL << WIDX_LEFT_CURVE_VERY_SMALL) | (1uLL << WIDX_RIGHT_CURVE_VERY_SMALL); } if (_currentlySelectedTrack != TrackCurve::none) { From 815ac9352a795d459a3ecf6eaf394aebd99eb755 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek <1478678+Gymnasiast@users.noreply.github.com> Date: Sat, 17 Oct 2026 11:06:44 +0200 Subject: [PATCH 16/33] Fix #27293: ObjectAsset is unable to compile (#27297) --- src/openrct2/object/ObjectAsset.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/openrct2/object/ObjectAsset.h b/src/openrct2/object/ObjectAsset.h index bb7e4a2572..9288bd5514 100644 --- a/src/openrct2/object/ObjectAsset.h +++ b/src/openrct2/object/ObjectAsset.h @@ -9,6 +9,7 @@ #pragma once +#include #include #include #include From 105131d5f4301f6bde5df13b3082c0cb41c878b1 Mon Sep 17 00:00:00 2001 From: MarkAlliban <115544029+MarkAlliban@users.noreply.github.com> Date: Sun, 18 Oct 2026 08:27:25 +0100 Subject: [PATCH 17/33] For plugin API, add segmentLength to the ride.stations array (#27298) This is required for several reasons: calculating soft guest cap for harder guest generation, stat requirements for multi-station rides, etc. --- distribution/scripting/openrct2.d.ts | 1 + src/openrct2/scripting/bindings/ride/ScRideStation.cpp | 8 ++++++++ src/openrct2/scripting/bindings/ride/ScRideStation.hpp | 1 + 3 files changed, 10 insertions(+) diff --git a/distribution/scripting/openrct2.d.ts b/distribution/scripting/openrct2.d.ts index 8483c784f9..39830f227a 100644 --- a/distribution/scripting/openrct2.d.ts +++ b/distribution/scripting/openrct2.d.ts @@ -2637,6 +2637,7 @@ declare global { exit: CoordsXYZD; /** Queue wait time in minutes for this station. */ readonly queueTime: number; + readonly segmentLength: number; } interface TrackSegment { diff --git a/src/openrct2/scripting/bindings/ride/ScRideStation.cpp b/src/openrct2/scripting/bindings/ride/ScRideStation.cpp index 3afa140ee9..347d55311a 100644 --- a/src/openrct2/scripting/bindings/ride/ScRideStation.cpp +++ b/src/openrct2/scripting/bindings/ride/ScRideStation.cpp @@ -11,6 +11,7 @@ #include "ScRideStation.hpp" + #include "../../../core/UnitConversion.h" #include "../../../ride/Ride.h" namespace OpenRCT2::Scripting @@ -23,6 +24,7 @@ namespace OpenRCT2::Scripting JS_CGETSET_DEF("entrance", ScRideStation::entrance_get, ScRideStation::entrance_set), JS_CGETSET_DEF("exit", ScRideStation::exit_get, ScRideStation::exit_set), JS_CGETSET_DEF("queueTime", ScRideStation::queueTime_get, nullptr), + JS_CGETSET_DEF("segmentLength", ScRideStation::segmentLength_get, nullptr), }; RegisterBase(ctx, "RideStation", Finalize, funcs); } @@ -102,6 +104,12 @@ namespace OpenRCT2::Scripting return JS_UNDEFINED; } + JSValue ScRideStation::segmentLength_get(JSContext* ctx, JSValue thisVal) + { + auto station = GetRideStation(thisVal); + return JS_NewInt32(ctx, station != nullptr ? ToHumanReadableRideLength(station->segmentLength) : 0); + } + JSValue ScRideStation::entrance_get(JSContext* ctx, JSValue thisVal) { auto station = GetRideStation(thisVal); diff --git a/src/openrct2/scripting/bindings/ride/ScRideStation.hpp b/src/openrct2/scripting/bindings/ride/ScRideStation.hpp index 6886235681..1482cbae67 100644 --- a/src/openrct2/scripting/bindings/ride/ScRideStation.hpp +++ b/src/openrct2/scripting/bindings/ride/ScRideStation.hpp @@ -51,6 +51,7 @@ namespace OpenRCT2::Scripting static JSValue exit_get(JSContext* ctx, JSValue thisVal); static JSValue exit_set(JSContext* ctx, JSValue thisVal, JSValue value); static JSValue queueTime_get(JSContext* ctx, JSValue thisVal); + static JSValue segmentLength_get(JSContext* ctx, JSValue thisVal); }; } // namespace OpenRCT2::Scripting From 53bbc400e28be44d3c2e56fa514d5f65b61a64d4 Mon Sep 17 00:00:00 2001 From: MarkAlliban <115544029+MarkAlliban@users.noreply.github.com> Date: Sun, 18 Oct 2026 08:28:19 +0100 Subject: [PATCH 18/33] Populate scenario.objective.length (the getter already exists) (#27294) --- src/openrct2/scripting/bindings/world/ScScenario.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/openrct2/scripting/bindings/world/ScScenario.hpp b/src/openrct2/scripting/bindings/world/ScScenario.hpp index f740844f2f..32dcca431f 100644 --- a/src/openrct2/scripting/bindings/world/ScScenario.hpp +++ b/src/openrct2/scripting/bindings/world/ScScenario.hpp @@ -207,6 +207,7 @@ namespace OpenRCT2::Scripting JS_CGETSET_DEF("guests", ScScenarioObjective::guests_get, ScScenarioObjective::guests_set), JS_CGETSET_DEF("year", ScScenarioObjective::year_get, ScScenarioObjective::year_set), JS_CGETSET_DEF("excitement", ScScenarioObjective::excitement_get, ScScenarioObjective::excitement_set), + JS_CGETSET_DEF("length", ScScenarioObjective::length_get, ScScenarioObjective::length_set), JS_CGETSET_DEF("monthlyIncome", ScScenarioObjective::monthlyIncome_get, ScScenarioObjective::monthlyIncome_set), JS_CGETSET_DEF("parkValue", ScScenarioObjective::parkValue_get, ScScenarioObjective::parkValue_set), }; From 5679873393bd4b474d3d7ae6873f4286a37f08ee Mon Sep 17 00:00:00 2001 From: mix Date: Mon, 19 Oct 2026 22:20:21 +0100 Subject: [PATCH 19/33] Fix #27300: Can't place walls on all tiles of air powered slopes --- distribution/changelog.txt | 1 + src/openrct2/ride/TrackData.cpp | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index f4aa3ecfa1..373440e7ad 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -5,6 +5,7 @@ - Fix: [#24524] Some build types (like AppImage) lack information about their specific build. - Fix: [#27264] Headless server crashes when loading a recolourable terrain surface. - Fix: [#27286] Headless servers no longer write chat logs. +- Fix: [#27300] Walls cannot be placed on every edge of the Reverse Freefall/Air Powered flat to vertical slopes (original bug). 0.5.6 (2026-10-10) ------------------------------------------------------------------------ diff --git a/src/openrct2/ride/TrackData.cpp b/src/openrct2/ride/TrackData.cpp index 4342a0eb4e..e5716dc227 100644 --- a/src/openrct2/ride/TrackData.cpp +++ b/src/openrct2/ride/TrackData.cpp @@ -2288,6 +2288,7 @@ namespace OpenRCT2::TrackMetadata static constexpr SequenceDescriptor kReverseFreefallSlopeSeq6 = { .clearance = { -160, 0, 0, 208, { 0b1111, 0 }, {} }, + .allowedWallEdges = 0b1010, .woodenSupports = { WoodenSupportSubType::neSw }, .blockedSegments = kFlatStraightBlockedSegments, }; @@ -4544,7 +4545,7 @@ namespace OpenRCT2::TrackMetadata static constexpr SequenceDescriptor kAirThrustVerticalDownToLevelSeq1 = { .clearance = { 32, 0, 0, 208, { 0b1111, 0 }, {} }, - .allowedWallEdges = 0b1010, + .allowedWallEdges = 0b1110, .woodenSupports = { WoodenSupportSubType::neSw }, .blockedSegments = { { kSegmentsUnimplemented, // narrow @@ -4600,6 +4601,7 @@ namespace OpenRCT2::TrackMetadata static constexpr SequenceDescriptor kAirThrustVerticalDownToLevelSeq6 = { .clearance = { -160, 0, 0, 16, { 0b1111, 0 }, {} }, + .allowedWallEdges = 0b1010, .woodenSupports = { WoodenSupportSubType::neSw }, .blockedSegments = { { kSegmentsUnimplemented, // narrow From 2f7ad0cc476c0539f8aaff222e82b2e4789cc9e0 Mon Sep 17 00:00:00 2001 From: mix Date: Mon, 19 Oct 2026 22:22:32 +0100 Subject: [PATCH 20/33] Make height markers on airThrustVerticalDownToLevel equal to up variant --- src/openrct2/ride/TrackData.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openrct2/ride/TrackData.cpp b/src/openrct2/ride/TrackData.cpp index e5716dc227..ff98dad8f1 100644 --- a/src/openrct2/ride/TrackData.cpp +++ b/src/openrct2/ride/TrackData.cpp @@ -4534,7 +4534,6 @@ namespace OpenRCT2::TrackMetadata static constexpr SequenceDescriptor kAirThrustVerticalDownToLevelSeq0 = { .clearance = { 0, 0, 0, 208, { 0b1111, 0 }, {} }, .allowedWallEdges = 0b1010, - .flags = { SequenceFlag::hasHeightMarker }, .woodenSupports = { WoodenSupportSubType::neSw }, .blockedSegments = { { kSegmentsUnimplemented, // narrow @@ -4546,6 +4545,7 @@ namespace OpenRCT2::TrackMetadata static constexpr SequenceDescriptor kAirThrustVerticalDownToLevelSeq1 = { .clearance = { 32, 0, 0, 208, { 0b1111, 0 }, {} }, .allowedWallEdges = 0b1110, + .flags = { SequenceFlag::hasHeightMarker }, .woodenSupports = { WoodenSupportSubType::neSw }, .blockedSegments = { { kSegmentsUnimplemented, // narrow @@ -4590,7 +4590,6 @@ namespace OpenRCT2::TrackMetadata static constexpr SequenceDescriptor kAirThrustVerticalDownToLevelSeq5 = { .clearance = { -128, 0, 0, 32, { 0b1111, 0 }, {} }, .allowedWallEdges = 0b1010, - .flags = { SequenceFlag::hasHeightMarker }, .woodenSupports = { WoodenSupportSubType::neSw }, .blockedSegments = { { kSegmentsUnimplemented, // narrow @@ -4602,6 +4601,7 @@ namespace OpenRCT2::TrackMetadata static constexpr SequenceDescriptor kAirThrustVerticalDownToLevelSeq6 = { .clearance = { -160, 0, 0, 16, { 0b1111, 0 }, {} }, .allowedWallEdges = 0b1010, + .flags = { SequenceFlag::hasHeightMarker }, .woodenSupports = { WoodenSupportSubType::neSw }, .blockedSegments = { { kSegmentsUnimplemented, // narrow From d7176d3cb09bdb9fa225dfbdde2ca2dec4eb59da Mon Sep 17 00:00:00 2001 From: mix Date: Mon, 19 Oct 2026 22:24:54 +0100 Subject: [PATCH 21/33] Remove narrow and inverted blocks in reverseFreefallSlope sequences --- src/openrct2/ride/TrackData.cpp | 42 +++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/src/openrct2/ride/TrackData.cpp b/src/openrct2/ride/TrackData.cpp index ff98dad8f1..0f93d4b1ea 100644 --- a/src/openrct2/ride/TrackData.cpp +++ b/src/openrct2/ride/TrackData.cpp @@ -2247,35 +2247,55 @@ namespace OpenRCT2::TrackMetadata .allowedWallEdges = 0b1010, .flags = { SequenceFlag::hasHeightMarker }, .woodenSupports = { WoodenSupportSubType::neSw }, - .blockedSegments = kFlatStraightBlockedSegments, + .blockedSegments = { { + kSegmentsUnimplemented, // narrow + kSegmentsUnimplemented, // inverted + kSegmentsAll, // wide + } }, }; static constexpr SequenceDescriptor kReverseFreefallSlopeSeq1 = { .clearance = { -32, 0, 0, 32, { 0b1111, 0 }, {} }, .allowedWallEdges = 0b1010, .woodenSupports = { WoodenSupportSubType::neSw }, - .blockedSegments = kFlatStraightBlockedSegments, + .blockedSegments = { { + kSegmentsUnimplemented, // narrow + kSegmentsUnimplemented, // inverted + kSegmentsAll, // wide + } }, }; static constexpr SequenceDescriptor kReverseFreefallSlopeSeq2 = { .clearance = { -64, 0, 0, 48, { 0b1111, 0 }, {} }, .allowedWallEdges = 0b1010, .woodenSupports = { WoodenSupportSubType::neSw }, - .blockedSegments = kFlatStraightBlockedSegments, + .blockedSegments = { { + kSegmentsUnimplemented, // narrow + kSegmentsUnimplemented, // inverted + kSegmentsAll, // wide + } }, }; static constexpr SequenceDescriptor kReverseFreefallSlopeSeq3 = { .clearance = { -96, 0, 0, 80, { 0b1111, 0 }, {} }, .allowedWallEdges = 0b1010, .woodenSupports = { WoodenSupportSubType::neSw }, - .blockedSegments = kFlatStraightBlockedSegments, + .blockedSegments = { { + kSegmentsUnimplemented, // narrow + kSegmentsUnimplemented, // inverted + kSegmentsAll, // wide + } }, }; static constexpr SequenceDescriptor kReverseFreefallSlopeSeq4 = { .clearance = { -128, 0, 0, 160, { 0b1111, 0 }, {} }, .allowedWallEdges = 0b1010, .woodenSupports = { WoodenSupportSubType::neSw }, - .blockedSegments = kFlatStraightBlockedSegments, + .blockedSegments = { { + kSegmentsUnimplemented, // narrow + kSegmentsUnimplemented, // inverted + kSegmentsAll, // wide + } }, }; static constexpr SequenceDescriptor kReverseFreefallSlopeSeq5 = { @@ -2283,14 +2303,22 @@ namespace OpenRCT2::TrackMetadata .allowedWallEdges = 0b1011, .flags = { SequenceFlag::hasHeightMarker }, .woodenSupports = { WoodenSupportSubType::neSw }, - .blockedSegments = kFlatStraightBlockedSegments, + .blockedSegments = { { + kSegmentsUnimplemented, // narrow + kSegmentsUnimplemented, // inverted + kSegmentsAll, // wide + } }, }; static constexpr SequenceDescriptor kReverseFreefallSlopeSeq6 = { .clearance = { -160, 0, 0, 208, { 0b1111, 0 }, {} }, .allowedWallEdges = 0b1010, .woodenSupports = { WoodenSupportSubType::neSw }, - .blockedSegments = kFlatStraightBlockedSegments, + .blockedSegments = { { + kSegmentsUnimplemented, // narrow + kSegmentsUnimplemented, // inverted + kSegmentsAll, // wide + } }, }; static constexpr SequenceDescriptor kReverseFreefallVerticalSeq0 = { From 22bed1ad0309847a5b7140ac5a782e3c60dbbb4d Mon Sep 17 00:00:00 2001 From: mix Date: Mon, 19 Oct 2026 22:26:09 +0100 Subject: [PATCH 22/33] Bump network version --- src/openrct2/network/NetworkBase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2/network/NetworkBase.cpp b/src/openrct2/network/NetworkBase.cpp index de263f5c63..0232a246df 100644 --- a/src/openrct2/network/NetworkBase.cpp +++ b/src/openrct2/network/NetworkBase.cpp @@ -47,7 +47,7 @@ // It is used for making sure only compatible builds get connected, even within // single OpenRCT2 version. -constexpr uint8_t kStreamVersion = 0; +constexpr uint8_t kStreamVersion = 1; const std::string kStreamID = std::string(kOpenRCT2Version) + "-" + std::to_string(kStreamVersion); From 0a5f145ae5e51afddb76fa6905d7d82656c4f604 Mon Sep 17 00:00:00 2001 From: MarkAlliban <115544029+MarkAlliban@users.noreply.github.com> Date: Wed, 21 Oct 2026 10:06:21 +0100 Subject: [PATCH 23/33] =?UTF-8?q?Add=20=E2=80=98popularity=E2=80=99=20to?= =?UTF-8?q?=20plugin,=20fix=20values=20for=20=E2=80=98satisfaction?= =?UTF-8?q?=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contributors.md | 1 + distribution/scripting/openrct2.d.ts | 9 +++++++-- src/openrct2/scripting/bindings/ride/ScRide.cpp | 13 ++++++++++++- src/openrct2/scripting/bindings/ride/ScRide.hpp | 1 + 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/contributors.md b/contributors.md index f05c48b141..12f6d6343a 100644 --- a/contributors.md +++ b/contributors.md @@ -132,6 +132,7 @@ Appreciation for contributors who have provided substantial work, but are no lon * Ben Spurlock (BenDaSpur) - Plugin API automation helpers * (frozensnowy) - Draggable path slopes, self-intersecting track designs, refactors, bug fixes, misc. * Arjan van Dijk (Manticore-007) - Added guests entertained to API. +* Mark Alliban (MarkAlliban) - Added plugin API fields. ## Bug fixes & Refactors * Claudio Tiecher (janclod) diff --git a/distribution/scripting/openrct2.d.ts b/distribution/scripting/openrct2.d.ts index 39830f227a..d4c8e32aab 100644 --- a/distribution/scripting/openrct2.d.ts +++ b/distribution/scripting/openrct2.d.ts @@ -2530,9 +2530,14 @@ declare global { readonly minLiftHillSpeed: number; /** - * The satisfaction rating of the ride from 0 to 100. + * The satisfaction rating of the ride from 0 to 100, or NULL if not yet calculated. */ - readonly satisfaction: number; + readonly satisfaction: number | null; + + /** + * The popularity rating of the ride from 0 to 100, or NULL if not calculated. + */ + readonly popularity: number | null; /** * The max speed in miles per hour. diff --git a/src/openrct2/scripting/bindings/ride/ScRide.cpp b/src/openrct2/scripting/bindings/ride/ScRide.cpp index 0669b77c55..ccf31aa7dc 100644 --- a/src/openrct2/scripting/bindings/ride/ScRide.cpp +++ b/src/openrct2/scripting/bindings/ride/ScRide.cpp @@ -63,6 +63,7 @@ namespace OpenRCT2::Scripting JS_CGETSET_DEF("maxLiftHillSpeed", ScRide::maxLiftHillSpeed_get, nullptr), JS_CGETSET_DEF("minLiftHillSpeed", ScRide::minLiftHillSpeed_get, nullptr), JS_CGETSET_DEF("satisfaction", ScRide::satisfaction_get, nullptr), + JS_CGETSET_DEF("popularity", ScRide::popularity_get, nullptr), JS_CGETSET_DEF("maxSpeed", ScRide::maxSpeed_get, nullptr), JS_CGETSET_DEF("averageSpeed", ScRide::averageSpeed_get, nullptr), JS_CGETSET_DEF("rideTime", ScRide::rideTime_get, nullptr), @@ -732,7 +733,17 @@ namespace OpenRCT2::Scripting JSValue ScRide::satisfaction_get(JSContext* ctx, JSValue thisVal) { auto ride = GetRide(thisVal); - return JS_NewUint32(ctx, ride != nullptr ? ride->satisfaction * 5 : 0); + if (ride == nullptr || ride->satisfaction == 255) + return JS_NULL; + return JS_NewUint32(ctx, ride->satisfaction * 5); + } + + JSValue ScRide::popularity_get(JSContext* ctx, JSValue thisVal) + { + auto ride = GetRide(thisVal); + if (ride == nullptr || ride->popularity == 255) + return JS_NULL; + return JS_NewUint32(ctx, ride->popularity * 4); } JSValue ScRide::maxSpeed_get(JSContext* ctx, JSValue thisVal) diff --git a/src/openrct2/scripting/bindings/ride/ScRide.hpp b/src/openrct2/scripting/bindings/ride/ScRide.hpp index 276487155c..69e42e5d79 100644 --- a/src/openrct2/scripting/bindings/ride/ScRide.hpp +++ b/src/openrct2/scripting/bindings/ride/ScRide.hpp @@ -133,6 +133,7 @@ namespace OpenRCT2::Scripting static JSValue maxLiftHillSpeed_get(JSContext* ctx, JSValue thisVal); static JSValue minLiftHillSpeed_get(JSContext* ctx, JSValue thisVal); static JSValue satisfaction_get(JSContext* ctx, JSValue thisVal); + static JSValue popularity_get(JSContext* ctx, JSValue thisVal); static JSValue maxSpeed_get(JSContext* ctx, JSValue thisVal); static JSValue averageSpeed_get(JSContext* ctx, JSValue thisVal); static JSValue rideTime_get(JSContext* ctx, JSValue thisVal); From f67b6891db5773bf6c59dc665b46f11932389658 Mon Sep 17 00:00:00 2001 From: mix <167040362+mixiate@users.noreply.github.com> Date: Fri, 23 Oct 2026 21:59:40 +0100 Subject: [PATCH 24/33] Fix a few height markers on large gentle turns, diagonal banked piece (#27316) --- distribution/changelog.txt | 1 + src/openrct2/ride/TrackData.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 373440e7ad..c27f103430 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -6,6 +6,7 @@ - Fix: [#27264] Headless server crashes when loading a recolourable terrain surface. - Fix: [#27286] Headless servers no longer write chat logs. - Fix: [#27300] Walls cannot be placed on every edge of the Reverse Freefall/Air Powered flat to vertical slopes (original bug). +- Fix: [#27316] Height markers are incorrect on diagonal flat to left banked down, large gentle turn left and right banked large gentle turn pieces. 0.5.6 (2026-10-10) ------------------------------------------------------------------------ diff --git a/src/openrct2/ride/TrackData.cpp b/src/openrct2/ride/TrackData.cpp index 0f93d4b1ea..fc427ffe25 100644 --- a/src/openrct2/ride/TrackData.cpp +++ b/src/openrct2/ride/TrackData.cpp @@ -5561,6 +5561,7 @@ namespace OpenRCT2::TrackMetadata static constexpr SequenceDescriptor kLeftEighthToOrthogonalUp25Seq4 = { .clearance = { -64, 32, 32, 16, { 0b1111, 0 }, {} }, .allowedWallEdges = 0b0010, + .flags = { SequenceFlag::hasHeightMarker }, .woodenSupports = { WoodenSupportSubType::neSw }, .blockedSegments = blockedSegmentsRotate(kRightEighthToDiagUp25Seq0.blockedSegments, 2), }; @@ -6172,7 +6173,6 @@ namespace OpenRCT2::TrackMetadata static constexpr SequenceDescriptor kDiagFlatToLeftBankedDown25Seq0 = { .clearance = { 0, 0, 0, 8, { 0b1101, 0 }, {} }, - .flags = { SequenceFlag::hasHeightMarker }, .blockedSegments = kDiagFlatSeq0.blockedSegments, }; @@ -6192,6 +6192,7 @@ namespace OpenRCT2::TrackMetadata static constexpr SequenceDescriptor kDiagFlatToLeftBankedDown25Seq3 = { .clearance = { -32, 32, 0, 8, { 0b0010, 0 }, {} }, + .flags = { SequenceFlag::hasHeightMarker }, .blockedSegments = kDiagFlatSeq3.blockedSegments, }; @@ -6617,7 +6618,6 @@ namespace OpenRCT2::TrackMetadata static constexpr SequenceDescriptor kRightEighthBankToOrthogonalDown25Seq0 = { .clearance = { 0, 0, -16, 24, { 0b1101, 0 }, {} }, - .flags = { SequenceFlag::hasHeightMarker }, .woodenSupports = { WoodenSupportSubType::neSw, WoodenSupportTransitionType::up25Deg }, .extraSupportRotation = 2, .blockedSegments = kRightEighthBankToOrthogonalUp25Seq0.blockedSegments, From 47163dabbb7a13d1bf11e6c24e735c3d59201208 Mon Sep 17 00:00:00 2001 From: anying <49945850+anyingiit@users.noreply.github.com> Date: Sat, 24 Oct 2026 05:10:59 +0800 Subject: [PATCH 25/33] Update constant notation in Entrance.h and NewsItem.h (#27317) Part of #21432. --- src/openrct2-ui/windows/News.cpp | 4 ++-- .../actions/park/ParkEntrancePlaceAction.cpp | 4 ++-- .../actions/ride/RideEntranceExitPlaceAction.cpp | 10 +++++----- src/openrct2/interface/InteractiveConsole.cpp | 2 +- src/openrct2/management/NewsItem.cpp | 12 ++++++------ src/openrct2/management/NewsItem.h | 12 ++++++------ src/openrct2/rct2/S6Importer.cpp | 2 +- src/openrct2/scripting/bindings/world/ScPark.cpp | 12 ++++++------ .../scripting/bindings/world/ScParkMessage.cpp | 2 +- src/openrct2/world/Entrance.h | 8 ++++---- 10 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/openrct2-ui/windows/News.cpp b/src/openrct2-ui/windows/News.cpp index 1084e46c6f..0c3359a23b 100644 --- a/src/openrct2-ui/windows/News.cpp +++ b/src/openrct2-ui/windows/News.cpp @@ -511,7 +511,7 @@ namespace OpenRCT2::Ui::Windows auto borderStyle = Rectangle::BorderStyle::outset; if (_pressedNewsItemIndex != -1) { - News::IsValidIndex(_pressedNewsItemIndex + News::ItemHistoryStart); + News::IsValidIndex(_pressedNewsItemIndex + News::kItemHistoryStart); if (i == _pressedNewsItemIndex && _pressedButtonIndex == 1) { borderStyle = Rectangle::BorderStyle::inset; @@ -593,7 +593,7 @@ namespace OpenRCT2::Ui::Windows auto borderStyle = Rectangle::BorderStyle::outset; if (_pressedNewsItemIndex != -1) { - News::IsValidIndex(_pressedNewsItemIndex + News::ItemHistoryStart); + News::IsValidIndex(_pressedNewsItemIndex + News::kItemHistoryStart); if (i == _pressedNewsItemIndex && _pressedButtonIndex == 2) borderStyle = Rectangle::BorderStyle::inset; } diff --git a/src/openrct2/actions/park/ParkEntrancePlaceAction.cpp b/src/openrct2/actions/park/ParkEntrancePlaceAction.cpp index 45f9979cd1..66aa654693 100644 --- a/src/openrct2/actions/park/ParkEntrancePlaceAction.cpp +++ b/src/openrct2/actions/park/ParkEntrancePlaceAction.cpp @@ -88,7 +88,7 @@ namespace OpenRCT2::GameActions } auto zLow = _loc.z; - auto zHigh = zLow + ParkEntranceHeight; + auto zHigh = zLow + kParkEntranceHeight; CoordsXYZ entranceLoc = _loc; for (uint8_t index = 0; index < 3; index++) { @@ -130,7 +130,7 @@ namespace OpenRCT2::GameActions park.entrances.push_back(_loc); auto zLow = _loc.z; - auto zHigh = zLow + ParkEntranceHeight; + auto zHigh = zLow + kParkEntranceHeight; CoordsXY entranceLoc = { _loc.x, _loc.y }; constexpr auto kEntranceSequences = std::to_array( diff --git a/src/openrct2/actions/ride/RideEntranceExitPlaceAction.cpp b/src/openrct2/actions/ride/RideEntranceExitPlaceAction.cpp index 5071c12592..407a866b43 100644 --- a/src/openrct2/actions/ride/RideEntranceExitPlaceAction.cpp +++ b/src/openrct2/actions/ride/RideEntranceExitPlaceAction.cpp @@ -117,7 +117,7 @@ namespace OpenRCT2::GameActions { return Result(Status::noFreeElements, errorTitle, STR_TILE_ELEMENT_LIMIT_REACHED); } - auto clear_z = z + (_isExit ? RideExitHeight : RideEntranceHeight); + auto clear_z = z + (_isExit ? kRideExitHeight : kRideEntranceHeight); auto canBuild = MapCanConstructWithClearAt( { _loc, z, clear_z }, MapPlaceNonSceneryClearFunc, { 0b1111, 0 }, GetFlags()); if (canBuild.error != Status::ok) @@ -132,7 +132,7 @@ namespace OpenRCT2::GameActions return Result(Status::disallowed, errorTitle, STR_RIDE_CANT_BUILD_THIS_UNDERWATER); } - if (z > MaxRideEntranceOrExitHeight) + if (z > kMaxRideEntranceOrExitHeight) { return Result(Status::disallowed, errorTitle, STR_TOO_HIGH); } @@ -186,7 +186,7 @@ namespace OpenRCT2::GameActions WallRemoveAtZ({ _loc, z }); } - auto clear_z = z + (_isExit ? RideExitHeight : RideEntranceHeight); + auto clear_z = z + (_isExit ? kRideExitHeight : kRideEntranceHeight); auto canBuild = MapCanConstructWithClearAt( { _loc, z, clear_z }, MapPlaceNonSceneryClearFunc, { 0b1111, 0 }, GetFlags().with(CommandFlag::apply)); if (canBuild.error != Status::ok) @@ -253,7 +253,7 @@ namespace OpenRCT2::GameActions return Result(Status::noFreeElements, errorTitle, STR_TILE_ELEMENT_LIMIT_REACHED); } int16_t baseZ = loc.z; - int16_t clearZ = baseZ + (isExit ? RideExitHeight : RideEntranceHeight); + int16_t clearZ = baseZ + (isExit ? kRideExitHeight : kRideEntranceHeight); auto canBuild = MapCanConstructWithClearAt({ loc, baseZ, clearZ }, MapPlaceNonSceneryClearFunc, { 0b1111, 0 }, {}); if (canBuild.error != Status::ok) { @@ -267,7 +267,7 @@ namespace OpenRCT2::GameActions return Result(Status::disallowed, errorTitle, STR_RIDE_CANT_BUILD_THIS_UNDERWATER); } - if (baseZ > MaxRideEntranceOrExitHeight) + if (baseZ > kMaxRideEntranceOrExitHeight) { return Result(Status::disallowed, errorTitle, STR_TOO_HIGH); } diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index 06d1ecfebf..bc2fe9afb8 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -1623,7 +1623,7 @@ static void ConsoleCommandAddNewsItem([[maybe_unused]] InteractiveConsole& conso if (argv.size() < 2) { console.WriteLineWarning("Too few arguments"); - static_assert(News::ItemTypeCount == 11, "News::ItemType::count changed, update console command!"); + static_assert(News::kItemTypeCount == 11, "News::ItemType::count changed, update console command!"); console.WriteLine("add_news_item [assoc]"); console.WriteLine("type is one of:"); console.WriteLine(" 0 (News::ItemType::null)"); diff --git a/src/openrct2/management/NewsItem.cpp b/src/openrct2/management/NewsItem.cpp index 811b52a07c..e4e4b3e2ef 100644 --- a/src/openrct2/management/NewsItem.cpp +++ b/src/openrct2/management/NewsItem.cpp @@ -44,7 +44,7 @@ const News::Item& News::ItemQueues::current() const bool News::IsValidIndex(int32_t index) { - if (index >= MaxItems) + if (index >= kMaxItems) { LOG_ERROR("Tried to get news item past MAX_NEWS."); return false; @@ -466,14 +466,14 @@ void News::AddItemToQueue(ItemQueues& queues, Item* newNewsItem) void News::RemoveItem(ItemQueues& queues, int32_t index) { - if (index < 0 || index >= MaxItems) + if (index < 0 || index >= kMaxItems) return; // News item is already null, no need to remove it if (queues[index].type == ItemType::null) return; - size_t newsBoundary = index < ItemHistoryStart ? ItemHistoryStart : MaxItems; + size_t newsBoundary = index < kItemHistoryStart ? kItemHistoryStart : kMaxItems; for (size_t i = index; i < newsBoundary - 1; i++) { queues[i] = queues[i + 1]; @@ -485,12 +485,12 @@ void News::importNewsItems(ItemQueues& queues, const std::span recen { queues.clear(); - for (size_t i = 0; i < std::min(recent.size(), ItemHistoryStart); i++) + for (size_t i = 0; i < std::min(recent.size(), kItemHistoryStart); i++) { queues[i] = recent[i]; } - for (size_t i = 0; i < std::min(archived.size(), MaxItemsArchive); i++) + for (size_t i = 0; i < std::min(archived.size(), kMaxItemsArchive); i++) { - queues[ItemHistoryStart + i] = archived[i]; + queues[kItemHistoryStart + i] = archived[i]; } } diff --git a/src/openrct2/management/NewsItem.h b/src/openrct2/management/NewsItem.h index 4de97c90f7..baf013082c 100644 --- a/src/openrct2/management/NewsItem.h +++ b/src/openrct2/management/NewsItem.h @@ -50,7 +50,7 @@ namespace OpenRCT2::News count }; - constexpr size_t ItemTypeCount = static_cast(ItemType::count); + constexpr size_t kItemTypeCount = static_cast(ItemType::count); enum ItemTypeProperty : uint8_t { @@ -126,9 +126,9 @@ namespace OpenRCT2::News } }; - constexpr int32_t ItemHistoryStart = 11; - constexpr int32_t MaxItemsArchive = 50; - constexpr int32_t MaxItems = ItemHistoryStart + MaxItemsArchive; + constexpr int32_t kItemHistoryStart = 11; + constexpr int32_t kMaxItemsArchive = 50; + constexpr int32_t kMaxItems = kItemHistoryStart + kMaxItemsArchive; template class ItemQueue @@ -296,8 +296,8 @@ namespace OpenRCT2::News private: int32_t removeTime() const; - ItemQueue _recent; - ItemQueue _archived; + ItemQueue _recent; + ItemQueue _archived; }; void InitQueue(Park::ParkData& park); diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 3deaf0ea3a..d430462462 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -315,7 +315,7 @@ namespace OpenRCT2::RCT2 if (src.Type == 0) break; - if (src.Type >= News::ItemTypeCount) + if (src.Type >= News::kItemTypeCount) { LOG_ERROR("Invalid news type 0x%x for news item %d, ignoring remaining news items", src.Type, index); break; diff --git a/src/openrct2/scripting/bindings/world/ScPark.cpp b/src/openrct2/scripting/bindings/world/ScPark.cpp index 67995b84b1..7240288e67 100644 --- a/src/openrct2/scripting/bindings/world/ScPark.cpp +++ b/src/openrct2/scripting/bindings/world/ScPark.cpp @@ -363,7 +363,7 @@ namespace OpenRCT2::Scripting } for (size_t i = 0, newsSize = newsItems.getArchived().size(); i < newsSize; i++) { - auto offset = i + News::ItemHistoryStart; + auto offset = i + News::kItemHistoryStart; JS_SetPropertyInt64(ctx, result, resultIdx++, gScParkMessage.New(ctx, offset)); } return result; @@ -372,14 +372,14 @@ namespace OpenRCT2::Scripting JSValue ScPark::messages_set(JSContext* ctx, JSValue thisVal, JSValue value) { int32_t index = 0; - int32_t archiveIndex = News::ItemHistoryStart; + int32_t archiveIndex = News::kItemHistoryStart; auto& newsItems = getGameState().park.newsItems; JSIterateArray(ctx, value, [&index, &archiveIndex, &newsItems](JSContext* ctx2, JSValue item) { auto isArchived = AsOrDefault(ctx2, item, "isArchived", false); auto newsItem = NewsItemFromJS(ctx2, item); if (isArchived) { - if (archiveIndex < News::MaxItems) + if (archiveIndex < News::kMaxItems) { newsItems[archiveIndex] = newsItem; archiveIndex++; @@ -387,7 +387,7 @@ namespace OpenRCT2::Scripting } else { - if (index < News::ItemHistoryStart) + if (index < News::kItemHistoryStart) { newsItems[index] = newsItem; index++; @@ -396,11 +396,11 @@ namespace OpenRCT2::Scripting }); // End the lists by setting next item to null - if (index < News::ItemHistoryStart) + if (index < News::kItemHistoryStart) { newsItems[index].type = News::ItemType::null; } - if (archiveIndex < News::MaxItems) + if (archiveIndex < News::kMaxItems) { newsItems[archiveIndex].type = News::ItemType::null; } diff --git a/src/openrct2/scripting/bindings/world/ScParkMessage.cpp b/src/openrct2/scripting/bindings/world/ScParkMessage.cpp index ed033a36f2..91efa39ece 100644 --- a/src/openrct2/scripting/bindings/world/ScParkMessage.cpp +++ b/src/openrct2/scripting/bindings/world/ScParkMessage.cpp @@ -29,7 +29,7 @@ namespace OpenRCT2::Scripting JSValue ScParkMessage::isArchived_get(JSContext* ctx, JSValue thisVal) { auto index = gScParkMessage.GetOpaque(thisVal)->index; - return JS_NewBool(ctx, index >= News::ItemHistoryStart); + return JS_NewBool(ctx, index >= News::kItemHistoryStart); } JSValue ScParkMessage::month_get(JSContext* ctx, JSValue thisVal) diff --git a/src/openrct2/world/Entrance.h b/src/openrct2/world/Entrance.h index 64addd0570..5ee0b983cf 100644 --- a/src/openrct2/world/Entrance.h +++ b/src/openrct2/world/Entrance.h @@ -16,14 +16,14 @@ struct CoordsXYE; struct CoordsXYZ; struct CoordsXYZD; -constexpr uint8_t ParkEntranceHeight = 12 * kCoordsZStep; -constexpr uint8_t RideEntranceHeight = 7 * kCoordsZStep; -constexpr uint8_t RideExitHeight = 5 * kCoordsZStep; +constexpr uint8_t kParkEntranceHeight = 12 * kCoordsZStep; +constexpr uint8_t kRideEntranceHeight = 7 * kCoordsZStep; +constexpr uint8_t kRideExitHeight = 5 * kCoordsZStep; extern bool gParkEntranceGhostExists; extern CoordsXYZD gParkEntranceGhostPosition; -constexpr int32_t MaxRideEntranceOrExitHeight = 244 * kCoordsZStep; +constexpr int32_t kMaxRideEntranceOrExitHeight = 244 * kCoordsZStep; extern CoordsXYZD gRideEntranceExitGhostPosition; extern StationIndex gRideEntranceExitGhostStationIndex; From 7c93b24193fb6fc4a4bc4eea6e9993159c538653 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek <1478678+Gymnasiast@users.noreply.github.com> Date: Sun, 25 Oct 2026 21:07:53 +0100 Subject: [PATCH 26/33] Rework news items (#27296) This does away with the notion of news items being one continuous list of 61 items, except for scripts. To this end, the accessors in ItemQueues (now Items) have been removed in favour of accessing the correct list directly. This struct now instead handles actions that involve both lists, as items that have stayed in the queue long enough (or are clicked away) need to move to the archive. --- src/openrct2-ui/windows/GameStatusBar.cpp | 2 +- src/openrct2-ui/windows/News.cpp | 18 +- src/openrct2-ui/windows/NewsTicker.cpp | 15 +- src/openrct2/GameState.cpp | 2 +- src/openrct2/ReplayManager.cpp | 8 +- src/openrct2/entity/Guest.cpp | 16 +- src/openrct2/entity/Peep.cpp | 39 ++-- src/openrct2/interface/InteractiveConsole.cpp | 2 +- src/openrct2/management/Award.cpp | 2 +- src/openrct2/management/Marketing.cpp | 4 +- src/openrct2/management/NewsItem.cpp | 188 ++++-------------- src/openrct2/management/NewsItem.h | 113 +++++------ src/openrct2/management/Research.cpp | 9 +- src/openrct2/park/ParkFile.cpp | 10 +- src/openrct2/rct1/S4Importer.cpp | 3 +- src/openrct2/rct2/S6Importer.cpp | 3 +- src/openrct2/ride/Ride.cpp | 29 ++- src/openrct2/ride/Vehicle.Crash.cpp | 7 +- src/openrct2/ride/Vehicle.Station.cpp | 4 +- src/openrct2/scenario/Scenario.cpp | 18 +- src/openrct2/scenario/ScenarioObjective.cpp | 2 +- .../scripting/bindings/world/ScPark.cpp | 32 +-- .../bindings/world/ScParkMessage.cpp | 15 +- src/openrct2/world/ParkData.h | 2 +- 24 files changed, 219 insertions(+), 324 deletions(-) diff --git a/src/openrct2-ui/windows/GameStatusBar.cpp b/src/openrct2-ui/windows/GameStatusBar.cpp index de48881fc5..e210a5150b 100644 --- a/src/openrct2-ui/windows/GameStatusBar.cpp +++ b/src/openrct2-ui/windows/GameStatusBar.cpp @@ -110,7 +110,7 @@ namespace OpenRCT2::Ui::Windows widgets[WIDX_PANEL_OUTSET].right = width - 1; widgets[WIDX_PANEL_INSET].right = width - 3; - bool useFullToolbar = getGameState().park.newsItems.isEmpty() + bool useFullToolbar = getGameState().park.newsItems.queue.empty() && (ThemeGetFlags() & UITHEME_FLAG_USE_GAME_STATUS_BAR) && gLegacyScene == LegacyScene::playing; widgets[WIDX_PANEL_OUTSET].setVisible(useFullToolbar); diff --git a/src/openrct2-ui/windows/News.cpp b/src/openrct2-ui/windows/News.cpp index 0c3359a23b..bbcd5a2cf8 100644 --- a/src/openrct2-ui/windows/News.cpp +++ b/src/openrct2-ui/windows/News.cpp @@ -114,7 +114,7 @@ namespace OpenRCT2::Ui::Windows private: int32_t _pressedNewsItemIndex{}, _pressedButtonIndex{}, _suspendUpdateTicks{}; WidgetIndex _baseCheckboxIndex{}; - News::ItemQueues& _queues; + News::Items& _queues; static int32_t CalculateNewsItemHeight() { @@ -365,12 +365,12 @@ namespace OpenRCT2::Ui::Windows size_t j = _pressedNewsItemIndex; _pressedNewsItemIndex = -1; - if (j >= _queues.getArchived().size()) + if (j >= _queues.archive.size()) { return; } - const auto& newsItem = _queues.getArchived()[j]; + const auto& newsItem = _queues.archive[j]; if (newsItem.hasButton()) { return; @@ -412,7 +412,7 @@ namespace OpenRCT2::Ui::Windows ScreenSize onScrollGetSize(int32_t scrollIndex) override { - int32_t scrollHeight = static_cast(_queues.getArchived().size()) * CalculateNewsItemHeight() + int32_t scrollHeight = static_cast(_queues.archive.size()) * CalculateNewsItemHeight() - kItemSeparatorHeight; return { kWindowSize.width, scrollHeight }; } @@ -423,7 +423,7 @@ namespace OpenRCT2::Ui::Windows int32_t i = 0; int32_t buttonIndex = 0; auto mutableScreenCoords = screenCoords; - for (const auto& newsItem : _queues.getArchived()) + for (const auto& newsItem : _queues.archive) { if (mutableScreenCoords.y < itemHeight) { @@ -470,7 +470,7 @@ namespace OpenRCT2::Ui::Windows const bool scrollbarVisible = scrolls[0].contentHeight > widgets[WIDX_SCROLL].height() - 1; const auto scrollbarFill = scrollbarVisible ? 0 : kScrollBarWidth; - for (const auto& newsItem : _queues.getArchived()) + for (const auto& newsItem : _queues.archive) { if (y >= rt.y + rt.height) break; @@ -509,9 +509,8 @@ namespace OpenRCT2::Ui::Windows auto screenCoords = ScreenCoordsXY{ 328 + scrollbarFill, y + lineHeight + 4 }; auto borderStyle = Rectangle::BorderStyle::outset; - if (_pressedNewsItemIndex != -1) + if (_pressedNewsItemIndex != -1 && _pressedNewsItemIndex < static_cast(_queues.archive.size())) { - News::IsValidIndex(_pressedNewsItemIndex + News::kItemHistoryStart); if (i == _pressedNewsItemIndex && _pressedButtonIndex == 1) { borderStyle = Rectangle::BorderStyle::inset; @@ -591,9 +590,8 @@ namespace OpenRCT2::Ui::Windows auto screenCoords = ScreenCoordsXY{ 352 + scrollbarFill, y + lineHeight + 4 }; auto borderStyle = Rectangle::BorderStyle::outset; - if (_pressedNewsItemIndex != -1) + if (_pressedNewsItemIndex != -1 && _pressedNewsItemIndex < static_cast(_queues.archive.size())) { - News::IsValidIndex(_pressedNewsItemIndex + News::kItemHistoryStart); if (i == _pressedNewsItemIndex && _pressedButtonIndex == 2) borderStyle = Rectangle::BorderStyle::inset; } diff --git a/src/openrct2-ui/windows/NewsTicker.cpp b/src/openrct2-ui/windows/NewsTicker.cpp index 318d50a94e..c5c64a0ee7 100644 --- a/src/openrct2-ui/windows/NewsTicker.cpp +++ b/src/openrct2-ui/windows/NewsTicker.cpp @@ -53,11 +53,11 @@ namespace OpenRCT2::Ui::Windows class NewsTicker final : public Window { private: - News::ItemQueues& _queues; + News::Items& _queues; void drawNewsItem(RenderTarget& rt) { - const auto* newsItem = News::GetItem(_queues, 0); + const auto* newsItem = _queues.getActiveMessage(); if (newsItem == nullptr) return; @@ -184,14 +184,14 @@ namespace OpenRCT2::Ui::Windows void onMouseUp(WidgetIndex widgetIndex) override { - const auto* newsItem = News::GetItem(_queues, 0); + const auto* newsItem = _queues.getActiveMessage(); if (newsItem == nullptr) return; switch (widgetIndex) { case WIDX_PANEL_INSET: - News::CloseCurrentItem(_queues); + _queues.archiveActiveItem(); break; case WIDX_NEWS_SUBJECT: News::OpenSubject(newsItem->type, newsItem->assoc); @@ -230,7 +230,10 @@ namespace OpenRCT2::Ui::Windows widgets[WIDX_NEWS_LOCATE].right = width - 6; widgets[WIDX_NEWS_LOCATE].left = widgets[WIDX_NEWS_LOCATE].right - 24; - auto* newsItem = News::GetItem(_queues, 0); + auto* newsItem = _queues.getActiveMessage(); + if (newsItem == nullptr) + return; + setWidgetDisabled(WIDX_NEWS_SUBJECT, false); setWidgetDisabled(WIDX_NEWS_LOCATE, false); @@ -265,7 +268,7 @@ namespace OpenRCT2::Ui::Windows if (currentFrame >= 24) currentFrame = 0; - if (_queues.isEmpty()) + if (_queues.queue.empty()) close(); } }; diff --git a/src/openrct2/GameState.cpp b/src/openrct2/GameState.cpp index 28ebaebee2..d102227c92 100644 --- a/src/openrct2/GameState.cpp +++ b/src/openrct2/GameState.cpp @@ -332,7 +332,7 @@ namespace OpenRCT2 ResearchUpdate(); RideRating::UpdateAll(); RideMeasurementsUpdate(); - News::UpdateCurrentItem(park.newsItems); + park.newsItems.updateActiveItem(); MapAnimations::InvalidateAndUpdateAll(); VehicleSoundsUpdate(); diff --git a/src/openrct2/ReplayManager.cpp b/src/openrct2/ReplayManager.cpp index f15b3b58b9..5b11a7cf22 100644 --- a/src/openrct2/ReplayManager.cpp +++ b/src/openrct2/ReplayManager.cpp @@ -344,8 +344,8 @@ namespace OpenRCT2 _currentRecording.reset(); - News::Item* news = News::AddItemToQueue( - getGameState().park.newsItems, News::ItemType::blank, "Replay recording stopped", 0); + News::Item* news = getGameState().park.newsItems.addItemToQueue( + News::ItemType::blank, "Replay recording stopped", 0); news->setFlags(News::ItemFlags::hasButton); // Has no subject. return true; @@ -471,8 +471,8 @@ namespace OpenRCT2 // During normal playback we pause the game if stopped. if (_mode == ReplayMode::playing) { - News::Item* news = News::AddItemToQueue( - getGameState().park.newsItems, News::ItemType::blank, "Replay playback complete", 0); + News::Item* news = getGameState().park.newsItems.addItemToQueue( + News::ItemType::blank, "Replay playback complete", 0); news->setFlags(News::ItemFlags::hasButton); // Has no subject. } diff --git a/src/openrct2/entity/Guest.cpp b/src/openrct2/entity/Guest.cpp index fd89d06d3c..1b3ed6f483 100644 --- a/src/openrct2/entity/Guest.cpp +++ b/src/openrct2/entity/Guest.cpp @@ -1619,9 +1619,8 @@ namespace OpenRCT2 ft.Add(shopItemDescriptor.Naming.Indefinite); if (Config::Get().notifications.guestBoughtItem) { - News::AddItemToQueue( - getGameState().park.newsItems, News::ItemType::peepOnRide, STR_PEEP_TRACKING_NOTIFICATION_BOUGHT_X, - guest.id, ft); + getGameState().park.newsItems.addItemToQueue( + News::ItemType::peepOnRide, STR_PEEP_TRACKING_NOTIFICATION_BOUGHT_X, guest.id, ft); } } @@ -3553,9 +3552,8 @@ namespace OpenRCT2 ride.formatNameTo(ft); if (Config::Get().notifications.rideWarnings) { - News::AddItemToQueue( - getGameState().park.newsItems, News::ItemType::ride, STR_GUESTS_GETTING_STUCK_ON_RIDE, - guest.currentRide.ToUnderlying(), ft); + getGameState().park.newsItems.addItemToQueue( + News::ItemType::ride, STR_GUESTS_GETTING_STUCK_ON_RIDE, guest.currentRide.ToUnderlying(), ft); } } } @@ -3860,7 +3858,7 @@ namespace OpenRCT2 if (Config::Get().notifications.guestOnRide) { - News::AddItemToQueue(getGameState().park.newsItems, News::ItemType::peepOnRide, msg_string, id, ft); + getGameState().park.newsItems.addItemToQueue(News::ItemType::peepOnRide, msg_string, id, ft); } } @@ -5019,8 +5017,8 @@ namespace OpenRCT2 if (Config::Get().notifications.guestLeftRide) { - News::AddItemToQueue( - getGameState().park.newsItems, News::ItemType::peepOnRide, STR_PEEP_TRACKING_LEFT_RIDE_X, id, ft); + getGameState().park.newsItems.addItemToQueue( + News::ItemType::peepOnRide, STR_PEEP_TRACKING_LEFT_RIDE_X, id, ft); } } } diff --git a/src/openrct2/entity/Peep.cpp b/src/openrct2/entity/Peep.cpp index 134c1b94cf..27fabfcca0 100644 --- a/src/openrct2/entity/Peep.cpp +++ b/src/openrct2/entity/Peep.cpp @@ -787,7 +787,7 @@ namespace OpenRCT2 { auto ft = Formatter(); formatNameTo(ft); - News::AddItemToQueue(park.newsItems, News::ItemType::blank, STR_NEWS_ITEM_GUEST_DROWNED, x | (y << 16), ft); + park.newsItems.addItemToQueue(News::ItemType::blank, STR_NEWS_ITEM_GUEST_DROWNED, x | (y << 16), ft); } park.ratingCasualtyPenalty = std::min(park.ratingCasualtyPenalty + 25, 1000); @@ -1049,7 +1049,7 @@ namespace OpenRCT2 if (Config::Get().notifications.guestWarnings) { constexpr auto kThoughtId = static_cast(PeepThoughtType::hungry); - News::AddItemToQueue(newsItems, News::ItemType::peeps, STR_PEEPS_ARE_HUNGRY, kThoughtId, {}); + newsItems.addItemToQueue(News::ItemType::peeps, STR_PEEPS_ARE_HUNGRY, kThoughtId, {}); } } @@ -1061,7 +1061,7 @@ namespace OpenRCT2 if (Config::Get().notifications.guestWarnings) { constexpr auto kThoughtId = static_cast(PeepThoughtType::thirsty); - News::AddItemToQueue(newsItems, News::ItemType::peeps, STR_PEEPS_ARE_THIRSTY, kThoughtId, {}); + newsItems.addItemToQueue(News::ItemType::peeps, STR_PEEPS_ARE_THIRSTY, kThoughtId, {}); } } @@ -1073,7 +1073,7 @@ namespace OpenRCT2 if (Config::Get().notifications.guestWarnings) { constexpr auto kThoughtId = static_cast(PeepThoughtType::toilet); - News::AddItemToQueue(newsItems, News::ItemType::peeps, STR_PEEPS_CANT_FIND_TOILET, kThoughtId, {}); + newsItems.addItemToQueue(News::ItemType::peeps, STR_PEEPS_CANT_FIND_TOILET, kThoughtId, {}); } } @@ -1085,7 +1085,7 @@ namespace OpenRCT2 if (Config::Get().notifications.guestWarnings) { constexpr auto kThoughtId = static_cast(PeepThoughtType::badLitter); - News::AddItemToQueue(newsItems, News::ItemType::peeps, STR_PEEPS_DISLIKE_LITTER, kThoughtId, {}); + newsItems.addItemToQueue(News::ItemType::peeps, STR_PEEPS_DISLIKE_LITTER, kThoughtId, {}); } } @@ -1097,7 +1097,7 @@ namespace OpenRCT2 if (Config::Get().notifications.guestWarnings) { constexpr auto kThoughtId = static_cast(PeepThoughtType::pathDisgusting); - News::AddItemToQueue(newsItems, News::ItemType::peeps, STR_PEEPS_DISGUSTED_BY_PATHS, kThoughtId, {}); + newsItems.addItemToQueue(News::ItemType::peeps, STR_PEEPS_DISGUSTED_BY_PATHS, kThoughtId, {}); } } @@ -1109,7 +1109,7 @@ namespace OpenRCT2 if (Config::Get().notifications.guestWarnings) { constexpr auto kThoughtId = static_cast(PeepThoughtType::vandalism); - News::AddItemToQueue(newsItems, News::ItemType::peeps, STR_PEEPS_DISLIKE_VANDALISM, kThoughtId, {}); + newsItems.addItemToQueue(News::ItemType::peeps, STR_PEEPS_DISLIKE_VANDALISM, kThoughtId, {}); } } @@ -1121,7 +1121,7 @@ namespace OpenRCT2 if (Config::Get().notifications.guestWarnings) { constexpr auto kThoughtId = static_cast(PeepThoughtType::cantFindExit); - News::AddItemToQueue(newsItems, News::ItemType::peeps, STR_PEEPS_GETTING_LOST_OR_STUCK, kThoughtId, {}); + newsItems.addItemToQueue(News::ItemType::peeps, STR_PEEPS_GETTING_LOST_OR_STUCK, kThoughtId, {}); } } else if (lostCounter >= kPeepLostWarningThreshold) @@ -1130,7 +1130,7 @@ namespace OpenRCT2 if (Config::Get().notifications.guestWarnings) { constexpr auto kThoughtId = static_cast(PeepThoughtType::lost); - News::AddItemToQueue(newsItems, News::ItemType::peeps, STR_PEEPS_GETTING_LOST_OR_STUCK, kThoughtId, {}); + newsItems.addItemToQueue(News::ItemType::peeps, STR_PEEPS_GETTING_LOST_OR_STUCK, kThoughtId, {}); } } @@ -1146,8 +1146,8 @@ namespace OpenRCT2 queueComplainingGuestsMap.begin(), queueComplainingGuestsMap.end(), [](auto& lhs, auto& rhs) { return lhs.second < rhs.second; }); auto rideId = rideWithMostQueueComplaints->first.ToUnderlying(); - News::AddItemToQueue( - newsItems, News::ItemType::ride, STR_PEEPS_COMPLAINING_ABOUT_QUEUE_LENGTH_WARNING, rideId, {}); + + newsItems.addItemToQueue(News::ItemType::ride, STR_PEEPS_COMPLAINING_ABOUT_QUEUE_LENGTH_WARNING, rideId, {}); } } } @@ -1652,9 +1652,8 @@ namespace OpenRCT2 ride->formatNameTo(ft); if (Config::Get().notifications.guestQueuingForRide) { - News::AddItemToQueue( - getGameState().park.newsItems, News::ItemType::peepOnRide, STR_PEEP_TRACKING_PEEP_JOINED_QUEUE_FOR_X, - guest->id, ft); + getGameState().park.newsItems.addItemToQueue( + News::ItemType::peepOnRide, STR_PEEP_TRACKING_PEEP_JOINED_QUEUE_FOR_X, guest->id, ft); } } } @@ -1714,9 +1713,8 @@ namespace OpenRCT2 guest->formatNameTo(ft); if (Config::Get().notifications.guestLeftPark) { - News::AddItemToQueue( - getGameState().park.newsItems, News::ItemType::peepOnRide, STR_PEEP_TRACKING_LEFT_PARK, guest->id, - ft); + getGameState().park.newsItems.addItemToQueue( + News::ItemType::peepOnRide, STR_PEEP_TRACKING_LEFT_PARK, guest->id, ft); } } return true; @@ -2108,9 +2106,8 @@ namespace OpenRCT2 ride->formatNameTo(ft); if (Config::Get().notifications.guestQueuingForRide) { - News::AddItemToQueue( - getGameState().park.newsItems, News::ItemType::peepOnRide, - STR_PEEP_TRACKING_PEEP_JOINED_QUEUE_FOR_X, guest->id, ft); + getGameState().park.newsItems.addItemToQueue( + News::ItemType::peepOnRide, STR_PEEP_TRACKING_PEEP_JOINED_QUEUE_FOR_X, guest->id, ft); } } @@ -2228,7 +2225,7 @@ namespace OpenRCT2 : STR_PEEP_TRACKING_PEEP_IS_ON_X; if (Config::Get().notifications.guestUsedFacility) { - News::AddItemToQueue(getGameState().park.newsItems, News::ItemType::peepOnRide, string_id, guest->id, ft); + getGameState().park.newsItems.addItemToQueue(News::ItemType::peepOnRide, string_id, guest->id, ft); } } } diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index bc2fe9afb8..dff5988a63 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -1663,7 +1663,7 @@ static void ConsoleCommandAddNewsItem([[maybe_unused]] InteractiveConsole& conso } } - News::AddItemToQueue(getGameState().park.newsItems, itemType, msg, assoc); + getGameState().park.newsItems.addItemToQueue(itemType, msg, assoc); console.WriteLine("Successfully added News Item"); } diff --git a/src/openrct2/management/Award.cpp b/src/openrct2/management/Award.cpp index 8f339615fe..578a0f8bb9 100644 --- a/src/openrct2/management/Award.cpp +++ b/src/openrct2/management/Award.cpp @@ -624,7 +624,7 @@ static void AwardAdd(AwardType type) park.currentAwards.push_back(Award{ 5u, type }); if (Config::Get().notifications.parkAward) { - News::AddItemToQueue(park.newsItems, News::ItemType::award, AwardGetNews(type), 0, {}); + park.newsItems.addItemToQueue(News::ItemType::award, AwardGetNews(type), 0, {}); } Ui::GetWindowManager()->InvalidateByClass(WindowClass::parkInformation); } diff --git a/src/openrct2/management/Marketing.cpp b/src/openrct2/management/Marketing.cpp index 5b32473090..12ffd74ba1 100644 --- a/src/openrct2/management/Marketing.cpp +++ b/src/openrct2/management/Marketing.cpp @@ -100,8 +100,8 @@ static void MarketingRaiseFinishedNotification(const MarketingCampaign& campaign ft.Add(GetShopItemDescriptor(campaign.shopItemType).Naming.Plural); } - News::AddItemToQueue( - getGameState().park.newsItems, News::ItemType::campaign, kMarketingCampaignNames[campaign.type][2], 0, ft); + getGameState().park.newsItems.addItemToQueue( + News::ItemType::campaign, kMarketingCampaignNames[campaign.type][2], 0, ft); } } diff --git a/src/openrct2/management/NewsItem.cpp b/src/openrct2/management/NewsItem.cpp index e4e4b3e2ef..6e0d3c2ce7 100644 --- a/src/openrct2/management/NewsItem.cpp +++ b/src/openrct2/management/NewsItem.cpp @@ -32,78 +32,20 @@ using namespace OpenRCT2; -News::Item& News::ItemQueues::current() -{ - return _recent.front(); -} - -const News::Item& News::ItemQueues::current() const -{ - return _recent.front(); -} - -bool News::IsValidIndex(int32_t index) -{ - if (index >= kMaxItems) - { - LOG_ERROR("Tried to get news item past MAX_NEWS."); - return false; - } - return true; -} - -News::Item* News::GetItem(ItemQueues& queues, int32_t index) -{ - return queues.at(index); -} - -News::Item& News::ItemQueues::operator[](size_t index) -{ - return const_cast(const_cast(*this)[index]); -} - -const News::Item& News::ItemQueues::operator[](size_t index) const -{ - if (index < _recent.capacity()) - return _recent[index]; - - return _archived[index - _recent.capacity()]; -} - -News::Item* News::ItemQueues::at(int32_t index) -{ - return const_cast(const_cast(*this).at(index)); -} - -const News::Item* News::ItemQueues::at(int32_t index) const -{ - if (IsValidIndex(index)) - { - return &(*this)[index]; - } - - return nullptr; -} - -bool News::ItemQueues::isEmpty() const -{ - return _recent.empty(); -} - /** * * rct2: 0x0066DF32 */ -void News::ItemQueues::clear() +void News::Items::clear() { - _recent.clear(); - _archived.clear(); + queue.clear(); + archive.clear(); } void News::InitQueue(Park::ParkData& park) { park.newsItems.clear(); - assert(park.newsItems.isEmpty()); + assert(park.newsItems.archive.empty() && park.newsItems.queue.empty()); // Throttles for warning types (PEEP_*_WARNING) for (auto& warningThrottle : park.peepWarningThrottle) @@ -115,14 +57,9 @@ void News::InitQueue(Park::ParkData& park) ContextBroadcastIntent(&intent); } -uint16_t News::ItemQueues::incrementTicks() +void News::Items::tickActiveItem() { - return ++current().ticks; -} - -static void TickCurrent(News::ItemQueues& queues) -{ - int32_t ticks = queues.incrementTicks(); + int32_t ticks = ++queue.front().ticks; // Only play news item sound when in normal playing mode if (ticks == 1 && (gLegacyScene == LegacyScene::playing)) { @@ -131,66 +68,57 @@ static void TickCurrent(News::ItemQueues& queues) } } -int32_t News::ItemQueues::removeTime() const +int32_t News::Items::removeTime() const { - if (!_recent[5].isEmpty() && !_recent[4].isEmpty() && !_recent[3].isEmpty() && !_recent[2].isEmpty()) + if (!queue[5].isEmpty() && !queue[4].isEmpty() && !queue[3].isEmpty() && !queue[2].isEmpty()) { return 256; } return 320; } -bool News::ItemQueues::currentShouldBeArchived() const +bool News::Items::activeItemShouldBeArchived() const { - return current().ticks >= removeTime(); + return queue.front().ticks >= removeTime(); } /** * * rct2: 0x0066E252 */ -void News::UpdateCurrentItem(ItemQueues& queues) +void News::Items::updateActiveItem() { PROFILED_FUNCTION(); // Check if there is a current news item - if (queues.isEmpty()) + if (queue.empty()) return; auto intent = Intent(INTENT_ACTION_UPDATE_NEWS_TICKER); ContextBroadcastIntent(&intent); // Update the current news item - TickCurrent(queues); + tickActiveItem(); // Removal of current news item - if (queues.currentShouldBeArchived()) - queues.archiveCurrent(); + if (activeItemShouldBeArchived()) + archiveActiveItem(); } -/** - * - * rct2: 0x0066E377 - */ -void News::CloseCurrentItem(ItemQueues& queues) -{ - queues.archiveCurrent(); -} - -void News::ItemQueues::archiveCurrent() +void News::Items::archiveActiveItem() { // Check if there is a current message - if (isEmpty()) + if (queue.empty()) return; - _archived.push_back(current()); + archive.push_back(queue.front()); // Invalidate the news window auto* windowMgr = Ui::GetWindowManager(); windowMgr->InvalidateByClass(WindowClass::recentNews); // Dequeue the current news item, shift news up - _recent.pop_front(); + queue.pop_front(); // Invalidate current news item bar auto intent = Intent(INTENT_ACTION_UPDATE_NEWS_TICKER); @@ -285,47 +213,50 @@ std::optional News::GetSubjectLocation(ItemType type, int32_t subject return subjectLoc; } -News::Item* News::ItemQueues::firstOpenOrNewSlot() +News::Item* News::Items::firstOpenOrNewSlot() { - for (auto emptySlots = _recent.capacity() - _recent.size(); emptySlots < 2; ++emptySlots) + for (auto emptySlots = queue.capacity() - queue.size(); emptySlots < 2; ++emptySlots) { - archiveCurrent(); + archiveActiveItem(); } - auto res = _recent.end(); + auto res = queue.end(); // The for loop above guarantees there is always an extra element to use - assert(_recent.capacity() - _recent.size() >= 2); + assert(queue.capacity() - queue.size() >= 2); auto newsItem = res + 1; newsItem->type = ItemType::null; return &*res; } +const News::Item* News::Items::getActiveMessage() const +{ + return queue.at(0); +} + /** * * rct2: 0x0066DF55 */ -News::Item* News::AddItemToQueue( - ItemQueues& queues, ItemType type, StringId string_id, uint32_t assoc, const Formatter& formatter) +News::Item* News::Items::addItemToQueue(ItemType type, StringId string_id, uint32_t assoc, const Formatter& formatter) { utf8 buffer[256]; // overflows possible? FormatStringLegacy(buffer, 256, string_id, formatter.Data()); - return AddItemToQueue(queues, type, buffer, assoc); + return addItemToQueue(type, buffer, assoc); } // TODO: Use variant for assoc, requires strong type for each possible input. -News::Item* News::AddItemToQueue( - ItemQueues& queues, ItemType type, StringId string_id, EntityId assoc, const Formatter& formatter) +News::Item* News::Items::addItemToQueue(ItemType type, StringId string_id, EntityId assoc, const Formatter& formatter) { - return AddItemToQueue(queues, type, string_id, assoc.ToUnderlying(), formatter); + return addItemToQueue(type, string_id, assoc.ToUnderlying(), formatter); } -News::Item* News::AddItemToQueue(ItemQueues& queues, ItemType type, const utf8* text, uint32_t assoc) +News::Item* News::Items::addItemToQueue(ItemType type, const utf8* text, uint32_t assoc) { auto& date = GetDate(); - Item* newsItem = queues.firstOpenOrNewSlot(); + Item* newsItem = firstOpenOrNewSlot(); newsItem->type = type; newsItem->flags = 0; newsItem->assoc = assoc; // Make optional for Award, Money, Graph and Null @@ -433,64 +364,29 @@ void News::OpenSubject(ItemType type, int32_t subject) * * rct2: 0x0066E407 */ -void News::DisableNewsItems(ItemQueues& queues, ItemType type, uint32_t assoc) +void News::DisableNewsItems(Items& newsItems, ItemType type, uint32_t assoc) { // TODO: write test invalidating windows - queues.foreachRecentNews([type, assoc, &queues](auto& newsItem) { + for (auto& newsItem : newsItems.queue) + { if (type == newsItem.type && assoc == newsItem.assoc) { newsItem.setFlags(ItemFlags::hasButton); - if (&newsItem == &queues.current()) + if (&newsItem == &newsItems.queue.front()) { auto intent = Intent(INTENT_ACTION_UPDATE_NEWS_TICKER); ContextBroadcastIntent(&intent); } } - }); + } - queues.foreachArchivedNews([type, assoc](auto& newsItem) { + for (auto& newsItem : newsItems.archive) + { if (type == newsItem.type && assoc == newsItem.assoc) { newsItem.setFlags(ItemFlags::hasButton); auto* windowMgr = Ui::GetWindowManager(); windowMgr->InvalidateByClass(WindowClass::recentNews); } - }); -} - -void News::AddItemToQueue(ItemQueues& queues, Item* newNewsItem) -{ - Item* newsItem = queues.firstOpenOrNewSlot(); - *newsItem = *newNewsItem; -} - -void News::RemoveItem(ItemQueues& queues, int32_t index) -{ - if (index < 0 || index >= kMaxItems) - return; - - // News item is already null, no need to remove it - if (queues[index].type == ItemType::null) - return; - - size_t newsBoundary = index < kItemHistoryStart ? kItemHistoryStart : kMaxItems; - for (size_t i = index; i < newsBoundary - 1; i++) - { - queues[i] = queues[i + 1]; - } - queues[newsBoundary - 1].type = ItemType::null; -} - -void News::importNewsItems(ItemQueues& queues, const std::span recent, const std::span archived) -{ - queues.clear(); - - for (size_t i = 0; i < std::min(recent.size(), kItemHistoryStart); i++) - { - queues[i] = recent[i]; - } - for (size_t i = 0; i < std::min(archived.size(), kMaxItemsArchive); i++) - { - queues[kItemHistoryStart + i] = archived[i]; } } diff --git a/src/openrct2/management/NewsItem.h b/src/openrct2/management/NewsItem.h index baf013082c..0ce485dcea 100644 --- a/src/openrct2/management/NewsItem.h +++ b/src/openrct2/management/NewsItem.h @@ -126,12 +126,11 @@ namespace OpenRCT2::News } }; - constexpr int32_t kItemHistoryStart = 11; - constexpr int32_t kMaxItemsArchive = 50; - constexpr int32_t kMaxItems = kItemHistoryStart + kMaxItemsArchive; + constexpr int32_t kNewsQueueSize = 11; + constexpr int32_t kNewsArchiveSize = 50; template - class ItemQueue + class ItemCollection { public: static_assert(N > 0, "Cannot instantiate News::ItemQueue with size=0"); @@ -148,7 +147,7 @@ namespace OpenRCT2::News using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator; - ItemQueue() + ItemCollection() { std::get<0>(_queue).type = ItemType::null; } @@ -248,81 +247,75 @@ namespace OpenRCT2::News std::fill(_queue.begin(), _queue.end(), Item{}); } + const_pointer at(int32_t index) const + { + if (_queue[index].type == ItemType::null) + return nullptr; + + return &_queue[index]; + } + + void remove(int32_t index) + { + // News item is already null, no need to remove it + if (_queue[index].type == ItemType::null) + return; + + for (size_t i = index; i < N - 1; i++) + { + _queue[i] = _queue[i + 1]; + } + _queue[N - 1].type = ItemType::null; + } + + void importQueue(const std::span src) + { + clear(); + + for (size_t i = 0; i < std::min(src.size(), N); i++) + { + _queue[i] = src[i]; + } + } + private: std::array _queue; }; - struct ItemQueues + using NewsArchive = ItemCollection; + using NewsQueue = ItemCollection; + + struct Items { - Item& operator[](size_t index); - const Item& operator[](size_t index) const; - Item* at(int32_t index); - const Item* at(int32_t index) const; - bool isEmpty() const; + NewsQueue queue; + NewsArchive archive; + void clear(); - uint16_t incrementTicks(); - Item& current(); - const Item& current() const; - bool currentShouldBeArchived() const; - void archiveCurrent(); - Item* firstOpenOrNewSlot(); - const auto& getRecent() const - { - return _recent; - } - const auto& getArchived() const - { - return _archived; - } - template - void foreachRecentNews(Predicate&& p) - { - for (auto& newsItem : _recent) - { - p(newsItem); - } - } + void updateActiveItem(); + void archiveActiveItem(); - template - void foreachArchivedNews(Predicate&& p) - { - for (auto& newsItem : _archived) - { - p(newsItem); - } - } + const Item* getActiveMessage() const; + + Item* addItemToQueue(ItemType type, StringId string_id, uint32_t assoc, const Formatter& formatter); + Item* addItemToQueue(ItemType type, StringId string_id, EntityId assoc, const Formatter& formatter); + Item* addItemToQueue(ItemType type, const utf8* text, uint32_t assoc); private: + Item* firstOpenOrNewSlot(); int32_t removeTime() const; - ItemQueue _recent; - ItemQueue _archived; + bool activeItemShouldBeArchived() const; + void tickActiveItem(); }; void InitQueue(Park::ParkData& park); - void UpdateCurrentItem(ItemQueues& queues); - void CloseCurrentItem(ItemQueues& queues); - std::optional GetSubjectLocation(ItemType type, int32_t subject); - Item* AddItemToQueue(ItemQueues& queues, ItemType type, StringId string_id, uint32_t assoc, const Formatter& formatter); - Item* AddItemToQueue(ItemQueues& queues, ItemType type, StringId string_id, EntityId assoc, const Formatter& formatter); - Item* AddItemToQueue(ItemQueues& queues, ItemType type, const utf8* text, uint32_t assoc); - bool CheckIfItemRequiresAssoc(ItemType type); void OpenSubject(ItemType type, int32_t subject); - void DisableNewsItems(ItemQueues& queues, ItemType type, uint32_t assoc); - - Item* GetItem(ItemQueues& queues, int32_t index); - - bool IsValidIndex(int32_t index); - - void AddItemToQueue(ItemQueues& queues, Item* newNewsItem); - void RemoveItem(ItemQueues& queues, int32_t index); - - void importNewsItems(ItemQueues& queues, std::span recent, std::span archived); + void DisableNewsItems(Items& newsItems, ItemType type, uint32_t assoc); } // namespace OpenRCT2::News diff --git a/src/openrct2/management/Research.cpp b/src/openrct2/management/Research.cpp index cca9e34fad..5765dd003d 100644 --- a/src/openrct2/management/Research.cpp +++ b/src/openrct2/management/Research.cpp @@ -266,8 +266,8 @@ void ResearchFinishItem(const ResearchItem& researchItem) { if (Config::Get().notifications.rideResearched) { - News::AddItemToQueue( - gameState.park.newsItems, News::ItemType::research, availabilityString, researchItem.rawValue, ft); + gameState.park.newsItems.addItemToQueue( + News::ItemType::research, availabilityString, researchItem.rawValue, ft); } } @@ -290,9 +290,8 @@ void ResearchFinishItem(const ResearchItem& researchItem) { if (Config::Get().notifications.rideResearched) { - News::AddItemToQueue( - gameState.park.newsItems, News::ItemType::research, STR_NEWS_ITEM_RESEARCH_NEW_SCENERY_SET_AVAILABLE, - researchItem.rawValue, ft); + gameState.park.newsItems.addItemToQueue( + News::ItemType::research, STR_NEWS_ITEM_RESEARCH_NEW_SCENERY_SET_AVAILABLE, researchItem.rawValue, ft); } } diff --git a/src/openrct2/park/ParkFile.cpp b/src/openrct2/park/ParkFile.cpp index 9add45539b..ce2884f358 100644 --- a/src/openrct2/park/ParkFile.cpp +++ b/src/openrct2/park/ParkFile.cpp @@ -1212,25 +1212,25 @@ namespace OpenRCT2 cs.readWrite(item.category); } - void ReadWriteNotificationsChunk(News::ItemQueues& queues, OrcaStream& os) + void ReadWriteNotificationsChunk(News::Items& queues, OrcaStream& os) { os.readWriteChunk(ParkFileChunkType::notifications, [&queues](OrcaStream::ChunkStream& cs) { if (cs.getMode() == OrcaStream::Mode::reading) { std::vector recent; cs.readWriteVector(recent, [&cs](News::Item& item) { ReadWriteNewsItem(cs, item); }); + queues.queue.importQueue(recent); std::vector archived; cs.readWriteVector(archived, [&cs](News::Item& item) { ReadWriteNewsItem(cs, item); }); - - News::importNewsItems(queues, recent, archived); + queues.archive.importQueue(archived); } else { - std::vector recent(std::begin(queues.getRecent()), std::end(queues.getRecent())); + std::vector recent(std::begin(queues.queue), std::end(queues.queue)); cs.readWriteVector(recent, [&cs](News::Item& item) { ReadWriteNewsItem(cs, item); }); - std::vector archived(std::begin(queues.getArchived()), std::end(queues.getArchived())); + std::vector archived(std::begin(queues.archive), std::end(queues.archive)); cs.readWriteVector(archived, [&cs](News::Item& item) { ReadWriteNewsItem(cs, item); }); } }); diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 6d444e59df..73196d518b 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -2291,8 +2291,9 @@ namespace OpenRCT2::RCT1 // News items auto recentMessages = convertNewsQueue(_s4.recentMessages); + park.newsItems.queue.importQueue(recentMessages); auto archivedMessages = convertNewsQueue(_s4.archivedMessages); - News::importNewsItems(park.newsItems, recentMessages, archivedMessages); + park.newsItems.archive.importQueue(archivedMessages); // Initial guest status gameState.scenarioOptions.guestInitialCash = ToMoney64(_s4.GuestInitialCash); diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index d430462462..baf6ab0142 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -594,8 +594,9 @@ namespace OpenRCT2::RCT2 // News items auto recentMessages = convertNewsQueue(_s6.recentMessages); + park.newsItems.queue.importQueue(recentMessages); auto archivedMessages = convertNewsQueue(_s6.archivedMessages); - News::importNewsItems(park.newsItems, recentMessages, archivedMessages); + park.newsItems.archive.importQueue(archivedMessages); // Pad13CE730 // rct1_scenario_flags diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 100c980c36..db64140fda 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -1345,8 +1345,9 @@ namespace OpenRCT2 { Formatter ft; ride.formatNameTo(ft); - News::AddItemToQueue( - getGameState().park.newsItems, News::ItemType::ride, STR_RIDE_IS_BROKEN_DOWN, ride.id.ToUnderlying(), ft); + + getGameState().park.newsItems.addItemToQueue( + News::ItemType::ride, STR_RIDE_IS_BROKEN_DOWN, ride.id.ToUnderlying(), ft); } } @@ -1373,9 +1374,8 @@ namespace OpenRCT2 { Formatter ft; ride.formatNameTo(ft); - News::AddItemToQueue( - getGameState().park.newsItems, News::ItemType::ride, STR_RIDE_IS_STILL_NOT_FIXED, - ride.id.ToUnderlying(), ft); + getGameState().park.newsItems.addItemToQueue( + News::ItemType::ride, STR_RIDE_IS_STILL_NOT_FIXED, ride.id.ToUnderlying(), ft); } } } @@ -2065,9 +2065,8 @@ namespace OpenRCT2 ride.formatNameTo(ft); if (Config::Get().notifications.rideWarnings) { - News::AddItemToQueue( - getGameState().park.newsItems, News::ItemType::ride, STR_ENTRANCE_NOT_CONNECTED, ride.id.ToUnderlying(), - ft); + getGameState().park.newsItems.addItemToQueue( + News::ItemType::ride, STR_ENTRANCE_NOT_CONNECTED, ride.id.ToUnderlying(), ft); } ride.connectedMessageThrottle = 3; } @@ -2079,9 +2078,8 @@ namespace OpenRCT2 ride.formatNameTo(ft); if (Config::Get().notifications.rideWarnings) { - News::AddItemToQueue( - getGameState().park.newsItems, News::ItemType::ride, STR_EXIT_NOT_CONNECTED, ride.id.ToUnderlying(), - ft); + getGameState().park.newsItems.addItemToQueue( + News::ItemType::ride, STR_EXIT_NOT_CONNECTED, ride.id.ToUnderlying(), ft); } ride.connectedMessageThrottle = 3; } @@ -2148,8 +2146,9 @@ namespace OpenRCT2 { Formatter ft; ride2->formatNameTo(ft); - News::AddItemToQueue( - getGameState().park.newsItems, News::ItemType::ride, STR_ENTRANCE_NOT_CONNECTED, ride2->id.ToUnderlying(), ft); + + getGameState().park.newsItems.addItemToQueue( + News::ItemType::ride, STR_ENTRANCE_NOT_CONNECTED, ride2->id.ToUnderlying(), ft); } ride2->connectedMessageThrottle = 3; @@ -5047,8 +5046,8 @@ namespace OpenRCT2 { Formatter ft; formatNameTo(ft); - News::AddItemToQueue( - getGameState().park.newsItems, News::ItemType::ride, STR_RIDE_HAS_CRASHED, id.ToUnderlying(), ft); + + getGameState().park.newsItems.addItemToQueue(News::ItemType::ride, STR_RIDE_HAS_CRASHED, id.ToUnderlying(), ft); } } diff --git a/src/openrct2/ride/Vehicle.Crash.cpp b/src/openrct2/ride/Vehicle.Crash.cpp index 6c2a6112f0..d80714ca4a 100644 --- a/src/openrct2/ride/Vehicle.Crash.cpp +++ b/src/openrct2/ride/Vehicle.Crash.cpp @@ -296,9 +296,10 @@ static void ride_train_crash(Ride& ride, uint16_t numFatalities) if (Config::Get().notifications.rideCasualties) { ride.formatNameTo(ft); - News::AddItemToQueue( - getGameState().park.newsItems, News::ItemType::ride, - numFatalities == 1 ? STR_X_PERSON_DIED_ON_X : STR_X_PEOPLE_DIED_ON_X, ride.id.ToUnderlying(), ft); + + getGameState().park.newsItems.addItemToQueue( + News::ItemType::ride, numFatalities == 1 ? STR_X_PERSON_DIED_ON_X : STR_X_PEOPLE_DIED_ON_X, + ride.id.ToUnderlying(), ft); } // TODO: get park id from ride/vehicle diff --git a/src/openrct2/ride/Vehicle.Station.cpp b/src/openrct2/ride/Vehicle.Station.cpp index 09a8a51a3d..a8cbca423a 100644 --- a/src/openrct2/ride/Vehicle.Station.cpp +++ b/src/openrct2/ride/Vehicle.Station.cpp @@ -1329,8 +1329,8 @@ void Vehicle::CheckIfMissing() curRide->formatNameTo(ft); ft.Add(GetRideComponentName(GetRideTypeDescriptor(curRide->type).NameConvention.station).singular); - News::AddItemToQueue( - getGameState().park.newsItems, News::ItemType::ride, STR_NEWS_VEHICLE_HAS_STALLED, ride.ToUnderlying(), ft); + getGameState().park.newsItems.addItemToQueue( + News::ItemType::ride, STR_NEWS_VEHICLE_HAS_STALLED, ride.ToUnderlying(), ft); } } diff --git a/src/openrct2/scenario/Scenario.cpp b/src/openrct2/scenario/Scenario.cpp index d79e6074dd..f92229b447 100644 --- a/src/openrct2/scenario/Scenario.cpp +++ b/src/openrct2/scenario/Scenario.cpp @@ -217,7 +217,7 @@ static void ScenarioCheckEntranceFeeTooHigh() uint32_t packed_xy = (y << 16) | x; if (Config::Get().notifications.parkWarnings) { - News::AddItemToQueue(park.newsItems, News::ItemType::blank, STR_ENTRANCE_FEE_TOO_HI, packed_xy, {}); + park.newsItems.addItemToQueue(News::ItemType::blank, STR_ENTRANCE_FEE_TOO_HI, packed_xy, {}); } } } @@ -272,20 +272,20 @@ static void scenarioUpdateLowRatingDayCount(Park::ParkData& park, GameState_t& g switch (park.scenarioParkRatingWarningDays) { case 1: - News::AddItemToQueue( - park.newsItems, News::ItemType::graph, STR_PARK_RATING_WARNING_4_WEEKS_REMAINING, 0, {}); + + park.newsItems.addItemToQueue(News::ItemType::graph, STR_PARK_RATING_WARNING_4_WEEKS_REMAINING, 0, {}); break; case 8: - News::AddItemToQueue( - park.newsItems, News::ItemType::graph, STR_PARK_RATING_WARNING_3_WEEKS_REMAINING, 0, {}); + + park.newsItems.addItemToQueue(News::ItemType::graph, STR_PARK_RATING_WARNING_3_WEEKS_REMAINING, 0, {}); break; case 15: - News::AddItemToQueue( - park.newsItems, News::ItemType::graph, STR_PARK_RATING_WARNING_2_WEEKS_REMAINING, 0, {}); + + park.newsItems.addItemToQueue(News::ItemType::graph, STR_PARK_RATING_WARNING_2_WEEKS_REMAINING, 0, {}); break; case 22: - News::AddItemToQueue( - park.newsItems, News::ItemType::graph, STR_PARK_RATING_WARNING_1_WEEK_REMAINING, 0, {}); + + park.newsItems.addItemToQueue(News::ItemType::graph, STR_PARK_RATING_WARNING_1_WEEK_REMAINING, 0, {}); break; } } diff --git a/src/openrct2/scenario/ScenarioObjective.cpp b/src/openrct2/scenario/ScenarioObjective.cpp index 8d14859237..4c76d05058 100644 --- a/src/openrct2/scenario/ScenarioObjective.cpp +++ b/src/openrct2/scenario/ScenarioObjective.cpp @@ -257,7 +257,7 @@ namespace OpenRCT2::Scenario { case ObjectiveType::guestsAndRating: { - News::AddItemToQueue(park.newsItems, News::ItemType::graph, STR_PARK_HAS_BEEN_CLOSED_DOWN, 0, {}); + park.newsItems.addItemToQueue(News::ItemType::graph, STR_PARK_HAS_BEEN_CLOSED_DOWN, 0, {}); park.flags.unset(ParkFlag::parkOpen); gameState.scenarioOptions.guestInitialHappiness = 50; break; diff --git a/src/openrct2/scripting/bindings/world/ScPark.cpp b/src/openrct2/scripting/bindings/world/ScPark.cpp index 7240288e67..97d9f6b481 100644 --- a/src/openrct2/scripting/bindings/world/ScPark.cpp +++ b/src/openrct2/scripting/bindings/world/ScPark.cpp @@ -357,13 +357,13 @@ namespace OpenRCT2::Scripting JSValue result = JS_NewArray(ctx); int64_t resultIdx = 0; auto& newsItems = getGameState().park.newsItems; - for (size_t i = 0, newsSize = newsItems.getRecent().size(); i < newsSize; i++) + for (size_t i = 0, newsSize = newsItems.queue.size(); i < newsSize; i++) { JS_SetPropertyInt64(ctx, result, resultIdx++, gScParkMessage.New(ctx, i)); } - for (size_t i = 0, newsSize = newsItems.getArchived().size(); i < newsSize; i++) + for (size_t i = 0, newsSize = newsItems.archive.size(); i < newsSize; i++) { - auto offset = i + News::kItemHistoryStart; + auto offset = i + News::kNewsQueueSize; JS_SetPropertyInt64(ctx, result, resultIdx++, gScParkMessage.New(ctx, offset)); } return result; @@ -371,38 +371,38 @@ namespace OpenRCT2::Scripting JSValue ScPark::messages_set(JSContext* ctx, JSValue thisVal, JSValue value) { - int32_t index = 0; - int32_t archiveIndex = News::kItemHistoryStart; + size_t queueIndex = 0; + size_t archiveIndex = 0; auto& newsItems = getGameState().park.newsItems; - JSIterateArray(ctx, value, [&index, &archiveIndex, &newsItems](JSContext* ctx2, JSValue item) { + JSIterateArray(ctx, value, [&queueIndex, &archiveIndex, &newsItems](JSContext* ctx2, JSValue item) { auto isArchived = AsOrDefault(ctx2, item, "isArchived", false); auto newsItem = NewsItemFromJS(ctx2, item); if (isArchived) { - if (archiveIndex < News::kMaxItems) + if (archiveIndex < newsItems.archive.capacity()) { - newsItems[archiveIndex] = newsItem; + newsItems.archive[archiveIndex] = newsItem; archiveIndex++; } } else { - if (index < News::kItemHistoryStart) + if (queueIndex < newsItems.queue.capacity()) { - newsItems[index] = newsItem; - index++; + newsItems.queue[queueIndex] = newsItem; + queueIndex++; } } }); // End the lists by setting next item to null - if (index < News::kItemHistoryStart) + if (queueIndex < newsItems.queue.capacity()) { - newsItems[index].type = News::ItemType::null; + newsItems.queue[queueIndex].type = News::ItemType::null; } - if (archiveIndex < News::kMaxItems) + if (archiveIndex < newsItems.archive.capacity()) { - newsItems[archiveIndex].type = News::ItemType::null; + newsItems.archive[archiveIndex].type = News::ItemType::null; } return JS_UNDEFINED; } @@ -440,7 +440,7 @@ namespace OpenRCT2::Scripting assoc = JSToUint(ctx, subject); } } - News::AddItemToQueue(getGameState().park.newsItems, type, text.c_str(), assoc); + getGameState().park.newsItems.addItemToQueue(type, text.c_str(), assoc); return JS_UNDEFINED; } diff --git a/src/openrct2/scripting/bindings/world/ScParkMessage.cpp b/src/openrct2/scripting/bindings/world/ScParkMessage.cpp index 91efa39ece..6d3d30e5b9 100644 --- a/src/openrct2/scripting/bindings/world/ScParkMessage.cpp +++ b/src/openrct2/scripting/bindings/world/ScParkMessage.cpp @@ -23,13 +23,17 @@ namespace OpenRCT2::Scripting News::Item* ScParkMessage::GetMessage(JSValue thisVal) { auto index = gScParkMessage.GetOpaque(thisVal)->index; - return &getGameState().park.newsItems[index]; + + if (index < News::kNewsQueueSize) + return &getGameState().park.newsItems.queue[index]; + + return &getGameState().park.newsItems.archive[index - News::kNewsQueueSize]; } JSValue ScParkMessage::isArchived_get(JSContext* ctx, JSValue thisVal) { auto index = gScParkMessage.GetOpaque(thisVal)->index; - return JS_NewBool(ctx, index >= News::kItemHistoryStart); + return JS_NewBool(ctx, index >= News::kNewsQueueSize); } JSValue ScParkMessage::month_get(JSContext* ctx, JSValue thisVal) @@ -173,7 +177,12 @@ namespace OpenRCT2::Scripting JSValue ScParkMessage::remove(JSContext* ctx, JSValue thisVal, int argc, JSValue* argv) { auto index = gScParkMessage.GetOpaque(thisVal)->index; - News::RemoveItem(getGameState().park.newsItems, static_cast(index)); + + if (index < News::kNewsQueueSize) + getGameState().park.newsItems.queue.remove(static_cast(index)); + else + getGameState().park.newsItems.archive.remove(static_cast(index - News::kNewsQueueSize)); + return JS_UNDEFINED; } diff --git a/src/openrct2/world/ParkData.h b/src/openrct2/world/ParkData.h index f26e0238dc..ff148a219b 100644 --- a/src/openrct2/world/ParkData.h +++ b/src/openrct2/world/ParkData.h @@ -132,6 +132,6 @@ namespace OpenRCT2::Park std::vector currentAwards; std::vector marketingCampaigns; - News::ItemQueues newsItems; + News::Items newsItems; }; } // namespace OpenRCT2::Park From b2357d46955a3434d889d91bb8b4673da9139007 Mon Sep 17 00:00:00 2001 From: WisdomK-ROK Date: Mon, 26 Oct 2026 05:36:15 +0900 Subject: [PATCH 27/33] Remove unused parameter (#27307) --- src/openrct2-win/openrct2-win.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2-win/openrct2-win.cpp b/src/openrct2-win/openrct2-win.cpp index e26f09726c..114fe3cf02 100644 --- a/src/openrct2-win/openrct2-win.cpp +++ b/src/openrct2-win/openrct2-win.cpp @@ -32,7 +32,7 @@ static std::vector GetCommandLineArgs(int argc, wchar_t** argvW); /** * Windows entry point to OpenRCT2 with a console window using a traditional C main function. */ -int wmain(int argc, wchar_t** argvW, [[maybe_unused]] wchar_t* envp) +int wmain(int argc, wchar_t** argvW) { auto argvStrings = GetCommandLineArgs(argc, argvW); From 9521e6cdf91228f95c0770245d0b2aaaf961be48 Mon Sep 17 00:00:00 2001 From: itu-itis24-iyigun24 Date: Mon, 26 Oct 2026 03:00:41 +0300 Subject: [PATCH 28/33] Fix use-after-free when unregistering script classes twice (#27143) ScBase::Unregister() freed the class prototype but kept proto and protoCtx. The script classes are globals and the JS runtime is freed when a context is destroyed, so these values become dangling pointers. The script classes are registered only by ScriptEngine::Initialise(), but ~ScriptEngine() always unregisters them. Destroying a context whose script engine was never initialised, after an initialised one had been destroyed, therefore freed the stale prototype again through the freed JSContext. On Windows this crashed WaterObjectTest when it ran after TileElementsViewTests in the same test process. Reset proto and protoCtx after freeing them, and add a test that destroys an uninitialised context after an initialised one. Co-authored-by: Claude Opus 5 (1M context) --- src/openrct2/scripting/ScriptEngine.h | 2 ++ test/tests/ScriptingTests.cpp | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/openrct2/scripting/ScriptEngine.h b/src/openrct2/scripting/ScriptEngine.h index 8f1c2b6818..cc52747324 100644 --- a/src/openrct2/scripting/ScriptEngine.h +++ b/src/openrct2/scripting/ScriptEngine.h @@ -333,6 +333,8 @@ namespace OpenRCT2::Scripting classId = JS_INVALID_CLASS_ID; if (protoCtx != nullptr) JS_FreeValue(protoCtx, proto); + proto = JS_NULL; + protoCtx = nullptr; } [[nodiscard]] JSValue GetProto() const diff --git a/test/tests/ScriptingTests.cpp b/test/tests/ScriptingTests.cpp index 712a7914fb..f5b0b2527d 100644 --- a/test/tests/ScriptingTests.cpp +++ b/test/tests/ScriptingTests.cpp @@ -73,4 +73,21 @@ TEST_F(ScriptingTests, MultipleSubscribersToSameEventShouldNotCrash) hookEngine.Call(HookType::intervalTick, arg, false); } +TEST(ScriptEngineLifetimeTests, UninitialisedContextCanBeDestroyedAfterInitialisedOne) +{ + gOpenRCT2Headless = true; + gOpenRCT2NoGraphics = true; + + // Registers the global script classes and then frees the JS runtime they belong to. + { + auto context = CreateContext(); + context->GetScriptEngine().Initialise(); + } + + // Unregisters the global script classes again without registering them first. + { + auto context = CreateContext(); + } +} + #endif From 52a55c3e8da5972460642bdfed61d091fe9cabfd Mon Sep 17 00:00:00 2001 From: mrmbernardi Date: Mon, 26 Oct 2026 11:01:23 +1100 Subject: [PATCH 29/33] Remove unused variables (#27322) --- src/openrct2/drawing/TTF.cpp | 22 +++++++++++----------- src/openrct2/entity/Peep.cpp | 3 --- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/openrct2/drawing/TTF.cpp b/src/openrct2/drawing/TTF.cpp index 0b4eea1803..b39707cabb 100644 --- a/src/openrct2/drawing/TTF.cpp +++ b/src/openrct2/drawing/TTF.cpp @@ -53,13 +53,13 @@ struct ttf_getwidth_cache_entry static ttf_cache_entry _ttfSurfaceCache[kTTFSurfaceCacheSize] = {}; static int32_t _ttfSurfaceCacheCount = 0; -static int32_t _ttfSurfaceCacheHitCount = 0; -static int32_t _ttfSurfaceCacheMissCount = 0; +// static int32_t _ttfSurfaceCacheHitCount = 0; +// static int32_t _ttfSurfaceCacheMissCount = 0; static ttf_getwidth_cache_entry _ttfGetWidthCache[kTTFGetWidthCacheSize] = {}; -static int32_t _ttfGetWidthCacheCount = 0; -static int32_t _ttfGetWidthCacheHitCount = 0; -static int32_t _ttfGetWidthCacheMissCount = 0; +// static int32_t _ttfGetWidthCacheCount = 0; +// static int32_t _ttfGetWidthCacheHitCount = 0; +// static int32_t _ttfGetWidthCacheMissCount = 0; static std::mutex _mutex; @@ -220,7 +220,7 @@ TTFSurface* TTFSurfaceCacheGetOrAdd(TTF_Font* font, std::string_view text) break; if (entry->font == font && String::equals(entry->text, text)) { - _ttfSurfaceCacheHitCount++; + // _ttfSurfaceCacheHitCount++; entry->lastUseTick = gCurrentDrawCount; return entry->surface; } @@ -246,7 +246,7 @@ TTFSurface* TTFSurfaceCacheGetOrAdd(TTF_Font* font, std::string_view text) return nullptr; } - _ttfSurfaceCacheMissCount++; + // _ttfSurfaceCacheMissCount++; // printf("CACHE HITS: %d MISSES: %d)\n", _ttfSurfaceCacheHitCount, _ttfSurfaceCacheMissCount); _ttfSurfaceCacheCount++; @@ -272,7 +272,7 @@ static void TTFGetWidthCacheDisposeAll() for (int32_t i = 0; i < kTTFGetWidthCacheSize; i++) { TTFGetWidthCacheDispose(&_ttfGetWidthCache[i]); - _ttfGetWidthCacheCount--; + // _ttfGetWidthCacheCount--; } } @@ -294,7 +294,7 @@ uint32_t TTFGetWidthCacheGetOrAdd(TTF_Font* font, std::string_view text) break; if (entry->font == font && String::equals(entry->text, text)) { - _ttfGetWidthCacheHitCount++; + // _ttfGetWidthCacheHitCount++; entry->lastUseTick = gCurrentDrawCount; return entry->width; } @@ -317,9 +317,9 @@ uint32_t TTFGetWidthCacheGetOrAdd(TTF_Font* font, std::string_view text) int32_t width, height; TTFGetSize(font, text, &width, &height); - _ttfGetWidthCacheMissCount++; + // _ttfGetWidthCacheMissCount++; - _ttfGetWidthCacheCount++; + // _ttfGetWidthCacheCount++; entry->width = width; entry->font = font; entry->text = text; diff --git a/src/openrct2/entity/Peep.cpp b/src/openrct2/entity/Peep.cpp index 27fabfcca0..2b020eadcd 100644 --- a/src/openrct2/entity/Peep.cpp +++ b/src/openrct2/entity/Peep.cpp @@ -71,7 +71,6 @@ namespace OpenRCT2 using namespace OpenRCT2::Drawing; static uint8_t _backupAnimationImageIdOffset; - static TileElement* _peepRideEntranceExitElement; static std::shared_ptr _crowdSoundChannel = nullptr; @@ -1563,12 +1562,10 @@ namespace OpenRCT2 if (entranceType == EntranceType::rideExit) { pathing_result |= PATHING_RIDE_EXIT; - _peepRideEntranceExitElement = tile_element; } else if (entranceType == EntranceType::rideEntrance) { pathing_result |= PATHING_RIDE_ENTRANCE; - _peepRideEntranceExitElement = tile_element; } if (entranceType == EntranceType::rideExit) From aca477060424cc9f2e3d925fa3b13f84f4fbf3f7 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek <1478678+Gymnasiast@users.noreply.github.com> Date: Mon, 26 Oct 2026 23:29:04 +0100 Subject: [PATCH 30/33] Fix #18954: Bumbly Beach unlocks Classic Mini Roller Coaster Twice through research (#27313) --- distribution/changelog.txt | 1 + src/openrct2/management/Research.cpp | 12 ++---------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index c27f103430..7ed3fd0e5d 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -1,6 +1,7 @@ 0.5.7 (in development) ------------------------------------------------------------------------ - Fix: [#16807] Error messages when trying to load regular JSON files as custom objects. +- Fix: [#18954] When researching Classic Mini Roller Coaster vehicles in Bumbly Beach, they all appear as new rides. - Fix: [#21030, #26981] Slow object loading and index building when using RCT Classic or running from a Flatpak. - Fix: [#24524] Some build types (like AppImage) lack information about their specific build. - Fix: [#27264] Headless server crashes when loading a recolourable terrain surface. diff --git a/src/openrct2/management/Research.cpp b/src/openrct2/management/Research.cpp index 5765dd003d..a73745f030 100644 --- a/src/openrct2/management/Research.cpp +++ b/src/openrct2/management/Research.cpp @@ -1099,20 +1099,12 @@ void ResearchDetermineFirstOfType() if (gameState.researchNextItem.has_value()) { ResearchUpdateFirstOfType(&gameState.researchNextItem.value()); - ResearchMarkRideTypeAsSeen(gameState.researchNextItem.value()); + // The next research item is (sometimes?) also present in gameState.researchItemsUninvented. To make things worse, + // the base ride entry or the entry index of researchNextItem may be corrupted. } for (auto& researchItem : gameState.researchItemsUninvented) { - // The next research item is (sometimes?) also present in gameState.researchItemsUninvented - if (gameState.researchNextItem.has_value() && !gameState.researchNextItem->isNull() - && researchItem.baseRideType == gameState.researchNextItem.value().baseRideType) - { - // Copy the "first of type" flag. - researchItem.flags = gameState.researchNextItem->flags; - continue; - } - ResearchUpdateFirstOfType(&researchItem); ResearchMarkRideTypeAsSeen(researchItem); } From 3b7114c8ea2373fc4da66dbd0f8c007333fa1546 Mon Sep 17 00:00:00 2001 From: OpenRCT2 git bot Date: Wed, 28 Oct 2026 04:03:50 +0000 Subject: [PATCH 31/33] Merge Localisation/master into OpenRCT2/develop --- data/language/gl-ES.txt | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/data/language/gl-ES.txt b/data/language/gl-ES.txt index 22d664e17e..3b5a638311 100644 --- a/data/language/gl-ES.txt +++ b/data/language/gl-ES.txt @@ -2679,8 +2679,8 @@ STR_5582 :Capturar cursor do rato na xanela STR_5583  :{COMMA1DP16}m/s STR_5584 :SI STR_5585 :Desbloquea os límites de operación da atracción, permitindo cousas como pendentes de elevación a {VELOCITY} -STR_5586 :Abrir tendas e postos automaticamente -STR_5587 :As tendas e os postos abriranse automaticamente despois de seren construidos. +STR_5586 :Abrir e pechar automaticamente as tendas e os postos +STR_5587 :As tendas e os postos abriranse automaticamente despois de construílos e pecharanse automaticamente antes de comezar a construción. STR_5588 :Xogar con outros xogadores STR_5589 :Configuración de notificacións STR_5590 :Premios do parque @@ -3844,3 +3844,22 @@ STR_7060 :Visitantes mirando a construción de {STRINGID} STR_7061 :Visitantes mirando a decoración STR_7062 :Visitantes saíndo do parque STR_7063 :Visitantes mirando a construción dunha nova atracción +STR_7064 :Dourado +STR_7065 :Ámbar +STR_7066 :Amatista +STR_7067 :Espárrago +STR_7068 :Marrón +STR_7069 :Rosa queimado +STR_7070 :Cacto +STR_7071 :Caramelo +STR_7072 :Cobre +STR_7073 :Carmesí +STR_7074 :Auga escura +STR_7075 :Esmeralda +STR_7076 :Indigo +STR_7077 :Pesto +STR_7078 :Verde piñeiro +STR_7079 :Rubí +STR_7080 :Azul intenso +STR_7081 :Prata + From 20fbc0936d060dd927d7127d785c8090c2104a24 Mon Sep 17 00:00:00 2001 From: WisdomK-ROK Date: Sat, 31 Oct 2026 21:51:14 +0900 Subject: [PATCH 32/33] Remove unused function (#27345) --- src/openrct2-ui/Ui.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/openrct2-ui/Ui.cpp b/src/openrct2-ui/Ui.cpp index 64e7ffa5b7..098bce8150 100644 --- a/src/openrct2-ui/Ui.cpp +++ b/src/openrct2-ui/Ui.cpp @@ -31,12 +31,6 @@ using namespace OpenRCT2; using namespace OpenRCT2::Audio; using namespace OpenRCT2::Ui; -template -static std::shared_ptr ToShared(std::unique_ptr&& src) -{ - return std::shared_ptr(std::move(src)); -} - /** * Main entry point for non-Windows systems. Windows instead uses its own DLL proxy. */ From bb63204036c6b6465818f5d1503a0c2b5c6d59ae Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sun, 1 Nov 2026 06:37:54 -0300 Subject: [PATCH 33/33] Update BACKTRACE_TOKEN in preparation for v0.5.7 --- src/openrct2/platform/Crash.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2/platform/Crash.cpp b/src/openrct2/platform/Crash.cpp index 9163ec002a..8775870b30 100644 --- a/src/openrct2/platform/Crash.cpp +++ b/src/openrct2/platform/Crash.cpp @@ -58,7 +58,7 @@ static const wchar_t* _wszArchitecture = WSZ(OPENRCT2_ARCHITECTURE); static std::map _uploadFiles; static std::mutex _uploadFilesMutex; - #define BACKTRACE_TOKEN "f509d427f8ee73ef96c59c46a0c8ef5f79d9cac9ed5f014da986e3bb15a24389" + #define BACKTRACE_TOKEN "25e2ab471a2fc23d2ab786112eaf5d316e84721badd080c7347e405812e204db" using namespace OpenRCT2;