Skip to content

Commit

Permalink
Merge pull request OpenRCT2#21390 from Harry-Hopkinson/gMapSize-to-Ga…
Browse files Browse the repository at this point in the history
…meState_t

Move gMapSize to GameState_t
  • Loading branch information
ZehMatt authored Feb 13, 2024
2 parents 64787ff + ce8afe2 commit 5ed5fec
Show file tree
Hide file tree
Showing 25 changed files with 130 additions and 90 deletions.
20 changes: 13 additions & 7 deletions src/openrct2-ui/windows/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <openrct2/Cheats.h>
#include <openrct2/Context.h>
#include <openrct2/Game.h>
#include <openrct2/GameState.h>
#include <openrct2/Input.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/actions/LandSetRightsAction.h>
Expand All @@ -38,6 +39,8 @@
#include <openrct2/world/Surface.h>
#include <vector>

using namespace OpenRCT2;

static constexpr uint16_t MapColour2(uint8_t colourA, uint8_t colourB)
{
return (colourA << 8) | colourB;
Expand Down Expand Up @@ -162,7 +165,8 @@ class MapWindow final : public Window
CentreMapOnViewPoint();
FootpathSelectDefault();

_mapWidthAndHeightLinked = gMapSize.x == gMapSize.y;
auto& gameState = GetGameState();
_mapWidthAndHeightLinked = gameState.MapSize.x == gameState.MapSize.y;

// Reset land rights tool size
_landRightsToolSize = 1;
Expand Down Expand Up @@ -630,7 +634,7 @@ class MapWindow final : public Window
size += 2;
size = std::clamp(size, MINIMUM_MAP_SIZE_TECHNICAL, MAXIMUM_MAP_SIZE_TECHNICAL);

TileCoordsXY newMapSize = gMapSize;
TileCoordsXY newMapSize = GetGameState().MapSize;
if (_resizeDirection != ResizeDirection::X)
newMapSize.y = size;
if (_resizeDirection != ResizeDirection::Y)
Expand Down Expand Up @@ -755,7 +759,8 @@ class MapWindow final : public Window
pressed_widgets |= (1uLL << WIDX_CONSTRUCTION_RIGHTS_OWNED_CHECKBOX);

// Set disabled widgets
SetWidgetDisabled(WIDX_MAP_SIZE_LINK, gMapSize.x != gMapSize.y);
auto& gameState = GetGameState();
SetWidgetDisabled(WIDX_MAP_SIZE_LINK, gameState.MapSize.x != gameState.MapSize.y);

// Resize widgets to window size
ResizeFrameWithPage();
Expand Down Expand Up @@ -971,7 +976,7 @@ class MapWindow final : public Window

void IncreaseMapSize()
{
auto newMapSize = gMapSize;
auto newMapSize = GetGameState().MapSize;
if (IsWidgetPressed(WIDX_MAP_SIZE_LINK) || _resizeDirection == ResizeDirection::Y)
newMapSize.y++;
if (IsWidgetPressed(WIDX_MAP_SIZE_LINK) || _resizeDirection == ResizeDirection::X)
Expand All @@ -983,7 +988,7 @@ class MapWindow final : public Window

void DecreaseMapSize()
{
auto newMapSize = gMapSize;
auto newMapSize = GetGameState().MapSize;
if (IsWidgetPressed(WIDX_MAP_SIZE_LINK) || _resizeDirection == ResizeDirection::Y)
newMapSize.y--;
if (IsWidgetPressed(WIDX_MAP_SIZE_LINK) || _resizeDirection == ResizeDirection::X)
Expand Down Expand Up @@ -1312,9 +1317,10 @@ class MapWindow final : public Window
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 = GetGameState();
auto ft = Formatter::Common();
ft.Add<uint16_t>(gMapSize.y - 2);
ft.Add<uint16_t>(gMapSize.x - 2);
ft.Add<uint16_t>(gameState.MapSize.y - 2);
ft.Add<uint16_t>(gameState.MapSize.x - 2);
}

void InputLandSize()
Expand Down
7 changes: 4 additions & 3 deletions src/openrct2-ui/windows/RideConstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2591,9 +2591,10 @@ class RideConstructionWindow final : public Window
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);
Expand Down Expand Up @@ -2660,7 +2661,7 @@ class RideConstructionWindow final : public Window
trackBlock++;
}

gMapSize = preserveMapSize;
gameState.MapSize = preserveMapSize;

PaintSessionArrange(*session);
PaintDrawStructs(*session);
Expand Down
5 changes: 3 additions & 2 deletions src/openrct2/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/openrct2/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/GameState.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ namespace OpenRCT2
money64 ScenarioCompanyValueRecord;
random_engine_t ScenarioRand;
int32_t MapBaseZ;
TileCoordsXY MapSize;

SCENARIO_CATEGORY ScenarioCategory;
std::string ScenarioName;
Expand Down
5 changes: 3 additions & 2 deletions src/openrct2/actions/CheatSetAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions src/openrct2/actions/ClearAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/actions/FootpathPlaceAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "FootpathPlaceAction.h"

#include "../Cheats.h"
#include "../GameState.h"
#include "../OpenRCT2.h"
#include "../core/MemoryStream.h"
#include "../interface/Window.h"
Expand Down
14 changes: 8 additions & 6 deletions src/openrct2/actions/MapChangeSizeAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
}

Expand Down
1 change: 1 addition & 0 deletions src/openrct2/actions/PeepSpawnPlaceAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "PeepSpawnPlaceAction.h"

#include "../Cheats.h"
#include "../GameState.h"
#include "../OpenRCT2.h"
#include "../core/MemoryStream.h"
#include "../localisation/StringIds.h"
Expand Down
5 changes: 3 additions & 2 deletions src/openrct2/actions/RideDemolishAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 11 additions & 8 deletions src/openrct2/interface/Screenshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) } },
},
};

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/network/NetworkServerAdvertiser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ class NetworkServerAdvertiser final : public INetworkServerAdvertiser

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() },
Expand Down
13 changes: 7 additions & 6 deletions src/openrct2/park/ParkFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>();

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/rct2/S6Importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t>(_s6.SamePriceThroughoutExtended) << 32);
gameState.SuggestedGuestMaximum = _s6.SuggestedMaxGuests;
gameState.ScenarioParkRatingWarningDays = _s6.ParkRatingWarningDays;
Expand Down
15 changes: 9 additions & 6 deletions src/openrct2/ride/Ride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down Expand Up @@ -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<EntranceElement>(tilePos.ToCoordsXY()))
{
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions src/openrct2/ride/RideConstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "RideConstruction.h"

#include "../Context.h"
#include "../GameState.h"
#include "../Input.h"
#include "../actions/MazeSetTrackAction.h"
#include "../actions/RideEntranceExitRemoveAction.h"
Expand Down Expand Up @@ -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<TrackElement>(tilePos.ToCoordsXY()))
{
Expand Down
Loading

0 comments on commit 5ed5fec

Please sign in to comment.