2020-10-11 16:33:43 +02:00
|
|
|
#pragma once
|
|
|
|
|
2023-03-13 21:33:37 +11:00
|
|
|
#include "serializer.h"
|
2023-10-31 14:44:58 +11:00
|
|
|
#include "coreplayer.h"
|
2023-10-05 13:10:47 +11:00
|
|
|
#include "d_net.h"
|
2020-10-11 16:33:43 +02:00
|
|
|
|
2023-09-24 13:40:15 +10:00
|
|
|
enum : unsigned
|
|
|
|
{
|
|
|
|
CS_CANCROUCH = 1,
|
|
|
|
CS_DISABLETOGGLE = 2,
|
|
|
|
};
|
|
|
|
|
2023-09-25 19:51:53 +10:00
|
|
|
enum : unsigned
|
|
|
|
{
|
|
|
|
VEH_CANMOVE = 1,
|
|
|
|
VEH_CANTURN = 2,
|
|
|
|
VEH_SCALETURN = 4,
|
|
|
|
};
|
|
|
|
|
2023-04-03 18:46:36 +10:00
|
|
|
class GameInput
|
|
|
|
{
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
BUILDTICRATE = 120,
|
|
|
|
TURBOTURNBASE = 590,
|
|
|
|
};
|
|
|
|
|
2023-04-21 20:09:19 +10:00
|
|
|
static constexpr double YAW_TURNSPEEDS[3] = { 234.375 * (360. / 2048.), 890.625 * (360. / 2048.), 1548.75 * (360. / 2048.) };
|
2023-10-04 08:56:08 +11:00
|
|
|
static constexpr DVector3 MAXVEL[3] = { { 0., 0., 1. }, { 1., 1., 1. }, { 2., 2., 1. } };
|
2023-11-13 20:44:47 +11:00
|
|
|
static constexpr DRotator MAXANG = { DAngle90 - minAngle, DAngle180 - minAngle, DAngle180 - minAngle };
|
2023-10-03 20:58:38 +11:00
|
|
|
static constexpr DAngle MOUSE_SCALE = DAngle::fromDeg(1. / 16.);
|
2023-04-03 18:46:36 +10:00
|
|
|
|
2023-04-03 18:40:34 +10:00
|
|
|
// Input received from the OS.
|
|
|
|
float joyAxes[NUM_JOYAXIS];
|
2023-10-04 19:20:57 +11:00
|
|
|
FVector2 mouseInput;
|
2023-04-03 18:40:34 +10:00
|
|
|
|
2023-04-03 18:46:36 +10:00
|
|
|
// Internal variables when generating a packet.
|
|
|
|
InputPacket inputBuffer;
|
2023-10-04 16:08:03 +11:00
|
|
|
ESyncBits ActionsToSend;
|
2023-04-03 18:46:36 +10:00
|
|
|
double turnheldtime;
|
2023-10-04 16:08:03 +11:00
|
|
|
double scaleAdjust;
|
2023-10-05 13:10:47 +11:00
|
|
|
bool syncinput;
|
2023-04-03 18:46:36 +10:00
|
|
|
int WeaponToSend;
|
|
|
|
int dpad_lock;
|
2023-10-04 16:08:03 +11:00
|
|
|
int keymove;
|
2023-04-03 18:46:36 +10:00
|
|
|
|
|
|
|
// Turn speed doubling after x amount of tics.
|
2023-10-04 16:08:03 +11:00
|
|
|
void updateTurnHeldAmt()
|
2023-04-03 18:46:36 +10:00
|
|
|
{
|
2023-10-31 14:44:58 +11:00
|
|
|
turnheldtime += getTicrateScale(BUILDTICRATE * scaleAdjust);
|
2023-04-03 18:46:36 +10:00
|
|
|
}
|
|
|
|
bool isTurboTurnTime()
|
|
|
|
{
|
|
|
|
return turnheldtime >= getTicrateScale(TURBOTURNBASE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prototypes for private member functions.
|
2023-04-03 18:40:34 +10:00
|
|
|
void processInputBits();
|
2023-04-03 18:46:36 +10:00
|
|
|
|
|
|
|
public:
|
|
|
|
// Bit sender updates.
|
|
|
|
void SendWeapon(const int weapon)
|
|
|
|
{
|
|
|
|
WeaponToSend = weapon;
|
|
|
|
}
|
|
|
|
void SendAction(const ESyncBits action)
|
|
|
|
{
|
|
|
|
ActionsToSend |= action;
|
|
|
|
}
|
|
|
|
|
2023-09-24 17:50:06 +10:00
|
|
|
// Clear all values within this object.
|
|
|
|
void Clear()
|
|
|
|
{
|
2023-09-29 08:31:03 +10:00
|
|
|
memset(this, 0, sizeof(*this));
|
2023-09-24 17:50:06 +10:00
|
|
|
}
|
|
|
|
|
2023-04-03 18:40:34 +10:00
|
|
|
// Receives mouse input from OS for processing.
|
|
|
|
void MouseAddToPos(float x, float y)
|
|
|
|
{
|
|
|
|
mouseInput.X += x;
|
|
|
|
mouseInput.Y += y;
|
|
|
|
}
|
|
|
|
|
2023-10-04 16:08:03 +11: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 13:10:47 +11: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 18:46:36 +10:00
|
|
|
// Prototypes for large member functions.
|
2023-10-04 16:08:03 +11: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 17:50:06 +10:00
|
|
|
void resetCrouchToggle();
|
2023-04-03 18:46:36 +10:00
|
|
|
};
|
2023-04-02 18:26:22 +10:00
|
|
|
|
2023-04-03 18:46:36 +10:00
|
|
|
extern GameInput gameInput;
|