2001-04-15 07:18:04 +00:00
|
|
|
/*
|
|
|
|
in_common.c
|
|
|
|
|
|
|
|
general input driver
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
|
|
|
|
Copyright (C) 1999,2000 contributors of the QuakeForge project
|
|
|
|
Please see the file "AUTHORS" for a list of contributors
|
|
|
|
|
|
|
|
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-04-15 07:18:04 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define _BSD
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
2001-08-27 01:00:03 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2001-04-15 07:18:04 +00:00
|
|
|
|
2012-02-01 12:52:47 +00:00
|
|
|
#include "QF/cbuf.h"
|
2001-04-15 07:18:04 +00:00
|
|
|
#include "QF/cvar.h"
|
2001-08-14 00:03:03 +00:00
|
|
|
#include "QF/in_event.h"
|
2001-04-15 07:18:04 +00:00
|
|
|
#include "QF/input.h"
|
|
|
|
#include "QF/joystick.h"
|
|
|
|
#include "QF/keys.h"
|
|
|
|
#include "QF/mathlib.h"
|
2007-11-06 10:17:14 +00:00
|
|
|
#include "QF/sys.h"
|
2001-09-28 16:54:31 +00:00
|
|
|
#include "QF/vid.h"
|
2001-04-15 07:18:04 +00:00
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE viewdelta_t viewdelta;
|
2001-10-23 16:55:23 +00:00
|
|
|
|
2001-08-30 20:04:13 +00:00
|
|
|
cvar_t *in_grab;
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE cvar_t *in_amp;
|
|
|
|
VISIBLE cvar_t *in_pre_amp;
|
2001-08-17 07:26:01 +00:00
|
|
|
cvar_t *in_freelook;
|
2001-08-15 23:04:54 +00:00
|
|
|
cvar_t *in_mouse_filter;
|
2001-08-17 07:26:01 +00:00
|
|
|
cvar_t *in_mouse_amp;
|
|
|
|
cvar_t *in_mouse_pre_amp;
|
2001-04-15 07:18:04 +00:00
|
|
|
cvar_t *lookstrafe;
|
|
|
|
|
|
|
|
kbutton_t in_mlook, in_klook;
|
|
|
|
kbutton_t in_strafe;
|
|
|
|
kbutton_t in_speed;
|
|
|
|
|
|
|
|
qboolean in_mouse_avail;
|
|
|
|
float in_mouse_x, in_mouse_y;
|
|
|
|
static float in_old_mouse_x, in_old_mouse_y;
|
|
|
|
|
2003-02-13 19:03:48 +00:00
|
|
|
void
|
|
|
|
IN_UpdateGrab (cvar_t *var) // called from context_*.c
|
2001-08-30 20:04:13 +00:00
|
|
|
{
|
2003-02-25 06:04:42 +00:00
|
|
|
if (var) {
|
2003-03-07 03:55:51 +00:00
|
|
|
IN_LL_Grab_Input (var->int_val);
|
2001-08-30 20:04:13 +00:00
|
|
|
}
|
|
|
|
}
|
2001-08-17 07:26:01 +00:00
|
|
|
|
2001-04-15 07:18:04 +00:00
|
|
|
void
|
2003-04-08 18:45:12 +00:00
|
|
|
IN_ProcessEvents (void)
|
2001-04-15 07:18:04 +00:00
|
|
|
{
|
2003-01-28 21:31:55 +00:00
|
|
|
/* Get events from environment. */
|
2003-04-08 18:45:12 +00:00
|
|
|
JOY_Command ();
|
|
|
|
IN_LL_ProcessEvents ();
|
2001-04-15 07:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IN_Move (void)
|
|
|
|
{
|
|
|
|
JOY_Move ();
|
|
|
|
|
|
|
|
if (!in_mouse_avail)
|
|
|
|
return;
|
|
|
|
|
2001-09-08 03:34:28 +00:00
|
|
|
in_mouse_x *= in_mouse_pre_amp->value * in_pre_amp->value;
|
|
|
|
in_mouse_y *= in_mouse_pre_amp->value * in_pre_amp->value;
|
2001-08-06 05:01:31 +00:00
|
|
|
|
2001-08-15 23:04:54 +00:00
|
|
|
if (in_mouse_filter->int_val) {
|
2001-04-15 07:18:04 +00:00
|
|
|
in_mouse_x = (in_mouse_x + in_old_mouse_x) * 0.5;
|
|
|
|
in_mouse_y = (in_mouse_y + in_old_mouse_y) * 0.5;
|
2001-08-15 23:04:54 +00:00
|
|
|
|
|
|
|
in_old_mouse_x = in_mouse_x;
|
|
|
|
in_old_mouse_y = in_mouse_y;
|
2001-04-15 07:18:04 +00:00
|
|
|
}
|
|
|
|
|
2001-09-08 03:33:57 +00:00
|
|
|
in_mouse_x *= in_mouse_amp->value * in_amp->value;
|
|
|
|
in_mouse_y *= in_mouse_amp->value * in_amp->value;
|
2001-04-15 07:18:04 +00:00
|
|
|
|
|
|
|
if ((in_strafe.state & 1) || (lookstrafe->int_val && freelook))
|
|
|
|
viewdelta.position[0] += in_mouse_x;
|
|
|
|
else
|
|
|
|
viewdelta.angles[YAW] -= in_mouse_x;
|
|
|
|
|
|
|
|
if (freelook && !(in_strafe.state & 1)) {
|
|
|
|
viewdelta.angles[PITCH] += in_mouse_y;
|
|
|
|
} else {
|
|
|
|
viewdelta.position[2] -= in_mouse_y;
|
|
|
|
}
|
|
|
|
in_mouse_x = in_mouse_y = 0.0;
|
|
|
|
}
|
|
|
|
|
2001-08-27 01:00:03 +00:00
|
|
|
/* Called at shutdown */
|
2019-07-12 14:15:26 +00:00
|
|
|
static void
|
2020-06-25 05:03:52 +00:00
|
|
|
IN_shutdown (void *data)
|
2001-04-15 07:18:04 +00:00
|
|
|
{
|
|
|
|
JOY_Shutdown ();
|
|
|
|
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_vid, "IN_Shutdown\n");
|
2001-04-15 07:18:04 +00:00
|
|
|
IN_LL_Shutdown ();
|
2001-08-14 00:03:03 +00:00
|
|
|
|
|
|
|
IE_Shutdown ();
|
2001-04-15 07:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-01 12:52:47 +00:00
|
|
|
IN_Init (cbuf_t *cbuf)
|
2001-04-15 07:18:04 +00:00
|
|
|
{
|
2020-06-25 05:03:52 +00:00
|
|
|
Sys_RegisterShutdown (IN_shutdown, 0);
|
2019-07-12 14:15:26 +00:00
|
|
|
|
2001-08-14 00:03:03 +00:00
|
|
|
IE_Init ();
|
2001-04-15 07:18:04 +00:00
|
|
|
IN_LL_Init ();
|
2012-02-01 12:52:47 +00:00
|
|
|
Key_Init (cbuf);
|
2001-04-15 07:18:04 +00:00
|
|
|
JOY_Init ();
|
|
|
|
|
|
|
|
in_mouse_x = in_mouse_y = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IN_Init_Cvars (void)
|
|
|
|
{
|
2001-08-14 00:03:03 +00:00
|
|
|
IE_Init_Cvars ();
|
2012-02-01 12:52:47 +00:00
|
|
|
Key_Init_Cvars ();
|
2001-04-15 07:18:04 +00:00
|
|
|
JOY_Init_Cvars ();
|
2001-09-18 04:53:01 +00:00
|
|
|
in_grab = Cvar_Get ("in_grab", "0", CVAR_ARCHIVE, IN_UpdateGrab,
|
2003-01-28 21:31:55 +00:00
|
|
|
"With this set to 1, quake will grab the mouse, "
|
|
|
|
"preventing loss of input focus.");
|
2001-08-17 07:26:01 +00:00
|
|
|
in_amp = Cvar_Get ("in_amp", "1", CVAR_ARCHIVE, NULL,
|
|
|
|
"global in_amp multiplier");
|
|
|
|
in_pre_amp = Cvar_Get ("in_pre_amp", "1", CVAR_ARCHIVE, NULL,
|
|
|
|
"global in_pre_amp multiplier");
|
2001-04-17 03:08:52 +00:00
|
|
|
in_freelook = Cvar_Get ("freelook", "0", CVAR_ARCHIVE, NULL,
|
2001-08-17 07:26:01 +00:00
|
|
|
"force +mlook");
|
|
|
|
in_mouse_filter = Cvar_Get ("in_mouse_filter", "0", CVAR_ARCHIVE, NULL,
|
|
|
|
"Toggle mouse input filtering.");
|
|
|
|
in_mouse_amp = Cvar_Get ("in_mouse_amp", "15", CVAR_ARCHIVE, NULL,
|
|
|
|
"mouse in_mouse_amp multiplier");
|
|
|
|
in_mouse_pre_amp = Cvar_Get ("in_mouse_pre_amp", "1", CVAR_ARCHIVE, NULL,
|
|
|
|
"mouse in_mouse_pre_amp multiplier");
|
2001-04-15 07:18:04 +00:00
|
|
|
lookstrafe = Cvar_Get ("lookstrafe", "0", CVAR_ARCHIVE, NULL,
|
|
|
|
"when mlook/klook on player will strafe");
|
|
|
|
IN_LL_Init_Cvars ();
|
|
|
|
}
|
2001-04-15 21:11:41 +00:00
|
|
|
|
2001-04-17 15:55:33 +00:00
|
|
|
void
|
|
|
|
IN_ClearStates (void)
|
|
|
|
{
|
|
|
|
IN_LL_ClearStates ();
|
|
|
|
Key_ClearStates ();
|
|
|
|
}
|