2024-03-01 14:37:59 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Types of input the player might want
|
|
|
|
typedef enum {
|
|
|
|
input_Key_Left,
|
|
|
|
input_Key_Right,
|
|
|
|
input_Key_Up,
|
|
|
|
input_Key_Down,
|
|
|
|
input_Key_Jump,
|
|
|
|
input_Key_Attack,
|
|
|
|
input_Key_Spell,
|
|
|
|
input_Key_Use,
|
|
|
|
input_Key_Count
|
|
|
|
} input_Key;
|
|
|
|
|
2024-03-01 16:15:21 +08:00
|
|
|
// Names for input_Key
|
|
|
|
const char *input_KeyNames[input_Key_Count] = {
|
|
|
|
"Left",
|
|
|
|
"Right",
|
|
|
|
"Up",
|
|
|
|
"Down",
|
|
|
|
"Jump",
|
|
|
|
"Attack",
|
|
|
|
"Spell",
|
|
|
|
"Use"};
|
|
|
|
|
|
|
|
|
2024-03-01 14:37:59 +08:00
|
|
|
// States a key might in
|
|
|
|
typedef enum {
|
|
|
|
Pressed,
|
|
|
|
JustPressed,
|
|
|
|
Released,
|
|
|
|
JustReleased
|
|
|
|
} input_KeyState;
|
|
|
|
|
2024-03-01 16:15:21 +08:00
|
|
|
static inline bool input_IsPressed(input_KeyState state) { return state == Pressed || state == JustPressed; }
|
|
|
|
static inline bool input_IsReleased(input_KeyState state) { return state == Released || state == JustReleased; }
|
|
|
|
|
|
|
|
|
2024-03-01 17:09:24 +08:00
|
|
|
typedef struct _App App;
|
|
|
|
|
2024-03-01 14:37:59 +08:00
|
|
|
typedef struct {
|
2024-03-01 17:09:24 +08:00
|
|
|
App *super;
|
|
|
|
|
2024-03-01 16:15:21 +08:00
|
|
|
input_KeyState keys[input_Key_Count]; // States of keys
|
|
|
|
unsigned int systemKeymap[input_Key_Count]; // Which system key (VK code) this function uses
|
|
|
|
// https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
|
2024-03-01 14:37:59 +08:00
|
|
|
} System_Input;
|
|
|
|
|
|
|
|
|
2024-03-01 16:15:21 +08:00
|
|
|
// Creates a new input system.
|
|
|
|
// Uses a default keymap
|
2024-03-01 17:09:24 +08:00
|
|
|
System_Input *input_NewSystem(App *super);
|
2024-03-01 16:15:21 +08:00
|
|
|
void input_DeleteSystem(System_Input *sys);
|
|
|
|
|
|
|
|
// Sets the keymaps to default.
|
|
|
|
void input_SetDefaultKeymap(System_Input *sys);
|
|
|
|
|
|
|
|
// Update key states
|
|
|
|
void input_Advance(System_Input *sys);
|
|
|
|
|
|
|
|
|
2024-03-01 14:37:59 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|