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})
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})

View file

@ -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})

View file

@ -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;
}

View file

@ -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()

View file

@ -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

View file

@ -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

View file

@ -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() {}

View file

@ -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