From cb3b2a77e758a8102bf71147631035f184ef74a2 Mon Sep 17 00:00:00 2001 From: Jan Kelemen Date: Thu, 21 Mar 2024 22:50:18 +0100 Subject: [PATCH] Move gWidePathTileLoopPosition and gGrassSceneryTileLoopPosition to GameState_t --- src/openrct2/GameState.h | 3 +++ src/openrct2/park/ParkFile.cpp | 4 ++-- src/openrct2/rct2/S6Importer.cpp | 5 ++--- src/openrct2/world/Map.cpp | 30 ++++++++++++------------------ src/openrct2/world/Map.h | 3 --- 5 files changed, 19 insertions(+), 26 deletions(-) diff --git a/src/openrct2/GameState.h b/src/openrct2/GameState.h index 15f6e127b4..7bf8f1ddea 100644 --- a/src/openrct2/GameState.h +++ b/src/openrct2/GameState.h @@ -109,6 +109,9 @@ namespace OpenRCT2 News::ItemQueues NewsItems; + uint16_t GrassSceneryTileLoopPosition; + CoordsXY WidePathTileLoopPosition; + colour_t StaffHandymanColour; colour_t StaffMechanicColour; colour_t StaffSecurityColour; diff --git a/src/openrct2/park/ParkFile.cpp b/src/openrct2/park/ParkFile.cpp index 4fcb146030..fe205516e6 100644 --- a/src/openrct2/park/ParkFile.cpp +++ b/src/openrct2/park/ParkFile.cpp @@ -549,8 +549,8 @@ namespace OpenRCT2 cs.ReadWrite(gameState.LandPrice); cs.ReadWrite(gameState.ConstructionRightsPrice); } - cs.ReadWrite(gGrassSceneryTileLoopPosition); - cs.ReadWrite(gWidePathTileLoopPosition); + cs.ReadWrite(gameState.GrassSceneryTileLoopPosition); + cs.ReadWrite(gameState.WidePathTileLoopPosition); auto& rideRatings = gameState.RideRatingUpdateStates; if (os.GetHeader().TargetVersion >= 21) diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index d41c191381..6ead1df5e7 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -448,7 +448,7 @@ namespace RCT2 ImportRideRatingsCalcData(); ImportRideMeasurements(); gameState.NextGuestNumber = _s6.NextGuestIndex; - gGrassSceneryTileLoopPosition = _s6.GrassAndSceneryTilepos; + gameState.GrassSceneryTileLoopPosition = _s6.GrassAndSceneryTilepos; // unk_13CA73E // Pad13CA73F // unk_13CA740 @@ -496,8 +496,7 @@ namespace RCT2 // Pad13CE730 // rct1_scenario_flags - gWidePathTileLoopPosition.x = _s6.WidePathTileLoopX; - gWidePathTileLoopPosition.y = _s6.WidePathTileLoopY; + gameState.WidePathTileLoopPosition = { _s6.WidePathTileLoopX, _s6.WidePathTileLoopY }; // Pad13CE778 // Fix and set dynamic variables diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 6dea32e1a7..7c32ab9dab 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -88,9 +88,6 @@ CoordsXY gMapSelectPositionB; CoordsXYZ gMapSelectArrowPosition; uint8_t gMapSelectArrowDirection; -TileCoordsXY gWidePathTileLoopPosition; -uint16_t gGrassSceneryTileLoopPosition; - std::vector gMapSelectionTiles; bool gLandMountainMode; @@ -462,8 +459,8 @@ void MapInit(const TileCoordsXY& size) auto& gameState = GetGameState(); - gGrassSceneryTileLoopPosition = 0; - gWidePathTileLoopPosition = {}; + gameState.GrassSceneryTileLoopPosition = 0; + gameState.WidePathTileLoopPosition = {}; gameState.MapSize = size; MapRemoveOutOfRangeElements(); MapAnimationAutoCreate(); @@ -761,26 +758,23 @@ void MapUpdatePathWideFlags() // Presumably update_path_wide_flags is too computationally expensive to call for every // tile every update, so gWidePathTileLoopX and gWidePathTileLoopY store the x and y // progress. A maximum of 128 calls is done per update. - auto x = gWidePathTileLoopPosition.x; - auto y = gWidePathTileLoopPosition.y; + CoordsXY& loopPosition = GetGameState().WidePathTileLoopPosition; for (int32_t i = 0; i < 128; i++) { - FootpathUpdatePathWideFlags({ x, y }); + FootpathUpdatePathWideFlags(loopPosition); // Next x, y tile - x += COORDS_XY_STEP; - if (x >= MAXIMUM_MAP_SIZE_BIG) + loopPosition.x += COORDS_XY_STEP; + if (loopPosition.x >= MAXIMUM_MAP_SIZE_BIG) { - x = 0; - y += COORDS_XY_STEP; - if (y >= MAXIMUM_MAP_SIZE_BIG) + loopPosition.x = 0; + loopPosition.y += COORDS_XY_STEP; + if (loopPosition.y >= MAXIMUM_MAP_SIZE_BIG) { - y = 0; + loopPosition.y = 0; } } } - gWidePathTileLoopPosition.x = x; - gWidePathTileLoopPosition.y = y; } /** @@ -1266,7 +1260,7 @@ void MapUpdateTiles() int32_t x = 0; int32_t y = 0; - uint16_t interleaved_xy = gGrassSceneryTileLoopPosition; + uint16_t interleaved_xy = gameState.GrassSceneryTileLoopPosition; for (int32_t i = 0; i < 8; i++) { x = (x << 1) | (interleaved_xy & 1); @@ -1293,7 +1287,7 @@ void MapUpdateTiles() } } - gGrassSceneryTileLoopPosition++; + gameState.GrassSceneryTileLoopPosition++; } } diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index b83626a45e..837fcad2ae 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -107,9 +107,6 @@ enum extern const std::array CoordsDirectionDelta; extern const TileCoordsXY TileDirectionDelta[]; -extern TileCoordsXY gWidePathTileLoopPosition; -extern uint16_t gGrassSceneryTileLoopPosition; - CoordsXY GetMapSizeUnits(); CoordsXY GetMapSizeMinus2(); CoordsXY GetMapSizeMaxXY();