Rework input common to compile with CMake + go into Core

This commit is contained in:
Daniel Stuart Baxter 2015-05-25 00:56:45 -05:00
parent 2547423835
commit 9dcbb07840
8 changed files with 57 additions and 28 deletions

View file

@ -14,7 +14,7 @@ set(HEADERS
create_directory_groups(${SRCS} ${HEADERS}) create_directory_groups(${SRCS} ${HEADERS})
add_executable(citra ${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 ${GLFW_LIBRARIES} ${OPENGL_gl_LIBRARY} inih)
target_link_libraries(citra ${PLATFORM_LIBRARIES}) target_link_libraries(citra ${PLATFORM_LIBRARIES})

View file

@ -69,7 +69,7 @@ if (APPLE)
else() else()
add_executable(citra-qt ${SRCS} ${HEADERS} ${UI_HDRS}) add_executable(citra-qt ${SRCS} ${HEADERS} ${UI_HDRS})
endif() 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 ${OPENGL_gl_LIBRARY} ${CITRA_QT_LIBS})
target_link_libraries(citra-qt ${PLATFORM_LIBRARIES}) target_link_libraries(citra-qt ${PLATFORM_LIBRARIES})

View file

@ -5,6 +5,8 @@
#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"
@ -60,6 +62,8 @@ 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

@ -1,7 +1,11 @@
set(SRCS input_common.cpp) set(SRCS input_common.cpp)
if(SDL2_FOUND) if(SDL2_FOUND)
set(SRCS sdl_input/sdl_input.cpp) set(SDL_SRCS sdl_input/sdl_input.cpp)
endif() 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()

View file

@ -3,29 +3,34 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "input_common/input_common.h" #include "input_common/input_common.h"
#include "input_common/sdl_input/sdl_input.h"
namespace InputCommon { namespace InputCommon {
ControllerBase::ControllerBase() { //Set to nullptr until initialized by a backend
device_name = "None"; ControllerBase* g_user_input = nullptr;
//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;
}
std::string ControllerBase::GetDeviceName() const { std::string ControllerBase::GetDeviceName() const {
return device_name; return device_name;
} }
//Set to nullptr until initialized by a backend void Init(ControllerBackends backend) {
ControllerBase* g_user_input = nullptr; 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 } // namespace

View file

@ -9,10 +9,16 @@
namespace InputCommon { namespace InputCommon {
///Enum defining available backends
enum ControllerBackends {
NO_JOY,
SDL2_JOY
};
class ControllerBase { class ControllerBase {
public: public:
ControllerBase(); ControllerBase() {}
virtual ~ControllerBase(); virtual ~ControllerBase() {}
///Initializes input based on specific backends ///Initializes input based on specific backends
virtual bool Init() = 0; virtual bool Init() = 0;
@ -29,18 +35,17 @@ public:
///Returns internal name of currently selected device. Expose this to the UI ///Returns internal name of currently selected device. Expose this to the UI
std::string GetDeviceName() const; std::string GetDeviceName() const;
private: protected:
///Internal view this specific object will have of 3DS input states
ControllerState controller_state;
///Internal name of currently selected device ///Internal name of currently selected device
std::string device_name; std::string device_name;
}; };
///Initialize the user input system
void Init(ControllerBackends backend);
///InputCommon 'plugin' ///InputCommon 'plugin'
extern ControllerBase* g_user_input; extern ControllerBase* g_user_input;
} // namespace } // namespace

View file

@ -7,9 +7,14 @@
namespace InputCommon { namespace InputCommon {
SDLController::SDLController() { SDLController::SDLController() {
name = "SDL2::NONE"; device_name = "SDL2::NONE";
j_pad = nullptr; j_pad = nullptr;
index = 0; 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() { SDLController::~SDLController() {
@ -39,6 +44,9 @@ void SDLController::ShutDown() {
if(j_pad != nullptr) { if(j_pad != nullptr) {
SDL_JoystickClose(j_pad); SDL_JoystickClose(j_pad);
} }
//Delete the current user input plugin
delete g_user_input;
} }
void SDLController::Poll() {} void SDLController::Poll() {}

View file

@ -31,11 +31,14 @@ public:
SDL_Event input_event; SDL_Event input_event;
private: private:
std::string name;
SDL_Joystick* j_pad; SDL_Joystick* j_pad;
///Index of joystick, used for opening/closing a joystick ///Index of joystick, used for opening/closing a joystick
int index; int index;
///Internal view this specific object will have of 3DS input states
ControllerState controller_state;
}; };
} //namespace } //namespace