2020-10-11 14:33:43 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
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"
|
2020-10-11 14:55:12 +00:00
|
|
|
#include "serializer.h"
|
2021-03-22 22:40:25 +00:00
|
|
|
#include "build.h"
|
2020-10-11 14:33:43 +00:00
|
|
|
|
2022-06-11 08:36:20 +00:00
|
|
|
|
2020-10-11 14:33:43 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// code fron gameexec/conrun
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
int getincangle(int a, int na)
|
|
|
|
{
|
|
|
|
a &= 2047;
|
|
|
|
na &= 2047;
|
|
|
|
|
2020-11-22 10:45:16 +00:00
|
|
|
if(abs(a-na) >= 1024)
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
|
|
|
if(na > 1024) na -= 2048;
|
|
|
|
if(a > 1024) a -= 2048;
|
|
|
|
}
|
2020-11-22 10:45:16 +00:00
|
|
|
|
|
|
|
return na-a;
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
|
2021-04-11 05:43:11 +00:00
|
|
|
binangle getincanglebam(binangle a, binangle na)
|
2020-11-22 10:45:16 +00:00
|
|
|
{
|
2021-04-14 22:25:08 +00:00
|
|
|
int64_t cura = a.asbam();
|
|
|
|
int64_t newa = na.asbam();
|
2020-11-22 10:45:16 +00:00
|
|
|
|
2021-04-14 22:25:08 +00:00
|
|
|
if(abs(cura-newa) > INT32_MAX)
|
2020-11-22 10:45:16 +00:00
|
|
|
{
|
2021-04-14 22:25:08 +00:00
|
|
|
if(newa > INT32_MAX) newa -= UINT32_MAX;
|
|
|
|
if(cura > INT32_MAX) cura -= UINT32_MAX;
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
2020-11-22 10:45:16 +00:00
|
|
|
|
2021-05-11 23:50:41 +00:00
|
|
|
return bamang(uint32_t(newa-cura));
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
|
2022-07-22 04:56:38 +00:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Input scale helper functions.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
inline static double getTicrateScale(const double value)
|
|
|
|
{
|
|
|
|
return value * (1. / GameTicRate);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static double getPushScale(const double scaleAdjust)
|
|
|
|
{
|
|
|
|
return (2. / 9.) * (scaleAdjust < 1. ? (1. - scaleAdjust * 0.5) * 1.5 : 1.);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static fixedhoriz getscaledhoriz(const double value, const double scaleAdjust, const fixedhoriz& object, const double push)
|
|
|
|
{
|
|
|
|
return buildfhoriz(scaleAdjust * ((object.asbuildf() * getTicrateScale(value)) + push));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static binangle getscaledangle(const double value, const double scaleAdjust, const binangle& object, const double push)
|
|
|
|
{
|
|
|
|
return buildfang(scaleAdjust * ((object.signedbuildf() * getTicrateScale(value)) + push));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static void scaletozero(fixedhoriz& object, const double value, const double scaleAdjust, const double push = DBL_MAX)
|
|
|
|
{
|
|
|
|
if (auto sgn = Sgn(object.asq16()))
|
|
|
|
{
|
|
|
|
object -= getscaledhoriz(value, scaleAdjust, object, push == DBL_MAX ? sgn * getPushScale(scaleAdjust) : push);
|
|
|
|
if (sgn != Sgn(object.asq16())) object = q16horiz(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static void scaletozero(binangle& object, const double value, const double scaleAdjust, const double push = DBL_MAX)
|
|
|
|
{
|
|
|
|
if (auto sgn = Sgn(object.signedbam()))
|
|
|
|
{
|
|
|
|
object -= getscaledangle(value, scaleAdjust, object, push == DBL_MAX ? sgn * getPushScale(scaleAdjust) : push);
|
|
|
|
if (sgn != Sgn(object.signedbam())) object = bamang(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-01 22:53:03 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Functions for determining whether its turbo turn time (turn key held for a number of tics).
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2021-11-05 22:28:39 +00:00
|
|
|
/*
|
|
|
|
// Turbo turn time.
|
|
|
|
Blood: 24 * 30 = 720;
|
|
|
|
Duke: 120 / 8 * 30 = 450;
|
|
|
|
SW: 120 / 8 * 40 = 600;
|
|
|
|
Exhumed: N/A;
|
|
|
|
Average: 590.;
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
BUILDTICRATE = 120,
|
|
|
|
TURBOTURNBASE = 590,
|
|
|
|
};
|
|
|
|
|
2021-01-01 22:53:03 +00:00
|
|
|
static double turnheldtime;
|
|
|
|
|
|
|
|
void updateTurnHeldAmt(double const scaleAdjust)
|
|
|
|
{
|
2022-05-30 11:06:32 +00:00
|
|
|
turnheldtime += getTicrateScale(BUILDTICRATE) * scaleAdjust;
|
2021-01-01 22:53:03 +00:00
|
|
|
}
|
|
|
|
|
2021-10-08 17:06:41 +00:00
|
|
|
bool isTurboTurnTime()
|
2021-01-01 22:53:03 +00:00
|
|
|
{
|
2021-11-06 01:39:19 +00:00
|
|
|
return turnheldtime >= getTicrateScale(TURBOTURNBASE);
|
2021-01-01 22:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void resetTurnHeldAmt()
|
|
|
|
{
|
|
|
|
turnheldtime = 0;
|
|
|
|
}
|
|
|
|
|
2022-06-11 08:36:20 +00:00
|
|
|
|
2020-10-11 14:33:43 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Player's movement function, called from game's ticker or from gi->GetInput() as required.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2020-10-15 08:47:14 +00:00
|
|
|
/*
|
|
|
|
// Running speed.
|
|
|
|
Blood: 92 / 4 * 2 * 30 = 1380;
|
|
|
|
Duke: 15 * 2 * 2 * 30 = 1800;
|
|
|
|
SW: 28 * 1.40625 * 40 = 1575; // Precisely, ((((28 * 12) + ((28 * 12) / 4)) * 3) / 32) * 40
|
2021-11-05 22:28:39 +00:00
|
|
|
Exhumed: 12 * 4 * 30 = 1440;
|
|
|
|
Average: 1548.75;
|
2020-10-15 08:47:14 +00:00
|
|
|
|
|
|
|
// Normal speed.
|
|
|
|
Blood: 92 / 4 * 30 = 690;
|
|
|
|
Duke: 15 * 2 * 30 = 900;
|
|
|
|
SW: 18 * 1.40625 * 40 = 1012.5; // Precisely, (((((12 + 6) * 12) + (((12 + 6) * 12) / 4)) * 3) / 32) * 40
|
2021-11-05 22:28:39 +00:00
|
|
|
Exhumed: 8 * 4 * 30 = 960;
|
|
|
|
Average: 890.625;
|
2020-10-15 08:47:14 +00:00
|
|
|
|
|
|
|
// Preamble.
|
2021-11-05 22:28:39 +00:00
|
|
|
Blood: N/A;
|
|
|
|
Exhumed: N/A;
|
2020-10-15 08:47:14 +00:00
|
|
|
Duke: 5 * 2 * 30 = 300;
|
|
|
|
SW: 3 * 1.40625 * 40 = 168.75; // Precisely, ((((3 * 12) + ((3 * 12) / 4)) * 3) / 32) * 40
|
|
|
|
Average: 234.375;
|
|
|
|
*/
|
|
|
|
|
2022-06-11 08:36:20 +00:00
|
|
|
static constexpr double RUNNINGTURNBASE = 1548.75;
|
|
|
|
static constexpr double NORMALTURNBASE = 890.625;
|
|
|
|
static constexpr double PREAMBLEBASE = 234.375;
|
|
|
|
static constexpr double PREAMBLESCALE = PREAMBLEBASE / NORMALTURNBASE;
|
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, bool const allowstrafe, double const turnscale)
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
|
|
|
// set up variables
|
|
|
|
int const running = !!(inputBuffer->actions & SB_RUN);
|
|
|
|
int const keymove = gi->playerKeyMove() << running;
|
2022-06-11 07:12:56 +00:00
|
|
|
bool const strafing = buttonMap.ButtonDown(gamefunc_Strafe) && allowstrafe;
|
2021-11-05 22:28:39 +00:00
|
|
|
float const mousevelscale = keymove * (1.f / 160.f);
|
2021-11-07 07:27:26 +00:00
|
|
|
double const hidprescale = g_gameType & GAMEFLAG_PSEXHUMED ? 5. : 1.;
|
2021-11-06 01:39:19 +00:00
|
|
|
double const hidspeed = getTicrateScale(running ? RUNNINGTURNBASE : NORMALTURNBASE) * BAngToDegree;
|
2020-10-11 14:33:43 +00:00
|
|
|
|
|
|
|
// process mouse and initial controller input.
|
2022-06-11 07:12:56 +00:00
|
|
|
if (!strafing)
|
2021-05-11 23:50:41 +00:00
|
|
|
currInput->avel += float(hidInput->mouseturnx + (scaleAdjust * hidInput->dyaw * hidspeed * turnscale));
|
2022-06-11 07:12:56 +00:00
|
|
|
else
|
|
|
|
currInput->svel -= int16_t(((hidInput->mousemovex * mousevelscale) + (scaleAdjust * hidInput->dyaw * keymove)) * hidprescale);
|
2020-10-11 14:33:43 +00:00
|
|
|
|
|
|
|
if (!(inputBuffer->actions & SB_AIMMODE))
|
|
|
|
currInput->horz -= hidInput->mouseturny;
|
|
|
|
else
|
2022-06-11 08:36:20 +00:00
|
|
|
currInput->fvel -= int16_t(hidInput->mousemovey * mousevelscale * hidprescale);
|
2020-10-11 14:33:43 +00:00
|
|
|
|
|
|
|
// process remaining controller input.
|
2021-05-11 23:50:41 +00:00
|
|
|
currInput->horz -= float(scaleAdjust * hidInput->dpitch * hidspeed);
|
2022-06-11 08:36:20 +00:00
|
|
|
currInput->svel += int16_t(scaleAdjust * hidInput->dx * keymove * hidprescale);
|
|
|
|
currInput->fvel += int16_t(scaleAdjust * hidInput->dz * keymove * hidprescale);
|
2020-10-11 14:33:43 +00:00
|
|
|
|
|
|
|
// process keyboard turning keys.
|
2022-06-11 07:12:56 +00:00
|
|
|
if (!strafing)
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2021-11-05 22:28:39 +00:00
|
|
|
bool const turnleft = buttonMap.ButtonDown(gamefunc_Turn_Left) || (buttonMap.ButtonDown(gamefunc_Strafe_Left) && !allowstrafe);
|
|
|
|
bool const turnright = buttonMap.ButtonDown(gamefunc_Turn_Right) || (buttonMap.ButtonDown(gamefunc_Strafe_Right) && !allowstrafe);
|
2020-10-11 14:33:43 +00:00
|
|
|
|
2021-11-05 22:28:39 +00:00
|
|
|
if (turnleft || turnright)
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2021-01-01 22:53:03 +00:00
|
|
|
updateTurnHeldAmt(scaleAdjust);
|
2022-06-11 08:36:20 +00:00
|
|
|
float const turnamount = float(scaleAdjust * hidspeed * turnscale * (isTurboTurnTime() ? 1. : PREAMBLESCALE));
|
2021-11-05 22:28:39 +00:00
|
|
|
|
|
|
|
if (turnleft)
|
2021-11-12 07:59:52 +00:00
|
|
|
currInput->avel -= turnamount;
|
2021-11-05 22:28:39 +00:00
|
|
|
|
|
|
|
if (turnright)
|
2021-11-12 07:59:52 +00:00
|
|
|
currInput->avel += turnamount;
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-01 22:53:03 +00:00
|
|
|
resetTurnHeldAmt();
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-11 07:12:56 +00:00
|
|
|
else
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-06-11 07:12:56 +00:00
|
|
|
if (buttonMap.ButtonDown(gamefunc_Turn_Left))
|
2020-10-11 14:33:43 +00:00
|
|
|
currInput->svel += keymove;
|
|
|
|
|
2022-06-11 07:12:56 +00:00
|
|
|
if (buttonMap.ButtonDown(gamefunc_Turn_Right))
|
2020-10-11 14:33:43 +00:00
|
|
|
currInput->svel -= keymove;
|
|
|
|
}
|
2022-06-11 07:12:56 +00:00
|
|
|
|
|
|
|
// process keyboard side velocity keys.
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Strafe_Left) && allowstrafe)
|
|
|
|
currInput->svel += keymove;
|
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Strafe_Right) && allowstrafe)
|
|
|
|
currInput->svel -= keymove;
|
|
|
|
|
|
|
|
// process keyboard forward velocity keys.
|
|
|
|
if (!(isRR() && drink_amt >= 66 && drink_amt <= 87))
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-06-11 07:12:56 +00:00
|
|
|
if (buttonMap.ButtonDown(gamefunc_Move_Forward))
|
|
|
|
currInput->fvel += keymove;
|
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Move_Backward))
|
|
|
|
currInput->fvel -= keymove;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Move_Forward))
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-06-11 07:12:56 +00:00
|
|
|
currInput->fvel += keymove;
|
|
|
|
currInput->svel += drink_amt & 1 ? keymove : -keymove;
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
|
2022-06-11 07:12:56 +00:00
|
|
|
if (buttonMap.ButtonDown(gamefunc_Move_Backward))
|
|
|
|
{
|
|
|
|
currInput->fvel -= keymove;
|
|
|
|
currInput->svel -= drink_amt & 1 ? keymove : -keymove;
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2021-11-05 22:18:11 +00:00
|
|
|
/*
|
|
|
|
// Aim speed.
|
|
|
|
Duke: 6 * 30 = 180;
|
|
|
|
SW: (16 / 2) * 40 = 320;
|
|
|
|
Average: 250.;
|
|
|
|
|
|
|
|
// Look speed.
|
|
|
|
Duke: 12 * 30 = 360;
|
|
|
|
SW: 16 * 40 = 640;
|
|
|
|
Average: 500.;
|
|
|
|
|
|
|
|
// Return to centre speed.
|
|
|
|
Duke: (1 / 3) * 30 = 10;
|
|
|
|
SW: (1 / 4) * 40 = 10;
|
|
|
|
Average: 10.;
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
AIMSPEED = 250,
|
|
|
|
LOOKSPEED = 500,
|
|
|
|
CNTRSPEED = 10,
|
|
|
|
};
|
|
|
|
|
2021-04-21 10:41:04 +00:00
|
|
|
void PlayerHorizon::applyinput(float const horz, ESyncBits* actions, double const scaleAdjust)
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-06-11 08:36:20 +00:00
|
|
|
// Process only if movement isn't locked.
|
2021-07-18 09:25:41 +00:00
|
|
|
if (!movementlocked())
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2021-11-06 04:34:10 +00:00
|
|
|
// Test if we have input to process.
|
|
|
|
if (horz || *actions & (SB_AIM_UP | SB_AIM_DOWN | SB_LOOK_UP | SB_LOOK_DOWN))
|
2021-04-02 11:41:47 +00:00
|
|
|
{
|
2021-11-06 04:34:10 +00:00
|
|
|
// Store current horizon as true pitch.
|
|
|
|
double pitch = horiz.aspitch();
|
2020-10-11 14:33:43 +00:00
|
|
|
|
2021-11-06 04:34:10 +00:00
|
|
|
// Process mouse input.
|
|
|
|
if (horz)
|
2021-11-06 04:07:28 +00:00
|
|
|
{
|
2021-11-06 04:34:10 +00:00
|
|
|
*actions &= ~SB_CENTERVIEW;
|
|
|
|
pitch += horz;
|
2021-11-06 04:07:28 +00:00
|
|
|
}
|
2021-04-02 11:41:47 +00:00
|
|
|
|
2021-11-06 04:34:10 +00:00
|
|
|
// Process keyboard input.
|
|
|
|
auto doKbdInput = [&](ESyncBits_ const up, ESyncBits_ const down, double const rate, bool const lock)
|
|
|
|
{
|
|
|
|
if (*actions & (up | down))
|
|
|
|
{
|
|
|
|
if (lock) *actions &= ~SB_CENTERVIEW; else *actions |= SB_CENTERVIEW;
|
|
|
|
double const amount = scaleAdjust * HorizToPitch(getTicrateScale(rate));
|
|
|
|
|
|
|
|
if (*actions & down)
|
|
|
|
pitch -= amount;
|
|
|
|
|
|
|
|
if (*actions & up)
|
|
|
|
pitch += amount;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
doKbdInput(SB_AIM_UP, SB_AIM_DOWN, AIMSPEED, true);
|
|
|
|
doKbdInput(SB_LOOK_UP, SB_LOOK_DOWN, LOOKSPEED, false);
|
|
|
|
|
|
|
|
// clamp before converting back to horizon
|
|
|
|
horiz = q16horiz(clamp(PitchToHoriz(pitch), gi->playerHorizMin(), gi->playerHorizMax()));
|
|
|
|
}
|
2021-04-02 11:41:47 +00:00
|
|
|
|
|
|
|
// return to center if conditions met.
|
2021-11-07 07:25:37 +00:00
|
|
|
if ((*actions & SB_CENTERVIEW) && !(*actions & (SB_LOOK_UP|SB_LOOK_DOWN)))
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2021-11-07 00:37:12 +00:00
|
|
|
scaletozero(horiz, CNTRSPEED, scaleAdjust);
|
|
|
|
if (!horiz.asq16()) *actions &= ~SB_CENTERVIEW;
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-02 12:23:24 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
*actions &= ~SB_CENTERVIEW;
|
|
|
|
}
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
|
2022-06-11 08:36:20 +00:00
|
|
|
|
2020-10-11 14:33:43 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Player's angle function, called from game's ticker or from gi->GetInput() as required.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2021-11-05 23:26:29 +00:00
|
|
|
/*
|
|
|
|
// Rotate return speed.
|
|
|
|
Duke: (1 / 2) * 30 = 15;
|
|
|
|
|
|
|
|
// Look return speed.
|
|
|
|
Duke: (1 / 4) * 30 = 7.5;
|
|
|
|
|
|
|
|
// Rotating speed.
|
|
|
|
Duke: 24 * 30 = 720;
|
|
|
|
|
|
|
|
// Looking speed.
|
|
|
|
Duke: 152 * 30 = 4560;
|
|
|
|
|
|
|
|
// Spin standing speed.
|
|
|
|
Duke: 128 * 30 = 3840;
|
|
|
|
Blood: 128 * 30 = 3840;
|
|
|
|
|
|
|
|
// Looking speed.
|
|
|
|
Blood: 64 * 30 = 1920;
|
|
|
|
*/
|
|
|
|
|
2022-06-11 08:36:20 +00:00
|
|
|
static constexpr double ROTRETURNSPEED = (1. / 2.) * 30.;
|
|
|
|
static constexpr double LOOKRETURNSPEED = (1. / 4.) * 30.;
|
|
|
|
|
2021-11-05 23:26:29 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ROTATESPEED = 720,
|
|
|
|
LOOKINGSPEED = 4560,
|
|
|
|
SPINSTAND = 3840,
|
|
|
|
SPINCROUCH = 1920,
|
|
|
|
};
|
|
|
|
|
2021-04-21 10:41:04 +00:00
|
|
|
void PlayerAngle::applyinput(float const avel, ESyncBits* actions, double const scaleAdjust)
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2021-11-07 00:37:12 +00:00
|
|
|
// Process angle return to zeros.
|
2022-06-11 08:36:20 +00:00
|
|
|
scaletozero(rotscrnang, ROTRETURNSPEED, scaleAdjust);
|
|
|
|
scaletozero(look_ang, LOOKRETURNSPEED, scaleAdjust);
|
2020-10-11 14:33:43 +00:00
|
|
|
|
2021-11-06 06:57:00 +00:00
|
|
|
// Process keyboard input.
|
|
|
|
auto doLookKeys = [&](ESyncBits_ const key, double const direction)
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2021-11-06 06:57:00 +00:00
|
|
|
if (*actions & key)
|
|
|
|
{
|
2022-07-22 04:56:38 +00:00
|
|
|
look_ang += buildfang(getTicrateScale(LOOKINGSPEED) * scaleAdjust * direction);
|
|
|
|
rotscrnang -= buildfang(getTicrateScale(ROTATESPEED) * scaleAdjust * direction);
|
2021-11-06 06:57:00 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
doLookKeys(SB_LOOK_LEFT, -1);
|
|
|
|
doLookKeys(SB_LOOK_RIGHT, 1);
|
2020-10-11 14:33:43 +00:00
|
|
|
|
2021-07-18 09:25:41 +00:00
|
|
|
if (!movementlocked())
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2021-04-02 11:41:47 +00:00
|
|
|
if (*actions & SB_TURNAROUND)
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2021-04-19 10:50:01 +00:00
|
|
|
if (spin == 0)
|
2021-04-02 11:41:47 +00:00
|
|
|
{
|
|
|
|
// currently not spinning, so start a spin
|
2021-04-19 10:50:01 +00:00
|
|
|
spin = -1024.;
|
2021-04-02 11:41:47 +00:00
|
|
|
}
|
|
|
|
*actions &= ~SB_TURNAROUND;
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
|
2021-04-21 10:41:04 +00:00
|
|
|
if (avel)
|
|
|
|
{
|
|
|
|
// add player's input
|
|
|
|
ang += degang(avel);
|
|
|
|
}
|
|
|
|
|
2021-04-19 10:50:01 +00:00
|
|
|
if (spin < 0)
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2021-04-02 11:41:47 +00:00
|
|
|
// return spin to 0
|
2022-05-30 11:06:32 +00:00
|
|
|
double add = getTicrateScale(!(*actions & SB_CROUCH) ? SPINSTAND : SPINCROUCH) * scaleAdjust;
|
2021-04-19 10:50:01 +00:00
|
|
|
spin += add;
|
|
|
|
if (spin > 0)
|
2021-04-02 11:41:47 +00:00
|
|
|
{
|
|
|
|
// Don't overshoot our target. With variable factor this is possible.
|
2021-04-19 10:50:01 +00:00
|
|
|
add -= spin;
|
|
|
|
spin = 0;
|
2021-04-02 11:41:47 +00:00
|
|
|
}
|
2021-04-19 10:50:01 +00:00
|
|
|
ang += buildfang(add);
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-02 11:41:47 +00:00
|
|
|
else
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2021-04-19 10:50:01 +00:00
|
|
|
spin = 0;
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-11 08:36:20 +00:00
|
|
|
|
2021-01-01 13:30:01 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Player's slope tilt when playing without a mouse and on a slope.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2021-11-06 02:31:21 +00:00
|
|
|
/*
|
|
|
|
// Horizoff centre speed.
|
|
|
|
Duke: (1 / 8) * 30 = 3.75;
|
|
|
|
SW: (1 / 8) * 40 = 5;
|
|
|
|
Average: 4.375;
|
|
|
|
*/
|
|
|
|
|
2022-06-11 08:36:20 +00:00
|
|
|
static constexpr double HORIZOFFSPEED = (1. / 8.) * 35.;
|
|
|
|
|
2021-11-05 22:24:47 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
// Values used by Duke/SW, where this function originated from.
|
|
|
|
DEFSINSHIFT = 5,
|
|
|
|
DEFVIEWPITCH = 160,
|
|
|
|
|
|
|
|
// Values used by Blood since it calculates differently to Duke/SW.
|
|
|
|
BLOODSINSHIFT = 8,
|
|
|
|
SINSHIFTDELTA = BLOODSINSHIFT - DEFSINSHIFT,
|
|
|
|
BLOODVIEWPITCH = (0x4000 >> SINSHIFTDELTA) - (DEFVIEWPITCH << (SINSHIFTDELTA - 1)), // 1408.
|
|
|
|
};
|
|
|
|
|
2021-11-24 01:03:53 +00:00
|
|
|
void PlayerHorizon::calcviewpitch(vec2_t const pos, binangle const ang, bool const aimmode, bool const canslopetilt, sectortype* const cursectnum, double const scaleAdjust, bool const climbing)
|
2021-01-01 13:30:01 +00:00
|
|
|
{
|
2021-11-24 01:03:53 +00:00
|
|
|
if (cl_slopetilting && cursectnum != nullptr)
|
2021-01-01 13:30:01 +00:00
|
|
|
{
|
2021-01-01 13:34:44 +00:00
|
|
|
if (aimmode && canslopetilt) // If the floor is sloped
|
2021-01-01 13:30:01 +00:00
|
|
|
{
|
2021-01-02 03:40:35 +00:00
|
|
|
// Get a point, 512 (64 for Blood) units ahead of player's position
|
2021-11-05 22:24:47 +00:00
|
|
|
int const shift = -(isBlood() ? BLOODSINSHIFT : DEFSINSHIFT);
|
2021-12-22 09:26:51 +00:00
|
|
|
int const x = pos.X + ang.bcos(shift);
|
2021-12-22 09:28:51 +00:00
|
|
|
int const y = pos.Y + ang.bsin(shift);
|
2021-11-24 01:03:53 +00:00
|
|
|
auto tempsect = cursectnum;
|
2021-01-01 13:34:44 +00:00
|
|
|
updatesector(x, y, &tempsect);
|
|
|
|
|
2021-11-24 01:03:53 +00:00
|
|
|
if (tempsect != nullptr) // If the new point is inside a valid sector...
|
2021-01-01 13:30:01 +00:00
|
|
|
{
|
2021-01-01 13:34:44 +00:00
|
|
|
// Get the floorz as if the new (x,y) point was still in
|
|
|
|
// your sector
|
2021-12-22 09:28:51 +00:00
|
|
|
int const j = getflorzofslopeptr(cursectnum, pos.X, pos.Y);
|
2021-11-24 01:03:53 +00:00
|
|
|
int const k = getflorzofslopeptr(tempsect, x, y);
|
2021-01-01 13:34:44 +00:00
|
|
|
|
|
|
|
// If extended point is in same sector as you or the slopes
|
|
|
|
// of the sector of the extended point and your sector match
|
|
|
|
// closely (to avoid accidently looking straight out when
|
|
|
|
// you're at the edge of a sector line) then adjust horizon
|
|
|
|
// accordingly
|
2021-11-24 01:03:53 +00:00
|
|
|
if (cursectnum == tempsect || (!isBlood() && abs(getflorzofslopeptr(tempsect, x, y) - k) <= (4 << 8)))
|
2021-01-01 13:34:44 +00:00
|
|
|
{
|
2022-06-11 08:36:20 +00:00
|
|
|
horizoff += q16horiz(fixed_t(scaleAdjust * ((j - k) * (!isBlood() ? DEFVIEWPITCH : BLOODVIEWPITCH))));
|
2021-01-01 13:34:44 +00:00
|
|
|
}
|
2021-01-01 13:30:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-01 13:34:44 +00:00
|
|
|
if (climbing)
|
2021-01-01 13:30:01 +00:00
|
|
|
{
|
2021-01-01 13:34:44 +00:00
|
|
|
// tilt when climbing but you can't even really tell it.
|
2022-06-11 08:36:20 +00:00
|
|
|
if (horizoff.asq16() < IntToFixed(100)) horizoff += getscaledhoriz(HORIZOFFSPEED, scaleAdjust, buildhoriz(100) - horizoff, 1.);
|
2021-01-01 13:30:01 +00:00
|
|
|
}
|
2021-11-07 07:25:37 +00:00
|
|
|
else
|
2021-01-01 13:30:01 +00:00
|
|
|
{
|
2021-01-01 13:34:44 +00:00
|
|
|
// Make horizoff grow towards 0 since horizoff is not modified when you're not on a slope.
|
2022-06-11 08:36:20 +00:00
|
|
|
scaletozero(horizoff, HORIZOFFSPEED, scaleAdjust, Sgn(horizoff.asq16()));
|
2021-01-01 13:30:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-11 08:36:20 +00:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2020-10-11 14:55:12 +00:00
|
|
|
FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngle& w, PlayerAngle* def)
|
|
|
|
{
|
|
|
|
if (arc.BeginObject(keyname))
|
|
|
|
{
|
|
|
|
arc("ang", w.ang)
|
|
|
|
("lookang", w.look_ang)
|
|
|
|
("rotscrnang", w.rotscrnang)
|
|
|
|
("spin", w.spin)
|
2021-07-18 09:25:41 +00:00
|
|
|
("inputdisabled", w.inputdisabled)
|
2020-10-11 14:55:12 +00:00
|
|
|
.EndObject();
|
|
|
|
|
|
|
|
if (arc.isReading())
|
|
|
|
{
|
|
|
|
w.oang = w.ang;
|
|
|
|
w.olook_ang = w.look_ang;
|
|
|
|
w.orotscrnang = w.rotscrnang;
|
2021-07-18 09:25:41 +00:00
|
|
|
w.inputdisabled = w.inputdisabled;
|
2020-10-11 14:55:12 +00:00
|
|
|
w.resetadjustment();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return arc;
|
|
|
|
}
|
|
|
|
|
|
|
|
FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerHorizon& w, PlayerHorizon* def)
|
|
|
|
{
|
|
|
|
if (arc.BeginObject(keyname))
|
|
|
|
{
|
|
|
|
arc("horiz", w.horiz)
|
|
|
|
("horizoff", w.horizoff)
|
2021-07-18 09:25:41 +00:00
|
|
|
("inputdisabled", w.inputdisabled)
|
2020-10-11 14:55:12 +00:00
|
|
|
.EndObject();
|
|
|
|
|
|
|
|
if (arc.isReading())
|
|
|
|
{
|
|
|
|
w.ohoriz = w.horiz;
|
|
|
|
w.ohorizoff = w.horizoff;
|
2021-07-18 09:25:41 +00:00
|
|
|
w.inputdisabled = w.inputdisabled;
|
2020-10-11 14:55:12 +00:00
|
|
|
w.resetadjustment();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return arc;
|
|
|
|
}
|