Use CoreTiming for input polling, sync to vblank

This commit is contained in:
Daniel Stuart Baxter 2015-05-26 00:43:22 -05:00
parent 9dcbb07840
commit 614da6bc17
3 changed files with 31 additions and 4 deletions

View file

@ -5,8 +5,6 @@
#include "common/common_types.h" #include "common/common_types.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "input_common/input_common.h"
#include "core/core.h" #include "core/core.h"
#include "core/core_timing.h" #include "core/core_timing.h"
@ -62,8 +60,6 @@ int Init() {
g_sys_core = new ARM_DynCom(USER32MODE); g_sys_core = new ARM_DynCom(USER32MODE);
g_app_core = new ARM_DynCom(USER32MODE); g_app_core = new ARM_DynCom(USER32MODE);
InputCommon::Init(InputCommon::SDL2_JOY);
LOG_DEBUG(Core, "Initialized OK"); LOG_DEBUG(Core, "Initialized OK");
return 0; return 0;
} }

View file

@ -12,6 +12,8 @@
#include "video_core/video_core.h" #include "video_core/video_core.h"
#include "input_common/input_common.h"
namespace System { namespace System {
void Init(EmuWindow* emu_window) { void Init(EmuWindow* emu_window) {
@ -22,9 +24,11 @@ void Init(EmuWindow* emu_window) {
Kernel::Init(); Kernel::Init();
HLE::Init(); HLE::Init();
VideoCore::Init(emu_window); VideoCore::Init(emu_window);
InputCommon::Init(InputCommon::SDL2_JOY);
} }
void Shutdown() { void Shutdown() {
//InputCommon::Shutdown();
VideoCore::Shutdown(); VideoCore::Shutdown();
HLE::Shutdown(); HLE::Shutdown();
Kernel::Shutdown(); Kernel::Shutdown();

View file

@ -5,11 +5,32 @@
#include "input_common/input_common.h" #include "input_common/input_common.h"
#include "input_common/sdl_input/sdl_input.h" #include "input_common/sdl_input/sdl_input.h"
#include "core/core_timing.h"
#include "core/settings.h"
namespace InputCommon { namespace InputCommon {
//Set to nullptr until initialized by a backend //Set to nullptr until initialized by a backend
ControllerBase* g_user_input = nullptr; 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 { std::string ControllerBase::GetDeviceName() const {
return device_name; return device_name;
} }
@ -30,6 +51,12 @@ void Init(ControllerBackends backend) {
default: default:
break; 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 } // namespace