Skip to content

Commit

Permalink
- Move some PlayerHorizon/PlayerAngle class methods out into inli…
Browse files Browse the repository at this point in the history
…nes 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.
  • Loading branch information
mjr4077au committed Jul 23, 2022
1 parent 7856d30 commit 1906491
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 56 deletions.
56 changes: 49 additions & 7 deletions source/core/gameinput.cpp
Expand Up @@ -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).
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
{
Expand Down
49 changes: 0 additions & 49 deletions source/core/gameinput.h
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 1906491

Please sign in to comment.