raze/source/exhumed/src/input.cpp

236 lines
5.8 KiB
C++
Raw Normal View History

//-------------------------------------------------------------------------
/*
Copyright (C) 2010-2019 EDuke32 developers and contributors
Copyright (C) 2019 sirlemonhead, Nuke.YKT
This file is part of PCExhumed.
PCExhumed 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"
2019-11-24 09:03:19 +00:00
#include "ps_input.h"
#include "exhumed.h"
#include "player.h"
#include "status.h"
#include "view.h"
#include "menu.h"
BEGIN_PS_NS
static int turn;
static int counter;
short nInputStack = 0;
short bStackNode[kMaxPlayers];
short nTypeStack[kMaxPlayers];
PlayerInput sPlayerInput[kMaxPlayers];
int *pStackPtr;
// (nInputStack * 32) - 11;
void PushInput(PlayerInput *pInput, int edx)
{
if (!bStackNode[edx])
{
// memcpy(sInputStack[nInputStack], pInput,
}
}
int PopInput()
{
if (!nInputStack)
return -1;
nInputStack--;
// TEMP
return 0;
}
void InitInput()
{
memset(nTypeStack, 0, sizeof(nTypeStack));
nInputStack = 0;
memset(bStackNode, 0, sizeof(bStackNode));
// pStackPtr = &sInputStack;
}
void ClearSpaceBar(short nPlayer)
{
sPlayerInput[nPlayer].actions &= SB_OPEN;
2019-11-24 09:03:19 +00:00
buttonMap.ClearButton(gamefunc_Open);
}
void BackupInput()
{
}
void SendInput()
{
}
void CheckKeys2()
{
if (PlayerList[nLocalPlayer].nHealth <= 0)
{
SetAirFrame();
}
}
static void processMovement(ControlInfo* const hidInput)
2020-08-26 22:58:21 +00:00
{
// JBF: Run key behaviour is selectable
2020-08-28 22:57:07 +00:00
int const playerRunning = !!(localInput.actions & SB_RUN);
2020-08-26 22:58:21 +00:00
int const turnAmount = playerRunning ? 12 : 8;
int const keyMove = playerRunning ? 12 : 6;
bool const mouseaim = !(localInput.actions & SB_AIMMODE);
double const scaleAdjust = InputScale();
InputPacket tempinput {};
2020-08-26 22:58:21 +00:00
if (buttonMap.ButtonDown(gamefunc_Strafe))
{
tempinput.svel -= xs_CRoundToInt((hidInput->mousex * 32.) + (scaleAdjust * (hidInput->dyaw * keyMove)));
2020-08-26 22:58:21 +00:00
}
else
{
tempinput.q16avel += FloatToFixed(hidInput->mousex + (scaleAdjust * hidInput->dyaw));
2020-08-26 22:58:21 +00:00
}
if (mouseaim)
{
tempinput.q16horz += FloatToFixed(hidInput->mousey);
}
2020-08-26 22:58:21 +00:00
else
{
tempinput.fvel -= xs_CRoundToInt(hidInput->mousey * 8.);
}
2020-08-26 22:58:21 +00:00
if (!in_mouseflip)
tempinput.q16horz = -tempinput.q16horz;
2020-08-26 22:58:21 +00:00
tempinput.q16horz -= FloatToFixed(scaleAdjust * hidInput->dpitch);
tempinput.svel -= xs_CRoundToInt(scaleAdjust * (hidInput->dx * keyMove));
tempinput.fvel -= xs_CRoundToInt(scaleAdjust * (hidInput->dz * keyMove));
2020-08-26 22:58:21 +00:00
if (buttonMap.ButtonDown(gamefunc_Strafe))
{
if (buttonMap.ButtonDown(gamefunc_Turn_Left))
tempinput.svel -= -keyMove;
2020-08-26 22:58:21 +00:00
if (buttonMap.ButtonDown(gamefunc_Turn_Right))
tempinput.svel -= keyMove;
2020-08-26 22:58:21 +00:00
}
else
{
if (buttonMap.ButtonDown(gamefunc_Turn_Left))
{
turn -= 2;
if (turn < -turnAmount)
turn = -turnAmount;
}
else if (buttonMap.ButtonDown(gamefunc_Turn_Right))
{
turn += 2;
if (turn > turnAmount)
turn = turnAmount;
}
if (turn < 0)
{
turn++;
if (turn > 0)
turn = 0;
}
if (turn > 0)
{
turn--;
if (turn < 0)
turn = 0;
}
//if ((counter++) % 4 == 0) // what was this for???
tempinput.q16avel += FloatToFixed(scaleAdjust * (turn * 2));
2020-08-26 22:58:21 +00:00
}
if (buttonMap.ButtonDown(gamefunc_Strafe_Left))
tempinput.svel += keyMove;
2020-08-26 22:58:21 +00:00
if (buttonMap.ButtonDown(gamefunc_Strafe_Right))
tempinput.svel += -keyMove;
2020-08-26 22:58:21 +00:00
if (buttonMap.ButtonDown(gamefunc_Move_Forward))
tempinput.fvel += keyMove;
2020-08-26 22:58:21 +00:00
if (buttonMap.ButtonDown(gamefunc_Move_Backward))
tempinput.fvel += -keyMove;
2020-08-26 22:58:21 +00:00
localInput.fvel = clamp(localInput.fvel + tempinput.fvel, -12, 12);
localInput.svel = clamp(localInput.svel + tempinput.svel, -12, 12);
localInput.q16avel += tempinput.q16avel;
localInput.q16horz += tempinput.q16horz;
2020-08-26 22:58:21 +00:00
if (!cl_syncinput)
2020-08-26 22:58:21 +00:00
{
Player* pPlayer = &PlayerList[nLocalPlayer];
2020-08-26 22:58:21 +00:00
if (!nFreeze)
{
applylook(&pPlayer->q16angle, &pPlayer->q16look_ang, &pPlayer->q16rotscrnang, &pPlayer->spin, tempinput.q16avel, &sPlayerInput[nLocalPlayer].actions, scaleAdjust, eyelevel[nLocalPlayer] > -14080);
sethorizon(&pPlayer->q16horiz, tempinput.q16horz, &sPlayerInput[nLocalPlayer].actions, scaleAdjust);
UpdatePlayerSpriteAngle(pPlayer);
}
playerProcessHelpers(&pPlayer->q16angle, &pPlayer->angAdjust, &pPlayer->angTarget, &pPlayer->q16horiz, &pPlayer->horizAdjust, &pPlayer->horizTarget, scaleAdjust);
}
}
2020-08-26 22:58:21 +00:00
void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput)
{
if (paused || M_Active())
{
localInput = {};
return;
2020-08-26 22:58:21 +00:00
}
if (packet != nullptr)
2020-08-26 22:58:21 +00:00
{
localInput = {};
ApplyGlobalInput(localInput, hidInput);
if (PlayerList[nLocalPlayer].nHealth == 0) localInput.actions &= SB_OPEN;
2020-08-26 22:58:21 +00:00
}
if (PlayerList[nLocalPlayer].nHealth == 0)
{
lPlayerYVel = 0;
lPlayerXVel = 0;
return;
}
processMovement(hidInput);
if (packet) *packet = localInput;
}
END_PS_NS