[input] Allow buttons and axes to be deregistered

This is used by the Ruamoko input bindings so progs can clean up.
This commit is contained in:
Bill Currie 2023-09-15 14:00:37 +09:00
parent 5e041ef3f8
commit 1a36d3786d
3 changed files with 30 additions and 0 deletions

View file

@ -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);

View file

@ -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)
{

View file

@ -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)
{