2020-10-11 14:33:43 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "m_fixed.h"
|
|
|
|
#include "gamecvars.h"
|
2021-04-02 11:46:43 +00:00
|
|
|
#include "gamestruct.h"
|
2022-08-28 04:19:04 +00:00
|
|
|
#include "gamefuncs.h"
|
2020-10-11 14:33:43 +00:00
|
|
|
#include "packet.h"
|
|
|
|
|
2022-11-25 06:09:11 +00:00
|
|
|
struct PlayerAngles
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-11-25 06:09:11 +00:00
|
|
|
friend FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, PlayerAngles* def);
|
2021-07-18 09:25:41 +00:00
|
|
|
|
2022-11-25 06:09:11 +00:00
|
|
|
// Prototypes for applying input.
|
2022-11-25 05:43:37 +00:00
|
|
|
void applyPitch(float const horz, ESyncBits* actions, double const scaleAdjust = 1);
|
2022-11-25 06:09:11 +00:00
|
|
|
void applyYaw(float const avel, ESyncBits* actions, double const scaleAdjust = 1);
|
2021-03-31 08:44:50 +00:00
|
|
|
|
2022-11-25 06:09:11 +00:00
|
|
|
// Prototypes for applying view.
|
|
|
|
void doViewPitch(const DVector2& pos, DAngle const ang, bool const aimmode, bool const canslopetilt, sectortype* const cursectnum, double const scaleAdjust = 1, bool const climbing = false);
|
2021-07-18 09:25:41 +00:00
|
|
|
|
2022-11-25 06:09:11 +00:00
|
|
|
// Pitch methods.
|
2022-11-25 05:41:51 +00:00
|
|
|
void lockPitch() { legacyDisabledPitch = true; }
|
|
|
|
void unlockPitch() { legacyDisabledPitch = false; }
|
2022-11-25 06:09:11 +00:00
|
|
|
bool targetedPitch() { return legacyTargetPitch.Sgn(); }
|
2022-11-25 05:41:51 +00:00
|
|
|
bool lockedPitch() { return targetedPitch() || legacyDisabledPitch; }
|
2022-11-27 02:56:35 +00:00
|
|
|
void addPitch(DAngle const value)
|
2022-05-30 10:35:41 +00:00
|
|
|
{
|
|
|
|
if (!SyncInput())
|
|
|
|
{
|
2022-11-25 05:41:51 +00:00
|
|
|
legacyAdjustmentPitch += value;
|
2022-05-30 10:35:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-11-25 03:48:31 +00:00
|
|
|
ZzHORIZON += value;
|
2022-05-30 10:35:41 +00:00
|
|
|
}
|
|
|
|
}
|
2022-11-27 02:56:35 +00:00
|
|
|
void setPitch(DAngle value, bool const backup = false)
|
2022-05-30 10:35:41 +00:00
|
|
|
{
|
2022-06-05 11:24:50 +00:00
|
|
|
// Clamp incoming variable because sometimes the caller can exceed bounds.
|
2022-09-28 03:39:01 +00:00
|
|
|
value = ClampViewPitch(value);
|
2022-05-30 10:35:41 +00:00
|
|
|
|
2022-06-06 08:41:45 +00:00
|
|
|
if (!SyncInput() && !backup)
|
2022-05-30 10:35:41 +00:00
|
|
|
{
|
2022-11-25 05:41:51 +00:00
|
|
|
legacyTargetPitch = value.Sgn() ? value : minAngle;
|
2022-05-30 10:35:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-11-25 03:48:31 +00:00
|
|
|
ZzHORIZON = value;
|
2022-11-25 03:51:53 +00:00
|
|
|
if (backup) ZzOLDHORIZON = ZzHORIZON;
|
2022-05-30 10:35:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-25 06:09:11 +00:00
|
|
|
// Yaw methods.
|
|
|
|
void lockYaw() { legacyDisabledYaw = true; }
|
|
|
|
void unlockYaw() { legacyDisabledYaw = false; }
|
|
|
|
bool targetedYaw() { return legacyTargetYaw.Sgn(); }
|
|
|
|
bool lockedYaw() { return targetedYaw() || legacyDisabledYaw; }
|
|
|
|
void addYaw(const DAngle value)
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-11-25 06:09:11 +00:00
|
|
|
if (!SyncInput())
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-11-25 06:09:11 +00:00
|
|
|
legacyAdjustmentYaw += value.Normalized180();
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
2022-11-25 06:09:11 +00:00
|
|
|
else
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-11-25 06:09:11 +00:00
|
|
|
ZzANGLE += value;
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-25 06:09:11 +00:00
|
|
|
void setYaw(const DAngle value, bool const backup = false)
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-11-25 06:09:11 +00:00
|
|
|
if (!SyncInput() && !backup)
|
|
|
|
{
|
|
|
|
legacyTargetYaw = value.Sgn() ? value : minAngle;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ZzANGLE = value;
|
|
|
|
if (backup) ZzOLDANGLE = ZzANGLE;
|
|
|
|
}
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
|
2022-11-25 06:09:11 +00:00
|
|
|
// Miscellaneous helpers.
|
2022-11-25 05:46:48 +00:00
|
|
|
double angLOOKANGHALF(double const interpfrac) { return angRENDERLOOKANG(interpfrac).Normalized180().Degrees() * (128. / 45.); }
|
|
|
|
double angLOOKINGARC(double const interpfrac) { return fabs(angRENDERLOOKANG(interpfrac).Normalized180().Degrees() * (1024. / 1620.)); }
|
2021-07-18 09:25:41 +00:00
|
|
|
|
2022-10-16 07:33:42 +00:00
|
|
|
// Crosshair x/y offsets based on look_ang's tangent.
|
2022-11-25 05:46:48 +00:00
|
|
|
DVector2 angCROSSHAIROFFSETS(const double interpfrac)
|
2022-10-16 07:33:42 +00:00
|
|
|
{
|
2022-11-25 05:46:48 +00:00
|
|
|
return DVector2(159.72, 145.5 * angRENDERROTSCRN(interpfrac).Sin()) * -angRENDERLOOKANG(interpfrac).Tan() * (1. / tan(r_fov * pi::pi() / 360.));
|
2022-10-16 07:33:42 +00:00
|
|
|
}
|
|
|
|
|
2022-10-13 05:06:05 +00:00
|
|
|
// Weapon x/y offsets based on the above.
|
2022-11-25 05:46:48 +00:00
|
|
|
DVector2 angWEAPONOFFSETS(const double interpfrac)
|
2022-10-13 05:06:05 +00:00
|
|
|
{
|
2022-11-25 05:46:48 +00:00
|
|
|
auto offsets = angCROSSHAIROFFSETS(interpfrac); offsets.Y = abs(offsets.Y) * 4.;
|
2022-10-13 05:06:05 +00:00
|
|
|
return offsets;
|
|
|
|
}
|
|
|
|
|
2022-11-25 06:09:11 +00:00
|
|
|
|
|
|
|
// Legacy, to be removed.
|
|
|
|
DAngle ZzHORIZON, ZzOLDHORIZON, ZzHORIZOFF, ZzOHORIZOFF;
|
|
|
|
void processLegacyHelperPitch(double const scaleAdjust)
|
2022-05-30 10:35:41 +00:00
|
|
|
{
|
2022-11-25 06:09:11 +00:00
|
|
|
if (targetedPitch())
|
2022-05-30 10:35:41 +00:00
|
|
|
{
|
2022-11-25 06:09:11 +00:00
|
|
|
auto delta = deltaangle(ZzHORIZON, legacyTargetPitch);
|
|
|
|
|
|
|
|
if (abs(delta).Degrees() > 0.45)
|
|
|
|
{
|
|
|
|
ZzHORIZON += delta * scaleAdjust;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ZzHORIZON = legacyTargetPitch;
|
|
|
|
legacyTargetPitch = nullAngle;
|
|
|
|
}
|
2022-05-30 10:35:41 +00:00
|
|
|
}
|
2022-11-25 06:09:11 +00:00
|
|
|
else if (legacyAdjustmentPitch.Sgn())
|
2022-05-30 10:35:41 +00:00
|
|
|
{
|
2022-11-25 06:09:11 +00:00
|
|
|
ZzHORIZON += legacyAdjustmentPitch * scaleAdjust;
|
2022-05-30 10:35:41 +00:00
|
|
|
}
|
|
|
|
}
|
2022-11-25 06:09:11 +00:00
|
|
|
void backupPitch()
|
2022-05-30 10:35:41 +00:00
|
|
|
{
|
2022-11-25 06:09:11 +00:00
|
|
|
ZzOLDHORIZON = ZzHORIZON;
|
|
|
|
ZzOHORIZOFF = ZzHORIZOFF;
|
|
|
|
}
|
|
|
|
void restorePitch()
|
|
|
|
{
|
|
|
|
ZzHORIZON = ZzOLDHORIZON;
|
|
|
|
ZzHORIZOFF = ZzOHORIZOFF;
|
2022-05-30 10:35:41 +00:00
|
|
|
}
|
2022-11-25 06:09:11 +00:00
|
|
|
DAngle horizOLDSUM() { return ZzOLDHORIZON + ZzOHORIZOFF; }
|
|
|
|
DAngle horizSUM() { return ZzHORIZON + ZzHORIZOFF; }
|
|
|
|
DAngle horizLERPSUM(double const interpfrac) { return interpolatedvalue(horizOLDSUM(), horizSUM(), interpfrac); }
|
|
|
|
void resetAdjustmentPitch() { legacyAdjustmentPitch = nullAngle; }
|
2022-05-30 10:35:41 +00:00
|
|
|
|
2022-11-25 06:09:11 +00:00
|
|
|
DAngle ZzANGLE, ZzOLDANGLE, ZzLOOKANG, ZzOLDLOOKANG, ZzROTSCRNANG, ZzOLDROTSCRNANG, YawSpin;
|
2022-11-27 02:58:53 +00:00
|
|
|
void processLegacyHelperYaw(double const scaleAdjust)
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-11-27 02:58:53 +00:00
|
|
|
if (targetedYaw())
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-11-25 05:41:09 +00:00
|
|
|
auto delta = deltaangle(ZzANGLE, legacyTargetYaw);
|
2020-10-11 14:33:43 +00:00
|
|
|
|
2022-08-28 04:41:05 +00:00
|
|
|
if (abs(delta) > DAngleBuildToDeg)
|
2021-04-02 11:46:43 +00:00
|
|
|
{
|
2022-11-25 05:24:03 +00:00
|
|
|
ZzANGLE += delta * scaleAdjust;
|
2021-04-02 11:46:43 +00:00
|
|
|
}
|
|
|
|
else
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-11-25 05:41:09 +00:00
|
|
|
ZzANGLE = legacyTargetYaw;
|
|
|
|
legacyTargetYaw = nullAngle;
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
2022-11-25 05:41:09 +00:00
|
|
|
else if (legacyAdjustmentYaw.Sgn())
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-11-25 05:41:09 +00:00
|
|
|
ZzANGLE += legacyAdjustmentYaw * scaleAdjust;
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
2022-11-25 06:09:11 +00:00
|
|
|
void backupYaw()
|
|
|
|
{
|
|
|
|
ZzOLDANGLE = ZzANGLE;
|
|
|
|
ZzOLDLOOKANG = ZzLOOKANG;
|
|
|
|
ZzOLDROTSCRNANG = ZzROTSCRNANG;
|
|
|
|
}
|
|
|
|
void restoreYaw()
|
|
|
|
{
|
|
|
|
ZzANGLE = ZzOLDANGLE;
|
|
|
|
ZzLOOKANG = ZzOLDLOOKANG;
|
|
|
|
ZzROTSCRNANG = ZzOLDROTSCRNANG;
|
|
|
|
}
|
|
|
|
DAngle angOLDSUM() { return ZzOLDANGLE + ZzOLDLOOKANG; }
|
|
|
|
DAngle angSUM() { return ZzANGLE + ZzLOOKANG; }
|
|
|
|
DAngle angLERPSUM(double const interpfrac) { return interpolatedvalue(angOLDSUM(), angSUM(), interpfrac); }
|
|
|
|
DAngle angLERPANG(double const interpfrac) { return interpolatedvalue(ZzOLDANGLE, ZzANGLE, interpfrac); }
|
|
|
|
DAngle angLERPLOOKANG(double const interpfrac) { return interpolatedvalue(ZzOLDLOOKANG, ZzLOOKANG, interpfrac); }
|
|
|
|
DAngle angLERPROTSCRN(double const interpfrac) { return interpolatedvalue(ZzOLDROTSCRNANG, ZzROTSCRNANG, interpfrac); }
|
|
|
|
DAngle angRENDERLOOKANG(double const interpfrac) { return !SyncInput() ? ZzLOOKANG : angLERPLOOKANG(interpfrac); }
|
|
|
|
DAngle angRENDERROTSCRN(double const interpfrac) { return !SyncInput() ? ZzROTSCRNANG : angLERPROTSCRN(interpfrac); }
|
|
|
|
void resetAdjustmentYaw() { legacyAdjustmentYaw = nullAngle; }
|
2020-10-11 14:33:43 +00:00
|
|
|
|
2021-04-02 11:46:43 +00:00
|
|
|
private:
|
2022-11-25 06:09:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Legacy, to be removed.
|
|
|
|
DAngle legacyTargetPitch, legacyAdjustmentPitch;
|
|
|
|
bool legacyDisabledPitch;
|
|
|
|
|
2022-11-25 05:41:09 +00:00
|
|
|
DAngle legacyTargetYaw, legacyAdjustmentYaw;
|
|
|
|
bool legacyDisabledYaw;
|
2020-10-11 14:33:43 +00:00
|
|
|
};
|
|
|
|
|
2020-10-11 14:55:12 +00:00
|
|
|
class FSerializer;
|
2022-11-25 06:09:11 +00:00
|
|
|
FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, PlayerAngles* def);
|
2020-10-11 14:55:12 +00:00
|
|
|
|
2021-01-01 22:53:03 +00:00
|
|
|
|
|
|
|
void updateTurnHeldAmt(double const scaleAdjust);
|
2021-10-08 17:06:41 +00:00
|
|
|
bool isTurboTurnTime();
|
2021-01-01 22:53:03 +00:00
|
|
|
void resetTurnHeldAmt();
|
2021-11-05 22:28:39 +00:00
|
|
|
void processMovement(InputPacket* const currInput, InputPacket* const inputBuffer, ControlInfo* const hidInput, double const scaleAdjust, int const drink_amt = 0, bool const allowstrafe = true, double const turnscale = 1);
|