mirror of https://github.com/OpenRCT2/OpenRCT2.git
Remove GameState class
This commit is contained in:
parent
28451027b1
commit
fef1a27342
|
@ -714,9 +714,7 @@ public:
|
|||
{
|
||||
if (_titleSequencePlayer == nullptr)
|
||||
{
|
||||
auto context = GetContext();
|
||||
auto gameState = context->GetGameState();
|
||||
_titleSequencePlayer = OpenRCT2::Title::CreateTitleSequencePlayer(*gameState);
|
||||
_titleSequencePlayer = OpenRCT2::Title::CreateTitleSequencePlayer();
|
||||
}
|
||||
return _titleSequencePlayer.get();
|
||||
}
|
||||
|
|
|
@ -46,8 +46,6 @@ namespace OpenRCT2::Title
|
|||
class TitleSequencePlayer final : public ITitleSequencePlayer
|
||||
{
|
||||
private:
|
||||
GameState& _gameState;
|
||||
|
||||
std::unique_ptr<TitleSequence> _sequence;
|
||||
int32_t _position = 0;
|
||||
int32_t _waitCounter = 0;
|
||||
|
@ -57,8 +55,7 @@ namespace OpenRCT2::Title
|
|||
ScreenCoordsXY _previousViewPosition = {};
|
||||
|
||||
public:
|
||||
explicit TitleSequencePlayer(GameState& gameState)
|
||||
: _gameState(gameState)
|
||||
explicit TitleSequencePlayer()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -248,7 +245,7 @@ namespace OpenRCT2::Title
|
|||
{
|
||||
if (Update())
|
||||
{
|
||||
_gameState.UpdateLogic();
|
||||
gameStateUpdateLogic();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -431,8 +428,8 @@ namespace OpenRCT2::Title
|
|||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<ITitleSequencePlayer> CreateTitleSequencePlayer(GameState& gameState)
|
||||
std::unique_ptr<ITitleSequencePlayer> CreateTitleSequencePlayer()
|
||||
{
|
||||
return std::make_unique<TitleSequencePlayer>(gameState);
|
||||
return std::make_unique<TitleSequencePlayer>();
|
||||
}
|
||||
} // namespace OpenRCT2::Title
|
||||
|
|
|
@ -17,10 +17,8 @@ struct IScenarioRepository;
|
|||
|
||||
namespace OpenRCT2
|
||||
{
|
||||
class GameState;
|
||||
|
||||
namespace Title
|
||||
{
|
||||
[[nodiscard]] std::unique_ptr<ITitleSequencePlayer> CreateTitleSequencePlayer(GameState& gameState);
|
||||
[[nodiscard]] std::unique_ptr<ITitleSequencePlayer> CreateTitleSequencePlayer();
|
||||
} // namespace Title
|
||||
} // namespace OpenRCT2
|
||||
|
|
|
@ -123,7 +123,6 @@ namespace OpenRCT2
|
|||
|
||||
// Game states
|
||||
std::unique_ptr<TitleScreen> _titleScreen;
|
||||
std::unique_ptr<GameState> _gameState;
|
||||
|
||||
DrawingEngine _drawingEngineType = DrawingEngine::Software;
|
||||
std::unique_ptr<IDrawingEngine> _drawingEngine;
|
||||
|
@ -221,11 +220,6 @@ namespace OpenRCT2
|
|||
}
|
||||
#endif
|
||||
|
||||
GameState* GetGameState() override
|
||||
{
|
||||
return _gameState.get();
|
||||
}
|
||||
|
||||
std::shared_ptr<IPlatformEnvironment> GetPlatformEnvironment() override
|
||||
{
|
||||
return _env;
|
||||
|
@ -477,14 +471,13 @@ namespace OpenRCT2
|
|||
InputResetPlaceObjModifier();
|
||||
ViewportInitAll();
|
||||
|
||||
_gameState = std::make_unique<GameState>();
|
||||
_gameState->InitAll(DEFAULT_MAP_SIZE);
|
||||
gameStateInitAll(GetGameState(), DEFAULT_MAP_SIZE);
|
||||
|
||||
#ifdef ENABLE_SCRIPTING
|
||||
_scriptEngine.Initialise();
|
||||
#endif
|
||||
|
||||
_titleScreen = std::make_unique<TitleScreen>(*_gameState);
|
||||
_titleScreen = std::make_unique<TitleScreen>();
|
||||
_uiContext->Initialise();
|
||||
|
||||
return true;
|
||||
|
@ -1199,7 +1192,7 @@ namespace OpenRCT2
|
|||
}
|
||||
else
|
||||
{
|
||||
_gameState->Tick();
|
||||
gameStateTick();
|
||||
}
|
||||
|
||||
#ifdef __ENABLE_DISCORD__
|
||||
|
|
|
@ -81,7 +81,6 @@ class NetworkBase;
|
|||
namespace OpenRCT2
|
||||
{
|
||||
class AssetPackManager;
|
||||
class GameState;
|
||||
|
||||
struct IPlatformEnvironment;
|
||||
struct IReplayManager;
|
||||
|
@ -125,7 +124,6 @@ namespace OpenRCT2
|
|||
|
||||
[[nodiscard]] virtual std::shared_ptr<Audio::IAudioContext> GetAudioContext() abstract;
|
||||
[[nodiscard]] virtual std::shared_ptr<Ui::IUiContext> GetUiContext() abstract;
|
||||
virtual GameState* GetGameState() abstract;
|
||||
[[nodiscard]] virtual std::shared_ptr<IPlatformEnvironment> GetPlatformEnvironment() abstract;
|
||||
virtual Localisation::LocalisationService& GetLocalisationService() abstract;
|
||||
virtual IObjectManager& GetObjectManager() abstract;
|
||||
|
|
|
@ -105,7 +105,7 @@ namespace Editor
|
|||
auto& gameState = GetGameState();
|
||||
Audio::StopAll();
|
||||
ObjectListLoad();
|
||||
GetContext()->GetGameState()->InitAll(DEFAULT_MAP_SIZE);
|
||||
gameStateInitAll(gameState, DEFAULT_MAP_SIZE);
|
||||
gScreenFlags = SCREEN_FLAGS_SCENARIO_EDITOR;
|
||||
gameState.EditorStep = EditorStep::ObjectSelection;
|
||||
gameState.ParkFlags |= PARK_FLAGS_SHOW_REAL_GUEST_NAMES;
|
||||
|
@ -167,7 +167,7 @@ namespace Editor
|
|||
|
||||
ObjectManagerUnloadAllObjects();
|
||||
ObjectListLoad();
|
||||
GetContext()->GetGameState()->InitAll(DEFAULT_MAP_SIZE);
|
||||
gameStateInitAll(GetGameState(), DEFAULT_MAP_SIZE);
|
||||
SetAllLandOwned();
|
||||
GetGameState().EditorStep = EditorStep::ObjectSelection;
|
||||
ViewportInitAll();
|
||||
|
@ -188,7 +188,7 @@ namespace Editor
|
|||
|
||||
ObjectManagerUnloadAllObjects();
|
||||
ObjectListLoad();
|
||||
GetContext()->GetGameState()->InitAll(DEFAULT_MAP_SIZE);
|
||||
gameStateInitAll(GetGameState(), DEFAULT_MAP_SIZE);
|
||||
SetAllLandOwned();
|
||||
GetGameState().EditorStep = EditorStep::ObjectSelection;
|
||||
ViewportInitAll();
|
||||
|
|
|
@ -58,20 +58,14 @@ namespace OpenRCT2
|
|||
{
|
||||
return _gameState;
|
||||
}
|
||||
} // namespace OpenRCT2
|
||||
|
||||
GameState::GameState()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialises the map, park etc. basically all S6 data.
|
||||
*/
|
||||
void GameState::InitAll(const TileCoordsXY& mapSize)
|
||||
void gameStateInitAll(GameState_t& gameState, const TileCoordsXY& mapSize)
|
||||
{
|
||||
PROFILED_FUNCTION();
|
||||
|
||||
auto& gameState = GetGameState();
|
||||
gInMapInitCode = true;
|
||||
gameState.CurrentTicks = 0;
|
||||
|
||||
|
@ -115,7 +109,7 @@ void GameState::InitAll(const TileCoordsXY& mapSize)
|
|||
* when operating as a client it may run multiple updates to catch up with the server tick,
|
||||
* another influence can be the game speed setting.
|
||||
*/
|
||||
void GameState::Tick()
|
||||
void gameStateTick()
|
||||
{
|
||||
PROFILED_FUNCTION();
|
||||
|
||||
|
@ -201,7 +195,7 @@ void GameState::Tick()
|
|||
// Update the game one or more times
|
||||
for (uint32_t i = 0; i < numUpdates; i++)
|
||||
{
|
||||
UpdateLogic();
|
||||
gameStateUpdateLogic();
|
||||
if (gGameSpeed == 1)
|
||||
{
|
||||
if (InputGetState() == InputState::Reset || InputGetState() == InputState::Normal)
|
||||
|
@ -267,7 +261,18 @@ void GameState::Tick()
|
|||
gDoSingleUpdate = false;
|
||||
}
|
||||
|
||||
void GameState::UpdateLogic()
|
||||
static void gameStateCreateStateSnapshot()
|
||||
{
|
||||
PROFILED_FUNCTION();
|
||||
|
||||
IGameStateSnapshots* snapshots = GetContext()->GetGameStateSnapshots();
|
||||
|
||||
auto& snapshot = snapshots->CreateSnapshot();
|
||||
snapshots->Capture(snapshot);
|
||||
snapshots->LinkSnapshot(snapshot, GetGameState().CurrentTicks, ScenarioRandState().s0);
|
||||
}
|
||||
|
||||
void gameStateUpdateLogic()
|
||||
{
|
||||
PROFILED_FUNCTION();
|
||||
|
||||
|
@ -285,7 +290,7 @@ void GameState::UpdateLogic()
|
|||
{
|
||||
if (NetworkGamestateSnapshotsEnabled())
|
||||
{
|
||||
CreateStateSnapshot();
|
||||
gameStateCreateStateSnapshot();
|
||||
}
|
||||
|
||||
// Send current tick out.
|
||||
|
@ -309,7 +314,7 @@ void GameState::UpdateLogic()
|
|||
{
|
||||
// Create snapshot from this tick so we can compare it later
|
||||
// as we won't pause the game on this event.
|
||||
CreateStateSnapshot();
|
||||
gameStateCreateStateSnapshot();
|
||||
|
||||
NetworkRequestGamestateSnapshot();
|
||||
}
|
||||
|
@ -381,15 +386,4 @@ void GameState::UpdateLogic()
|
|||
|
||||
gInUpdateCode = false;
|
||||
}
|
||||
|
||||
void GameState::CreateStateSnapshot()
|
||||
{
|
||||
PROFILED_FUNCTION();
|
||||
|
||||
IGameStateSnapshots* snapshots = GetContext()->GetGameStateSnapshots();
|
||||
|
||||
auto& snapshot = snapshots->CreateSnapshot();
|
||||
snapshots->Capture(snapshot);
|
||||
snapshots->LinkSnapshot(snapshot, GetGameState().CurrentTicks, ScenarioRandState().s0);
|
||||
}
|
||||
|
||||
} // namespace OpenRCT2
|
||||
|
|
|
@ -158,20 +158,8 @@ namespace OpenRCT2
|
|||
|
||||
GameState_t& GetGameState();
|
||||
|
||||
/**
|
||||
* Class to update the state of the map and park.
|
||||
*/
|
||||
class GameState final
|
||||
{
|
||||
public:
|
||||
GameState();
|
||||
GameState(const GameState&) = delete;
|
||||
void gameStateInitAll(GameState_t& gameState, const TileCoordsXY& mapSize);
|
||||
void gameStateTick();
|
||||
void gameStateUpdateLogic();
|
||||
|
||||
void InitAll(const TileCoordsXY& mapSize);
|
||||
void Tick();
|
||||
void UpdateLogic();
|
||||
|
||||
private:
|
||||
void CreateStateSnapshot();
|
||||
};
|
||||
} // namespace OpenRCT2
|
||||
|
|
|
@ -59,7 +59,7 @@ static exitcode_t HandleSimulate(CommandLineArgEnumerator* argEnumerator)
|
|||
Console::WriteLine("Running %d ticks...", ticks);
|
||||
for (uint32_t i = 0; i < ticks; i++)
|
||||
{
|
||||
context->GetGameState()->UpdateLogic();
|
||||
gameStateUpdateLogic();
|
||||
}
|
||||
Console::WriteLine("Completed: %s", GetAllEntitiesChecksum().ToString().c_str());
|
||||
}
|
||||
|
|
|
@ -1063,8 +1063,7 @@ namespace OpenRCT2
|
|||
|
||||
if (cs.GetMode() == OrcaStream::Mode::READING)
|
||||
{
|
||||
// TODO: Use the passed gameState instead of the global one.
|
||||
OpenRCT2::GetContext()->GetGameState()->InitAll(gameState.MapSize);
|
||||
gameStateInitAll(gameState, gameState.MapSize);
|
||||
|
||||
auto numElements = cs.Read<uint32_t>();
|
||||
|
||||
|
|
|
@ -326,8 +326,7 @@ namespace RCT1
|
|||
gScenarioFileName = GetRCT1ScenarioName();
|
||||
|
||||
// Do map initialisation, same kind of stuff done when loading scenario editor
|
||||
auto context = OpenRCT2::GetContext();
|
||||
context->GetGameState()->InitAll({ mapSize, mapSize });
|
||||
gameStateInitAll(gameState, { mapSize, mapSize });
|
||||
gameState.EditorStep = EditorStep::ObjectSelection;
|
||||
gameState.ParkFlags |= PARK_FLAGS_SHOW_REAL_GUEST_NAMES;
|
||||
gameState.ScenarioCategory = SCENARIO_CATEGORY_OTHER;
|
||||
|
|
|
@ -229,7 +229,7 @@ namespace RCT2
|
|||
|
||||
void Import(GameState_t& gameState) override
|
||||
{
|
||||
Initialise();
|
||||
Initialise(gameState);
|
||||
|
||||
gameState.EditorStep = _s6.Info.EditorStep;
|
||||
gameState.ScenarioCategory = static_cast<SCENARIO_CATEGORY>(_s6.Info.Category);
|
||||
|
@ -1719,9 +1719,9 @@ namespace RCT2
|
|||
dst->position.y = src->y;
|
||||
}
|
||||
|
||||
void Initialise()
|
||||
void Initialise(GameState_t& gameState)
|
||||
{
|
||||
OpenRCT2::GetContext()->GetGameState()->InitAll({ _s6.MapSize, _s6.MapSize });
|
||||
gameStateInitAll(gameState, { _s6.MapSize, _s6.MapSize });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -39,8 +39,7 @@ using namespace OpenRCT2;
|
|||
bool gPreviewingTitleSequenceInGame;
|
||||
static TitleScreen* _singleton = nullptr;
|
||||
|
||||
TitleScreen::TitleScreen(GameState& gameState)
|
||||
: _gameState(gameState)
|
||||
TitleScreen::TitleScreen()
|
||||
{
|
||||
_singleton = this;
|
||||
}
|
||||
|
@ -129,7 +128,7 @@ void TitleScreen::Load()
|
|||
GetContext()->GetNetwork().Close();
|
||||
#endif
|
||||
OpenRCT2::Audio::StopAll();
|
||||
GetContext()->GetGameState()->InitAll(DEFAULT_MAP_SIZE);
|
||||
gameStateInitAll(GetGameState(), DEFAULT_MAP_SIZE);
|
||||
ViewportInitAll();
|
||||
ContextOpenWindow(WindowClass::MainWindow);
|
||||
CreateWindows();
|
||||
|
@ -173,7 +172,7 @@ void TitleScreen::Tick()
|
|||
}
|
||||
for (int32_t i = 0; i < numUpdates; i++)
|
||||
{
|
||||
_gameState.UpdateLogic();
|
||||
gameStateUpdateLogic();
|
||||
}
|
||||
UpdatePaletteEffects();
|
||||
// update_weather_animation();
|
||||
|
@ -336,7 +335,7 @@ bool TitleScreen::TryLoadSequence(bool loadPreview)
|
|||
_loadedTitleSequenceId = SIZE_MAX;
|
||||
if (!loadPreview)
|
||||
{
|
||||
GetContext()->GetGameState()->InitAll(DEFAULT_MAP_SIZE);
|
||||
gameStateInitAll(GetGameState(), DEFAULT_MAP_SIZE);
|
||||
GameNotifyMapChanged();
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -16,12 +16,10 @@ struct ITitleSequencePlayer;
|
|||
|
||||
namespace OpenRCT2
|
||||
{
|
||||
class GameState;
|
||||
|
||||
class TitleScreen final
|
||||
{
|
||||
public:
|
||||
TitleScreen(GameState& gameState);
|
||||
TitleScreen();
|
||||
~TitleScreen();
|
||||
|
||||
ITitleSequencePlayer* GetSequencePlayer();
|
||||
|
@ -38,8 +36,6 @@ namespace OpenRCT2
|
|||
void ChangePresetSequence(size_t preset);
|
||||
|
||||
private:
|
||||
GameState& _gameState;
|
||||
|
||||
ITitleSequencePlayer* _sequencePlayer = nullptr;
|
||||
size_t _loadedTitleSequenceId = SIZE_MAX;
|
||||
size_t _currentSequence = SIZE_MAX;
|
||||
|
|
|
@ -45,8 +45,6 @@ TEST(MultiLaunchTest, all)
|
|||
|
||||
// Check ride count to check load was successful
|
||||
ASSERT_EQ(RideGetCount(), 134);
|
||||
auto gs = context->GetGameState();
|
||||
ASSERT_NE(gs, nullptr);
|
||||
|
||||
auto& date = GetGameState().Date;
|
||||
// NOTE: This value is saved in the SV6 file, after the import this will be the current state.
|
||||
|
@ -55,7 +53,7 @@ TEST(MultiLaunchTest, all)
|
|||
|
||||
for (int j = 0; j < updatesToTest; j++)
|
||||
{
|
||||
gs->UpdateLogic();
|
||||
gameStateUpdateLogic();
|
||||
}
|
||||
|
||||
ASSERT_EQ(date.GetMonthTicks(), 7862 + updatesToTest);
|
||||
|
|
|
@ -68,11 +68,11 @@ static std::unique_ptr<IContext> localStartGame(const std::string& parkPath)
|
|||
return context;
|
||||
}
|
||||
|
||||
template<class Fn> static bool updateUntil(GameState& gs, int maxSteps, Fn&& fn)
|
||||
template<class Fn> static bool updateUntil(int maxSteps, Fn&& fn)
|
||||
{
|
||||
while (maxSteps-- && !fn())
|
||||
{
|
||||
gs.UpdateLogic();
|
||||
gameStateUpdateLogic();
|
||||
}
|
||||
return maxSteps > 0;
|
||||
}
|
||||
|
@ -96,9 +96,6 @@ TEST_F(PlayTests, SecondGuestInQueueShouldNotRideIfNoFunds)
|
|||
auto context = localStartGame(initStateFile);
|
||||
ASSERT_NE(context.get(), nullptr);
|
||||
|
||||
auto gs = context->GetGameState();
|
||||
ASSERT_NE(gs, nullptr);
|
||||
|
||||
auto& gameState = GetGameState();
|
||||
|
||||
// Open park for free but charging for rides
|
||||
|
@ -125,7 +122,7 @@ TEST_F(PlayTests, SecondGuestInQueueShouldNotRideIfNoFunds)
|
|||
richGuest->CashInPocket = 3000;
|
||||
|
||||
// Wait for rich guest to get in queue
|
||||
bool matched = updateUntil(*gs, 1000, [&]() { return richGuest->State == PeepState::Queuing; });
|
||||
bool matched = updateUntil(1000, [&]() { return richGuest->State == PeepState::Queuing; });
|
||||
ASSERT_TRUE(matched);
|
||||
|
||||
// Insert poor guest
|
||||
|
@ -133,7 +130,7 @@ TEST_F(PlayTests, SecondGuestInQueueShouldNotRideIfNoFunds)
|
|||
poorGuest->CashInPocket = 5;
|
||||
|
||||
// Wait for poor guest to get in queue
|
||||
matched = updateUntil(*gs, 1000, [&]() { return poorGuest->State == PeepState::Queuing; });
|
||||
matched = updateUntil(1000, [&]() { return poorGuest->State == PeepState::Queuing; });
|
||||
ASSERT_TRUE(matched);
|
||||
|
||||
// Raise the price of the ride to a value poor guest can't pay
|
||||
|
@ -142,7 +139,7 @@ TEST_F(PlayTests, SecondGuestInQueueShouldNotRideIfNoFunds)
|
|||
// Verify that the poor guest goes back to walking without riding
|
||||
// since it doesn't have enough money to pay for it
|
||||
bool enteredTheRide = false;
|
||||
matched = updateUntil(*gs, 10000, [&]() {
|
||||
matched = updateUntil(10000, [&]() {
|
||||
enteredTheRide |= poorGuest->State == PeepState::OnRide;
|
||||
return poorGuest->State == PeepState::Walking || enteredTheRide;
|
||||
});
|
||||
|
@ -159,9 +156,6 @@ TEST_F(PlayTests, CarRideWithOneCarOnlyAcceptsTwoGuests)
|
|||
auto context = localStartGame(initStateFile);
|
||||
ASSERT_NE(context.get(), nullptr);
|
||||
|
||||
auto gs = context->GetGameState();
|
||||
ASSERT_NE(gs, nullptr);
|
||||
|
||||
auto& gameState = GetGameState();
|
||||
|
||||
// Open park for free but charging for rides
|
||||
|
@ -191,7 +185,7 @@ TEST_F(PlayTests, CarRideWithOneCarOnlyAcceptsTwoGuests)
|
|||
|
||||
// Wait until one of them is riding
|
||||
auto guestIsOnRide = [](auto* g) { return g->State == PeepState::OnRide; };
|
||||
bool matched = updateUntil(*gs, 10000, [&]() { return std::any_of(guests.begin(), guests.end(), guestIsOnRide); });
|
||||
bool matched = updateUntil(10000, [&]() { return std::any_of(guests.begin(), guests.end(), guestIsOnRide); });
|
||||
ASSERT_TRUE(matched);
|
||||
|
||||
// For the next few ticks at most two guests can be on the ride
|
||||
|
@ -199,6 +193,6 @@ TEST_F(PlayTests, CarRideWithOneCarOnlyAcceptsTwoGuests)
|
|||
{
|
||||
int numRiding = std::count_if(guests.begin(), guests.end(), guestIsOnRide);
|
||||
ASSERT_LE(numRiding, 2);
|
||||
gs->UpdateLogic();
|
||||
gameStateUpdateLogic();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,9 +81,6 @@ TEST_P(ReplayTests, RunReplay)
|
|||
bool initialised = context->Initialise();
|
||||
ASSERT_TRUE(initialised);
|
||||
|
||||
auto gs = context->GetGameState();
|
||||
ASSERT_NE(gs, nullptr);
|
||||
|
||||
IReplayManager* replayManager = context->GetReplayManager();
|
||||
ASSERT_NE(replayManager, nullptr);
|
||||
|
||||
|
@ -92,7 +89,7 @@ TEST_P(ReplayTests, RunReplay)
|
|||
|
||||
while (replayManager->IsReplaying())
|
||||
{
|
||||
gs->UpdateLogic();
|
||||
gameStateUpdateLogic();
|
||||
if (replayManager->IsPlaybackStateMismatching())
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -138,10 +138,9 @@ static void RecordGameStateSnapshot(std::unique_ptr<IContext>& context, MemorySt
|
|||
|
||||
static void AdvanceGameTicks(uint32_t ticks, std::unique_ptr<IContext>& context)
|
||||
{
|
||||
auto* gameState = context->GetGameState();
|
||||
for (uint32_t i = 0; i < ticks; i++)
|
||||
{
|
||||
gameState->UpdateLogic();
|
||||
gameStateUpdateLogic();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue