2019-09-19 22:42:45 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Copyright (C) 2010-2019 EDuke32 developers and contributors
|
|
|
|
Copyright (C) 2019 Nuke.YKT
|
|
|
|
|
|
|
|
This file is part of NBlood.
|
|
|
|
|
|
|
|
NBlood is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License version 2
|
|
|
|
as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
2019-09-21 18:59:54 +00:00
|
|
|
|
|
|
|
#include "ns.h" // Must come before everything else!
|
|
|
|
|
2019-09-19 22:42:45 +00:00
|
|
|
#include "compat.h"
|
2020-02-16 20:31:29 +00:00
|
|
|
#include "mmulti.h"
|
2019-10-25 22:32:49 +00:00
|
|
|
#include "gamecontrol.h"
|
2019-09-19 22:42:45 +00:00
|
|
|
#include "common_game.h"
|
|
|
|
#include "blood.h"
|
|
|
|
#include "controls.h"
|
|
|
|
#include "globals.h"
|
|
|
|
#include "levels.h"
|
|
|
|
#include "map2d.h"
|
|
|
|
#include "view.h"
|
2019-11-03 19:24:50 +00:00
|
|
|
#include "d_event.h"
|
2020-07-29 21:18:08 +00:00
|
|
|
#include "gamestate.h"
|
2020-08-03 18:01:08 +00:00
|
|
|
#include "sound.h"
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2019-09-22 06:39:22 +00:00
|
|
|
BEGIN_BLD_NS
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2020-09-01 21:34:04 +00:00
|
|
|
InputPacket gInput;
|
2019-09-19 22:42:45 +00:00
|
|
|
bool bSilentAim = false;
|
|
|
|
|
|
|
|
int iTurnCount = 0;
|
|
|
|
|
|
|
|
int32_t mouseyaxismode = -1;
|
|
|
|
|
2020-09-01 13:00:35 +00:00
|
|
|
fixed_t gViewLook, gViewAngle;
|
2020-01-30 13:05:34 +00:00
|
|
|
float gViewAngleAdjust;
|
|
|
|
float gViewLookAdjust;
|
|
|
|
int gViewLookRecenter;
|
|
|
|
|
2020-09-01 21:34:04 +00:00
|
|
|
void GetInputInternal(InputPacket &inputParm)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2020-05-29 01:20:40 +00:00
|
|
|
int prevPauseState = paused;
|
2019-09-19 22:42:45 +00:00
|
|
|
ControlInfo info;
|
|
|
|
|
2020-05-29 01:20:40 +00:00
|
|
|
static double lastInputTicks;
|
2020-08-25 23:27:09 +00:00
|
|
|
auto const currentHiTicks = I_msTimeF();
|
2020-05-29 01:20:40 +00:00
|
|
|
double const elapsedInputTicks = currentHiTicks - lastInputTicks;
|
|
|
|
|
|
|
|
lastInputTicks = currentHiTicks;
|
|
|
|
|
|
|
|
auto scaleAdjustmentToInterval = [=](double x) { return x * kTicsPerSec / (1000.0 / elapsedInputTicks); };
|
|
|
|
|
2020-08-26 15:12:48 +00:00
|
|
|
InputPacket input = {};
|
2020-01-30 13:05:34 +00:00
|
|
|
|
2019-09-19 22:42:45 +00:00
|
|
|
CONTROL_GetInput(&info);
|
|
|
|
|
2020-09-01 21:34:04 +00:00
|
|
|
ApplyGlobalInput(inputParm, &info);
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2020-09-01 21:34:04 +00:00
|
|
|
bool mouseaim = !(inputParm.actions & SB_AIMMODE);
|
|
|
|
if (!mouseaim) inputParm.actions |= SB_CENTERVIEW;
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2020-05-29 01:28:41 +00:00
|
|
|
if (gPlayer[myconnectindex].nextWeapon == 0)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-09-01 21:34:04 +00:00
|
|
|
if (inputParm.actions & (SB_LOOK_UP|SB_LOOK_DOWN))
|
|
|
|
inputParm.actions |= SB_CENTERVIEW;
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2020-09-01 21:34:04 +00:00
|
|
|
int const run = !!(inputParm.actions & SB_RUN);
|
2020-01-30 13:05:34 +00:00
|
|
|
int const keyMove = (1 + run) << 10;
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2020-09-01 21:34:04 +00:00
|
|
|
if (inputParm.fvel < keyMove && inputParm.fvel > -keyMove)
|
2020-01-30 13:05:34 +00:00
|
|
|
{
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Move_Forward))
|
2020-08-26 14:54:13 +00:00
|
|
|
input.fvel += keyMove;
|
2020-01-30 13:05:34 +00:00
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Move_Backward))
|
2020-08-26 14:54:13 +00:00
|
|
|
input.fvel -= keyMove;
|
2020-01-30 13:05:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-01 21:34:04 +00:00
|
|
|
if (inputParm.svel < keyMove && inputParm.svel > -keyMove)
|
2020-01-30 13:05:34 +00:00
|
|
|
{
|
2020-03-30 22:22:55 +00:00
|
|
|
if (buttonMap.ButtonDown(gamefunc_Strafe_Left))
|
2020-08-26 14:54:13 +00:00
|
|
|
input.svel += keyMove;
|
2020-03-30 22:22:55 +00:00
|
|
|
if (buttonMap.ButtonDown(gamefunc_Strafe_Right))
|
2020-08-26 14:54:13 +00:00
|
|
|
input.svel -= keyMove;
|
2020-01-30 13:05:34 +00:00
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
char turnLeft = 0, turnRight = 0;
|
|
|
|
|
2019-11-04 22:01:50 +00:00
|
|
|
if (buttonMap.ButtonDown(gamefunc_Strafe))
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2020-09-01 21:34:04 +00:00
|
|
|
if (inputParm.svel < keyMove && inputParm.svel > -keyMove)
|
2020-01-30 13:05:34 +00:00
|
|
|
{
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Turn_Left))
|
2020-08-26 14:54:13 +00:00
|
|
|
input.svel += keyMove;
|
2020-01-30 13:05:34 +00:00
|
|
|
if (buttonMap.ButtonDown(gamefunc_Turn_Right))
|
2020-08-26 14:54:13 +00:00
|
|
|
input.svel -= keyMove;
|
2020-01-30 13:05:34 +00:00
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-04 22:01:50 +00:00
|
|
|
if (buttonMap.ButtonDown(gamefunc_Turn_Left))
|
2019-09-19 22:42:45 +00:00
|
|
|
turnLeft = 1;
|
2019-11-04 22:01:50 +00:00
|
|
|
if (buttonMap.ButtonDown(gamefunc_Turn_Right))
|
2019-09-19 22:42:45 +00:00
|
|
|
turnRight = 1;
|
|
|
|
}
|
|
|
|
|
2020-01-30 13:05:34 +00:00
|
|
|
static int32_t turnHeldTime;
|
|
|
|
static int32_t lastInputClock; // MED
|
2020-08-25 23:10:14 +00:00
|
|
|
int32_t const elapsedTics = gameclock - lastInputClock;
|
2020-01-30 13:05:34 +00:00
|
|
|
|
2020-06-24 13:11:42 +00:00
|
|
|
// Blood's q16mlook scaling is different from the other games, therefore use the below constant to attenuate
|
|
|
|
// the speed to match the other games.
|
|
|
|
float const mlookScale = 3.25f;
|
|
|
|
|
2020-08-25 23:10:14 +00:00
|
|
|
lastInputClock = gameclock;
|
2020-01-30 13:05:34 +00:00
|
|
|
|
2019-09-19 22:42:45 +00:00
|
|
|
if (turnLeft || turnRight)
|
2020-01-30 13:05:34 +00:00
|
|
|
turnHeldTime += elapsedTics;
|
2019-09-19 22:42:45 +00:00
|
|
|
else
|
2020-01-30 13:05:34 +00:00
|
|
|
turnHeldTime = 0;
|
2019-09-19 22:42:45 +00:00
|
|
|
|
|
|
|
if (turnLeft)
|
2020-09-01 13:00:35 +00:00
|
|
|
input.q16avel -= FloatToFixed(scaleAdjustmentToInterval(ClipHigh(12 * turnHeldTime, gTurnSpeed)>>2));
|
2019-09-19 22:42:45 +00:00
|
|
|
if (turnRight)
|
2020-09-01 13:00:35 +00:00
|
|
|
input.q16avel += FloatToFixed(scaleAdjustmentToInterval(ClipHigh(12 * turnHeldTime, gTurnSpeed)>>2));
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2020-08-28 22:57:07 +00:00
|
|
|
if (run && turnHeldTime > 24)
|
2020-08-26 14:54:13 +00:00
|
|
|
input.q16avel <<= 1;
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2019-11-04 22:01:50 +00:00
|
|
|
if (buttonMap.ButtonDown(gamefunc_Strafe))
|
2020-06-24 13:11:42 +00:00
|
|
|
{
|
2020-08-26 14:54:13 +00:00
|
|
|
input.svel -= info.mousex * 32.f;
|
|
|
|
input.svel -= scaleAdjustmentToInterval(info.dyaw * keyMove);
|
2020-06-24 13:11:42 +00:00
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
else
|
2020-06-24 13:11:42 +00:00
|
|
|
{
|
2020-09-01 13:00:35 +00:00
|
|
|
input.q16avel += FloatToFixed(info.mousex);
|
|
|
|
input.q16avel += FloatToFixed(scaleAdjustmentToInterval(info.dyaw));
|
2020-06-24 13:11:42 +00:00
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2020-08-26 14:54:13 +00:00
|
|
|
input.svel -= scaleAdjustmentToInterval(info.dx * keyMove);
|
|
|
|
input.fvel -= scaleAdjustmentToInterval(info.dz * keyMove);
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2019-12-05 00:08:35 +00:00
|
|
|
if (mouseaim)
|
2020-09-01 13:00:35 +00:00
|
|
|
input.q16horz += FloatToFixed(info.mousey / mlookScale);
|
2019-08-16 04:31:07 +00:00
|
|
|
else
|
2020-08-26 14:54:13 +00:00
|
|
|
input.fvel -= info.mousey * 64.f;
|
2019-10-22 22:59:01 +00:00
|
|
|
if (!in_mouseflip)
|
2020-08-26 14:54:13 +00:00
|
|
|
input.q16horz = -input.q16horz;
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2020-09-01 13:00:35 +00:00
|
|
|
input.q16horz -= FloatToFixed(scaleAdjustmentToInterval(info.dpitch / mlookScale));
|
2020-06-24 13:11:42 +00:00
|
|
|
|
2020-08-24 17:47:09 +00:00
|
|
|
if (!automapFollow && automapMode != am_off)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2020-08-26 14:54:13 +00:00
|
|
|
gViewMap.turn += input.q16avel<<2;
|
|
|
|
gViewMap.forward += input.fvel;
|
|
|
|
gViewMap.strafe += input.svel;
|
|
|
|
input.q16avel = 0;
|
|
|
|
input.fvel = 0;
|
|
|
|
input.svel = 0;
|
2020-01-30 13:05:34 +00:00
|
|
|
}
|
2020-09-01 21:34:04 +00:00
|
|
|
inputParm.fvel = clamp(inputParm.fvel + input.fvel, -2048, 2048);
|
|
|
|
inputParm.svel = clamp(inputParm.svel + input.svel, -2048, 2048);
|
|
|
|
inputParm.q16avel += input.q16avel;
|
|
|
|
inputParm.q16horz = clamp(inputParm.q16horz + input.q16horz, IntToFixed(-127)>>2, IntToFixed(127)>>2);
|
|
|
|
if (gMe && gMe->pXSprite && gMe->pXSprite->health != 0 && !paused)
|
2020-01-30 13:05:34 +00:00
|
|
|
{
|
2020-04-01 11:55:36 +00:00
|
|
|
int upAngle = 289;
|
|
|
|
int downAngle = -347;
|
|
|
|
double lookStepUp = 4.0*upAngle/60.0;
|
|
|
|
double lookStepDown = -4.0*downAngle/60.0;
|
2020-09-01 13:00:35 +00:00
|
|
|
gViewAngle = (gViewAngle + input.q16avel + FloatToFixed(scaleAdjustmentToInterval(gViewAngleAdjust))) & 0x7ffffff;
|
2020-01-30 13:05:34 +00:00
|
|
|
if (gViewLookRecenter)
|
|
|
|
{
|
|
|
|
if (gViewLook < 0)
|
2020-09-01 13:00:35 +00:00
|
|
|
gViewLook = min(gViewLook+FloatToFixed(scaleAdjustmentToInterval(lookStepDown)), 0);
|
2020-01-30 13:05:34 +00:00
|
|
|
if (gViewLook > 0)
|
2020-09-01 13:00:35 +00:00
|
|
|
gViewLook = max(gViewLook-FloatToFixed(scaleAdjustmentToInterval(lookStepUp)), 0);
|
2020-01-30 13:05:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-01 13:00:35 +00:00
|
|
|
gViewLook = clamp(gViewLook+FloatToFixed(scaleAdjustmentToInterval(gViewLookAdjust)), IntToFixed(downAngle), IntToFixed(upAngle));
|
2020-01-30 13:05:34 +00:00
|
|
|
}
|
2020-09-01 13:00:35 +00:00
|
|
|
gViewLook = clamp(gViewLook+(input.q16horz << 3), IntToFixed(downAngle), IntToFixed(upAngle));
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-22 06:39:22 +00:00
|
|
|
|
2020-09-01 21:34:04 +00:00
|
|
|
void GameInterface::GetInput(InputPacket* packet)
|
|
|
|
{
|
|
|
|
GetInputInternal(gInput);
|
|
|
|
if (packet)
|
|
|
|
{
|
|
|
|
*packet = gInput;
|
|
|
|
gInput = {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-22 06:39:22 +00:00
|
|
|
END_BLD_NS
|