Replace gCurrentTicks with the one in GameState_t

This commit is contained in:
ζeh Matt 2023-12-28 00:53:43 +02:00
parent 4c919f74aa
commit a5dde0f8dc
No known key found for this signature in database
GPG Key ID: 18CE582C71A225B0
39 changed files with 259 additions and 146 deletions

View File

@ -36,6 +36,8 @@
#include <openrct2/world/Footpath.h>
#include <openrct2/world/Park.h>
using namespace OpenRCT2;
static constexpr StringId WINDOW_TITLE = STR_STRINGID;
static constexpr int32_t WH = 157;
static constexpr int32_t WW = 192;
@ -1146,7 +1148,7 @@ private:
int32_t guestEntryTime = peep->GetParkEntryTime();
if (guestEntryTime != -1)
{
int32_t timeInPark = (gCurrentTicks - guestEntryTime) >> 11;
int32_t timeInPark = (GetGameState().CurrentTicks - guestEntryTime) >> 11;
auto ft = Formatter();
ft.Add<uint16_t>(timeInPark & 0xFFFF);
DrawTextBasic(dpi, screenCoords, STR_GUEST_STAT_TIME_IN_PARK, ft);
@ -1233,7 +1235,7 @@ private:
}
// Every 2048 ticks do a full window_invalidate
int32_t numTicks = gCurrentTicks - guest->GetParkEntryTime();
int32_t numTicks = GetGameState().CurrentTicks - guest->GetParkEntryTime();
if (!(numTicks & 0x7FF))
Invalidate();

View File

@ -13,6 +13,7 @@
#include <openrct2-ui/windows/Window.h>
#include <openrct2/Context.h>
#include <openrct2/Game.h>
#include <openrct2/GameState.h>
#include <openrct2/config/Config.h>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/entity/EntityRegistry.h>
@ -28,6 +29,8 @@
#include <openrct2/world/Park.h>
#include <vector>
using namespace OpenRCT2;
static constexpr StringId WINDOW_TITLE = STR_GUESTS;
static constexpr int32_t WH = 330;
static constexpr int32_t WW = 350;
@ -812,7 +815,7 @@ private:
bool IsRefreshOfGroupsRequired()
{
uint32_t tick256 = Floor2(gCurrentTicks, 256);
uint32_t tick256 = Floor2(GetGameState().CurrentTicks, 256);
if (_selectedView == _lastFindGroupsSelectedView)
{
if (_lastFindGroupsWait != 0 || _lastFindGroupsTick == tick256)
@ -839,7 +842,7 @@ private:
void RefreshGroups()
{
_lastFindGroupsTick = Floor2(gCurrentTicks, 256);
_lastFindGroupsTick = Floor2(GetGameState().CurrentTicks, 256);
_lastFindGroupsSelectedView = _selectedView;
_lastFindGroupsWait = 320;
_groups.clear();

View File

@ -21,6 +21,7 @@
#include <openrct2/Cheats.h>
#include <openrct2/Context.h>
#include <openrct2/Game.h>
#include <openrct2/GameState.h>
#include <openrct2/Input.h>
#include <openrct2/Limits.h>
#include <openrct2/OpenRCT2.h>
@ -4661,7 +4662,7 @@ private:
{
colour_t spriteColour = COLOUR_BLACK;
// Limit update rate of preview to avoid making people dizzy.
if ((gCurrentTicks % 64) == 0)
if ((GetGameState().CurrentTicks % 64) == 0)
{
spriteColour++;
if (spriteColour >= COLOUR_NUM_NORMAL)

View File

@ -87,7 +87,6 @@ bool gIsAutosaveLoaded = false;
bool gLoadKeepWindowsOpen = false;
uint32_t gCurrentTicks;
uint32_t gCurrentRealTimeTicks;
#ifdef ENABLE_SCRIPTING

View File

@ -134,7 +134,6 @@ enum
ERROR_TYPE_FILE_LOAD = 255
};
extern uint32_t gCurrentTicks;
extern uint32_t gCurrentRealTimeTicks;
extern uint16_t gCurrentDeltaTime;

View File

@ -52,10 +52,15 @@ using namespace OpenRCT2::Scripting;
static GameState_t _gameState{};
GameState_t& GetGameState()
namespace OpenRCT2
{
return _gameState;
}
GameState_t& GetGameState()
{
return _gameState;
}
} // namespace OpenRCT2
GameState::GameState()
{
@ -70,7 +75,7 @@ void GameState::InitAll(const TileCoordsXY& mapSize)
PROFILED_FUNCTION();
gInMapInitCode = true;
gCurrentTicks = 0;
GetGameState().CurrentTicks = 0;
MapInit(mapSize);
_park->Initialise();
@ -137,7 +142,7 @@ void GameState::Tick()
if (NetworkGetMode() == NETWORK_MODE_CLIENT && NetworkGetStatus() == NETWORK_STATUS_CONNECTED
&& NetworkGetAuthstatus() == NetworkAuth::Ok)
{
numUpdates = std::clamp<uint32_t>(NetworkGetServerTick() - gCurrentTicks, 0, 10);
numUpdates = std::clamp<uint32_t>(NetworkGetServerTick() - GetGameState().CurrentTicks, 0, 10);
}
else
{
@ -287,7 +292,7 @@ void GameState::UpdateLogic()
else if (NetworkGetMode() == NETWORK_MODE_CLIENT)
{
// Don't run past the server, this condition can happen during map changes.
if (NetworkGetServerTick() == gCurrentTicks)
if (NetworkGetServerTick() == GetGameState().CurrentTicks)
{
gInUpdateCode = false;
return;
@ -359,7 +364,7 @@ void GameState::UpdateLogic()
NetworkProcessPending();
NetworkFlush();
gCurrentTicks++;
GetGameState().CurrentTicks++;
gSavedAge++;
#ifdef ENABLE_SCRIPTING
@ -383,7 +388,7 @@ void GameState::CreateStateSnapshot()
auto& snapshot = snapshots->CreateSnapshot();
snapshots->Capture(snapshot);
snapshots->LinkSnapshot(snapshot, gCurrentTicks, ScenarioRandState().s0);
snapshots->LinkSnapshot(snapshot, GetGameState().CurrentTicks, ScenarioRandState().s0);
}
void GameState::SetDate(Date newDate)

View File

@ -23,6 +23,7 @@ namespace OpenRCT2
struct GameState_t
{
uint32_t CurrentTicks{};
};
GameState_t& GetGameState();

View File

@ -11,6 +11,7 @@
#include "Context.h"
#include "Game.h"
#include "GameState.h"
#include "GameStateSnapshots.h"
#include "OpenRCT2.h"
#include "ParkImporter.h"
@ -145,7 +146,7 @@ namespace OpenRCT2
auto ga = GameActions::Clone(action);
_currentRecording->commands.emplace(gCurrentTicks, std::move(ga), _commandId++);
_currentRecording->commands.emplace(tick, std::move(ga), _commandId++);
}
void AddChecksum(uint32_t tick, EntitiesChecksum&& checksum)
@ -159,17 +160,19 @@ namespace OpenRCT2
if (_mode == ReplayMode::NONE)
return;
if ((_mode == ReplayMode::RECORDING || _mode == ReplayMode::NORMALISATION) && gCurrentTicks == _nextChecksumTick)
const auto currentTicks = GetGameState().CurrentTicks;
if ((_mode == ReplayMode::RECORDING || _mode == ReplayMode::NORMALISATION) && currentTicks == _nextChecksumTick)
{
EntitiesChecksum checksum = GetAllEntitiesChecksum();
AddChecksum(gCurrentTicks, std::move(checksum));
AddChecksum(currentTicks, std::move(checksum));
_nextChecksumTick = gCurrentTicks + ChecksumTicksDelta();
_nextChecksumTick = currentTicks + ChecksumTicksDelta();
}
if (_mode == ReplayMode::RECORDING)
{
if (gCurrentTicks >= _currentRecording->tickEnd)
if (currentTicks >= _currentRecording->tickEnd)
{
StopRecording();
return;
@ -185,7 +188,7 @@ namespace OpenRCT2
ReplayCommands();
// Normal playback will always end at the specific tick.
if (gCurrentTicks >= _currentReplay->tickEnd)
if (currentTicks >= _currentReplay->tickEnd)
{
StopPlayback();
return;
@ -214,7 +217,7 @@ namespace OpenRCT2
auto& snapshot = snapshots->CreateSnapshot();
snapshots->Capture(snapshot);
snapshots->LinkSnapshot(snapshot, gCurrentTicks, ScenarioRandState().s0);
snapshots->LinkSnapshot(snapshot, GetGameState().CurrentTicks, ScenarioRandState().s0);
DataSerialiser snapShotDs(true, snapshotStream);
snapshots->SerialiseSnapshot(snapshot, snapShotDs);
}
@ -230,14 +233,16 @@ namespace OpenRCT2
if (_mode != ReplayMode::NONE && _mode != ReplayMode::NORMALISATION)
return false;
const auto currentTicks = GetGameState().CurrentTicks;
auto replayData = std::make_unique<ReplayRecordData>();
replayData->magic = ReplayMagic;
replayData->version = ReplayVersion;
replayData->networkId = NetworkGetVersion();
replayData->name = name;
replayData->tickStart = gCurrentTicks;
replayData->tickStart = currentTicks;
if (maxTicks != k_MaxReplayTicks)
replayData->tickEnd = gCurrentTicks + maxTicks;
replayData->tickEnd = currentTicks + maxTicks;
else
replayData->tickEnd = k_MaxReplayTicks;
@ -266,7 +271,7 @@ namespace OpenRCT2
_currentRecording = std::move(replayData);
_recordType = rt;
_nextChecksumTick = gCurrentTicks + 1;
_nextChecksumTick = currentTicks + 1;
return true;
}
@ -283,11 +288,13 @@ namespace OpenRCT2
return true;
}
_currentRecording->tickEnd = gCurrentTicks;
const auto currentTicks = GetGameState().CurrentTicks;
_currentRecording->tickEnd = currentTicks;
{
EntitiesChecksum checksum = GetAllEntitiesChecksum();
AddChecksum(gCurrentTicks, std::move(checksum));
AddChecksum(currentTicks, std::move(checksum));
}
TakeGameStateSnapshot(_currentRecording->gameStateSnapshots);
@ -366,7 +373,7 @@ namespace OpenRCT2
info.Version = data->version;
info.TimeRecorded = data->timeRecorded;
if (_mode == ReplayMode::RECORDING)
info.Ticks = gCurrentTicks - data->tickStart;
info.Ticks = GetGameState().CurrentTicks - data->tickStart;
else if (_mode == ReplayMode::PLAYING)
info.Ticks = data->tickEnd - data->tickStart;
info.NumCommands = static_cast<uint32_t>(data->commands.size());
@ -384,9 +391,11 @@ namespace OpenRCT2
GameStateSnapshot_t& replaySnapshot = snapshots->CreateSnapshot();
snapshots->SerialiseSnapshot(replaySnapshot, ds);
const auto currentTicks = GetGameState().CurrentTicks;
auto& localSnapshot = snapshots->CreateSnapshot();
snapshots->Capture(localSnapshot);
snapshots->LinkSnapshot(localSnapshot, gCurrentTicks, ScenarioRandState().s0);
snapshots->LinkSnapshot(localSnapshot, currentTicks, ScenarioRandState().s0);
try
{
GameStateCompareData cmpData = snapshots->Compare(replaySnapshot, localSnapshot);
@ -402,7 +411,7 @@ namespace OpenRCT2
std::string outputPath = GetContext()->GetPlatformEnvironment()->GetDirectoryPath(
DIRBASE::USER, DIRID::LOG_DESYNCS);
char uniqueFileName[128] = {};
snprintf(uniqueFileName, sizeof(uniqueFileName), "replay_desync_%u.txt", gCurrentTicks);
snprintf(uniqueFileName, sizeof(uniqueFileName), "replay_desync_%u.txt", currentTicks);
std::string outputFile = Path::Combine(outputPath, uniqueFileName);
snapshots->LogCompareDataToFile(outputFile, cmpData);
@ -433,7 +442,7 @@ namespace OpenRCT2
return false;
}
gCurrentTicks = replayData->tickStart;
GetGameState().CurrentTicks = replayData->tickStart;
LoadAndCompareSnapshot(replayData->gameStateSnapshots);
@ -495,7 +504,7 @@ namespace OpenRCT2
return false;
}
_nextReplayTick = gCurrentTicks + 1;
_nextReplayTick = GetGameState().CurrentTicks + 1;
return true;
}
@ -788,19 +797,21 @@ namespace OpenRCT2
if (checksumIndex >= _currentReplay->checksums.size())
return;
const auto currentTicks = GetGameState().CurrentTicks;
const auto& savedChecksum = _currentReplay->checksums[checksumIndex];
if (_currentReplay->checksums[checksumIndex].first == gCurrentTicks)
if (_currentReplay->checksums[checksumIndex].first == currentTicks)
{
_currentReplay->checksumIndex++;
EntitiesChecksum checksum = GetAllEntitiesChecksum();
if (savedChecksum.second.raw != checksum.raw)
{
uint32_t replayTick = gCurrentTicks - _currentReplay->tickStart;
uint32_t replayTick = currentTicks - _currentReplay->tickStart;
// Detected different game state.
LOG_WARNING(
"Different sprite checksum at tick %u (Replay Tick: %u) ; Saved: %s, Current: %s", gCurrentTicks,
"Different sprite checksum at tick %u (Replay Tick: %u) ; Saved: %s, Current: %s", currentTicks,
replayTick, savedChecksum.second.ToString().c_str(), checksum.ToString().c_str());
_faultyChecksumIndex = checksumIndex;
@ -809,8 +820,8 @@ namespace OpenRCT2
{
// Good state.
LOG_VERBOSE(
"Good state at tick %u ; Saved: %s, Current: %s", gCurrentTicks,
savedChecksum.second.ToString().c_str(), checksum.ToString().c_str());
"Good state at tick %u ; Saved: %s, Current: %s", currentTicks, savedChecksum.second.ToString().c_str(),
checksum.ToString().c_str());
}
}
}
@ -820,6 +831,8 @@ namespace OpenRCT2
{
auto& replayQueue = _currentReplay->commands;
const auto currentTicks = GetGameState().CurrentTicks;
while (replayQueue.begin() != replayQueue.end())
{
const ReplayCommand& command = (*replayQueue.begin());
@ -827,16 +840,16 @@ namespace OpenRCT2
if (_mode == ReplayMode::PLAYING)
{
// If this is a normal playback wait for the correct tick.
if (command.tick != gCurrentTicks)
if (command.tick != currentTicks)
break;
}
else if (_mode == ReplayMode::NORMALISATION)
{
// Allow one entry per tick.
if (gCurrentTicks != _nextReplayTick)
if (currentTicks != _nextReplayTick)
break;
_nextReplayTick = gCurrentTicks + 1;
_nextReplayTick = currentTicks + 1;
}
bool isPositionValid = false;

View File

@ -10,6 +10,7 @@
#include "GameAction.h"
#include "../Context.h"
#include "../GameState.h"
#include "../ReplayManager.h"
#include "../core/Guard.hpp"
#include "../core/Memory.hpp"
@ -101,7 +102,7 @@ namespace GameActions
return;
}
const uint32_t currentTick = gCurrentTicks;
const uint32_t currentTick = GetGameState().CurrentTicks;
while (_actionQueue.begin() != _actionQueue.end())
{
@ -251,7 +252,7 @@ namespace GameActions
char temp[128] = {};
snprintf(
temp, sizeof(temp), "[%s] Tick: %u, GA: %s (%08X) (", GetRealm(), gCurrentTicks, action->GetName(),
temp, sizeof(temp), "[%s] Tick: %u, GA: %s (%08X) (", GetRealm(), GetGameState().CurrentTicks, action->GetName(),
EnumValue(action->GetType()));
output.Write(temp, strlen(temp));
@ -345,7 +346,7 @@ namespace GameActions
if (!(actionFlags & GameActions::Flags::ClientOnly) && !(flags & GAME_COMMAND_FLAG_NETWORKED))
{
LOG_VERBOSE("[%s] GameAction::Execute %s (Queue)", GetRealm(), action->GetName());
Enqueue(action, gCurrentTicks);
Enqueue(action, GetGameState().CurrentTicks);
return result;
}
@ -415,7 +416,7 @@ namespace GameActions
}
if (recordAction)
{
replayManager->AddGameAction(gCurrentTicks, action);
replayManager->AddGameAction(GetGameState().CurrentTicks, action);
}
}
}

View File

@ -10,6 +10,7 @@
#include "Weather.h"
#include "../Game.h"
#include "../GameState.h"
#include "../config/Config.h"
#include "../interface/Viewport.h"
#include "../ride/TrackDesign.h"
@ -83,15 +84,17 @@ void DrawWeather(DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer)
static void DrawLightRain(
DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height)
{
int32_t x_start = -static_cast<int32_t>(gCurrentTicks) + 8;
int32_t y_start = (gCurrentTicks * 3) + 7;
const auto currentTicks = GetGameState().CurrentTicks;
int32_t x_start = -static_cast<int32_t>(currentTicks) + 8;
int32_t y_start = (currentTicks * 3) + 7;
y_start = -y_start;
x_start += left;
y_start += top;
weatherDrawer->Draw(dpi, left, top, width, height, x_start, y_start, RainPattern);
x_start = -static_cast<int32_t>(gCurrentTicks) + 0x18;
y_start = (gCurrentTicks * 4) + 0x0D;
x_start = -static_cast<int32_t>(currentTicks) + 0x18;
y_start = (currentTicks * 4) + 0x0D;
y_start = -y_start;
x_start += left;
y_start += top;
@ -105,29 +108,31 @@ static void DrawLightRain(
static void DrawHeavyRain(
DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height)
{
int32_t x_start = -static_cast<int32_t>(gCurrentTicks);
int32_t y_start = gCurrentTicks * 5;
const auto currentTicks = GetGameState().CurrentTicks;
int32_t x_start = -static_cast<int32_t>(currentTicks);
int32_t y_start = currentTicks * 5;
y_start = -y_start;
x_start += left;
y_start += top;
weatherDrawer->Draw(dpi, left, top, width, height, x_start, y_start, RainPattern);
x_start = -static_cast<int32_t>(gCurrentTicks) + 0x10;
y_start = (gCurrentTicks * 6) + 5;
x_start = -static_cast<int32_t>(currentTicks) + 0x10;
y_start = (currentTicks * 6) + 5;
y_start = -y_start;
x_start += left;
y_start += top;
weatherDrawer->Draw(dpi, left, top, width, height, x_start, y_start, RainPattern);
x_start = -static_cast<int32_t>(gCurrentTicks) + 8;
y_start = (gCurrentTicks * 3) + 7;
x_start = -static_cast<int32_t>(currentTicks) + 8;
y_start = (currentTicks * 3) + 7;
y_start = -y_start;
x_start += left;
y_start += top;
weatherDrawer->Draw(dpi, left, top, width, height, x_start, y_start, RainPattern);
x_start = -static_cast<int32_t>(gCurrentTicks) + 0x18;
y_start = (gCurrentTicks * 4) + 0x0D;
x_start = -static_cast<int32_t>(currentTicks) + 0x18;
y_start = (currentTicks * 4) + 0x0D;
y_start = -y_start;
x_start += left;
y_start += top;
@ -137,9 +142,11 @@ static void DrawHeavyRain(
static void DrawLightSnow(
DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height)
{
const uint32_t t = gCurrentTicks / 2;
const auto currentTicks = GetGameState().CurrentTicks;
const uint32_t t = currentTicks / 2;
const int32_t negT = -static_cast<int32_t>(t);
const double cosTick = static_cast<double>(gCurrentTicks) * 0.05;
const double cosTick = static_cast<double>(currentTicks) * 0.05;
int32_t x_start = negT + 1 + (cos(1.0 + cosTick) * 6);
int32_t y_start = t + 1;
@ -159,29 +166,31 @@ static void DrawLightSnow(
static void DrawHeavySnow(
DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height)
{
int32_t x_start = -static_cast<int32_t>(gCurrentTicks * 3) + 1;
int32_t y_start = gCurrentTicks + 23;
const auto currentTicks = GetGameState().CurrentTicks;
int32_t x_start = -static_cast<int32_t>(currentTicks * 3) + 1;
int32_t y_start = currentTicks + 23;
y_start = -y_start;
x_start += left;
y_start += top;
weatherDrawer->Draw(dpi, left, top, width, height, x_start, y_start, SnowPattern);
x_start = -static_cast<int32_t>(gCurrentTicks * 4) + 6;
y_start = gCurrentTicks + 5;
x_start = -static_cast<int32_t>(currentTicks * 4) + 6;
y_start = currentTicks + 5;
y_start = -y_start;
x_start += left;
y_start += top;
weatherDrawer->Draw(dpi, left, top, width, height, x_start, y_start, SnowPattern);
x_start = -static_cast<int32_t>(gCurrentTicks * 2) + 11;
y_start = gCurrentTicks + 18;
x_start = -static_cast<int32_t>(currentTicks * 2) + 11;
y_start = currentTicks + 18;
y_start = -y_start;
x_start += left;
y_start += top;
weatherDrawer->Draw(dpi, left, top, width, height, x_start, y_start, SnowPattern);
x_start = -static_cast<int32_t>(gCurrentTicks * 3) + 17;
y_start = gCurrentTicks + 11;
x_start = -static_cast<int32_t>(currentTicks * 3) + 17;
y_start = currentTicks + 11;
y_start = -y_start;
x_start += left;
y_start += top;

View File

@ -9,6 +9,7 @@
#include "Duck.h"
#include "../Game.h"
#include "../GameState.h"
#include "../audio/audio.h"
#include "../core/DataSerialiser.h"
#include "../localisation/Date.h"
@ -23,6 +24,8 @@
#include <iterator>
#include <limits>
using namespace OpenRCT2;
constexpr int32_t DUCK_MAX_STATES = 5;
// clang-format off
@ -88,7 +91,9 @@ void Duck::Remove()
void Duck::UpdateFlyToWater()
{
if ((gCurrentTicks & 3) != 0)
const auto currentTicks = GetGameState().CurrentTicks;
if ((currentTicks & 3) != 0)
return;
frame++;
@ -150,7 +155,9 @@ void Duck::UpdateFlyToWater()
void Duck::UpdateSwim()
{
if (((gCurrentTicks + Id.ToUnderlying()) & 3) != 0)
const auto currentTicks = GetGameState().CurrentTicks;
if (((currentTicks + Id.ToUnderlying()) & 3) != 0)
return;
uint32_t randomNumber = ScenarioRand();
@ -246,7 +253,7 @@ void Duck::UpdateDoubleDrink()
void Duck::UpdateFlyAway()
{
if ((gCurrentTicks & 3) == 0)
if ((GetGameState().CurrentTicks & 3) == 0)
{
frame++;
if (frame >= std::size(DuckAnimationFlyAway))

View File

@ -10,6 +10,7 @@
#include "Fountain.h"
#include "../Game.h"
#include "../GameState.h"
#include "../core/DataSerialiser.h"
#include "../object/PathAdditionEntry.h"
#include "../paint/Paint.h"
@ -21,6 +22,8 @@
#include "../world/Scenery.h"
#include "EntityRegistry.h"
using namespace OpenRCT2;
enum class PATTERN
{
CYCLIC_SQUARES,
@ -86,11 +89,13 @@ template<> bool EntityBase::Is<JumpingFountain>() const
void JumpingFountain::StartAnimation(const JumpingFountainType newType, const CoordsXY& newLoc, const TileElement* tileElement)
{
const auto currentTicks = GetGameState().CurrentTicks;
int32_t randomIndex;
auto newZ = tileElement->GetBaseZ();
// Change pattern approximately every 51 seconds
uint32_t pattern = (gCurrentTicks >> 11) & 7;
uint32_t pattern = (currentTicks >> 11) & 7;
switch (static_cast<PATTERN>(pattern))
{
case PATTERN::CYCLIC_SQUARES:

View File

@ -11,6 +11,7 @@
#include "../Context.h"
#include "../Game.h"
#include "../GameState.h"
#include "../OpenRCT2.h"
#include "../audio/audio.h"
#include "../config/Config.h"
@ -899,7 +900,9 @@ void Guest::Loc68FA89()
void Guest::Tick128UpdateGuest(int32_t index)
{
if (static_cast<uint32_t>(index & 0x1FF) == (gCurrentTicks & 0x1FF))
const auto currentTicks = GetGameState().CurrentTicks;
if (static_cast<uint32_t>(index & 0x1FF) == (currentTicks & 0x1FF))
{
/* Effect of masking with 0x1FF here vs mask 0x7F,
* which is the condition for calling this function, is
@ -1009,7 +1012,7 @@ void Guest::Tick128UpdateGuest(int32_t index)
if (State == PeepState::Walking && !OutsideOfPark && !(PeepFlags & PEEP_FLAGS_LEAVING_PARK) && GuestNumRides == 0
&& GuestHeadingToRideId.IsNull())
{
uint32_t time_duration = gCurrentTicks - ParkEntryTime;
uint32_t time_duration = currentTicks - ParkEntryTime;
time_duration /= 2048;
if (time_duration >= 5)
@ -1033,7 +1036,7 @@ void Guest::Tick128UpdateGuest(int32_t index)
PickRideToGoOn();
}
if (static_cast<uint32_t>(index & 0x3FF) == (gCurrentTicks & 0x3FF))
if (static_cast<uint32_t>(index & 0x3FF) == (currentTicks & 0x3FF))
{
/* Effect of masking with 0x3FF here vs mask 0x1FF,
* which is used in the encompassing conditional, is
@ -3559,12 +3562,14 @@ void PeepUpdateRideLeaveEntranceSpiralSlide(Guest* peep, Ride& ride, CoordsXYZD&
void PeepUpdateRideLeaveEntranceDefault(Guest* peep, Ride& ride, CoordsXYZD& entrance_loc)
{
const auto currentTicks = GetGameState().CurrentTicks;
// If the ride type was changed guests will become stuck.
// Inform the player about this if its a new issue or hasn't been addressed within 120 seconds.
if ((ride.current_issues & RIDE_ISSUE_GUESTS_STUCK) == 0 || gCurrentTicks - ride.last_issue_time > 3000)
if ((ride.current_issues & RIDE_ISSUE_GUESTS_STUCK) == 0 || currentTicks - ride.last_issue_time > 3000)
{
ride.current_issues |= RIDE_ISSUE_GUESTS_STUCK;
ride.last_issue_time = gCurrentTicks;
ride.last_issue_time = currentTicks;
auto ft = Formatter();
ride.FormatNameTo(ft);
@ -5281,6 +5286,8 @@ void Guest::UpdateWalking()
if (!CheckForPath())
return;
const auto currentTicks = GetGameState().CurrentTicks;
if (!IsOnLevelCrossing())
{
if (PeepFlags & PEEP_FLAGS_WAVING && IsActionInterruptable() && (0xFFFF & ScenarioRand()) < 936)
@ -5335,7 +5342,7 @@ void Guest::UpdateWalking()
}
else if (HasEmptyContainer())
{
if ((!GetNextIsSurface()) && (static_cast<uint32_t>(Id.ToUnderlying() & 0x1FF) == (gCurrentTicks & 0x1FF))
if ((!GetNextIsSurface()) && (static_cast<uint32_t>(Id.ToUnderlying() & 0x1FF) == (currentTicks & 0x1FF))
&& ((0xFFFF & ScenarioRand()) <= 4096))
{
int32_t container = UtilBitScanForward(GetEmptyContainerFlags());
@ -5699,7 +5706,7 @@ void Guest::UpdateEnteringPark()
SetState(PeepState::Falling);
OutsideOfPark = false;
ParkEntryTime = gCurrentTicks;
ParkEntryTime = GetGameState().CurrentTicks;
IncrementGuestsInPark();
DecrementGuestsHeadingForPark();
auto intent = Intent(INTENT_ACTION_UPDATE_GUEST_COUNT);

View File

@ -2,6 +2,7 @@
#include "../Cheats.h"
#include "../Game.h"
#include "../GameState.h"
#include "../core/DataSerialiser.h"
#include "../localisation/StringIds.h"
#include "../paint/Paint.h"
@ -11,6 +12,8 @@
#include "EntityList.h"
#include "EntityRegistry.h"
using namespace OpenRCT2;
template<> bool EntityBase::Is<Litter>() const
{
return Type == EntityType::Litter;
@ -86,7 +89,7 @@ void Litter::Create(const CoordsXYZD& litterPos, Type type)
litter->SpriteData.HeightMax = 3;
litter->SubType = type;
litter->MoveTo(offsetLitterPos);
litter->creationTick = gCurrentTicks;
litter->creationTick = GetGameState().CurrentTicks;
}
/**
@ -137,7 +140,7 @@ StringId Litter::GetName() const
uint32_t Litter::GetAge() const
{
return gCurrentTicks - creationTick;
return GetGameState().CurrentTicks - creationTick;
}
void Litter::Serialise(DataSerialiser& stream)

View File

@ -12,6 +12,7 @@
#include "../Cheats.h"
#include "../Context.h"
#include "../Game.h"
#include "../GameState.h"
#include "../Input.h"
#include "../OpenRCT2.h"
#include "../actions/GameAction.h"
@ -62,6 +63,7 @@
#include <memory>
#include <optional>
using namespace OpenRCT2;
using namespace OpenRCT2::Audio;
uint8_t gGuestChangeModifier;
@ -211,11 +213,13 @@ void PeepUpdateAll()
if (gScreenFlags & SCREEN_FLAGS_EDITOR)
return;
const auto currentTicks = GetGameState().CurrentTicks;
int32_t i = 0;
// Warning this loop can delete peeps
for (auto peep : EntityList<Guest>())
{
if (static_cast<uint32_t>(i & 0x7F) != (gCurrentTicks & 0x7F))
if (static_cast<uint32_t>(i & 0x7F) != (currentTicks & 0x7F))
{
peep->Update();
}
@ -234,7 +238,7 @@ void PeepUpdateAll()
for (auto staff : EntityList<Staff>())
{
if (static_cast<uint32_t>(i & 0x7F) != (gCurrentTicks & 0x7F))
if (static_cast<uint32_t>(i & 0x7F) != (currentTicks & 0x7F))
{
staff->Update();
}
@ -888,7 +892,7 @@ void Peep::SetState(PeepState new_state)
*/
void Peep::UpdatePicked()
{
if (gCurrentTicks & 0x1F)
if (GetGameState().CurrentTicks & 0x1F)
return;
SubState++;
auto* guest = As<Guest>();

View File

@ -11,6 +11,7 @@
#include "../Context.h"
#include "../Game.h"
#include "../GameState.h"
#include "../Input.h"
#include "../actions/StaffSetOrdersAction.h"
#include "../audio/audio.h"
@ -49,6 +50,8 @@
#include <algorithm>
#include <iterator>
using namespace OpenRCT2;
// clang-format off
const StringId StaffCostumeNames[] = {
STR_STAFF_OPTION_COSTUME_PANDA,
@ -487,7 +490,7 @@ bool Staff::DoHandymanPathFinding()
Direction litterDirection = INVALID_DIRECTION;
uint8_t validDirections = GetValidPatrolDirections(NextLoc);
if ((StaffOrders & STAFF_ORDERS_SWEEPING) && ((gCurrentTicks + Id.ToUnderlying()) & 0xFFF) > 110)
if ((StaffOrders & STAFF_ORDERS_SWEEPING) && ((GetGameState().CurrentTicks + Id.ToUnderlying()) & 0xFFF) > 110)
{
litterDirection = HandymanDirectionToNearestLitter();
}

View File

@ -11,6 +11,7 @@
#include "../Date.h"
#include "../Game.h"
#include "../GameState.h"
#include "../OpenRCT2.h"
#include "../actions/ParkSetResearchFundingAction.h"
#include "../config/Config.h"
@ -315,7 +316,7 @@ void ResearchUpdate()
return;
}
if (gCurrentTicks % 32 != 0)
if (GetGameState().CurrentTicks % 32 != 0)
{
return;
}

View File

@ -11,6 +11,7 @@
#include "../Context.h"
#include "../Game.h"
#include "../GameState.h"
#include "../GameStateSnapshots.h"
#include "../OpenRCT2.h"
#include "../PlatformEnvironment.h"
@ -39,6 +40,8 @@
#include <iterator>
#include <stdexcept>
using namespace OpenRCT2;
// This string specifies which version of network stream current build uses.
// It is used for making sure only compatible builds get connected, even within
// single OpenRCT2 version.
@ -783,12 +786,14 @@ bool NetworkBase::IsDesynchronised() const noexcept
bool NetworkBase::CheckDesynchronizaton()
{
const auto currentTicks = GetGameState().CurrentTicks;
// Check synchronisation
if (GetMode() == NETWORK_MODE_CLIENT && _serverState.state != NetworkServerStatus::Desynced
&& !CheckSRAND(gCurrentTicks, ScenarioRandState().s0))
&& !CheckSRAND(currentTicks, ScenarioRandState().s0))
{
_serverState.state = NetworkServerStatus::Desynced;
_serverState.desyncTick = gCurrentTicks;
_serverState.desyncTick = currentTicks;
char str_desync[256];
FormatStringLegacy(str_desync, 256, STR_MULTIPLAYER_DESYNC, nullptr);
@ -1496,7 +1501,7 @@ void NetworkBase::Client_Send_GAME_ACTION(const GameAction* action)
DataSerialiser stream(true);
action->Serialise(stream);
packet << gCurrentTicks << action->GetType() << stream;
packet << GetGameState().CurrentTicks << action->GetType() << stream;
_serverConnection->QueuePacket(std::move(packet));
}
@ -1507,7 +1512,7 @@ void NetworkBase::ServerSendGameAction(const GameAction* action)
DataSerialiser stream(true);
action->Serialise(stream);
packet << gCurrentTicks << action->GetType() << stream;
packet << GetGameState().CurrentTicks << action->GetType() << stream;
SendPacketToClients(packet);
}
@ -1515,7 +1520,7 @@ void NetworkBase::ServerSendGameAction(const GameAction* action)
void NetworkBase::ServerSendTick()
{
NetworkPacket packet(NetworkCommand::Tick);
packet << gCurrentTicks << ScenarioRandState().s0;
packet << GetGameState().CurrentTicks << ScenarioRandState().s0;
uint32_t flags = 0;
// Simple counter which limits how often a sprite checksum gets sent.
// This can get somewhat expensive, so we don't want to push it every tick in release,
@ -1542,7 +1547,7 @@ void NetworkBase::ServerSendTick()
void NetworkBase::ServerSendPlayerInfo(int32_t playerId)
{
NetworkPacket packet(NetworkCommand::PlayerInfo);
packet << gCurrentTicks;
packet << GetGameState().CurrentTicks;
auto* player = GetPlayerByID(playerId);
if (player == nullptr)
@ -1555,7 +1560,7 @@ void NetworkBase::ServerSendPlayerInfo(int32_t playerId)
void NetworkBase::ServerSendPlayerList()
{
NetworkPacket packet(NetworkCommand::PlayerList);
packet << gCurrentTicks << static_cast<uint8_t>(player_list.size());
packet << GetGameState().CurrentTicks << static_cast<uint8_t>(player_list.size());
for (auto& player : player_list)
{
player->Write(packet);
@ -1849,7 +1854,7 @@ void NetworkBase::ProcessPlayerList()
auto itPending = _pendingPlayerLists.begin();
while (itPending != _pendingPlayerLists.end())
{
if (itPending->first > gCurrentTicks)
if (itPending->first > GetGameState().CurrentTicks)
break;
// List of active players found in the list.
@ -1921,7 +1926,9 @@ void NetworkBase::ProcessPlayerList()
void NetworkBase::ProcessPlayerInfo()
{
auto range = _pendingPlayerInfo.equal_range(gCurrentTicks);
const auto currentTicks = GetGameState().CurrentTicks;
auto range = _pendingPlayerInfo.equal_range(currentTicks);
for (auto it = range.first; it != range.second; it++)
{
auto* player = GetPlayerByID(it->second.Id);
@ -1936,7 +1943,7 @@ void NetworkBase::ProcessPlayerInfo()
player->CommandsRan = networkedInfo.CommandsRan;
}
}
_pendingPlayerInfo.erase(gCurrentTicks);
_pendingPlayerInfo.erase(currentTicks);
}
void NetworkBase::ProcessDisconnectedClients()
@ -2750,7 +2757,7 @@ void NetworkBase::Client_Handle_MAP([[maybe_unused]] NetworkConnection& connecti
GameLoadInit();
GameLoadScripts();
GameNotifyMapChanged();
_serverState.tick = gCurrentTicks;
_serverState.tick = GetGameState().CurrentTicks;
// WindowNetworkStatusOpen("Loaded new map from network");
_serverState.state = NetworkServerStatus::Ok;
_clientMapLoaded = true;
@ -4030,7 +4037,7 @@ NetworkAuth NetworkGetAuthstatus()
}
uint32_t NetworkGetServerTick()
{
return gCurrentTicks;
return GetGameState().CurrentTicks;
}
void NetworkFlush()
{

View File

@ -10,6 +10,7 @@
#include "Painter.h"
#include "../Game.h"
#include "../GameState.h"
#include "../Intro.h"
#include "../OpenRCT2.h"
#include "../ReplayManager.h"
@ -94,7 +95,7 @@ void Painter::PaintReplayNotice(DrawPixelInfo& dpi, const char* text)
auto stringWidth = GfxGetStringWidth(buffer, FontStyle::Medium);
screenCoords.x = screenCoords.x - stringWidth;
if (((gCurrentTicks >> 1) & 0xF) > 4)
if (((GetGameState().CurrentTicks >> 1) & 0xF) > 4)
GfxDrawString(dpi, screenCoords, buffer, { COLOUR_SATURATED_RED });
// Make area dirty so the text doesn't get drawn over the last

View File

@ -10,6 +10,7 @@
#include "../Paint.h"
#include "../../Game.h"
#include "../../GameState.h"
#include "../../config/Config.h"
#include "../../interface/Viewport.h"
#include "../../localisation/Formatter.h"
@ -25,6 +26,8 @@
#include "../../world/TileInspector.h"
#include "Paint.TileElement.h"
using namespace OpenRCT2;
// BannerBoundBoxes[rotation][0] is for the pole in the back
// BannerBoundBoxes[rotation][1] is for the pole and the banner in the front
constexpr CoordsXY BannerBoundBoxes[][2] = {
@ -65,7 +68,7 @@ static void PaintBannerScrollingText(
}
auto stringWidth = GfxGetStringWidth(text, FontStyle::Tiny);
auto scroll = (gCurrentTicks / 2) % stringWidth;
auto scroll = (GetGameState().CurrentTicks / 2) % stringWidth;
auto imageId = ScrollingTextSetup(session, STR_BANNER_TEXT_FORMAT, ft, scroll, scrollingMode, COLOUR_BLACK);
PaintAddImageAsChild(session, imageId, { 0, 0, height + 22 }, { bbOffset, { 1, 1, 21 } });
}

View File

@ -71,7 +71,7 @@ static void PaintRideEntranceExitScrollingText(
FormatStringLegacy(text, sizeof(text), STR_BANNER_TEXT_FORMAT, ft.Data());
}
auto stringWidth = GfxGetStringWidth(text, FontStyle::Tiny);
auto scroll = stringWidth > 0 ? (gCurrentTicks / 2) % stringWidth : 0;
auto scroll = stringWidth > 0 ? (GetGameState().CurrentTicks / 2) % stringWidth : 0;
PaintAddImageAsChild(
session, ScrollingTextSetup(session, STR_BANNER_TEXT_FORMAT, ft, scroll, stationObj.ScrollingMode, COLOUR_BLACK),
@ -244,7 +244,7 @@ static void PaintParkEntranceScrollingText(
}
auto stringWidth = GfxGetStringWidth(text, FontStyle::Tiny);
auto scroll = stringWidth > 0 ? (gCurrentTicks / 2) % stringWidth : 0;
auto scroll = stringWidth > 0 ? (GetGameState().CurrentTicks / 2) % stringWidth : 0;
auto imageIndex = ScrollingTextSetup(
session, STR_BANNER_TEXT_FORMAT, ft, scroll, scrollingMode + direction / 2, COLOUR_BLACK);
auto textHeight = height + entrance.GetTextHeight();

View File

@ -10,6 +10,7 @@
#include "../Paint.h"
#include "../../Game.h"
#include "../../GameState.h"
#include "../../config/Config.h"
#include "../../core/Numerics.hpp"
#include "../../core/String.hpp"
@ -30,6 +31,8 @@
#include "../Supports.h"
#include "Paint.TileElement.h"
using namespace OpenRCT2;
// clang-format off
static constexpr BoundBoxXY LargeSceneryBoundBoxes[] = {
{ { 3, 3 }, { 26, 26 } },
@ -323,7 +326,7 @@ static void PaintLargeSceneryScrollingText(
auto scrollMode = sceneryEntry.scrolling_mode + ((direction + 1) & 3);
auto stringWidth = GfxGetStringWidth(text, FontStyle::Tiny);
auto scroll = stringWidth > 0 ? (gCurrentTicks / 2) % stringWidth : 0;
auto scroll = stringWidth > 0 ? (GetGameState().CurrentTicks / 2) % stringWidth : 0;
auto imageId = ScrollingTextSetup(session, STR_SCROLLING_SIGN_TEXT, ft, scroll, scrollMode, textPaletteIndex);
PaintAddImageAsChild(session, imageId, { 0, 0, height + 25 }, { bbOffset, { 1, 1, 21 } });
}

View File

@ -11,6 +11,7 @@
#include "../../Context.h"
#include "../../Game.h"
#include "../../GameState.h"
#include "../../config/Config.h"
#include "../../core/Numerics.hpp"
#include "../../entity/PatrolArea.h"
@ -330,7 +331,7 @@ static void PathPaintFencesAndQueueBanners(
}
uint16_t stringWidth = GfxGetStringWidth(gCommonStringFormatBuffer, FontStyle::Tiny);
uint16_t scroll = stringWidth > 0 ? (gCurrentTicks / 2) % stringWidth : 0;
uint16_t scroll = stringWidth > 0 ? (GetGameState().CurrentTicks / 2) % stringWidth : 0;
PaintAddImageAsChild(
session, ScrollingTextSetup(session, STR_BANNER_TEXT_FORMAT, ft, scroll, scrollingMode, COLOUR_BLACK),

View File

@ -10,6 +10,7 @@
#include "../Paint.h"
#include "../../Game.h"
#include "../../GameState.h"
#include "../../config/Config.h"
#include "../../interface/Viewport.h"
#include "../../localisation/Date.h"
@ -23,6 +24,8 @@
#include "../Supports.h"
#include "Paint.TileElement.h"
using namespace OpenRCT2;
static constexpr CoordsXY lengths[] = {
{ 12, 26 },
{ 26, 12 },
@ -209,23 +212,25 @@ static void PaintSmallSceneryBody(
if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_ANIMATED))
{
const auto currentTicks = GetGameState().CurrentTicks;
if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_VISIBLE_WHEN_ZOOMED) || (session.DPI.zoom_level <= ZoomLevel{ 1 }))
{
if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_FOUNTAIN_SPRAY_1))
{
auto imageIndex = sceneryEntry->image + 4 + ((gCurrentTicks / 2) & 0xF);
auto imageIndex = sceneryEntry->image + 4 + ((currentTicks / 2) & 0xF);
auto imageId = imageTemplate.WithIndex(imageIndex);
PaintAddImageAsChild(session, imageId, offset, boundBox);
}
else if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_FOUNTAIN_SPRAY_4))
{
auto imageIndex = sceneryEntry->image + 8 + ((gCurrentTicks / 2) & 0xF);
auto imageIndex = sceneryEntry->image + 8 + ((currentTicks / 2) & 0xF);
PaintAddImageAsChild(session, imageTemplate.WithIndex(imageIndex), offset, boundBox);
imageIndex = direction + sceneryEntry->image + 4;
PaintAddImageAsChild(session, imageTemplate.WithIndex(imageIndex), offset, boundBox);
imageIndex = sceneryEntry->image + 24 + ((gCurrentTicks / 2) & 0xF);
imageIndex = sceneryEntry->image + 24 + ((currentTicks / 2) & 0xF);
PaintAddImageAsChild(session, imageTemplate.WithIndex(imageIndex), offset, boundBox);
}
else if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_IS_CLOCK))
@ -260,7 +265,7 @@ static void PaintSmallSceneryBody(
}
else if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_SWAMP_GOO))
{
auto imageIndex = gCurrentTicks;
auto imageIndex = currentTicks;
imageIndex += session.SpritePosition.x / 4;
imageIndex += session.SpritePosition.y / 4;
imageIndex = sceneryEntry->image + ((imageIndex / 4) % 16);
@ -269,7 +274,7 @@ static void PaintSmallSceneryBody(
else if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_HAS_FRAME_OFFSETS))
{
auto delay = sceneryEntry->animation_delay & 0xFF;
auto frame = gCurrentTicks;
auto frame = currentTicks;
if (!(sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_COG)))
{
frame += ((session.SpritePosition.x / 4) + (session.SpritePosition.y / 4));

View File

@ -10,6 +10,7 @@
#include "../Paint.h"
#include "../../Game.h"
#include "../../GameState.h"
#include "../../common.h"
#include "../../config/Config.h"
#include "../../drawing/Drawing.h"
@ -28,6 +29,8 @@
#include "../../world/Wall.h"
#include "Paint.TileElement.h"
using namespace OpenRCT2;
static constexpr uint8_t DirectionToDoorImageOffset0[] = {
2, 2, 22, 26, 30, 34, 34, 34, 34, 34, 30, 26, 22, 2, 6, 2, 2, 2, 6, 10, 14, 18, 18, 18, 18, 18, 14, 10, 6, 2, 22, 2,
};
@ -137,7 +140,7 @@ static void PaintWallWall(
{
PROFILED_FUNCTION();
auto frameNum = (wallEntry.flags2 & WALL_SCENERY_2_ANIMATED) ? (gCurrentTicks & 7) * 2 : 0;
auto frameNum = (wallEntry.flags2 & WALL_SCENERY_2_ANIMATED) ? (GetGameState().CurrentTicks & 7) * 2 : 0;
auto imageIndex = wallEntry.image + imageOffset + frameNum;
PaintAddImageAsParent(session, imageTemplate.WithIndex(imageIndex), offset, boundBox);
if ((wallEntry.flags & WALL_SCENERY_HAS_GLASS) && !isGhost)
@ -184,7 +187,7 @@ static void PaintWallScrollingText(
}
auto stringWidth = GfxGetStringWidth(signString, FontStyle::Tiny);
auto scroll = stringWidth > 0 ? (gCurrentTicks / 2) % stringWidth : 0;
auto scroll = stringWidth > 0 ? (GetGameState().CurrentTicks / 2) % stringWidth : 0;
auto imageId = ScrollingTextSetup(session, STR_SCROLLING_SIGN_TEXT, ft, scroll, scrollingMode, textPaletteIndex);
PaintAddImageAsChild(session, imageId, { 0, 0, height + 8 }, { boundsOffset, { 1, 1, 13 } });
}

View File

@ -480,7 +480,7 @@ namespace OpenRCT2
const uint8_t isPaused = (gGamePaused & GAME_PAUSED_NORMAL);
cs.Write(isPaused);
}
cs.ReadWrite(gCurrentTicks);
cs.ReadWrite(GetGameState().CurrentTicks);
if (cs.GetMode() == OrcaStream::Mode::READING)
{
uint16_t monthTicks;

View File

@ -2121,7 +2121,7 @@ namespace RCT1
void ImportParkFlags()
{
// Date and srand
gCurrentTicks = _s4.Ticks;
GetGameState().CurrentTicks = _s4.Ticks;
ScenarioRandSeed(_s4.RandomA, _s4.RandomB);
GetContext()->GetGameState()->SetDate(Date(_s4.Month, _s4.Day));

View File

@ -77,6 +77,8 @@
#include <algorithm>
using namespace OpenRCT2;
namespace RCT2
{
#define DECRYPT_MONEY(money) (static_cast<money32>(Numerics::rol32((money) ^ 0xF4EC9621, 13)))
@ -250,7 +252,7 @@ namespace RCT2
}
OpenRCT2::GetContext()->GetGameState()->SetDate(OpenRCT2::Date(_s6.ElapsedMonths, _s6.CurrentDay));
gCurrentTicks = _s6.GameTicks1;
GetGameState().CurrentTicks = _s6.GameTicks1;
ScenarioRandSeed(_s6.ScenarioSrand0, _s6.ScenarioSrand1);

View File

@ -13,6 +13,7 @@
#include "../Context.h"
#include "../Editor.h"
#include "../Game.h"
#include "../GameState.h"
#include "../Input.h"
#include "../OpenRCT2.h"
#include "../actions/ResultWithMessage.h"
@ -1128,7 +1129,7 @@ void Ride::Update()
// Breakdown updates originally were performed when (id == (gCurrentTicks / 2) & 0xFF)
// with the increased MAX_RIDES the update is tied to the first byte of the id this allows
// for identical balance with vanilla.
const auto updatingRideByte = static_cast<uint8_t>((gCurrentTicks / 2) & 0xFF);
const auto updatingRideByte = static_cast<uint8_t>((GetGameState().CurrentTicks / 2) & 0xFF);
if (updatingRideByte == static_cast<uint8_t>(id.ToUnderlying()))
RideBreakdownStatusUpdate(*this);
}
@ -1252,7 +1253,7 @@ static constexpr CoordsXY ride_spiral_slide_main_tile_offset[][4] = {
void UpdateSpiralSlide(Ride& ride)
{
if (gCurrentTicks & 3)
if (GetGameState().CurrentTicks & 3)
return;
if (ride.slide_in_use == 0)
return;
@ -1312,7 +1313,7 @@ static uint8_t _breakdownProblemProbabilities[] = {
*/
static void RideInspectionUpdate(Ride& ride)
{
if (gCurrentTicks & 2047)
if (GetGameState().CurrentTicks & 2047)
return;
if (gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER)
return;
@ -1377,7 +1378,8 @@ static int32_t GetAgePenalty(const Ride& ride)
*/
static void RideBreakdownUpdate(Ride& ride)
{
if (gCurrentTicks & 255)
const auto currentTicks = GetGameState().CurrentTicks;
if (currentTicks & 255)
return;
if (gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER)
@ -1386,7 +1388,7 @@ static void RideBreakdownUpdate(Ride& ride)
if (ride.lifecycle_flags & (RIDE_LIFECYCLE_BROKEN_DOWN | RIDE_LIFECYCLE_CRASHED))
ride.downtime_history[0]++;
if (!(gCurrentTicks & 8191))
if (!(currentTicks & 8191))
{
int32_t totalDowntime = 0;
@ -1889,7 +1891,7 @@ static bool RideMusicBreakdownEffect(Ride& ride)
{
if (ride.breakdown_reason_pending == BREAKDOWN_CONTROL_FAILURE)
{
if (!(gCurrentTicks & 7))
if (!(GetGameState().CurrentTicks & 7))
if (ride.breakdown_sound_modifier != 255)
ride.breakdown_sound_modifier++;
}
@ -2029,13 +2031,15 @@ static void RideMeasurementUpdate(Ride& ride, RideMeasurement& measurement)
if (measurement.current_item >= RideMeasurement::MAX_ITEMS)
return;
const auto currentTicks = GetGameState().CurrentTicks;
if (measurement.flags & RIDE_MEASUREMENT_FLAG_G_FORCES)
{
auto gForces = vehicle->GetGForces();
gForces.VerticalG = std::clamp(gForces.VerticalG / 8, -127, 127);
gForces.LateralG = std::clamp(gForces.LateralG / 8, -127, 127);
if (gCurrentTicks & 1)
if (currentTicks & 1)
{
gForces.VerticalG = (gForces.VerticalG + measurement.vertical[measurement.current_item]) / 2;
gForces.LateralG = (gForces.LateralG + measurement.lateral[measurement.current_item]) / 2;
@ -2048,7 +2052,7 @@ static void RideMeasurementUpdate(Ride& ride, RideMeasurement& measurement)
auto velocity = std::min(std::abs((vehicle->velocity * 5) >> 16), 255);
auto altitude = std::min(vehicle->z / 8, 255);
if (gCurrentTicks & 1)
if (currentTicks & 1)
{
velocity = (velocity + measurement.velocity[measurement.current_item]) / 2;
altitude = (altitude + measurement.altitude[measurement.current_item]) / 2;
@ -2057,7 +2061,7 @@ static void RideMeasurementUpdate(Ride& ride, RideMeasurement& measurement)
measurement.velocity[measurement.current_item] = velocity & 0xFF;
measurement.altitude[measurement.current_item] = altitude & 0xFF;
if (gCurrentTicks & 1)
if (currentTicks & 1)
{
measurement.current_item++;
measurement.num_items = std::max(measurement.num_items, measurement.current_item);
@ -2162,7 +2166,7 @@ std::pair<RideMeasurement*, OpenRCT2String> Ride::GetMeasurement()
assert(measurement != nullptr);
}
measurement->last_use_tick = gCurrentTicks;
measurement->last_use_tick = GetGameState().CurrentTicks;
if (measurement->flags & 1)
{
return { measurement.get(), { STR_EMPTY, {} } };

View File

@ -10,6 +10,7 @@
#include "Station.h"
#include "../Game.h"
#include "../GameState.h"
#include "../entity/Guest.h"
#include "../scenario/Scenario.h"
#include "../world/Location.hpp"
@ -17,6 +18,8 @@
#include "Track.h"
#include "Vehicle.h"
using namespace OpenRCT2;
static void RideUpdateStationBlockSection(Ride& ride, StationIndex stationIndex);
static void RideUpdateStationDodgems(Ride& ride, StationIndex stationIndex);
static void RideUpdateStationNormal(Ride& ride, StationIndex stationIndex);
@ -151,10 +154,11 @@ static void RideUpdateStationNormal(Ride& ride, StationIndex stationIndex)
{
auto& station = ride.GetStation(stationIndex);
int32_t time = station.Depart & STATION_DEPART_MASK;
const auto currentTicks = GetGameState().CurrentTicks;
if ((ride.lifecycle_flags & (RIDE_LIFECYCLE_BROKEN_DOWN | RIDE_LIFECYCLE_CRASHED))
|| (ride.status == RideStatus::Closed && ride.num_riders == 0))
{
if (time != 0 && time != 127 && !(gCurrentTicks & 7))
if (time != 0 && time != 127 && !(currentTicks & 7))
time--;
station.Depart = time;
@ -169,7 +173,7 @@ static void RideUpdateStationNormal(Ride& ride, StationIndex stationIndex)
}
else
{
if (time != 127 && !(gCurrentTicks & 31))
if (time != 127 && !(currentTicks & 31))
time--;
station.Depart = time;

View File

@ -10,6 +10,7 @@
#include "TrackPaint.h"
#include "../Game.h"
#include "../GameState.h"
#include "../config/Config.h"
#include "../drawing/Drawing.h"
#include "../drawing/LightFX.h"
@ -29,6 +30,7 @@
#include "TrackData.h"
#include "TrackDesign.h"
using namespace OpenRCT2;
using namespace OpenRCT2::TrackMetaData;
/* rct2: 0x007667AC */
@ -2020,7 +2022,7 @@ void TrackPaintUtilLeftQuarterTurn1TileTunnel(
void TrackPaintUtilSpinningTunnelPaint(PaintSession& session, int8_t thickness, int16_t height, Direction direction)
{
int32_t frame = gCurrentTicks >> 2 & 3;
int32_t frame = (GetGameState().CurrentTicks >> 2) & 3;
auto colourFlags = session.SupportColours;
auto colourFlags2 = session.TrackColours;

View File

@ -12,6 +12,7 @@
#include "../Context.h"
#include "../Editor.h"
#include "../Game.h"
#include "../GameState.h"
#include "../OpenRCT2.h"
#include "../actions/RideSetStatusAction.h"
#include "../audio/AudioChannel.h"
@ -55,6 +56,7 @@
#include <algorithm>
#include <iterator>
using namespace OpenRCT2;
using namespace OpenRCT2::Audio;
using namespace OpenRCT2::TrackMetaData;
using namespace OpenRCT2::Math::Trigonometry;
@ -1069,7 +1071,7 @@ static void UpdateSound(
sound.Pan = sound_params->pan_x;
sound.Channel->SetPan(DStoMixerPan(sound_params->pan_x));
}
if (!(gCurrentTicks & 3) && sound_params->frequency != sound.Frequency)
if (!(GetGameState().CurrentTicks & 3) && sound_params->frequency != sound.Frequency)
{
sound.Frequency = sound_params->frequency;
if (ShouldUpdateChannelRate<type>(id))
@ -4909,7 +4911,7 @@ void Vehicle::UpdateHauntedHouseOperating()
if (Pitch != 0)
{
if (gCurrentTicks & 1)
if (GetGameState().CurrentTicks & 1)
{
Pitch++;
Invalidate();
@ -5422,11 +5424,12 @@ void Vehicle::UpdateSound()
frictionSound.volume = std::min(208 + (ecx & 0xFF), 255);
}
const auto currentTicks = GetGameState().CurrentTicks;
switch (carEntry.sound_range)
{
case SOUND_RANGE_WHISTLE:
screamSound.id = scream_sound_id;
if (!(gCurrentTicks & 0x7F))
if (!(currentTicks & 0x7F))
{
if (velocity < 4.0_mph || scream_sound_id != OpenRCT2::Audio::SoundId::Null)
{
@ -5448,7 +5451,7 @@ void Vehicle::UpdateSound()
case SOUND_RANGE_BELL:
screamSound.id = scream_sound_id;
if (!(gCurrentTicks & 0x7F))
if (!(currentTicks & 0x7F))
{
if (velocity < 4.0_mph || scream_sound_id != OpenRCT2::Audio::SoundId::Null)
{
@ -5724,7 +5727,7 @@ int32_t Vehicle::UpdateMotionDodgems()
if (!(curRide->lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN))
|| curRide->breakdown_reason_pending != BREAKDOWN_SAFETY_CUT_OUT)
{
if (gCurrentTicks & 1 && var_34 != 0)
if ((GetGameState().CurrentTicks & 1) && var_34 != 0)
{
if (var_34 > 0)
{
@ -7669,7 +7672,7 @@ Loc6DAEB9:
{
acceleration = -_vehicleVelocityF64E08 * 16;
}
else if (!(gCurrentTicks & 0x0F))
else if (!(GetGameState().CurrentTicks & 0x0F))
{
if (_vehicleF64E2C == 0)
{

View File

@ -10,6 +10,7 @@
#include "VehiclePaint.h"
#include "../Game.h"
#include "../GameState.h"
#include "../drawing/Drawing.h"
#include "../drawing/LightFX.h"
#include "../entity/EntityRegistry.h"
@ -23,6 +24,7 @@
#include <iterator>
using namespace OpenRCT2;
using namespace OpenRCT2::Entity::Yaw;
#pragma region VehicleBoundboxes
@ -3799,7 +3801,7 @@ static void vehicle_visual_splash1_effect(PaintSession& session, int32_t z, cons
return;
}
int32_t image_id = SPR_SPLASH_EFFECT_1_NE_0 + ((((vehicle->Orientation / 8) + session.CurrentRotation) & 3) * 8)
+ ((gCurrentTicks / 2) & 7);
+ ((GetGameState().CurrentTicks / 2) & 7);
PaintAddImageAsChild(session, ImageId(image_id), { 0, 0, z }, { { 0, 0, z }, { 0, 0, 0 } });
}
@ -3822,7 +3824,7 @@ static void vehicle_visual_splash2_effect(PaintSession& session, int32_t z, cons
return;
}
int32_t image_id = SPR_SPLASH_EFFECT_3_NE_0 + ((((vehicle->Orientation / 8) + session.CurrentRotation) & 3) * 8)
+ ((gCurrentTicks / 2) & 7);
+ ((GetGameState().CurrentTicks / 2) & 7);
PaintAddImageAsChild(session, ImageId(image_id), { 0, 0, z }, { { 0, 0, z }, { 0, 0, 0 } });
}
@ -3845,7 +3847,7 @@ static void vehicle_visual_splash3_effect(PaintSession& session, int32_t z, cons
return;
}
int32_t image_id = SPR_SPLASH_EFFECT_1_NE_0 + ((((vehicle->Orientation / 8) + session.CurrentRotation) & 3) * 8)
+ ((gCurrentTicks / 2) & 7);
+ ((GetGameState().CurrentTicks / 2) & 7);
PaintAddImageAsChild(session, ImageId(image_id), { 0, 0, z }, { { 0, 0, z }, { 0, 0, 0 } });
}
@ -3873,7 +3875,7 @@ static void vehicle_visual_splash4_effect(PaintSession& session, int32_t z, cons
return;
}
int32_t image_id = SPR_SPLASH_EFFECT_5_NE_0 + ((((vehicle->Orientation / 8) + session.CurrentRotation) & 3) * 8)
+ ((gCurrentTicks / 2) & 7);
+ ((GetGameState().CurrentTicks / 2) & 7);
PaintAddImageAsChild(session, ImageId(image_id), { 0, 0, z }, { { 0, 0, z }, { 1, 1, 0 } });
}
@ -3905,7 +3907,7 @@ static void vehicle_visual_splash5_effect(PaintSession& session, int32_t z, cons
return;
}
int32_t image_id = SPR_SPLASH_EFFECT_5_NE_0 + ((((vehicle->Orientation / 8) + session.CurrentRotation) & 3) * 8)
+ ((gCurrentTicks / 2) & 7);
+ ((GetGameState().CurrentTicks / 2) & 7);
PaintAddImageAsChild(session, ImageId(image_id), { 0, 0, z }, { { 0, 0, z }, { 1, 1, 0 } });
}

View File

@ -8,6 +8,7 @@
*****************************************************************************/
#include "../../Game.h"
#include "../../GameState.h"
#include "../../config/Config.h"
#include "../../interface/Viewport.h"
#include "../../paint/Paint.h"
@ -19,6 +20,8 @@
#include "../Vehicle.h"
#include "../VehiclePaint.h"
using namespace OpenRCT2;
#ifndef NO_VEHICLES
// 0x0099279E:
static constexpr VehicleBoundBox _riverRapidsBoundbox[] = {
@ -690,7 +693,7 @@ static void PaintRiverRapidsTrackWaterfall(
{
ImageId imageId;
uint16_t frameNum = (gCurrentTicks / 2) & 7;
uint16_t frameNum = (GetGameState().CurrentTicks / 2) & 7;
if (direction & 1)
{
@ -761,7 +764,7 @@ static void PaintRiverRapidsTrackRapids(
{
ImageId imageId;
uint16_t frameNum = (gCurrentTicks / 2) & 7;
uint16_t frameNum = (GetGameState().CurrentTicks / 2) & 7;
if (direction & 1)
{
@ -813,7 +816,7 @@ static void PaintRiverRapidsTrackWhirlpool(
{
ImageId imageId;
uint8_t frameNum = (gCurrentTicks / 4) % 16;
uint8_t frameNum = (GetGameState().CurrentTicks / 4) % 16;
if (direction & 1)
{

View File

@ -69,7 +69,7 @@ namespace OpenRCT2::Scripting
uint32_t ticksElapsed_get() const
{
return gCurrentTicks;
return GetGameState().CurrentTicks;
}
int32_t day_get() const

View File

@ -12,6 +12,7 @@
#include "../Cheats.h"
#include "../Context.h"
#include "../Game.h"
#include "../GameState.h"
#include "../OpenRCT2.h"
#include "../audio/AudioChannel.h"
#include "../audio/AudioMixer.h"
@ -30,6 +31,7 @@
#include <iterator>
#include <memory>
using namespace OpenRCT2;
using namespace OpenRCT2::Audio;
constexpr int32_t MAX_THUNDER_INSTANCES = 2;
@ -136,7 +138,7 @@ void ClimateUpdate()
}
gClimateUpdateTimer--;
}
else if (!(gCurrentTicks & 0x7F))
else if (!(GetGameState().CurrentTicks & 0x7F))
{
if (gClimateCurrent.Temperature == gClimateNext.Temperature)
{

View File

@ -11,6 +11,7 @@
#include "../Context.h"
#include "../Game.h"
#include "../GameState.h"
#include "../entity/EntityList.h"
#include "../entity/Peep.h"
#include "../interface/Viewport.h"
@ -28,6 +29,8 @@
#include "Map.h"
#include "Scenery.h"
using namespace OpenRCT2;
using map_animation_invalidate_event_handler = bool (*)(const CoordsXYZ& loc);
static std::vector<MapAnimation> _mapAnimations;
@ -192,7 +195,7 @@ static bool MapAnimationInvalidateSmallScenery(const CoordsXYZ& loc)
if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_IS_CLOCK))
{
// Peep, looking at scenery
if (!(gCurrentTicks & 0x3FF) && GameIsNotPaused())
if (!(GetGameState().CurrentTicks & 0x3FF) && GameIsNotPaused())
{
int32_t direction = tileElement->GetDirection();
auto quad = EntityTileList<Peep>(CoordsXY{ loc } - CoordsDirectionDelta[direction]);
@ -480,7 +483,7 @@ static bool MapAnimationInvalidateWallDoor(const CoordsXYZ& loc)
TileCoordsXYZ tileLoc{ loc };
TileElement* tileElement;
if (gCurrentTicks & 1)
if (GetGameState().CurrentTicks & 1)
return false;
bool removeAnimation = true;

View File

@ -313,8 +313,10 @@ void Park::Update(const Date& date)
UpdateHistories();
}
const auto currentTicks = GetGameState().CurrentTicks;
// Every ~13 seconds
if (gCurrentTicks % 512 == 0)
if (currentTicks % 512 == 0)
{
gParkRating = CalculateParkRating();
gParkValue = CalculateParkValue();
@ -329,7 +331,7 @@ void Park::Update(const Date& date)
}
// Every ~102 seconds
if (gCurrentTicks % 4096 == 0)
if (currentTicks % 4096 == 0)
{
gParkSize = CalculateParkSize();
WindowInvalidateByClass(WindowClass::ParkInformation);

View File

@ -123,7 +123,7 @@ static void RecordGameStateSnapshot(std::unique_ptr<IContext>& context, MemorySt
auto& snapshot = snapshots->CreateSnapshot();
snapshots->Capture(snapshot);
snapshots->LinkSnapshot(snapshot, gCurrentTicks, ScenarioRandState().s0);
snapshots->LinkSnapshot(snapshot, GetGameState().CurrentTicks, ScenarioRandState().s0);
DataSerialiser snapShotDs(true, snapshotStream);
snapshots->SerialiseSnapshot(snapshot, snapShotDs);
}