2020-10-11 14:33:43 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "m_fixed.h"
|
2022-08-28 02:57:47 +00:00
|
|
|
#include "fixedhorizon.h"
|
2020-10-11 14:33:43 +00:00
|
|
|
#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
|
|
|
|
{
|
2021-04-02 11:46:43 +00:00
|
|
|
fixedhoriz 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-08-27 12:25:27 +00:00
|
|
|
void calcviewpitch(vec2_t const pos, DAngle const ang, bool const aimmode, bool const canslopetilt, sectortype* const cursectnum, double const scaleAdjust = 1, bool const climbing = false);
|
|
|
|
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)
|
2022-02-05 09:16:50 +00:00
|
|
|
{
|
|
|
|
vec2_t ps = { int(pos.X * worldtoint), int(pos.Y * worldtoint) };
|
|
|
|
calcviewpitch(ps, ang, aimmode, canslopetilt, cursectnum, scaleAdjust, climbing);
|
|
|
|
}
|
2022-08-27 12:25:27 +00:00
|
|
|
void calcviewpitch(const DVector3& pos, DAngle const ang, bool const aimmode, bool const canslopetilt, sectortype* const cursectnum, double const scaleAdjust = 1, bool const climbing = false)
|
2022-02-05 09:16:50 +00:00
|
|
|
{
|
|
|
|
vec2_t ps = { int(pos.X * worldtoint), int(pos.Y * worldtoint) };
|
|
|
|
calcviewpitch(ps, ang, aimmode, canslopetilt, cursectnum, scaleAdjust, climbing);
|
|
|
|
}
|
2021-10-30 09:07:52 +00:00
|
|
|
|
|
|
|
// Interpolation helpers.
|
2020-10-11 14:33:43 +00:00
|
|
|
void backup()
|
|
|
|
{
|
|
|
|
ohoriz = horiz;
|
|
|
|
ohorizoff = horizoff;
|
|
|
|
}
|
|
|
|
void restore()
|
|
|
|
{
|
|
|
|
horiz = ohoriz;
|
|
|
|
horizoff = ohorizoff;
|
|
|
|
}
|
|
|
|
|
2021-10-30 09:07:52 +00:00
|
|
|
// Commonly used getters.
|
|
|
|
fixedhoriz osum() { return ohoriz + ohorizoff; }
|
|
|
|
fixedhoriz sum() { return horiz + horizoff; }
|
2022-09-07 08:11:12 +00:00
|
|
|
fixedhoriz 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.
|
|
|
|
void resetadjustment() { adjustment = 0; }
|
|
|
|
bool targetset() { return target.asq16(); }
|
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
|
|
|
|
2021-10-30 09:07:52 +00:00
|
|
|
// Draw code helpers.
|
2022-09-07 08:11:12 +00:00
|
|
|
double horizsumfrac(double const interpfrac) { return (!SyncInput() ? sum() : interpolatedsum(interpfrac)).asbuildf() * (1. / 16.); }
|
2021-07-18 09:25:41 +00:00
|
|
|
|
2022-05-30 10:35:41 +00:00
|
|
|
// Ticrate playsim adjustment setters and processor.
|
|
|
|
void addadjustment(fixedhoriz const value)
|
|
|
|
{
|
|
|
|
if (!SyncInput())
|
|
|
|
{
|
|
|
|
adjustment += value.asbuildf();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
horiz += value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-06 08:41:45 +00:00
|
|
|
void settarget(fixedhoriz 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-05-30 10:35:41 +00:00
|
|
|
value = q16horiz(clamp(value.asq16(), gi->playerHorizMin(), gi->playerHorizMax()));
|
|
|
|
|
2022-06-06 08:41:45 +00:00
|
|
|
if (!SyncInput() && !backup)
|
2022-05-30 10:35:41 +00:00
|
|
|
{
|
2022-06-05 11:24:50 +00:00
|
|
|
target = value.asq16() ? value : q16horiz(1);
|
2022-05-30 10:35:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
horiz = value;
|
2022-06-06 08:41:45 +00:00
|
|
|
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
|
|
|
{
|
2021-04-11 05:43:11 +00:00
|
|
|
auto delta = (target - horiz).asbuildf();
|
2020-10-11 14:33:43 +00:00
|
|
|
|
2021-04-11 05:43:11 +00:00
|
|
|
if (abs(delta) > 1)
|
2021-04-02 11:46:43 +00:00
|
|
|
{
|
2021-04-11 05:43:11 +00:00
|
|
|
horiz += buildfhoriz(scaleAdjust * delta);
|
2021-04-02 11:46:43 +00:00
|
|
|
}
|
|
|
|
else
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2021-03-31 08:44:50 +00:00
|
|
|
horiz = target;
|
|
|
|
target = q16horiz(0);
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (adjustment)
|
|
|
|
{
|
2021-04-11 05:43:11 +00:00
|
|
|
horiz += buildfhoriz(scaleAdjust * adjustment);
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-02 11:46:43 +00:00
|
|
|
private:
|
|
|
|
fixedhoriz target;
|
|
|
|
double 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-08-28 04:41:05 +00:00
|
|
|
target = value.Sgn() ? value : DAngle::fromBam(1);
|
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);
|