Merge pull request #7581 from lioncash/input-iface
common/input: Avoid numerous large copies of CallbackStatus
This commit is contained in:
commit
5e732e7aec
10 changed files with 192 additions and 155 deletions
|
@ -19,23 +19,36 @@ public:
|
|||
: up(std::move(up_)), down(std::move(down_)), left(std::move(left_)),
|
||||
right(std::move(right_)), modifier(std::move(modifier_)), modifier_scale(modifier_scale_),
|
||||
modifier_angle(modifier_angle_) {
|
||||
Common::Input::InputCallback button_up_callback{
|
||||
[this](Common::Input::CallbackStatus callback_) { UpdateUpButtonStatus(callback_); }};
|
||||
Common::Input::InputCallback button_down_callback{
|
||||
[this](Common::Input::CallbackStatus callback_) { UpdateDownButtonStatus(callback_); }};
|
||||
Common::Input::InputCallback button_left_callback{
|
||||
[this](Common::Input::CallbackStatus callback_) { UpdateLeftButtonStatus(callback_); }};
|
||||
Common::Input::InputCallback button_right_callback{
|
||||
[this](Common::Input::CallbackStatus callback_) {
|
||||
UpdateRightButtonStatus(callback_);
|
||||
}};
|
||||
Common::Input::InputCallback button_modifier_callback{
|
||||
[this](Common::Input::CallbackStatus callback_) { UpdateModButtonStatus(callback_); }};
|
||||
up->SetCallback(button_up_callback);
|
||||
down->SetCallback(button_down_callback);
|
||||
left->SetCallback(button_left_callback);
|
||||
right->SetCallback(button_right_callback);
|
||||
modifier->SetCallback(button_modifier_callback);
|
||||
up->SetCallback({
|
||||
.on_change =
|
||||
[this](const Common::Input::CallbackStatus& callback_) {
|
||||
UpdateUpButtonStatus(callback_);
|
||||
},
|
||||
});
|
||||
down->SetCallback({
|
||||
.on_change =
|
||||
[this](const Common::Input::CallbackStatus& callback_) {
|
||||
UpdateDownButtonStatus(callback_);
|
||||
},
|
||||
});
|
||||
left->SetCallback({
|
||||
.on_change =
|
||||
[this](const Common::Input::CallbackStatus& callback_) {
|
||||
UpdateLeftButtonStatus(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_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;
|
||||
UpdateStatus();
|
||||
}
|
||||
|
||||
void UpdateDownButtonStatus(Common::Input::CallbackStatus button_callback) {
|
||||
void UpdateDownButtonStatus(const Common::Input::CallbackStatus& button_callback) {
|
||||
down_status = button_callback.button_status.value;
|
||||
UpdateStatus();
|
||||
}
|
||||
|
||||
void UpdateLeftButtonStatus(Common::Input::CallbackStatus button_callback) {
|
||||
void UpdateLeftButtonStatus(const Common::Input::CallbackStatus& button_callback) {
|
||||
left_status = button_callback.button_status.value;
|
||||
UpdateStatus();
|
||||
}
|
||||
|
||||
void UpdateRightButtonStatus(Common::Input::CallbackStatus button_callback) {
|
||||
void UpdateRightButtonStatus(const Common::Input::CallbackStatus& button_callback) {
|
||||
right_status = button_callback.button_status.value;
|
||||
UpdateStatus();
|
||||
}
|
||||
|
||||
void UpdateModButtonStatus(Common::Input::CallbackStatus button_callback) {
|
||||
void UpdateModButtonStatus(const Common::Input::CallbackStatus& button_callback) {
|
||||
modifier_status = button_callback.button_status.value;
|
||||
UpdateStatus();
|
||||
}
|
||||
|
@ -265,18 +278,18 @@ private:
|
|||
Button left;
|
||||
Button right;
|
||||
Button modifier;
|
||||
float modifier_scale;
|
||||
float modifier_angle;
|
||||
float modifier_scale{};
|
||||
float modifier_angle{};
|
||||
float angle{};
|
||||
float goal_angle{};
|
||||
float amplitude{};
|
||||
bool up_status;
|
||||
bool down_status;
|
||||
bool left_status;
|
||||
bool right_status;
|
||||
bool modifier_status;
|
||||
float last_x_axis_value;
|
||||
float last_y_axis_value;
|
||||
bool up_status{};
|
||||
bool down_status{};
|
||||
bool left_status{};
|
||||
bool right_status{};
|
||||
bool modifier_status{};
|
||||
float last_x_axis_value{};
|
||||
float last_y_axis_value{};
|
||||
const Common::Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false};
|
||||
std::chrono::time_point<std::chrono::steady_clock> last_update;
|
||||
};
|
||||
|
|
|
@ -14,10 +14,13 @@ public:
|
|||
using Button = std::unique_ptr<Common::Input::InputDevice>;
|
||||
TouchFromButtonDevice(Button button_, int touch_id_, float x_, float 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;
|
||||
button->SetCallback(button_up_callback);
|
||||
button->SetCallback({
|
||||
.on_change =
|
||||
[this](const Common::Input::CallbackStatus& callback_) {
|
||||
UpdateButtonStatus(callback_);
|
||||
},
|
||||
});
|
||||
button->ForceUpdate();
|
||||
}
|
||||
|
||||
|
@ -47,7 +50,7 @@ public:
|
|||
return status;
|
||||
}
|
||||
|
||||
void UpdateButtonStatus(Common::Input::CallbackStatus button_callback) {
|
||||
void UpdateButtonStatus(const Common::Input::CallbackStatus& button_callback) {
|
||||
const Common::Input::CallbackStatus status{
|
||||
.type = Common::Input::InputType::Touch,
|
||||
.touch_status = GetStatus(button_callback.button_status.value),
|
||||
|
|
|
@ -12,8 +12,7 @@ namespace InputCommon {
|
|||
|
||||
class DummyInput final : public Common::Input::InputDevice {
|
||||
public:
|
||||
explicit DummyInput() {}
|
||||
~DummyInput() {}
|
||||
explicit DummyInput() = default;
|
||||
};
|
||||
|
||||
class InputFromButton final : public Common::Input::InputDevice {
|
||||
|
@ -33,7 +32,7 @@ public:
|
|||
callback_key = input_engine->SetCallback(input_identifier);
|
||||
}
|
||||
|
||||
~InputFromButton() {
|
||||
~InputFromButton() override {
|
||||
input_engine->DeleteCallback(callback_key);
|
||||
}
|
||||
|
||||
|
@ -45,7 +44,7 @@ public:
|
|||
};
|
||||
}
|
||||
|
||||
void ForceUpdate() {
|
||||
void ForceUpdate() override {
|
||||
const Common::Input::CallbackStatus status{
|
||||
.type = Common::Input::InputType::Button,
|
||||
.button_status = GetStatus(),
|
||||
|
@ -94,7 +93,7 @@ public:
|
|||
callback_key = input_engine->SetCallback(input_identifier);
|
||||
}
|
||||
|
||||
~InputFromHatButton() {
|
||||
~InputFromHatButton() override {
|
||||
input_engine->DeleteCallback(callback_key);
|
||||
}
|
||||
|
||||
|
@ -106,7 +105,7 @@ public:
|
|||
};
|
||||
}
|
||||
|
||||
void ForceUpdate() {
|
||||
void ForceUpdate() override {
|
||||
const Common::Input::CallbackStatus status{
|
||||
.type = Common::Input::InputType::Button,
|
||||
.button_status = GetStatus(),
|
||||
|
@ -167,7 +166,7 @@ public:
|
|||
callback_key_y = input_engine->SetCallback(y_input_identifier);
|
||||
}
|
||||
|
||||
~InputFromStick() {
|
||||
~InputFromStick() override {
|
||||
input_engine->DeleteCallback(callback_key_x);
|
||||
input_engine->DeleteCallback(callback_key_y);
|
||||
}
|
||||
|
@ -190,7 +189,7 @@ public:
|
|||
return status;
|
||||
}
|
||||
|
||||
void ForceUpdate() {
|
||||
void ForceUpdate() override {
|
||||
const Common::Input::CallbackStatus status{
|
||||
.type = Common::Input::InputType::Stick,
|
||||
.stick_status = GetStatus(),
|
||||
|
@ -266,7 +265,7 @@ public:
|
|||
callback_key_y = input_engine->SetCallback(y_input_identifier);
|
||||
}
|
||||
|
||||
~InputFromTouch() {
|
||||
~InputFromTouch() override {
|
||||
input_engine->DeleteCallback(callback_key_button);
|
||||
input_engine->DeleteCallback(callback_key_x);
|
||||
input_engine->DeleteCallback(callback_key_y);
|
||||
|
@ -352,7 +351,7 @@ public:
|
|||
axis_callback_key = input_engine->SetCallback(axis_input_identifier);
|
||||
}
|
||||
|
||||
~InputFromTrigger() {
|
||||
~InputFromTrigger() override {
|
||||
input_engine->DeleteCallback(callback_key_button);
|
||||
input_engine->DeleteCallback(axis_callback_key);
|
||||
}
|
||||
|
@ -419,7 +418,7 @@ public:
|
|||
callback_key = input_engine->SetCallback(input_identifier);
|
||||
}
|
||||
|
||||
~InputFromAnalog() {
|
||||
~InputFromAnalog() override {
|
||||
input_engine->DeleteCallback(callback_key);
|
||||
}
|
||||
|
||||
|
@ -466,7 +465,7 @@ public:
|
|||
callback_key = input_engine->SetCallback(input_identifier);
|
||||
}
|
||||
|
||||
~InputFromBattery() {
|
||||
~InputFromBattery() override {
|
||||
input_engine->DeleteCallback(callback_key);
|
||||
}
|
||||
|
||||
|
@ -474,7 +473,7 @@ public:
|
|||
return static_cast<Common::Input::BatteryLevel>(input_engine->GetBattery(identifier));
|
||||
}
|
||||
|
||||
void ForceUpdate() {
|
||||
void ForceUpdate() override {
|
||||
const Common::Input::CallbackStatus status{
|
||||
.type = Common::Input::InputType::Battery,
|
||||
.battery_status = GetStatus(),
|
||||
|
@ -518,7 +517,7 @@ public:
|
|||
callback_key = input_engine->SetCallback(input_identifier);
|
||||
}
|
||||
|
||||
~InputFromMotion() {
|
||||
~InputFromMotion() override {
|
||||
input_engine->DeleteCallback(callback_key);
|
||||
}
|
||||
|
||||
|
@ -593,7 +592,7 @@ public:
|
|||
callback_key_z = input_engine->SetCallback(z_input_identifier);
|
||||
}
|
||||
|
||||
~InputFromAxisMotion() {
|
||||
~InputFromAxisMotion() override {
|
||||
input_engine->DeleteCallback(callback_key_x);
|
||||
input_engine->DeleteCallback(callback_key_y);
|
||||
input_engine->DeleteCallback(callback_key_z);
|
||||
|
@ -618,7 +617,7 @@ public:
|
|||
return status;
|
||||
}
|
||||
|
||||
void ForceUpdate() {
|
||||
void ForceUpdate() override {
|
||||
const Common::Input::CallbackStatus status{
|
||||
.type = Common::Input::InputType::Motion,
|
||||
.motion_status = GetStatus(),
|
||||
|
@ -668,16 +667,16 @@ public:
|
|||
explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_)
|
||||
: identifier(identifier_), input_engine(input_engine_) {}
|
||||
|
||||
virtual void SetLED(const Common::Input::LedStatus& led_status) {
|
||||
void SetLED(const Common::Input::LedStatus& led_status) override {
|
||||
input_engine->SetLeds(identifier, led_status);
|
||||
}
|
||||
|
||||
virtual Common::Input::VibrationError SetVibration(
|
||||
const Common::Input::VibrationStatus& vibration_status) {
|
||||
Common::Input::VibrationError SetVibration(
|
||||
const Common::Input::VibrationStatus& vibration_status) override {
|
||||
return input_engine->SetRumble(identifier, vibration_status);
|
||||
}
|
||||
|
||||
virtual Common::Input::PollingError SetPollingMode(Common::Input::PollingMode polling_mode) {
|
||||
Common::Input::PollingError SetPollingMode(Common::Input::PollingMode polling_mode) override {
|
||||
return input_engine->SetPollingMode(identifier, polling_mode);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue