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"
|
|
|
|
|
2020-11-22 10:45:16 +00:00
|
|
|
int getincangle(int a, int na);
|
2021-04-11 05:43:11 +00:00
|
|
|
binangle getincanglebam(binangle a, binangle na);
|
2020-10-11 14:33:43 +00:00
|
|
|
|
2021-11-06 01:39:19 +00:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Functions for dividing an input value by current ticrate for angle/horiz scaling.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
inline double getTicrateScale(double const value)
|
|
|
|
{
|
|
|
|
return value / GameTicRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline double getTicrateScale(double const value, double const scaleAdjust)
|
|
|
|
{
|
|
|
|
return scaleAdjust * getTicrateScale(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-11 14:33:43 +00:00
|
|
|
struct PlayerHorizon
|
|
|
|
{
|
|
|
|
fixedhoriz horiz, ohoriz, horizoff, ohorizoff;
|
|
|
|
|
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);
|
|
|
|
void calcviewpitch(vec2_t const pos, binangle const ang, bool const aimmode, bool const canslopetilt, int const cursectnum, double const scaleAdjust = 1, bool const climbing = false);
|
|
|
|
|
|
|
|
// 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-11-11 23:48:53 +00:00
|
|
|
fixedhoriz interpolatedoff(double const smoothratio) { return interpolatedhorizon(ohorizoff, horizoff, smoothratio); }
|
2020-10-11 14:33:43 +00:00
|
|
|
|
2021-10-30 09:07:52 +00:00
|
|
|
// Ticrate playsim adjustment helpers.
|
|
|
|
void addadjustment(double value) { __addadjustment(buildfhoriz(value)); }
|
|
|
|
void addadjustment(fixedhoriz value) { __addadjustment(value); }
|
|
|
|
void settarget(double value, bool backup = false) { __settarget(buildfhoriz(value), backup); }
|
|
|
|
void settarget(fixedhoriz value, bool backup = false) { __settarget(value, backup); }
|
|
|
|
void resetadjustment() { adjustment = 0; }
|
|
|
|
bool targetset() { return target.asq16(); }
|
2021-03-31 08:44:50 +00:00
|
|
|
|
2021-10-30 09:07:52 +00:00
|
|
|
// Input locking helpers.
|
|
|
|
void lockinput() { inputdisabled = true; }
|
|
|
|
void unlockinput() { inputdisabled = false; }
|
2021-10-30 09:30:08 +00:00
|
|
|
bool movementlocked() { return targetset() || inputdisabled; }
|
2021-03-31 08:44:50 +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-04-02 11:46:43 +00:00
|
|
|
|
2021-11-07 00:37:12 +00:00
|
|
|
// Ticrate scale helpers.
|
2021-11-06 01:39:19 +00:00
|
|
|
fixedhoriz getscaledhoriz(double const value, double const scaleAdjust = 1., fixedhoriz* const object = nullptr, double const push = 0.)
|
2021-07-18 09:25:41 +00:00
|
|
|
{
|
2021-11-06 01:39:19 +00:00
|
|
|
return buildfhoriz(scaleAdjust * (((object ? object->asbuildf() : 1.) * getTicrateScale(value)) + push));
|
2021-07-18 09:25:41 +00:00
|
|
|
}
|
2021-11-07 00:37:12 +00:00
|
|
|
void scaletozero(fixedhoriz& object, double const value, double const scaleAdjust, double const push = 0.)
|
2021-07-18 09:25:41 +00:00
|
|
|
{
|
2021-11-07 07:25:37 +00:00
|
|
|
if (object.asq16())
|
2021-05-12 01:44:05 +00:00
|
|
|
{
|
2021-11-07 07:25:37 +00:00
|
|
|
auto sgn = Sgn(object.asq16());
|
|
|
|
object -= getscaledhoriz(value, scaleAdjust, &object, push == 0 ? sgn * (1. / 3.) : push);
|
|
|
|
if (sgn != Sgn(object.asq16())) object = q16horiz(0);
|
2021-05-12 01:44:05 +00:00
|
|
|
}
|
2021-07-18 09:25:41 +00:00
|
|
|
}
|
|
|
|
|
2021-10-30 09:07:52 +00:00
|
|
|
// Ticrate playsim adjustment processor.
|
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)
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2021-04-11 05:43:11 +00:00
|
|
|
horiz += buildfhoriz(scaleAdjust * delta);
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
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);
|
2021-05-12 01:44:05 +00:00
|
|
|
}
|
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;
|
2021-04-02 11:46:43 +00:00
|
|
|
|
|
|
|
void __addadjustment(fixedhoriz value)
|
|
|
|
{
|
|
|
|
if (!SyncInput())
|
|
|
|
{
|
2021-04-11 05:43:11 +00:00
|
|
|
adjustment += value.asbuildf();
|
2021-04-02 11:46:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
horiz += value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 05:43:11 +00:00
|
|
|
void __settarget(fixedhoriz value, bool backup)
|
2021-04-02 11:46:43 +00:00
|
|
|
{
|
2021-04-21 10:41:04 +00:00
|
|
|
value = q16horiz(clamp(value.asq16(), gi->playerHorizMin(), gi->playerHorizMax()));
|
|
|
|
|
2021-04-02 11:46:43 +00:00
|
|
|
if (!SyncInput() && !backup)
|
|
|
|
{
|
|
|
|
target = value;
|
|
|
|
if (!targetset()) target = q16horiz(1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
horiz = value;
|
|
|
|
if (backup) ohoriz = horiz;
|
|
|
|
}
|
|
|
|
}
|
2020-10-11 14:33:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PlayerAngle
|
|
|
|
{
|
2021-04-11 05:43:11 +00:00
|
|
|
binangle ang, oang, look_ang, olook_ang, rotscrnang, orotscrnang;
|
|
|
|
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.
|
|
|
|
binangle osum() { return oang + olook_ang; }
|
|
|
|
binangle sum() { return ang + look_ang; }
|
|
|
|
binangle interpolatedsum(double const smoothratio) { return interpolatedangle(osum(), sum(), smoothratio); }
|
|
|
|
binangle interpolatedlookang(double const smoothratio) { return interpolatedangle(olook_ang, look_ang, smoothratio); }
|
|
|
|
binangle 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 addadjustment(double value) { __addadjustment(buildfang(value)); }
|
|
|
|
void addadjustment(binangle value) { __addadjustment(value); }
|
|
|
|
void settarget(double value, bool backup = false) { __settarget(buildfang(value), backup); }
|
|
|
|
void settarget(binangle value, bool backup = false) { __settarget(value, backup); }
|
|
|
|
void resetadjustment() { adjustment = 0; }
|
|
|
|
bool targetset() { return target.asbam(); }
|
2020-11-22 10:47:13 +00:00
|
|
|
|
2021-10-30 09:07:52 +00:00
|
|
|
// Input locking helpers.
|
|
|
|
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 look_anghalf(double const smoothratio) { return (!SyncInput() ? look_ang : interpolatedlookang(smoothratio)).signedbuildf() * 0.5; }
|
|
|
|
double looking_arc(double const smoothratio) { return fabs((!SyncInput() ? look_ang : interpolatedlookang(smoothratio)).signedbuildf()) * (1. / 9.); }
|
2020-10-11 14:33:43 +00:00
|
|
|
|
2021-11-07 00:37:12 +00:00
|
|
|
// Ticrate scale helpers.
|
2021-11-06 01:39:19 +00:00
|
|
|
binangle getscaledangle(double const value, double const scaleAdjust = 1., binangle* const object = nullptr, double const push = 0.)
|
2020-11-22 12:57:35 +00:00
|
|
|
{
|
2021-11-06 01:39:19 +00:00
|
|
|
return buildfang(scaleAdjust * (((object ? object->signedbuildf() : 1.) * getTicrateScale(value)) + push));
|
2021-05-12 01:44:05 +00:00
|
|
|
}
|
2021-11-07 00:37:12 +00:00
|
|
|
void scaletozero(binangle& object, double const value, double const scaleAdjust, double const push = 0.)
|
2021-07-18 09:25:41 +00:00
|
|
|
{
|
2021-11-07 07:25:37 +00:00
|
|
|
if (object.asbam())
|
2021-07-18 09:25:41 +00:00
|
|
|
{
|
2021-11-07 07:25:37 +00:00
|
|
|
auto sgn = Sgn(object.signedbam());
|
|
|
|
object -= getscaledangle(value, scaleAdjust, &object, push == 0 ? sgn * (1. / 3.) : push);
|
|
|
|
if (sgn != Sgn(object.signedbam())) object = bamang(0);
|
2021-07-18 09:25:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-30 09:07:52 +00:00
|
|
|
// Ticrate playsim adjustment processor.
|
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 = getincanglebam(ang, target).signedbuildf();
|
2020-10-11 14:33:43 +00:00
|
|
|
|
2021-04-11 05:43:11 +00:00
|
|
|
if (abs(delta) > 1)
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2021-04-11 05:43:11 +00:00
|
|
|
ang += buildfang(scaleAdjust * delta);
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
2021-04-02 11:46:43 +00:00
|
|
|
else
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2021-03-31 08:43:41 +00:00
|
|
|
ang = target;
|
|
|
|
target = bamang(0);
|
2021-05-12 01:44:05 +00:00
|
|
|
}
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
else if (adjustment)
|
|
|
|
{
|
2021-04-11 05:43:11 +00:00
|
|
|
ang += buildfang(scaleAdjust * adjustment);
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-02 11:46:43 +00:00
|
|
|
private:
|
|
|
|
binangle target;
|
|
|
|
double adjustment;
|
2021-07-18 09:25:41 +00:00
|
|
|
bool inputdisabled;
|
2021-04-02 11:46:43 +00:00
|
|
|
|
2021-04-11 05:43:11 +00:00
|
|
|
void __addadjustment(binangle value)
|
2021-04-02 11:46:43 +00:00
|
|
|
{
|
|
|
|
if (!SyncInput())
|
|
|
|
{
|
2021-04-11 07:52:29 +00:00
|
|
|
adjustment += value.signedbuildf();
|
2021-04-02 11:46:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ang += value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 05:43:11 +00:00
|
|
|
void __settarget(binangle value, bool backup)
|
2021-04-02 11:46:43 +00:00
|
|
|
{
|
|
|
|
if (!SyncInput() && !backup)
|
|
|
|
{
|
|
|
|
target = value;
|
|
|
|
if (!targetset()) target = bamang(1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ang = value;
|
|
|
|
if (backup) oang = ang;
|
|
|
|
}
|
|
|
|
}
|
2020-10-11 14:33:43 +00:00
|
|
|
};
|
|
|
|
|
2021-10-30 09:20:10 +00:00
|
|
|
struct PlayerPosition
|
|
|
|
{
|
|
|
|
vec3_t pos, opos;
|
|
|
|
|
|
|
|
// Interpolation helpers.
|
|
|
|
void backupx() { opos.x = pos.x; }
|
|
|
|
void backupy() { opos.y = pos.y; }
|
|
|
|
void backupz() { opos.z = pos.z; }
|
|
|
|
void backuppos() { opos = pos; }
|
|
|
|
|
|
|
|
// Interpolated points.
|
|
|
|
int32_t interpolatedx(double const smoothratio, int const scale = 16) { return interpolatedvalue(opos.x, pos.x, smoothratio, scale); }
|
|
|
|
int32_t interpolatedy(double const smoothratio, int const scale = 16) { return interpolatedvalue(opos.y, pos.y, smoothratio, scale); }
|
|
|
|
int32_t interpolatedz(double const smoothratio, int const scale = 16) { return interpolatedvalue(opos.z, pos.z, smoothratio, scale); }
|
|
|
|
|
|
|
|
// Interpolated vectors.
|
|
|
|
vec2_t interpolatedvec2(double const smoothratio, int const scale = 16)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
{
|
|
|
|
interpolatedx(smoothratio, scale),
|
|
|
|
interpolatedy(smoothratio, scale)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
vec3_t interpolatedvec3(double const smoothratio, int const scale = 16)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
{
|
|
|
|
interpolatedx(smoothratio, scale),
|
|
|
|
interpolatedy(smoothratio, scale),
|
|
|
|
interpolatedz(smoothratio, scale)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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-10-30 09:20:10 +00:00
|
|
|
FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerPosition& w, PlayerPosition* 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);
|