From 5050947dcaaa769e0739591e5fd978169f37a64b Mon Sep 17 00:00:00 2001 From: Mitch Richters Date: Sat, 6 Nov 2021 17:57:00 +1100 Subject: [PATCH] - `PlayerAngle::applyinput()`: Consolidate some mostly duplicated code into a lambda. --- source/core/gameinput.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index 1742c7807..a643719e7 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -389,19 +389,17 @@ void PlayerAngle::applyinput(float const avel, ESyncBits* actions, double const if (abs(look_ang.signedbam()) < (BAMUNIT >> 2)) look_ang = bamang(0); } - if (*actions & SB_LOOK_LEFT) + // Process keyboard input. + auto doLookKeys = [&](ESyncBits_ const key, double const direction) { - // start looking left - look_ang -= getscaledangle(LOOKINGSPEED, scaleAdjust); - rotscrnang += getscaledangle(ROTATESPEED, scaleAdjust); - } - - if (*actions & SB_LOOK_RIGHT) - { - // start looking right - look_ang += getscaledangle(LOOKINGSPEED, scaleAdjust); - rotscrnang -= getscaledangle(ROTATESPEED, scaleAdjust); - } + if (*actions & key) + { + look_ang += getscaledangle(LOOKINGSPEED, scaleAdjust * direction); + rotscrnang -= getscaledangle(ROTATESPEED, scaleAdjust * direction); + } + }; + doLookKeys(SB_LOOK_LEFT, -1); + doLookKeys(SB_LOOK_RIGHT, 1); if (!movementlocked()) {