Rename stuff, generate basic pad IDs for SDL input
This commit is contained in:
parent
614da6bc17
commit
0d6c90a1ea
5 changed files with 72 additions and 16 deletions
|
@ -10,7 +10,7 @@
|
||||||
namespace InputCommon {
|
namespace InputCommon {
|
||||||
|
|
||||||
struct ControllerState {
|
struct ControllerState {
|
||||||
Service::HID::PadState jpad_state;
|
Service::HID::PadState pad_state;
|
||||||
s16 circle_pad_x;
|
s16 circle_pad_x;
|
||||||
s16 circle_pad_y;
|
s16 circle_pad_y;
|
||||||
u16 touch_screen_x;
|
u16 touch_screen_x;
|
||||||
|
|
|
@ -35,6 +35,11 @@ std::string ControllerBase::GetDeviceName() const {
|
||||||
return device_name;
|
return device_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const Service::HID::PadState ControllerBase::GetPadState() const {
|
||||||
|
return controller.pad_state;
|
||||||
|
}
|
||||||
|
|
||||||
void Init(ControllerBackends backend) {
|
void Init(ControllerBackends backend) {
|
||||||
switch(backend)
|
switch(backend)
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,9 +35,15 @@ 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;
|
||||||
|
|
||||||
|
///Returns internal pad state
|
||||||
|
const Service::HID::PadState GetPadState() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
///Internal name of currently selected device
|
///Internal name of currently selected device
|
||||||
std::string device_name;
|
std::string device_name;
|
||||||
|
|
||||||
|
///Internal view this specific object will have of 3DS input states
|
||||||
|
ControllerState controller;
|
||||||
};
|
};
|
||||||
|
|
||||||
///Initialize the user input system
|
///Initialize the user input system
|
||||||
|
|
|
@ -8,13 +8,15 @@ namespace InputCommon {
|
||||||
|
|
||||||
SDLController::SDLController() {
|
SDLController::SDLController() {
|
||||||
device_name = "SDL2::NONE";
|
device_name = "SDL2::NONE";
|
||||||
j_pad = nullptr;
|
jpad = nullptr;
|
||||||
index = 0;
|
index = 0;
|
||||||
|
|
||||||
controller_state.circle_pad_x = 0;
|
controller.circle_pad_x = 0;
|
||||||
controller_state.circle_pad_y = 0;
|
controller.circle_pad_y = 0;
|
||||||
controller_state.touch_screen_x = 0;
|
controller.touch_screen_x = 0;
|
||||||
controller_state.touch_screen_y = 0;
|
controller.touch_screen_y = 0;
|
||||||
|
|
||||||
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
SDLController::~SDLController() {
|
SDLController::~SDLController() {
|
||||||
|
@ -30,9 +32,10 @@ bool SDLController::Init() {
|
||||||
|
|
||||||
//Attempt to open joystick with SDL
|
//Attempt to open joystick with SDL
|
||||||
//TODO - Use DiscoverDevice to generate a list of available joysticks, then open the correct index
|
//TODO - Use DiscoverDevice to generate a list of available joysticks, then open the correct index
|
||||||
j_pad = SDL_JoystickOpen(index);
|
jpad = SDL_JoystickOpen(index);
|
||||||
|
|
||||||
if(j_pad == nullptr) {
|
if(jpad == nullptr) {
|
||||||
|
std::cout<<"What\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,14 +44,57 @@ void SDLController::DiscoverDevices() {}
|
||||||
|
|
||||||
void SDLController::ShutDown() {
|
void SDLController::ShutDown() {
|
||||||
//Attempt to close joystick with SDL
|
//Attempt to close joystick with SDL
|
||||||
if(j_pad != nullptr) {
|
if(jpad != nullptr) {
|
||||||
SDL_JoystickClose(j_pad);
|
SDL_JoystickClose(jpad);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Delete the current user input plugin
|
//Delete the current user input plugin
|
||||||
delete g_user_input;
|
delete g_user_input;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLController::Poll() {}
|
void SDLController::Poll() {
|
||||||
|
if(SDL_PollEvent(&input_event)) {
|
||||||
|
if((input_event.type == SDL_JOYBUTTONDOWN) || (input_event.type == SDL_JOYBUTTONUP)
|
||||||
|
|| (input_event.type == SDL_JOYAXISMOTION) || (input_event.type == SDL_JOYHATMOTION)) {
|
||||||
|
ProcessInput();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SDLController::ProcessInput() {
|
||||||
|
//Use a unique id for joystick input
|
||||||
|
int pad_id = 0;
|
||||||
|
int val = 0;
|
||||||
|
|
||||||
|
//Pressed state, for joystick buttons only
|
||||||
|
bool pressed = false;
|
||||||
|
|
||||||
|
//Generate the id based on input from an event
|
||||||
|
switch(input_event.type) {
|
||||||
|
//Joystick button press events
|
||||||
|
case SDL_JOYBUTTONDOWN:
|
||||||
|
pad_id = 100;
|
||||||
|
pad_id += input_event.jbutton.button;
|
||||||
|
pressed = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
//Joystick button release events
|
||||||
|
case SDL_JOYBUTTONUP:
|
||||||
|
pad_id = 100;
|
||||||
|
pad_id += input_event.jbutton.button;
|
||||||
|
pressed = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
//Joystick axis motion events
|
||||||
|
case SDL_JOYAXISMOTION:
|
||||||
|
pad_id = 200;
|
||||||
|
pad_id += (input_event.jaxis.axis * 2);
|
||||||
|
val = input_event.jaxis.value;
|
||||||
|
|
||||||
|
if(val > 0) {
|
||||||
|
pad_id += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}//namespace
|
}//namespace
|
||||||
|
|
|
@ -27,18 +27,17 @@ public:
|
||||||
///Shuts down all joysticks opened by SDL2
|
///Shuts down all joysticks opened by SDL2
|
||||||
void ShutDown();
|
void ShutDown();
|
||||||
|
|
||||||
|
///Processes input when polling
|
||||||
|
void ProcessInput();
|
||||||
|
|
||||||
///SDL event used for polling
|
///SDL event used for polling
|
||||||
SDL_Event input_event;
|
SDL_Event input_event;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SDL_Joystick* j_pad;
|
SDL_Joystick* jpad;
|
||||||
|
|
||||||
///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
|
||||||
|
|
Loading…
Reference in a new issue