mirror of
https://github.com/citra-emu/citra.git
synced 2024-11-25 20:50:15 +00:00
Cleanup old code.
This commit is contained in:
parent
6d9a4eccf5
commit
134cd66ae3
@ -12,26 +12,7 @@ Keyboard::Keyboard() {}
|
|||||||
Keyboard::~Keyboard() {}
|
Keyboard::~Keyboard() {}
|
||||||
|
|
||||||
bool Keyboard::InitDevice(int number, Settings::InputDeviceMapping device_mapping) {
|
bool Keyboard::InitDevice(int number, Settings::InputDeviceMapping device_mapping) {
|
||||||
|
|
||||||
// Check if keyboard is mapped for circle up or left. if so, set modifier to -1
|
|
||||||
/*for (const auto& entry : key_mapping) {
|
|
||||||
if (entry.first == "")
|
|
||||||
continue;
|
|
||||||
for (const auto& padstate : entry.second) {
|
|
||||||
if (padstate == Service::HID::PAD_CIRCLE_UP ||
|
|
||||||
padstate == Service::HID::PAD_CIRCLE_LEFT) {
|
|
||||||
circle_pad_directions[stoi(entry.first)] = -1.0;
|
|
||||||
} else if (padstate == Service::HID::PAD_CIRCLE_DOWN ||
|
|
||||||
padstate == Service::HID::PAD_CIRCLE_RIGHT) {
|
|
||||||
circle_pad_directions[stoi(entry.first)] = 1.0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
// Check if responsible for circle pad modifier
|
|
||||||
input_device_mapping = device_mapping;
|
input_device_mapping = device_mapping;
|
||||||
auto mapping = Settings::values.pad_circle_modifier;
|
|
||||||
if (mapping.device == Settings::Device::Keyboard && mapping.key != -1)
|
|
||||||
circle_pad_modifier = KeyboardKey(mapping.key, "");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,16 +51,10 @@ void Keyboard::Clear() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Settings::InputDeviceMapping Keyboard::GetInput() {
|
Settings::InputDeviceMapping Keyboard::GetInput() {
|
||||||
std::map<KeyboardKey, bool> keysPressedCopy;
|
auto result = ProcessInput();
|
||||||
{
|
for (const auto& entry : result) {
|
||||||
std::lock_guard<std::mutex> lock(m);
|
if (entry.second > 0.5)
|
||||||
keysPressedCopy = keys_pressed;
|
return entry.first;
|
||||||
}
|
|
||||||
for (const auto& entry : keysPressedCopy) {
|
|
||||||
int keycode = entry.first.key;
|
|
||||||
if (keysPressedCopy[entry.first] == true && keys_pressed_last[keycode] == false) {
|
|
||||||
return Settings::InputDeviceMapping("SDL/0/Keyboard/" + std::to_string(keycode));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return Settings::InputDeviceMapping("");
|
return Settings::InputDeviceMapping("");
|
||||||
}
|
}
|
||||||
|
@ -35,15 +35,10 @@ bool SDLGamepad::InitDevice(int number, Settings::InputDeviceMapping device_mapp
|
|||||||
if (SDL_IsGameController(number)) {
|
if (SDL_IsGameController(number)) {
|
||||||
gamepad = SDL_GameControllerOpen(number);
|
gamepad = SDL_GameControllerOpen(number);
|
||||||
if (gamepad == nullptr) {
|
if (gamepad == nullptr) {
|
||||||
LOG_INFO(Input, "Controller found but unable to open connection.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
input_device_mapping = device_mapping;
|
input_device_mapping = device_mapping;
|
||||||
/*for (const auto& entry : key_mapping) {
|
|
||||||
keys_pressed[entry.first] = false;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,10 +63,12 @@ std::map<Settings::InputDeviceMapping, float> SDLGamepad::ProcessInput() {
|
|||||||
button_status.emplace(input_device_mapping, 0);
|
button_status.emplace(input_device_mapping, 0);
|
||||||
input_device_mapping.key += 1; // minus axis value is always one greater
|
input_device_mapping.key += 1; // minus axis value is always one greater
|
||||||
button_status.emplace(input_device_mapping, abs(strength));
|
button_status.emplace(input_device_mapping, abs(strength));
|
||||||
} else {
|
} else if (strength >= 0 && i < 4) {
|
||||||
button_status.emplace(input_device_mapping, abs(strength));
|
button_status.emplace(input_device_mapping, abs(strength));
|
||||||
input_device_mapping.key += 1; // minus axis value is always one greater
|
input_device_mapping.key += 1;
|
||||||
button_status.emplace(input_device_mapping, 0);
|
button_status.emplace(input_device_mapping, 0);
|
||||||
|
} else { // Only trigger buttons
|
||||||
|
button_status.emplace(input_device_mapping, abs(strength));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return button_status;
|
return button_status;
|
||||||
@ -86,20 +83,12 @@ bool SDLGamepad::CloseDevice() {
|
|||||||
|
|
||||||
std::vector<std::shared_ptr<IDevice>> SDLGamepad::GetAllDevices() {
|
std::vector<std::shared_ptr<IDevice>> SDLGamepad::GetAllDevices() {
|
||||||
std::vector<std::shared_ptr<IDevice>> devices;
|
std::vector<std::shared_ptr<IDevice>> devices;
|
||||||
if (!SDLGamepad::SDLInitialized && SDL_Init(SDL_INIT_GAMECONTROLLER) < 0) {
|
|
||||||
LOG_CRITICAL(Input, "SDL_Init(SDL_INIT_GAMECONTROLLER) failed");
|
|
||||||
return devices;
|
|
||||||
}
|
|
||||||
LoadGameControllerDB();
|
|
||||||
SDL_GameControllerEventState(SDL_IGNORE);
|
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
SDL_GameController* gamecontroller;
|
auto gamepad = std::make_shared<SDLGamepad>();
|
||||||
if (SDL_IsGameController(i)) {
|
bool success = gamepad->InitDevice(
|
||||||
gamecontroller = SDL_GameControllerOpen(i);
|
i, Settings::InputDeviceMapping("SDL/" + std::to_string(i) + "/Gamepad/-1"));
|
||||||
if (gamecontroller != nullptr) {
|
if (success)
|
||||||
devices.push_back(std::make_shared<SDLGamepad>(i, gamecontroller));
|
devices.push_back(gamepad);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return devices;
|
return devices;
|
||||||
}
|
}
|
||||||
@ -121,54 +110,11 @@ void SDLGamepad::LoadGameControllerDB() {
|
|||||||
Settings::InputDeviceMapping SDLGamepad::GetInput() {
|
Settings::InputDeviceMapping SDLGamepad::GetInput() {
|
||||||
if (gamepad == nullptr)
|
if (gamepad == nullptr)
|
||||||
return Settings::InputDeviceMapping("");
|
return Settings::InputDeviceMapping("");
|
||||||
SDL_GameControllerUpdate();
|
|
||||||
for (int i = 0; i < SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_MAX; i++) {
|
|
||||||
Uint8 pressed = SDL_GameControllerGetButton(gamepad, SDL_GameControllerButton(i));
|
|
||||||
if (pressed == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
auto buttonName = SDL_GameControllerGetStringForButton(SDL_GameControllerButton(i));
|
auto results = ProcessInput();
|
||||||
for (const auto& mapping : gamepadinput_to_sdlname_mapping) {
|
for (auto& input : results) {
|
||||||
if (mapping.second == buttonName) {
|
if (input.second > 0.5)
|
||||||
return Settings::InputDeviceMapping(
|
return input.first;
|
||||||
"SDL/" + std::to_string(number) + "/" + "Gamepad/" +
|
|
||||||
std::to_string(static_cast<int>(mapping.first)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int i = 0; i < SDL_GameControllerAxis::SDL_CONTROLLER_AXIS_MAX; i++) {
|
|
||||||
Sint16 value = SDL_GameControllerGetAxis(gamepad, SDL_GameControllerAxis(i));
|
|
||||||
// TODO: calculate deadzone by radial field rather than axial field. (sqrt(x^2 + y^2) >
|
|
||||||
// deadzone)
|
|
||||||
// dont process if in deadzone. Replace later with settings for deadzone.
|
|
||||||
if (abs(value) < 0.2 * 32767.0)
|
|
||||||
continue;
|
|
||||||
std::string modifier;
|
|
||||||
if (value > 0)
|
|
||||||
modifier = "+";
|
|
||||||
else
|
|
||||||
modifier = "-";
|
|
||||||
std::string axisName = SDL_GameControllerGetStringForAxis(SDL_GameControllerAxis(i));
|
|
||||||
for (const auto& mapping : gamepadinput_to_sdlname_mapping) {
|
|
||||||
if (mapping.second == axisName) {
|
|
||||||
if ((mapping.first == GamepadInputs::LeftXMinus ||
|
|
||||||
mapping.first == GamepadInputs::LeftYMinus ||
|
|
||||||
mapping.first == GamepadInputs::RightXMinus ||
|
|
||||||
mapping.first == GamepadInputs::RightYMinus) &&
|
|
||||||
modifier == "+") {
|
|
||||||
continue;
|
|
||||||
} else if ((mapping.first == GamepadInputs::LeftXPlus ||
|
|
||||||
mapping.first == GamepadInputs::LeftYPlus ||
|
|
||||||
mapping.first == GamepadInputs::RightXPlus ||
|
|
||||||
mapping.first == GamepadInputs::RightYPlus) &&
|
|
||||||
modifier == "-") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
return Settings::InputDeviceMapping(
|
|
||||||
"SDL/" + std::to_string(this->number) + "/" + "Gamepad/" +
|
|
||||||
std::to_string(static_cast<int>(mapping.first)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return Settings::InputDeviceMapping("");
|
return Settings::InputDeviceMapping("");
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,7 @@ void InputCore::InputTickCallback(u64, int cycles_late) {
|
|||||||
void InputCore::UpdateEmulatorInputs(
|
void InputCore::UpdateEmulatorInputs(
|
||||||
std::vector<std::map<Settings::InputDeviceMapping, float>> inputs) {
|
std::vector<std::map<Settings::InputDeviceMapping, float>> inputs) {
|
||||||
std::lock_guard<std::mutex> lock(pad_state_mutex);
|
std::lock_guard<std::mutex> lock(pad_state_mutex);
|
||||||
|
|
||||||
// Apply deadzone
|
// Apply deadzone
|
||||||
float leftx = 0, lefty = 0;
|
float leftx = 0, lefty = 0;
|
||||||
float circle_pad_modifier = 1.0;
|
float circle_pad_modifier = 1.0;
|
||||||
@ -202,14 +203,11 @@ void InputCore::GenerateUniqueDevices() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
devices.push_back(input);
|
devices.push_back(input);
|
||||||
|
|
||||||
// Build map of inputs to listen for, for this device
|
|
||||||
BuildKeyMapping();
|
|
||||||
|
|
||||||
input->InitDevice(mapping.number, mapping);
|
input->InitDevice(mapping.number, mapping);
|
||||||
}
|
}
|
||||||
if (main_keyboard == nullptr) {
|
if (main_keyboard == nullptr) {
|
||||||
main_keyboard = std::make_shared<Keyboard>();
|
main_keyboard = std::make_shared<Keyboard>();
|
||||||
|
main_keyboard->InitDevice(0, Settings::InputDeviceMapping("SDL/0/Keyboard/-1"));
|
||||||
devices.push_back(main_keyboard);
|
devices.push_back(main_keyboard);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -217,6 +215,7 @@ void InputCore::GenerateUniqueDevices() {
|
|||||||
/// Read settings to initialize devices
|
/// Read settings to initialize devices
|
||||||
void InputCore::ParseSettings() {
|
void InputCore::ParseSettings() {
|
||||||
GenerateUniqueDevices();
|
GenerateUniqueDevices();
|
||||||
|
BuildKeyMapping();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<float, float> InputCore::ApplyDeadzone(float x, float y, float dead_zone) {
|
std::tuple<float, float> InputCore::ApplyDeadzone(float x, float y, float dead_zone) {
|
||||||
@ -244,7 +243,9 @@ void InputCore::ReloadSettings() {
|
|||||||
/// Returns all available input devices. Used for key binding in GUI
|
/// Returns all available input devices. Used for key binding in GUI
|
||||||
std::vector<std::shared_ptr<IDevice>> InputCore::GetAllDevices() {
|
std::vector<std::shared_ptr<IDevice>> InputCore::GetAllDevices() {
|
||||||
auto all_devices = SDLGamepad::GetAllDevices();
|
auto all_devices = SDLGamepad::GetAllDevices();
|
||||||
all_devices.push_back(InputCore::GetKeyboard());
|
auto keyboard = InputCore::GetKeyboard();
|
||||||
|
keyboard->InitDevice(0, Settings::InputDeviceMapping("SDL/0/Keyboard/-1"));
|
||||||
|
all_devices.push_back(keyboard);
|
||||||
|
|
||||||
return all_devices;
|
return all_devices;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user