48 lines
1 KiB
C
48 lines
1 KiB
C
#ifndef _fencer_input_h
|
|
#define _fencer_input_h
|
|
|
|
#include "list.h"
|
|
#include "input_axis.h"
|
|
#include <SDL2/SDL_events.h>
|
|
#include <SDL2/SDL_scancode.h>
|
|
#include <SDL2/SDL_keyboard.h>
|
|
#include <SDL2/SDL_gamecontroller.h>
|
|
|
|
struct PlayerInput;
|
|
|
|
typedef struct InputListener {
|
|
void* self;
|
|
InputDelegateFn fn;
|
|
InputAxis axis;
|
|
} InputListener;
|
|
|
|
typedef enum InputDeviceType {
|
|
InputDevice_Gamepad,
|
|
InputDevice_KBM
|
|
} InputDeviceType;
|
|
|
|
typedef struct InputDevice {
|
|
List* listeners;
|
|
InputDeviceType type;
|
|
int id;
|
|
union {
|
|
struct {
|
|
const uint8_t* state;
|
|
} keyboard;
|
|
struct {
|
|
SDL_JoystickID id;
|
|
SDL_GameController* controller;
|
|
} gamepad;
|
|
};
|
|
} InputDevice;
|
|
|
|
extern void input_init();
|
|
extern void input_clean();
|
|
|
|
// handle an input event
|
|
extern void input_handle_event(SDL_Event event);
|
|
extern void input_device_set_listeners(InputDevice* self, List* listeners);
|
|
extern InputDevice* input_get_device_by_id(int id);
|
|
|
|
#endif // !_fencer_input_h
|