From 614da6bc178eade3d1a4d62d188bf8c38584c551 Mon Sep 17 00:00:00 2001 From: Daniel Stuart Baxter Date: Tue, 26 May 2015 00:43:22 -0500 Subject: [PATCH] Use CoreTiming for input polling, sync to vblank --- src/core/core.cpp | 4 ---- src/core/system.cpp | 4 ++++ src/input_common/input_common.cpp | 27 +++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/core/core.cpp b/src/core/core.cpp index b6fbf692b..79038cd52 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -5,8 +5,6 @@ #include "common/common_types.h" #include "common/logging/log.h" -#include "input_common/input_common.h" - #include "core/core.h" #include "core/core_timing.h" @@ -62,8 +60,6 @@ int Init() { g_sys_core = new ARM_DynCom(USER32MODE); g_app_core = new ARM_DynCom(USER32MODE); - InputCommon::Init(InputCommon::SDL2_JOY); - LOG_DEBUG(Core, "Initialized OK"); return 0; } diff --git a/src/core/system.cpp b/src/core/system.cpp index 561ff82f0..8a075bfe9 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -12,6 +12,8 @@ #include "video_core/video_core.h" +#include "input_common/input_common.h" + namespace System { void Init(EmuWindow* emu_window) { @@ -22,9 +24,11 @@ void Init(EmuWindow* emu_window) { Kernel::Init(); HLE::Init(); VideoCore::Init(emu_window); + InputCommon::Init(InputCommon::SDL2_JOY); } void Shutdown() { + //InputCommon::Shutdown(); VideoCore::Shutdown(); HLE::Shutdown(); Kernel::Shutdown(); diff --git a/src/input_common/input_common.cpp b/src/input_common/input_common.cpp index 57299fc99..00edfc949 100644 --- a/src/input_common/input_common.cpp +++ b/src/input_common/input_common.cpp @@ -5,11 +5,32 @@ #include "input_common/input_common.h" #include "input_common/sdl_input/sdl_input.h" +#include "core/core_timing.h" +#include "core/settings.h" + namespace InputCommon { //Set to nullptr until initialized by a backend ControllerBase* g_user_input = nullptr; +//Event id for CoreTiming +static int input_event; + +//Ticks for CoreTiming event, same as VBlank in GPU +static u64 frame_ticks; + +///Callback for CoreTiming +static void InputCallback(u64 userdata, int cycles_late) { + + //Call user input plugin Poll() + if(g_user_input != nullptr) { + g_user_input->Poll(); + } + + // Reschedule recurrent event + CoreTiming::ScheduleEvent(frame_ticks - cycles_late, input_event); +} + std::string ControllerBase::GetDeviceName() const { return device_name; } @@ -30,6 +51,12 @@ void Init(ControllerBackends backend) { default: break; } + + //Setup CoreTiming + frame_ticks = 268123480 / Settings::values.gpu_refresh_rate; + + input_event = CoreTiming::RegisterEvent("InputCommon::InputCallback", InputCallback); + CoreTiming::ScheduleEvent(frame_ticks, input_event); } } // namespace