From 09ac66388c01187ed6a402efcad76984c8af9a2e Mon Sep 17 00:00:00 2001 From: James Rowe Date: Thu, 20 Sep 2018 00:28:05 -0600 Subject: 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 --- src/input_common/main.cpp | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) (limited to 'src/input_common/main.cpp') diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index 37f572853..8e66c1b15 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp @@ -17,10 +17,7 @@ namespace InputCommon { static std::shared_ptr keyboard; static std::shared_ptr motion_emu; - -#ifdef HAVE_SDL2 -static std::thread poll_thread; -#endif +static std::unique_ptr sdl; void Init() { keyboard = std::make_shared(); @@ -30,15 +27,7 @@ void Init() { motion_emu = std::make_shared(); Input::RegisterFactory("motion_emu", motion_emu); -#ifdef HAVE_SDL2 - SDL::Init(); -#endif -} - -void StartJoystickEventHandler() { -#ifdef HAVE_SDL2 - poll_thread = std::thread(SDL::PollLoop); -#endif + sdl = SDL::Init(); } void Shutdown() { @@ -47,11 +36,7 @@ void Shutdown() { Input::UnregisterFactory("analog_from_button"); Input::UnregisterFactory("motion_emu"); motion_emu.reset(); - -#ifdef HAVE_SDL2 - SDL::Shutdown(); - poll_thread.join(); -#endif + sdl.reset(); } Keyboard* GetKeyboard() { @@ -88,7 +73,7 @@ namespace Polling { std::vector> GetPollers(DeviceType type) { #ifdef HAVE_SDL2 - return SDL::Polling::GetPollers(type); + return sdl->GetPollers(type); #else return {}; #endif -- cgit v1.2.3