Input: Remove global variables from SDL Input

Changes the interface as well to remove any unique methods that
frontends needed to call such as StartJoystickEventHandler by
conditionally starting the polling thread only if the frontend hasn't
started it already. Additionally, moves all global state into a single
SDLState class in order to guarantee that the destructors are called in
the proper order
This commit is contained in:
James Rowe 2018-09-20 00:28:05 -06:00
parent bfcc712132
commit 3f4a7f8f58
9 changed files with 213 additions and 810 deletions

View file

@ -19,10 +19,7 @@ namespace InputCommon {
static std::shared_ptr<Keyboard> keyboard;
static std::shared_ptr<MotionEmu> motion_emu;
static std::unique_ptr<CemuhookUDP::State> udp;
#ifdef HAVE_SDL2
static std::thread poll_thread;
#endif
static std::unique_ptr<SDL::State> sdl;
void Init() {
keyboard = std::make_shared<Keyboard>();
@ -32,30 +29,19 @@ void Init() {
motion_emu = std::make_shared<MotionEmu>();
Input::RegisterFactory<Input::MotionDevice>("motion_emu", motion_emu);
#ifdef HAVE_SDL2
SDL::Init();
#endif
sdl = SDL::Init();
udp = CemuhookUDP::Init();
}
void StartJoystickEventHandler() {
#ifdef HAVE_SDL2
poll_thread = std::thread(SDL::PollLoop);
#endif
}
void Shutdown() {
Input::UnregisterFactory<Input::ButtonDevice>("keyboard");
keyboard.reset();
Input::UnregisterFactory<Input::AnalogDevice>("analog_from_button");
Input::UnregisterFactory<Input::MotionDevice>("motion_emu");
motion_emu.reset();
#ifdef HAVE_SDL2
SDL::Shutdown();
poll_thread.join();
#endif
sdl.reset();
udp.reset();
}
Keyboard* GetKeyboard() {
@ -99,7 +85,7 @@ std::vector<std::unique_ptr<DevicePoller>> GetPollers(DeviceType type) {
std::vector<std::unique_ptr<DevicePoller>> pollers;
#ifdef HAVE_SDL2
SDL::Polling::GetPollers(type, pollers);
sdl->GetPollers(type, pollers);
#endif
return pollers;