mirror of
https://gitlab.com/suyu-emu/suyu.git
synced 2024-03-15 23:15:44 +00:00
common/input: Avoid numerous large copies of CallbackStatus
CallbackStatus instances aren't the cheapest things to copy around (relative to everything else), given that they're currently 520 bytes in size and are currently copied numerous times when callbacks are invoked. Instead, we can pass the status by const reference to avoid all the copying.
This commit is contained in:
parent
54eafbaf17
commit
e05d2a70b2
|
@ -227,7 +227,7 @@ struct CallbackStatus {
|
||||||
|
|
||||||
// Triggered once every input change
|
// Triggered once every input change
|
||||||
struct InputCallback {
|
struct InputCallback {
|
||||||
std::function<void(CallbackStatus)> on_change;
|
std::function<void(const CallbackStatus&)> on_change;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// An abstract class template for an input device (a button, an analog input, etc.).
|
/// An abstract class template for an input device (a button, an analog input, etc.).
|
||||||
|
@ -247,7 +247,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Triggers the function set in the callback
|
// Triggers the function set in the callback
|
||||||
void TriggerOnChange(CallbackStatus status) {
|
void TriggerOnChange(const CallbackStatus& status) {
|
||||||
if (callback.on_change) {
|
if (callback.on_change) {
|
||||||
callback.on_change(status);
|
callback.on_change(status);
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,9 +66,10 @@ void EmulatedConsole::ReloadInput() {
|
||||||
|
|
||||||
motion_devices = Common::Input::CreateDevice<Common::Input::InputDevice>(motion_params);
|
motion_devices = Common::Input::CreateDevice<Common::Input::InputDevice>(motion_params);
|
||||||
if (motion_devices) {
|
if (motion_devices) {
|
||||||
Common::Input::InputCallback motion_callback{
|
motion_devices->SetCallback({
|
||||||
[this](Common::Input::CallbackStatus callback) { SetMotion(callback); }};
|
.on_change =
|
||||||
motion_devices->SetCallback(motion_callback);
|
[this](const Common::Input::CallbackStatus& callback) { SetMotion(callback); },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unique index for identifying touch device source
|
// Unique index for identifying touch device source
|
||||||
|
@ -78,9 +79,12 @@ void EmulatedConsole::ReloadInput() {
|
||||||
if (!touch_device) {
|
if (!touch_device) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Common::Input::InputCallback touch_callback{
|
touch_device->SetCallback({
|
||||||
[this, index](Common::Input::CallbackStatus callback) { SetTouch(callback, index); }};
|
.on_change =
|
||||||
touch_device->SetCallback(touch_callback);
|
[this, index](const Common::Input::CallbackStatus& callback) {
|
||||||
|
SetTouch(callback, index);
|
||||||
|
},
|
||||||
|
});
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,7 +131,7 @@ void EmulatedConsole::SetMotionParam(Common::ParamPackage param) {
|
||||||
ReloadInput();
|
ReloadInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmulatedConsole::SetMotion(Common::Input::CallbackStatus callback) {
|
void EmulatedConsole::SetMotion(const Common::Input::CallbackStatus& callback) {
|
||||||
std::lock_guard lock{mutex};
|
std::lock_guard lock{mutex};
|
||||||
auto& raw_status = console.motion_values.raw_status;
|
auto& raw_status = console.motion_values.raw_status;
|
||||||
auto& emulated = console.motion_values.emulated;
|
auto& emulated = console.motion_values.emulated;
|
||||||
|
@ -162,8 +166,7 @@ void EmulatedConsole::SetMotion(Common::Input::CallbackStatus callback) {
|
||||||
TriggerOnChange(ConsoleTriggerType::Motion);
|
TriggerOnChange(ConsoleTriggerType::Motion);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmulatedConsole::SetTouch(Common::Input::CallbackStatus callback,
|
void EmulatedConsole::SetTouch(const Common::Input::CallbackStatus& callback, std::size_t index) {
|
||||||
[[maybe_unused]] std::size_t index) {
|
|
||||||
if (index >= console.touch_values.size()) {
|
if (index >= console.touch_values.size()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,14 +155,14 @@ private:
|
||||||
* Updates the motion status of the console
|
* Updates the motion status of the console
|
||||||
* @param callback A CallbackStatus containing gyro and accelerometer data
|
* @param callback A CallbackStatus containing gyro and accelerometer data
|
||||||
*/
|
*/
|
||||||
void SetMotion(Common::Input::CallbackStatus callback);
|
void SetMotion(const Common::Input::CallbackStatus& callback);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the touch status of the console
|
* Updates the touch status of the console
|
||||||
* @param callback A CallbackStatus containing the touch position
|
* @param callback A CallbackStatus containing the touch position
|
||||||
* @param index Finger ID to be updated
|
* @param index Finger ID to be updated
|
||||||
*/
|
*/
|
||||||
void SetTouch(Common::Input::CallbackStatus callback, std::size_t index);
|
void SetTouch(const Common::Input::CallbackStatus& callback, std::size_t index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Triggers a callback that something has changed on the console status
|
* Triggers a callback that something has changed on the console status
|
||||||
|
|
|
@ -205,11 +205,12 @@ void EmulatedController::ReloadInput() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const auto uuid = Common::UUID{button_params[index].Get("guid", "")};
|
const auto uuid = Common::UUID{button_params[index].Get("guid", "")};
|
||||||
Common::Input::InputCallback button_callback{
|
button_devices[index]->SetCallback({
|
||||||
[this, index, uuid](Common::Input::CallbackStatus callback) {
|
.on_change =
|
||||||
SetButton(callback, index, uuid);
|
[this, index, uuid](const Common::Input::CallbackStatus& callback) {
|
||||||
}};
|
SetButton(callback, index, uuid);
|
||||||
button_devices[index]->SetCallback(button_callback);
|
},
|
||||||
|
});
|
||||||
button_devices[index]->ForceUpdate();
|
button_devices[index]->ForceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,11 +219,12 @@ void EmulatedController::ReloadInput() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const auto uuid = Common::UUID{stick_params[index].Get("guid", "")};
|
const auto uuid = Common::UUID{stick_params[index].Get("guid", "")};
|
||||||
Common::Input::InputCallback stick_callback{
|
stick_devices[index]->SetCallback({
|
||||||
[this, index, uuid](Common::Input::CallbackStatus callback) {
|
.on_change =
|
||||||
SetStick(callback, index, uuid);
|
[this, index, uuid](const Common::Input::CallbackStatus& callback) {
|
||||||
}};
|
SetStick(callback, index, uuid);
|
||||||
stick_devices[index]->SetCallback(stick_callback);
|
},
|
||||||
|
});
|
||||||
stick_devices[index]->ForceUpdate();
|
stick_devices[index]->ForceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,11 +233,12 @@ void EmulatedController::ReloadInput() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const auto uuid = Common::UUID{trigger_params[index].Get("guid", "")};
|
const auto uuid = Common::UUID{trigger_params[index].Get("guid", "")};
|
||||||
Common::Input::InputCallback trigger_callback{
|
trigger_devices[index]->SetCallback({
|
||||||
[this, index, uuid](Common::Input::CallbackStatus callback) {
|
.on_change =
|
||||||
SetTrigger(callback, index, uuid);
|
[this, index, uuid](const Common::Input::CallbackStatus& callback) {
|
||||||
}};
|
SetTrigger(callback, index, uuid);
|
||||||
trigger_devices[index]->SetCallback(trigger_callback);
|
},
|
||||||
|
});
|
||||||
trigger_devices[index]->ForceUpdate();
|
trigger_devices[index]->ForceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,9 +246,12 @@ void EmulatedController::ReloadInput() {
|
||||||
if (!battery_devices[index]) {
|
if (!battery_devices[index]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Common::Input::InputCallback battery_callback{
|
battery_devices[index]->SetCallback({
|
||||||
[this, index](Common::Input::CallbackStatus callback) { SetBattery(callback, index); }};
|
.on_change =
|
||||||
battery_devices[index]->SetCallback(battery_callback);
|
[this, index](const Common::Input::CallbackStatus& callback) {
|
||||||
|
SetBattery(callback, index);
|
||||||
|
},
|
||||||
|
});
|
||||||
battery_devices[index]->ForceUpdate();
|
battery_devices[index]->ForceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,9 +259,12 @@ void EmulatedController::ReloadInput() {
|
||||||
if (!motion_devices[index]) {
|
if (!motion_devices[index]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Common::Input::InputCallback motion_callback{
|
motion_devices[index]->SetCallback({
|
||||||
[this, index](Common::Input::CallbackStatus callback) { SetMotion(callback, index); }};
|
.on_change =
|
||||||
motion_devices[index]->SetCallback(motion_callback);
|
[this, index](const Common::Input::CallbackStatus& callback) {
|
||||||
|
SetMotion(callback, index);
|
||||||
|
},
|
||||||
|
});
|
||||||
motion_devices[index]->ForceUpdate();
|
motion_devices[index]->ForceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,22 +276,24 @@ void EmulatedController::ReloadInput() {
|
||||||
if (!tas_button_devices[index]) {
|
if (!tas_button_devices[index]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Common::Input::InputCallback button_callback{
|
tas_button_devices[index]->SetCallback({
|
||||||
[this, index, tas_uuid](Common::Input::CallbackStatus callback) {
|
.on_change =
|
||||||
SetButton(callback, index, tas_uuid);
|
[this, index, tas_uuid](const Common::Input::CallbackStatus& callback) {
|
||||||
}};
|
SetButton(callback, index, tas_uuid);
|
||||||
tas_button_devices[index]->SetCallback(button_callback);
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::size_t index = 0; index < tas_stick_devices.size(); ++index) {
|
for (std::size_t index = 0; index < tas_stick_devices.size(); ++index) {
|
||||||
if (!tas_stick_devices[index]) {
|
if (!tas_stick_devices[index]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Common::Input::InputCallback stick_callback{
|
tas_stick_devices[index]->SetCallback({
|
||||||
[this, index, tas_uuid](Common::Input::CallbackStatus callback) {
|
.on_change =
|
||||||
SetStick(callback, index, tas_uuid);
|
[this, index, tas_uuid](const Common::Input::CallbackStatus& callback) {
|
||||||
}};
|
SetStick(callback, index, tas_uuid);
|
||||||
tas_stick_devices[index]->SetCallback(stick_callback);
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,7 +451,7 @@ void EmulatedController::SetButtonParam(std::size_t index, Common::ParamPackage
|
||||||
if (index >= button_params.size()) {
|
if (index >= button_params.size()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
button_params[index] = param;
|
button_params[index] = std::move(param);
|
||||||
ReloadInput();
|
ReloadInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,7 +459,7 @@ void EmulatedController::SetStickParam(std::size_t index, Common::ParamPackage p
|
||||||
if (index >= stick_params.size()) {
|
if (index >= stick_params.size()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
stick_params[index] = param;
|
stick_params[index] = std::move(param);
|
||||||
ReloadInput();
|
ReloadInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,11 +467,11 @@ void EmulatedController::SetMotionParam(std::size_t index, Common::ParamPackage
|
||||||
if (index >= motion_params.size()) {
|
if (index >= motion_params.size()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
motion_params[index] = param;
|
motion_params[index] = std::move(param);
|
||||||
ReloadInput();
|
ReloadInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmulatedController::SetButton(Common::Input::CallbackStatus callback, std::size_t index,
|
void EmulatedController::SetButton(const Common::Input::CallbackStatus& callback, std::size_t index,
|
||||||
Common::UUID uuid) {
|
Common::UUID uuid) {
|
||||||
if (index >= controller.button_values.size()) {
|
if (index >= controller.button_values.size()) {
|
||||||
return;
|
return;
|
||||||
|
@ -600,7 +611,7 @@ void EmulatedController::SetButton(Common::Input::CallbackStatus callback, std::
|
||||||
TriggerOnChange(ControllerTriggerType::Button, true);
|
TriggerOnChange(ControllerTriggerType::Button, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmulatedController::SetStick(Common::Input::CallbackStatus callback, std::size_t index,
|
void EmulatedController::SetStick(const Common::Input::CallbackStatus& callback, std::size_t index,
|
||||||
Common::UUID uuid) {
|
Common::UUID uuid) {
|
||||||
if (index >= controller.stick_values.size()) {
|
if (index >= controller.stick_values.size()) {
|
||||||
return;
|
return;
|
||||||
|
@ -650,8 +661,8 @@ void EmulatedController::SetStick(Common::Input::CallbackStatus callback, std::s
|
||||||
TriggerOnChange(ControllerTriggerType::Stick, true);
|
TriggerOnChange(ControllerTriggerType::Stick, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmulatedController::SetTrigger(Common::Input::CallbackStatus callback, std::size_t index,
|
void EmulatedController::SetTrigger(const Common::Input::CallbackStatus& callback,
|
||||||
Common::UUID uuid) {
|
std::size_t index, Common::UUID uuid) {
|
||||||
if (index >= controller.trigger_values.size()) {
|
if (index >= controller.trigger_values.size()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -692,7 +703,8 @@ void EmulatedController::SetTrigger(Common::Input::CallbackStatus callback, std:
|
||||||
TriggerOnChange(ControllerTriggerType::Trigger, true);
|
TriggerOnChange(ControllerTriggerType::Trigger, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmulatedController::SetMotion(Common::Input::CallbackStatus callback, std::size_t index) {
|
void EmulatedController::SetMotion(const Common::Input::CallbackStatus& callback,
|
||||||
|
std::size_t index) {
|
||||||
if (index >= controller.motion_values.size()) {
|
if (index >= controller.motion_values.size()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -730,7 +742,8 @@ void EmulatedController::SetMotion(Common::Input::CallbackStatus callback, std::
|
||||||
TriggerOnChange(ControllerTriggerType::Motion, true);
|
TriggerOnChange(ControllerTriggerType::Motion, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmulatedController::SetBattery(Common::Input::CallbackStatus callback, std::size_t index) {
|
void EmulatedController::SetBattery(const Common::Input::CallbackStatus& callback,
|
||||||
|
std::size_t index) {
|
||||||
if (index >= controller.battery_values.size()) {
|
if (index >= controller.battery_values.size()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1110,7 +1123,7 @@ void EmulatedController::TriggerOnChange(ControllerTriggerType type, bool is_npa
|
||||||
|
|
||||||
int EmulatedController::SetCallback(ControllerUpdateCallback update_callback) {
|
int EmulatedController::SetCallback(ControllerUpdateCallback update_callback) {
|
||||||
std::lock_guard lock{mutex};
|
std::lock_guard lock{mutex};
|
||||||
callback_list.insert_or_assign(last_callback_key, update_callback);
|
callback_list.insert_or_assign(last_callback_key, std::move(update_callback));
|
||||||
return last_callback_key++;
|
return last_callback_key++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -328,35 +328,38 @@ private:
|
||||||
* @param callback A CallbackStatus containing the button status
|
* @param callback A CallbackStatus containing the button status
|
||||||
* @param index Button ID of the to be updated
|
* @param index Button ID of the to be updated
|
||||||
*/
|
*/
|
||||||
void SetButton(Common::Input::CallbackStatus callback, std::size_t index, Common::UUID uuid);
|
void SetButton(const Common::Input::CallbackStatus& callback, std::size_t index,
|
||||||
|
Common::UUID uuid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the analog stick status of the controller
|
* Updates the analog stick status of the controller
|
||||||
* @param callback A CallbackStatus containing the analog stick status
|
* @param callback A CallbackStatus containing the analog stick status
|
||||||
* @param index stick ID of the to be updated
|
* @param index stick ID of the to be updated
|
||||||
*/
|
*/
|
||||||
void SetStick(Common::Input::CallbackStatus callback, std::size_t index, Common::UUID uuid);
|
void SetStick(const Common::Input::CallbackStatus& callback, std::size_t index,
|
||||||
|
Common::UUID uuid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the trigger status of the controller
|
* Updates the trigger status of the controller
|
||||||
* @param callback A CallbackStatus containing the trigger status
|
* @param callback A CallbackStatus containing the trigger status
|
||||||
* @param index trigger ID of the to be updated
|
* @param index trigger ID of the to be updated
|
||||||
*/
|
*/
|
||||||
void SetTrigger(Common::Input::CallbackStatus callback, std::size_t index, Common::UUID uuid);
|
void SetTrigger(const Common::Input::CallbackStatus& callback, std::size_t index,
|
||||||
|
Common::UUID uuid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the motion status of the controller
|
* Updates the motion status of the controller
|
||||||
* @param callback A CallbackStatus containing gyro and accelerometer data
|
* @param callback A CallbackStatus containing gyro and accelerometer data
|
||||||
* @param index motion ID of the to be updated
|
* @param index motion ID of the to be updated
|
||||||
*/
|
*/
|
||||||
void SetMotion(Common::Input::CallbackStatus callback, std::size_t index);
|
void SetMotion(const Common::Input::CallbackStatus& callback, std::size_t index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the battery status of the controller
|
* Updates the battery status of the controller
|
||||||
* @param callback A CallbackStatus containing the battery status
|
* @param callback A CallbackStatus containing the battery status
|
||||||
* @param index Button ID of the to be updated
|
* @param index Button ID of the to be updated
|
||||||
*/
|
*/
|
||||||
void SetBattery(Common::Input::CallbackStatus callback, std::size_t index);
|
void SetBattery(const Common::Input::CallbackStatus& callback, std::size_t index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Triggers a callback that something has changed on the controller status
|
* Triggers a callback that something has changed on the controller status
|
||||||
|
|
|
@ -70,50 +70,55 @@ void EmulatedDevices::ReloadInput() {
|
||||||
if (!mouse_button_devices[index]) {
|
if (!mouse_button_devices[index]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Common::Input::InputCallback button_callback{
|
mouse_button_devices[index]->SetCallback({
|
||||||
[this, index](Common::Input::CallbackStatus callback) {
|
.on_change =
|
||||||
SetMouseButton(callback, index);
|
[this, index](const Common::Input::CallbackStatus& callback) {
|
||||||
}};
|
SetMouseButton(callback, index);
|
||||||
mouse_button_devices[index]->SetCallback(button_callback);
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::size_t index = 0; index < mouse_analog_devices.size(); ++index) {
|
for (std::size_t index = 0; index < mouse_analog_devices.size(); ++index) {
|
||||||
if (!mouse_analog_devices[index]) {
|
if (!mouse_analog_devices[index]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Common::Input::InputCallback button_callback{
|
mouse_analog_devices[index]->SetCallback({
|
||||||
[this, index](Common::Input::CallbackStatus callback) {
|
.on_change =
|
||||||
SetMouseAnalog(callback, index);
|
[this, index](const Common::Input::CallbackStatus& callback) {
|
||||||
}};
|
SetMouseAnalog(callback, index);
|
||||||
mouse_analog_devices[index]->SetCallback(button_callback);
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mouse_stick_device) {
|
if (mouse_stick_device) {
|
||||||
Common::Input::InputCallback button_callback{
|
mouse_stick_device->SetCallback({
|
||||||
[this](Common::Input::CallbackStatus callback) { SetMouseStick(callback); }};
|
.on_change =
|
||||||
mouse_stick_device->SetCallback(button_callback);
|
[this](const Common::Input::CallbackStatus& callback) { SetMouseStick(callback); },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::size_t index = 0; index < keyboard_devices.size(); ++index) {
|
for (std::size_t index = 0; index < keyboard_devices.size(); ++index) {
|
||||||
if (!keyboard_devices[index]) {
|
if (!keyboard_devices[index]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Common::Input::InputCallback button_callback{
|
keyboard_devices[index]->SetCallback({
|
||||||
[this, index](Common::Input::CallbackStatus callback) {
|
.on_change =
|
||||||
SetKeyboardButton(callback, index);
|
[this, index](const Common::Input::CallbackStatus& callback) {
|
||||||
}};
|
SetKeyboardButton(callback, index);
|
||||||
keyboard_devices[index]->SetCallback(button_callback);
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::size_t index = 0; index < keyboard_modifier_devices.size(); ++index) {
|
for (std::size_t index = 0; index < keyboard_modifier_devices.size(); ++index) {
|
||||||
if (!keyboard_modifier_devices[index]) {
|
if (!keyboard_modifier_devices[index]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Common::Input::InputCallback button_callback{
|
keyboard_modifier_devices[index]->SetCallback({
|
||||||
[this, index](Common::Input::CallbackStatus callback) {
|
.on_change =
|
||||||
SetKeyboardModifier(callback, index);
|
[this, index](const Common::Input::CallbackStatus& callback) {
|
||||||
}};
|
SetKeyboardModifier(callback, index);
|
||||||
keyboard_modifier_devices[index]->SetCallback(button_callback);
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +164,8 @@ void EmulatedDevices::RestoreConfig() {
|
||||||
ReloadFromSettings();
|
ReloadFromSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmulatedDevices::SetKeyboardButton(Common::Input::CallbackStatus callback, std::size_t index) {
|
void EmulatedDevices::SetKeyboardButton(const Common::Input::CallbackStatus& callback,
|
||||||
|
std::size_t index) {
|
||||||
if (index >= device_status.keyboard_values.size()) {
|
if (index >= device_status.keyboard_values.size()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -216,7 +222,7 @@ void EmulatedDevices::UpdateKey(std::size_t key_index, bool status) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmulatedDevices::SetKeyboardModifier(Common::Input::CallbackStatus callback,
|
void EmulatedDevices::SetKeyboardModifier(const Common::Input::CallbackStatus& callback,
|
||||||
std::size_t index) {
|
std::size_t index) {
|
||||||
if (index >= device_status.keyboard_moddifier_values.size()) {
|
if (index >= device_status.keyboard_moddifier_values.size()) {
|
||||||
return;
|
return;
|
||||||
|
@ -286,7 +292,8 @@ void EmulatedDevices::SetKeyboardModifier(Common::Input::CallbackStatus callback
|
||||||
TriggerOnChange(DeviceTriggerType::KeyboardModdifier);
|
TriggerOnChange(DeviceTriggerType::KeyboardModdifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmulatedDevices::SetMouseButton(Common::Input::CallbackStatus callback, std::size_t index) {
|
void EmulatedDevices::SetMouseButton(const Common::Input::CallbackStatus& callback,
|
||||||
|
std::size_t index) {
|
||||||
if (index >= device_status.mouse_button_values.size()) {
|
if (index >= device_status.mouse_button_values.size()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -347,7 +354,8 @@ void EmulatedDevices::SetMouseButton(Common::Input::CallbackStatus callback, std
|
||||||
TriggerOnChange(DeviceTriggerType::Mouse);
|
TriggerOnChange(DeviceTriggerType::Mouse);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmulatedDevices::SetMouseAnalog(Common::Input::CallbackStatus callback, std::size_t index) {
|
void EmulatedDevices::SetMouseAnalog(const Common::Input::CallbackStatus& callback,
|
||||||
|
std::size_t index) {
|
||||||
if (index >= device_status.mouse_analog_values.size()) {
|
if (index >= device_status.mouse_analog_values.size()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -374,7 +382,7 @@ void EmulatedDevices::SetMouseAnalog(Common::Input::CallbackStatus callback, std
|
||||||
TriggerOnChange(DeviceTriggerType::Mouse);
|
TriggerOnChange(DeviceTriggerType::Mouse);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmulatedDevices::SetMouseStick(Common::Input::CallbackStatus callback) {
|
void EmulatedDevices::SetMouseStick(const Common::Input::CallbackStatus& callback) {
|
||||||
std::lock_guard lock{mutex};
|
std::lock_guard lock{mutex};
|
||||||
const auto touch_value = TransformToTouch(callback);
|
const auto touch_value = TransformToTouch(callback);
|
||||||
|
|
||||||
|
@ -435,7 +443,7 @@ void EmulatedDevices::TriggerOnChange(DeviceTriggerType type) {
|
||||||
|
|
||||||
int EmulatedDevices::SetCallback(InterfaceUpdateCallback update_callback) {
|
int EmulatedDevices::SetCallback(InterfaceUpdateCallback update_callback) {
|
||||||
std::lock_guard lock{mutex};
|
std::lock_guard lock{mutex};
|
||||||
callback_list.insert_or_assign(last_callback_key, update_callback);
|
callback_list.insert_or_assign(last_callback_key, std::move(update_callback));
|
||||||
return last_callback_key++;
|
return last_callback_key++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -156,35 +156,34 @@ private:
|
||||||
* @param callback A CallbackStatus containing the key status
|
* @param callback A CallbackStatus containing the key status
|
||||||
* @param index key ID to be updated
|
* @param index key ID to be updated
|
||||||
*/
|
*/
|
||||||
void SetKeyboardButton(Common::Input::CallbackStatus callback, std::size_t index);
|
void SetKeyboardButton(const Common::Input::CallbackStatus& callback, std::size_t index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the keyboard status of the keyboard device
|
* Updates the keyboard status of the keyboard device
|
||||||
* @param callback A CallbackStatus containing the modifier key status
|
* @param callback A CallbackStatus containing the modifier key status
|
||||||
* @param index modifier key ID to be updated
|
* @param index modifier key ID to be updated
|
||||||
*/
|
*/
|
||||||
void SetKeyboardModifier(Common::Input::CallbackStatus callback, std::size_t index);
|
void SetKeyboardModifier(const Common::Input::CallbackStatus& callback, std::size_t index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the mouse button status of the mouse device
|
* Updates the mouse button status of the mouse device
|
||||||
* @param callback A CallbackStatus containing the button status
|
* @param callback A CallbackStatus containing the button status
|
||||||
* @param index Button ID to be updated
|
* @param index Button ID to be updated
|
||||||
*/
|
*/
|
||||||
void SetMouseButton(Common::Input::CallbackStatus callback, std::size_t index);
|
void SetMouseButton(const Common::Input::CallbackStatus& callback, std::size_t index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the mouse wheel status of the mouse device
|
* Updates the mouse wheel status of the mouse device
|
||||||
* @param callback A CallbackStatus containing the wheel status
|
* @param callback A CallbackStatus containing the wheel status
|
||||||
* @param index wheel ID to be updated
|
* @param index wheel ID to be updated
|
||||||
*/
|
*/
|
||||||
void SetMouseAnalog(Common::Input::CallbackStatus callback, std::size_t index);
|
void SetMouseAnalog(const Common::Input::CallbackStatus& callback, std::size_t index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the mouse position status of the mouse device
|
* Updates the mouse position status of the mouse device
|
||||||
* @param callback A CallbackStatus containing the position status
|
* @param callback A CallbackStatus containing the position status
|
||||||
* @param index stick ID to be updated
|
|
||||||
*/
|
*/
|
||||||
void SetMouseStick(Common::Input::CallbackStatus callback);
|
void SetMouseStick(const Common::Input::CallbackStatus& callback);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Triggers a callback that something has changed on the device status
|
* Triggers a callback that something has changed on the device status
|
||||||
|
|
|
@ -19,23 +19,36 @@ public:
|
||||||
: up(std::move(up_)), down(std::move(down_)), left(std::move(left_)),
|
: up(std::move(up_)), down(std::move(down_)), left(std::move(left_)),
|
||||||
right(std::move(right_)), modifier(std::move(modifier_)), modifier_scale(modifier_scale_),
|
right(std::move(right_)), modifier(std::move(modifier_)), modifier_scale(modifier_scale_),
|
||||||
modifier_angle(modifier_angle_) {
|
modifier_angle(modifier_angle_) {
|
||||||
Common::Input::InputCallback button_up_callback{
|
up->SetCallback({
|
||||||
[this](Common::Input::CallbackStatus callback_) { UpdateUpButtonStatus(callback_); }};
|
.on_change =
|
||||||
Common::Input::InputCallback button_down_callback{
|
[this](const Common::Input::CallbackStatus& callback_) {
|
||||||
[this](Common::Input::CallbackStatus callback_) { UpdateDownButtonStatus(callback_); }};
|
UpdateUpButtonStatus(callback_);
|
||||||
Common::Input::InputCallback button_left_callback{
|
},
|
||||||
[this](Common::Input::CallbackStatus callback_) { UpdateLeftButtonStatus(callback_); }};
|
});
|
||||||
Common::Input::InputCallback button_right_callback{
|
down->SetCallback({
|
||||||
[this](Common::Input::CallbackStatus callback_) {
|
.on_change =
|
||||||
UpdateRightButtonStatus(callback_);
|
[this](const Common::Input::CallbackStatus& callback_) {
|
||||||
}};
|
UpdateDownButtonStatus(callback_);
|
||||||
Common::Input::InputCallback button_modifier_callback{
|
},
|
||||||
[this](Common::Input::CallbackStatus callback_) { UpdateModButtonStatus(callback_); }};
|
});
|
||||||
up->SetCallback(button_up_callback);
|
left->SetCallback({
|
||||||
down->SetCallback(button_down_callback);
|
.on_change =
|
||||||
left->SetCallback(button_left_callback);
|
[this](const Common::Input::CallbackStatus& callback_) {
|
||||||
right->SetCallback(button_right_callback);
|
UpdateLeftButtonStatus(callback_);
|
||||||
modifier->SetCallback(button_modifier_callback);
|
},
|
||||||
|
});
|
||||||
|
right->SetCallback({
|
||||||
|
.on_change =
|
||||||
|
[this](const Common::Input::CallbackStatus& callback_) {
|
||||||
|
UpdateRightButtonStatus(callback_);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
modifier->SetCallback({
|
||||||
|
.on_change =
|
||||||
|
[this](const Common::Input::CallbackStatus& callback_) {
|
||||||
|
UpdateModButtonStatus(callback_);
|
||||||
|
},
|
||||||
|
});
|
||||||
last_x_axis_value = 0.0f;
|
last_x_axis_value = 0.0f;
|
||||||
last_y_axis_value = 0.0f;
|
last_y_axis_value = 0.0f;
|
||||||
}
|
}
|
||||||
|
@ -133,27 +146,27 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateUpButtonStatus(Common::Input::CallbackStatus button_callback) {
|
void UpdateUpButtonStatus(const Common::Input::CallbackStatus& button_callback) {
|
||||||
up_status = button_callback.button_status.value;
|
up_status = button_callback.button_status.value;
|
||||||
UpdateStatus();
|
UpdateStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateDownButtonStatus(Common::Input::CallbackStatus button_callback) {
|
void UpdateDownButtonStatus(const Common::Input::CallbackStatus& button_callback) {
|
||||||
down_status = button_callback.button_status.value;
|
down_status = button_callback.button_status.value;
|
||||||
UpdateStatus();
|
UpdateStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateLeftButtonStatus(Common::Input::CallbackStatus button_callback) {
|
void UpdateLeftButtonStatus(const Common::Input::CallbackStatus& button_callback) {
|
||||||
left_status = button_callback.button_status.value;
|
left_status = button_callback.button_status.value;
|
||||||
UpdateStatus();
|
UpdateStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateRightButtonStatus(Common::Input::CallbackStatus button_callback) {
|
void UpdateRightButtonStatus(const Common::Input::CallbackStatus& button_callback) {
|
||||||
right_status = button_callback.button_status.value;
|
right_status = button_callback.button_status.value;
|
||||||
UpdateStatus();
|
UpdateStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateModButtonStatus(Common::Input::CallbackStatus button_callback) {
|
void UpdateModButtonStatus(const Common::Input::CallbackStatus& button_callback) {
|
||||||
modifier_status = button_callback.button_status.value;
|
modifier_status = button_callback.button_status.value;
|
||||||
UpdateStatus();
|
UpdateStatus();
|
||||||
}
|
}
|
||||||
|
@ -265,18 +278,18 @@ private:
|
||||||
Button left;
|
Button left;
|
||||||
Button right;
|
Button right;
|
||||||
Button modifier;
|
Button modifier;
|
||||||
float modifier_scale;
|
float modifier_scale{};
|
||||||
float modifier_angle;
|
float modifier_angle{};
|
||||||
float angle{};
|
float angle{};
|
||||||
float goal_angle{};
|
float goal_angle{};
|
||||||
float amplitude{};
|
float amplitude{};
|
||||||
bool up_status;
|
bool up_status{};
|
||||||
bool down_status;
|
bool down_status{};
|
||||||
bool left_status;
|
bool left_status{};
|
||||||
bool right_status;
|
bool right_status{};
|
||||||
bool modifier_status;
|
bool modifier_status{};
|
||||||
float last_x_axis_value;
|
float last_x_axis_value{};
|
||||||
float last_y_axis_value;
|
float last_y_axis_value{};
|
||||||
const Common::Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false};
|
const Common::Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false};
|
||||||
std::chrono::time_point<std::chrono::steady_clock> last_update;
|
std::chrono::time_point<std::chrono::steady_clock> last_update;
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,10 +14,13 @@ public:
|
||||||
using Button = std::unique_ptr<Common::Input::InputDevice>;
|
using Button = std::unique_ptr<Common::Input::InputDevice>;
|
||||||
TouchFromButtonDevice(Button button_, int touch_id_, float x_, float y_)
|
TouchFromButtonDevice(Button button_, int touch_id_, float x_, float y_)
|
||||||
: button(std::move(button_)), touch_id(touch_id_), x(x_), y(y_) {
|
: button(std::move(button_)), touch_id(touch_id_), x(x_), y(y_) {
|
||||||
Common::Input::InputCallback button_up_callback{
|
|
||||||
[this](Common::Input::CallbackStatus callback_) { UpdateButtonStatus(callback_); }};
|
|
||||||
last_button_value = false;
|
last_button_value = false;
|
||||||
button->SetCallback(button_up_callback);
|
button->SetCallback({
|
||||||
|
.on_change =
|
||||||
|
[this](const Common::Input::CallbackStatus& callback_) {
|
||||||
|
UpdateButtonStatus(callback_);
|
||||||
|
},
|
||||||
|
});
|
||||||
button->ForceUpdate();
|
button->ForceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +50,7 @@ public:
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateButtonStatus(Common::Input::CallbackStatus button_callback) {
|
void UpdateButtonStatus(const Common::Input::CallbackStatus& button_callback) {
|
||||||
const Common::Input::CallbackStatus status{
|
const Common::Input::CallbackStatus status{
|
||||||
.type = Common::Input::InputType::Touch,
|
.type = Common::Input::InputType::Touch,
|
||||||
.touch_status = GetStatus(button_callback.button_status.value),
|
.touch_status = GetStatus(button_callback.button_status.value),
|
||||||
|
|
Loading…
Reference in a new issue