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"
|
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"
|
|
|
|
#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
|
|
|
|
2001-08-28 23:05:45 +00:00
|
|
|
#include "compat.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/chase.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
|
|
|
|
|
|
|
/*
|
|
|
|
KEY BUTTONS
|
|
|
|
|
|
|
|
Continuous button event tracking is complicated by the fact that two
|
|
|
|
different input sources (say, mouse button 1 and the control key) can
|
2010-01-13 06:42:26 +00:00
|
|
|
both press the same button, but the button should be released only when
|
2001-02-19 21:15:25 +00:00
|
|
|
both of the pressing key have been released.
|
|
|
|
|
|
|
|
When a key event issues a button command (+forward, +attack, etc), it
|
|
|
|
appends its key number as a parameter to the command so it can be
|
|
|
|
matched up with the release.
|
|
|
|
|
|
|
|
state bit 0 is the current state of the key
|
|
|
|
state bit 1 is edge triggered on the up to down transition
|
|
|
|
state bit 2 is edge triggered on the down to up transition
|
|
|
|
*/
|
|
|
|
|
[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
|
|
|
in_button_t in_left, in_right, in_forward, in_back;
|
|
|
|
in_button_t in_lookup, in_lookdown, in_moveleft, in_moveright;
|
|
|
|
in_button_t in_use, in_jump, in_attack;
|
|
|
|
in_button_t in_up, in_down;
|
|
|
|
in_button_t in_strafe, in_klook, in_speed, in_mlook;
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
const char *name;
|
|
|
|
in_button_t *button;
|
|
|
|
const char *description;
|
|
|
|
} cl_in_buttons[] = {
|
|
|
|
{ "left", &in_left,
|
|
|
|
"When active the player is turning left"
|
|
|
|
},
|
|
|
|
{ "right", &in_right,
|
|
|
|
"When active the player is turning right"
|
|
|
|
},
|
|
|
|
{ "forward", &in_forward,
|
|
|
|
"When active the player is moving forward"
|
|
|
|
},
|
|
|
|
{ "back", &in_back,
|
|
|
|
"When active the player is moving backwards"
|
|
|
|
},
|
|
|
|
{ "lookup", &in_lookup,
|
|
|
|
"When active the player's view is looking up"
|
|
|
|
},
|
|
|
|
{ "lookdown", &in_lookdown,
|
|
|
|
"When active the player's view is looking down"
|
|
|
|
},
|
|
|
|
{ "moveleft", &in_moveleft,
|
|
|
|
"When active the player is strafing left"
|
|
|
|
},
|
|
|
|
{ "moveright", &in_moveright,
|
|
|
|
"When active the player is strafing right"
|
|
|
|
},
|
|
|
|
{ "use", &in_use,
|
|
|
|
"Left over command for opening doors and triggering switches"
|
|
|
|
},
|
|
|
|
{ "jump", &in_jump,
|
|
|
|
"When active the player is jumping"
|
|
|
|
},
|
|
|
|
{ "attack", &in_attack,
|
|
|
|
"When active player is firing/using current weapon"
|
|
|
|
},
|
|
|
|
{ "moveup", &in_up,
|
|
|
|
"When active the player is swimming up in a liquid"
|
|
|
|
},
|
|
|
|
{ "movedown", &in_down,
|
|
|
|
"When active the player is swimming down in a liquid"
|
|
|
|
},
|
|
|
|
{ "strafe", &in_strafe,
|
|
|
|
"When active, +left and +right function like +moveleft and +moveright"
|
|
|
|
},
|
|
|
|
{ "speed", &in_speed,
|
|
|
|
"When active the player is running"
|
|
|
|
},
|
|
|
|
{ "klook", &in_klook,
|
|
|
|
"When active, +forward and +back perform +lookup and +lookdown"
|
|
|
|
},
|
|
|
|
{ "mlook", &in_mlook,
|
|
|
|
"When active moving the mouse or joystick forwards "
|
|
|
|
"and backwards performs +lookup and "
|
|
|
|
"+lookdown"
|
|
|
|
},
|
|
|
|
{ }
|
|
|
|
};
|
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
|
|
|
|
}
|
|
|
|
|
2001-05-14 03:08:24 +00:00
|
|
|
cvar_t *cl_anglespeedkey;
|
2001-02-19 21:15:25 +00:00
|
|
|
cvar_t *cl_backspeed;
|
2001-05-14 03:08:24 +00:00
|
|
|
cvar_t *cl_forwardspeed;
|
2001-02-19 21:15:25 +00:00
|
|
|
cvar_t *cl_movespeedkey;
|
|
|
|
cvar_t *cl_pitchspeed;
|
2001-05-14 03:08:24 +00:00
|
|
|
cvar_t *cl_sidespeed;
|
|
|
|
cvar_t *cl_upspeed;
|
|
|
|
cvar_t *cl_yawspeed;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
CL_AdjustAngles
|
|
|
|
|
|
|
|
Moves the local angle positions
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-19 21:15:25 +00:00
|
|
|
CL_AdjustAngles (void)
|
|
|
|
{
|
2004-07-11 01:41:01 +00:00
|
|
|
float down, up;
|
|
|
|
float pitchspeed, yawspeed;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-07-11 01:41:01 +00:00
|
|
|
pitchspeed = cl_pitchspeed->value;
|
|
|
|
yawspeed = cl_yawspeed->value;
|
|
|
|
|
[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
|
|
|
if (in_speed.state & inb_down) {
|
2004-07-11 01:41:01 +00:00
|
|
|
pitchspeed *= cl_anglespeedkey->value;
|
|
|
|
yawspeed *= cl_anglespeedkey->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((cl.fpd & FPD_LIMIT_PITCH) && pitchspeed > FPD_MAXPITCH)
|
|
|
|
pitchspeed = FPD_MAXPITCH;
|
2011-06-19 00:49:39 +00:00
|
|
|
if ((cl.fpd & FPD_LIMIT_YAW) && yawspeed > FPD_MAXYAW)
|
|
|
|
yawspeed = FPD_MAXYAW;
|
|
|
|
|
|
|
|
pitchspeed *= host_frametime;
|
|
|
|
yawspeed *= host_frametime;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
[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
|
|
|
if (!(in_strafe.state & inb_down)) {
|
|
|
|
cl.viewstate.angles[YAW] -= yawspeed * IN_ButtonState (&in_right);
|
|
|
|
cl.viewstate.angles[YAW] += yawspeed * IN_ButtonState (&in_left);
|
2021-03-19 16:48:26 +00:00
|
|
|
cl.viewstate.angles[YAW] = anglemod (cl.viewstate.angles[YAW]);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
[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
|
|
|
if (in_klook.state & inb_down) {
|
2001-02-19 21:15:25 +00:00
|
|
|
V_StopPitchDrift ();
|
[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
|
|
|
cl.viewstate.angles[PITCH] -= pitchspeed * IN_ButtonState (&in_forward);
|
|
|
|
cl.viewstate.angles[PITCH] += pitchspeed * IN_ButtonState (&in_back);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
[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
|
|
|
up = IN_ButtonState (&in_lookup);
|
|
|
|
down = IN_ButtonState (&in_lookdown);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-03-19 16:48:26 +00:00
|
|
|
cl.viewstate.angles[PITCH] -= pitchspeed * up;
|
|
|
|
cl.viewstate.angles[PITCH] += pitchspeed * down;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (up || down)
|
|
|
|
V_StopPitchDrift ();
|
|
|
|
|
2002-07-02 18:35:36 +00:00
|
|
|
// FIXME: Need to clean up view angle limits
|
2021-03-19 16:48:26 +00:00
|
|
|
if (cl.viewstate.angles[PITCH] > 80)
|
|
|
|
cl.viewstate.angles[PITCH] = 80;
|
|
|
|
if (cl.viewstate.angles[PITCH] < -70)
|
|
|
|
cl.viewstate.angles[PITCH] = -70;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-03-19 16:48:26 +00:00
|
|
|
if (cl.viewstate.angles[ROLL] > 50)
|
|
|
|
cl.viewstate.angles[ROLL] = 50;
|
|
|
|
if (cl.viewstate.angles[ROLL] < -50)
|
|
|
|
cl.viewstate.angles[ROLL] = -50;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
CL_BaseMove
|
|
|
|
|
|
|
|
Send the intended movement message to the server
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
CL_BaseMove (usercmd_t *cmd)
|
|
|
|
{
|
[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
|
|
|
if (IN_ButtonReleased (&in_mlook) && !freelook && lookspring->int_val) {
|
|
|
|
V_StartPitchDrift ();
|
|
|
|
}
|
|
|
|
|
2021-03-19 16:48:26 +00:00
|
|
|
if (cls.state != ca_active) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
CL_AdjustAngles ();
|
|
|
|
|
|
|
|
memset (cmd, 0, sizeof (*cmd));
|
|
|
|
|
2021-03-19 16:48:26 +00:00
|
|
|
VectorCopy (cl.viewstate.angles, cmd->angles);
|
[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
|
|
|
if (in_strafe.state & inb_down) {
|
|
|
|
cmd->sidemove += cl_sidespeed->value * IN_ButtonState (&in_right);
|
|
|
|
cmd->sidemove -= cl_sidespeed->value * IN_ButtonState (&in_left);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
[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->sidemove += cl_sidespeed->value * IN_ButtonState (&in_moveright);
|
|
|
|
cmd->sidemove -= cl_sidespeed->value * IN_ButtonState (&in_moveleft);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
[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->upmove += cl_upspeed->value * IN_ButtonState (&in_up);
|
|
|
|
cmd->upmove -= cl_upspeed->value * IN_ButtonState (&in_down);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
[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
|
|
|
if (!(in_klook.state & inb_down)) {
|
|
|
|
cmd->forwardmove += cl_forwardspeed->value * IN_ButtonState (&in_forward);
|
|
|
|
cmd->forwardmove -= cl_backspeed->value * IN_ButtonState (&in_back);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-05-14 03:08:24 +00:00
|
|
|
|
2001-08-28 23:05:45 +00:00
|
|
|
// adjust for speed key
|
[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
|
|
|
if (in_speed.state & inb_down) {
|
2001-02-19 21:15:25 +00:00
|
|
|
cmd->forwardmove *= cl_movespeedkey->value;
|
|
|
|
cmd->sidemove *= cl_movespeedkey->value;
|
|
|
|
cmd->upmove *= cl_movespeedkey->value;
|
|
|
|
}
|
2001-04-11 07:57:08 +00:00
|
|
|
|
|
|
|
if (freelook)
|
|
|
|
V_StopPitchDrift ();
|
|
|
|
|
|
|
|
viewdelta.angles[0] = viewdelta.angles[1] = viewdelta.angles[2] = 0;
|
|
|
|
viewdelta.position[0] = viewdelta.position[1] = viewdelta.position[2] = 0;
|
|
|
|
|
|
|
|
IN_Move ();
|
|
|
|
|
2002-07-02 18:35:36 +00:00
|
|
|
// adjust for chase camera angles
|
2021-03-19 11:18:45 +00:00
|
|
|
/*FIXME:chase figure out just what this does and get it working
|
2011-06-19 00:49:39 +00:00
|
|
|
if (cl.chase
|
|
|
|
&& (chase_active->int_val == 2 || chase_active->int_val == 3)) {
|
|
|
|
vec3_t forward, right, up, f, r;
|
|
|
|
vec3_t dir = {0, 0, 0};
|
|
|
|
|
2021-03-19 16:48:26 +00:00
|
|
|
dir[1] = r_data->refdef->viewangles[1] - cl.viewstate.angles[1];
|
2001-09-28 07:51:15 +00:00
|
|
|
AngleVectors (dir, forward, right, up);
|
2001-12-11 20:49:10 +00:00
|
|
|
VectorScale (forward, cmd->forwardmove, f);
|
2011-06-19 00:49:39 +00:00
|
|
|
VectorScale (right, cmd->sidemove, r);
|
2001-12-11 20:49:10 +00:00
|
|
|
cmd->forwardmove = f[0] + r[0];
|
2011-06-19 00:49:39 +00:00
|
|
|
cmd->sidemove = f[1] + r[1];
|
2001-12-11 20:49:10 +00:00
|
|
|
VectorScale (forward, viewdelta.position[2], f);
|
2011-06-19 00:49:39 +00:00
|
|
|
VectorScale (right, viewdelta.position[0], r);
|
|
|
|
viewdelta.position[2] = f[0] + r[0];
|
2001-12-11 20:49:10 +00:00
|
|
|
viewdelta.position[0] = (f[1] + r[1]) * -1;
|
2001-09-28 07:51:15 +00:00
|
|
|
}
|
2021-03-19 11:18:45 +00:00
|
|
|
*/
|
2001-09-28 07:51:15 +00:00
|
|
|
|
2001-04-11 07:57:08 +00:00
|
|
|
cmd->forwardmove += viewdelta.position[2] * m_forward->value;
|
|
|
|
cmd->sidemove += viewdelta.position[0] * m_side->value;
|
|
|
|
cmd->upmove += viewdelta.position[1];
|
2021-03-19 16:48:26 +00:00
|
|
|
cl.viewstate.angles[PITCH] += viewdelta.angles[PITCH] * m_pitch->value;
|
|
|
|
cl.viewstate.angles[YAW] += viewdelta.angles[YAW] * m_yaw->value;
|
|
|
|
cl.viewstate.angles[ROLL] += viewdelta.angles[ROLL];
|
2001-04-11 07:57:08 +00:00
|
|
|
|
[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
|
|
|
if (freelook && !(in_strafe.state & inb_down)) {
|
2021-03-19 16:48:26 +00:00
|
|
|
cl.viewstate.angles[PITCH]
|
|
|
|
= bound (-70, cl.viewstate.angles[PITCH], 80);
|
2001-04-11 07:57:08 +00:00
|
|
|
}
|
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;
|
|
|
|
|
2021-03-19 16:48:26 +00:00
|
|
|
VectorCopy (cl.viewstate.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
|
|
|
|
CL_Input_Init (void)
|
|
|
|
{
|
[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
|
|
|
for (int i = 0; cl_in_buttons[i].name; i++) {
|
|
|
|
IN_RegisterButton (cl_in_buttons[i].button, cl_in_buttons[i].name,
|
|
|
|
cl_in_buttons[i].description);
|
|
|
|
}
|
2021-03-19 18:56:16 +00:00
|
|
|
Cmd_AddDataCommand ("impulse", IN_Impulse, 0,
|
|
|
|
"Call a game function or QuakeC function.");
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CL_Input_Init_Cvars (void)
|
|
|
|
{
|
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
|
|
|
}
|