2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
cl_input.c
|
|
|
|
|
2001-07-15 00:03:11 +00:00
|
|
|
builds an intended movement command to send to the server
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2005-08-04 15:27:09 +00:00
|
|
|
static __attribute__ ((used)) const char rcsid[] =
|
2003-01-15 15:31:36 +00:00
|
|
|
"$Id$";
|
|
|
|
|
2001-05-09 05:41:34 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/cmd.h"
|
2001-05-31 03:41:35 +00:00
|
|
|
#include "QF/cvar.h"
|
2001-04-11 07:57:08 +00:00
|
|
|
#include "QF/input.h"
|
2001-05-09 05:41:34 +00:00
|
|
|
#include "QF/keys.h"
|
|
|
|
#include "QF/msg.h"
|
2007-11-06 10:17:14 +00:00
|
|
|
#include "QF/sys.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "QF/plugin/vid_render.h"
|
|
|
|
|
2001-10-28 04:23:37 +00:00
|
|
|
#include "chase.h"
|
2001-04-15 21:11:41 +00:00
|
|
|
#include "client.h"
|
2001-08-29 02:12:57 +00:00
|
|
|
#include "compat.h"
|
2001-05-09 05:41:34 +00:00
|
|
|
#include "host.h"
|
2001-04-15 21:11:41 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
/*
|
2001-07-15 00:03:11 +00:00
|
|
|
KEY BUTTONS
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-07-15 00:03:11 +00:00
|
|
|
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-07-15 00:03:11 +00:00
|
|
|
both of the pressing key have been released.
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-07-15 00:03:11 +00:00
|
|
|
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.
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-07-15 00:03:11 +00:00
|
|
|
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
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
kbutton_t in_left, in_right, in_forward, in_back;
|
|
|
|
kbutton_t in_lookup, in_lookdown, in_moveleft, in_moveright;
|
2001-10-23 16:55:23 +00:00
|
|
|
kbutton_t in_use, in_jump, in_attack;
|
2001-02-26 06:48:02 +00:00
|
|
|
kbutton_t in_up, in_down;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int in_impulse;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2010-08-24 00:53:54 +00:00
|
|
|
void (*write_angles) (sizebuf_t *sb, const vec3_t angles);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyPress (kbutton_t *b)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-07-15 07:04:17 +00:00
|
|
|
const char *c;
|
2001-08-29 02:12:57 +00:00
|
|
|
int k;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
c = Cmd_Argv (1);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (c[0])
|
2001-02-26 06:48:02 +00:00
|
|
|
k = atoi (c);
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2001-02-26 06:48:02 +00:00
|
|
|
k = -1; // typed manually at the console for
|
2001-07-15 00:03:11 +00:00
|
|
|
// continuous down
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (k == b->down[0] || k == b->down[1])
|
2001-02-26 06:48:02 +00:00
|
|
|
return; // repeating key
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!b->down[0])
|
|
|
|
b->down[0] = k;
|
|
|
|
else if (!b->down[1])
|
|
|
|
b->down[1] = k;
|
2001-02-26 06:48:02 +00:00
|
|
|
else {
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("Three keys down for a button!\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (b->state & 1)
|
2001-02-26 06:48:02 +00:00
|
|
|
return; // still down
|
|
|
|
b->state |= 1 + 2; // down + impulse down
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyRelease (kbutton_t *b)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-07-15 07:04:17 +00:00
|
|
|
const char *c;
|
2001-08-29 02:12:57 +00:00
|
|
|
int k;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
c = Cmd_Argv (1);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (c[0])
|
2001-02-26 06:48:02 +00:00
|
|
|
k = atoi (c);
|
|
|
|
else { // typed manually at the console,
|
2001-07-15 00:03:11 +00:00
|
|
|
// assume for unsticking, so clear
|
|
|
|
// all
|
2001-02-19 21:15:25 +00:00
|
|
|
b->down[0] = b->down[1] = 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
b->state = 4; // impulse up
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (b->down[0] == k)
|
|
|
|
b->down[0] = 0;
|
|
|
|
else if (b->down[1] == k)
|
|
|
|
b->down[1] = 0;
|
|
|
|
else
|
2001-02-26 06:48:02 +00:00
|
|
|
return; // key up without coresponding down
|
2001-07-15 00:03:11 +00:00
|
|
|
// (menu pass through)
|
2001-02-19 21:15:25 +00:00
|
|
|
if (b->down[0] || b->down[1])
|
2001-02-26 06:48:02 +00:00
|
|
|
return; // some other key is still holding it
|
2001-07-15 00:03:11 +00:00
|
|
|
// down
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!(b->state & 1))
|
2001-02-26 06:48:02 +00:00
|
|
|
return; // still up (this should not happen)
|
|
|
|
b->state &= ~1; // now up
|
|
|
|
b->state |= 4; // impulse up
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_KLookPress (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyPress (&in_klook);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_KLookRelease (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyRelease (&in_klook);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_MLookPress (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyPress (&in_mlook);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_MLookRelease (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyRelease (&in_mlook);
|
2011-06-19 00:49:39 +00:00
|
|
|
if (!freelook && lookspring->int_val)
|
2001-02-26 06:48:02 +00:00
|
|
|
V_StartPitchDrift ();
|
|
|
|
}
|
2001-05-09 05:41:34 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_UpPress (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyPress (&in_up);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_UpRelease (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyRelease (&in_up);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_DownPress (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyPress (&in_down);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_DownRelease (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyRelease (&in_down);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_LeftPress (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyPress (&in_left);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_LeftRelease (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyRelease (&in_left);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_RightPress (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyPress (&in_right);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_RightRelease (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyRelease (&in_right);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_ForwardPress (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyPress (&in_forward);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_ForwardRelease (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyRelease (&in_forward);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_BackPress (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyPress (&in_back);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_BackRelease (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyRelease (&in_back);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_LookupPress (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyPress (&in_lookup);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_LookupRelease (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyRelease (&in_lookup);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_LookdownPress (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyPress (&in_lookdown);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_LookdownRelease (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyRelease (&in_lookdown);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_MoveleftPress (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyPress (&in_moveleft);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_MoveleftRelease (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyRelease (&in_moveleft);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_MoverightPress (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyPress (&in_moveright);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_MoverightRelease (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyRelease (&in_moveright);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_SpeedPress (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyPress (&in_speed);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_SpeedRelease (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyRelease (&in_speed);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_StrafePress (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyPress (&in_strafe);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_StrafeRelease (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyRelease (&in_strafe);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_AttackPress (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyPress (&in_attack);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_AttackRelease (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyRelease (&in_attack);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_UsePress (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyPress (&in_use);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_UseRelease (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyRelease (&in_use);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_JumpPress (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyPress (&in_jump);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2004-02-03 05:16:22 +00:00
|
|
|
IN_JumpRelease (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
KeyRelease (&in_jump);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
IN_Impulse (void)
|
|
|
|
{
|
|
|
|
in_impulse = atoi (Cmd_Argv (1));
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/*
|
2001-05-14 03:08:24 +00:00
|
|
|
CL_KeyState
|
|
|
|
|
|
|
|
Returns 0.25 if a key was pressed and released during the frame,
|
|
|
|
0.5 if it was pressed and held
|
|
|
|
0 if held then released, and
|
|
|
|
1.0 if held for the entire time
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
float
|
|
|
|
CL_KeyState (kbutton_t *key)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
float val;
|
|
|
|
qboolean impulsedown, impulseup, down;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
impulsedown = key->state & 2;
|
|
|
|
impulseup = key->state & 4;
|
|
|
|
down = key->state & 1;
|
|
|
|
val = 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (impulsedown && !impulseup) {
|
|
|
|
if (down)
|
2001-02-26 06:48:02 +00:00
|
|
|
val = 0.5; // pressed and held this frame
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2001-02-26 06:48:02 +00:00
|
|
|
val = 0; // I_Error ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
if (impulseup && !impulsedown) {
|
|
|
|
if (down)
|
2001-02-26 06:48:02 +00:00
|
|
|
val = 0; // I_Error ();
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2001-02-26 06:48:02 +00:00
|
|
|
val = 0; // released this frame
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
if (!impulsedown && !impulseup) {
|
|
|
|
if (down)
|
2001-02-26 06:48:02 +00:00
|
|
|
val = 1.0; // held the entire frame
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2001-02-26 06:48:02 +00:00
|
|
|
val = 0; // up the entire frame
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
if (impulsedown && impulseup) {
|
|
|
|
if (down)
|
2001-02-26 06:48:02 +00:00
|
|
|
val = 0.75; // released and re-pressed this frame
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2001-02-26 06:48:02 +00:00
|
|
|
val = 0.25; // pressed and released this frame
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
key->state &= 1; // clear impulses
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2001-05-14 03:08:24 +00:00
|
|
|
cvar_t *cl_anglespeedkey;
|
2001-02-26 06:48:02 +00:00
|
|
|
cvar_t *cl_backspeed;
|
2001-05-14 03:08:24 +00:00
|
|
|
cvar_t *cl_forwardspeed;
|
2001-02-26 06:48:02 +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
|
|
|
|
|
|
|
/*
|
2001-05-14 03:08:24 +00:00
|
|
|
CL_AdjustAngles
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-14 03:08:24 +00:00
|
|
|
Moves the local angle positions
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
CL_AdjustAngles (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2011-06-19 00:49:39 +00:00
|
|
|
float down, up;
|
|
|
|
float pitchspeed, yawspeed;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2011-06-19 00:49:39 +00:00
|
|
|
pitchspeed = cl_pitchspeed->value;
|
|
|
|
yawspeed = cl_yawspeed->value;
|
|
|
|
|
|
|
|
if (in_speed.state & 1) {
|
|
|
|
pitchspeed *= cl_anglespeedkey->value;
|
|
|
|
yawspeed *= cl_anglespeedkey->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((cl.fpd & FPD_LIMIT_PITCH) && pitchspeed > FPD_MAXPITCH)
|
|
|
|
pitchspeed = FPD_MAXPITCH;
|
|
|
|
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
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!(in_strafe.state & 1)) {
|
2011-06-19 00:49:39 +00:00
|
|
|
cl.viewangles[YAW] -= yawspeed * CL_KeyState (&in_right);
|
|
|
|
cl.viewangles[YAW] += yawspeed * CL_KeyState (&in_left);
|
2001-02-26 06:48:02 +00:00
|
|
|
cl.viewangles[YAW] = anglemod (cl.viewangles[YAW]);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
if (in_klook.state & 1) {
|
2001-02-19 21:15:25 +00:00
|
|
|
V_StopPitchDrift ();
|
2011-06-19 00:49:39 +00:00
|
|
|
cl.viewangles[PITCH] -= pitchspeed * CL_KeyState (&in_forward);
|
|
|
|
cl.viewangles[PITCH] += pitchspeed * CL_KeyState (&in_back);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
up = CL_KeyState (&in_lookup);
|
2001-02-26 06:48:02 +00:00
|
|
|
down = CL_KeyState (&in_lookdown);
|
|
|
|
|
2011-06-19 00:49:39 +00:00
|
|
|
cl.viewangles[PITCH] -= pitchspeed * up;
|
|
|
|
cl.viewangles[PITCH] += pitchspeed * down;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (up || down)
|
|
|
|
V_StopPitchDrift ();
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2011-06-19 00:49:39 +00:00
|
|
|
// FIXME: Need to clean up view angle limits
|
2001-02-19 21:15:25 +00:00
|
|
|
if (cl.viewangles[PITCH] > 80)
|
|
|
|
cl.viewangles[PITCH] = 80;
|
|
|
|
if (cl.viewangles[PITCH] < -70)
|
|
|
|
cl.viewangles[PITCH] = -70;
|
|
|
|
|
|
|
|
if (cl.viewangles[ROLL] > 50)
|
|
|
|
cl.viewangles[ROLL] = 50;
|
|
|
|
if (cl.viewangles[ROLL] < -50)
|
|
|
|
cl.viewangles[ROLL] = -50;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-05-14 03:08:24 +00:00
|
|
|
CL_BaseMove
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-14 03:08:24 +00:00
|
|
|
Send the intended movement message to the server
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
CL_BaseMove (usercmd_t *cmd)
|
|
|
|
{
|
2001-02-19 21:15:25 +00:00
|
|
|
if (cls.signon != SIGNONS)
|
|
|
|
return;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
CL_AdjustAngles ();
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
memset (cmd, 0, sizeof (*cmd));
|
|
|
|
|
|
|
|
if (in_strafe.state & 1) {
|
2001-02-19 21:15:25 +00:00
|
|
|
cmd->sidemove += cl_sidespeed->value * CL_KeyState (&in_right);
|
|
|
|
cmd->sidemove -= cl_sidespeed->value * CL_KeyState (&in_left);
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd->sidemove += cl_sidespeed->value * CL_KeyState (&in_moveright);
|
|
|
|
cmd->sidemove -= cl_sidespeed->value * CL_KeyState (&in_moveleft);
|
|
|
|
|
|
|
|
cmd->upmove += cl_upspeed->value * CL_KeyState (&in_up);
|
|
|
|
cmd->upmove -= cl_upspeed->value * CL_KeyState (&in_down);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!(in_klook.state & 1)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
cmd->forwardmove += cl_forwardspeed->value * CL_KeyState (&in_forward);
|
|
|
|
cmd->forwardmove -= cl_backspeed->value * CL_KeyState (&in_back);
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
2001-05-14 03:08:24 +00:00
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
// adjust for speed key
|
2001-02-26 06:48:02 +00:00
|
|
|
if (in_speed.state & 1) {
|
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 ();
|
|
|
|
|
2001-09-28 07:51:15 +00:00
|
|
|
// adjust for chase camera angles
|
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};
|
2004-02-03 05:16:22 +00:00
|
|
|
|
2012-02-14 08:28:09 +00:00
|
|
|
dir[1] = r_data->refdef->viewangles[1] - cl.viewangles[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);
|
2004-02-03 05:16:22 +00:00
|
|
|
VectorScale (right, cmd->sidemove, r);
|
2001-12-11 20:49:10 +00:00
|
|
|
cmd->forwardmove = f[0] + r[0];
|
2004-02-03 05:16:22 +00:00
|
|
|
cmd->sidemove = f[1] + r[1];
|
2001-12-11 20:49:10 +00:00
|
|
|
VectorScale (forward, viewdelta.position[2], f);
|
2004-02-03 05:16:22 +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
|
|
|
}
|
|
|
|
|
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];
|
|
|
|
cl.viewangles[PITCH] += viewdelta.angles[PITCH] * m_pitch->value;
|
|
|
|
cl.viewangles[YAW] += viewdelta.angles[YAW] * m_yaw->value;
|
|
|
|
cl.viewangles[ROLL] += viewdelta.angles[ROLL];
|
|
|
|
|
|
|
|
if (freelook && !(in_strafe.state & 1)) {
|
|
|
|
cl.viewangles[PITCH] = bound (-70, cl.viewangles[PITCH], 80);
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
CL_SendMove (usercmd_t *cmd)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
byte data[128];
|
2001-12-12 21:56:09 +00:00
|
|
|
int bits;
|
2001-08-29 02:12:57 +00:00
|
|
|
sizebuf_t buf;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
buf.maxsize = 128;
|
|
|
|
buf.cursize = 0;
|
|
|
|
buf.data = data;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
cl.cmd = *cmd;
|
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
// send the movement message
|
2001-02-26 06:48:02 +00:00
|
|
|
MSG_WriteByte (&buf, clc_move);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-02-03 05:16:22 +00:00
|
|
|
MSG_WriteFloat (&buf, cl.mtime[0]); // so server can get ping times
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2010-08-24 00:53:54 +00:00
|
|
|
write_angles (&buf, cl.viewangles);
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
MSG_WriteShort (&buf, cmd->forwardmove);
|
|
|
|
MSG_WriteShort (&buf, cmd->sidemove);
|
|
|
|
MSG_WriteShort (&buf, cmd->upmove);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
// send button bits
|
2001-02-19 21:15:25 +00:00
|
|
|
bits = 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
if (in_attack.state & 3)
|
2001-02-19 21:15:25 +00:00
|
|
|
bits |= 1;
|
|
|
|
in_attack.state &= ~2;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (in_jump.state & 3)
|
|
|
|
bits |= 2;
|
|
|
|
in_jump.state &= ~2;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
MSG_WriteByte (&buf, bits);
|
|
|
|
|
|
|
|
MSG_WriteByte (&buf, in_impulse);
|
2001-02-19 21:15:25 +00:00
|
|
|
in_impulse = 0;
|
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
// deliver the message
|
2001-02-19 21:15:25 +00:00
|
|
|
if (cls.demoplayback)
|
|
|
|
return;
|
|
|
|
|
2001-08-29 02:12:57 +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-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
if (NET_SendUnreliableMessage (cls.netcon, &buf) == -1) {
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("CL_SendMove: lost server connection\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
CL_Disconnect ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
2011-06-19 00:49:39 +00:00
|
|
|
CL_Input_Init (void)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
2004-02-03 05:16:22 +00:00
|
|
|
Cmd_AddCommand ("+moveup", IN_UpPress, "When active the player is "
|
2001-07-15 00:03:11 +00:00
|
|
|
"swimming up in a liquid");
|
2004-02-03 05:16:22 +00:00
|
|
|
Cmd_AddCommand ("-moveup", IN_UpRelease, "When active the player is not "
|
|
|
|
"swimming up in a liquid");
|
|
|
|
Cmd_AddCommand ("+movedown", IN_DownPress, "When active the player is "
|
2001-07-15 00:03:11 +00:00
|
|
|
"swimming down in a liquid");
|
2004-02-03 05:16:22 +00:00
|
|
|
Cmd_AddCommand ("-movedown", IN_DownRelease, "When active the player is "
|
|
|
|
"not swimming down in a liquid");
|
|
|
|
Cmd_AddCommand ("+left", IN_LeftPress, "When active the player is turning "
|
2001-07-15 00:03:11 +00:00
|
|
|
"left");
|
2004-02-03 05:16:22 +00:00
|
|
|
Cmd_AddCommand ("-left", IN_LeftRelease, "When active the player is not "
|
|
|
|
"turning left");
|
|
|
|
Cmd_AddCommand ("+right", IN_RightPress, "When active the player is "
|
2001-07-15 00:03:11 +00:00
|
|
|
"turning right");
|
2004-02-03 05:16:22 +00:00
|
|
|
Cmd_AddCommand ("-right", IN_RightRelease, "When active the player is not "
|
2001-07-15 00:03:11 +00:00
|
|
|
"turning right");
|
2004-02-03 05:16:22 +00:00
|
|
|
Cmd_AddCommand ("+forward", IN_ForwardPress, "When active the player is "
|
2001-07-15 00:03:11 +00:00
|
|
|
"moving forward");
|
2004-02-03 05:16:22 +00:00
|
|
|
Cmd_AddCommand ("-forward", IN_ForwardRelease, "When active the player is "
|
|
|
|
"not moving forward");
|
|
|
|
Cmd_AddCommand ("+back", IN_BackPress, "When active the player is moving "
|
2001-07-15 00:03:11 +00:00
|
|
|
"backwards");
|
2004-02-03 05:16:22 +00:00
|
|
|
Cmd_AddCommand ("-back", IN_BackRelease, "When active the player is not "
|
2001-07-15 00:03:11 +00:00
|
|
|
"moving backwards");
|
2004-02-03 05:16:22 +00:00
|
|
|
Cmd_AddCommand ("+lookup", IN_LookupPress, "When active the player's view "
|
2001-07-15 00:03:11 +00:00
|
|
|
"is looking up");
|
2004-02-03 05:16:22 +00:00
|
|
|
Cmd_AddCommand ("-lookup", IN_LookupRelease, "When active the player's "
|
2001-07-15 00:03:11 +00:00
|
|
|
"view is not looking up");
|
2004-02-03 05:16:22 +00:00
|
|
|
Cmd_AddCommand ("+lookdown", IN_LookdownPress, "When active the player's "
|
|
|
|
"view is looking down");
|
|
|
|
Cmd_AddCommand ("-lookdown", IN_LookdownRelease, "When active the "
|
|
|
|
"player's view is not looking up");
|
|
|
|
Cmd_AddCommand ("+strafe", IN_StrafePress, "When active, +left and +right "
|
2001-07-15 00:03:11 +00:00
|
|
|
"function like +moveleft and +moveright");
|
2004-02-03 05:16:22 +00:00
|
|
|
Cmd_AddCommand ("-strafe", IN_StrafeRelease, "When active, +left and "
|
|
|
|
"+right stop functioning like +moveleft and +moveright");
|
|
|
|
Cmd_AddCommand ("+moveleft", IN_MoveleftPress, "When active the player is "
|
2001-07-15 00:03:11 +00:00
|
|
|
"strafing left");
|
2004-02-03 05:16:22 +00:00
|
|
|
Cmd_AddCommand ("-moveleft", IN_MoveleftRelease, "When active the player "
|
|
|
|
"is not strafing left");
|
|
|
|
Cmd_AddCommand ("+moveright", IN_MoverightPress, "When active the player "
|
2001-07-15 00:03:11 +00:00
|
|
|
"is strafing right");
|
2004-02-03 05:16:22 +00:00
|
|
|
Cmd_AddCommand ("-moveright", IN_MoverightRelease, "When active the "
|
|
|
|
"player is not strafing right");
|
|
|
|
Cmd_AddCommand ("+speed", IN_SpeedPress, "When active the player is "
|
2001-07-15 00:03:11 +00:00
|
|
|
"running");
|
2004-02-03 05:16:22 +00:00
|
|
|
Cmd_AddCommand ("-speed", IN_SpeedRelease, "When active the player is not "
|
2001-07-15 00:03:11 +00:00
|
|
|
"running");
|
2004-02-03 05:16:22 +00:00
|
|
|
Cmd_AddCommand ("+attack", IN_AttackPress, "When active player is "
|
2001-07-15 00:03:11 +00:00
|
|
|
"firing/using current weapon");
|
2004-02-03 05:16:22 +00:00
|
|
|
Cmd_AddCommand ("-attack", IN_AttackRelease, "When active player is not "
|
2001-07-15 00:03:11 +00:00
|
|
|
"firing/using current weapon");
|
2004-02-03 05:16:22 +00:00
|
|
|
Cmd_AddCommand ("+use", IN_UsePress, "Non-functional. Left over command "
|
2001-07-15 00:03:11 +00:00
|
|
|
"for opening doors and triggering switches");
|
2004-02-03 05:16:22 +00:00
|
|
|
Cmd_AddCommand ("-use", IN_UseRelease, "Non-functional. Left over command "
|
|
|
|
"for opening doors and triggering switches");
|
|
|
|
Cmd_AddCommand ("+jump", IN_JumpPress, "When active the player is "
|
|
|
|
"jumping");
|
|
|
|
Cmd_AddCommand ("-jump", IN_JumpRelease, "When active the player is not "
|
2001-07-15 00:03:11 +00:00
|
|
|
"jumping");
|
|
|
|
Cmd_AddCommand ("impulse", IN_Impulse, "Call a game function or QuakeC "
|
|
|
|
"function.");
|
2004-02-03 05:16:22 +00:00
|
|
|
Cmd_AddCommand ("+klook", IN_KLookPress, "When active, +forward and +back "
|
2001-07-15 00:03:11 +00:00
|
|
|
"perform +lookup and +lookdown");
|
2004-02-03 05:16:22 +00:00
|
|
|
Cmd_AddCommand ("-klook", IN_KLookRelease, "When active, +forward and "
|
|
|
|
"+back don't perform +lookup and +lookdown");
|
|
|
|
Cmd_AddCommand ("+mlook", IN_MLookPress, "When active moving the mouse or "
|
2001-07-15 00:03:11 +00:00
|
|
|
"joystick forwards and backwards performs +lookup and "
|
|
|
|
"+lookdown");
|
2004-02-03 05:16:22 +00:00
|
|
|
Cmd_AddCommand ("-mlook", IN_MLookRelease, "When active moving the mouse "
|
|
|
|
"or joystick forwards and backwards doesn't perform "
|
|
|
|
"+lookup and +lookdown");
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|