diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp index 991f85ea1..910affa9a 100644 --- a/src/core/core_timing.cpp +++ b/src/core/core_timing.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include #include "common/assert.h" #include "common/logging/log.h" @@ -20,9 +21,15 @@ bool Timing::Event::operator<(const Timing::Event& right) const { } Timing::Timing(std::size_t num_cores, u32 cpu_clock_percentage) { + // Generate non-zero base tick count to simulate time the system ran before launching the game. + // This accounts for games that rely on the system tick to seed randomness. + // Bounded to 32 bits to make sure we don't generate too high of a counter and risk overflowing. + std::mt19937 random_gen(std::random_device{}()); + const u32 base_ticks = random_gen(); + timers.resize(num_cores); for (std::size_t i = 0; i < num_cores; ++i) { - timers[i] = std::make_shared(); + timers[i] = std::make_shared(base_ticks); } UpdateClockSpeed(cpu_clock_percentage); current_timer = timers[0].get(); @@ -146,7 +153,7 @@ std::shared_ptr Timing::GetTimer(std::size_t cpu_id) { return timers[cpu_id]; } -Timing::Timer::Timer() = default; +Timing::Timer::Timer(s64 base_ticks) : executed_ticks(base_ticks) {} Timing::Timer::~Timer() { MoveEvents(); diff --git a/src/core/core_timing.h b/src/core/core_timing.h index 9f9c40027..68ed08dc8 100644 --- a/src/core/core_timing.h +++ b/src/core/core_timing.h @@ -185,7 +185,7 @@ public: class Timer { public: - Timer(); + Timer(s64 base_ticks = 0); ~Timer(); s64 GetMaxSliceLength() const;