mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-26 14:20:59 +00:00
[ruamoko] Replace rua_key with rua_input
And create rua_game to coordinate other game builtins. Menus are broken for key handling, but have been since the input rewrite anyway. rua_input adds the ability to create buttons and axes (but not destroy them). More work needs to be done to flesh things out, though.
This commit is contained in:
parent
8e08f5f84e
commit
33e48025dd
12 changed files with 296 additions and 21 deletions
|
@ -315,13 +315,16 @@ QF_PROCESS_NEED_LIST(ruamoko,[qwaq])
|
|||
if test "$ENABLE_tools_qfcc" = "yes" -a "$ENABLE_tools_pak" = "yes"; then
|
||||
QF_NEED(top, [ruamoko])
|
||||
qfac_qfcc_include_qf="\$(qfcc_include_qf)"
|
||||
qfac_qfcc_include_qf_input="\$(qfcc_include_qf_input)"
|
||||
fi
|
||||
QF_SUBST(qfac_qfcc_include_qf)
|
||||
QF_SUBST(qfac_qfcc_include_qf_input)
|
||||
|
||||
if test x"${top_need_libs}" = xyes; then
|
||||
qfac_include_qf="\$(include_qf)"
|
||||
qfac_include_qf_gl="\$(include_qf_gl)"
|
||||
qfac_include_qf_glsl="\$(include_qf_glsl)"
|
||||
qfac_include_qf_input="\$(include_qf_input)"
|
||||
qfac_include_qf_math="\$(include_qf_math)"
|
||||
qfac_include_qf_plugin="\$(include_qf_plugin)"
|
||||
qfac_include_qf_scene="\$(include_qf_scene)"
|
||||
|
@ -332,6 +335,7 @@ fi
|
|||
QF_SUBST(qfac_include_qf)
|
||||
QF_SUBST(qfac_include_qf_gl)
|
||||
QF_SUBST(qfac_include_qf_glsl)
|
||||
QF_SUBST(qfac_include_qf_input)
|
||||
QF_SUBST(qfac_include_qf_math)
|
||||
QF_SUBST(qfac_include_qf_plugin)
|
||||
QF_SUBST(qfac_include_qf_scene)
|
||||
|
|
|
@ -191,10 +191,12 @@ include_qf_vulkan = \
|
|||
|
||||
# headers shared with ruamoko
|
||||
qfcc_include_qf = include/QF/keys.h
|
||||
qfcc_include_qf_input = include/QF/input/binding.h
|
||||
|
||||
qf_includedir = $(includedir)/QF
|
||||
qf_gl_includedir = $(includedir)/QF/GL
|
||||
qf_glsl_includedir = $(includedir)/QF/GLSL
|
||||
qf_input_includedir = $(includedir)/QF/input
|
||||
qf_math_includedir = $(includedir)/QF/math
|
||||
qf_plugin_includedir = $(includedir)/QF/plugin
|
||||
qf_scene_includedir = $(includedir)/QF/scene
|
||||
|
@ -204,6 +206,7 @@ qf_vulkan_includedir = $(includedir)/QF/Vulkan
|
|||
qf_include_HEADERS = @qfac_include_qf@
|
||||
qf_gl_include_HEADERS = @qfac_include_qf_gl@
|
||||
qf_glsl_include_HEADERS = @qfac_include_qf_glsl@
|
||||
qf_input_include_HEADERS = @qfac_include_qf_input@
|
||||
qf_math_include_HEADERS = @qfac_include_qf_math@
|
||||
qf_plugin_include_HEADERS = @qfac_include_qf_plugin@
|
||||
qf_scene_include_HEADERS = @qfac_include_qf_scene@
|
||||
|
@ -212,7 +215,9 @@ qf_ui_include_HEADERS = @qfac_include_qf_ui@
|
|||
qf_vulkan_include_HEADERS = @qfac_include_qf_vulkan@
|
||||
|
||||
ruamoko_qf_includedir = $(ruamoko_includedir)/QF
|
||||
ruamoko_qf_input_includedir = $(ruamoko_includedir)/QF/input
|
||||
ruamoko_qf_include_HEADERS = @qfac_qfcc_include_qf@
|
||||
ruamoko_qf_input_include_HEADERS = @qfac_qfcc_include_qf_input@
|
||||
|
||||
EXTRA_HEADERS += \
|
||||
$(include_qf) \
|
||||
|
@ -225,4 +230,5 @@ EXTRA_HEADERS += \
|
|||
$(include_qf_simd) \
|
||||
$(include_qf_ui) \
|
||||
$(include_qf_vulkan) \
|
||||
$(qfcc_include_qf)
|
||||
$(qfcc_include_qf) \
|
||||
$(qfcc_include_qf_input)
|
||||
|
|
|
@ -105,6 +105,7 @@ int IN_AddDevice (int driver, void *device, const char *name, const char *id);
|
|||
void IN_RemoveDevice (int devid);
|
||||
|
||||
void IN_SendConnectedDevices (void);
|
||||
int IN_FindDeviceId (const char *id) __attribute__((pure));
|
||||
const char *IN_GetDeviceName (int devid) __attribute__((pure));
|
||||
const char *IN_GetDeviceId (int devid) __attribute__((pure));
|
||||
void IN_SetDeviceEventData (int devid, void *data);
|
||||
|
|
|
@ -30,9 +30,9 @@
|
|||
#define __QF_input_binding_h
|
||||
|
||||
#ifndef __QFCC__
|
||||
|
||||
#include "QF/listener.h"
|
||||
#include "QF/mathlib.h"
|
||||
#endif
|
||||
|
||||
/*** Recipe for converting an axis to a floating point value.
|
||||
|
||||
|
@ -86,17 +86,21 @@ typedef struct in_axis_s {
|
|||
in_axis_mode mode; ///< method used for updating the destination
|
||||
float abs_input; ///< input from an absolute axis (eg, joystick)
|
||||
float rel_input; ///< input from a relative axis (eg, mouse)
|
||||
#ifndef __QFCC__
|
||||
struct axis_listener_set_s *listeners;
|
||||
const char *name;
|
||||
const char *description;
|
||||
#endif
|
||||
} in_axis_t;
|
||||
|
||||
#ifndef __QFCC__
|
||||
typedef struct axis_listener_set_s LISTENER_SET_TYPE (in_axis_t)
|
||||
axis_listener_set_t;
|
||||
|
||||
/*** Function type for axis listeners.
|
||||
*/
|
||||
typedef void (*axis_listener_t) (void *data, const in_axis_t *axis);
|
||||
#endif
|
||||
|
||||
/*** Current state of the logical button.
|
||||
|
||||
|
@ -123,11 +127,14 @@ typedef enum {
|
|||
typedef struct in_button_s {
|
||||
int down[2]; ///< button ids holding this button down
|
||||
int state; ///< in_button_state
|
||||
#ifndef __QFCC__
|
||||
struct button_listener_set_s *listeners;
|
||||
const char *name;
|
||||
const char *description;
|
||||
#endif
|
||||
} in_button_t;
|
||||
|
||||
#ifndef __QFCC__
|
||||
typedef struct button_listener_set_s LISTENER_SET_TYPE (in_button_t)
|
||||
button_listener_set_t;
|
||||
|
||||
|
|
|
@ -38,7 +38,10 @@ struct cbuf_s;
|
|||
|
||||
void RUA_Init (struct progs_s *pr, int secure);
|
||||
void RUA_Cbuf_SetCbuf (struct progs_s *pr, struct cbuf_s *cbuf);
|
||||
func_t RUA_Obj_msg_lookup (struct progs_s *pr, pointer_t _self, pointer_t __cmd);
|
||||
func_t RUA_Obj_msg_lookup (struct progs_s *pr, pointer_t _self,
|
||||
pointer_t __cmd);
|
||||
|
||||
void RUA_Game_Init (struct progs_s *pr, int secure);
|
||||
|
||||
// self is expected in param 0
|
||||
int RUA_obj_increment_retaincount (struct progs_s *pr);
|
||||
|
|
|
@ -34,35 +34,24 @@
|
|||
#include "QF/quakeio.h"
|
||||
|
||||
void RUA_Cbuf_Init (struct progs_s *pr, int secure);
|
||||
|
||||
void RUA_Cmd_Init (struct progs_s *pr, int secure);
|
||||
|
||||
void RUA_Cvar_Init (struct progs_s *pr, int secure);
|
||||
|
||||
void RUA_Hash_Init (struct progs_s *pr, int secure);
|
||||
|
||||
void RUA_Math_Init (struct progs_s *pr, int secure);
|
||||
|
||||
void RUA_MsgBuf_Init (struct progs_s *pr, int secure);
|
||||
|
||||
void RUA_Obj_Init (struct progs_s *pr, int secure);
|
||||
|
||||
void RUA_Plist_Init (struct progs_s *pr, int secure);
|
||||
|
||||
void RUA_Runtime_Init (struct progs_s *pr, int secure);
|
||||
|
||||
void RUA_Script_Init (progs_t *pr, int secure);
|
||||
|
||||
void RUA_Set_Init (progs_t *pr, int secure);
|
||||
|
||||
void RUA_Stdlib_Init (struct progs_s *pr, int secure);
|
||||
|
||||
void RUA_String_Init (struct progs_s *pr, int secure);
|
||||
|
||||
void RUA_QFile_Init (struct progs_s *pr, int secure);
|
||||
void RUA_QFS_Init (struct progs_s *pr, int secure);
|
||||
|
||||
int QFile_AllocHandle (struct progs_s *pr, QFile *file);
|
||||
QFile *QFile_GetFile (struct progs_s *pr, int handle);
|
||||
|
||||
void RUA_QFS_Init (struct progs_s *pr, int secure);
|
||||
void RUA_Input_Init (struct progs_s *pr, int secure);
|
||||
|
||||
#endif//__rua_internal_h
|
||||
|
|
|
@ -597,10 +597,10 @@ Menu_Init (void)
|
|||
|
||||
PR_RegisterBuiltins (&menu_pr_state, builtins);
|
||||
|
||||
RUA_Init (&menu_pr_state, 1);
|
||||
RUA_Init (&menu_pr_state, 3);
|
||||
|
||||
InputLine_Progs_Init (&menu_pr_state);
|
||||
RUA_Key_Init (&menu_pr_state);
|
||||
RUA_Game_Init (&menu_pr_state, 1);
|
||||
GIB_Progs_Init (&menu_pr_state);
|
||||
PR_Cmds_Init (&menu_pr_state);
|
||||
R_Progs_Init (&menu_pr_state);
|
||||
|
|
|
@ -174,6 +174,17 @@ IN_SendConnectedDevices (void)
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
const char *
|
||||
IN_GetDeviceName (int devid)
|
||||
{
|
||||
|
|
|
@ -35,4 +35,5 @@ libs_ruamoko_libQFruamoko_client_la_DEPENDENCIES= \
|
|||
libs/ruamoko/libQFruamoko.la \
|
||||
$(ruamoko_rua_libs)
|
||||
libs_ruamoko_libQFruamoko_client_la_SOURCES= \
|
||||
libs/ruamoko/rua_keys.c
|
||||
libs/ruamoko/rua_game_init.c \
|
||||
libs/ruamoko/rua_input.c
|
||||
|
|
47
libs/ruamoko/rua_game_init.c
Normal file
47
libs/ruamoko/rua_game_init.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
bi_game_init.c
|
||||
|
||||
CSQC builtins init
|
||||
|
||||
Copyright (C) 2021 Bill Currie <bill@taniwha.org>
|
||||
|
||||
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
|
||||
|
||||
#include "QF/progs.h"
|
||||
#include "QF/ruamoko.h"
|
||||
|
||||
#include "rua_internal.h"
|
||||
|
||||
static void (*init_funcs[])(progs_t *, int) = {
|
||||
RUA_Input_Init,
|
||||
};
|
||||
|
||||
VISIBLE void
|
||||
RUA_Game_Init (progs_t *pr, int secure)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < sizeof (init_funcs) / sizeof (init_funcs[0]); i++)
|
||||
init_funcs[i] (pr, secure);
|
||||
}
|
205
libs/ruamoko/rua_input.c
Normal file
205
libs/ruamoko/rua_input.c
Normal file
|
@ -0,0 +1,205 @@
|
|||
/*
|
||||
bi_input.c
|
||||
|
||||
CSQC file builtins
|
||||
|
||||
Copyright (C) 2021 Bill Currie <bill@taniwha.org>
|
||||
|
||||
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
|
||||
|
||||
#include <stdlib.h>
|
||||
#ifdef HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
#endif
|
||||
|
||||
#include "QF/input.h"
|
||||
#include "QF/progs.h"
|
||||
|
||||
#include "rua_internal.h"
|
||||
|
||||
//typedef struct input_resources_s {
|
||||
//} input_resources_t;
|
||||
|
||||
static void
|
||||
bi_IN_FindDeviceId (progs_t *pr)
|
||||
{
|
||||
const char *id = P_GSTRING (pr, 0);
|
||||
|
||||
R_INT (pr) = IN_FindDeviceId (id);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_IN_GetDeviceName (progs_t *pr)
|
||||
{
|
||||
int devid = P_INT (pr, 0);
|
||||
|
||||
RETURN_STRING (pr, IN_GetDeviceName (devid));
|
||||
}
|
||||
|
||||
static void
|
||||
bi_IN_GetDeviceId (progs_t *pr)
|
||||
{
|
||||
int devid = P_INT (pr, 0);
|
||||
|
||||
RETURN_STRING (pr, IN_GetDeviceId (devid));
|
||||
}
|
||||
|
||||
static void
|
||||
bi_IN_AxisInfo (progs_t *pr)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
bi_IN_ButtonInfo (progs_t *pr)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
bi_IN_GetAxisName (progs_t *pr)
|
||||
{
|
||||
int devid = P_INT (pr, 0);
|
||||
int axis = P_INT (pr, 1);
|
||||
|
||||
RETURN_STRING (pr, IN_GetAxisName (devid, axis));
|
||||
}
|
||||
|
||||
static void
|
||||
bi_IN_GetButtonName (progs_t *pr)
|
||||
{
|
||||
int devid = P_INT (pr, 0);
|
||||
int button = P_INT (pr, 1);
|
||||
|
||||
RETURN_STRING (pr, IN_GetButtonName (devid, button));
|
||||
}
|
||||
|
||||
static void
|
||||
bi_IN_GetAxisNumber (progs_t *pr)
|
||||
{
|
||||
int devid = P_INT (pr, 0);
|
||||
const char *axis_name = P_GSTRING (pr, 1);
|
||||
|
||||
R_INT (pr) = IN_GetAxisNumber (devid, axis_name);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_IN_GetButtonNumber (progs_t *pr)
|
||||
{
|
||||
int devid = P_INT (pr, 0);
|
||||
const char *button_name = P_GSTRING (pr, 1);
|
||||
|
||||
R_INT (pr) = IN_GetButtonNumber (devid, button_name);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_IN_ProcessEvents (progs_t *pr)
|
||||
{
|
||||
IN_ProcessEvents ();
|
||||
}
|
||||
|
||||
static void
|
||||
bi_IN_ClearStates (progs_t *pr)
|
||||
{
|
||||
IN_ClearStates ();
|
||||
}
|
||||
|
||||
static void
|
||||
bi_IN_CreateButton (progs_t *pr)
|
||||
{
|
||||
const char *name = P_GSTRING (pr, 0);
|
||||
const char *desc = P_GSTRING (pr, 1);
|
||||
in_button_t *button = PR_Zone_Malloc (pr, sizeof (in_button_t));
|
||||
button->name = name;
|
||||
button->description = desc;
|
||||
IN_RegisterButton (button);
|
||||
RETURN_POINTER (pr, button);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_IN_CreateAxis (progs_t *pr)
|
||||
{
|
||||
const char *name = P_GSTRING (pr, 0);
|
||||
const char *desc = P_GSTRING (pr, 1);
|
||||
in_axis_t *axis = PR_Zone_Malloc (pr, sizeof (in_axis_t));
|
||||
axis->name = name;
|
||||
axis->description = desc;
|
||||
IN_RegisterAxis (axis);
|
||||
RETURN_POINTER (pr, axis);
|
||||
}
|
||||
|
||||
static void
|
||||
secured (progs_t *pr)
|
||||
{
|
||||
PR_RunError (pr, "Secured function called");
|
||||
}
|
||||
|
||||
#define bi(x) {#x, secured, -1}
|
||||
static builtin_t secure_builtins[] = {
|
||||
bi(IN_CreateButton),
|
||||
bi(IN_CreateAxis),
|
||||
{0}
|
||||
};
|
||||
|
||||
#undef bi
|
||||
#define bi(x) {#x, bi_##x, -1}
|
||||
static builtin_t insecure_builtins[] = {
|
||||
bi(IN_CreateButton),
|
||||
bi(IN_CreateAxis),
|
||||
{0}
|
||||
};
|
||||
static builtin_t builtins[] = {
|
||||
bi(IN_FindDeviceId),
|
||||
bi(IN_GetDeviceName),
|
||||
bi(IN_GetDeviceId),
|
||||
bi(IN_AxisInfo),
|
||||
bi(IN_ButtonInfo),
|
||||
bi(IN_GetAxisName),
|
||||
bi(IN_GetButtonName),
|
||||
bi(IN_GetAxisNumber),
|
||||
bi(IN_GetButtonNumber),
|
||||
bi(IN_ProcessEvents),
|
||||
bi(IN_ClearStates),
|
||||
{0}
|
||||
};
|
||||
|
||||
//static void
|
||||
//bi_input_clear (progs_t *pr, void *_res)
|
||||
//{
|
||||
//}
|
||||
|
||||
void
|
||||
RUA_Input_Init (progs_t *pr, int secure)
|
||||
{
|
||||
//input_resources_t *res = calloc (sizeof (input_resources_t), 1);
|
||||
//PR_Resources_Register (pr, "input", res, bi_input_clear);
|
||||
|
||||
if (secure & 2) {
|
||||
PR_RegisterBuiltins (pr, secure_builtins);
|
||||
} else {
|
||||
PR_RegisterBuiltins (pr, insecure_builtins);
|
||||
}
|
||||
PR_RegisterBuiltins (pr, builtins);
|
||||
}
|
|
@ -51,6 +51,7 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$";
|
|||
#include "QF/progs.h"
|
||||
#include "QF/quakefs.h"
|
||||
#include "QF/render.h"
|
||||
#include "QF/ruamoko.h"
|
||||
#include "QF/screen.h"
|
||||
#include "QF/sound.h"
|
||||
#include "QF/sys.h"
|
||||
|
@ -165,7 +166,7 @@ BI_Graphics_Init (progs_t *pr)
|
|||
Mod_Init ();
|
||||
R_Init ();
|
||||
R_Progs_Init (pr);
|
||||
RUA_Key_Init (pr);
|
||||
RUA_Game_Init (pr, thread->rua_security);
|
||||
S_Progs_Init (pr);
|
||||
|
||||
Con_Init ("client");
|
||||
|
|
Loading…
Reference in a new issue