raze/source/blood/src/controls.cpp

173 lines
5.1 KiB
C++
Raw Normal View History

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.
*/
//-------------------------------------------------------------------------
#include "ns.h" // Must come before everything else!
2019-09-19 22:42:45 +00:00
#include "compat.h"
#include "mmulti.h"
#include "gamecontrol.h"
2019-09-19 22:42:45 +00:00
#include "common_game.h"
#include "blood.h"
#include "globals.h"
#include "levels.h"
#include "view.h"
2019-11-03 19:24:50 +00:00
#include "d_event.h"
#include "gamestate.h"
#include "sound.h"
2019-09-19 22:42:45 +00:00
BEGIN_BLD_NS
2019-09-19 22:42:45 +00:00
static InputPacket gInput;
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)
2019-09-19 22:42:45 +00:00
{
2020-09-15 05:24:00 +00:00
double const scaleAdjust = InputScale();
2020-05-29 01:20:40 +00:00
int prevPauseState = paused;
2019-09-19 22:42:45 +00:00
InputPacket input = {};
ApplyGlobalInput(gInput, hidInput);
2019-09-19 22:42:45 +00:00
bool mouseaim = !(gInput.actions & SB_AIMMODE);
if (!mouseaim) gInput.actions |= SB_CENTERVIEW;
2019-09-19 22:42:45 +00:00
if (gPlayer[myconnectindex].nextWeapon == 0)
2019-09-19 22:42:45 +00:00
{
}
if (gInput.actions & (SB_LOOK_UP|SB_LOOK_DOWN))
gInput.actions |= SB_CENTERVIEW;
2019-09-19 22:42:45 +00:00
int const run = !!(gInput.actions & SB_RUN);
int const keyMove = (1 + run) << 10;
2019-09-19 22:42:45 +00:00
if (gInput.fvel < keyMove && gInput.fvel > -keyMove)
{
if (buttonMap.ButtonDown(gamefunc_Move_Forward))
input.fvel += keyMove;
if (buttonMap.ButtonDown(gamefunc_Move_Backward))
input.fvel -= keyMove;
}
if (gInput.svel < keyMove && gInput.svel > -keyMove)
{
if (buttonMap.ButtonDown(gamefunc_Strafe_Left))
input.svel += keyMove;
if (buttonMap.ButtonDown(gamefunc_Strafe_Right))
input.svel -= keyMove;
}
2019-09-19 22:42:45 +00:00
char turnLeft = 0, turnRight = 0;
if (buttonMap.ButtonDown(gamefunc_Strafe))
2019-09-19 22:42:45 +00:00
{
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;
}
2019-09-19 22:42:45 +00:00
}
else
{
if (buttonMap.ButtonDown(gamefunc_Turn_Left))
2019-09-19 22:42:45 +00:00
turnLeft = 1;
if (buttonMap.ButtonDown(gamefunc_Turn_Right))
2019-09-19 22:42:45 +00:00
turnRight = 1;
}
static int32_t turnHeldTime;
static int32_t lastInputClock; // MED
int32_t const elapsedTics = gFrameClock - lastInputClock;
// 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;
lastInputClock = gFrameClock;
2019-09-19 22:42:45 +00:00
if (turnLeft || turnRight)
turnHeldTime += elapsedTics;
2019-09-19 22:42:45 +00:00
else
turnHeldTime = 0;
2019-09-19 22:42:45 +00:00
if (turnLeft)
2020-09-15 05:24:00 +00:00
input.q16avel -= FloatToFixed(scaleAdjust * (ClipHigh(12 * turnHeldTime, gTurnSpeed) >> 2));
2019-09-19 22:42:45 +00:00
if (turnRight)
2020-09-15 05:24:00 +00:00
input.q16avel += FloatToFixed(scaleAdjust * (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)
input.q16avel <<= 1;
2019-09-19 22:42:45 +00:00
if (buttonMap.ButtonDown(gamefunc_Strafe))
{
2020-09-15 05:24:00 +00:00
input.svel -= xs_CRoundToInt((hidInput->mousex * 32.) + (scaleAdjust * (hidInput->dyaw * keyMove)));
}
2019-09-19 22:42:45 +00:00
else
{
2020-09-15 05:24:00 +00:00
input.q16avel += FloatToFixed(hidInput->mousex + (scaleAdjust * (hidInput->dyaw)));
}
2019-09-19 22:42:45 +00:00
2020-09-15 05:24:00 +00:00
input.svel -= xs_CRoundToInt(scaleAdjust * (hidInput->dx * keyMove));
input.fvel -= xs_CRoundToInt(scaleAdjust * (hidInput->dz * keyMove));
2019-09-19 22:42:45 +00:00
if (mouseaim)
input.q16horz += FloatToFixed(hidInput->mousey / mlookScale);
else
2020-09-15 05:24:00 +00:00
input.fvel -= xs_CRoundToInt(hidInput->mousey * 64.);
if (!in_mouseflip)
input.q16horz = -input.q16horz;
2019-09-19 22:42:45 +00:00
2020-09-15 05:24:00 +00:00
input.q16horz -= FloatToFixed(scaleAdjust * (hidInput->dpitch / mlookScale));
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);
}
2019-09-19 22:42:45 +00:00
}
void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput)
{
GetInputInternal(hidInput);
if (packet)
{
*packet = gInput;
gInput = {};
}
}
END_BLD_NS