From 854f6b8688063544310edbc0fc27a8c42f517d9b Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 15 Nov 2014 01:47:29 -0800 Subject: [PATCH] HW: Poll system input from system timers Rather than playing terrible hacks to determine the start of input frames, just update system input periodically. Specifically, every 60th of a second. --- Source/Core/Core/HW/GCPad.cpp | 9 --------- Source/Core/Core/HW/SystemTimers.cpp | 14 ++++++++++++++ Source/Core/Core/HW/Wiimote.cpp | 8 -------- Source/Core/Core/State.cpp | 2 +- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/Source/Core/Core/HW/GCPad.cpp b/Source/Core/Core/HW/GCPad.cpp index b765ff67e1..1c61e3dd7f 100644 --- a/Source/Core/Core/HW/GCPad.cpp +++ b/Source/Core/Core/HW/GCPad.cpp @@ -64,15 +64,6 @@ void GetStatus(u8 _numPAD, GCPadStatus* _pPADStatus) return; } - // if we are on the next input cycle, update output and input - // if we can get a lock - static int _last_numPAD = 4; - if (_numPAD <= _last_numPAD) - { - g_controller_interface.UpdateInput(); - } - _last_numPAD = _numPAD; - // get input ((GCPad*)s_config.controllers[_numPAD])->GetInput(_pPADStatus); } diff --git a/Source/Core/Core/HW/SystemTimers.cpp b/Source/Core/Core/HW/SystemTimers.cpp index 3f79f2e39a..c907d3f1a1 100644 --- a/Source/Core/Core/HW/SystemTimers.cpp +++ b/Source/Core/Core/HW/SystemTimers.cpp @@ -61,6 +61,8 @@ IPC_HLE_PERIOD: For the Wiimote this is the call schedule: #include "Core/IPC_HLE/WII_IPC_HLE.h" #include "Core/PowerPC/PowerPC.h" +#include "InputCommon/ControllerInterface/ControllerInterface.h" + #include "VideoCommon/CommandProcessor.h" #include "VideoCommon/VideoBackendBase.h" @@ -79,6 +81,7 @@ static int et_DSP; static int et_IPC_HLE; static int et_PatchEngine; // PatchEngine updates every 1/60th of a second by default static int et_Throttle; +static int et_UpdateInput; // These are badly educated guesses // Feel free to experiment. Set these in Init below. @@ -132,6 +135,14 @@ static void VICallback(u64 userdata, int cyclesLate) CoreTiming::ScheduleEvent(VideoInterface::GetTicksPerLine() - cyclesLate, et_VI); } +static void UpdateInputCallback(u64 userdata, int cyclesLate) +{ + g_controller_interface.UpdateInput(); + + // Poll system input every 1/60th of a second. + CoreTiming::ScheduleEvent(SystemTimers::GetTicksPerSecond() / 60 - cyclesLate, et_UpdateInput); +} + static void SICallback(u64 userdata, int cyclesLate) { SerialInterface::UpdateDevices(); @@ -258,6 +269,7 @@ void Init() et_IPC_HLE = CoreTiming::RegisterEvent("IPC_HLE_UpdateCallback", IPC_HLE_UpdateCallback); et_PatchEngine = CoreTiming::RegisterEvent("PatchEngine", PatchEngineCallback); et_Throttle = CoreTiming::RegisterEvent("Throttle", ThrottleCallback); + et_UpdateInput = CoreTiming::RegisterEvent("UpdateInput", UpdateInputCallback); CoreTiming::ScheduleEvent(VideoInterface::GetTicksPerLine(), et_VI); CoreTiming::ScheduleEvent(0, et_DSP); @@ -271,6 +283,8 @@ void Init() if (SConfig::GetInstance().m_LocalCoreStartupParameter.bWii) CoreTiming::ScheduleEvent(IPC_HLE_PERIOD, et_IPC_HLE); + + CoreTiming::ScheduleEvent(0, et_UpdateInput); } void Shutdown() diff --git a/Source/Core/Core/HW/Wiimote.cpp b/Source/Core/Core/HW/Wiimote.cpp index 74ecaef1e7..14ab7dfeb1 100644 --- a/Source/Core/Core/HW/Wiimote.cpp +++ b/Source/Core/Core/HW/Wiimote.cpp @@ -17,7 +17,6 @@ namespace Wiimote { static InputConfig s_config(WIIMOTE_INI_NAME, _trans("Wiimote"), "Wiimote"); -static int s_last_number = 4; InputConfig* GetConfig() { @@ -115,12 +114,6 @@ void Update(int _number) // TODO: change this to a try_to_lock, and make it give empty input on failure std::lock_guard lk(s_config.controls_lock); - if (_number <= s_last_number) - { - g_controller_interface.UpdateInput(); - } - s_last_number = _number; - if (WIIMOTE_SRC_EMU & g_wiimote_sources[_number]) ((WiimoteEmu::Wiimote*)s_config.controllers[_number])->Update(); else @@ -153,7 +146,6 @@ void DoState(u8 **ptr, PointerWrap::Mode mode) // TODO: PointerWrap p(ptr, mode); - p.Do(s_last_number); for (unsigned int i=0; iDoState(p); } diff --git a/Source/Core/Core/State.cpp b/Source/Core/Core/State.cpp index c8d3db9d7c..d156bb4adc 100644 --- a/Source/Core/Core/State.cpp +++ b/Source/Core/Core/State.cpp @@ -64,7 +64,7 @@ static Common::Event g_compressAndDumpStateSyncEvent; static std::thread g_save_thread; // Don't forget to increase this after doing changes on the savestate system -static const u32 STATE_VERSION = 36; +static const u32 STATE_VERSION = 37; enum {