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
|
|
|
|
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"
|
2021-11-18 06:27:44 +00:00
|
|
|
#include "QF/console.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
|
|
|
|
2021-11-18 06:27:44 +00:00
|
|
|
#include "QF/input/event.h"
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "QF/plugin/vid_render.h"
|
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
#include "compat.h"
|
2020-06-21 14:15:17 +00:00
|
|
|
|
2021-11-25 03:46:54 +00:00
|
|
|
#include "client/input.h"
|
|
|
|
|
2020-06-21 14:15:17 +00:00
|
|
|
#include "nq/include/client.h"
|
|
|
|
#include "nq/include/host.h"
|
2001-04-15 21:11:41 +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
|
2021-03-19 18:56:16 +00:00
|
|
|
IN_Impulse (void *data)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
|
|
|
in_impulse = atoi (Cmd_Argv (1));
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/*
|
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)
|
|
|
|
{
|
2021-03-19 16:48:26 +00:00
|
|
|
if (cls.state != ca_active) {
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
2021-03-19 16:48:26 +00:00
|
|
|
}
|
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-26 06:48:02 +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];
|
2022-03-01 02:43:23 +00:00
|
|
|
cl.viewstate.movecmd = cl.movestate.move;
|
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
|
|
|
|
2022-03-01 02:43:23 +00:00
|
|
|
write_angles (&buf, cl.viewstate.player_angles);
|
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
|
|
|
|
[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
|
|
|
bits |= IN_ButtonPressed (&in_attack) << 0;
|
|
|
|
bits |= IN_ButtonPressed (&in_jump) << 1;
|
|
|
|
bits |= IN_ButtonPressed (&in_use) << 2;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
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
|
2022-02-22 06:23:09 +00:00
|
|
|
CL_Init_Input (cbuf_t *cbuf)
|
2001-02-26 06:48:02 +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.");
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2021-11-18 06:27:44 +00:00
|
|
|
|
|
|
|
void
|
2022-02-22 06:23:09 +00:00
|
|
|
CL_Init_Input_Cvars (void)
|
2021-11-18 06:27:44 +00:00
|
|
|
{
|
2022-02-22 06:23:09 +00:00
|
|
|
CL_Input_Init_Cvars ();
|
2021-11-18 06:27:44 +00:00
|
|
|
}
|