aboutsummaryrefslogtreecommitdiff
path: root/src/input_common/helpers/stick_from_buttons.cpp
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2021-12-13 21:09:28 -0500
committerLioncash <mathew1800@gmail.com>2021-12-13 21:22:02 -0500
commite05d2a70b24e550d67fcdd24aae7094ad41745f8 (patch)
treeaf5116d02b99366344c261df03cae992b2e96ae5 /src/input_common/helpers/stick_from_buttons.cpp
parent54eafbaf172309d92c6b2c5069de23fc534dd2d2 (diff)
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.
Diffstat (limited to 'src/input_common/helpers/stick_from_buttons.cpp')
-rw-r--r--src/input_common/helpers/stick_from_buttons.cpp75
1 files changed, 44 insertions, 31 deletions
diff --git a/src/input_common/helpers/stick_from_buttons.cpp b/src/input_common/helpers/stick_from_buttons.cpp
index 77fcd655ed..e23394f5f5 100644
--- a/src/input_common/helpers/stick_from_buttons.cpp
+++ b/src/input_common/helpers/stick_from_buttons.cpp
@@ -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;
};