1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-29 17:54:50 +01:00

Move gMapSize to GameState_t

This commit is contained in:
Harry-Hopkinson
2024-02-12 21:32:08 +00:00
parent 72ca04633e
commit b755c873e5
25 changed files with 128 additions and 90 deletions

View File

@@ -91,8 +91,6 @@ uint8_t gMapSelectArrowDirection;
TileCoordsXY gWidePathTileLoopPosition;
uint16_t gGrassSceneryTileLoopPosition;
TileCoordsXY gMapSize;
std::vector<CoordsXY> gMapSelectionTiles;
std::vector<PeepSpawn> 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<TileElement>& 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 });