From 1a36d3786d627799a63c2404be06bfbc7acc9203 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 15 Sep 2023 14:00:37 +0900 Subject: [PATCH] [input] Allow buttons and axes to be deregistered This is used by the Ruamoko input bindings so progs can clean up. --- include/QF/input/binding.h | 2 ++ libs/input/in_axis.c | 12 ++++++++++++ libs/input/in_button.c | 16 ++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/include/QF/input/binding.h b/include/QF/input/binding.h index fec91e9ce..d5b6cd6d5 100644 --- a/include/QF/input/binding.h +++ b/include/QF/input/binding.h @@ -349,8 +349,10 @@ IN_ClampAxis (in_axis_t *axis, float minval, float maxval) void IN_ButtonAction (in_button_t *buttin, int id, int pressed); int IN_RegisterButton (in_button_t *button); +int IN_UnregisterButton (in_button_t *button); void IN_ButtonInit (void); int IN_RegisterAxis (in_axis_t *axis); +int IN_UnregisterAxis (in_axis_t *axis); void IN_AxisInit (void); in_button_t *IN_FindButton (const char *name); void IN_ButtonClearStates (void); diff --git a/libs/input/in_axis.c b/libs/input/in_axis.c index 122b36d9e..51a3b787e 100644 --- a/libs/input/in_axis.c +++ b/libs/input/in_axis.c @@ -69,6 +69,18 @@ IN_RegisterAxis (in_axis_t *axis) return 1; } +VISIBLE int +IN_UnregisterAxis (in_axis_t *axis) +{ + const char *name = axis->name; + if (!Hash_Find (axis_tab, name)) { + return 0; + } + + Hash_Free (axis_tab, Hash_Del (axis_tab, name)); + return 1; +} + VISIBLE in_axis_t * IN_FindAxis (const char *name) { diff --git a/libs/input/in_button.c b/libs/input/in_button.c index f79d1ceaa..74e1551b7 100644 --- a/libs/input/in_button.c +++ b/libs/input/in_button.c @@ -63,6 +63,9 @@ static void button_free (void *b, void *data) { regbutton_t *rb = b; + + Cmd_RemoveCommand (rb->release_cmd); + Cmd_RemoveCommand (rb->press_cmd); if (rb->button->listeners) { DARRAY_CLEAR (rb->button->listeners); free (rb->button->listeners); @@ -197,6 +200,19 @@ IN_RegisterButton (in_button_t *button) return 1; } +VISIBLE int +IN_UnregisterButton (in_button_t *button) +{ + const char *name = button->name; + regbutton_t *regbutton = Hash_Find (button_tab, name); + if (!regbutton) { + return 0; + } + + Hash_Free (button_tab, Hash_Del (button_tab, name)); + return 1; +} + in_button_t * IN_FindButton (const char *name) {