Beginning input refactor
This commit is contained in:
@@ -8,23 +8,60 @@
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
typedef uint8_t inputbind_t;
|
||||
typedef inputbind_t inputstate_t;
|
||||
#if INPUT_SDL2 == 1
|
||||
#include <SDL2/SDL.h>
|
||||
#else
|
||||
#error "No input backend defined"
|
||||
#endif
|
||||
|
||||
#define INPUT_BIND_UP (1 << 0)
|
||||
#define INPUT_BIND_DOWN (1 << 1)
|
||||
#define INPUT_BIND_LEFT (1 << 2)
|
||||
#define INPUT_BIND_RIGHT (1 << 3)
|
||||
#define INPUT_BIND_ACTION (1 << 4)
|
||||
#define INPUT_BIND_CANCEL (1 << 5)
|
||||
#define INPUT_BIND_CONSOLE (1 << 6)
|
||||
#define INPUT_BIND_QUIT (1 << 7)
|
||||
// Keyboard defs
|
||||
#if INPUT_KEYBOARD == 1
|
||||
#define INPUT_BIND_KEYBOARD_BUTTONS_MAX 32
|
||||
|
||||
#define INPUT_BIND_COUNT (INPUT_BIND_QUIT + 1)
|
||||
#if INPUT_SDL2 == 1
|
||||
typedef SDL_Scancode inputscancode_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Gamepad defs
|
||||
#if INPUT_GAMEPAD == 1
|
||||
#define INPUT_GAMEPAD_BUTTON_NAME_MAX 8
|
||||
#define INPUT_BIND_GAMEPAD_BUTTONS_MAX 8
|
||||
|
||||
#if INPUT_SDL2 == 1
|
||||
typedef SDL_GameControllerButton inputgamepadbutton_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
INPUT_BIND_UP,
|
||||
INPUT_BIND_DOWN,
|
||||
INPUT_BIND_LEFT,
|
||||
INPUT_BIND_RIGHT,
|
||||
INPUT_BIND_ACCEPT,
|
||||
INPUT_BIND_CANCEL,
|
||||
INPUT_BIND_CONSOLE,
|
||||
|
||||
INPUT_BIND_COUNT
|
||||
} inputbind_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t current;
|
||||
uint8_t previous;
|
||||
inputbind_t bind;
|
||||
float_t lastValue;
|
||||
float_t currentValue;
|
||||
|
||||
#if INPUT_GAMEPAD == 1
|
||||
inputgamepadbutton_t gamepad[INPUT_BIND_GAMEPAD_BUTTONS_MAX];
|
||||
uint8_t gamepadButtonCount;
|
||||
#endif
|
||||
|
||||
#if INPUT_KEYBOARD == 1
|
||||
inputscancode_t keyboard[INPUT_BIND_KEYBOARD_BUTTONS_MAX];
|
||||
#endif
|
||||
} inputbinddata_t;
|
||||
|
||||
typedef struct {
|
||||
inputbinddata_t binds[INPUT_BIND_COUNT];
|
||||
} input_t;
|
||||
|
||||
extern input_t INPUT;
|
||||
@@ -40,11 +77,20 @@ void inputInit(void);
|
||||
void inputUpdate(void);
|
||||
|
||||
/**
|
||||
* Gets the current input state as a bitmask.
|
||||
* Gets the current value of a specific input bind.
|
||||
*
|
||||
* @return The current input state as a bitmask.
|
||||
* @param bind The input bind to get the value for.
|
||||
* @return The current value of the bind (0.0f to 1.0f).
|
||||
*/
|
||||
inputstate_t inputStateGet(void);
|
||||
float_t inputGetCurrentValue(const inputbind_t bind);
|
||||
|
||||
/**
|
||||
* Gets the last value of a specific input bind.
|
||||
*
|
||||
* @param bind The input bind to get the value for.
|
||||
* @return The last value of the bind (0.0f to 1.0f).
|
||||
*/
|
||||
float_t inputGetLast(const inputbind_t bind);
|
||||
|
||||
/**
|
||||
* Checks if a specific input bind is currently pressed.
|
||||
|
Reference in New Issue
Block a user