diff --git a/src/citra/CMakeLists.txt b/src/citra/CMakeLists.txt index 713f49193..03519bb64 100644 --- a/src/citra/CMakeLists.txt +++ b/src/citra/CMakeLists.txt @@ -14,7 +14,7 @@ set(HEADERS create_directory_groups(${SRCS} ${HEADERS}) add_executable(citra ${SRCS} ${HEADERS}) -target_link_libraries(citra core common video_core) +target_link_libraries(citra core common input_common video_core) target_link_libraries(citra ${GLFW_LIBRARIES} ${OPENGL_gl_LIBRARY} inih) target_link_libraries(citra ${PLATFORM_LIBRARIES}) diff --git a/src/citra_qt/CMakeLists.txt b/src/citra_qt/CMakeLists.txt index efccdbec6..4161ff3eb 100644 --- a/src/citra_qt/CMakeLists.txt +++ b/src/citra_qt/CMakeLists.txt @@ -69,7 +69,7 @@ if (APPLE) else() add_executable(citra-qt ${SRCS} ${HEADERS} ${UI_HDRS}) endif() -target_link_libraries(citra-qt core common video_core qhexedit) +target_link_libraries(citra-qt core common input_common video_core qhexedit) target_link_libraries(citra-qt ${OPENGL_gl_LIBRARY} ${CITRA_QT_LIBS}) target_link_libraries(citra-qt ${PLATFORM_LIBRARIES}) diff --git a/src/core/core.cpp b/src/core/core.cpp index 79038cd52..b6fbf692b 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -5,6 +5,8 @@ #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" @@ -60,6 +62,8 @@ 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/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index 84577e8dd..d0965892b 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt @@ -1,7 +1,11 @@ set(SRCS input_common.cpp) if(SDL2_FOUND) - set(SRCS sdl_input/sdl_input.cpp) + set(SDL_SRCS sdl_input/sdl_input.cpp) endif() -add_library(input_common STATIC ${SRCS}) +add_library(input_common STATIC ${SRCS} ${SDL_SRCS}) + +if(SDL2_FOUND) + target_link_libraries(input_common ${SDL2_LIBRARY}) +endif() diff --git a/src/input_common/input_common.cpp b/src/input_common/input_common.cpp index edbd572bd..57299fc99 100644 --- a/src/input_common/input_common.cpp +++ b/src/input_common/input_common.cpp @@ -3,29 +3,34 @@ // Refer to the license.txt file included. #include "input_common/input_common.h" +#include "input_common/sdl_input/sdl_input.h" namespace InputCommon { -ControllerBase::ControllerBase() { - device_name = "None"; - - //Make sure internal 3DS input is in a neutral state before continuing - for(int x = 0; x < 15; x++) { - controller_state.buttons[x] = false; - } - - controller_state.circle_pad_x = 0; - controller_state.circle_pad_y = 0; - controller_state.touch_screen_x = 0; - controller_state.touch_screen_y = 0; -} +//Set to nullptr until initialized by a backend +ControllerBase* g_user_input = nullptr; std::string ControllerBase::GetDeviceName() const { return device_name; } -//Set to nullptr until initialized by a backend -ControllerBase* g_user_input = nullptr; +void Init(ControllerBackends backend) { + switch(backend) + { + //SDL2 backend selected + case SDL2_JOY: + g_user_input = new SDLController(); + break; + + //No backend selected + case NO_JOY: + break; + + //What? + default: + break; + } +} } // namespace diff --git a/src/input_common/input_common.h b/src/input_common/input_common.h index d13500555..fe4351439 100644 --- a/src/input_common/input_common.h +++ b/src/input_common/input_common.h @@ -9,10 +9,16 @@ namespace InputCommon { +///Enum defining available backends +enum ControllerBackends { + NO_JOY, + SDL2_JOY +}; + class ControllerBase { public: - ControllerBase(); - virtual ~ControllerBase(); + ControllerBase() {} + virtual ~ControllerBase() {} ///Initializes input based on specific backends virtual bool Init() = 0; @@ -29,18 +35,17 @@ public: ///Returns internal name of currently selected device. Expose this to the UI std::string GetDeviceName() const; -private: - - ///Internal view this specific object will have of 3DS input states - ControllerState controller_state; - +protected: ///Internal name of currently selected device std::string device_name; }; +///Initialize the user input system +void Init(ControllerBackends backend); ///InputCommon 'plugin' extern ControllerBase* g_user_input; + } // namespace diff --git a/src/input_common/sdl_input/sdl_input.cpp b/src/input_common/sdl_input/sdl_input.cpp index 7ca83be09..53d941d36 100644 --- a/src/input_common/sdl_input/sdl_input.cpp +++ b/src/input_common/sdl_input/sdl_input.cpp @@ -7,9 +7,14 @@ namespace InputCommon { SDLController::SDLController() { - name = "SDL2::NONE"; + device_name = "SDL2::NONE"; j_pad = nullptr; index = 0; + + controller_state.circle_pad_x = 0; + controller_state.circle_pad_y = 0; + controller_state.touch_screen_x = 0; + controller_state.touch_screen_y = 0; } SDLController::~SDLController() { @@ -39,6 +44,9 @@ void SDLController::ShutDown() { if(j_pad != nullptr) { SDL_JoystickClose(j_pad); } + + //Delete the current user input plugin + delete g_user_input; } void SDLController::Poll() {} diff --git a/src/input_common/sdl_input/sdl_input.h b/src/input_common/sdl_input/sdl_input.h index d91fd9bd5..4ffb67c3b 100644 --- a/src/input_common/sdl_input/sdl_input.h +++ b/src/input_common/sdl_input/sdl_input.h @@ -31,11 +31,14 @@ public: SDL_Event input_event; private: - std::string name; SDL_Joystick* j_pad; ///Index of joystick, used for opening/closing a joystick int index; + + ///Internal view this specific object will have of 3DS input states + ControllerState controller_state; + }; } //namespace