From 902e242194f58c1ca4f23e5ca3bac5c37aaf6113 Mon Sep 17 00:00:00 2001 From: Kp Date: Fri, 28 Oct 2016 03:39:40 +0000 Subject: [PATCH] Remove redundant store in kconfig_read_controls Adjust the value as a local, then write it back when finished. --- similar/main/kconfig.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/similar/main/kconfig.cpp b/similar/main/kconfig.cpp index 7cf76d44a..f7432cfa2 100644 --- a/similar/main/kconfig.cpp +++ b/similar/main/kconfig.cpp @@ -1725,9 +1725,7 @@ void kconfig_read_controls(const d_event &event, int automap_flag) break; const auto &av = event_joystick_get_axis(event); const auto &axis = av.axis; - const auto &value = av.value; - - Controls.raw_joy_axis[axis] = value; + auto value = av.value; if (axis == kcm_joystick[13].value) // Pitch U/D Deadzone joy_null_value = PlayerCfg.JoystickDead[1]*8; @@ -1742,12 +1740,13 @@ void kconfig_read_controls(const d_event &event, int automap_flag) else if (axis == kcm_joystick[23].value) // Throttle - default deadzone joy_null_value = PlayerCfg.JoystickDead[5]*3; - if (Controls.raw_joy_axis[axis] > joy_null_value) - Controls.raw_joy_axis[axis] = ((Controls.raw_joy_axis[axis]-joy_null_value)*128)/(128-joy_null_value); - else if (Controls.raw_joy_axis[axis] < -joy_null_value) - Controls.raw_joy_axis[axis] = ((Controls.raw_joy_axis[axis]+joy_null_value)*128)/(128-joy_null_value); + if (value > joy_null_value) + value = ((value - joy_null_value) * 128) / (128 - joy_null_value); + else if (value < -joy_null_value) + value = ((value + joy_null_value) * 128) / (128 - joy_null_value); else - Controls.raw_joy_axis[axis] = 0; + value = 0; + Controls.raw_joy_axis[axis] = value; break; } #endif