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"
|
|
|
|
|
|
|
|
struct PlayerHorizon
|
|
|
|
{
|
2022-10-11 02:37:20 +00:00
|
|
|
DAngle horiz, ohoriz, horizoff, ohorizoff;
|
2020-10-11 14:33:43 +00:00
|
|
|
|
2021-07-18 09:25:41 +00:00
|
|
|
friend FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerHorizon& w, PlayerHorizon* def);
|
|
|
|
|
2021-10-30 09:07:52 +00:00
|
|
|
// Prototypes for functions in gameinput.cpp.
|
|
|
|
void applyinput(float const horz, ESyncBits* actions, double const scaleAdjust = 1);
|
2022-09-27 05:51:42 +00:00
|
|
|
void calcviewpitch(const DVector2& pos, DAngle const ang, bool const aimmode, bool const canslopetilt, sectortype* const cursectnum, double const scaleAdjust = 1, bool const climbing = false);
|
2021-10-30 09:07:52 +00:00
|
|
|
|
|
|
|
// Interpolation helpers.
|
2020-10-11 14:33:43 +00:00
|
|
|
void backup()
|
|
|
|
{
|
2022-10-11 02:37:20 +00:00
|
|
|
ohoriz = horiz;
|
2020-10-11 14:33:43 +00:00
|
|
|
ohorizoff = horizoff;
|
|
|
|
}
|
|
|
|
void restore()
|
|
|
|
{
|
2022-10-11 02:37:20 +00:00
|
|
|
horiz = ohoriz;
|
2020-10-11 14:33:43 +00:00
|
|
|
horizoff = ohorizoff;
|
|
|
|
}
|
|
|
|
|
2021-10-30 09:07:52 +00:00
|
|
|
// Commonly used getters.
|
2022-09-28 03:39:01 +00:00
|
|
|
DAngle osum() { return ohoriz + ohorizoff; }
|
2022-10-11 02:37:20 +00:00
|
|
|
DAngle sum() { return horiz + horizoff; }
|
2022-09-28 03:39:01 +00:00
|
|
|
DAngle interpolatedsum(double const interpfrac) { return interpolatedvalue(osum(), sum(), interpfrac); }
|
2021-03-31 08:44:50 +00:00
|
|
|
|
2021-10-30 09:07:52 +00:00
|
|
|
// Ticrate playsim adjustment helpers.
|
2022-09-28 03:39:01 +00:00
|
|
|
void resetadjustment() { adjustment = nullAngle; }
|
2022-09-27 04:12:16 +00:00
|
|
|
bool targetset() { return target.Sgn(); }
|
2021-07-18 09:25:41 +00:00
|
|
|
|
2021-10-30 09:07:52 +00:00
|
|
|
// Input locking helpers.
|
2022-06-06 08:41:45 +00:00
|
|
|
void lockinput() { inputdisabled = true; }
|
|
|
|
void unlockinput() { inputdisabled = false; }
|
2021-10-30 09:30:08 +00:00
|
|
|
bool movementlocked() { return targetset() || inputdisabled; }
|
2020-10-11 14:33:43 +00:00
|
|
|
|
2022-05-30 10:35:41 +00:00
|
|
|
// Ticrate playsim adjustment setters and processor.
|
2022-09-28 03:39:01 +00:00
|
|
|
void addadjustment(DAngle const value)
|
2022-05-30 10:35:41 +00:00
|
|
|
{
|
|
|
|
if (!SyncInput())
|
|
|
|
{
|
2022-09-28 03:39:01 +00:00
|
|
|
adjustment += value;
|
2022-05-30 10:35:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-10-11 02:37:20 +00:00
|
|
|
horiz += value;
|
2022-05-30 10:35:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-28 03:39:01 +00:00
|
|
|
void settarget(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-09-28 03:39:01 +00:00
|
|
|
target = value.Sgn() ? value : minAngle;
|
2022-05-30 10:35:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-10-11 02:37:20 +00:00
|
|
|
horiz = value;
|
|
|
|
if (backup) ohoriz = horiz;
|
2022-05-30 10:35:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-11 14:33:43 +00:00
|
|
|
void processhelpers(double const scaleAdjust)
|
|
|
|
{
|
2021-04-02 11:46:43 +00:00
|
|
|
if (targetset())
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-10-11 02:37:20 +00:00
|
|
|
auto delta = deltaangle(horiz, target);
|
2020-10-11 14:33:43 +00:00
|
|
|
|
2022-09-28 03:39:01 +00:00
|
|
|
if (abs(delta).Degrees() > 0.45)
|
2021-04-02 11:46:43 +00:00
|
|
|
{
|
2022-10-11 02:37:20 +00:00
|
|
|
horiz += delta * scaleAdjust;
|
2021-04-02 11:46:43 +00:00
|
|
|
}
|
|
|
|
else
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-10-11 02:37:20 +00:00
|
|
|
horiz = target;
|
2022-09-28 03:39:01 +00:00
|
|
|
target = nullAngle;
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-28 03:39:01 +00:00
|
|
|
else if (adjustment.Sgn())
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-10-11 02:37:20 +00:00
|
|
|
horiz += adjustment * scaleAdjust;
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-02 11:46:43 +00:00
|
|
|
private:
|
2022-09-28 03:39:01 +00:00
|
|
|
DAngle target, adjustment;
|
2021-07-18 09:25:41 +00:00
|
|
|
bool inputdisabled;
|
2020-10-11 14:33:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PlayerAngle
|
|
|
|
{
|
2022-08-28 02:09:44 +00:00
|
|
|
DAngle ang, oang, look_ang, olook_ang, rotscrnang, orotscrnang, spin;
|
2020-10-11 14:33:43 +00:00
|
|
|
|
2021-07-18 09:25:41 +00:00
|
|
|
friend FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngle& w, PlayerAngle* def);
|
|
|
|
|
2021-10-30 09:07:52 +00:00
|
|
|
// Prototypes for functions in gameinput.cpp.
|
|
|
|
void applyinput(float const avel, ESyncBits* actions, double const scaleAdjust = 1);
|
|
|
|
|
|
|
|
// Interpolation helpers.
|
2020-10-11 14:33:43 +00:00
|
|
|
void backup()
|
|
|
|
{
|
|
|
|
oang = ang;
|
|
|
|
olook_ang = look_ang;
|
|
|
|
orotscrnang = rotscrnang;
|
|
|
|
}
|
|
|
|
void restore()
|
|
|
|
{
|
|
|
|
ang = oang;
|
|
|
|
look_ang = olook_ang;
|
|
|
|
rotscrnang = orotscrnang;
|
|
|
|
}
|
|
|
|
|
2021-10-30 09:07:52 +00:00
|
|
|
// Commonly used getters.
|
2022-08-27 13:09:22 +00:00
|
|
|
DAngle osum() { return oang + olook_ang; }
|
|
|
|
DAngle sum() { return ang + look_ang; }
|
2022-09-07 08:11:12 +00:00
|
|
|
DAngle interpolatedsum(double const interpfrac) { return interpolatedvalue(osum(), sum(), interpfrac); }
|
|
|
|
DAngle interpolatedang(double const interpfrac) { return interpolatedvalue(oang, ang, interpfrac); }
|
|
|
|
DAngle interpolatedlookang(double const interpfrac) { return interpolatedvalue(olook_ang, look_ang, interpfrac); }
|
|
|
|
DAngle interpolatedrotscrn(double const interpfrac) { return interpolatedvalue(orotscrnang, rotscrnang, interpfrac); }
|
|
|
|
DAngle renderlookang(double const interpfrac) { return !SyncInput() ? look_ang : interpolatedlookang(interpfrac); }
|
2020-11-22 10:47:13 +00:00
|
|
|
|
2021-10-30 09:07:52 +00:00
|
|
|
// Ticrate playsim adjustment helpers.
|
2022-08-28 04:41:05 +00:00
|
|
|
void resetadjustment() { adjustment = nullAngle; }
|
|
|
|
bool targetset() { return target.Sgn(); }
|
2020-10-11 14:33:43 +00:00
|
|
|
|
2021-10-30 09:07:52 +00:00
|
|
|
// Input locking helpers.
|
2022-06-06 08:41:45 +00:00
|
|
|
void lockinput() { inputdisabled = true; }
|
|
|
|
void unlockinput() { inputdisabled = false; }
|
2021-10-30 09:30:08 +00:00
|
|
|
bool movementlocked() { return targetset() || inputdisabled; }
|
2020-10-11 14:33:43 +00:00
|
|
|
|
2022-08-27 11:48:57 +00:00
|
|
|
// Draw code helpers. The logic where these are used rely heavily on Build's angle period.
|
2022-09-07 08:50:01 +00:00
|
|
|
double look_anghalf(double const interpfrac) { return renderlookang(interpfrac).Normalized180().Degrees() * (128. / 45.); }
|
|
|
|
double looking_arc(double const interpfrac) { return fabs(renderlookang(interpfrac).Normalized180().Degrees() * (1024. / 1620.)); }
|
2021-07-18 09:25:41 +00:00
|
|
|
|
2022-05-30 10:35:41 +00:00
|
|
|
// Ticrate playsim adjustment setters and processor.
|
2022-08-27 13:43:23 +00:00
|
|
|
void addadjustment(const DAngle value)
|
2022-05-30 10:35:41 +00:00
|
|
|
{
|
|
|
|
if (!SyncInput())
|
|
|
|
{
|
2022-08-28 04:41:05 +00:00
|
|
|
adjustment += value.Normalized180();
|
2022-05-30 10:35:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-27 13:09:22 +00:00
|
|
|
ang += value;
|
2022-05-30 10:35:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-27 12:20:38 +00:00
|
|
|
void settarget(const DAngle value, bool const backup = false)
|
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-09-28 03:39:01 +00:00
|
|
|
target = value.Sgn() ? value : minAngle;
|
2022-05-30 10:35:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-27 13:09:22 +00:00
|
|
|
ang = value;
|
2022-06-06 08:41:45 +00:00
|
|
|
if (backup) oang = ang;
|
2022-05-30 10:35:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-11 14:33:43 +00:00
|
|
|
void processhelpers(double const scaleAdjust)
|
|
|
|
{
|
2021-04-02 11:46:43 +00:00
|
|
|
if (targetset())
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-08-28 04:41:05 +00:00
|
|
|
auto delta = deltaangle(ang, target);
|
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-08-28 04:41:05 +00:00
|
|
|
ang += delta * scaleAdjust;
|
2021-04-02 11:46:43 +00:00
|
|
|
}
|
|
|
|
else
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-08-27 13:09:22 +00:00
|
|
|
ang = target;
|
2022-08-28 00:40:50 +00:00
|
|
|
target = nullAngle;
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-28 04:41:05 +00:00
|
|
|
else if (adjustment.Sgn())
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-08-28 04:41:05 +00:00
|
|
|
ang += adjustment * scaleAdjust;
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-02 11:46:43 +00:00
|
|
|
private:
|
2022-08-28 04:41:05 +00:00
|
|
|
DAngle target, adjustment;
|
2021-07-18 09:25:41 +00:00
|
|
|
bool inputdisabled;
|
2020-10-11 14:33:43 +00:00
|
|
|
};
|
|
|
|
|
2020-10-11 14:55:12 +00:00
|
|
|
class FSerializer;
|
|
|
|
FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngle& w, PlayerAngle* def);
|
|
|
|
FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerHorizon& w, PlayerHorizon* def);
|
|
|
|
|
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);
|