2019-11-20 16:21:32 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
2019-11-22 23:11:37 +00:00
|
|
|
#include "ns.h"
|
2019-11-24 09:03:19 +00:00
|
|
|
#include "ps_input.h"
|
2019-08-26 03:59:14 +00:00
|
|
|
#include "engine.h"
|
|
|
|
#include "exhumed.h"
|
|
|
|
#include "player.h"
|
2020-08-23 05:41:29 +00:00
|
|
|
#include "aistuff.h"
|
|
|
|
#include "status.h"
|
|
|
|
#include "view.h"
|
2020-08-24 18:34:18 +00:00
|
|
|
#include "gamecontrol.h"
|
2019-08-26 03:59:14 +00:00
|
|
|
#include <string.h>
|
2020-09-02 19:42:12 +00:00
|
|
|
#include "v_video.h"
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-11-22 23:11:37 +00:00
|
|
|
BEGIN_PS_NS
|
|
|
|
|
2020-08-26 22:58:21 +00:00
|
|
|
extern short bPlayerPan;
|
|
|
|
extern short bLockPan;
|
|
|
|
|
2019-08-26 03:59:14 +00:00
|
|
|
short nInputStack = 0;
|
|
|
|
|
|
|
|
short bStackNode[kMaxPlayers];
|
|
|
|
|
|
|
|
short nTypeStack[kMaxPlayers];
|
|
|
|
PlayerInput sPlayerInput[kMaxPlayers];
|
|
|
|
|
|
|
|
int *pStackPtr;
|
|
|
|
|
|
|
|
// (nInputStack * 32) - 11;
|
|
|
|
|
|
|
|
void PushInput(PlayerInput *pInput, int edx)
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
if (!bStackNode[edx])
|
|
|
|
{
|
2019-08-26 03:59:14 +00:00
|
|
|
// memcpy(sInputStack[nInputStack], pInput,
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int PopInput()
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
if (!nInputStack)
|
|
|
|
return -1;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
nInputStack--;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
// TEMP
|
|
|
|
return 0;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InitInput()
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
memset(nTypeStack, 0, sizeof(nTypeStack));
|
|
|
|
nInputStack = 0;
|
|
|
|
memset(bStackNode, 0, sizeof(bStackNode));
|
2019-08-26 03:59:14 +00:00
|
|
|
|
|
|
|
// pStackPtr = &sInputStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearSpaceBar(short nPlayer)
|
|
|
|
{
|
2020-08-28 20:51:05 +00:00
|
|
|
sPlayerInput[nPlayer].actions &= SB_OPEN;
|
2019-11-24 09:03:19 +00:00
|
|
|
buttonMap.ClearButton(gamefunc_Open);
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BackupInput()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendInput()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-08-23 05:41:29 +00:00
|
|
|
static int32_t nonsharedtimer;
|
2020-08-18 08:28:19 +00:00
|
|
|
|
2020-08-23 05:41:29 +00:00
|
|
|
void CheckKeys2()
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
2020-09-02 19:42:12 +00:00
|
|
|
static int nonsharedtimer;
|
|
|
|
int ms = screen->FrameTime;
|
|
|
|
int interval;
|
|
|
|
if (nonsharedtimer > 0 || ms < nonsharedtimer)
|
|
|
|
{
|
|
|
|
interval = ms - nonsharedtimer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
interval = 0;
|
|
|
|
}
|
|
|
|
nonsharedtimer = screen->FrameTime;
|
|
|
|
|
|
|
|
if (System_WantGuiCapture())
|
|
|
|
return;
|
|
|
|
|
2020-08-24 17:54:26 +00:00
|
|
|
if (automapMode != am_off)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2020-09-02 19:42:12 +00:00
|
|
|
double j = interval * (120. / 1000);
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2020-08-23 05:41:29 +00:00
|
|
|
if (buttonMap.ButtonDown(gamefunc_Enlarge_Screen))
|
2020-09-02 19:42:12 +00:00
|
|
|
lMapZoom += (int)fmulscale6(j, max(lMapZoom, 256));
|
2020-08-23 05:41:29 +00:00
|
|
|
if (buttonMap.ButtonDown(gamefunc_Shrink_Screen))
|
2020-09-02 19:42:12 +00:00
|
|
|
lMapZoom -= (int)fmulscale6(j, max(lMapZoom, 256));
|
2020-08-23 05:41:29 +00:00
|
|
|
|
|
|
|
lMapZoom = clamp(lMapZoom, 48, 2048);
|
|
|
|
}
|
2020-08-23 14:11:18 +00:00
|
|
|
if (PlayerList[nLocalPlayer].nHealth <= 0)
|
2020-08-23 05:41:29 +00:00
|
|
|
{
|
|
|
|
SetAirFrame();
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
2020-08-23 14:11:18 +00:00
|
|
|
|
2020-08-26 22:58:21 +00:00
|
|
|
void PlayerInterruptKeys(bool after)
|
|
|
|
{
|
|
|
|
ControlInfo info;
|
|
|
|
memset(&info, 0, sizeof(ControlInfo)); // this is done within CONTROL_GetInput() anyway
|
|
|
|
CONTROL_GetInput(&info);
|
|
|
|
|
|
|
|
static double lastInputTicks;
|
|
|
|
auto const currentHiTicks = I_msTimeF();
|
|
|
|
double const elapsedInputTicks = currentHiTicks - lastInputTicks;
|
|
|
|
|
|
|
|
lastInputTicks = currentHiTicks;
|
|
|
|
|
|
|
|
auto scaleAdjustmentToInterval = [=](double x) { return x * (120 / 4) / (1000.0 / elapsedInputTicks); };
|
|
|
|
|
|
|
|
if (paused)
|
|
|
|
return;
|
|
|
|
|
2020-08-29 11:32:14 +00:00
|
|
|
InputPacket tempinput{};
|
2020-09-01 13:00:35 +00:00
|
|
|
fixed_t input_angle = 0;
|
2020-08-26 22:58:21 +00:00
|
|
|
|
|
|
|
if (PlayerList[nLocalPlayer].nHealth == 0)
|
|
|
|
{
|
2020-08-29 11:32:14 +00:00
|
|
|
localInput = {};
|
2020-08-26 22:58:21 +00:00
|
|
|
lPlayerYVel = 0;
|
|
|
|
lPlayerXVel = 0;
|
|
|
|
nPlayerDAng = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-26 22:53:35 +00:00
|
|
|
if (!after)
|
|
|
|
{
|
2020-08-29 11:32:14 +00:00
|
|
|
localInput = {};
|
2020-08-26 22:53:35 +00:00
|
|
|
ApplyGlobalInput(localInput, &info);
|
2020-08-28 20:51:05 +00:00
|
|
|
if (PlayerList[nLocalPlayer].nHealth == 0) localInput.actions &= ~(SB_FIRE | SB_JUMP | SB_CROUCH);
|
2020-08-26 22:53:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Strafe))
|
|
|
|
{
|
2020-08-29 11:32:14 +00:00
|
|
|
tempinput.svel -= info.mousex * 4.f;
|
|
|
|
tempinput.svel -= info.dyaw * keyMove;
|
2020-08-26 22:58:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-01 13:00:35 +00:00
|
|
|
input_angle += FloatToFixed(info.mousex + scaleAdjustmentToInterval(info.dyaw));
|
2020-08-26 22:58:21 +00:00
|
|
|
}
|
|
|
|
|
2020-08-31 18:51:22 +00:00
|
|
|
bool mouseaim = !(localInput.actions & SB_AIMMODE);
|
2020-08-26 22:58:21 +00:00
|
|
|
|
2020-08-29 11:32:14 +00:00
|
|
|
if (mouseaim)
|
2020-09-01 13:00:35 +00:00
|
|
|
tempinput.q16horz += FloatToFixed(info.mousey);
|
2020-08-26 22:58:21 +00:00
|
|
|
else
|
2020-08-29 11:32:14 +00:00
|
|
|
tempinput.fvel -= info.mousey * 8.f;
|
2020-08-26 22:58:21 +00:00
|
|
|
|
2020-08-29 11:32:14 +00:00
|
|
|
if (!in_mouseflip) tempinput.q16horz = -tempinput.q16horz;
|
2020-08-26 22:58:21 +00:00
|
|
|
|
2020-09-01 13:00:35 +00:00
|
|
|
tempinput.q16horz -= FloatToFixed(scaleAdjustmentToInterval(info.dpitch));
|
2020-08-29 11:32:14 +00:00
|
|
|
tempinput.svel -= info.dx * keyMove;
|
|
|
|
tempinput.fvel -= info.dz * keyMove;
|
2020-08-26 22:58:21 +00:00
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Strafe))
|
|
|
|
{
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Turn_Left))
|
2020-08-29 11:32:14 +00:00
|
|
|
tempinput.svel -= -keyMove;
|
2020-08-26 22:58:21 +00:00
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Turn_Right))
|
2020-08-29 11:32:14 +00:00
|
|
|
tempinput.svel -= keyMove;
|
2020-08-26 22:58:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static int turn = 0;
|
|
|
|
static int counter = 0;
|
|
|
|
// normal, non strafing movement
|
|
|
|
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???
|
2020-09-01 13:00:35 +00:00
|
|
|
input_angle += FloatToFixed(scaleAdjustmentToInterval(turn * 2));
|
2020-08-26 22:58:21 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Strafe_Left))
|
2020-08-29 11:32:14 +00:00
|
|
|
tempinput.svel += keyMove;
|
2020-08-26 22:58:21 +00:00
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Strafe_Right))
|
2020-08-29 11:32:14 +00:00
|
|
|
tempinput.svel += -keyMove;
|
2020-08-26 22:58:21 +00:00
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Move_Forward))
|
2020-08-29 11:32:14 +00:00
|
|
|
tempinput.fvel += keyMove;
|
2020-08-26 22:58:21 +00:00
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Move_Backward))
|
2020-08-29 11:32:14 +00:00
|
|
|
tempinput.fvel += -keyMove;
|
2020-08-26 22:58:21 +00:00
|
|
|
|
2020-08-29 11:32:14 +00:00
|
|
|
localInput.fvel = clamp(localInput.fvel + tempinput.fvel, -12, 12);
|
|
|
|
localInput.svel = clamp(localInput.svel + tempinput.svel, -12, 12);
|
2020-08-26 22:58:21 +00:00
|
|
|
|
2020-09-01 13:00:35 +00:00
|
|
|
localInput.q16avel += input_angle;
|
2020-08-26 22:58:21 +00:00
|
|
|
|
|
|
|
if (!nFreeze)
|
|
|
|
{
|
2020-09-01 13:00:35 +00:00
|
|
|
PlayerList[nLocalPlayer].q16angle = (PlayerList[nLocalPlayer].q16angle + input_angle) & 0x7FFFFFF;
|
2020-08-26 22:58:21 +00:00
|
|
|
|
|
|
|
// A horiz diff of 128 equal 45 degrees,
|
|
|
|
// so we convert horiz to 1024 angle units
|
|
|
|
|
2020-09-01 13:00:35 +00:00
|
|
|
float const horizAngle = clamp(atan2f(PlayerList[nLocalPlayer].q16horiz - IntToFixed(92), IntToFixed(128)) * (512.f / fPI) + FixedToFloat(tempinput.q16horz), -255.f, 255.f);
|
2020-09-04 19:24:48 +00:00
|
|
|
auto newq16horiz = IntToFixed(92) + xs_CRoundToInt(IntToFixed(128) * tanf(horizAngle * (fPI / 512.f)));
|
2020-08-31 19:48:17 +00:00
|
|
|
if (PlayerList[nLocalPlayer].q16horiz != newq16horiz)
|
|
|
|
{
|
|
|
|
bLockPan = true;
|
|
|
|
PlayerList[nLocalPlayer].q16horiz = newq16horiz;
|
|
|
|
nDestVertPan[nLocalPlayer] = PlayerList[nLocalPlayer].q16horiz;
|
|
|
|
}
|
2020-08-26 22:58:21 +00:00
|
|
|
|
|
|
|
// Look/aim up/down functions.
|
2020-08-29 11:32:14 +00:00
|
|
|
if (localInput.actions & (SB_LOOK_UP|SB_AIM_UP))
|
2020-08-26 22:58:21 +00:00
|
|
|
{
|
2020-08-31 19:48:17 +00:00
|
|
|
bLockPan |= (localInput.actions & SB_LOOK_UP);
|
2020-09-01 13:00:35 +00:00
|
|
|
if (PlayerList[nLocalPlayer].q16horiz < IntToFixed(180)) {
|
|
|
|
PlayerList[nLocalPlayer].q16horiz += FloatToFixed(scaleAdjustmentToInterval(4));
|
2020-08-26 22:58:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bPlayerPan = true;
|
|
|
|
nDestVertPan[nLocalPlayer] = PlayerList[nLocalPlayer].q16horiz;
|
|
|
|
}
|
2020-08-29 11:32:14 +00:00
|
|
|
else if (localInput.actions & (SB_LOOK_DOWN|SB_AIM_DOWN))
|
2020-08-26 22:58:21 +00:00
|
|
|
{
|
2020-08-31 19:48:17 +00:00
|
|
|
bLockPan |= (localInput.actions & SB_LOOK_DOWN);
|
2020-09-01 13:00:35 +00:00
|
|
|
if (PlayerList[nLocalPlayer].q16horiz > IntToFixed(4)) {
|
|
|
|
PlayerList[nLocalPlayer].q16horiz -= FloatToFixed(scaleAdjustmentToInterval(4));
|
2020-08-26 22:58:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bPlayerPan = true;
|
|
|
|
nDestVertPan[nLocalPlayer] = PlayerList[nLocalPlayer].q16horiz;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// loc_1C048:
|
|
|
|
if (totalvel[nLocalPlayer] > 20) {
|
|
|
|
bPlayerPan = false;
|
|
|
|
}
|
2020-08-31 19:41:39 +00:00
|
|
|
if (nFreeze) return;
|
2020-08-26 22:58:21 +00:00
|
|
|
|
|
|
|
// loc_1C05E
|
2020-09-01 13:00:35 +00:00
|
|
|
fixed_t dVertPan = nDestVertPan[nLocalPlayer] - PlayerList[nLocalPlayer].q16horiz;
|
2020-08-31 19:41:39 +00:00
|
|
|
if (dVertPan != 0 && !bLockPan)
|
2020-08-26 22:58:21 +00:00
|
|
|
{
|
2020-08-31 19:41:39 +00:00
|
|
|
int val = dVertPan / 4;
|
|
|
|
if (abs(val) >= 4)
|
2020-08-26 22:58:21 +00:00
|
|
|
{
|
2020-08-31 19:41:39 +00:00
|
|
|
if (val >= 4)
|
2020-09-01 13:00:35 +00:00
|
|
|
PlayerList[nLocalPlayer].q16horiz += IntToFixed(4);
|
2020-08-31 19:41:39 +00:00
|
|
|
else if (val <= -4)
|
2020-09-01 13:00:35 +00:00
|
|
|
PlayerList[nLocalPlayer].q16horiz -= IntToFixed(4);
|
2020-08-31 19:41:39 +00:00
|
|
|
}
|
2020-09-01 13:00:35 +00:00
|
|
|
else if (abs(dVertPan) >= FRACUNIT)
|
2020-08-31 19:41:39 +00:00
|
|
|
PlayerList[nLocalPlayer].q16horiz += dVertPan / 2.0f;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (mouseaim) bLockPan = true;
|
|
|
|
PlayerList[nLocalPlayer].q16horiz = nDestVertPan[nLocalPlayer];
|
2020-08-26 22:58:21 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-31 19:41:39 +00:00
|
|
|
else bLockPan = mouseaim;
|
2020-09-01 13:00:35 +00:00
|
|
|
PlayerList[nLocalPlayer].q16horiz = clamp(PlayerList[nLocalPlayer].q16horiz, 0, IntToFixed(184));
|
2020-08-26 22:58:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-02 20:55:57 +00:00
|
|
|
void GameInterface::GetInput(InputPacket* packet)
|
|
|
|
{
|
|
|
|
PlayerInterruptKeys(packet == nullptr);
|
|
|
|
if (packet) *packet = localInput;
|
|
|
|
}
|
|
|
|
|
2020-08-27 22:03:35 +00:00
|
|
|
END_PS_NS
|