2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
cl_input.c
|
|
|
|
|
|
|
|
builds an intended movement command to send to the server
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/checksum.h"
|
|
|
|
#include "QF/cmd.h"
|
2021-11-16 00:37:39 +00:00
|
|
|
#include "QF/console.h"
|
2001-05-31 03:41:35 +00:00
|
|
|
#include "QF/cvar.h"
|
2001-04-10 21:45:42 +00:00
|
|
|
#include "QF/input.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/keys.h"
|
2021-11-28 15:01:57 +00:00
|
|
|
#include "QF/listener.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/msg.h"
|
2007-11-06 10:17:14 +00:00
|
|
|
#include "QF/sys.h"
|
2001-05-09 18:04:45 +00:00
|
|
|
#include "QF/teamplay.h"
|
2002-05-11 00:36:12 +00:00
|
|
|
#include "QF/va.h"
|
2001-05-31 03:41:35 +00:00
|
|
|
|
2021-11-16 00:37:39 +00:00
|
|
|
#include "QF/input/event.h"
|
|
|
|
|
2001-08-28 23:05:45 +00:00
|
|
|
#include "compat.h"
|
2021-03-12 02:48:53 +00:00
|
|
|
|
2021-11-25 03:46:54 +00:00
|
|
|
#include "client/input.h"
|
2021-03-12 02:48:53 +00:00
|
|
|
#include "client/view.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2020-06-21 14:15:17 +00:00
|
|
|
#include "qw/msg_ucmd.h"
|
|
|
|
|
|
|
|
#include "qw/include/cl_cam.h"
|
|
|
|
#include "qw/include/cl_demo.h"
|
|
|
|
#include "qw/include/cl_input.h"
|
|
|
|
#include "qw/include/cl_parse.h"
|
|
|
|
#include "qw/include/client.h"
|
|
|
|
#include "qw/include/host.h"
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
cvar_t *cl_nodelta;
|
2001-12-03 09:01:17 +00:00
|
|
|
cvar_t *cl_maxnetfps;
|
|
|
|
cvar_t *cl_spamimpulse;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
int in_impulse;
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2021-03-19 18:56:16 +00:00
|
|
|
IN_Impulse (void *data)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
in_impulse = atoi (Cmd_Argv (1));
|
|
|
|
if (Cmd_Argc () <= 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Team_BestWeaponImpulse (); // HACK HACK HACK
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
CL_BaseMove
|
|
|
|
|
|
|
|
Send the intended movement message to the server
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
CL_BaseMove (usercmd_t *cmd)
|
|
|
|
{
|
2021-03-19 16:48:26 +00:00
|
|
|
if (cls.state != ca_active) {
|
|
|
|
return;
|
|
|
|
}
|
2022-03-01 02:43:23 +00:00
|
|
|
VectorCopy (cl.viewstate.player_angles, cl.movestate.angles);//FIXME
|
2022-02-25 06:48:57 +00:00
|
|
|
CL_Input_BuildMove (host_frametime, &cl.movestate, &cl.viewstate);
|
2022-03-01 02:43:23 +00:00
|
|
|
VectorCopy (cl.movestate.angles, cl.viewstate.player_angles);//FIXME
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
memset (cmd, 0, sizeof (*cmd));
|
2022-02-22 06:23:09 +00:00
|
|
|
cmd->forwardmove = cl.movestate.move[FORWARD];
|
|
|
|
cmd->sidemove = cl.movestate.move[SIDE];
|
|
|
|
cmd->upmove = cl.movestate.move[UP];
|
|
|
|
VectorCopy (cl.movestate.angles, cmd->angles);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static int
|
2001-02-19 21:15:25 +00:00
|
|
|
MakeChar (int i)
|
|
|
|
{
|
|
|
|
i &= ~3;
|
|
|
|
if (i < -127 * 4)
|
|
|
|
i = -127 * 4;
|
|
|
|
if (i > 127 * 4)
|
|
|
|
i = 127 * 4;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-19 21:15:25 +00:00
|
|
|
CL_FinishMove (usercmd_t *cmd)
|
|
|
|
{
|
2004-02-02 21:18:11 +00:00
|
|
|
int ms, i;
|
|
|
|
static double accum = 0.0;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-28 23:05:45 +00:00
|
|
|
// always dump the first two message, because it may contain leftover
|
|
|
|
// inputs from the last level
|
2001-02-19 21:15:25 +00:00
|
|
|
if (++cl.movemessages <= 2)
|
|
|
|
return;
|
2001-05-14 03:08:24 +00:00
|
|
|
|
2001-08-28 23:05:45 +00:00
|
|
|
// figure button bits
|
[input] Rework logical buttons
kbutton_t is now in_button_t and has been moved to input.h. Also, a
button registration function has been added to take care of +button and
-button command creation and, eventually, direct binding of "physical"
buttons to logical buttons. "Physical" buttons are those coming in from
the OS (keyboard, mouse, joystick...), logical buttons are what the code
looks at for button state.
Additionally, the button edge detection code has been cleaned up such
that it no longer uses magic numbers, and the conversion to a float is
cleaner. Interestingly, I found that the handling is extremely
frame-rate dependent (eg, +forward will accelerate the player to full
speed much faster at 72fps than it does at 20fps). This may be a factor
in why gamers are frame rate obsessed: other games doing the same thing
would certainly feel different under varying frame rates.
2021-10-01 00:16:31 +00:00
|
|
|
cmd->buttons |= IN_ButtonPressed (&in_attack) << 0;
|
|
|
|
cmd->buttons |= IN_ButtonPressed (&in_jump) << 1;
|
|
|
|
cmd->buttons |= IN_ButtonPressed (&in_use) << 2;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// send milliseconds of time to apply the move
|
2004-02-02 21:18:11 +00:00
|
|
|
accum += (host_frametime * 1000.0);
|
|
|
|
ms = accum + 0.5;
|
|
|
|
accum -= ms;
|
|
|
|
|
|
|
|
if (ms > 250) {
|
2001-02-19 21:15:25 +00:00
|
|
|
ms = 100; // time was unreasonable
|
2004-02-02 21:18:11 +00:00
|
|
|
accum = 0.0;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
cmd->msec = ms;
|
|
|
|
|
2022-03-01 02:43:23 +00:00
|
|
|
VectorCopy (cl.viewstate.player_angles, cmd->angles);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
cmd->impulse = in_impulse;
|
|
|
|
in_impulse = 0;
|
|
|
|
|
2001-08-28 23:05:45 +00:00
|
|
|
// chop down so no extra bits are kept that the server wouldn't get
|
2001-02-19 21:15:25 +00:00
|
|
|
cmd->forwardmove = MakeChar (cmd->forwardmove);
|
|
|
|
cmd->sidemove = MakeChar (cmd->sidemove);
|
|
|
|
cmd->upmove = MakeChar (cmd->upmove);
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
2001-08-28 23:05:45 +00:00
|
|
|
cmd->angles[i] = ((int) (cmd->angles[i] * (65536.0 / 360.0)) & 65535) *
|
|
|
|
(360.0 / 65536.0);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2002-06-19 05:03:24 +00:00
|
|
|
static inline int
|
|
|
|
pps_check (int dontdrop)
|
|
|
|
{
|
|
|
|
static float pps_balance = 0.0;
|
|
|
|
static int dropcount = 0;
|
|
|
|
|
|
|
|
pps_balance += host_frametime;
|
|
|
|
// never drop more than 2 messages in a row -- that'll cause PL
|
|
|
|
// and don't drop if one of the last two movemessages have an impulse
|
|
|
|
if (pps_balance > 0.0 || dropcount >= 2 || dontdrop) {
|
|
|
|
float pps;
|
|
|
|
|
|
|
|
if (!(pps = cl_maxnetfps->int_val))
|
|
|
|
pps = rate->value / 80.0;
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2002-06-19 05:03:24 +00:00
|
|
|
pps = bound (1, pps, 72);
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2002-06-19 05:03:24 +00:00
|
|
|
pps_balance -= 1.0 / pps;
|
|
|
|
pps_balance = bound (-0.1, pps_balance, 0.1);
|
|
|
|
dropcount = 0;
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
int i;
|
|
|
|
// don't count this message when calculating PL
|
|
|
|
i = cls.netchan.outgoing_sequence & UPDATE_MASK;
|
|
|
|
cl.frames[i].receivedtime = -3;
|
|
|
|
// drop this message
|
|
|
|
cls.netchan.outgoing_sequence++;
|
|
|
|
dropcount++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-19 23:16:41 +00:00
|
|
|
static inline void
|
|
|
|
build_cmd (usercmd_t *cmd)
|
|
|
|
{
|
|
|
|
// get basic movement from keyboard, mouse, etc
|
|
|
|
CL_BaseMove (cmd);
|
|
|
|
|
|
|
|
// if we are spectator, try autocam
|
|
|
|
if (cl.spectator)
|
|
|
|
Cam_Track (cmd);
|
|
|
|
|
|
|
|
CL_FinishMove (cmd);
|
|
|
|
|
|
|
|
Cam_FinishMove (cmd);
|
|
|
|
}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
void
|
|
|
|
CL_SendCmd (void)
|
|
|
|
{
|
2001-12-03 09:01:17 +00:00
|
|
|
byte data[128];
|
2002-06-19 17:16:13 +00:00
|
|
|
int checksumIndex, lost, seq_hash, frame;
|
2001-12-03 09:01:17 +00:00
|
|
|
qboolean dontdrop; // FIXME: needed without cl_c2sImpulseBackup?
|
|
|
|
sizebuf_t buf;
|
|
|
|
usercmd_t *cmd, *oldcmd;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-10-02 21:56:45 +00:00
|
|
|
if (cls.demoplayback && !cls.demoplayback2)
|
2001-02-19 21:15:25 +00:00
|
|
|
return; // sendcmds come from the demo
|
|
|
|
|
|
|
|
// save this command off for prediction
|
2002-06-19 17:16:13 +00:00
|
|
|
frame = cls.netchan.outgoing_sequence & UPDATE_MASK;
|
|
|
|
cmd = &cl.frames[frame].cmd;
|
|
|
|
cl.frames[frame].senttime = realtime;
|
|
|
|
cl.frames[frame].receivedtime = -1; // we haven't gotten a reply yet
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-14 03:08:24 +00:00
|
|
|
// seq_hash = (cls.netchan.outgoing_sequence & 0xffff) ; // ^ QW_CHECK_HASH;
|
2001-02-19 21:15:25 +00:00
|
|
|
seq_hash = cls.netchan.outgoing_sequence;
|
|
|
|
|
2002-06-19 23:16:41 +00:00
|
|
|
build_cmd (cmd);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-10-02 21:56:45 +00:00
|
|
|
if (cls.demoplayback2) {
|
|
|
|
cls.netchan.outgoing_sequence++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-08-28 23:05:45 +00:00
|
|
|
// send this and the previous cmds in the message, so
|
|
|
|
// if the last packet was dropped, it can be recovered
|
2001-02-19 21:15:25 +00:00
|
|
|
buf.maxsize = 128;
|
|
|
|
buf.cursize = 0;
|
|
|
|
buf.data = data;
|
|
|
|
|
|
|
|
MSG_WriteByte (&buf, clc_move);
|
|
|
|
|
|
|
|
// save the position for a checksum byte
|
|
|
|
checksumIndex = buf.cursize;
|
|
|
|
MSG_WriteByte (&buf, 0);
|
|
|
|
|
|
|
|
// write our lossage percentage
|
|
|
|
lost = CL_CalcNet ();
|
|
|
|
MSG_WriteByte (&buf, (byte) lost);
|
|
|
|
|
2001-12-03 09:01:17 +00:00
|
|
|
dontdrop = false;
|
|
|
|
|
2002-06-19 17:16:13 +00:00
|
|
|
frame = (cls.netchan.outgoing_sequence - 2) & UPDATE_MASK;
|
|
|
|
cmd = &cl.frames[frame].cmd;
|
2001-12-03 09:01:17 +00:00
|
|
|
if (cl_spamimpulse->int_val >= 2)
|
|
|
|
dontdrop = dontdrop || cmd->impulse;
|
2001-02-19 21:15:25 +00:00
|
|
|
MSG_WriteDeltaUsercmd (&buf, &nullcmd, cmd);
|
|
|
|
oldcmd = cmd;
|
|
|
|
|
2002-06-19 17:16:13 +00:00
|
|
|
frame = (cls.netchan.outgoing_sequence - 1) & UPDATE_MASK;
|
|
|
|
cmd = &cl.frames[frame].cmd;
|
2001-12-03 09:01:17 +00:00
|
|
|
if (cl_spamimpulse->int_val >= 3)
|
|
|
|
dontdrop = dontdrop || cmd->impulse;
|
2001-02-19 21:15:25 +00:00
|
|
|
MSG_WriteDeltaUsercmd (&buf, oldcmd, cmd);
|
|
|
|
oldcmd = cmd;
|
|
|
|
|
2002-06-19 17:16:13 +00:00
|
|
|
frame = (cls.netchan.outgoing_sequence) & UPDATE_MASK;
|
|
|
|
cmd = &cl.frames[frame].cmd;
|
2001-12-03 09:01:17 +00:00
|
|
|
if (cl_spamimpulse->int_val >= 1)
|
|
|
|
dontdrop = dontdrop || cmd->impulse;
|
2001-02-19 21:15:25 +00:00
|
|
|
MSG_WriteDeltaUsercmd (&buf, oldcmd, cmd);
|
|
|
|
|
|
|
|
// calculate a checksum over the move commands
|
|
|
|
buf.data[checksumIndex] =
|
|
|
|
COM_BlockSequenceCRCByte (buf.data + checksumIndex + 1,
|
|
|
|
buf.cursize - checksumIndex - 1, seq_hash);
|
|
|
|
|
|
|
|
// request delta compression of entities
|
|
|
|
if (cls.netchan.outgoing_sequence - cl.validsequence >= UPDATE_BACKUP - 1)
|
|
|
|
cl.validsequence = 0;
|
|
|
|
|
2002-06-19 17:16:13 +00:00
|
|
|
if (cl.validsequence && !cl_nodelta->int_val && cls.state == ca_active
|
|
|
|
&& !cls.demorecording) {
|
|
|
|
cl.frames[frame].delta_sequence = cl.validsequence;
|
2001-02-19 21:15:25 +00:00
|
|
|
MSG_WriteByte (&buf, clc_delta);
|
|
|
|
MSG_WriteByte (&buf, cl.validsequence & 255);
|
2002-06-19 17:16:13 +00:00
|
|
|
} else {
|
|
|
|
cl.frames[frame].delta_sequence = -1;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (cls.demorecording)
|
|
|
|
CL_WriteDemoCmd (cmd);
|
|
|
|
|
2001-08-28 23:05:45 +00:00
|
|
|
// deliver the message
|
2002-06-19 05:03:24 +00:00
|
|
|
if (pps_check (dontdrop))
|
|
|
|
Netchan_Transmit (&cls.netchan, buf.cursize, buf.data);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-02-22 06:23:09 +00:00
|
|
|
CL_Init_Input (cbuf_t *cbuf)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2022-02-22 06:23:09 +00:00
|
|
|
CL_Input_Init (cbuf);
|
2021-03-19 18:56:16 +00:00
|
|
|
Cmd_AddDataCommand ("impulse", IN_Impulse, 0,
|
|
|
|
"Call a game function or QuakeC function.");
|
2021-11-11 15:24:04 +00:00
|
|
|
}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
void
|
2022-02-22 06:23:09 +00:00
|
|
|
CL_Init_Input_Cvars (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2022-02-22 06:23:09 +00:00
|
|
|
CL_Input_Init_Cvars ();
|
2001-04-10 23:39:30 +00:00
|
|
|
cl_nodelta = Cvar_Get ("cl_nodelta", "0", CVAR_NONE, NULL,
|
2001-05-14 03:08:24 +00:00
|
|
|
"Disable player delta compression. Set to 1 if you "
|
|
|
|
"have a poor ISP and get many U_REMOVE warnings.");
|
2001-12-03 09:01:17 +00:00
|
|
|
cl_maxnetfps = Cvar_Get ("cl_maxnetfps", "0", CVAR_ARCHIVE, NULL,
|
|
|
|
"Controls number of command packets sent per "
|
|
|
|
"second. Default 0 is unlimited.");
|
|
|
|
cl_spamimpulse = Cvar_Get ("cl_spamimpulse", "3", CVAR_NONE, NULL,
|
|
|
|
"Controls number of duplicate packets sent if "
|
|
|
|
"an impulse is being sent. Default (id "
|
|
|
|
"behavior) is 3.");
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|