From b755c873e590ed3dca826444615862dcdae84a21 Mon Sep 17 00:00:00 2001 From: Harry-Hopkinson Date: Mon, 12 Feb 2024 21:32:08 +0000 Subject: [PATCH] Move gMapSize to GameState_t --- src/openrct2-ui/windows/Map.cpp | 18 +++++---- src/openrct2-ui/windows/RideConstruction.cpp | 7 ++-- src/openrct2/Editor.cpp | 5 ++- src/openrct2/Game.cpp | 3 +- src/openrct2/GameState.h | 1 + src/openrct2/actions/CheatSetAction.cpp | 5 ++- src/openrct2/actions/ClearAction.cpp | 6 ++- src/openrct2/actions/FootpathPlaceAction.cpp | 1 + src/openrct2/actions/MapChangeSizeAction.cpp | 14 ++++--- src/openrct2/actions/PeepSpawnPlaceAction.cpp | 1 + src/openrct2/actions/RideDemolishAction.cpp | 5 ++- src/openrct2/interface/Screenshot.cpp | 19 +++++---- .../network/NetworkServerAdvertiser.cpp | 2 +- src/openrct2/park/ParkFile.cpp | 13 ++++--- src/openrct2/rct2/S6Importer.cpp | 2 +- src/openrct2/ride/Ride.cpp | 15 ++++--- src/openrct2/ride/RideConstruction.cpp | 6 ++- src/openrct2/ride/RideRatings.cpp | 6 ++- src/openrct2/ride/TrackDesign.cpp | 4 +- src/openrct2/scenario/Scenario.cpp | 5 ++- .../scripting/bindings/world/ScMap.cpp | 3 +- src/openrct2/world/Banner.cpp | 5 ++- src/openrct2/world/Map.cpp | 39 +++++++++++++------ src/openrct2/world/Map.h | 18 ++------- src/openrct2/world/MapGen.cpp | 15 ++++--- 25 files changed, 128 insertions(+), 90 deletions(-) diff --git a/src/openrct2-ui/windows/Map.cpp b/src/openrct2-ui/windows/Map.cpp index ab3ca10360..ad5f97cdb2 100644 --- a/src/openrct2-ui/windows/Map.cpp +++ b/src/openrct2-ui/windows/Map.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -162,7 +163,8 @@ public: CentreMapOnViewPoint(); FootpathSelectDefault(); - _mapWidthAndHeightLinked = gMapSize.x == gMapSize.y; + auto& gameState = OpenRCT2::GetGameState(); + _mapWidthAndHeightLinked = gameState.MapSize.x == gameState.MapSize.y; // Reset land rights tool size _landRightsToolSize = 1; @@ -630,7 +632,7 @@ public: size += 2; size = std::clamp(size, MINIMUM_MAP_SIZE_TECHNICAL, MAXIMUM_MAP_SIZE_TECHNICAL); - TileCoordsXY newMapSize = gMapSize; + TileCoordsXY newMapSize = OpenRCT2::GetGameState().MapSize; if (_resizeDirection != ResizeDirection::X) newMapSize.y = size; if (_resizeDirection != ResizeDirection::Y) @@ -755,7 +757,8 @@ public: pressed_widgets |= (1uLL << WIDX_CONSTRUCTION_RIGHTS_OWNED_CHECKBOX); // Set disabled widgets - SetWidgetDisabled(WIDX_MAP_SIZE_LINK, gMapSize.x != gMapSize.y); + auto& gameState = OpenRCT2::GetGameState(); + SetWidgetDisabled(WIDX_MAP_SIZE_LINK, gameState.MapSize.x != gameState.MapSize.y); // Resize widgets to window size ResizeFrameWithPage(); @@ -971,7 +974,7 @@ private: void IncreaseMapSize() { - auto newMapSize = gMapSize; + auto newMapSize = OpenRCT2::GetGameState().MapSize; if (IsWidgetPressed(WIDX_MAP_SIZE_LINK) || _resizeDirection == ResizeDirection::Y) newMapSize.y++; if (IsWidgetPressed(WIDX_MAP_SIZE_LINK) || _resizeDirection == ResizeDirection::X) @@ -983,7 +986,7 @@ private: void DecreaseMapSize() { - auto newMapSize = gMapSize; + auto newMapSize = OpenRCT2::GetGameState().MapSize; if (IsWidgetPressed(WIDX_MAP_SIZE_LINK) || _resizeDirection == ResizeDirection::Y) newMapSize.y--; if (IsWidgetPressed(WIDX_MAP_SIZE_LINK) || _resizeDirection == ResizeDirection::X) @@ -1312,9 +1315,10 @@ private: widgets[WIDX_MAP_GENERATOR].type = WindowWidgetType::Button; // Push width (Y) and height (X) to the common formatter arguments for the map size spinners to use + auto& gameState = OpenRCT2::GetGameState(); auto ft = Formatter::Common(); - ft.Add(gMapSize.y - 2); - ft.Add(gMapSize.x - 2); + ft.Add(gameState.MapSize.y - 2); + ft.Add(gameState.MapSize.x - 2); } void InputLandSize() diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 70d58f00b3..2eb8aff4f7 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -2591,9 +2591,10 @@ private: return; } - auto preserveMapSize = gMapSize; + auto& gameState = OpenRCT2::GetGameState(); + auto preserveMapSize = gameState.MapSize; - gMapSize = { MAXIMUM_MAP_SIZE_TECHNICAL, MAXIMUM_MAP_SIZE_TECHNICAL }; + gameState.MapSize = { MAXIMUM_MAP_SIZE_TECHNICAL, MAXIMUM_MAP_SIZE_TECHNICAL }; // Setup non changing parts of the temporary track tile element tempTrackTileElement.SetType(TileElementType::Track); @@ -2660,7 +2661,7 @@ private: trackBlock++; } - gMapSize = preserveMapSize; + gameState.MapSize = preserveMapSize; PaintSessionArrange(*session); PaintDrawStructs(*session); diff --git a/src/openrct2/Editor.cpp b/src/openrct2/Editor.cpp index f96d10c163..05b49f17f8 100644 --- a/src/openrct2/Editor.cpp +++ b/src/openrct2/Editor.cpp @@ -205,8 +205,9 @@ namespace Editor */ static void SetAllLandOwned() { - MapRange range = { 2 * COORDS_XY_STEP, 2 * COORDS_XY_STEP, (gMapSize.x - 3) * COORDS_XY_STEP, - (gMapSize.y - 3) * COORDS_XY_STEP }; + auto& gameState = GetGameState(); + MapRange range = { 2 * COORDS_XY_STEP, 2 * COORDS_XY_STEP, (gameState.MapSize.x - 3) * COORDS_XY_STEP, + (gameState.MapSize.y - 3) * COORDS_XY_STEP }; auto landSetRightsAction = LandSetRightsAction(range, LandSetRightSetting::SetForSale); landSetRightsAction.SetFlags(GAME_COMMAND_FLAG_NO_SPEND); GameActions::Execute(&landSetRightsAction); diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 526ff90801..8da3d83d8c 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -469,7 +469,8 @@ static void FixInvalidSurfaces() // Fix the invisible border tiles. // At this point, we can be sure that surfaceElement is not NULL. - if (x == 0 || x == gMapSize.x - 1 || y == 0 || y == gMapSize.y - 1) + auto& gameState = GetGameState(); + if (x == 0 || x == gameState.MapSize.x - 1 || y == 0 || y == gameState.MapSize.y - 1) { surfaceElement->SetBaseZ(MINIMUM_LAND_HEIGHT_BIG); surfaceElement->SetClearanceZ(MINIMUM_LAND_HEIGHT_BIG); diff --git a/src/openrct2/GameState.h b/src/openrct2/GameState.h index 518f6c723f..f4c335b8ba 100644 --- a/src/openrct2/GameState.h +++ b/src/openrct2/GameState.h @@ -63,6 +63,7 @@ namespace OpenRCT2 money64 ScenarioCompanyValueRecord; random_engine_t ScenarioRand; int32_t MapBaseZ; + TileCoordsXY MapSize; SCENARIO_CATEGORY ScenarioCategory; std::string ScenarioName; diff --git a/src/openrct2/actions/CheatSetAction.cpp b/src/openrct2/actions/CheatSetAction.cpp index 9ff3440fff..149be4ae49 100644 --- a/src/openrct2/actions/CheatSetAction.cpp +++ b/src/openrct2/actions/CheatSetAction.cpp @@ -419,9 +419,10 @@ ParametersRange CheatSetAction::GetParameterRange(CheatType cheatType) const void CheatSetAction::SetGrassLength(int32_t length) const { - for (int32_t y = 0; y < gMapSize.y; y++) + auto& gameState = GetGameState(); + for (int32_t y = 0; y < gameState.MapSize.y; y++) { - for (int32_t x = 0; x < gMapSize.x; x++) + for (int32_t x = 0; x < gameState.MapSize.x; x++) { auto surfaceElement = MapGetSurfaceElementAt(TileCoordsXY{ x, y }); if (surfaceElement == nullptr) diff --git a/src/openrct2/actions/ClearAction.cpp b/src/openrct2/actions/ClearAction.cpp index 0e1511c7c8..ef4fdfef17 100644 --- a/src/openrct2/actions/ClearAction.cpp +++ b/src/openrct2/actions/ClearAction.cpp @@ -10,6 +10,7 @@ #include "ClearAction.h" #include "../Context.h" +#include "../GameState.h" #include "../core/MemoryStream.h" #include "../drawing/Drawing.h" #include "../localisation/StringIds.h" @@ -216,10 +217,11 @@ money64 ClearAction::ClearSceneryFromTile(const CoordsXY& tilePos, bool executin void ClearAction::ResetClearLargeSceneryFlag() { + auto& gameState = OpenRCT2::GetGameState(); // TODO: Improve efficiency of this - for (int32_t y = 0; y < gMapSize.y; y++) + for (int32_t y = 0; y < gameState.MapSize.y; y++) { - for (int32_t x = 0; x < gMapSize.x; x++) + for (int32_t x = 0; x < gameState.MapSize.x; x++) { auto tileElement = MapGetFirstElementAt(TileCoordsXY{ x, y }); do diff --git a/src/openrct2/actions/FootpathPlaceAction.cpp b/src/openrct2/actions/FootpathPlaceAction.cpp index f22cf2e6d5..e0fcb85b42 100644 --- a/src/openrct2/actions/FootpathPlaceAction.cpp +++ b/src/openrct2/actions/FootpathPlaceAction.cpp @@ -10,6 +10,7 @@ #include "FootpathPlaceAction.h" #include "../Cheats.h" +#include "../GameState.h" #include "../OpenRCT2.h" #include "../core/MemoryStream.h" #include "../interface/Window.h" diff --git a/src/openrct2/actions/MapChangeSizeAction.cpp b/src/openrct2/actions/MapChangeSizeAction.cpp index 55b16ca8a6..9ceeb8711e 100644 --- a/src/openrct2/actions/MapChangeSizeAction.cpp +++ b/src/openrct2/actions/MapChangeSizeAction.cpp @@ -10,6 +10,7 @@ #include "MapChangeSizeAction.h" #include "../Context.h" +#include "../GameState.h" #include "../drawing/IDrawingEngine.h" #include "../ui/UiContext.h" #include "../ui/WindowManager.h" @@ -47,22 +48,23 @@ GameActions::Result MapChangeSizeAction::Query() const GameActions::Result MapChangeSizeAction::Execute() const { + auto& gameState = OpenRCT2::GetGameState(); // Expand map - while (_targetSize.x > gMapSize.x) + while (_targetSize.x > gameState.MapSize.x) { - gMapSize.x++; + gameState.MapSize.x++; MapExtendBoundarySurfaceX(); } - while (_targetSize.y > gMapSize.y) + while (_targetSize.y > gameState.MapSize.y) { - gMapSize.y++; + gameState.MapSize.y++; MapExtendBoundarySurfaceY(); } // Shrink map - if (_targetSize.x < gMapSize.x || _targetSize.y < gMapSize.y) + if (_targetSize.x < gameState.MapSize.x || _targetSize.y < gameState.MapSize.y) { - gMapSize = _targetSize; + gameState.MapSize = _targetSize; MapRemoveOutOfRangeElements(); } diff --git a/src/openrct2/actions/PeepSpawnPlaceAction.cpp b/src/openrct2/actions/PeepSpawnPlaceAction.cpp index 1455089dc9..6e38794033 100644 --- a/src/openrct2/actions/PeepSpawnPlaceAction.cpp +++ b/src/openrct2/actions/PeepSpawnPlaceAction.cpp @@ -10,6 +10,7 @@ #include "PeepSpawnPlaceAction.h" #include "../Cheats.h" +#include "../GameState.h" #include "../OpenRCT2.h" #include "../core/MemoryStream.h" #include "../localisation/StringIds.h" diff --git a/src/openrct2/actions/RideDemolishAction.cpp b/src/openrct2/actions/RideDemolishAction.cpp index efeeaee55e..f06c328705 100644 --- a/src/openrct2/actions/RideDemolishAction.cpp +++ b/src/openrct2/actions/RideDemolishAction.cpp @@ -195,10 +195,11 @@ money64 RideDemolishAction::DemolishTracks() const uint8_t oldpaused = gGamePaused; gGamePaused = 0; + auto& gameState = GetGameState(); - for (TileCoordsXY tilePos = {}; tilePos.x < gMapSize.x; ++tilePos.x) + for (TileCoordsXY tilePos = {}; tilePos.x < gameState.MapSize.x; ++tilePos.x) { - for (tilePos.y = 0; tilePos.y < gMapSize.y; ++tilePos.y) + for (tilePos.y = 0; tilePos.y < gameState.MapSize.y; ++tilePos.y) { const auto tileCoords = tilePos.ToCoordsXY(); // Loop over all elements of the tile until there are no more items to remove diff --git a/src/openrct2/interface/Screenshot.cpp b/src/openrct2/interface/Screenshot.cpp index 7c6420edb8..9796030201 100644 --- a/src/openrct2/interface/Screenshot.cpp +++ b/src/openrct2/interface/Screenshot.cpp @@ -280,22 +280,25 @@ static void ReleaseDPI(DrawPixelInfo& dpi) static Viewport GetGiantViewport(int32_t rotation, ZoomLevel zoom) { + auto& gameState = GetGameState(); // Get the tile coordinates of each corner const TileCoordsXY cornerCoords[2][4] = { { // Map corners { 1, 1 }, - { gMapSize.x - 2, gMapSize.y - 2 }, - { 1, gMapSize.y - 2 }, - { gMapSize.x - 2, 1 }, + { gameState.MapSize.x - 2, gameState.MapSize.y - 2 }, + { 1, gameState.MapSize.y - 2 }, + { gameState.MapSize.x - 2, 1 }, }, { // Horizontal view clipping corners TileCoordsXY{ CoordsXY{ std::max(gClipSelectionA.x, 32), std::max(gClipSelectionA.y, 32) } }, - TileCoordsXY{ CoordsXY{ std::min(gClipSelectionB.x, (gMapSize.x - 2) * 32), - std::min(gClipSelectionB.y, (gMapSize.y - 2) * 32) } }, - TileCoordsXY{ CoordsXY{ std::max(gClipSelectionA.x, 32), std::min(gClipSelectionB.y, (gMapSize.y - 2) * 32) } }, - TileCoordsXY{ CoordsXY{ std::min(gClipSelectionB.x, (gMapSize.x - 2) * 32), std::max(gClipSelectionA.y, 32) } }, + TileCoordsXY{ CoordsXY{ std::min(gClipSelectionB.x, (gameState.MapSize.x - 2) * 32), + std::min(gClipSelectionB.y, (gameState.MapSize.y - 2) * 32) } }, + TileCoordsXY{ + CoordsXY{ std::max(gClipSelectionA.x, 32), std::min(gClipSelectionB.y, (gameState.MapSize.y - 2) * 32) } }, + TileCoordsXY{ + CoordsXY{ std::min(gClipSelectionB.x, (gameState.MapSize.x - 2) * 32), std::max(gClipSelectionA.y, 32) } }, }, }; @@ -522,7 +525,7 @@ int32_t CommandLineForScreenshot(const char** argv, int32_t argc, ScreenshotOpti customRotation = std::atoi(argv[7]) & 3; } - const auto& mapSize = gMapSize; + const auto& mapSize = GetGameState().MapSize; if (resolutionWidth == 0 || resolutionHeight == 0) { resolutionWidth = (mapSize.x * COORDS_XY_STEP * 2) >> customZoom; diff --git a/src/openrct2/network/NetworkServerAdvertiser.cpp b/src/openrct2/network/NetworkServerAdvertiser.cpp index b1702206cb..eea3c50f11 100644 --- a/src/openrct2/network/NetworkServerAdvertiser.cpp +++ b/src/openrct2/network/NetworkServerAdvertiser.cpp @@ -303,7 +303,7 @@ private: const auto& gameState = GetGameState(); const auto& date = GetDate(); - json_t mapSize = { { "x", gMapSize.x - 2 }, { "y", gMapSize.y - 2 } }; + json_t mapSize = { { "x", gameState.MapSize.x - 2 }, { "y", gameState.MapSize.y - 2 } }; json_t gameInfo = { { "mapSize", mapSize }, { "day", date.GetMonthTicks() }, diff --git a/src/openrct2/park/ParkFile.cpp b/src/openrct2/park/ParkFile.cpp index c964bb6cfe..e7c40061dc 100644 --- a/src/openrct2/park/ParkFile.cpp +++ b/src/openrct2/park/ParkFile.cpp @@ -1062,14 +1062,14 @@ namespace OpenRCT2 auto found = os.ReadWriteChunk( ParkFileChunkType::TILES, - [pathToSurfaceMap, pathToQueueSurfaceMap, pathToRailingsMap, &os](OrcaStream::ChunkStream& cs) { - cs.ReadWrite(gMapSize.x); - cs.ReadWrite(gMapSize.y); + [pathToSurfaceMap, pathToQueueSurfaceMap, pathToRailingsMap, &os, &gameState](OrcaStream::ChunkStream& cs) { + cs.ReadWrite(gameState.MapSize.x); + cs.ReadWrite(gameState.MapSize.y); if (cs.GetMode() == OrcaStream::Mode::READING) { // TODO: Use the passed gameState instead of the global one. - OpenRCT2::GetContext()->GetGameState()->InitAll(gMapSize); + OpenRCT2::GetContext()->GetGameState()->InitAll(gameState.MapSize); auto numElements = cs.Read(); @@ -1151,9 +1151,10 @@ namespace OpenRCT2 void UpdateTrackElementsRideType() { - for (int32_t y = 0; y < gMapSize.y; y++) + auto& gameState = GetGameState(); + for (int32_t y = 0; y < gameState.MapSize.y; y++) { - for (int32_t x = 0; x < gMapSize.x; x++) + for (int32_t x = 0; x < gameState.MapSize.x; x++) { TileElement* tileElement = MapGetFirstElementAt(TileCoordsXY{ x, y }); if (tileElement == nullptr) diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 88e0b1ff9c..4a049b37db 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -402,7 +402,7 @@ namespace RCT2 gameState.Cash = ToMoney64(DECRYPT_MONEY(_s6.Cash)); // Pad013587FC gParkRatingCasualtyPenalty = _s6.ParkRatingCasualtyPenalty; - gMapSize = { _s6.MapSize, _s6.MapSize }; + gameState.MapSize = { _s6.MapSize, _s6.MapSize }; gSamePriceThroughoutPark = _s6.SamePriceThroughout | (static_cast(_s6.SamePriceThroughoutExtended) << 32); gameState.SuggestedGuestMaximum = _s6.SuggestedMaxGuests; gameState.ScenarioParkRatingWarningDays = _s6.ParkRatingWarningDays; diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 03c12fc133..5ffb004b61 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -5599,9 +5599,10 @@ void DetermineRideEntranceAndExitLocations() // Search the map to find it. Skip the outer ring of invisible tiles. bool alreadyFoundEntrance = false; bool alreadyFoundExit = false; - for (int32_t y = 1; y < gMapSize.y - 1; y++) + auto& gameState = GetGameState(); + for (int32_t y = 1; y < gameState.MapSize.y - 1; y++) { - for (int32_t x = 1; x < gMapSize.x - 1; x++) + for (int32_t x = 1; x < gameState.MapSize.x - 1; x++) { TileElement* tileElement = MapGetFirstElementAt(TileCoordsXY{ x, y }); @@ -5685,9 +5686,10 @@ void DetermineRideEntranceAndExitLocations() void RideClearLeftoverEntrances(const Ride& ride) { - for (TileCoordsXY tilePos = {}; tilePos.x < gMapSize.x; ++tilePos.x) + auto& gameState = GetGameState(); + for (TileCoordsXY tilePos = {}; tilePos.x < gameState.MapSize.x; ++tilePos.x) { - for (tilePos.y = 0; tilePos.y < gMapSize.y; ++tilePos.y) + for (tilePos.y = 0; tilePos.y < gameState.MapSize.y; ++tilePos.y) { for (auto* entrance : TileElementsView(tilePos.ToCoordsXY())) { @@ -5764,9 +5766,10 @@ void Ride::IncreaseNumShelteredSections() void Ride::UpdateRideTypeForAllPieces() { - for (int32_t y = 0; y < gMapSize.y; y++) + auto& gameState = GetGameState(); + for (int32_t y = 0; y < gameState.MapSize.y; y++) { - for (int32_t x = 0; x < gMapSize.x; x++) + for (int32_t x = 0; x < gameState.MapSize.x; x++) { auto* tileElement = MapGetFirstElementAt(TileCoordsXY(x, y)); if (tileElement == nullptr) diff --git a/src/openrct2/ride/RideConstruction.cpp b/src/openrct2/ride/RideConstruction.cpp index 80e463b23c..18a1ee100e 100644 --- a/src/openrct2/ride/RideConstruction.cpp +++ b/src/openrct2/ride/RideConstruction.cpp @@ -10,6 +10,7 @@ #include "RideConstruction.h" #include "../Context.h" +#include "../GameState.h" #include "../Input.h" #include "../actions/MazeSetTrackAction.h" #include "../actions/RideEntranceExitRemoveAction.h" @@ -340,9 +341,10 @@ void Ride::RemovePeeps() void RideClearBlockedTiles(const Ride& ride) { - for (TileCoordsXY tilePos = {}; tilePos.x < gMapSize.x; ++tilePos.x) + auto& gameState = GetGameState(); + for (TileCoordsXY tilePos = {}; tilePos.x < gameState.MapSize.x; ++tilePos.x) { - for (tilePos.y = 0; tilePos.y < gMapSize.y; ++tilePos.y) + for (tilePos.y = 0; tilePos.y < gameState.MapSize.y; ++tilePos.y) { for (auto* trackElement : TileElementsView(tilePos.ToCoordsXY())) { diff --git a/src/openrct2/ride/RideRatings.cpp b/src/openrct2/ride/RideRatings.cpp index f241574270..6fb54f01fd 100644 --- a/src/openrct2/ride/RideRatings.cpp +++ b/src/openrct2/ride/RideRatings.cpp @@ -11,6 +11,7 @@ #include "../Cheats.h" #include "../Context.h" +#include "../GameState.h" #include "../OpenRCT2.h" #include "../interface/Window.h" #include "../localisation/Date.h" @@ -1793,9 +1794,10 @@ static int32_t ride_ratings_get_scenery_score(const Ride& ride) // Count surrounding scenery items int32_t numSceneryItems = 0; auto tileLocation = TileCoordsXY(location); - for (int32_t yy = std::max(tileLocation.y - 5, 0); yy <= std::min(tileLocation.y + 5, gMapSize.y - 1); yy++) + auto& gameState = GetGameState(); + for (int32_t yy = std::max(tileLocation.y - 5, 0); yy <= std::min(tileLocation.y + 5, gameState.MapSize.y - 1); yy++) { - for (int32_t xx = std::max(tileLocation.x - 5, 0); xx <= std::min(tileLocation.x + 5, gMapSize.x - 1); xx++) + for (int32_t xx = std::max(tileLocation.x - 5, 0); xx <= std::min(tileLocation.x + 5, gameState.MapSize.x - 1); xx++) { // Count scenery items on this tile TileElement* tileElement = MapGetFirstElementAt(TileCoordsXY{ xx, yy }); diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index 32e0cfe05b..f6cb90ef6b 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -1944,7 +1944,7 @@ static bool TrackDesignPlacePreview(TrackDesignState& tds, TrackDesign* td6, mon uint8_t backup_rotation = _currentTrackPieceDirection; uint32_t backup_park_flags = gameState.ParkFlags; gameState.ParkFlags &= ~PARK_FLAGS_FORBID_HIGH_CONSTRUCTION; - auto mapSize = TileCoordsXY{ gMapSize.x * 16, gMapSize.y * 16 }; + auto mapSize = TileCoordsXY{ gameState.MapSize.x * 16, gameState.MapSize.y * 16 }; _currentTrackPieceDirection = 0; int32_t z = TrackDesignGetZPlacement( @@ -2101,7 +2101,7 @@ static void TrackDesignPreviewClearMap() { auto numTiles = MAXIMUM_MAP_SIZE_TECHNICAL * MAXIMUM_MAP_SIZE_TECHNICAL; - gMapSize = TRACK_DESIGN_PREVIEW_MAP_SIZE; + GetGameState().MapSize = TRACK_DESIGN_PREVIEW_MAP_SIZE; // Reserve ~8 elements per tile std::vector tileElements; diff --git a/src/openrct2/scenario/Scenario.cpp b/src/openrct2/scenario/Scenario.cpp index b7d8e7ee02..33f51b4f3e 100644 --- a/src/openrct2/scenario/Scenario.cpp +++ b/src/openrct2/scenario/Scenario.cpp @@ -434,8 +434,9 @@ bool ScenarioCreateDucks() constexpr int32_t SquareRadiusSize = SquareCentre * 32; CoordsXY centrePos; - centrePos.x = SquareRadiusSize + (ScenarioRandMax(gMapSize.x - SquareCentre) * 32); - centrePos.y = SquareRadiusSize + (ScenarioRandMax(gMapSize.y - SquareCentre) * 32); + auto& gameState = GetGameState(); + centrePos.x = SquareRadiusSize + (ScenarioRandMax(gameState.MapSize.x - SquareCentre) * 32); + centrePos.y = SquareRadiusSize + (ScenarioRandMax(gameState.MapSize.y - SquareCentre) * 32); Guard::Assert(MapIsLocationValid(centrePos)); diff --git a/src/openrct2/scripting/bindings/world/ScMap.cpp b/src/openrct2/scripting/bindings/world/ScMap.cpp index 84ac899274..df3b8560d6 100644 --- a/src/openrct2/scripting/bindings/world/ScMap.cpp +++ b/src/openrct2/scripting/bindings/world/ScMap.cpp @@ -11,6 +11,7 @@ # include "ScMap.hpp" +# include "../../../GameState.h" # include "../../../common.h" # include "../../../entity/Balloon.h" # include "../../../entity/Duck.h" @@ -43,7 +44,7 @@ namespace OpenRCT2::Scripting DukValue ScMap::size_get() const { - return ToDuk(_context, gMapSize); + return ToDuk(_context, GetGameState().MapSize); } int32_t ScMap::numRides_get() const diff --git a/src/openrct2/world/Banner.cpp b/src/openrct2/world/Banner.cpp index 2ed603df27..6390eb0766 100644 --- a/src/openrct2/world/Banner.cpp +++ b/src/openrct2/world/Banner.cpp @@ -251,10 +251,11 @@ struct BannerElementWithPos // Returns a list of BannerElement's with the tile position. static std::vector GetAllBannerElementsOnMap() { + auto& gameState = GetGameState(); std::vector banners; - for (int y = 0; y < gMapSize.y; y++) + for (int y = 0; y < gameState.MapSize.y; y++) { - for (int x = 0; x < gMapSize.x; x++) + for (int x = 0; x < gameState.MapSize.x; x++) { const auto tilePos = TileCoordsXY{ x, y }; for (auto* bannerElement : OpenRCT2::TileElementsView(tilePos.ToCoordsXY())) diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index cc1ec2d7ed..3cdb9ba1bf 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -91,8 +91,6 @@ uint8_t gMapSelectArrowDirection; TileCoordsXY gWidePathTileLoopPosition; uint16_t gGrassSceneryTileLoopPosition; -TileCoordsXY gMapSize; - std::vector gMapSelectionTiles; std::vector gPeepSpawns; @@ -120,7 +118,7 @@ void StashMap() { _tileIndexStash = std::move(_tileIndex); _tileElementsStash = std::move(_tileElements); - _mapSizeStash = gMapSize; + _mapSizeStash = GetGameState().MapSize; _currentRotationStash = gCurrentRotation; _tileElementsInUseStash = _tileElementsInUse; } @@ -129,11 +127,27 @@ void UnstashMap() { _tileIndex = std::move(_tileIndexStash); _tileElements = std::move(_tileElementsStash); - gMapSize = _mapSizeStash; + GetGameState().MapSize = _mapSizeStash; gCurrentRotation = _currentRotationStash; _tileElementsInUse = _tileElementsInUseStash; } +CoordsXY GetMapSizeUnits() +{ + auto& gameState = OpenRCT2::GetGameState(); + return { (gameState.MapSize.x - 1) * COORDS_XY_STEP, (gameState.MapSize.y - 1) * COORDS_XY_STEP }; +} +CoordsXY GetMapSizeMinus2() +{ + auto& gameState = OpenRCT2::GetGameState(); + return { (gameState.MapSize.x * COORDS_XY_STEP) + (8 * COORDS_XY_STEP - 2), + (gameState.MapSize.y * COORDS_XY_STEP) + (8 * COORDS_XY_STEP - 2) }; +} +CoordsXY GetMapSizeMaxXY() +{ + return GetMapSizeUnits() - CoordsXY{ 1, 1 }; +} + const std::vector& GetTileElements() { return _tileElements; @@ -449,7 +463,7 @@ void MapInit(const TileCoordsXY& size) gGrassSceneryTileLoopPosition = 0; gWidePathTileLoopPosition = {}; - gMapSize = size; + gameState.MapSize = size; gameState.MapBaseZ = 7; MapRemoveOutOfRangeElements(); MapAnimationAutoCreate(); @@ -467,10 +481,11 @@ void MapCountRemainingLandRights() { gLandRemainingOwnershipSales = 0; gLandRemainingConstructionSales = 0; + auto& gameState = GetGameState(); - for (int32_t y = 0; y < gMapSize.y; y++) + for (int32_t y = 0; y < gameState.MapSize.y; y++) { - for (int32_t x = 0; x < gMapSize.x; x++) + for (int32_t x = 0; x < gameState.MapSize.x; x++) { auto* surfaceElement = MapGetSurfaceElementAt(TileCoordsXY{ x, y }); // Surface elements are sometimes hacked out to save some space for other map elements @@ -1240,6 +1255,8 @@ void MapUpdateTiles() if (gScreenFlags & ignoreScreenFlags) return; + auto& gameState = GetGameState(); + // Update 43 more tiles (for each 256x256 block) for (int32_t j = 0; j < 43; j++) { @@ -1256,9 +1273,9 @@ void MapUpdateTiles() } // Repeat for each 256x256 block on the map - for (int32_t blockY = 0; blockY < gMapSize.y; blockY += 256) + for (int32_t blockY = 0; blockY < gameState.MapSize.y; blockY += 256) { - for (int32_t blockX = 0; blockX < gMapSize.x; blockX += 256) + for (int32_t blockX = 0; blockX < gameState.MapSize.x; blockX += 256) { auto mapPos = TileCoordsXY{ blockX + x, blockY + y }.ToCoordsXY(); if (MapIsEdge(mapPos)) @@ -1405,7 +1422,7 @@ static void MapExtendBoundarySurfaceExtendTile(const SurfaceElement& sourceTile, */ void MapExtendBoundarySurfaceY() { - auto y = gMapSize.y - 2; + auto y = GetGameState().MapSize.y - 2; for (auto x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++) { auto existingTileElement = MapGetSurfaceElementAt(TileCoordsXY{ x, y - 1 }); @@ -1425,7 +1442,7 @@ void MapExtendBoundarySurfaceY() */ void MapExtendBoundarySurfaceX() { - auto x = gMapSize.x - 2; + auto x = GetGameState().MapSize.x - 2; for (auto y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++) { auto existingTileElement = MapGetSurfaceElementAt(TileCoordsXY{ x - 1, y }); diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index 5ea4021c60..2a29ce9f88 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -106,21 +106,9 @@ extern const TileCoordsXY TileDirectionDelta[]; extern TileCoordsXY gWidePathTileLoopPosition; extern uint16_t gGrassSceneryTileLoopPosition; -extern TileCoordsXY gMapSize; - -inline CoordsXY GetMapSizeUnits() -{ - return { (gMapSize.x - 1) * COORDS_XY_STEP, (gMapSize.y - 1) * COORDS_XY_STEP }; -} -inline CoordsXY GetMapSizeMinus2() -{ - return { (gMapSize.x * COORDS_XY_STEP) + (8 * COORDS_XY_STEP - 2), - (gMapSize.y * COORDS_XY_STEP) + (8 * COORDS_XY_STEP - 2) }; -} -inline CoordsXY GetMapSizeMaxXY() -{ - return GetMapSizeUnits() - CoordsXY{ 1, 1 }; -} +CoordsXY GetMapSizeUnits(); +CoordsXY GetMapSizeMinus2(); +CoordsXY GetMapSizeMaxXY(); extern uint16_t gMapSelectFlags; extern uint16_t gMapSelectType; diff --git a/src/openrct2/world/MapGen.cpp b/src/openrct2/world/MapGen.cpp index 70ed2e30a3..c035acd20c 100644 --- a/src/openrct2/world/MapGen.cpp +++ b/src/openrct2/world/MapGen.cpp @@ -11,6 +11,7 @@ #include "../Context.h" #include "../Game.h" +#include "../GameState.h" #include "../common.h" #include "../core/Guard.hpp" #include "../core/Imaging.h" @@ -335,9 +336,10 @@ static void MapGenPlaceTrees() // Place trees CoordsXY pos; float treeToLandRatio = (10 + (UtilRand() % 30)) / 100.0f; - for (int32_t y = 1; y < gMapSize.y - 1; y++) + auto& gameState = OpenRCT2::GetGameState(); + for (int32_t y = 1; y < gameState.MapSize.y - 1; y++) { - for (int32_t x = 1; x < gMapSize.x - 1; x++) + for (int32_t x = 1; x < gameState.MapSize.x - 1; x++) { pos.x = x * COORDS_XY_STEP; pos.y = y * COORDS_XY_STEP; @@ -366,8 +368,8 @@ static void MapGenPlaceTrees() // Get map coord, clamped to the edges const auto offset = CoordsXY{ offsetX * COORDS_XY_STEP, offsetY * COORDS_XY_STEP }; auto neighbourPos = pos + offset; - neighbourPos.x = std::clamp(neighbourPos.x, COORDS_XY_STEP, COORDS_XY_STEP * (gMapSize.x - 1)); - neighbourPos.y = std::clamp(neighbourPos.y, COORDS_XY_STEP, COORDS_XY_STEP * (gMapSize.y - 1)); + neighbourPos.x = std::clamp(neighbourPos.x, COORDS_XY_STEP, COORDS_XY_STEP * (gameState.MapSize.x - 1)); + neighbourPos.y = std::clamp(neighbourPos.y, COORDS_XY_STEP, COORDS_XY_STEP * (gameState.MapSize.y - 1)); const auto neighboutSurface = MapGetSurfaceElementAt(neighbourPos); if (neighboutSurface != nullptr && neighboutSurface->GetWaterHeight() > 0) @@ -415,9 +417,10 @@ static void MapGenPlaceTrees() */ static void MapGenSetWaterLevel(int32_t waterLevel) { - for (int32_t y = 1; y < gMapSize.y - 1; y++) + auto& gameState = OpenRCT2::GetGameState(); + for (int32_t y = 1; y < gameState.MapSize.y - 1; y++) { - for (int32_t x = 1; x < gMapSize.x - 1; x++) + for (int32_t x = 1; x < gameState.MapSize.x - 1; x++) { auto surfaceElement = MapGetSurfaceElementAt(TileCoordsXY{ x, y }); if (surfaceElement != nullptr && surfaceElement->BaseHeight < waterLevel)