2005-01-13 15:10:42 +00:00
|
|
|
/*
|
2021-07-05 07:26:07 +00:00
|
|
|
rua_keys.c
|
2005-01-13 15:10:42 +00:00
|
|
|
|
2021-07-05 07:26:07 +00:00
|
|
|
Ruamoko key-api builtins
|
2005-01-13 15:10:42 +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
|
|
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "QF/csqc.h"
|
2021-11-03 10:02:39 +00:00
|
|
|
#include "QF/input.h"
|
2005-01-13 15:10:42 +00:00
|
|
|
#include "QF/progs.h"
|
|
|
|
#include "QF/zone.h"
|
|
|
|
|
2016-01-10 04:33:05 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Key_keydown (progs_t *pr, void *data)
|
2016-01-10 04:33:05 +00:00
|
|
|
{
|
2021-11-08 02:20:04 +00:00
|
|
|
#if 0
|
2016-01-10 04:33:05 +00:00
|
|
|
int keynum = P_INT (pr, 0);
|
|
|
|
R_INT (pr) = keydown[keynum];
|
2021-11-08 02:20:04 +00:00
|
|
|
#endif
|
2016-01-10 04:33:05 +00:00
|
|
|
}
|
|
|
|
|
2005-01-13 15:10:42 +00:00
|
|
|
/*
|
|
|
|
bi_Key_SetBinding
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2005-01-13 15:10:42 +00:00
|
|
|
QC-Function for set a binding
|
|
|
|
*/
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Key_SetBinding (progs_t *pr, void *data)
|
2005-01-13 15:10:42 +00:00
|
|
|
{
|
2021-11-08 02:20:04 +00:00
|
|
|
#if 0
|
2013-01-16 10:35:23 +00:00
|
|
|
const char *imt_name = P_GSTRING (pr, 0);
|
2005-01-13 15:10:42 +00:00
|
|
|
int keynum = P_INT (pr, 1);
|
|
|
|
const char *binding = P_GSTRING (pr, 2);
|
2013-01-16 10:35:23 +00:00
|
|
|
imt_t *imt;
|
2005-01-13 15:10:42 +00:00
|
|
|
|
2013-01-16 10:35:23 +00:00
|
|
|
if (binding && !binding[0]) {
|
2005-01-13 15:10:42 +00:00
|
|
|
binding = NULL; /* unbind a binding */
|
|
|
|
}
|
|
|
|
|
2013-01-16 10:35:23 +00:00
|
|
|
imt = Key_FindIMT (imt_name);
|
|
|
|
if (imt) {
|
|
|
|
Key_SetBinding (imt, keynum, binding);
|
|
|
|
}
|
2021-11-08 02:20:04 +00:00
|
|
|
#endif
|
2005-01-13 15:10:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
bi_Key_LookupBinding
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2005-01-13 15:10:42 +00:00
|
|
|
Perform a reverse-binding-lookup
|
|
|
|
*/
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Key_LookupBinding (progs_t *pr, void *data)
|
2005-01-13 15:10:42 +00:00
|
|
|
{
|
2021-11-08 02:20:04 +00:00
|
|
|
#if 0
|
2013-01-16 10:35:23 +00:00
|
|
|
const char *imt_name = P_GSTRING (pr, 0);
|
2005-01-13 15:10:42 +00:00
|
|
|
int bindnum = P_INT (pr, 1);
|
|
|
|
const char *binding = P_GSTRING (pr, 2);
|
2013-01-16 10:35:23 +00:00
|
|
|
imt_t *imt;
|
2005-01-13 15:10:42 +00:00
|
|
|
int i;
|
|
|
|
knum_t keynum = -1;
|
|
|
|
const char *keybind = NULL;
|
|
|
|
|
2013-01-16 10:35:23 +00:00
|
|
|
imt = Key_FindIMT (imt_name);
|
|
|
|
if (imt) {
|
|
|
|
for (i = 0; i < QFK_LAST; i++) {
|
2021-11-08 02:20:04 +00:00
|
|
|
keybind = imt->button_bindings.a[i].str;
|
2013-01-16 10:35:23 +00:00
|
|
|
if (keybind == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strcmp (keybind, binding) == 0) {
|
|
|
|
bindnum--;
|
|
|
|
if (bindnum == 0) {
|
|
|
|
keynum = i;
|
|
|
|
break;
|
|
|
|
}
|
2005-01-13 15:10:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-21 23:23:22 +00:00
|
|
|
R_INT (pr) = keynum;
|
2021-11-08 02:20:04 +00:00
|
|
|
#endif
|
|
|
|
}
|
2005-01-13 15:10:42 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
bi_Key_CountBinding
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2005-01-13 15:10:42 +00:00
|
|
|
Counts how often a binding is assigned to a key
|
|
|
|
*/
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Key_CountBinding (progs_t *pr, void *data)
|
2005-01-13 15:10:42 +00:00
|
|
|
{
|
2021-11-08 02:20:04 +00:00
|
|
|
#if 0
|
2013-01-16 10:35:23 +00:00
|
|
|
const char *imt_name = P_GSTRING (pr, 0);
|
2005-01-13 15:10:42 +00:00
|
|
|
const char *binding = P_GSTRING (pr, 1);
|
2007-04-07 05:06:42 +00:00
|
|
|
int i, res = 0;
|
2005-01-13 15:10:42 +00:00
|
|
|
const char *keybind = NULL;
|
2013-01-16 10:35:23 +00:00
|
|
|
imt_t *imt;
|
|
|
|
|
|
|
|
imt = Key_FindIMT (imt_name);
|
|
|
|
if (imt) {
|
|
|
|
for (i = 0; i < QFK_LAST; i++) {
|
2021-11-08 02:20:04 +00:00
|
|
|
keybind = imt->button_bindings.a[i].str;
|
2013-01-16 10:35:23 +00:00
|
|
|
if (keybind == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strcmp (keybind, binding) == 0) {
|
|
|
|
res++;
|
|
|
|
}
|
2005-01-13 15:10:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-21 23:23:22 +00:00
|
|
|
R_INT (pr) = res;
|
2021-11-08 02:20:04 +00:00
|
|
|
#endif
|
|
|
|
}
|
2005-01-13 15:10:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
bi_Key_LookupBinding
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2005-01-13 15:10:42 +00:00
|
|
|
Convertes a keynum to a string
|
|
|
|
*/
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Key_KeynumToString (progs_t *pr, void *data)
|
2005-01-13 15:10:42 +00:00
|
|
|
{
|
|
|
|
int keynum = P_INT (pr, 0);
|
|
|
|
|
|
|
|
RETURN_STRING (pr, Key_KeynumToString (keynum));
|
2021-11-08 02:20:04 +00:00
|
|
|
}
|
2005-01-13 15:10:42 +00:00
|
|
|
|
2016-01-04 07:10:22 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Key_StringToKeynum (progs_t *pr, void *data)
|
2016-01-04 07:10:22 +00:00
|
|
|
{
|
|
|
|
const char *keyname = P_GSTRING (pr, 0);
|
|
|
|
R_INT (pr) = Key_StringToKeynum (keyname);
|
|
|
|
}
|
|
|
|
|
2022-01-23 12:54:03 +00:00
|
|
|
#define bi(x,np,params...) {#x, bi_##x, -1, np, {params}}
|
|
|
|
#define p(type) PR_PARAM(type)
|
|
|
|
#define P(a, s) { .size = (s), .alignment = BITOP_LOG2 (a), }
|
2005-01-13 15:10:42 +00:00
|
|
|
static builtin_t builtins[] = {
|
2022-01-23 12:54:03 +00:00
|
|
|
bi(Key_keydown, 1, p(int)),
|
|
|
|
bi(Key_SetBinding, 3, p(string), p(int), p(string)),
|
|
|
|
bi(Key_LookupBinding, 3, p(string), p(int), p(string)),
|
|
|
|
bi(Key_CountBinding, 2, p(string), p(string)),
|
|
|
|
bi(Key_KeynumToString, 1, p(int)),
|
|
|
|
bi(Key_StringToKeynum, 1, p(string)),
|
2005-01-13 15:10:42 +00:00
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2022-02-14 03:28:38 +00:00
|
|
|
RUA_Key_Init (progs_t *pr, void *data)
|
2005-01-13 15:10:42 +00:00
|
|
|
{
|
2022-01-23 15:20:05 +00:00
|
|
|
PR_RegisterBuiltins (pr, builtins, 0);
|
2005-01-13 15:10:42 +00:00
|
|
|
}
|