typedef & PascalCase for ALL structs and enums
This commit is contained in:
@@ -12,16 +12,16 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
enum button_source {
|
||||
typedef enum ButtonSource {
|
||||
BUTTON_SOURCE_NOT_SET,
|
||||
BUTTON_SOURCE_KEYBOARD_PHYSICAL,
|
||||
BUTTON_SOURCE_KEYBOARD_CHARACTER,
|
||||
BUTTON_SOURCE_GAMEPAD,
|
||||
BUTTON_SOURCE_MOUSE,
|
||||
};
|
||||
} ButtonSource;
|
||||
|
||||
|
||||
union button_code {
|
||||
union ButtonCode {
|
||||
SDL_Scancode scancode;
|
||||
SDL_Keycode keycode;
|
||||
SDL_GameControllerButton gamepad_button;
|
||||
@@ -31,71 +31,71 @@ union button_code {
|
||||
|
||||
/* an input to which an action is bound */
|
||||
/* it is not limited to literal buttons */
|
||||
struct button {
|
||||
enum button_source source;
|
||||
union button_code code;
|
||||
};
|
||||
typedef struct Button {
|
||||
enum ButtonSource source;
|
||||
union ButtonCode code;
|
||||
} Button;
|
||||
|
||||
|
||||
/* represents the collective state of a group of buttons */
|
||||
/* that is, changes in the states of any of the bound buttons will affect it */
|
||||
struct action {
|
||||
typedef struct Action {
|
||||
size_t num_bindings;
|
||||
|
||||
/* if you bind more than NUM_KEYBIND_SLOTS (set in config.h) */
|
||||
/* it forgets the first button to add the new one at the end */
|
||||
struct button bindings[NUM_KEYBIND_SLOTS];
|
||||
/* it forgets the first Button to add the new one at the end */
|
||||
Button bindings[NUM_KEYBIND_SLOTS];
|
||||
|
||||
t_fvec2 position; /* set if applicable, e.g. mouse click */
|
||||
Vec2 position; /* set if applicable, e.g. mouse click */
|
||||
bool is_pressed;
|
||||
bool just_changed;
|
||||
};
|
||||
} Action;
|
||||
|
||||
|
||||
struct action_hash_item {
|
||||
typedef struct ActionHashItem {
|
||||
char *key;
|
||||
struct action value;
|
||||
};
|
||||
Action value;
|
||||
} ActionHashItem;
|
||||
|
||||
|
||||
struct input_state {
|
||||
struct action_hash_item *action_hash;
|
||||
typedef struct InputState {
|
||||
ActionHashItem *action_hash;
|
||||
const uint8_t *keyboard_state; /* array of booleans indexed by scancode */
|
||||
uint32_t mouse_state; /* SDL mouse button bitmask */
|
||||
t_vec2 mouse_window_position;
|
||||
t_vec2 mouse_relative_position;
|
||||
enum button_source last_active_source;
|
||||
Vec2i mouse_window_position;
|
||||
Vec2i mouse_relative_position;
|
||||
ButtonSource last_active_source;
|
||||
bool is_anything_just_pressed;
|
||||
};
|
||||
} InputState;
|
||||
|
||||
|
||||
TWN_API void input_state_init(struct input_state *input);
|
||||
TWN_API void input_state_deinit(struct input_state *input);
|
||||
TWN_API void input_state_update(struct input_state *input);
|
||||
TWN_API void input_state_init(InputState *input);
|
||||
TWN_API void input_state_deinit(InputState *input);
|
||||
TWN_API void input_state_update(InputState *input);
|
||||
|
||||
TWN_API void input_bind_action_scancode(struct input_state *input,
|
||||
TWN_API void input_bind_action_scancode(InputState *input,
|
||||
char *action_name,
|
||||
SDL_Scancode scancode);
|
||||
TWN_API void input_unbind_action_scancode(struct input_state *input,
|
||||
TWN_API void input_unbind_action_scancode(InputState *input,
|
||||
char *action_name,
|
||||
SDL_Scancode scancode);
|
||||
TWN_API void input_bind_action_mouse(struct input_state *input,
|
||||
TWN_API void input_bind_action_mouse(InputState *input,
|
||||
char *action_name,
|
||||
uint8_t mouse_button);
|
||||
TWN_API void input_unbind_action_mouse(struct input_state *input,
|
||||
TWN_API void input_unbind_action_mouse(InputState *input,
|
||||
char *action_name,
|
||||
uint8_t mouse_button);
|
||||
|
||||
TWN_API void input_add_action(struct input_state *input, char *action_name);
|
||||
TWN_API void input_delete_action(struct input_state *input, char *action_name);
|
||||
TWN_API void input_add_action(InputState *input, char *action_name);
|
||||
TWN_API void input_delete_action(InputState *input, char *action_name);
|
||||
|
||||
TWN_API bool input_is_action_pressed(struct input_state *input, char *action_name);
|
||||
TWN_API bool input_is_action_just_pressed(struct input_state *input, char *action_name);
|
||||
TWN_API bool input_is_action_just_released(struct input_state *input, char *action_name);
|
||||
TWN_API bool input_is_action_pressed(InputState *input, char *action_name);
|
||||
TWN_API bool input_is_action_just_pressed(InputState *input, char *action_name);
|
||||
TWN_API bool input_is_action_just_released(InputState *input, char *action_name);
|
||||
|
||||
TWN_API t_fvec2 input_get_action_position(struct input_state *input, char *action_name);
|
||||
TWN_API Vec2 input_get_action_position(InputState *input, char *action_name);
|
||||
|
||||
TWN_API void input_set_mouse_captured(struct input_state *input, bool value);
|
||||
TWN_API bool input_is_mouse_captured(struct input_state *input);
|
||||
TWN_API void input_set_mouse_captured(InputState *input, bool value);
|
||||
TWN_API bool input_is_mouse_captured(InputState *input);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user