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!
|
|
|
|
|
2020-02-16 20:31:29 +00:00
|
|
|
#include "mmulti.h"
|
2019-09-19 22:42:45 +00:00
|
|
|
#include "view.h"
|
2020-07-29 21:18:08 +00:00
|
|
|
#include "gamestate.h"
|
2020-09-16 10:23:59 +00:00
|
|
|
#include "menu.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-16 10:23:59 +00:00
|
|
|
static const double gTurnSpeed = 92.;
|
2020-09-14 05:14:22 +00:00
|
|
|
static InputPacket gInput;
|
2020-09-16 10:23:59 +00:00
|
|
|
static double turnHeldTime;
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
MAXFVEL = 2048,
|
|
|
|
MAXSVEL = 2048,
|
2020-09-21 21:46:30 +00:00
|
|
|
MAXHORIZVEL = 128
|
2020-09-16 10:23:59 +00:00
|
|
|
};
|
2020-01-30 13:05:34 +00:00
|
|
|
|
2020-09-21 07:00:07 +00:00
|
|
|
void UpdatePlayerSpriteAngle(PLAYER* pPlayer);
|
2020-09-16 08:22:01 +00:00
|
|
|
|
2020-09-16 10:23:59 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// handles movement
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2020-09-17 06:41:09 +00:00
|
|
|
static void processMovement(ControlInfo* const hidInput)
|
2020-09-16 10:23:59 +00:00
|
|
|
{
|
|
|
|
double const scaleAdjust = InputScale();
|
2020-09-14 05:14:22 +00:00
|
|
|
int const run = !!(gInput.actions & SB_RUN);
|
2020-01-30 13:05:34 +00:00
|
|
|
int const keyMove = (1 + run) << 10;
|
2020-09-16 10:23:59 +00:00
|
|
|
InputPacket input = {};
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2020-09-16 10:23:59 +00:00
|
|
|
if (buttonMap.ButtonDown(gamefunc_Strafe))
|
2020-01-30 13:05:34 +00:00
|
|
|
{
|
2020-09-16 10:23:59 +00:00
|
|
|
input.svel -= xs_CRoundToInt((hidInput->mousex * 32.) + (scaleAdjust * (hidInput->dyaw * keyMove)));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
input.q16avel += FloatToFixed(hidInput->mousex + (scaleAdjust * hidInput->dyaw));
|
2020-01-30 13:05:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-17 06:41:09 +00:00
|
|
|
if (!(gInput.actions & SB_AIMMODE))
|
2020-01-30 13:05:34 +00:00
|
|
|
{
|
2020-09-16 10:23:59 +00:00
|
|
|
input.q16horz += FloatToFixed(hidInput->mousey);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
input.fvel -= xs_CRoundToInt(hidInput->mousey * 64.);
|
2020-01-30 13:05:34 +00:00
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2020-09-16 10:23:59 +00:00
|
|
|
if (!in_mouseflip)
|
|
|
|
input.q16horz = -input.q16horz;
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2020-09-16 10:23:59 +00:00
|
|
|
input.q16horz -= FloatToFixed(scaleAdjust * hidInput->dpitch);
|
|
|
|
input.svel -= xs_CRoundToInt(scaleAdjust * (hidInput->dx * keyMove));
|
|
|
|
input.fvel -= xs_CRoundToInt(scaleAdjust * (hidInput->dz * keyMove));
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2019-11-04 22:01:50 +00:00
|
|
|
if (buttonMap.ButtonDown(gamefunc_Strafe))
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2020-09-14 05:14:22 +00:00
|
|
|
if (gInput.svel < keyMove && gInput.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-09-16 10:23:59 +00:00
|
|
|
|
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))
|
2020-09-16 10:23:59 +00:00
|
|
|
{
|
|
|
|
turnHeldTime += scaleAdjust * kTicsPerFrame;
|
|
|
|
input.q16avel -= FloatToFixed(scaleAdjust * (min(12. * turnHeldTime, gTurnSpeed) / 4.));
|
|
|
|
}
|
|
|
|
else if (buttonMap.ButtonDown(gamefunc_Turn_Right))
|
|
|
|
{
|
|
|
|
turnHeldTime += scaleAdjust * kTicsPerFrame;
|
|
|
|
input.q16avel += FloatToFixed(scaleAdjust * (min(12. * turnHeldTime, gTurnSpeed) / 4.));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
turnHeldTime = 0;
|
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-09-16 10:23:59 +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
|
|
|
|
2020-09-16 10:23:59 +00:00
|
|
|
if (abs(gInput.fvel) < keyMove)
|
2020-06-24 13:11:42 +00:00
|
|
|
{
|
2020-09-16 10:23:59 +00:00
|
|
|
if (buttonMap.ButtonDown(gamefunc_Move_Forward))
|
|
|
|
input.fvel += keyMove;
|
2020-09-15 05:24:00 +00:00
|
|
|
|
2020-09-16 10:23:59 +00:00
|
|
|
if (buttonMap.ButtonDown(gamefunc_Move_Backward))
|
|
|
|
input.fvel -= keyMove;
|
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2020-09-16 10:23:59 +00:00
|
|
|
if (abs(gInput.svel) < keyMove)
|
|
|
|
{
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Strafe_Left))
|
|
|
|
input.svel += keyMove;
|
2020-06-24 13:11:42 +00:00
|
|
|
|
2020-09-16 10:23:59 +00:00
|
|
|
if (buttonMap.ButtonDown(gamefunc_Strafe_Right))
|
|
|
|
input.svel -= keyMove;
|
|
|
|
}
|
2020-09-16 08:22:01 +00:00
|
|
|
|
|
|
|
if (!cl_syncinput && gamestate == GS_LEVEL)
|
|
|
|
{
|
2020-09-16 10:23:59 +00:00
|
|
|
PLAYER* pPlayer = &gPlayer[myconnectindex];
|
2020-09-16 11:59:19 +00:00
|
|
|
|
2020-09-16 12:02:05 +00:00
|
|
|
// Perform unsynchronised angle/horizon if not dead.
|
|
|
|
if (gView->pXSprite->health != 0)
|
|
|
|
{
|
2020-09-21 05:51:33 +00:00
|
|
|
applylook(&pPlayer->q16ang, &pPlayer->q16look_ang, &pPlayer->q16rotscrnang, &pPlayer->spin, input.q16avel, &pPlayer->input.actions, scaleAdjust, pPlayer->posture != 0);
|
2020-09-21 07:00:07 +00:00
|
|
|
UpdatePlayerSpriteAngle(pPlayer);
|
2020-09-20 10:01:05 +00:00
|
|
|
sethorizon(&pPlayer->q16horiz, input.q16horz, &pPlayer->input.actions, scaleAdjust);
|
2020-09-16 12:02:05 +00:00
|
|
|
}
|
2020-09-16 11:59:19 +00:00
|
|
|
|
2020-09-21 03:41:16 +00:00
|
|
|
playerProcessHelpers(&pPlayer->q16ang, &pPlayer->angAdjust, &pPlayer->angTarget, &pPlayer->q16horiz, &pPlayer->horizAdjust, &pPlayer->horizTarget, scaleAdjust);
|
2020-09-16 08:22:01 +00:00
|
|
|
}
|
2020-09-16 10:23:59 +00:00
|
|
|
|
|
|
|
gInput.fvel = clamp(gInput.fvel + input.fvel, -MAXFVEL, MAXFVEL);
|
|
|
|
gInput.svel = clamp(gInput.svel + input.svel, -MAXSVEL, MAXSVEL);
|
|
|
|
gInput.q16avel += input.q16avel;
|
|
|
|
gInput.q16horz = clamp(gInput.q16horz + input.q16horz, -IntToFixed(MAXHORIZVEL), IntToFixed(MAXHORIZVEL));
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
2019-09-22 06:39:22 +00:00
|
|
|
|
2020-09-06 10:17:54 +00:00
|
|
|
void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput)
|
2020-09-01 21:34:04 +00:00
|
|
|
{
|
2020-09-16 10:23:59 +00:00
|
|
|
if (paused || M_Active())
|
|
|
|
{
|
|
|
|
gInput = {};
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-17 06:41:09 +00:00
|
|
|
ApplyGlobalInput(gInput, hidInput);
|
|
|
|
processMovement(hidInput);
|
2020-09-16 10:23:59 +00:00
|
|
|
|
2020-09-01 21:34:04 +00:00
|
|
|
if (packet)
|
|
|
|
{
|
|
|
|
*packet = gInput;
|
|
|
|
gInput = {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-23 14:15:51 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2020-09-23 14:20:40 +00:00
|
|
|
// This is called from InputState::ClearAllInput and resets all static state being used here.
|
2020-09-23 14:15:51 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void GameInterface::clearlocalinputstate()
|
|
|
|
{
|
|
|
|
gInput = {};
|
|
|
|
turnHeldTime = 0;
|
|
|
|
}
|
|
|
|
|
2019-09-22 06:39:22 +00:00
|
|
|
END_BLD_NS
|