1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-25 12:12:50 +01:00

Offset get_timebased_time at game boot (#10744)

- Avoids game bugs in the case where games convert the value read from the clock to a float before performing delta time calculations
This commit is contained in:
Whatcookie 2021-08-23 08:06:02 -04:00 committed by GitHub
parent 92749f011e
commit d0451932bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 2 deletions

View File

@ -6,6 +6,8 @@
#include "util/asm.hpp"
u64 timebase_offset;
#ifdef _WIN32
#include <Windows.h>
@ -141,15 +143,22 @@ u64 get_timebased_time()
const u64 time = count.QuadPart;
const u64 freq = s_time_aux_info.perf_freq;
return (time / freq * g_timebase_freq + time % freq * g_timebase_freq / freq) * g_cfg.core.clocks_scale / 100u;
return ((time / freq * g_timebase_freq + time % freq * g_timebase_freq / freq) * g_cfg.core.clocks_scale / 100u) - timebase_offset;
#else
struct timespec ts;
ensure(::clock_gettime(CLOCK_MONOTONIC, &ts) == 0);
return (static_cast<u64>(ts.tv_sec) * g_timebase_freq + static_cast<u64>(ts.tv_nsec) * g_timebase_freq / 1000000000ull) * g_cfg.core.clocks_scale / 100u;
return ((static_cast<u64>(ts.tv_sec) * g_timebase_freq + static_cast<u64>(ts.tv_nsec) * g_timebase_freq / 1000000000ull) * g_cfg.core.clocks_scale / 100u) - timebase_offset;
#endif
}
// Add an offset to get_timebased_time to avoid leaking PC's uptime into the game
void initalize_timebased_time()
{
timebase_offset = 0;
timebase_offset = get_timebased_time();
}
// Returns some relative time in microseconds, don't change this fact
u64 get_system_time()
{

View File

@ -3,5 +3,6 @@
#include "util/types.hpp"
u64 get_timebased_time();
void initalize_timebased_time();
u64 get_system_time();
u64 get_guest_system_time();

View File

@ -642,6 +642,8 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
}
}
initalize_timebased_time();
// Set RTM usage
g_use_rtm = utils::has_rtm() && ((utils::has_mpx() && g_cfg.core.enable_TSX == tsx_usage::enabled) || g_cfg.core.enable_TSX == tsx_usage::forced);