mirror of https://github.com/OpenRCT2/OpenRCT2.git
Merge pull request #21454 from Gymnasiast/more-to-gamestate
Move _rides, _tileElements and _restrictedScenery to GameState_t
This commit is contained in:
commit
11ccbbfc5e
|
@ -10,9 +10,11 @@
|
|||
#pragma once
|
||||
|
||||
#include "Date.h"
|
||||
#include "Limits.h"
|
||||
#include "interface/ZoomLevel.h"
|
||||
#include "management/Finance.h"
|
||||
#include "management/NewsItem.h"
|
||||
#include "ride/Ride.h"
|
||||
#include "scenario/Scenario.h"
|
||||
#include "world/Banner.h"
|
||||
#include "world/Climate.h"
|
||||
|
@ -76,6 +78,11 @@ namespace OpenRCT2
|
|||
std::string ScenarioCompletedBy;
|
||||
|
||||
std::vector<Banner> Banners;
|
||||
// Ride storage for all the rides in the park, rides with RideId::Null are considered free.
|
||||
std::array<Ride, OpenRCT2::Limits::MaxRidesInPark> Rides{};
|
||||
std::vector<TileElement> TileElements;
|
||||
|
||||
std::vector<ScenerySelection> RestrictedScenery;
|
||||
|
||||
News::ItemQueues NewsItems;
|
||||
|
||||
|
|
|
@ -439,7 +439,7 @@ void News::DisableNewsItems(News::ItemType type, uint32_t assoc)
|
|||
{
|
||||
auto& gameState = GetGameState();
|
||||
// TODO: write test invalidating windows
|
||||
gameState.NewsItems.ForeachRecentNews([type, assoc, gameState](auto& newsItem) {
|
||||
gameState.NewsItems.ForeachRecentNews([type, assoc, &gameState](auto& newsItem) {
|
||||
if (type == newsItem.Type && assoc == newsItem.Assoc)
|
||||
{
|
||||
newsItem.SetFlags(News::ItemFlags::HasButton);
|
||||
|
|
|
@ -96,10 +96,7 @@ static constexpr int32_t RideInspectionInterval[] = {
|
|||
10, 20, 30, 45, 60, 120, 0, 0,
|
||||
};
|
||||
|
||||
// Ride storage for all the rides in the park, rides with RideId::Null are considered free.
|
||||
static std::array<Ride, OpenRCT2::Limits::MaxRidesInPark> _rides{};
|
||||
|
||||
// This is the highest used index + 1 of the _rides array.
|
||||
// This is the highest used index + 1 of the GameState_t::Rides array.
|
||||
static size_t _endOfUsedRange = 0;
|
||||
|
||||
// A special instance of Ride that is used to draw previews such as the track designs.
|
||||
|
@ -131,10 +128,11 @@ RideManager GetRideManager()
|
|||
|
||||
size_t RideManager::size() const
|
||||
{
|
||||
auto& gameState = GetGameState();
|
||||
size_t count = 0;
|
||||
for (size_t i = 0; i < _endOfUsedRange; i++)
|
||||
{
|
||||
if (!_rides[i].id.IsNull())
|
||||
if (!gameState.Rides[i].id.IsNull())
|
||||
{
|
||||
count++;
|
||||
}
|
||||
|
@ -159,9 +157,10 @@ RideManager::Iterator RideManager::get(RideId rideId)
|
|||
|
||||
RideId GetNextFreeRideId()
|
||||
{
|
||||
for (RideId::UnderlyingType i = 0; i < _rides.size(); i++)
|
||||
auto& gameState = GetGameState();
|
||||
for (RideId::UnderlyingType i = 0; i < gameState.Rides.size(); i++)
|
||||
{
|
||||
if (_rides[i].id.IsNull())
|
||||
if (gameState.Rides[i].id.IsNull())
|
||||
{
|
||||
return RideId::FromUnderlying(i);
|
||||
}
|
||||
|
@ -174,7 +173,7 @@ Ride* RideAllocateAtIndex(RideId index)
|
|||
const auto idx = index.ToUnderlying();
|
||||
_endOfUsedRange = std::max<size_t>(idx + 1, _endOfUsedRange);
|
||||
|
||||
auto result = &_rides[idx];
|
||||
auto result = &GetGameState().Rides[idx];
|
||||
assert(result->id == RideId::GetNull());
|
||||
|
||||
result->id = index;
|
||||
|
@ -196,16 +195,17 @@ static void RideReset(Ride& ride)
|
|||
|
||||
void RideDelete(RideId id)
|
||||
{
|
||||
auto& gameState = GetGameState();
|
||||
const auto idx = id.ToUnderlying();
|
||||
|
||||
assert(idx < _rides.size());
|
||||
assert(_rides[idx].type != RIDE_TYPE_NULL);
|
||||
assert(idx < gameState.Rides.size());
|
||||
assert(gameState.Rides[idx].type != RIDE_TYPE_NULL);
|
||||
|
||||
auto& ride = _rides[idx];
|
||||
auto& ride = gameState.Rides[idx];
|
||||
RideReset(ride);
|
||||
|
||||
// Shrink maximum ride size.
|
||||
while (_endOfUsedRange > 0 && _rides[_endOfUsedRange - 1].id.IsNull())
|
||||
while (_endOfUsedRange > 0 && gameState.Rides[_endOfUsedRange - 1].id.IsNull())
|
||||
{
|
||||
_endOfUsedRange--;
|
||||
}
|
||||
|
@ -218,14 +218,15 @@ Ride* GetRide(RideId index)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
auto& gameState = GetGameState();
|
||||
const auto idx = index.ToUnderlying();
|
||||
assert(idx < _rides.size());
|
||||
if (idx >= _rides.size())
|
||||
assert(idx < gameState.Rides.size());
|
||||
if (idx >= gameState.Rides.size())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto& ride = _rides[idx];
|
||||
auto& ride = gameState.Rides[idx];
|
||||
if (ride.type != RIDE_TYPE_NULL)
|
||||
{
|
||||
assert(ride.id == index);
|
||||
|
@ -942,7 +943,8 @@ bool Ride::SupportsStatus(RideStatus s) const
|
|||
*/
|
||||
void RideInitAll()
|
||||
{
|
||||
std::for_each(std::begin(_rides), std::end(_rides), RideReset);
|
||||
auto& gameState = GetGameState();
|
||||
std::for_each(std::begin(gameState.Rides), std::end(gameState.Rides), RideReset);
|
||||
_endOfUsedRange = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -106,7 +106,6 @@ uint32_t gLandRemainingConstructionSales;
|
|||
bool gMapLandRightsUpdateSuccess;
|
||||
|
||||
static TilePointerIndex<TileElement> _tileIndex;
|
||||
static std::vector<TileElement> _tileElements;
|
||||
static TilePointerIndex<TileElement> _tileIndexStash;
|
||||
static std::vector<TileElement> _tileElementsStash;
|
||||
static size_t _tileElementsInUse;
|
||||
|
@ -116,8 +115,9 @@ static int32_t _currentRotationStash;
|
|||
|
||||
void StashMap()
|
||||
{
|
||||
auto& gameState = GetGameState();
|
||||
_tileIndexStash = std::move(_tileIndex);
|
||||
_tileElementsStash = std::move(_tileElements);
|
||||
_tileElementsStash = std::move(gameState.TileElements);
|
||||
_mapSizeStash = GetGameState().MapSize;
|
||||
_currentRotationStash = gCurrentRotation;
|
||||
_tileElementsInUseStash = _tileElementsInUse;
|
||||
|
@ -125,8 +125,9 @@ void StashMap()
|
|||
|
||||
void UnstashMap()
|
||||
{
|
||||
auto& gameState = GetGameState();
|
||||
_tileIndex = std::move(_tileIndexStash);
|
||||
_tileElements = std::move(_tileElementsStash);
|
||||
gameState.TileElements = std::move(_tileElementsStash);
|
||||
GetGameState().MapSize = _mapSizeStash;
|
||||
gCurrentRotation = _currentRotationStash;
|
||||
_tileElementsInUse = _tileElementsInUseStash;
|
||||
|
@ -150,14 +151,16 @@ CoordsXY GetMapSizeMaxXY()
|
|||
|
||||
const std::vector<TileElement>& GetTileElements()
|
||||
{
|
||||
return _tileElements;
|
||||
return GetGameState().TileElements;
|
||||
}
|
||||
|
||||
void SetTileElements(std::vector<TileElement>&& tileElements)
|
||||
{
|
||||
_tileElements = std::move(tileElements);
|
||||
_tileIndex = TilePointerIndex<TileElement>(MAXIMUM_MAP_SIZE_TECHNICAL, _tileElements.data(), _tileElements.size());
|
||||
_tileElementsInUse = _tileElements.size();
|
||||
auto& gameState = GetGameState();
|
||||
gameState.TileElements = std::move(tileElements);
|
||||
_tileIndex = TilePointerIndex<TileElement>(
|
||||
MAXIMUM_MAP_SIZE_TECHNICAL, gameState.TileElements.data(), gameState.TileElements.size());
|
||||
_tileElementsInUse = gameState.TileElements.size();
|
||||
}
|
||||
|
||||
static TileElement GetDefaultSurfaceElement()
|
||||
|
@ -180,7 +183,7 @@ static TileElement GetDefaultSurfaceElement()
|
|||
std::vector<TileElement> GetReorganisedTileElementsWithoutGhosts()
|
||||
{
|
||||
std::vector<TileElement> newElements;
|
||||
newElements.reserve(std::max(MIN_TILE_ELEMENTS, _tileElements.size()));
|
||||
newElements.reserve(std::max(MIN_TILE_ELEMENTS, GetGameState().TileElements.size()));
|
||||
for (int32_t y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++)
|
||||
{
|
||||
for (int32_t x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++)
|
||||
|
@ -245,7 +248,7 @@ static void ReorganiseTileElements(size_t capacity)
|
|||
|
||||
void ReorganiseTileElements()
|
||||
{
|
||||
ReorganiseTileElements(_tileElements.size());
|
||||
ReorganiseTileElements(GetGameState().TileElements.size());
|
||||
}
|
||||
|
||||
static bool MapCheckFreeElementsAndReorganise(size_t numElementsOnTile, size_t numNewElements)
|
||||
|
@ -256,19 +259,20 @@ static bool MapCheckFreeElementsAndReorganise(size_t numElementsOnTile, size_t n
|
|||
return false;
|
||||
}
|
||||
|
||||
auto& gameState = GetGameState();
|
||||
auto totalElementsRequired = numElementsOnTile + numNewElements;
|
||||
auto freeElements = _tileElements.capacity() - _tileElements.size();
|
||||
auto freeElements = gameState.TileElements.capacity() - gameState.TileElements.size();
|
||||
if (freeElements >= totalElementsRequired)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// if space issue is due to fragmentation then Reorg Tiles without increasing capacity
|
||||
if (_tileElements.size() > totalElementsRequired + _tileElementsInUse)
|
||||
if (gameState.TileElements.size() > totalElementsRequired + _tileElementsInUse)
|
||||
{
|
||||
ReorganiseTileElements();
|
||||
// This check is not expected to fail
|
||||
freeElements = _tileElements.capacity() - _tileElements.size();
|
||||
freeElements = gameState.TileElements.capacity() - gameState.TileElements.size();
|
||||
if (freeElements >= totalElementsRequired)
|
||||
{
|
||||
return true;
|
||||
|
@ -276,7 +280,7 @@ static bool MapCheckFreeElementsAndReorganise(size_t numElementsOnTile, size_t n
|
|||
}
|
||||
|
||||
// Capacity must increase to handle the space (Note capacity can go above MAX_TILE_ELEMENTS)
|
||||
auto newCapacity = _tileElements.capacity() * 2;
|
||||
auto newCapacity = gameState.TileElements.capacity() * 2;
|
||||
ReorganiseTileElements(newCapacity);
|
||||
return true;
|
||||
}
|
||||
|
@ -524,7 +528,8 @@ void MapCountRemainingLandRights()
|
|||
*/
|
||||
void MapStripGhostFlagFromElements()
|
||||
{
|
||||
for (auto& element : _tileElements)
|
||||
auto& gameState = GetGameState();
|
||||
for (auto& element : gameState.TileElements)
|
||||
{
|
||||
element.SetGhost(false);
|
||||
}
|
||||
|
@ -1033,9 +1038,10 @@ void TileElementRemove(TileElement* tileElement)
|
|||
(tileElement - 1)->SetLastForTile(true);
|
||||
tileElement->BaseHeight = MAX_ELEMENT_HEIGHT;
|
||||
_tileElementsInUse--;
|
||||
if (tileElement == &_tileElements.back())
|
||||
auto& gameState = GetGameState();
|
||||
if (tileElement == &gameState.TileElements.back())
|
||||
{
|
||||
_tileElements.pop_back();
|
||||
gameState.TileElements.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1160,10 +1166,11 @@ static TileElement* AllocateTileElements(size_t numElementsOnTile, size_t numNew
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
auto oldSize = _tileElements.size();
|
||||
_tileElements.resize(_tileElements.size() + numElementsOnTile + numNewElements);
|
||||
auto& gameState = GetGameState();
|
||||
auto oldSize = gameState.TileElements.size();
|
||||
gameState.TileElements.resize(gameState.TileElements.size() + numElementsOnTile + numNewElements);
|
||||
_tileElementsInUse += numNewElements;
|
||||
return &_tileElements[oldSize];
|
||||
return &gameState.TileElements[oldSize];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -60,7 +60,7 @@ int16_t gSceneryCtrlPressZ;
|
|||
|
||||
money64 gClearSceneryCost;
|
||||
|
||||
static std::vector<ScenerySelection> _restrictedScenery;
|
||||
using namespace OpenRCT2;
|
||||
|
||||
// rct2: 0x009A3E74
|
||||
const CoordsXY SceneryQuadrantOffsets[] = {
|
||||
|
@ -373,17 +373,19 @@ static bool IsSceneryEntryValid(const ScenerySelection& item)
|
|||
|
||||
bool IsSceneryItemRestricted(const ScenerySelection& item)
|
||||
{
|
||||
return std::find(std::begin(_restrictedScenery), std::end(_restrictedScenery), item) != std::end(_restrictedScenery);
|
||||
auto& gameState = GetGameState();
|
||||
return std::find(std::begin(gameState.RestrictedScenery), std::end(gameState.RestrictedScenery), item)
|
||||
!= std::end(gameState.RestrictedScenery);
|
||||
}
|
||||
|
||||
void ClearRestrictedScenery()
|
||||
{
|
||||
_restrictedScenery.clear();
|
||||
GetGameState().RestrictedScenery.clear();
|
||||
}
|
||||
|
||||
std::vector<ScenerySelection>& GetRestrictedScenery()
|
||||
{
|
||||
return _restrictedScenery;
|
||||
return GetGameState().RestrictedScenery;
|
||||
}
|
||||
|
||||
static std::vector<ScenerySelection> GetAllMiscScenery()
|
||||
|
@ -418,16 +420,19 @@ static std::vector<ScenerySelection> GetAllMiscScenery()
|
|||
|
||||
void RestrictAllMiscScenery()
|
||||
{
|
||||
auto& gameState = GetGameState();
|
||||
auto miscScenery = GetAllMiscScenery();
|
||||
_restrictedScenery.insert(_restrictedScenery.begin(), miscScenery.begin(), miscScenery.end());
|
||||
gameState.RestrictedScenery.insert(gameState.RestrictedScenery.begin(), miscScenery.begin(), miscScenery.end());
|
||||
}
|
||||
|
||||
void MarkAllUnrestrictedSceneryAsInvented()
|
||||
{
|
||||
auto& gameState = GetGameState();
|
||||
auto miscScenery = GetAllMiscScenery();
|
||||
for (const auto& sceneryItem : miscScenery)
|
||||
{
|
||||
if (std::find(_restrictedScenery.begin(), _restrictedScenery.end(), sceneryItem) == _restrictedScenery.end())
|
||||
if (std::find(gameState.RestrictedScenery.begin(), gameState.RestrictedScenery.end(), sceneryItem)
|
||||
== gameState.RestrictedScenery.end())
|
||||
{
|
||||
ScenerySetInvented(sceneryItem);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue