CoreTiming: Fix 31bit overflow for events scheduling.
Events scheduled more than 4.12 seconds in the future (2.96 seconds for Wii games) would overflow the sign bit and get scheduled in the past instead, causing them to fire instantly.
This commit is contained in:
parent
2ebbfd6f85
commit
67dc26cf1d
|
@ -232,7 +232,7 @@ u64 GetIdleTicks()
|
|||
|
||||
// This is to be called when outside threads, such as the graphics thread, wants to
|
||||
// schedule things to be executed on the main thread.
|
||||
void ScheduleEvent_Threadsafe(int cyclesIntoFuture, int event_type, u64 userdata)
|
||||
void ScheduleEvent_Threadsafe(s64 cyclesIntoFuture, int event_type, u64 userdata)
|
||||
{
|
||||
_assert_msg_(POWERPC, !Core::IsCPUThread(), "ScheduleEvent_Threadsafe from wrong thread");
|
||||
if (Core::g_want_determinism)
|
||||
|
@ -271,7 +271,7 @@ void ScheduleEvent_Threadsafe_Immediate(int event_type, u64 userdata)
|
|||
}
|
||||
|
||||
// To be used from any thread, including the CPU thread
|
||||
void ScheduleEvent_AnyThread(int cyclesIntoFuture, int event_type, u64 userdata)
|
||||
void ScheduleEvent_AnyThread(s64 cyclesIntoFuture, int event_type, u64 userdata)
|
||||
{
|
||||
if (Core::IsCPUThread())
|
||||
ScheduleEvent(cyclesIntoFuture, event_type, userdata);
|
||||
|
@ -310,7 +310,7 @@ static void AddEventToQueue(Event* ne)
|
|||
// This must be run ONLY from within the CPU thread
|
||||
// cyclesIntoFuture may be VERY inaccurate if called from anything else
|
||||
// than Advance
|
||||
void ScheduleEvent(int cyclesIntoFuture, int event_type, u64 userdata)
|
||||
void ScheduleEvent(s64 cyclesIntoFuture, int event_type, u64 userdata)
|
||||
{
|
||||
_assert_msg_(POWERPC, Core::IsCPUThread() || Core::GetState() == Core::CORE_PAUSE,
|
||||
"ScheduleEvent from wrong thread");
|
||||
|
@ -363,12 +363,13 @@ void RemoveAllEvents(int event_type)
|
|||
RemoveEvent(event_type);
|
||||
}
|
||||
|
||||
void ForceExceptionCheck(int cycles)
|
||||
void ForceExceptionCheck(s64 cycles)
|
||||
{
|
||||
if (DowncountToCycles(PowerPC::ppcState.downcount) > cycles)
|
||||
if (s64(DowncountToCycles(PowerPC::ppcState.downcount)) > cycles)
|
||||
{
|
||||
slicelength -= (DowncountToCycles(PowerPC::ppcState.downcount) - cycles); // Account for cycles already executed by adjusting the slicelength
|
||||
PowerPC::ppcState.downcount = CyclesToDowncount(cycles);
|
||||
// downcount is always (much) smaller than MAX_INT so we can safely cast cycles to an int here.
|
||||
slicelength -= (DowncountToCycles(PowerPC::ppcState.downcount) - (int)cycles); // Account for cycles already executed by adjusting the g_slicelength
|
||||
PowerPC::ppcState.downcount = CyclesToDowncount((int)cycles);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,11 +45,11 @@ int RegisterEvent(const std::string& name, TimedCallback callback);
|
|||
void UnregisterAllEvents();
|
||||
|
||||
// userdata MAY NOT CONTAIN POINTERS. userdata might get written and reloaded from savestates.
|
||||
void ScheduleEvent(int cyclesIntoFuture, int event_type, u64 userdata = 0);
|
||||
void ScheduleEvent(s64 cyclesIntoFuture, int event_type, u64 userdata = 0);
|
||||
void ScheduleEvent_Immediate(int event_type, u64 userdata = 0);
|
||||
void ScheduleEvent_Threadsafe(int cyclesIntoFuture, int event_type, u64 userdata = 0);
|
||||
void ScheduleEvent_Threadsafe(s64 cyclesIntoFuture, int event_type, u64 userdata = 0);
|
||||
void ScheduleEvent_Threadsafe_Immediate(int event_type, u64 userdata = 0);
|
||||
void ScheduleEvent_AnyThread(int cyclesIntoFuture, int event_type, u64 userdata = 0);
|
||||
void ScheduleEvent_AnyThread(s64 cyclesIntoFuture, int event_type, u64 userdata = 0);
|
||||
|
||||
// We only permit one event of each type in the queue at a time.
|
||||
void RemoveEvent(int event_type);
|
||||
|
@ -77,7 +77,7 @@ void SetFakeTBStartValue(u64 val);
|
|||
u64 GetFakeTBStartTicks();
|
||||
void SetFakeTBStartTicks(u64 val);
|
||||
|
||||
void ForceExceptionCheck(int cycles);
|
||||
void ForceExceptionCheck(s64 cycles);
|
||||
|
||||
extern int slicelength;
|
||||
extern float lastOCFactor;
|
||||
|
|
Loading…
Reference in New Issue