mirror of
https://github.com/citra-emu/citra.git
synced 2024-11-24 18:51:05 +00:00
Preliminary analog input support
This commit is contained in:
parent
c736bc2572
commit
558422c2ac
@ -43,10 +43,11 @@ bool SDLController::Init() {
|
|||||||
|
|
||||||
//If joystick successfully opened, load up keymap from input configuration
|
//If joystick successfully opened, load up keymap from input configuration
|
||||||
//TODO - Make it NOT hardcoded
|
//TODO - Make it NOT hardcoded
|
||||||
else {
|
|
||||||
joypad_id = KeyMap::NewDeviceId();
|
joypad_id = KeyMap::NewDeviceId();
|
||||||
SetupKeyMaps();
|
SetupKeyMaps();
|
||||||
}
|
|
||||||
|
//TODO - Make it NOT hardcoded
|
||||||
|
SetDeadZone(8000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLController::DiscoverDevices() {}
|
void SDLController::DiscoverDevices() {}
|
||||||
@ -103,6 +104,20 @@ void SDLController::ProcessInput() {
|
|||||||
pad_id += 1;
|
pad_id += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//If analog input is beyond dead zone, set it
|
||||||
|
if(CheckDeadZone(val)) {
|
||||||
|
controller.pad_state.hex |= KeyMap::GetPadKey({pad_id, joypad_id}).hex;
|
||||||
|
} else {
|
||||||
|
controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id, joypad_id}).hex;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Release opposite axis
|
||||||
|
if(pad_id % 2 == 0) {
|
||||||
|
controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id+1, joypad_id}).hex;
|
||||||
|
} else {
|
||||||
|
controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id-1, joypad_id}).hex;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//Joystick hat motion events
|
//Joystick hat motion events
|
||||||
@ -208,4 +223,16 @@ void SDLController::SetupKeyMaps() {
|
|||||||
KeyMap::SetKeyMapping({203, joypad_id}, Service::HID::PAD_CIRCLE_DOWN);
|
KeyMap::SetKeyMapping({203, joypad_id}, Service::HID::PAD_CIRCLE_DOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SDLController::SetDeadZone(int range) {
|
||||||
|
dead_zone = range;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SDLController::CheckDeadZone(int range) {
|
||||||
|
if((range < -dead_zone) || (range > dead_zone)) {
|
||||||
|
return true;
|
||||||
|
} else if((range > -dead_zone) && (range < dead_zone)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}//namespace
|
}//namespace
|
||||||
|
@ -33,16 +33,25 @@ public:
|
|||||||
///Sets up keymaps from input configuration
|
///Sets up keymaps from input configuration
|
||||||
void SetupKeyMaps();
|
void SetupKeyMaps();
|
||||||
|
|
||||||
///SDL event used for polling
|
///Sets analog deadzones
|
||||||
SDL_Event input_event;
|
void SetDeadZone(int range);
|
||||||
|
|
||||||
|
///Checks if analog input is within the dead zone
|
||||||
|
bool CheckDeadZone(int range);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SDL_Joystick* jpad;
|
SDL_Joystick* jpad;
|
||||||
|
|
||||||
|
///SDL event used for polling
|
||||||
|
SDL_Event input_event;
|
||||||
|
|
||||||
///Index of joystick, used for opening/closing a joystick
|
///Index of joystick, used for opening/closing a joystick
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
|
///Keymap id for this controller
|
||||||
int joypad_id;
|
int joypad_id;
|
||||||
|
|
||||||
|
int dead_zone;
|
||||||
};
|
};
|
||||||
|
|
||||||
} //namespace
|
} //namespace
|
||||||
|
Loading…
Reference in New Issue
Block a user