mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-15 08:52:00 +00:00
- Blood: Clean up remainder of control.cpp in-line with Duke/SW.
* Split input bits and movement into separate functions. * Reordered movement to be more like Duke/SW for ease of comparison. * Removed a global. * Removed a few includes.
This commit is contained in:
parent
9c56dfffe0
commit
db7793bf54
4 changed files with 115 additions and 100 deletions
|
@ -337,7 +337,7 @@ void GameInterface::Ticker()
|
|||
thinktime.Unclock();
|
||||
|
||||
gFrameCount++;
|
||||
gFrameClock += 4;
|
||||
gFrameClock += kTicsPerFrame;
|
||||
if (gFrameClock == 8) gameaction = ga_autosave; // let the game run for 1 frame before saving.
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
|
|
|
@ -23,48 +23,115 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
|
||||
#include "ns.h" // Must come before everything else!
|
||||
|
||||
#include "compat.h"
|
||||
#include "mmulti.h"
|
||||
#include "gamecontrol.h"
|
||||
#include "common_game.h"
|
||||
#include "blood.h"
|
||||
#include "globals.h"
|
||||
#include "levels.h"
|
||||
#include "view.h"
|
||||
#include "d_event.h"
|
||||
#include "gamestate.h"
|
||||
#include "sound.h"
|
||||
#include "menu.h"
|
||||
|
||||
BEGIN_BLD_NS
|
||||
|
||||
static const double gTurnSpeed = 92.;
|
||||
static InputPacket gInput;
|
||||
static double turnHeldTime;
|
||||
|
||||
enum
|
||||
{
|
||||
MAXFVEL = 2048,
|
||||
MAXSVEL = 2048,
|
||||
MAXHORIZVEL = 32
|
||||
};
|
||||
|
||||
void applylook(PLAYER *pPlayer, fixed_t const q16avel, double const scaleAdjust);
|
||||
void sethorizon(PLAYER *pPlayer, fixed_t const q16horz, double const scaleAdjust);
|
||||
|
||||
static void GetInputInternal(ControlInfo* const hidInput)
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// handles the input bits
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
static void processInputBits(ControlInfo* const hidInput, bool* mouseaim)
|
||||
{
|
||||
ApplyGlobalInput(gInput, hidInput);
|
||||
*mouseaim = !(gInput.actions & SB_AIMMODE);
|
||||
|
||||
if (!mouseaim || (gInput.actions & (SB_LOOK_UP|SB_LOOK_DOWN)))
|
||||
{
|
||||
gInput.actions |= SB_CENTERVIEW;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// handles movement
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
static void processMovement(ControlInfo* const hidInput, bool const mouseaim)
|
||||
{
|
||||
double const scaleAdjust = InputScale();
|
||||
int prevPauseState = paused;
|
||||
|
||||
InputPacket input = {};
|
||||
|
||||
ApplyGlobalInput(gInput, hidInput);
|
||||
|
||||
bool mouseaim = !(gInput.actions & SB_AIMMODE);
|
||||
if (!mouseaim) gInput.actions |= SB_CENTERVIEW;
|
||||
|
||||
if (gPlayer[myconnectindex].nextWeapon == 0)
|
||||
{
|
||||
}
|
||||
|
||||
if (gInput.actions & (SB_LOOK_UP|SB_LOOK_DOWN))
|
||||
gInput.actions |= SB_CENTERVIEW;
|
||||
|
||||
int const run = !!(gInput.actions & SB_RUN);
|
||||
int const keyMove = (1 + run) << 10;
|
||||
InputPacket input = {};
|
||||
|
||||
if (gInput.fvel < keyMove && gInput.fvel > -keyMove)
|
||||
if (buttonMap.ButtonDown(gamefunc_Strafe))
|
||||
{
|
||||
input.svel -= xs_CRoundToInt((hidInput->mousex * 32.) + (scaleAdjust * (hidInput->dyaw * keyMove)));
|
||||
}
|
||||
else
|
||||
{
|
||||
input.q16avel += FloatToFixed(hidInput->mousex + (scaleAdjust * hidInput->dyaw));
|
||||
}
|
||||
|
||||
if (mouseaim)
|
||||
{
|
||||
input.q16horz += FloatToFixed(hidInput->mousey);
|
||||
}
|
||||
else
|
||||
{
|
||||
input.fvel -= xs_CRoundToInt(hidInput->mousey * 64.);
|
||||
}
|
||||
|
||||
if (!in_mouseflip)
|
||||
input.q16horz = -input.q16horz;
|
||||
|
||||
input.q16horz -= FloatToFixed(scaleAdjust * hidInput->dpitch);
|
||||
input.svel -= xs_CRoundToInt(scaleAdjust * (hidInput->dx * keyMove));
|
||||
input.fvel -= xs_CRoundToInt(scaleAdjust * (hidInput->dz * keyMove));
|
||||
|
||||
if (buttonMap.ButtonDown(gamefunc_Strafe))
|
||||
{
|
||||
if (gInput.svel < keyMove && gInput.svel > -keyMove)
|
||||
{
|
||||
if (buttonMap.ButtonDown(gamefunc_Turn_Left))
|
||||
input.svel += keyMove;
|
||||
|
||||
if (buttonMap.ButtonDown(gamefunc_Turn_Right))
|
||||
input.svel -= keyMove;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (buttonMap.ButtonDown(gamefunc_Turn_Left))
|
||||
{
|
||||
turnHeldTime += scaleAdjust * kTicsPerFrame;
|
||||
input.q16avel -= FloatToFixed(scaleAdjust * (min(12. * turnHeldTime, gTurnSpeed) / 4.));
|
||||
}
|
||||
else if (buttonMap.ButtonDown(gamefunc_Turn_Right))
|
||||
{
|
||||
turnHeldTime += scaleAdjust * kTicsPerFrame;
|
||||
input.q16avel += FloatToFixed(scaleAdjust * (min(12. * turnHeldTime, gTurnSpeed) / 4.));
|
||||
}
|
||||
else
|
||||
{
|
||||
turnHeldTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (run && turnHeldTime > 24.)
|
||||
input.q16avel <<= 1;
|
||||
|
||||
if (abs(gInput.fvel) < keyMove)
|
||||
{
|
||||
if (buttonMap.ButtonDown(gamefunc_Move_Forward))
|
||||
input.fvel += keyMove;
|
||||
|
@ -73,91 +140,41 @@ static void GetInputInternal(ControlInfo* const hidInput)
|
|||
input.fvel -= keyMove;
|
||||
}
|
||||
|
||||
if (gInput.svel < keyMove && gInput.svel > -keyMove)
|
||||
if (abs(gInput.svel) < keyMove)
|
||||
{
|
||||
if (buttonMap.ButtonDown(gamefunc_Strafe_Left))
|
||||
input.svel += keyMove;
|
||||
|
||||
if (buttonMap.ButtonDown(gamefunc_Strafe_Right))
|
||||
input.svel -= keyMove;
|
||||
}
|
||||
|
||||
|
||||
char turnLeft = 0, turnRight = 0;
|
||||
|
||||
if (buttonMap.ButtonDown(gamefunc_Strafe))
|
||||
{
|
||||
if (gInput.svel < keyMove && gInput.svel > -keyMove)
|
||||
{
|
||||
if (buttonMap.ButtonDown(gamefunc_Turn_Left))
|
||||
input.svel += keyMove;
|
||||
if (buttonMap.ButtonDown(gamefunc_Turn_Right))
|
||||
input.svel -= keyMove;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (buttonMap.ButtonDown(gamefunc_Turn_Left))
|
||||
turnLeft = 1;
|
||||
if (buttonMap.ButtonDown(gamefunc_Turn_Right))
|
||||
turnRight = 1;
|
||||
}
|
||||
|
||||
static int32_t turnHeldTime;
|
||||
static int32_t lastInputClock; // MED
|
||||
int32_t const elapsedTics = gFrameClock - lastInputClock;
|
||||
|
||||
lastInputClock = gFrameClock;
|
||||
|
||||
if (turnLeft || turnRight)
|
||||
turnHeldTime += elapsedTics;
|
||||
else
|
||||
turnHeldTime = 0;
|
||||
|
||||
if (turnLeft)
|
||||
input.q16avel -= FloatToFixed(scaleAdjust * (ClipHigh(12 * turnHeldTime, gTurnSpeed) >> 2));
|
||||
if (turnRight)
|
||||
input.q16avel += FloatToFixed(scaleAdjust * (ClipHigh(12 * turnHeldTime, gTurnSpeed) >> 2));
|
||||
|
||||
if (run && turnHeldTime > 24)
|
||||
input.q16avel <<= 1;
|
||||
|
||||
if (buttonMap.ButtonDown(gamefunc_Strafe))
|
||||
{
|
||||
input.svel -= xs_CRoundToInt((hidInput->mousex * 32.) + (scaleAdjust * (hidInput->dyaw * keyMove)));
|
||||
}
|
||||
else
|
||||
{
|
||||
input.q16avel += FloatToFixed(hidInput->mousex + (scaleAdjust * (hidInput->dyaw)));
|
||||
}
|
||||
|
||||
input.svel -= xs_CRoundToInt(scaleAdjust * (hidInput->dx * keyMove));
|
||||
input.fvel -= xs_CRoundToInt(scaleAdjust * (hidInput->dz * keyMove));
|
||||
|
||||
if (mouseaim)
|
||||
input.q16horz += FloatToFixed(hidInput->mousey);
|
||||
else
|
||||
input.fvel -= xs_CRoundToInt(hidInput->mousey * 64.);
|
||||
|
||||
if (!in_mouseflip)
|
||||
input.q16horz = -input.q16horz;
|
||||
|
||||
input.q16horz -= FloatToFixed(scaleAdjust * hidInput->dpitch);
|
||||
|
||||
gInput.fvel = clamp(gInput.fvel + input.fvel, -2048, 2048);
|
||||
gInput.svel = clamp(gInput.svel + input.svel, -2048, 2048);
|
||||
gInput.q16avel += input.q16avel;
|
||||
gInput.q16horz = clamp(gInput.q16horz + input.q16horz, IntToFixed(-127) >> 2, IntToFixed(127) >> 2);
|
||||
|
||||
if (!cl_syncinput && gamestate == GS_LEVEL)
|
||||
{
|
||||
applylook(&gPlayer[myconnectindex], input.q16avel, scaleAdjust);
|
||||
sethorizon(&gPlayer[myconnectindex], input.q16horz, scaleAdjust);
|
||||
PLAYER* pPlayer = &gPlayer[myconnectindex];
|
||||
applylook(pPlayer, input.q16avel, scaleAdjust);
|
||||
sethorizon(pPlayer, input.q16horz, scaleAdjust);
|
||||
}
|
||||
|
||||
gInput.fvel = clamp(gInput.fvel + input.fvel, -MAXFVEL, MAXFVEL);
|
||||
gInput.svel = clamp(gInput.svel + input.svel, -MAXSVEL, MAXSVEL);
|
||||
gInput.q16avel += input.q16avel;
|
||||
gInput.q16horz = clamp(gInput.q16horz + input.q16horz, -IntToFixed(MAXHORIZVEL), IntToFixed(MAXHORIZVEL));
|
||||
}
|
||||
|
||||
void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput)
|
||||
{
|
||||
GetInputInternal(hidInput);
|
||||
if (paused || M_Active())
|
||||
{
|
||||
gInput = {};
|
||||
return;
|
||||
}
|
||||
|
||||
bool mouseaim;
|
||||
|
||||
processInputBits(hidInput, &mouseaim);
|
||||
processMovement(hidInput, mouseaim);
|
||||
|
||||
if (packet)
|
||||
{
|
||||
*packet = gInput;
|
||||
|
|
|
@ -38,7 +38,6 @@ int gFrameCount;
|
|||
static const char *_module;
|
||||
static int _line;
|
||||
|
||||
int32_t gTurnSpeed = 92;
|
||||
int32_t gDetail = 4;
|
||||
bool gNoClip;
|
||||
bool gInfiniteAmmo;
|
||||
|
|
|
@ -35,7 +35,6 @@ extern int gFrameCount;
|
|||
|
||||
#define MAXPLAYERNAME 16
|
||||
|
||||
extern int32_t gTurnSpeed;
|
||||
extern int32_t gDetail;
|
||||
extern bool gNoClip;
|
||||
extern bool gInfiniteAmmo;
|
||||
|
|
Loading…
Reference in a new issue