[input] Move name and description into in_axis_t

Like with in_button_t, it makes creating static axes a little easier.
This commit is contained in:
Bill Currie 2021-11-10 15:48:22 +09:00
parent b231b63413
commit 9172e76107
2 changed files with 14 additions and 19 deletions

View file

@ -63,6 +63,8 @@ typedef enum {
typedef struct in_axis_s {
float value; ///< converted value of the axis
in_axis_mode mode; ///< method used for updating the destination
const char *name;
const char *description;
} in_axis_t;
/*** Current state of the logical button.
@ -95,7 +97,10 @@ typedef struct in_button_s {
} in_button_t;
typedef struct in_axisbinding_s {
in_recipe_t *recipe;
union {
in_recipe_t *recipe;///< for absolute axes
float scale; ///< for relative axes
};
in_axis_t *axis;
} in_axisbinding_t;
@ -210,8 +215,7 @@ IN_ButtonReleased (in_button_t *button)
void IN_ButtonAction (in_button_t *buttin, int id, int pressed);
int IN_RegisterButton (in_button_t *button);
int IN_RegisterAxis (in_axis_t *axis, const char *name,
const char *description);
int IN_RegisterAxis (in_axis_t *axis);
in_button_t *IN_FindButton (const char *name);
void IN_Binding_Init (void);

View file

@ -43,38 +43,29 @@
#include "QF/input.h"
#include "QF/sys.h"
typedef struct regaxis_s {
const char *name;
const char *description;
in_axis_t *axis;
} regaxis_t;
static hashtab_t *axis_tab;
static const char *
axis_get_key (const void *b, void *data)
axis_get_key (const void *a, void *data)
{
__auto_type regaxis = (const regaxis_t *) b;
return regaxis->name;
__auto_type axis = (const in_axis_t *) a;
return axis->name;
}
static void
axis_free (void *b, void *data)
axis_free (void *a, void *data)
{
free (b);
}
VISIBLE int
IN_RegisterAxis (in_axis_t *axis, const char *name, const char *description)
IN_RegisterAxis (in_axis_t *axis)
{
const char *name = axis->name;
if (Hash_Find (axis_tab, name)) {
return 0;
}
regaxis_t *regaxis = malloc (sizeof (regaxis_t));
regaxis->name = name;
regaxis->description = description;
regaxis->axis = axis;
Hash_Add (axis_tab, axis);
return 1;
}