mirror of
https://github.com/ZDoom/Raze.git
synced 2024-11-15 17:01:28 +00:00
- gamecontrol: Clean up remainder of legacy angle code.
This commit is contained in:
parent
d758a0ae28
commit
e53d58bd42
2 changed files with 151 additions and 306 deletions
|
@ -1436,171 +1436,6 @@ fixed_t getincangleq16(fixed_t a, fixed_t na)
|
|||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// PlayerHorizon struct functions.
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void PlayerHorizon::backup()
|
||||
{
|
||||
ohoriz = horiz;
|
||||
ohorizoff = horizoff;
|
||||
}
|
||||
|
||||
void PlayerHorizon::restore()
|
||||
{
|
||||
horiz = ohoriz;
|
||||
horizoff = ohorizoff;
|
||||
}
|
||||
|
||||
void PlayerHorizon::addadjustment(double value)
|
||||
{
|
||||
if (!cl_syncinput)
|
||||
{
|
||||
adjustment += value;
|
||||
}
|
||||
else
|
||||
{
|
||||
horiz += q16horiz(FloatToFixed(value));
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerHorizon::resetadjustment()
|
||||
{
|
||||
adjustment = 0;
|
||||
}
|
||||
|
||||
void PlayerHorizon::settarget(double value, bool backup)
|
||||
{
|
||||
if (!cl_syncinput)
|
||||
{
|
||||
target = FloatToFixed(value);
|
||||
if (target == 0) target += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
horiz = q16horiz(FloatToFixed(value));
|
||||
if (backup) ohoriz = horiz;
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerHorizon::processhelpers(double const scaleAdjust)
|
||||
{
|
||||
if (target)
|
||||
{
|
||||
horiz += q16horiz(xs_CRoundToInt(scaleAdjust * (target - horiz.asq16())));
|
||||
|
||||
if (abs(horiz.asq16() - target) < FRACUNIT)
|
||||
{
|
||||
horiz = q16horiz(target);
|
||||
target = 0;
|
||||
}
|
||||
}
|
||||
else if (adjustment)
|
||||
{
|
||||
horiz += q16horiz(FloatToFixed(scaleAdjust * adjustment));
|
||||
}
|
||||
}
|
||||
|
||||
fixedhoriz PlayerHorizon::sum()
|
||||
{
|
||||
return horiz + horizoff;
|
||||
}
|
||||
|
||||
fixedhoriz PlayerHorizon::interpolatedsum(double const smoothratio)
|
||||
{
|
||||
fixedhoriz prev = ohoriz + ohorizoff;
|
||||
fixedhoriz curr = horiz + horizoff;
|
||||
return q16horiz(prev.asq16() + mulscale16(curr.asq16() - prev.asq16(), smoothratio));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// PlayerAngle struct functions.
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void PlayerAngle::backup()
|
||||
{
|
||||
oang = ang;
|
||||
olook_ang = look_ang;
|
||||
orotscrnang = rotscrnang;
|
||||
}
|
||||
|
||||
void PlayerAngle::restore()
|
||||
{
|
||||
ang = oang;
|
||||
look_ang = olook_ang;
|
||||
rotscrnang = orotscrnang;
|
||||
}
|
||||
|
||||
void PlayerAngle::addadjustment(double value)
|
||||
{
|
||||
if (!cl_syncinput)
|
||||
{
|
||||
adjustment += value;
|
||||
}
|
||||
else
|
||||
{
|
||||
ang += bamang(xs_CRoundToUInt(value * BAMUNIT));
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerAngle::resetadjustment()
|
||||
{
|
||||
adjustment = 0;
|
||||
}
|
||||
|
||||
void PlayerAngle::settarget(double value, bool backup)
|
||||
{
|
||||
if (!cl_syncinput)
|
||||
{
|
||||
target = bamang(xs_CRoundToUInt(value * BAMUNIT));
|
||||
if (target.asbam() == 0) target += bamang(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ang = bamang(xs_CRoundToUInt(value * BAMUNIT));
|
||||
if (backup) oang = ang;
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerAngle::processhelpers(double const scaleAdjust)
|
||||
{
|
||||
if (target.asbam())
|
||||
{
|
||||
ang = bamang(ang.asbam() + xs_CRoundToInt(scaleAdjust * (target - ang).asbam()));
|
||||
|
||||
if (ang.asbam() - target.asbam() < BAMUNIT)
|
||||
{
|
||||
ang = target;
|
||||
target = bamang(0);
|
||||
}
|
||||
}
|
||||
else if (adjustment)
|
||||
{
|
||||
ang += bamang(xs_CRoundToUInt(scaleAdjust * adjustment * BAMUNIT));
|
||||
}
|
||||
}
|
||||
|
||||
binangle PlayerAngle::sum()
|
||||
{
|
||||
return bamang(ang.asbam() + look_ang.asbam());
|
||||
}
|
||||
|
||||
binangle PlayerAngle::interpolatedsum(double const smoothratio)
|
||||
{
|
||||
auto prev = oang.asbam() + olook_ang.asbam();
|
||||
auto curr = ang.asbam() + look_ang.asbam();
|
||||
return bamang(xs_CRoundToUInt(prev + fmulscale16(curr - prev, smoothratio)));
|
||||
}
|
||||
|
||||
lookangle PlayerAngle::interpolatedrotscrn(double const smoothratio)
|
||||
{
|
||||
return bamlook(xs_CRoundToUInt(orotscrnang.asbam() + fmulscale16(rotscrnang.asbam() - orotscrnang.asbam(), smoothratio)));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Player's movement function, called from game's ticker or from gi->GetInput() as required.
|
||||
|
@ -1854,123 +1689,3 @@ void applylook(PlayerAngle* angle, fixed_t const q16avel, ESyncBits* actions, do
|
|||
angle->ang += degang(FixedToFloat(q16avel));
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Player's angle function, called from game's ticker or from gi->GetInput() as required.
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void applylook2(fixed_t* q16ang, fixed_t* q16look_ang, fixed_t* q16rotscrnang, fixed_t* spin, fixed_t const q16avel, ESyncBits* actions, double const scaleAdjust, bool const crouching)
|
||||
{
|
||||
// return q16rotscrnang to 0 and set to 0 if less than a quarter of a FRACUNIT (16384)
|
||||
*q16rotscrnang -= xs_CRoundToInt(scaleAdjust * (*q16rotscrnang * (15. / GameTicRate)));
|
||||
if (abs(*q16rotscrnang) < (FRACUNIT >> 2)) *q16rotscrnang = 0;
|
||||
|
||||
// return q16look_ang to 0 and set to 0 if less than a quarter of a FRACUNIT (16384)
|
||||
*q16look_ang -= xs_CRoundToInt(scaleAdjust * (*q16look_ang * (7.5 / GameTicRate)));
|
||||
if (abs(*q16look_ang) < (FRACUNIT >> 2)) *q16look_ang = 0;
|
||||
|
||||
if (*actions & SB_LOOK_LEFT)
|
||||
{
|
||||
// start looking left
|
||||
*q16look_ang -= FloatToFixed(scaleAdjust * (4560. / GameTicRate));
|
||||
*q16rotscrnang += FloatToFixed(scaleAdjust * (720. / GameTicRate));
|
||||
}
|
||||
|
||||
if (*actions & SB_LOOK_RIGHT)
|
||||
{
|
||||
// start looking right
|
||||
*q16look_ang += FloatToFixed(scaleAdjust * (4560. / GameTicRate));
|
||||
*q16rotscrnang -= FloatToFixed(scaleAdjust * (720. / GameTicRate));
|
||||
}
|
||||
|
||||
if (*actions & SB_TURNAROUND)
|
||||
{
|
||||
if (*spin == 0)
|
||||
{
|
||||
// currently not spinning, so start a spin
|
||||
*spin = IntToFixed(-1024);
|
||||
}
|
||||
*actions &= ~SB_TURNAROUND;
|
||||
}
|
||||
|
||||
if (*spin < 0)
|
||||
{
|
||||
// return spin to 0
|
||||
fixed_t add = FloatToFixed(scaleAdjust * ((!crouching ? 3840. : 1920.) / GameTicRate));
|
||||
*spin += add;
|
||||
if (*spin > 0)
|
||||
{
|
||||
// Don't overshoot our target. With variable factor this is possible.
|
||||
add -= *spin;
|
||||
*spin = 0;
|
||||
}
|
||||
*q16ang += add;
|
||||
}
|
||||
|
||||
if (q16avel)
|
||||
{
|
||||
// add player's input
|
||||
*q16ang = (*q16ang + q16avel) & 0x7FFFFFF;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Player's ticrate helper functions.
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void playerAddAngle2(fixed_t* q16ang, double* helper, double adjustment)
|
||||
{
|
||||
if (!cl_syncinput)
|
||||
{
|
||||
*helper += adjustment;
|
||||
}
|
||||
else
|
||||
{
|
||||
*q16ang = (*q16ang + FloatToFixed(adjustment)) & 0x7FFFFFF;
|
||||
}
|
||||
}
|
||||
|
||||
void playerSetAngle2(fixed_t* q16ang, fixed_t* helper, double adjustment)
|
||||
{
|
||||
if (!cl_syncinput)
|
||||
{
|
||||
// Add slight offset if adjustment is coming in as absolute 0.
|
||||
if (adjustment == 0) adjustment += (1. / (FRACUNIT >> 1));
|
||||
|
||||
*helper = *q16ang + getincangleq16(*q16ang, FloatToFixed(adjustment));
|
||||
}
|
||||
else
|
||||
{
|
||||
*q16ang = FloatToFixed(adjustment);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Player's ticrate helper processor.
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void playerProcessHelpers(fixed_t* q16ang, double* angAdjust, fixed_t* angTarget, double const scaleAdjust)
|
||||
{
|
||||
// Process angle amendments from the game's ticker.
|
||||
if (*angTarget)
|
||||
{
|
||||
fixed_t angDelta = getincangleq16(*q16ang, *angTarget);
|
||||
*q16ang = (*q16ang + xs_CRoundToInt(scaleAdjust * angDelta));
|
||||
|
||||
if (abs(*q16ang - *angTarget) < FRACUNIT)
|
||||
{
|
||||
*q16ang = *angTarget;
|
||||
*angTarget = 0;
|
||||
}
|
||||
}
|
||||
else if (*angAdjust)
|
||||
{
|
||||
*q16ang = (*q16ang + FloatToFixed(scaleAdjust * *angAdjust)) & 0x7FFFFFF;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,14 +74,78 @@ struct PlayerHorizon
|
|||
fixed_t target;
|
||||
double adjustment;
|
||||
|
||||
void backup();
|
||||
void restore();
|
||||
void addadjustment(double value);
|
||||
void resetadjustment();
|
||||
void settarget(double value, bool backup = false);
|
||||
void processhelpers(double const scaleAdjust);
|
||||
fixedhoriz sum();
|
||||
fixedhoriz interpolatedsum(double const smoothratio);
|
||||
void backup()
|
||||
{
|
||||
ohoriz = horiz;
|
||||
ohorizoff = horizoff;
|
||||
}
|
||||
|
||||
void restore()
|
||||
{
|
||||
horiz = ohoriz;
|
||||
horizoff = ohorizoff;
|
||||
}
|
||||
|
||||
void addadjustment(double value)
|
||||
{
|
||||
if (!cl_syncinput)
|
||||
{
|
||||
adjustment += value;
|
||||
}
|
||||
else
|
||||
{
|
||||
horiz += q16horiz(FloatToFixed(value));
|
||||
}
|
||||
}
|
||||
|
||||
void resetadjustment()
|
||||
{
|
||||
adjustment = 0;
|
||||
}
|
||||
|
||||
void settarget(double value, bool backup = false)
|
||||
{
|
||||
if (!cl_syncinput)
|
||||
{
|
||||
target = FloatToFixed(value);
|
||||
if (target == 0) target += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
horiz = q16horiz(FloatToFixed(value));
|
||||
if (backup) ohoriz = horiz;
|
||||
}
|
||||
}
|
||||
|
||||
void processhelpers(double const scaleAdjust)
|
||||
{
|
||||
if (target)
|
||||
{
|
||||
horiz += q16horiz(xs_CRoundToInt(scaleAdjust * (target - horiz.asq16())));
|
||||
|
||||
if (abs(horiz.asq16() - target) < FRACUNIT)
|
||||
{
|
||||
horiz = q16horiz(target);
|
||||
target = 0;
|
||||
}
|
||||
}
|
||||
else if (adjustment)
|
||||
{
|
||||
horiz += q16horiz(FloatToFixed(scaleAdjust * adjustment));
|
||||
}
|
||||
}
|
||||
|
||||
fixedhoriz sum()
|
||||
{
|
||||
return horiz + horizoff;
|
||||
}
|
||||
|
||||
fixedhoriz interpolatedsum(double const smoothratio)
|
||||
{
|
||||
fixedhoriz prev = ohoriz + ohorizoff;
|
||||
fixedhoriz curr = horiz + horizoff;
|
||||
return q16horiz(prev.asq16() + mulscale16(curr.asq16() - prev.asq16(), smoothratio));
|
||||
}
|
||||
};
|
||||
|
||||
struct PlayerAngle
|
||||
|
@ -90,24 +154,90 @@ struct PlayerAngle
|
|||
lookangle look_ang, olook_ang, rotscrnang, orotscrnang, spin;
|
||||
double adjustment;
|
||||
|
||||
void backup();
|
||||
void restore();
|
||||
void addadjustment(double value);
|
||||
void resetadjustment();
|
||||
void settarget(double value, bool backup = false);
|
||||
void processhelpers(double const scaleAdjust);
|
||||
binangle sum();
|
||||
binangle interpolatedsum(double const smoothratio);
|
||||
lookangle interpolatedrotscrn(double const smoothratio);
|
||||
void backup()
|
||||
{
|
||||
oang = ang;
|
||||
olook_ang = look_ang;
|
||||
orotscrnang = rotscrnang;
|
||||
}
|
||||
|
||||
void restore()
|
||||
{
|
||||
ang = oang;
|
||||
look_ang = olook_ang;
|
||||
rotscrnang = orotscrnang;
|
||||
}
|
||||
|
||||
void addadjustment(double value)
|
||||
{
|
||||
if (!cl_syncinput)
|
||||
{
|
||||
adjustment += value;
|
||||
}
|
||||
else
|
||||
{
|
||||
ang += bamang(xs_CRoundToUInt(value * BAMUNIT));
|
||||
}
|
||||
}
|
||||
|
||||
void resetadjustment()
|
||||
{
|
||||
adjustment = 0;
|
||||
}
|
||||
|
||||
void settarget(double value, bool backup = false)
|
||||
{
|
||||
if (!cl_syncinput)
|
||||
{
|
||||
target = bamang(xs_CRoundToUInt(value * BAMUNIT));
|
||||
if (target.asbam() == 0) target += bamang(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ang = bamang(xs_CRoundToUInt(value * BAMUNIT));
|
||||
if (backup) oang = ang;
|
||||
}
|
||||
}
|
||||
|
||||
void processhelpers(double const scaleAdjust)
|
||||
{
|
||||
if (target.asbam())
|
||||
{
|
||||
ang = bamang(ang.asbam() + xs_CRoundToInt(scaleAdjust * (target - ang).asbam()));
|
||||
|
||||
if (ang.asbam() - target.asbam() < BAMUNIT)
|
||||
{
|
||||
ang = target;
|
||||
target = bamang(0);
|
||||
}
|
||||
}
|
||||
else if (adjustment)
|
||||
{
|
||||
ang += bamang(xs_CRoundToUInt(scaleAdjust * adjustment * BAMUNIT));
|
||||
}
|
||||
}
|
||||
|
||||
binangle sum()
|
||||
{
|
||||
return bamang(ang.asbam() + look_ang.asbam());
|
||||
}
|
||||
|
||||
binangle interpolatedsum(double const smoothratio)
|
||||
{
|
||||
auto prev = oang.asbam() + olook_ang.asbam();
|
||||
auto curr = ang.asbam() + look_ang.asbam();
|
||||
return bamang(xs_CRoundToUInt(prev + fmulscale16(curr - prev, smoothratio)));
|
||||
}
|
||||
|
||||
lookangle interpolatedrotscrn(double const smoothratio)
|
||||
{
|
||||
return bamlook(xs_CRoundToUInt(orotscrnang.asbam() + fmulscale16(rotscrnang.asbam() - orotscrnang.asbam(), smoothratio)));
|
||||
}
|
||||
};
|
||||
|
||||
void processMovement(InputPacket* currInput, InputPacket* inputBuffer, ControlInfo* const hidInput, double const scaleAdjust, int const drink_amt = 0, bool const allowstrafe = true, double const turnscale = 1);
|
||||
void sethorizon(fixedhoriz* horiz, float const horz, ESyncBits* actions, double const scaleAdjust);
|
||||
void applylook(PlayerAngle* angle, fixed_t const q16avel, ESyncBits* actions, double const scaleAdjust, bool const crouching);
|
||||
void applylook2(fixed_t* q16ang, fixed_t* q16look_ang, fixed_t* q16rotscrnang, fixed_t* spin, fixed_t const q16avel, ESyncBits* actions, double const scaleAdjust, bool const crouching);
|
||||
void playerAddAngle2(fixed_t* q16ang, double* helper, double adjustment);
|
||||
void playerSetAngle2(fixed_t* q16ang, fixed_t* helper, double adjustment);
|
||||
void playerProcessHelpers(fixed_t* q16ang, double* angAdjust, fixed_t* angTarget, double const scaleAdjust);
|
||||
|
||||
struct UserConfig
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue