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
|
|
|
|
|
|
|
#include "QF/cvar.h"
|
2021-08-27 00:10:21 +00:00
|
|
|
#include "QF/darray.h"
|
[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
|
|
|
#define IMPLEMENT_INPUT_Funcs
|
2001-04-15 07:18:04 +00:00
|
|
|
#include "QF/input.h"
|
|
|
|
#include "QF/joystick.h"
|
|
|
|
#include "QF/keys.h"
|
|
|
|
#include "QF/mathlib.h"
|
2021-11-14 01:17:05 +00:00
|
|
|
#include "QF/plist.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
|
|
|
|
2021-11-01 04:05:05 +00:00
|
|
|
#include "QF/input/event.h"
|
|
|
|
|
2021-09-28 01:53:51 +00:00
|
|
|
#include "qfselect.h"
|
|
|
|
|
2021-08-30 00:54:36 +00:00
|
|
|
typedef struct {
|
|
|
|
in_driver_t driver;
|
|
|
|
void *data;
|
|
|
|
} in_regdriver_t;
|
|
|
|
|
2021-08-30 05:40:19 +00:00
|
|
|
static struct DARRAY_TYPE (in_regdriver_t) in_drivers = { .grow = 8 };
|
2021-09-20 06:21:11 +00:00
|
|
|
static struct DARRAY_TYPE (in_device_t) in_devices = { .grow = 8 };
|
2021-08-27 00:10:21 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
int in_grab;
|
|
|
|
static cvar_t in_grab_cvar = {
|
|
|
|
.name = "in_grab",
|
|
|
|
.description =
|
|
|
|
"With this set to 1, quake will grab the mouse, preventing loss of "
|
|
|
|
"input focus.",
|
|
|
|
.default_value = "0",
|
|
|
|
.flags = CVAR_ARCHIVE,
|
|
|
|
.value = { .type = &cexpr_int, .value = &in_grab },
|
|
|
|
};
|
|
|
|
VISIBLE float in_amp;
|
|
|
|
static cvar_t in_amp_cvar = {
|
|
|
|
.name = "in_amp",
|
|
|
|
.description =
|
|
|
|
"global in_amp multiplier",
|
|
|
|
.default_value = "1",
|
|
|
|
.flags = CVAR_ARCHIVE,
|
|
|
|
.value = { .type = &cexpr_float, .value = &in_amp },
|
|
|
|
};
|
|
|
|
VISIBLE float in_pre_amp;
|
|
|
|
static cvar_t in_pre_amp_cvar = {
|
|
|
|
.name = "in_pre_amp",
|
|
|
|
.description =
|
|
|
|
"global in_pre_amp multiplier",
|
|
|
|
.default_value = "1",
|
|
|
|
.flags = CVAR_ARCHIVE,
|
|
|
|
.value = { .type = &cexpr_float, .value = &in_pre_amp },
|
|
|
|
};
|
|
|
|
int in_freelook;
|
|
|
|
static cvar_t in_freelook_cvar = {
|
|
|
|
.name = "freelook",
|
|
|
|
.description =
|
|
|
|
"force +mlook",
|
|
|
|
.default_value = "0",
|
|
|
|
.flags = CVAR_ARCHIVE,
|
|
|
|
.value = { .type = &cexpr_int, .value = &in_freelook },
|
|
|
|
};
|
2022-04-24 08:57:20 +00:00
|
|
|
int in_mouse_filter;
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
static cvar_t in_mouse_filter_cvar = {
|
|
|
|
.name = "in_mouse_filter",
|
|
|
|
.description =
|
|
|
|
"Toggle mouse input filtering.",
|
|
|
|
.default_value = "0",
|
|
|
|
.flags = CVAR_ARCHIVE,
|
2022-04-24 08:57:20 +00:00
|
|
|
.value = { .type = &cexpr_int, .value = &in_mouse_filter },
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
};
|
2022-04-24 08:57:20 +00:00
|
|
|
float in_mouse_amp;
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
static cvar_t in_mouse_amp_cvar = {
|
|
|
|
.name = "in_mouse_amp",
|
|
|
|
.description =
|
|
|
|
"mouse in_mouse_amp multiplier",
|
|
|
|
.default_value = "15",
|
|
|
|
.flags = CVAR_ARCHIVE,
|
2022-04-24 08:57:20 +00:00
|
|
|
.value = { .type = &cexpr_float, .value = &in_mouse_amp },
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
};
|
2022-04-24 08:57:20 +00:00
|
|
|
float in_mouse_pre_amp;
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
static cvar_t in_mouse_pre_amp_cvar = {
|
|
|
|
.name = "in_mouse_pre_amp",
|
|
|
|
.description =
|
|
|
|
"mouse in_mouse_pre_amp multiplier",
|
|
|
|
.default_value = "1",
|
|
|
|
.flags = CVAR_ARCHIVE,
|
2022-04-24 08:57:20 +00:00
|
|
|
.value = { .type = &cexpr_float, .value = &in_mouse_pre_amp },
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
};
|
2022-04-24 08:57:20 +00:00
|
|
|
int lookstrafe;
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
static cvar_t lookstrafe_cvar = {
|
|
|
|
.name = "lookstrafe",
|
|
|
|
.description =
|
|
|
|
"when mlook/klook on player will strafe",
|
|
|
|
.default_value = "0",
|
|
|
|
.flags = CVAR_ARCHIVE,
|
2022-04-24 08:57:20 +00:00
|
|
|
.value = { .type = &cexpr_int, .value = &lookstrafe },
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
};
|
2001-04-15 07:18:04 +00:00
|
|
|
|
2021-09-26 06:11:07 +00:00
|
|
|
int64_t in_timeout = 10000;//10ms default timeout
|
2001-04-15 07:18:04 +00:00
|
|
|
|
2021-08-30 00:54:36 +00:00
|
|
|
int
|
|
|
|
IN_RegisterDriver (in_driver_t *driver, void *data)
|
|
|
|
{
|
|
|
|
in_regdriver_t rdriver = { *driver, data };
|
|
|
|
DARRAY_APPEND (&in_drivers, rdriver);
|
|
|
|
return in_drivers.size - 1;
|
|
|
|
}
|
|
|
|
|
2021-08-27 00:10:21 +00:00
|
|
|
void
|
2021-08-30 00:54:36 +00:00
|
|
|
IN_DriverData (int handle, void *data)
|
2021-08-27 00:10:21 +00:00
|
|
|
{
|
2021-08-30 00:54:36 +00:00
|
|
|
in_drivers.a[handle].data = data;
|
2021-08-27 00:10:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-30 05:40:19 +00:00
|
|
|
static int
|
2021-11-03 10:02:39 +00:00
|
|
|
in_add_device (int driver, void *device, const char *name,
|
2021-09-20 06:21:11 +00:00
|
|
|
const char *id)
|
2021-08-30 05:40:19 +00:00
|
|
|
{
|
|
|
|
size_t devid;
|
2021-09-20 06:21:11 +00:00
|
|
|
in_device_t indev = {
|
|
|
|
.driverid = driver,
|
|
|
|
.device = device,
|
|
|
|
.name = name,
|
|
|
|
.id = id,
|
|
|
|
};
|
2021-08-30 05:40:19 +00:00
|
|
|
|
|
|
|
for (devid = 0; devid < in_devices.size; devid++) {
|
2021-09-20 06:21:11 +00:00
|
|
|
if (in_devices.a[devid].driverid == -1) {
|
|
|
|
in_devices.a[devid] = indev;
|
2021-08-30 05:40:19 +00:00
|
|
|
return devid;
|
|
|
|
}
|
|
|
|
}
|
2021-09-20 06:21:11 +00:00
|
|
|
DARRAY_APPEND (&in_devices, indev);
|
2021-08-30 05:40:19 +00:00
|
|
|
return devid;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2021-09-20 06:21:11 +00:00
|
|
|
IN_AddDevice (int driver, void *device, const char *name, const char *id)
|
2021-08-30 05:40:19 +00:00
|
|
|
{
|
2021-09-20 06:21:11 +00:00
|
|
|
if ((size_t) driver >= in_drivers.size) {
|
|
|
|
Sys_Error ("IN_AddDevice: invalid driver: %d", driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
int devid = in_add_device (driver, device, name, id);
|
2021-08-30 05:40:19 +00:00
|
|
|
|
|
|
|
IE_event_t event = {
|
|
|
|
.type = ie_add_device,
|
|
|
|
.when = Sys_LongTime (),
|
|
|
|
.device = {
|
|
|
|
.devid = devid,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
IE_Send_Event (&event);
|
|
|
|
return devid;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IN_RemoveDevice (int devid)
|
|
|
|
{
|
2021-09-20 06:21:11 +00:00
|
|
|
if ((size_t) devid >= in_devices.size) {
|
2021-08-30 05:40:19 +00:00
|
|
|
Sys_Error ("IN_RemoveDevice: invalid devid: %d", devid);
|
|
|
|
}
|
|
|
|
|
|
|
|
IE_event_t event = {
|
|
|
|
.type = ie_remove_device,
|
|
|
|
.when = Sys_LongTime (),
|
|
|
|
.device = {
|
|
|
|
.devid = devid,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
IE_Send_Event (&event);
|
|
|
|
|
2021-09-20 06:21:11 +00:00
|
|
|
in_devices.a[devid].device = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IN_SendConnectedDevices (void)
|
|
|
|
{
|
|
|
|
for (size_t devid = 0; devid < in_devices.size; devid++) {
|
|
|
|
if (in_devices.a[devid].driverid >= 0
|
|
|
|
&& in_devices.a[devid].device) {
|
|
|
|
IE_event_t event = {
|
|
|
|
.type = ie_add_device,
|
|
|
|
.when = Sys_LongTime (),//FIXME actual time?
|
|
|
|
.device = {
|
|
|
|
.devid = devid,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
IE_Send_Event (&event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-20 15:47:13 +00:00
|
|
|
int
|
|
|
|
IN_FindDeviceId (const char *id)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < in_devices.size; i++) {
|
|
|
|
if (strcmp (id, in_devices.a[i].id) == 0) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-09-20 06:21:11 +00:00
|
|
|
const char *
|
|
|
|
IN_GetDeviceName (int devid)
|
|
|
|
{
|
|
|
|
if ((size_t) devid >= in_devices.size) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!in_devices.a[devid].device || in_devices.a[devid].driverid == -1) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return in_devices.a[devid].name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
IN_GetDeviceId (int devid)
|
|
|
|
{
|
|
|
|
if ((size_t) devid >= in_devices.size) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!in_devices.a[devid].device || in_devices.a[devid].driverid == -1) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return in_devices.a[devid].id;
|
|
|
|
}
|
|
|
|
|
2021-11-09 13:31:09 +00:00
|
|
|
void
|
|
|
|
IN_SetDeviceEventData (int devid, void *data)
|
|
|
|
{
|
|
|
|
if ((size_t) devid >= in_devices.size) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!in_devices.a[devid].device || in_devices.a[devid].driverid == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
in_regdriver_t *rd = &in_drivers.a[in_devices.a[devid].driverid];
|
|
|
|
rd->driver.set_device_event_data (in_devices.a[devid].device, data,
|
|
|
|
rd->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
IN_GetDeviceEventData (int devid)
|
|
|
|
{
|
|
|
|
if ((size_t) devid >= in_devices.size) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!in_devices.a[devid].device || in_devices.a[devid].driverid == -1) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
in_regdriver_t *rd = &in_drivers.a[in_devices.a[devid].driverid];
|
|
|
|
return rd->driver.get_device_event_data (in_devices.a[devid].device,
|
|
|
|
rd->data);
|
|
|
|
}
|
|
|
|
|
2021-09-20 06:21:11 +00:00
|
|
|
int
|
|
|
|
IN_AxisInfo (int devid, in_axisinfo_t *axes, int *numaxes)
|
|
|
|
{
|
|
|
|
if ((size_t) devid >= in_devices.size) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!in_devices.a[devid].device || in_devices.a[devid].driverid == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
int driver = in_devices.a[devid].driverid;
|
|
|
|
in_regdriver_t *rd = &in_drivers.a[driver];
|
|
|
|
if (!rd->driver.axis_info) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
rd->driver.axis_info (rd->data, in_devices.a[devid].device, axes, numaxes);
|
|
|
|
if (axes) {
|
|
|
|
for (int i = 0; i < *numaxes; i++) {
|
|
|
|
axes[i].deviceid = devid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
IN_ButtonInfo (int devid, in_buttoninfo_t *buttons, int *numbuttons)
|
|
|
|
{
|
|
|
|
if ((size_t) devid >= in_devices.size) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!in_devices.a[devid].device || in_devices.a[devid].driverid == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
int driver = in_devices.a[devid].driverid;
|
|
|
|
in_regdriver_t *rd = &in_drivers.a[driver];
|
|
|
|
if (!rd->driver.button_info) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
rd->driver.button_info (rd->data, in_devices.a[devid].device,
|
|
|
|
buttons, numbuttons);
|
|
|
|
if (buttons) {
|
|
|
|
for (int i = 0; i < *numbuttons; i++) {
|
|
|
|
buttons[i].deviceid = devid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2021-08-30 05:40:19 +00:00
|
|
|
}
|
|
|
|
|
2021-11-18 03:59:18 +00:00
|
|
|
const char *
|
|
|
|
IN_GetAxisName (int devid, int axis_num)
|
|
|
|
{
|
|
|
|
if ((size_t) devid >= in_devices.size) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!in_devices.a[devid].device || in_devices.a[devid].driverid == -1) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int driver = in_devices.a[devid].driverid;
|
|
|
|
in_regdriver_t *rd = &in_drivers.a[driver];
|
|
|
|
if (!rd->driver.get_axis_name) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return rd->driver.get_axis_name (rd->data, in_devices.a[devid].device,
|
|
|
|
axis_num);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
IN_GetButtonName (int devid, int button_num)
|
|
|
|
{
|
|
|
|
if ((size_t) devid >= in_devices.size) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!in_devices.a[devid].device || in_devices.a[devid].driverid == -1) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int driver = in_devices.a[devid].driverid;
|
|
|
|
in_regdriver_t *rd = &in_drivers.a[driver];
|
|
|
|
if (!rd->driver.get_button_name) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return rd->driver.get_button_name (rd->data, in_devices.a[devid].device,
|
|
|
|
button_num);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
IN_GetAxisNumber (int devid, const char *axis_name)
|
|
|
|
{
|
|
|
|
if ((size_t) devid >= in_devices.size) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!in_devices.a[devid].device || in_devices.a[devid].driverid == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
int driver = in_devices.a[devid].driverid;
|
|
|
|
in_regdriver_t *rd = &in_drivers.a[driver];
|
|
|
|
if (!rd->driver.get_axis_num) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return rd->driver.get_axis_num (rd->data, in_devices.a[devid].device,
|
|
|
|
axis_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
IN_GetButtonNumber (int devid, const char *button_name)
|
|
|
|
{
|
|
|
|
if ((size_t) devid >= in_devices.size) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!in_devices.a[devid].device || in_devices.a[devid].driverid == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
int driver = in_devices.a[devid].driverid;
|
|
|
|
in_regdriver_t *rd = &in_drivers.a[driver];
|
|
|
|
if (!rd->driver.get_button_num) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return rd->driver.get_button_num (rd->data, in_devices.a[devid].device,
|
|
|
|
button_name);
|
|
|
|
}
|
|
|
|
|
2021-12-21 08:42:38 +00:00
|
|
|
int
|
|
|
|
IN_GetAxisInfo (int devid, int axis_num, in_axisinfo_t *info)
|
|
|
|
{
|
|
|
|
if ((size_t) devid >= in_devices.size) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!in_devices.a[devid].device || in_devices.a[devid].driverid == -1) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int driver = in_devices.a[devid].driverid;
|
|
|
|
in_regdriver_t *rd = &in_drivers.a[driver];
|
|
|
|
if (rd->driver.get_axis_info (rd->data, in_devices.a[devid].device,
|
|
|
|
axis_num, info)) {
|
|
|
|
info->deviceid = devid;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
IN_GetButtonInfo (int devid, int button_num, in_buttoninfo_t *info)
|
|
|
|
{
|
|
|
|
if ((size_t) devid >= in_devices.size) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!in_devices.a[devid].device || in_devices.a[devid].driverid == -1) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int driver = in_devices.a[devid].driverid;
|
|
|
|
in_regdriver_t *rd = &in_drivers.a[driver];
|
|
|
|
if (rd->driver.get_button_info (rd->data, in_devices.a[devid].device,
|
|
|
|
button_num, info)) {
|
|
|
|
info->deviceid = devid;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-02-13 19:03:48 +00:00
|
|
|
void
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
IN_UpdateGrab (int grab)
|
2001-08-30 20:04:13 +00:00
|
|
|
{
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
for (size_t i = 0; i < in_drivers.size; i++) {
|
|
|
|
in_regdriver_t *rd = &in_drivers.a[i];
|
|
|
|
if (rd->driver.grab_input) {
|
|
|
|
rd->driver.grab_input (rd->data, grab);
|
2021-08-27 00:10:21 +00:00
|
|
|
}
|
2001-08-30 20:04:13 +00:00
|
|
|
}
|
|
|
|
}
|
2001-08-17 07:26:01 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
static void
|
|
|
|
in_grab_f (void *data, const cvar_t *cvar)
|
|
|
|
{
|
|
|
|
IN_UpdateGrab (in_grab);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2021-09-28 01:53:51 +00:00
|
|
|
qf_fd_set fdset;
|
2021-09-26 06:11:07 +00:00
|
|
|
int maxfd = -1;
|
|
|
|
int64_t timeout = in_timeout;
|
|
|
|
|
2021-09-28 01:53:51 +00:00
|
|
|
QF_FD_ZERO (&fdset);
|
2021-08-27 00:10:21 +00:00
|
|
|
for (size_t i = 0; i < in_drivers.size; i++) {
|
2021-08-30 00:54:36 +00:00
|
|
|
in_regdriver_t *rd = &in_drivers.a[i];
|
2021-09-26 06:11:07 +00:00
|
|
|
if (rd->driver.add_select) {
|
|
|
|
rd->driver.add_select (&fdset, &maxfd, rd->data);
|
|
|
|
}
|
|
|
|
if (rd->driver.process_events) {
|
|
|
|
rd->driver.process_events (rd->data);
|
|
|
|
// if a driver can't use select, then we can't block in select
|
|
|
|
timeout = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (maxfd >= 0 && Sys_Select (maxfd, &fdset, timeout) > 0) {
|
|
|
|
for (size_t i = 0; i < in_drivers.size; i++) {
|
|
|
|
in_regdriver_t *rd = &in_drivers.a[i];
|
|
|
|
if (rd->driver.check_select) {
|
|
|
|
rd->driver.check_select (&fdset, rd->data);
|
|
|
|
}
|
|
|
|
}
|
2021-08-27 00:10:21 +00:00
|
|
|
}
|
2001-04-15 07:18:04 +00:00
|
|
|
}
|
|
|
|
|
2021-11-14 01:17:05 +00:00
|
|
|
void
|
|
|
|
IN_SaveConfig (plitem_t *config)
|
|
|
|
{
|
2022-05-12 08:54:23 +00:00
|
|
|
plitem_t *input_config = PL_NewDictionary (0);
|
2021-11-14 01:17:05 +00:00
|
|
|
PL_D_AddObject (config, "input", input_config);
|
|
|
|
|
|
|
|
IMT_SaveConfig (input_config);
|
|
|
|
IN_Binding_SaveConfig (input_config);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IN_LoadConfig (plitem_t *config)
|
|
|
|
{
|
|
|
|
plitem_t *input_config = PL_ObjectForKey (config, "input");
|
|
|
|
|
|
|
|
if (input_config) {
|
|
|
|
IMT_LoadConfig (input_config);
|
|
|
|
IN_Binding_LoadConfig (input_config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2021-08-27 00:10:21 +00:00
|
|
|
//JOY_Shutdown ();
|
2001-04-15 07:18:04 +00:00
|
|
|
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_vid, "IN_Shutdown\n");
|
2021-08-27 00:10:21 +00:00
|
|
|
for (size_t i = in_drivers.size; i-- > 0; ) {
|
2021-08-30 00:54:36 +00:00
|
|
|
in_regdriver_t *rd = &in_drivers.a[i];
|
|
|
|
if (rd->driver.shutdown) {
|
|
|
|
rd->driver.shutdown (rd->data);
|
2021-08-27 00:10:21 +00:00
|
|
|
}
|
|
|
|
}
|
2022-05-12 10:01:45 +00:00
|
|
|
IN_Binding_Shutdown ();
|
|
|
|
IMT_Shutdown ();
|
|
|
|
|
|
|
|
DARRAY_CLEAR (&in_drivers);
|
|
|
|
DARRAY_CLEAR (&in_devices);
|
2001-04-15 07:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-11-18 06:33:49 +00:00
|
|
|
IN_Init (void)
|
2001-04-15 07:18:04 +00:00
|
|
|
{
|
2020-06-25 05:03:52 +00:00
|
|
|
Sys_RegisterShutdown (IN_shutdown, 0);
|
2021-11-08 07:54:52 +00:00
|
|
|
IMT_Init ();
|
2021-11-03 13:20:17 +00:00
|
|
|
IN_Binding_Init ();
|
2019-07-12 14:15:26 +00:00
|
|
|
|
2021-08-27 00:10:21 +00:00
|
|
|
for (size_t i = 0; i < in_drivers.size; i++) {
|
2021-08-30 00:54:36 +00:00
|
|
|
in_regdriver_t *rd = &in_drivers.a[i];
|
|
|
|
rd->driver.init (rd->data);
|
2021-08-27 00:10:21 +00:00
|
|
|
}
|
2001-04-15 07:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IN_Init_Cvars (void)
|
|
|
|
{
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Cvar_Register (&in_grab_cvar, in_grab_f, 0);
|
|
|
|
Cvar_Register (&in_amp_cvar, 0, 0);
|
|
|
|
Cvar_Register (&in_pre_amp_cvar, 0, 0);
|
|
|
|
Cvar_Register (&in_freelook_cvar, 0, 0);
|
|
|
|
Cvar_Register (&in_mouse_filter_cvar, 0, 0);
|
|
|
|
Cvar_Register (&in_mouse_amp_cvar, 0, 0);
|
|
|
|
Cvar_Register (&in_mouse_pre_amp_cvar, 0, 0);
|
|
|
|
Cvar_Register (&lookstrafe_cvar, 0, 0);
|
2021-11-21 02:33:58 +00:00
|
|
|
for (size_t i = 0; i < in_drivers.size; i++) {
|
|
|
|
in_regdriver_t *rd = &in_drivers.a[i];
|
|
|
|
if (rd->driver.init_cvars) {
|
|
|
|
rd->driver.init_cvars (rd->data);
|
|
|
|
}
|
|
|
|
}
|
2001-04-15 07:18:04 +00:00
|
|
|
}
|
2001-04-15 21:11:41 +00:00
|
|
|
|
2001-04-17 15:55:33 +00:00
|
|
|
void
|
|
|
|
IN_ClearStates (void)
|
|
|
|
{
|
2021-08-27 00:10:21 +00:00
|
|
|
for (size_t i = 0; i < in_drivers.size; i++) {
|
2021-08-30 00:54:36 +00:00
|
|
|
in_regdriver_t *rd = &in_drivers.a[i];
|
|
|
|
if (rd->driver.clear_states) {
|
|
|
|
rd->driver.clear_states (rd->data);
|
2021-08-27 00:10:21 +00:00
|
|
|
}
|
|
|
|
}
|
2022-05-19 07:47:47 +00:00
|
|
|
IN_AxisClearStates ();
|
|
|
|
IN_ButtonClearStates ();
|
2001-04-17 15:55:33 +00:00
|
|
|
}
|
2021-08-27 00:10:21 +00:00
|
|
|
|
2021-09-28 01:57:12 +00:00
|
|
|
#ifdef HAVE_EVDEV
|
2021-08-27 00:10:21 +00:00
|
|
|
extern int in_evdev_force_link;
|
|
|
|
static __attribute__((used)) int *evdev_force_link = &in_evdev_force_link;
|
2021-09-28 01:57:12 +00:00
|
|
|
#endif
|