From 1906491129deeea89b0578ff01c3f5e4ff746e08 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Fri, 22 Jul 2022 14:56:38 +1000 Subject: [PATCH] - Move some `PlayerHorizon`/`PlayerAngle` class methods out into inlines in `gameinput.cpp`. * These class methods did nothing with the objects inside the class, they worked generically so they're better as inlines. * Also tidied up some of the internals so they're easier to read. --- source/core/gameinput.cpp | 56 ++++++++++++++++++++++++++++++++++----- source/core/gameinput.h | 49 ---------------------------------- 2 files changed, 49 insertions(+), 56 deletions(-) diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index f40292ad51f..edaa1c5acf7 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -64,6 +64,52 @@ binangle getincanglebam(binangle a, binangle na) return bamang(uint32_t(newa-cura)); } + +//--------------------------------------------------------------------------- +// +// Input scale helper functions. +// +//--------------------------------------------------------------------------- + +inline static double getTicrateScale(const double value) +{ + return value * (1. / GameTicRate); +} + +inline static double getPushScale(const double scaleAdjust) +{ + return (2. / 9.) * (scaleAdjust < 1. ? (1. - scaleAdjust * 0.5) * 1.5 : 1.); +} + +inline static fixedhoriz getscaledhoriz(const double value, const double scaleAdjust, const fixedhoriz& object, const double push) +{ + return buildfhoriz(scaleAdjust * ((object.asbuildf() * getTicrateScale(value)) + push)); +} + +inline static binangle getscaledangle(const double value, const double scaleAdjust, const binangle& object, const double push) +{ + return buildfang(scaleAdjust * ((object.signedbuildf() * getTicrateScale(value)) + push)); +} + +inline static void scaletozero(fixedhoriz& object, const double value, const double scaleAdjust, const double push = DBL_MAX) +{ + if (auto sgn = Sgn(object.asq16())) + { + object -= getscaledhoriz(value, scaleAdjust, object, push == DBL_MAX ? sgn * getPushScale(scaleAdjust) : push); + if (sgn != Sgn(object.asq16())) object = q16horiz(0); + } +} + +inline static void scaletozero(binangle& object, const double value, const double scaleAdjust, const double push = DBL_MAX) +{ + if (auto sgn = Sgn(object.signedbam())) + { + object -= getscaledangle(value, scaleAdjust, object, push == DBL_MAX ? sgn * getPushScale(scaleAdjust) : push); + if (sgn != Sgn(object.signedbam())) object = bamang(0); + } +} + + //--------------------------------------------------------------------------- // // Functions for determining whether its turbo turn time (turn key held for a number of tics). @@ -375,8 +421,8 @@ void PlayerAngle::applyinput(float const avel, ESyncBits* actions, double const { if (*actions & key) { - look_ang += getscaledangle(LOOKINGSPEED, scaleAdjust * direction); - rotscrnang -= getscaledangle(ROTATESPEED, scaleAdjust * direction); + look_ang += buildfang(getTicrateScale(LOOKINGSPEED) * scaleAdjust * direction); + rotscrnang -= buildfang(getTicrateScale(ROTATESPEED) * scaleAdjust * direction); } }; doLookKeys(SB_LOOK_LEFT, -1); @@ -480,11 +526,7 @@ void PlayerHorizon::calcviewpitch(vec2_t const pos, binangle const ang, bool con if (climbing) { // tilt when climbing but you can't even really tell it. - if (horizoff.asq16() < IntToFixed(100)) - { - auto temphorizoff = buildhoriz(100) - horizoff; - horizoff += getscaledhoriz(4.375, scaleAdjust, &temphorizoff, 1.); - } + if (horizoff.asq16() < IntToFixed(100)) horizoff += getscaledhoriz(4.375, scaleAdjust, buildhoriz(100) - horizoff, 1.); } else { diff --git a/source/core/gameinput.h b/source/core/gameinput.h index dffabff757d..29fbb39424d 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -9,25 +9,6 @@ int getincangle(int a, int na); binangle getincanglebam(binangle a, binangle na); - -//--------------------------------------------------------------------------- -// -// Function for dividing an input value by current ticrate for angle/horiz scaling. -// -//--------------------------------------------------------------------------- - -inline double getTicrateScale(double const value) -{ - return value / GameTicRate; -} - -inline double getPushScale(double const scaleAdjust) -{ - return (2. / 9.) * ((scaleAdjust < 1.) ? ((1. - scaleAdjust * 0.5) * 1.5) : (1.)); -} - - - struct PlayerHorizon { fixedhoriz horiz, ohoriz, horizoff, ohorizoff; @@ -67,21 +48,6 @@ struct PlayerHorizon // Draw code helpers. double horizsumfrac(double const smoothratio) { return (!SyncInput() ? sum() : interpolatedsum(smoothratio)).asbuildf() * (1. / 16.); } - // Ticrate scale helpers. - fixedhoriz getscaledhoriz(double const value, double const scaleAdjust = 1., fixedhoriz* const object = nullptr, double const push = 0.) - { - return buildfhoriz(scaleAdjust * (((object ? object->asbuildf() : 1.) * getTicrateScale(value)) + push)); - } - void scaletozero(fixedhoriz& object, double const value, double const scaleAdjust, double const push = DBL_MAX) - { - if (object.asq16()) - { - auto sgn = Sgn(object.asq16()); - object -= getscaledhoriz(value, scaleAdjust, &object, push == DBL_MAX ? sgn * getPushScale(scaleAdjust) : push); - if (sgn != Sgn(object.asq16())) object = q16horiz(0); - } - } - // Ticrate playsim adjustment setters and processor. void addadjustment(fixedhoriz const value) { @@ -183,21 +149,6 @@ struct PlayerAngle double look_anghalf(double const smoothratio) { return (!SyncInput() ? look_ang : interpolatedlookang(smoothratio)).signedbuildf() * 0.5; } double looking_arc(double const smoothratio) { return fabs((!SyncInput() ? look_ang : interpolatedlookang(smoothratio)).signedbuildf()) * (1. / 9.); } - // Ticrate scale helpers. - binangle getscaledangle(double const value, double const scaleAdjust = 1., binangle* const object = nullptr, double const push = 0.) - { - return buildfang(scaleAdjust * (((object ? object->signedbuildf() : 1.) * getTicrateScale(value)) + push)); - } - void scaletozero(binangle& object, double const value, double const scaleAdjust, double const push = DBL_MAX) - { - if (object.asbam()) - { - auto sgn = Sgn(object.signedbam()); - object -= getscaledangle(value, scaleAdjust, &object, push == DBL_MAX ? sgn * getPushScale(scaleAdjust) : push); - if (sgn != Sgn(object.signedbam())) object = bamang(0); - } - } - // Ticrate playsim adjustment setters and processor. void addadjustment(binangle const value) {