[input] Clean up imt.h a little

Unnecessary enum removed, and the imt block struct moved to imt.c
(doesn't need to be public). Also, remove device name from the imt block
(and thus the parameter to the functions) as it turns out not to be
needed.
This commit is contained in:
Bill Currie 2021-11-09 22:23:57 +09:00
parent 620ea30683
commit 5328c06fbf
2 changed files with 22 additions and 49 deletions

View file

@ -36,26 +36,6 @@
#include "QF/input/binding.h"
typedef enum {
imt_button,
imt_axis,
} imt_type;
/** Describe a region of imt bindings (axis or button)
Each device may have a block of axis bindings and a block of button
bindings (some devices will have only the one block). The device name is
used instead of a pointer to the device descriptor so configs can be
preserved even if the device is not present.
Bindings are allocated to a device in contiguous blocks.
*/
typedef struct imt_block_s {
const char *device; ///< name of the owning device
int base; ///< index of first binding
int count; ///< number of bindings
} imt_block_t;
/** Input Mapping Table
*/
typedef struct imt_s {
@ -76,8 +56,8 @@ typedef struct in_context_s {
struct cbuf_s *cbuf;
} in_context_t;
int IMT_GetAxisBlock (const char *device, int num_axes);
int IMT_GetButtonBlock (const char *device, int num_buttons);
int IMT_GetAxisBlock (int num_axes);
int IMT_GetButtonBlock (int num_buttons);
int IMT_CreateContext (const char *name);
int IMT_GetContext (void);
void IMT_SetContext (int ctx);

View file

@ -50,6 +50,18 @@
#include "QF/input/binding.h"
#include "QF/input/imt.h"
/** Describe a region of imt bindings (axis or button)
Each device may have a block of axis bindings and a block of button
bindings (some devices will have only the one block).
Bindings are allocated to a device in contiguous blocks.
*/
typedef struct imt_block_s {
int base; ///< index of first binding
int count; ///< number of bindings
} imt_block_t;
typedef struct DARRAY_TYPE (in_context_t) in_contextset_t;
typedef struct DARRAY_TYPE (imt_block_t) imt_blockset_t;
/** Binding blocks are allocated across all imts
@ -99,17 +111,6 @@ free_button_binding (in_buttonbinding_t *binding)
cmemfree (binding_mem, binding);
}
static imt_block_t * __attribute__((pure))
imt_find_block (imt_blockset_t *blockset, const char *device)
{
for (size_t i = 0; i < blockset->size; i++) {
if (strcmp (blockset->a[i].device, device) == 0) {
return &blockset->a[i];
}
}
return 0;
}
static imt_block_t *
imt_get_block (imt_blockset_t *blockset)
{
@ -157,28 +158,20 @@ imt_get_button_block (int count)
}
int
IMT_GetAxisBlock (const char *device, int num_axes)
IMT_GetAxisBlock (int num_axes)
{
imt_block_t *block;
if (!(block = imt_find_block (&axis_blocks, device))) {
block = imt_get_block (&axis_blocks);
block->device = device;
imt_block_t *block = imt_get_block (&axis_blocks);
block->base = imt_get_axis_block (num_axes);
block->count = num_axes;
}
return block - axis_blocks.a;
}
int
IMT_GetButtonBlock (const char *device, int num_buttons)
IMT_GetButtonBlock (int num_buttons)
{
imt_block_t *block;
if (!(block = imt_find_block (&button_blocks, device))) {
block = imt_get_block (&button_blocks);
block->device = device;
imt_block_t *block = imt_get_block (&button_blocks);
block->base = imt_get_button_block (num_buttons);
block->count = num_buttons;
}
return block - button_blocks.a;
}