2020-10-11 14:33:43 +00:00
|
|
|
#pragma once
|
|
|
|
|
2023-03-13 10:33:37 +00:00
|
|
|
#include "serializer.h"
|
2022-08-28 04:19:04 +00:00
|
|
|
#include "gamefuncs.h"
|
2023-10-05 02:10:47 +00:00
|
|
|
#include "d_net.h"
|
2020-10-11 14:33:43 +00:00
|
|
|
|
2023-09-24 03:40:15 +00:00
|
|
|
enum : unsigned
|
|
|
|
{
|
|
|
|
CS_CANCROUCH = 1,
|
|
|
|
CS_DISABLETOGGLE = 2,
|
|
|
|
};
|
|
|
|
|
2023-09-25 09:51:53 +00:00
|
|
|
enum : unsigned
|
|
|
|
{
|
|
|
|
VEH_CANMOVE = 1,
|
|
|
|
VEH_CANTURN = 2,
|
|
|
|
VEH_SCALETURN = 4,
|
|
|
|
};
|
|
|
|
|
2023-04-03 08:46:36 +00:00
|
|
|
inline double getTicrateScale(const double value)
|
|
|
|
{
|
|
|
|
return value / GameTicRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
class GameInput
|
|
|
|
{
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
BUILDTICRATE = 120,
|
|
|
|
TURBOTURNBASE = 590,
|
|
|
|
};
|
|
|
|
|
2023-04-21 10:09:19 +00:00
|
|
|
static constexpr double YAW_TURNSPEEDS[3] = { 234.375 * (360. / 2048.), 890.625 * (360. / 2048.), 1548.75 * (360. / 2048.) };
|
2023-10-03 21:56:08 +00:00
|
|
|
static constexpr DVector3 MAXVEL[3] = { { 0., 0., 1. }, { 1., 1., 1. }, { 2., 2., 1. } };
|
|
|
|
static constexpr DRotator MAXANG = { DAngle180 - minAngle, DAngle180 - minAngle, DAngle180 - minAngle };
|
2023-10-03 09:58:38 +00:00
|
|
|
static constexpr DAngle MOUSE_SCALE = DAngle::fromDeg(1. / 16.);
|
2023-04-03 08:46:36 +00:00
|
|
|
|
2023-04-03 08:40:34 +00:00
|
|
|
// Input received from the OS.
|
|
|
|
float joyAxes[NUM_JOYAXIS];
|
2023-10-04 08:20:57 +00:00
|
|
|
FVector2 mouseInput;
|
2023-04-03 08:40:34 +00:00
|
|
|
|
2023-04-03 08:46:36 +00:00
|
|
|
// Internal variables when generating a packet.
|
|
|
|
InputPacket inputBuffer;
|
2023-10-04 05:08:03 +00:00
|
|
|
ESyncBits ActionsToSend;
|
2023-04-03 08:46:36 +00:00
|
|
|
double turnheldtime;
|
2023-10-04 05:08:03 +00:00
|
|
|
double scaleAdjust;
|
2023-10-05 02:10:47 +00:00
|
|
|
bool syncinput;
|
2023-04-03 08:46:36 +00:00
|
|
|
int WeaponToSend;
|
|
|
|
int dpad_lock;
|
2023-10-04 05:08:03 +00:00
|
|
|
int keymove;
|
2023-04-03 08:46:36 +00:00
|
|
|
|
|
|
|
// Turn speed doubling after x amount of tics.
|
2023-10-04 05:08:03 +00:00
|
|
|
void updateTurnHeldAmt()
|
2023-04-03 08:46:36 +00:00
|
|
|
{
|
|
|
|
turnheldtime += getTicrateScale(BUILDTICRATE) * scaleAdjust;
|
|
|
|
}
|
|
|
|
bool isTurboTurnTime()
|
|
|
|
{
|
|
|
|
return turnheldtime >= getTicrateScale(TURBOTURNBASE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prototypes for private member functions.
|
2023-04-03 08:40:34 +00:00
|
|
|
void processInputBits();
|
2023-04-03 08:46:36 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
// Bit sender updates.
|
|
|
|
void SendWeapon(const int weapon)
|
|
|
|
{
|
|
|
|
WeaponToSend = weapon;
|
|
|
|
}
|
|
|
|
void SendAction(const ESyncBits action)
|
|
|
|
{
|
|
|
|
ActionsToSend |= action;
|
|
|
|
}
|
|
|
|
|
2023-09-24 07:50:06 +00:00
|
|
|
// Clear all values within this object.
|
|
|
|
void Clear()
|
|
|
|
{
|
2023-09-28 22:31:03 +00:00
|
|
|
memset(this, 0, sizeof(*this));
|
2023-09-24 07:50:06 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 08:40:34 +00:00
|
|
|
// Receives mouse input from OS for processing.
|
|
|
|
void MouseAddToPos(float x, float y)
|
|
|
|
{
|
|
|
|
mouseInput.X += x;
|
|
|
|
mouseInput.Y += y;
|
|
|
|
}
|
|
|
|
|
2023-10-04 05:08:03 +00:00
|
|
|
// Receives the current input scale from the engine's main loop.
|
|
|
|
void UpdateInputScale()
|
|
|
|
{
|
|
|
|
const double frac = I_GetInputFrac();
|
|
|
|
scaleAdjust = !SyncInput() ? frac : 1;
|
|
|
|
}
|
|
|
|
|
2023-10-05 02:10:47 +00:00
|
|
|
// Handling of whether to allow unsynchronised input.
|
|
|
|
bool SyncInput()
|
|
|
|
{
|
|
|
|
return syncinput || cl_syncinput || cl_capfps;
|
|
|
|
}
|
|
|
|
void ForceInputSync(const int pnum)
|
|
|
|
{
|
|
|
|
if (pnum == myconnectindex)
|
|
|
|
{
|
|
|
|
syncinput = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void ResetInputSync()
|
|
|
|
{
|
|
|
|
syncinput = false;
|
|
|
|
}
|
|
|
|
|
2023-04-03 08:46:36 +00:00
|
|
|
// Prototypes for large member functions.
|
2023-10-04 05:08:03 +00:00
|
|
|
void processMovement(const double turnscale = 1, const bool allowstrafe = true, const int drink_amt = 0);
|
|
|
|
void processVehicle(const double baseVel, const double velScale, const unsigned flags);
|
|
|
|
void getInput(InputPacket* packet = nullptr);
|
2023-09-24 07:50:06 +00:00
|
|
|
void resetCrouchToggle();
|
2023-04-03 08:46:36 +00:00
|
|
|
};
|
2023-04-02 08:26:22 +00:00
|
|
|
|
2022-11-25 06:09:11 +00:00
|
|
|
struct PlayerAngles
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-11-27 03:48:37 +00:00
|
|
|
// Player viewing angles, separate from the camera.
|
|
|
|
DRotator PrevViewAngles, ViewAngles;
|
|
|
|
|
2023-04-22 09:34:44 +00:00
|
|
|
// Strafe roll counter, to be incremented/managed by the game's velocity handler.
|
|
|
|
double PrevStrafeVel, StrafeVel;
|
|
|
|
|
2022-11-27 03:48:37 +00:00
|
|
|
// Holder of current yaw spin state for the 180 degree turn.
|
|
|
|
DAngle YawSpin;
|
|
|
|
|
2022-11-25 06:09:11 +00:00
|
|
|
friend FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, PlayerAngles* def);
|
2023-10-05 08:06:39 +00:00
|
|
|
friend void GameInput::processMovement(const double turnscale, const bool allowstrafe, const int drink_amt);
|
|
|
|
friend void GameInput::processVehicle(const double baseVel, const double velScale, const unsigned flags);
|
2021-07-18 09:25:41 +00:00
|
|
|
|
2022-12-09 07:09:59 +00:00
|
|
|
// Prototypes.
|
2023-04-18 12:37:28 +00:00
|
|
|
void doPitchInput(InputPacket* const input);
|
|
|
|
void doYawInput(InputPacket* const input);
|
2023-03-13 10:17:33 +00:00
|
|
|
void doViewPitch(const bool canslopetilt, const bool climbing = false);
|
2023-03-13 10:33:37 +00:00
|
|
|
void doViewYaw(InputPacket* const input);
|
2023-04-24 11:31:21 +00:00
|
|
|
void doRollInput(InputPacket* const input, const DVector2& nVelVect, const double nMaxVel, const bool bUnderwater);
|
2021-07-18 09:25:41 +00:00
|
|
|
|
2022-11-27 02:36:55 +00:00
|
|
|
// General methods.
|
2022-12-09 06:55:13 +00:00
|
|
|
void initialize(DCoreActor* const actor, const DAngle viewyaw = nullAngle)
|
|
|
|
{
|
2023-09-28 22:31:48 +00:00
|
|
|
memset(this, 0, sizeof(*this));
|
2023-09-27 11:14:58 +00:00
|
|
|
pActor = actor;
|
|
|
|
CameraAngles = PrevLerpAngles = pActor->spr.Angles;
|
2022-12-09 06:55:13 +00:00
|
|
|
PrevViewAngles.Yaw = ViewAngles.Yaw = viewyaw;
|
|
|
|
}
|
2022-11-25 11:24:32 +00:00
|
|
|
DAngle getPitchWithView()
|
|
|
|
{
|
2022-12-09 06:55:13 +00:00
|
|
|
return ClampViewPitch(pActor->spr.Angles.Pitch + ViewAngles.Pitch);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render angle functions.
|
2023-03-18 09:14:01 +00:00
|
|
|
const DRotator& getCameraAngles() const
|
2023-03-18 08:48:18 +00:00
|
|
|
{
|
|
|
|
return CameraAngles;
|
|
|
|
}
|
2022-12-05 05:09:43 +00:00
|
|
|
DRotator getRenderAngles(const double interpfrac)
|
|
|
|
{
|
2022-12-09 06:55:13 +00:00
|
|
|
// Get angles and return with clamped off pitch.
|
2023-03-17 03:20:36 +00:00
|
|
|
auto angles = CameraAngles + interpolatedvalue(PrevViewAngles, ViewAngles, interpfrac);
|
2022-12-09 06:55:13 +00:00
|
|
|
angles.Pitch = ClampViewPitch(angles.Pitch);
|
|
|
|
return angles;
|
|
|
|
}
|
2023-03-17 03:20:36 +00:00
|
|
|
void updateCameraAngles(const double interpfrac)
|
2022-12-09 06:55:13 +00:00
|
|
|
{
|
|
|
|
// Apply the current interpolated angle state to the render angles.
|
2023-02-04 06:05:18 +00:00
|
|
|
const auto lerpAngles = interpolatedvalue(pActor->PrevAngles, pActor->spr.Angles, interpfrac);
|
2023-03-17 03:20:36 +00:00
|
|
|
CameraAngles += lerpAngles - PrevLerpAngles;
|
2022-12-09 06:55:13 +00:00
|
|
|
PrevLerpAngles = lerpAngles;
|
|
|
|
}
|
2023-03-17 03:20:36 +00:00
|
|
|
void resetCameraAngles()
|
2022-12-09 06:55:13 +00:00
|
|
|
{
|
2023-10-02 19:38:58 +00:00
|
|
|
if (pActor != nullptr)
|
|
|
|
{
|
|
|
|
// Apply any last remaining ticrate angle updates and reset variables.
|
|
|
|
CameraAngles += pActor->spr.Angles - PrevLerpAngles;
|
|
|
|
PrevLerpAngles = pActor->spr.Angles = CameraAngles;
|
|
|
|
PrevViewAngles = ViewAngles;
|
|
|
|
}
|
2022-12-05 05:09:43 +00:00
|
|
|
}
|
|
|
|
|
2022-12-02 07:16:04 +00:00
|
|
|
// Draw code helpers.
|
|
|
|
auto getCrosshairOffsets(const double interpfrac)
|
|
|
|
{
|
2023-02-04 06:05:18 +00:00
|
|
|
// Set up angles and return as pair with roll as the 2nd object since all callers inevitably need it.
|
|
|
|
const auto viewAngles = interpolatedvalue(PrevViewAngles, ViewAngles, interpfrac);
|
|
|
|
return std::make_pair(DVector2(160, 120 * -viewAngles.Roll.Tan()) * -viewAngles.Yaw.Tan() / tan(r_fov * pi::pi() / 360.), viewAngles.Roll);
|
2022-12-02 07:16:04 +00:00
|
|
|
}
|
|
|
|
auto getWeaponOffsets(const double interpfrac)
|
|
|
|
{
|
2023-03-16 05:34:31 +00:00
|
|
|
// Push the Y down a bit since the weapon is at the edge of the screen. Also null roll for now.
|
|
|
|
auto offsets = getCrosshairOffsets(interpfrac); offsets.first.Y *= 4.; offsets.second = nullAngle;
|
2022-12-02 07:16:04 +00:00
|
|
|
return offsets;
|
|
|
|
}
|
|
|
|
|
2021-04-02 11:46:43 +00:00
|
|
|
private:
|
2023-03-18 08:48:18 +00:00
|
|
|
// Private data which should never be accessed publicly.
|
|
|
|
DRotator PrevLerpAngles, CameraAngles;
|
2022-11-27 02:36:55 +00:00
|
|
|
DCoreActor* pActor;
|
2023-04-03 07:07:34 +00:00
|
|
|
|
|
|
|
// Constants used throughout input functions.
|
2023-04-22 12:45:12 +00:00
|
|
|
static constexpr double ROLL_TILTAVELSCALE = (1966426. / 12000000.);
|
2023-10-06 22:37:45 +00:00
|
|
|
static constexpr DAngle ROLL_TILTAVELMAX = DAngle::fromDeg(90. / 32. * 1.5);
|
2023-04-22 09:34:44 +00:00
|
|
|
static constexpr double ROLL_TILTRETURN = 15.;
|
2023-04-03 07:07:34 +00:00
|
|
|
static constexpr double YAW_LOOKINGSPEED = 801.5625;
|
|
|
|
static constexpr double YAW_ROTATESPEED = 63.28125;
|
|
|
|
static constexpr double YAW_LOOKRETURN = 7.5;
|
|
|
|
static constexpr double YAW_SPINSTAND = 675.;
|
|
|
|
static constexpr double YAW_SPINCROUCH = YAW_SPINSTAND * 0.5;
|
2023-04-21 10:09:19 +00:00
|
|
|
static constexpr double PITCH_LOOKSPEED = (269426662. / 1209103.);
|
2023-04-03 07:07:34 +00:00
|
|
|
static constexpr double PITCH_AIMSPEED = PITCH_LOOKSPEED * 0.5;
|
|
|
|
static constexpr double PITCH_CENTERSPEED = 10.7375;
|
|
|
|
static constexpr double PITCH_HORIZOFFSPEED = 4.375;
|
|
|
|
static constexpr DAngle PITCH_CNTRSINEOFFSET = DAngle90 / 8.;
|
2023-04-22 12:45:12 +00:00
|
|
|
static constexpr DAngle PITCH_HORIZOFFCLIMB = DAngle::fromDeg(-127076387. / 3344227.);
|
2023-10-06 22:37:45 +00:00
|
|
|
static constexpr DAngle PITCH_HORIZOFFPUSH = DAngle::fromDeg(14115687. / 31535389.);
|
2020-10-11 14:33:43 +00:00
|
|
|
};
|
|
|
|
|
2023-04-03 08:46:36 +00:00
|
|
|
extern GameInput gameInput;
|
|
|
|
|
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);
|
2023-10-06 22:37:45 +00:00
|
|
|
bool scaletozero(DAngle& angle, const double scale, const DAngle push = DAngle::fromDeg(7646143. / 110386328.));
|