2020-10-11 14:33:43 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "m_fixed.h"
|
|
|
|
#include "binaryangle.h"
|
|
|
|
#include "gamecvars.h"
|
2021-04-02 11:46:43 +00:00
|
|
|
#include "gamestruct.h"
|
2020-10-11 14:33:43 +00:00
|
|
|
#include "packet.h"
|
|
|
|
|
2022-07-23 02:53:42 +00:00
|
|
|
inline constexpr binangle getincanglebam(binangle a, binangle na)
|
|
|
|
{
|
|
|
|
return na-a;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline constexpr int getincangle(int a, int na)
|
|
|
|
{
|
|
|
|
return getincanglebam(buildang(a), buildang(na)).signedbuild();
|
|
|
|
}
|
2021-04-11 05:43:11 +00:00
|
|
|
|
2020-10-11 14:33:43 +00:00
|
|
|
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; }
|
2021-11-06 03:00:41 +00:00
|
|
|
fixedhoriz interpolatedsum(double const smoothratio) { return interpolatedhorizon(osum(), sum(), smoothratio); }
|
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.
|
|
|
|
double horizsumfrac(double const smoothratio) { return (!SyncInput() ? sum() : interpolatedsum(smoothratio)).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-27 13:09:22 +00:00
|
|
|
DAngle ang, oang, look_ang, olook_ang, rotscrnang, orotscrnang;
|
2021-04-11 05:43:11 +00:00
|
|
|
double 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; }
|
|
|
|
DAngle interpolatedsum(double const smoothratio) { return interpolatedangle(osum(), sum(), smoothratio); }
|
2022-08-27 11:48:57 +00:00
|
|
|
DAngle interpolatedlookang(double const smoothratio) { return interpolatedangle(olook_ang, look_ang, smoothratio); }
|
|
|
|
DAngle interpolatedrotscrn(double const smoothratio) { return interpolatedangle(orotscrnang, rotscrnang, smoothratio); }
|
2020-11-22 10:47:13 +00:00
|
|
|
|
2021-10-30 09:07:52 +00:00
|
|
|
// Ticrate playsim adjustment helpers.
|
|
|
|
void resetadjustment() { adjustment = 0; }
|
2022-08-27 12:20:38 +00:00
|
|
|
bool targetset() { return target.BAMs(); }
|
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.
|
|
|
|
double look_anghalf(double const smoothratio) { return (!SyncInput() ? look_ang : interpolatedlookang(smoothratio)).Normalized180().Buildfang() * 0.5; }
|
|
|
|
double looking_arc(double const smoothratio) { return fabs((!SyncInput() ? look_ang : interpolatedlookang(smoothratio)).Normalized180().Buildfang()) * (1. / 9.); }
|
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-27 13:43:23 +00:00
|
|
|
adjustment += value.Normalized180().Degrees();
|
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-27 12:20:38 +00:00
|
|
|
target = value.BAMs() ? 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-27 13:09:22 +00:00
|
|
|
auto delta = deltaangle(ang, target).Normalized180().Degrees();
|
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
|
|
|
{
|
2022-08-27 13:09:22 +00:00
|
|
|
ang += DAngle::fromDeg(scaleAdjust * delta);
|
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-27 12:20:38 +00:00
|
|
|
target = DAngle::fromBam(0);
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (adjustment)
|
|
|
|
{
|
2022-08-27 13:09:22 +00:00
|
|
|
ang += DAngle::fromDeg(scaleAdjust * adjustment);
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-02 11:46:43 +00:00
|
|
|
private:
|
2022-08-27 12:20:38 +00:00
|
|
|
DAngle target;
|
2021-04-02 11:46:43 +00:00
|
|
|
double 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);
|