mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-27 20:20:40 +00:00
- split the game input code off gamecontrol.cpp into its own file.
This commit is contained in:
parent
8e1c71b867
commit
1757ef2aa6
9 changed files with 517 additions and 477 deletions
|
@ -784,6 +784,7 @@ set (PCH_SOURCES
|
|||
core/gameconfigfile.cpp
|
||||
core/gamecvars.cpp
|
||||
core/gamecontrol.cpp
|
||||
core/gameinput.cpp
|
||||
core/inputstate.cpp
|
||||
core/maphack.cpp
|
||||
core/mapinfo.cpp
|
||||
|
|
|
@ -31,6 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#include "dude.h"
|
||||
#include "levels.h"
|
||||
#include "qav.h"
|
||||
#include "gameinput.h"
|
||||
|
||||
BEGIN_BLD_NS
|
||||
|
||||
|
|
|
@ -76,8 +76,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
|
||||
CVAR(Bool, autoloadlights, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
||||
CVAR(Bool, autoloadbrightmaps, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
CVARD(Bool, invertmousex, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "invert horizontal mouse movement")
|
||||
CVARD(Bool, invertmouse, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "invert vertical mouse movement")
|
||||
|
||||
EXTERN_CVAR(Bool, ui_generic)
|
||||
|
||||
|
@ -1400,303 +1398,6 @@ void LoadDefinitions()
|
|||
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// code fron gameexec/conrun
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
int getincangle(int a, int na)
|
||||
{
|
||||
a &= 2047;
|
||||
na &= 2047;
|
||||
|
||||
if(abs(a-na) < 1024)
|
||||
return (na-a);
|
||||
else
|
||||
{
|
||||
if(na > 1024) na -= 2048;
|
||||
if(a > 1024) a -= 2048;
|
||||
|
||||
na -= 2048;
|
||||
a -= 2048;
|
||||
return (na-a);
|
||||
}
|
||||
}
|
||||
|
||||
fixed_t getincangleq16(fixed_t a, fixed_t na)
|
||||
{
|
||||
a &= 0x7FFFFFF;
|
||||
na &= 0x7FFFFFF;
|
||||
|
||||
if(abs(a-na) < IntToFixed(1024))
|
||||
return (na-a);
|
||||
else
|
||||
{
|
||||
if(na > IntToFixed(1024)) na -= IntToFixed(2048);
|
||||
if(a > IntToFixed(1024)) a -= IntToFixed(2048);
|
||||
|
||||
na -= IntToFixed(2048);
|
||||
a -= IntToFixed(2048);
|
||||
return (na-a);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Player's movement function, called from game's ticker or from gi->GetInput() as required.
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void processMovement(InputPacket* currInput, InputPacket* inputBuffer, ControlInfo* const hidInput, double const scaleAdjust, int const drink_amt, bool const allowstrafe, double const turnscale)
|
||||
{
|
||||
// set up variables
|
||||
int const running = !!(inputBuffer->actions & SB_RUN);
|
||||
int const keymove = gi->playerKeyMove() << running;
|
||||
int const cntrlvelscale = g_gameType & GAMEFLAG_PSEXHUMED ? 8 : 1;
|
||||
float const mousevelscale = keymove / 160.f;
|
||||
double const angtodegscale = 45. / 256.;
|
||||
double const hidspeed = ((running ? 43375. / 27. : 867.5) / GameTicRate) * angtodegscale;
|
||||
|
||||
// process mouse and initial controller input.
|
||||
if (buttonMap.ButtonDown(gamefunc_Strafe) && allowstrafe)
|
||||
currInput->svel -= xs_CRoundToInt((hidInput->mousemovex * mousevelscale) + (scaleAdjust * (hidInput->dyaw / 60) * keymove * cntrlvelscale));
|
||||
else
|
||||
currInput->avel += hidInput->mouseturnx + (scaleAdjust * hidInput->dyaw * hidspeed * turnscale);
|
||||
|
||||
if (!(inputBuffer->actions & SB_AIMMODE))
|
||||
currInput->horz -= hidInput->mouseturny;
|
||||
else
|
||||
currInput->fvel -= xs_CRoundToInt(hidInput->mousemovey * mousevelscale);
|
||||
|
||||
if (invertmouse)
|
||||
currInput->horz = -currInput->horz;
|
||||
|
||||
if (invertmousex)
|
||||
currInput->avel = -currInput->avel;
|
||||
|
||||
// process remaining controller input.
|
||||
currInput->horz -= scaleAdjust * hidInput->dpitch * hidspeed;
|
||||
currInput->svel -= xs_CRoundToInt(scaleAdjust * hidInput->dx * keymove * cntrlvelscale);
|
||||
currInput->fvel -= xs_CRoundToInt(scaleAdjust * hidInput->dz * keymove * cntrlvelscale);
|
||||
|
||||
// process keyboard turning keys.
|
||||
if (buttonMap.ButtonDown(gamefunc_Strafe) && allowstrafe)
|
||||
{
|
||||
if (abs(inputBuffer->svel) < keymove)
|
||||
{
|
||||
if (buttonMap.ButtonDown(gamefunc_Turn_Left))
|
||||
currInput->svel += keymove;
|
||||
|
||||
if (buttonMap.ButtonDown(gamefunc_Turn_Right))
|
||||
currInput->svel -= keymove;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
static double turnheldtime;
|
||||
int const turnheldamt = 120 / GameTicRate;
|
||||
double const turboturntime = 590. / GameTicRate;
|
||||
double turnamount = hidspeed * turnscale;
|
||||
double preambleturn = turnamount * (92. / 347.);
|
||||
|
||||
// allow Exhumed to use its legacy values given the drastic difference from the other games.
|
||||
if ((g_gameType & GAMEFLAG_PSEXHUMED) && cl_exhumedoldturn)
|
||||
{
|
||||
preambleturn = turnamount = (running ? 12 : 8) * angtodegscale;
|
||||
}
|
||||
|
||||
if (buttonMap.ButtonDown(gamefunc_Turn_Left) || (buttonMap.ButtonDown(gamefunc_Strafe_Left) && !allowstrafe))
|
||||
{
|
||||
turnheldtime += scaleAdjust * turnheldamt;
|
||||
currInput->avel -= scaleAdjust * (turnheldtime >= turboturntime ? turnamount : preambleturn);
|
||||
}
|
||||
else if (buttonMap.ButtonDown(gamefunc_Turn_Right) || (buttonMap.ButtonDown(gamefunc_Strafe_Right) && !allowstrafe))
|
||||
{
|
||||
turnheldtime += scaleAdjust * turnheldamt;
|
||||
currInput->avel += scaleAdjust * (turnheldtime >= turboturntime ? turnamount : preambleturn);
|
||||
}
|
||||
else
|
||||
{
|
||||
turnheldtime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// process keyboard forward/side velocity keys.
|
||||
if (abs(inputBuffer->svel) < keymove)
|
||||
{
|
||||
if (buttonMap.ButtonDown(gamefunc_Strafe_Left) && allowstrafe)
|
||||
currInput->svel += keymove;
|
||||
|
||||
if (buttonMap.ButtonDown(gamefunc_Strafe_Right) && allowstrafe)
|
||||
currInput->svel -= keymove;
|
||||
}
|
||||
if (abs(inputBuffer->fvel) < keymove)
|
||||
{
|
||||
if (isRR() && drink_amt >= 66 && drink_amt <= 87)
|
||||
{
|
||||
if (buttonMap.ButtonDown(gamefunc_Move_Forward))
|
||||
{
|
||||
currInput->fvel += keymove;
|
||||
if (drink_amt & 1)
|
||||
currInput->svel += keymove;
|
||||
else
|
||||
currInput->svel -= keymove;
|
||||
}
|
||||
|
||||
if (buttonMap.ButtonDown(gamefunc_Move_Backward))
|
||||
{
|
||||
currInput->fvel -= keymove;
|
||||
if (drink_amt & 1)
|
||||
currInput->svel -= keymove;
|
||||
else
|
||||
currInput->svel += keymove;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (buttonMap.ButtonDown(gamefunc_Move_Forward))
|
||||
currInput->fvel += keymove;
|
||||
|
||||
if (buttonMap.ButtonDown(gamefunc_Move_Backward))
|
||||
currInput->fvel -= keymove;
|
||||
}
|
||||
}
|
||||
|
||||
// add collected input to game's local input accumulation packet.
|
||||
inputBuffer->fvel = clamp(inputBuffer->fvel + currInput->fvel, -keymove, keymove);
|
||||
inputBuffer->svel = clamp(inputBuffer->svel + currInput->svel, -keymove, keymove);
|
||||
inputBuffer->avel += currInput->avel;
|
||||
inputBuffer->horz += currInput->horz;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Player's horizon function, called from game's ticker or from gi->GetInput() as required.
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void sethorizon(fixedhoriz* horiz, float const horz, ESyncBits* actions, double const scaleAdjust)
|
||||
{
|
||||
// Store current horizon as true pitch.
|
||||
double pitch = horiz->aspitch();
|
||||
|
||||
if (horz)
|
||||
{
|
||||
*actions &= ~SB_CENTERVIEW;
|
||||
pitch += horz;
|
||||
}
|
||||
|
||||
// this is the locked type
|
||||
if (*actions & (SB_AIM_UP|SB_AIM_DOWN))
|
||||
{
|
||||
*actions &= ~SB_CENTERVIEW;
|
||||
double const amount = HorizToPitch(250. / GameTicRate);
|
||||
|
||||
if (*actions & SB_AIM_DOWN)
|
||||
pitch -= scaleAdjust * amount;
|
||||
|
||||
if (*actions & SB_AIM_UP)
|
||||
pitch += scaleAdjust * amount;
|
||||
}
|
||||
|
||||
// this is the unlocked type
|
||||
if (*actions & (SB_LOOK_UP|SB_LOOK_DOWN))
|
||||
{
|
||||
*actions |= SB_CENTERVIEW;
|
||||
double const amount = HorizToPitch(500. / GameTicRate);
|
||||
|
||||
if (*actions & SB_LOOK_DOWN)
|
||||
pitch -= scaleAdjust * amount;
|
||||
|
||||
if (*actions & SB_LOOK_UP)
|
||||
pitch += scaleAdjust * amount;
|
||||
}
|
||||
|
||||
// clamp pitch after processing
|
||||
pitch = clamp(pitch, -90, 90);
|
||||
|
||||
// return to center if conditions met.
|
||||
if ((*actions & SB_CENTERVIEW) && !(*actions & (SB_LOOK_UP|SB_LOOK_DOWN)))
|
||||
{
|
||||
if (abs(pitch) > 0.1375)
|
||||
{
|
||||
// move pitch back to 0
|
||||
pitch += -scaleAdjust * pitch * (9. / GameTicRate);
|
||||
}
|
||||
else
|
||||
{
|
||||
// not looking anymore because pitch is back at 0
|
||||
pitch = 0;
|
||||
*actions &= ~SB_CENTERVIEW;
|
||||
}
|
||||
}
|
||||
|
||||
// clamp before returning
|
||||
*horiz = q16horiz(clamp(PitchToHoriz(pitch), gi->playerHorizMin(), gi->playerHorizMax()));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Player's angle function, called from game's ticker or from gi->GetInput() as required.
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void applylook(PlayerAngle* angle, float const avel, ESyncBits* actions, double const scaleAdjust, bool const crouching)
|
||||
{
|
||||
// return q16rotscrnang to 0 and set to 0 if less than a quarter of a unit
|
||||
angle->rotscrnang -= bamlook(xs_CRoundToInt(scaleAdjust * angle->rotscrnang.asbam() * (15. / GameTicRate)));
|
||||
if (abs(angle->rotscrnang.asbam()) < (BAMUNIT >> 2)) angle->rotscrnang = bamlook(0);
|
||||
|
||||
// return q16look_ang to 0 and set to 0 if less than a quarter of a unit
|
||||
angle->look_ang -= bamlook(xs_CRoundToInt(scaleAdjust * angle->look_ang.asbam() * (7.5 / GameTicRate)));
|
||||
if (abs(angle->look_ang.asbam()) < (BAMUNIT >> 2)) angle->look_ang = bamlook(0);
|
||||
|
||||
if (*actions & SB_LOOK_LEFT)
|
||||
{
|
||||
// start looking left
|
||||
angle->look_ang -= bamlook(xs_CRoundToInt(scaleAdjust * (4560. / GameTicRate) * BAMUNIT));
|
||||
angle->rotscrnang += bamlook(xs_CRoundToInt(scaleAdjust * (720. / GameTicRate) * BAMUNIT));
|
||||
}
|
||||
|
||||
if (*actions & SB_LOOK_RIGHT)
|
||||
{
|
||||
// start looking right
|
||||
angle->look_ang += bamlook(xs_CRoundToInt(scaleAdjust * (4560. / GameTicRate) * BAMUNIT));
|
||||
angle->rotscrnang -= bamlook(xs_CRoundToInt(scaleAdjust * (720. / GameTicRate) * BAMUNIT));
|
||||
}
|
||||
|
||||
if (*actions & SB_TURNAROUND)
|
||||
{
|
||||
if (angle->spin.asbam() == 0)
|
||||
{
|
||||
// currently not spinning, so start a spin
|
||||
angle->spin = buildlook(-1024);
|
||||
}
|
||||
*actions &= ~SB_TURNAROUND;
|
||||
}
|
||||
|
||||
if (angle->spin.asbam() < 0)
|
||||
{
|
||||
// return spin to 0
|
||||
lookangle add = bamlook(xs_CRoundToUInt(scaleAdjust * ((!crouching ? 3840. : 1920.) / GameTicRate) * BAMUNIT));
|
||||
angle->spin += add;
|
||||
if (angle->spin.asbam() > 0)
|
||||
{
|
||||
// Don't overshoot our target. With variable factor this is possible.
|
||||
add -= angle->spin;
|
||||
angle->spin = bamlook(0);
|
||||
}
|
||||
angle->ang += bamang(add.asbam());
|
||||
}
|
||||
|
||||
if (avel)
|
||||
{
|
||||
// add player's input
|
||||
angle->ang += degang(avel);
|
||||
}
|
||||
}
|
||||
|
||||
bool M_Active()
|
||||
{
|
||||
return CurrentMenu != nullptr || ConsoleState == c_down || ConsoleState == c_falling;
|
||||
|
|
|
@ -61,184 +61,6 @@ void DeferedStartGame(MapRecord* map, int skill, bool nostopsound = false);
|
|||
void ChangeLevel(MapRecord* map, int skill);
|
||||
void CompleteLevel(MapRecord* map);
|
||||
|
||||
int getincangle(int c, int n);
|
||||
fixed_t getincangleq16(fixed_t c, fixed_t n);
|
||||
|
||||
struct PlayerHorizon
|
||||
{
|
||||
fixedhoriz horiz, ohoriz, horizoff, ohorizoff;
|
||||
fixed_t target;
|
||||
double adjustment;
|
||||
|
||||
void backup()
|
||||
{
|
||||
ohoriz = horiz;
|
||||
ohorizoff = horizoff;
|
||||
}
|
||||
|
||||
void restore()
|
||||
{
|
||||
horiz = ohoriz;
|
||||
horizoff = ohorizoff;
|
||||
}
|
||||
|
||||
void addadjustment(double value)
|
||||
{
|
||||
if (!cl_syncinput)
|
||||
{
|
||||
adjustment += value;
|
||||
}
|
||||
else
|
||||
{
|
||||
horiz += q16horiz(FloatToFixed(value));
|
||||
}
|
||||
}
|
||||
|
||||
void resetadjustment()
|
||||
{
|
||||
adjustment = 0;
|
||||
}
|
||||
|
||||
void settarget(double value, bool backup = false)
|
||||
{
|
||||
if (!cl_syncinput)
|
||||
{
|
||||
target = FloatToFixed(value);
|
||||
if (target == 0) target += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
horiz = q16horiz(FloatToFixed(value));
|
||||
if (backup) ohoriz = horiz;
|
||||
}
|
||||
}
|
||||
|
||||
void processhelpers(double const scaleAdjust)
|
||||
{
|
||||
if (target)
|
||||
{
|
||||
horiz += q16horiz(xs_CRoundToInt(scaleAdjust * (target - horiz.asq16())));
|
||||
|
||||
if (abs(horiz.asq16() - target) < FRACUNIT)
|
||||
{
|
||||
horiz = q16horiz(target);
|
||||
target = 0;
|
||||
}
|
||||
}
|
||||
else if (adjustment)
|
||||
{
|
||||
horiz += q16horiz(FloatToFixed(scaleAdjust * adjustment));
|
||||
}
|
||||
}
|
||||
|
||||
fixedhoriz sum()
|
||||
{
|
||||
return horiz + horizoff;
|
||||
}
|
||||
|
||||
fixedhoriz interpolatedsum(double const smoothratio)
|
||||
{
|
||||
double const ratio = smoothratio / FRACUNIT;
|
||||
fixed_t const prev = (ohoriz + ohorizoff).asq16();
|
||||
fixed_t const curr = (horiz + horizoff).asq16();
|
||||
return q16horiz(prev + xs_CRoundToInt(ratio * (curr - prev)));
|
||||
}
|
||||
};
|
||||
|
||||
struct PlayerAngle
|
||||
{
|
||||
binangle ang, oang;
|
||||
lookangle look_ang, olook_ang, rotscrnang, orotscrnang, spin;
|
||||
double adjustment, target;
|
||||
|
||||
void backup()
|
||||
{
|
||||
oang = ang;
|
||||
olook_ang = look_ang;
|
||||
orotscrnang = rotscrnang;
|
||||
}
|
||||
|
||||
void restore()
|
||||
{
|
||||
ang = oang;
|
||||
look_ang = olook_ang;
|
||||
rotscrnang = orotscrnang;
|
||||
}
|
||||
|
||||
void addadjustment(double value)
|
||||
{
|
||||
if (!cl_syncinput)
|
||||
{
|
||||
adjustment += value;
|
||||
}
|
||||
else
|
||||
{
|
||||
ang += bamang(xs_CRoundToUInt(value * BAMUNIT));
|
||||
}
|
||||
}
|
||||
|
||||
void resetadjustment()
|
||||
{
|
||||
adjustment = 0;
|
||||
}
|
||||
|
||||
void settarget(double value, bool backup = false)
|
||||
{
|
||||
if (!cl_syncinput)
|
||||
{
|
||||
if (value == 0) value += (1. / BAMUNIT);
|
||||
target = xs_CRoundToUInt(value * BAMUNIT);
|
||||
}
|
||||
else
|
||||
{
|
||||
ang = bamang(xs_CRoundToUInt(value * BAMUNIT));
|
||||
if (backup) oang = ang;
|
||||
}
|
||||
}
|
||||
|
||||
void processhelpers(double const scaleAdjust)
|
||||
{
|
||||
if (target)
|
||||
{
|
||||
ang = bamang(ang.asbam() + xs_CRoundToInt(scaleAdjust * (target - ang.asbam())));
|
||||
|
||||
if (ang.asbam() - target < BAMUNIT)
|
||||
{
|
||||
ang = bamang(target);
|
||||
target = 0;
|
||||
}
|
||||
}
|
||||
else if (adjustment)
|
||||
{
|
||||
ang += bamang(xs_CRoundToUInt(scaleAdjust * adjustment * BAMUNIT));
|
||||
}
|
||||
}
|
||||
|
||||
binangle sum()
|
||||
{
|
||||
return bamang(ang.asbam() + look_ang.asbam());
|
||||
}
|
||||
|
||||
binangle interpolatedsum(double const smoothratio)
|
||||
{
|
||||
double const ratio = smoothratio / FRACUNIT;
|
||||
int32_t const dang = UINT32_MAX / 2;
|
||||
int64_t const prev = oang.asbam() + olook_ang.asbam();
|
||||
int64_t const curr = ang.asbam() + look_ang.asbam();
|
||||
return bamang(prev + xs_CRoundToUInt(ratio * (((curr + dang - prev) & 0xFFFFFFFF) - dang)));
|
||||
}
|
||||
|
||||
lookangle interpolatedrotscrn(double const smoothratio)
|
||||
{
|
||||
double const ratio = smoothratio / FRACUNIT;
|
||||
return bamlook(orotscrnang.asbam() + xs_CRoundToInt(ratio * (rotscrnang.asbam() - orotscrnang.asbam())));
|
||||
}
|
||||
};
|
||||
|
||||
void processMovement(InputPacket* currInput, InputPacket* inputBuffer, ControlInfo* const hidInput, double const scaleAdjust, int const drink_amt = 0, bool const allowstrafe = true, double const turnscale = 1);
|
||||
void sethorizon(fixedhoriz* horiz, float const horz, ESyncBits* actions, double const scaleAdjust);
|
||||
void applylook(PlayerAngle* angle, float const avel, ESyncBits* actions, double const scaleAdjust, bool const crouching);
|
||||
|
||||
struct UserConfig
|
||||
{
|
||||
FString gamegrp;
|
||||
|
|
327
source/core/gameinput.cpp
Normal file
327
source/core/gameinput.cpp
Normal file
|
@ -0,0 +1,327 @@
|
|||
//-------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (C) 2019 Christoph Oelckers
|
||||
Copyright (C) 2020 Mitchell Richters
|
||||
|
||||
This is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
*/
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
#include "gamecontrol.h"
|
||||
#include "gameinput.h"
|
||||
#include "gamestruct.h"
|
||||
|
||||
CVARD(Bool, invertmousex, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "invert horizontal mouse movement")
|
||||
CVARD(Bool, invertmouse, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "invert vertical mouse movement")
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// code fron gameexec/conrun
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
int getincangle(int a, int na)
|
||||
{
|
||||
a &= 2047;
|
||||
na &= 2047;
|
||||
|
||||
if(abs(a-na) < 1024)
|
||||
return (na-a);
|
||||
else
|
||||
{
|
||||
if(na > 1024) na -= 2048;
|
||||
if(a > 1024) a -= 2048;
|
||||
|
||||
na -= 2048;
|
||||
a -= 2048;
|
||||
return (na-a);
|
||||
}
|
||||
}
|
||||
|
||||
fixed_t getincangleq16(fixed_t a, fixed_t na)
|
||||
{
|
||||
a &= 0x7FFFFFF;
|
||||
na &= 0x7FFFFFF;
|
||||
|
||||
if(abs(a-na) < IntToFixed(1024))
|
||||
return (na-a);
|
||||
else
|
||||
{
|
||||
if(na > IntToFixed(1024)) na -= IntToFixed(2048);
|
||||
if(a > IntToFixed(1024)) a -= IntToFixed(2048);
|
||||
|
||||
na -= IntToFixed(2048);
|
||||
a -= IntToFixed(2048);
|
||||
return (na-a);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Player's movement function, called from game's ticker or from gi->GetInput() as required.
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void processMovement(InputPacket* currInput, InputPacket* inputBuffer, ControlInfo* const hidInput, double const scaleAdjust, int const drink_amt, bool const allowstrafe, double const turnscale)
|
||||
{
|
||||
// set up variables
|
||||
int const running = !!(inputBuffer->actions & SB_RUN);
|
||||
int const keymove = gi->playerKeyMove() << running;
|
||||
int const cntrlvelscale = g_gameType & GAMEFLAG_PSEXHUMED ? 8 : 1;
|
||||
float const mousevelscale = keymove / 160.f;
|
||||
double const angtodegscale = 45. / 256.;
|
||||
double const hidspeed = ((running ? 43375. / 27. : 867.5) / GameTicRate) * angtodegscale;
|
||||
|
||||
// process mouse and initial controller input.
|
||||
if (buttonMap.ButtonDown(gamefunc_Strafe) && allowstrafe)
|
||||
currInput->svel -= xs_CRoundToInt((hidInput->mousemovex * mousevelscale) + (scaleAdjust * (hidInput->dyaw / 60) * keymove * cntrlvelscale));
|
||||
else
|
||||
currInput->avel += hidInput->mouseturnx + (scaleAdjust * hidInput->dyaw * hidspeed * turnscale);
|
||||
|
||||
if (!(inputBuffer->actions & SB_AIMMODE))
|
||||
currInput->horz -= hidInput->mouseturny;
|
||||
else
|
||||
currInput->fvel -= xs_CRoundToInt(hidInput->mousemovey * mousevelscale);
|
||||
|
||||
if (invertmouse)
|
||||
currInput->horz = -currInput->horz;
|
||||
|
||||
if (invertmousex)
|
||||
currInput->avel = -currInput->avel;
|
||||
|
||||
// process remaining controller input.
|
||||
currInput->horz -= scaleAdjust * hidInput->dpitch * hidspeed;
|
||||
currInput->svel -= xs_CRoundToInt(scaleAdjust * hidInput->dx * keymove * cntrlvelscale);
|
||||
currInput->fvel -= xs_CRoundToInt(scaleAdjust * hidInput->dz * keymove * cntrlvelscale);
|
||||
|
||||
// process keyboard turning keys.
|
||||
if (buttonMap.ButtonDown(gamefunc_Strafe) && allowstrafe)
|
||||
{
|
||||
if (abs(inputBuffer->svel) < keymove)
|
||||
{
|
||||
if (buttonMap.ButtonDown(gamefunc_Turn_Left))
|
||||
currInput->svel += keymove;
|
||||
|
||||
if (buttonMap.ButtonDown(gamefunc_Turn_Right))
|
||||
currInput->svel -= keymove;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
static double turnheldtime;
|
||||
int const turnheldamt = 120 / GameTicRate;
|
||||
double const turboturntime = 590. / GameTicRate;
|
||||
double turnamount = hidspeed * turnscale;
|
||||
double preambleturn = turnamount * (92. / 347.);
|
||||
|
||||
// allow Exhumed to use its legacy values given the drastic difference from the other games.
|
||||
if ((g_gameType & GAMEFLAG_PSEXHUMED) && cl_exhumedoldturn)
|
||||
{
|
||||
preambleturn = turnamount = (running ? 12 : 8) * angtodegscale;
|
||||
}
|
||||
|
||||
if (buttonMap.ButtonDown(gamefunc_Turn_Left) || (buttonMap.ButtonDown(gamefunc_Strafe_Left) && !allowstrafe))
|
||||
{
|
||||
turnheldtime += scaleAdjust * turnheldamt;
|
||||
currInput->avel -= scaleAdjust * (turnheldtime >= turboturntime ? turnamount : preambleturn);
|
||||
}
|
||||
else if (buttonMap.ButtonDown(gamefunc_Turn_Right) || (buttonMap.ButtonDown(gamefunc_Strafe_Right) && !allowstrafe))
|
||||
{
|
||||
turnheldtime += scaleAdjust * turnheldamt;
|
||||
currInput->avel += scaleAdjust * (turnheldtime >= turboturntime ? turnamount : preambleturn);
|
||||
}
|
||||
else
|
||||
{
|
||||
turnheldtime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// process keyboard forward/side velocity keys.
|
||||
if (abs(inputBuffer->svel) < keymove)
|
||||
{
|
||||
if (buttonMap.ButtonDown(gamefunc_Strafe_Left) && allowstrafe)
|
||||
currInput->svel += keymove;
|
||||
|
||||
if (buttonMap.ButtonDown(gamefunc_Strafe_Right) && allowstrafe)
|
||||
currInput->svel -= keymove;
|
||||
}
|
||||
if (abs(inputBuffer->fvel) < keymove)
|
||||
{
|
||||
if (isRR() && drink_amt >= 66 && drink_amt <= 87)
|
||||
{
|
||||
if (buttonMap.ButtonDown(gamefunc_Move_Forward))
|
||||
{
|
||||
currInput->fvel += keymove;
|
||||
if (drink_amt & 1)
|
||||
currInput->svel += keymove;
|
||||
else
|
||||
currInput->svel -= keymove;
|
||||
}
|
||||
|
||||
if (buttonMap.ButtonDown(gamefunc_Move_Backward))
|
||||
{
|
||||
currInput->fvel -= keymove;
|
||||
if (drink_amt & 1)
|
||||
currInput->svel -= keymove;
|
||||
else
|
||||
currInput->svel += keymove;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (buttonMap.ButtonDown(gamefunc_Move_Forward))
|
||||
currInput->fvel += keymove;
|
||||
|
||||
if (buttonMap.ButtonDown(gamefunc_Move_Backward))
|
||||
currInput->fvel -= keymove;
|
||||
}
|
||||
}
|
||||
|
||||
// add collected input to game's local input accumulation packet.
|
||||
inputBuffer->fvel = clamp(inputBuffer->fvel + currInput->fvel, -keymove, keymove);
|
||||
inputBuffer->svel = clamp(inputBuffer->svel + currInput->svel, -keymove, keymove);
|
||||
inputBuffer->avel += currInput->avel;
|
||||
inputBuffer->horz += currInput->horz;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Player's horizon function, called from game's ticker or from gi->GetInput() as required.
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void sethorizon(fixedhoriz* horiz, float const horz, ESyncBits* actions, double const scaleAdjust)
|
||||
{
|
||||
// Store current horizon as true pitch.
|
||||
double pitch = horiz->aspitch();
|
||||
|
||||
if (horz)
|
||||
{
|
||||
*actions &= ~SB_CENTERVIEW;
|
||||
pitch += horz;
|
||||
}
|
||||
|
||||
// this is the locked type
|
||||
if (*actions & (SB_AIM_UP|SB_AIM_DOWN))
|
||||
{
|
||||
*actions &= ~SB_CENTERVIEW;
|
||||
double const amount = HorizToPitch(250. / GameTicRate);
|
||||
|
||||
if (*actions & SB_AIM_DOWN)
|
||||
pitch -= scaleAdjust * amount;
|
||||
|
||||
if (*actions & SB_AIM_UP)
|
||||
pitch += scaleAdjust * amount;
|
||||
}
|
||||
|
||||
// this is the unlocked type
|
||||
if (*actions & (SB_LOOK_UP|SB_LOOK_DOWN))
|
||||
{
|
||||
*actions |= SB_CENTERVIEW;
|
||||
double const amount = HorizToPitch(500. / GameTicRate);
|
||||
|
||||
if (*actions & SB_LOOK_DOWN)
|
||||
pitch -= scaleAdjust * amount;
|
||||
|
||||
if (*actions & SB_LOOK_UP)
|
||||
pitch += scaleAdjust * amount;
|
||||
}
|
||||
|
||||
// clamp pitch after processing
|
||||
pitch = clamp(pitch, -90, 90);
|
||||
|
||||
// return to center if conditions met.
|
||||
if ((*actions & SB_CENTERVIEW) && !(*actions & (SB_LOOK_UP|SB_LOOK_DOWN)))
|
||||
{
|
||||
if (abs(pitch) > 0.1375)
|
||||
{
|
||||
// move pitch back to 0
|
||||
pitch += -scaleAdjust * pitch * (9. / GameTicRate);
|
||||
}
|
||||
else
|
||||
{
|
||||
// not looking anymore because pitch is back at 0
|
||||
pitch = 0;
|
||||
*actions &= ~SB_CENTERVIEW;
|
||||
}
|
||||
}
|
||||
|
||||
// clamp before returning
|
||||
*horiz = q16horiz(clamp(PitchToHoriz(pitch), gi->playerHorizMin(), gi->playerHorizMax()));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Player's angle function, called from game's ticker or from gi->GetInput() as required.
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void applylook(PlayerAngle* angle, float const avel, ESyncBits* actions, double const scaleAdjust, bool const crouching)
|
||||
{
|
||||
// return q16rotscrnang to 0 and set to 0 if less than a quarter of a unit
|
||||
angle->rotscrnang -= bamlook(xs_CRoundToInt(scaleAdjust * angle->rotscrnang.asbam() * (15. / GameTicRate)));
|
||||
if (abs(angle->rotscrnang.asbam()) < (BAMUNIT >> 2)) angle->rotscrnang = bamlook(0);
|
||||
|
||||
// return q16look_ang to 0 and set to 0 if less than a quarter of a unit
|
||||
angle->look_ang -= bamlook(xs_CRoundToInt(scaleAdjust * angle->look_ang.asbam() * (7.5 / GameTicRate)));
|
||||
if (abs(angle->look_ang.asbam()) < (BAMUNIT >> 2)) angle->look_ang = bamlook(0);
|
||||
|
||||
if (*actions & SB_LOOK_LEFT)
|
||||
{
|
||||
// start looking left
|
||||
angle->look_ang -= bamlook(xs_CRoundToInt(scaleAdjust * (4560. / GameTicRate) * BAMUNIT));
|
||||
angle->rotscrnang += bamlook(xs_CRoundToInt(scaleAdjust * (720. / GameTicRate) * BAMUNIT));
|
||||
}
|
||||
|
||||
if (*actions & SB_LOOK_RIGHT)
|
||||
{
|
||||
// start looking right
|
||||
angle->look_ang += bamlook(xs_CRoundToInt(scaleAdjust * (4560. / GameTicRate) * BAMUNIT));
|
||||
angle->rotscrnang -= bamlook(xs_CRoundToInt(scaleAdjust * (720. / GameTicRate) * BAMUNIT));
|
||||
}
|
||||
|
||||
if (*actions & SB_TURNAROUND)
|
||||
{
|
||||
if (angle->spin.asbam() == 0)
|
||||
{
|
||||
// currently not spinning, so start a spin
|
||||
angle->spin = buildlook(-1024);
|
||||
}
|
||||
*actions &= ~SB_TURNAROUND;
|
||||
}
|
||||
|
||||
if (angle->spin.asbam() < 0)
|
||||
{
|
||||
// return spin to 0
|
||||
lookangle add = bamlook(xs_CRoundToUInt(scaleAdjust * ((!crouching ? 3840. : 1920.) / GameTicRate) * BAMUNIT));
|
||||
angle->spin += add;
|
||||
if (angle->spin.asbam() > 0)
|
||||
{
|
||||
// Don't overshoot our target. With variable factor this is possible.
|
||||
add -= angle->spin;
|
||||
angle->spin = bamlook(0);
|
||||
}
|
||||
angle->ang += bamang(add.asbam());
|
||||
}
|
||||
|
||||
if (avel)
|
||||
{
|
||||
// add player's input
|
||||
angle->ang += degang(avel);
|
||||
}
|
||||
}
|
||||
|
185
source/core/gameinput.h
Normal file
185
source/core/gameinput.h
Normal file
|
@ -0,0 +1,185 @@
|
|||
#pragma once
|
||||
|
||||
#include "m_fixed.h"
|
||||
#include "binaryangle.h"
|
||||
#include "gamecvars.h"
|
||||
#include "packet.h"
|
||||
|
||||
int getincangle(int c, int n);
|
||||
fixed_t getincangleq16(fixed_t c, fixed_t n);
|
||||
|
||||
struct PlayerHorizon
|
||||
{
|
||||
fixedhoriz horiz, ohoriz, horizoff, ohorizoff;
|
||||
fixed_t target;
|
||||
double adjustment;
|
||||
|
||||
void backup()
|
||||
{
|
||||
ohoriz = horiz;
|
||||
ohorizoff = horizoff;
|
||||
}
|
||||
|
||||
void restore()
|
||||
{
|
||||
horiz = ohoriz;
|
||||
horizoff = ohorizoff;
|
||||
}
|
||||
|
||||
void addadjustment(double value)
|
||||
{
|
||||
if (!cl_syncinput)
|
||||
{
|
||||
adjustment += value;
|
||||
}
|
||||
else
|
||||
{
|
||||
horiz += q16horiz(FloatToFixed(value));
|
||||
}
|
||||
}
|
||||
|
||||
void resetadjustment()
|
||||
{
|
||||
adjustment = 0;
|
||||
}
|
||||
|
||||
void settarget(double value, bool backup = false)
|
||||
{
|
||||
if (!cl_syncinput)
|
||||
{
|
||||
target = FloatToFixed(value);
|
||||
if (target == 0) target += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
horiz = q16horiz(FloatToFixed(value));
|
||||
if (backup) ohoriz = horiz;
|
||||
}
|
||||
}
|
||||
|
||||
void processhelpers(double const scaleAdjust)
|
||||
{
|
||||
if (target)
|
||||
{
|
||||
horiz += q16horiz(xs_CRoundToInt(scaleAdjust * (target - horiz.asq16())));
|
||||
|
||||
if (abs(horiz.asq16() - target) < FRACUNIT)
|
||||
{
|
||||
horiz = q16horiz(target);
|
||||
target = 0;
|
||||
}
|
||||
}
|
||||
else if (adjustment)
|
||||
{
|
||||
horiz += q16horiz(FloatToFixed(scaleAdjust * adjustment));
|
||||
}
|
||||
}
|
||||
|
||||
fixedhoriz sum()
|
||||
{
|
||||
return horiz + horizoff;
|
||||
}
|
||||
|
||||
fixedhoriz interpolatedsum(double const smoothratio)
|
||||
{
|
||||
double const ratio = smoothratio / FRACUNIT;
|
||||
fixed_t const prev = (ohoriz + ohorizoff).asq16();
|
||||
fixed_t const curr = (horiz + horizoff).asq16();
|
||||
return q16horiz(prev + xs_CRoundToInt(ratio * (curr - prev)));
|
||||
}
|
||||
};
|
||||
|
||||
struct PlayerAngle
|
||||
{
|
||||
binangle ang, oang;
|
||||
lookangle look_ang, olook_ang, rotscrnang, orotscrnang, spin;
|
||||
double adjustment, target;
|
||||
|
||||
void backup()
|
||||
{
|
||||
oang = ang;
|
||||
olook_ang = look_ang;
|
||||
orotscrnang = rotscrnang;
|
||||
}
|
||||
|
||||
void restore()
|
||||
{
|
||||
ang = oang;
|
||||
look_ang = olook_ang;
|
||||
rotscrnang = orotscrnang;
|
||||
}
|
||||
|
||||
void addadjustment(double value)
|
||||
{
|
||||
if (!cl_syncinput)
|
||||
{
|
||||
adjustment += value;
|
||||
}
|
||||
else
|
||||
{
|
||||
ang += bamang(xs_CRoundToUInt(value * BAMUNIT));
|
||||
}
|
||||
}
|
||||
|
||||
void resetadjustment()
|
||||
{
|
||||
adjustment = 0;
|
||||
}
|
||||
|
||||
void settarget(double value, bool backup = false)
|
||||
{
|
||||
if (!cl_syncinput)
|
||||
{
|
||||
if (value == 0) value += (1. / BAMUNIT);
|
||||
target = xs_CRoundToUInt(value * BAMUNIT);
|
||||
}
|
||||
else
|
||||
{
|
||||
ang = bamang(xs_CRoundToUInt(value * BAMUNIT));
|
||||
if (backup) oang = ang;
|
||||
}
|
||||
}
|
||||
|
||||
void processhelpers(double const scaleAdjust)
|
||||
{
|
||||
if (target)
|
||||
{
|
||||
ang = bamang(ang.asbam() + xs_CRoundToInt(scaleAdjust * (target - ang.asbam())));
|
||||
|
||||
if (ang.asbam() - target < BAMUNIT)
|
||||
{
|
||||
ang = bamang(target);
|
||||
target = 0;
|
||||
}
|
||||
}
|
||||
else if (adjustment)
|
||||
{
|
||||
ang += bamang(xs_CRoundToUInt(scaleAdjust * adjustment * BAMUNIT));
|
||||
}
|
||||
}
|
||||
|
||||
binangle sum()
|
||||
{
|
||||
return bamang(ang.asbam() + look_ang.asbam());
|
||||
}
|
||||
|
||||
binangle interpolatedsum(double const smoothratio)
|
||||
{
|
||||
double const ratio = smoothratio / FRACUNIT;
|
||||
int32_t const dang = UINT32_MAX / 2;
|
||||
int64_t const prev = oang.asbam() + olook_ang.asbam();
|
||||
int64_t const curr = ang.asbam() + look_ang.asbam();
|
||||
return bamang(prev + xs_CRoundToUInt(ratio * (((curr + dang - prev) & 0xFFFFFFFF) - dang)));
|
||||
}
|
||||
|
||||
lookangle interpolatedrotscrn(double const smoothratio)
|
||||
{
|
||||
double const ratio = smoothratio / FRACUNIT;
|
||||
return bamlook(orotscrnang.asbam() + xs_CRoundToInt(ratio * (rotscrnang.asbam() - orotscrnang.asbam())));
|
||||
}
|
||||
};
|
||||
|
||||
void processMovement(InputPacket* currInput, InputPacket* inputBuffer, ControlInfo* const hidInput, double const scaleAdjust, int const drink_amt = 0, bool const allowstrafe = true, double const turnscale = 1);
|
||||
void sethorizon(fixedhoriz* horiz, float const horz, ESyncBits* actions, double const scaleAdjust);
|
||||
void applylook(PlayerAngle* angle, float const avel, ESyncBits* actions, double const scaleAdjust, bool const crouching);
|
||||
|
|
@ -20,6 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
|
||||
#include "compat.h"
|
||||
#include "gamecontrol.h"
|
||||
#include "gameinput.h"
|
||||
|
||||
BEGIN_PS_NS
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "names.h"
|
||||
#include "packet.h"
|
||||
#include "d_net.h"
|
||||
#include "gameinput.h"
|
||||
|
||||
BEGIN_DUKE_NS
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
|
|||
#include "gamecontrol.h"
|
||||
#include "gamestruct.h"
|
||||
#include "packet.h"
|
||||
#include "gameinput.h"
|
||||
|
||||
EXTERN_CVAR(Bool, sw_ninjahack)
|
||||
EXTERN_CVAR(Bool, sw_darts)
|
||||
|
|
Loading…
Reference in a new issue