typedef & PascalCase for ALL structs and enums

This commit is contained in:
2024-09-23 14:43:16 -03:00
parent e093a6d492
commit 73bf92e706
43 changed files with 795 additions and 793 deletions

View File

@ -8,7 +8,7 @@
#include <stdlib.h>
static void update_action_pressed_state(struct input_state *input, struct action *action) {
static void update_action_pressed_state(InputState *input, Action *action) {
for (size_t i = 0; i < SDL_arraysize(action->bindings); ++i) {
switch (action->bindings[i].source) {
case BUTTON_SOURCE_NOT_SET:
@ -61,21 +61,21 @@ static void update_action_pressed_state(struct input_state *input, struct action
}
static void input_bind_code_to_action(struct input_state *input,
static void input_bind_code_to_action(InputState *input,
char *action_name,
enum button_source source,
union button_code code)
ButtonSource source,
union ButtonCode code)
{
struct action_hash_item *action_item = shgetp_null(input->action_hash, action_name);
ActionHashItem *action_item = shgetp_null(input->action_hash, action_name);
if (action_item == NULL) {
log_warn("(%s) Action \"%s\" does not exist.", __func__, action_name);
return;
}
struct action *action = &action_item->value;
Action *action = &action_item->value;
/* check every binding to make sure this code isn't already bound */
for (size_t i = 0; i < SDL_arraysize(action->bindings); ++i) {
struct button *binding = &action->bindings[i];
Button *binding = &action->bindings[i];
if (binding->source != source)
break;
@ -111,30 +111,30 @@ static void input_bind_code_to_action(struct input_state *input,
memmove(action->bindings, action->bindings + 1, shifted_size);
}
action->bindings[action->num_bindings++] = (struct button) {
action->bindings[action->num_bindings++] = (Button) {
.source = source,
.code = code,
};
}
static void input_unbind_code_from_action(struct input_state *input,
static void input_unbind_code_from_action(InputState *input,
char *action_name,
enum button_source source,
union button_code code)
ButtonSource source,
union ButtonCode code)
{
struct action_hash_item *action_item = shgetp_null(input->action_hash, action_name);
ActionHashItem *action_item = shgetp_null(input->action_hash, action_name);
if (action_item == NULL) {
log_warn("(%s) Action \"%s\" does not exist.", __func__, action_name);
return;
}
struct action *action = &action_item->value;
Action *action = &action_item->value;
/* check every binding to make sure this code is bound */
size_t index = 0;
bool is_bound = false;
for (index = 0; index < SDL_arraysize(action->bindings); ++index) {
struct button *binding = &action->bindings[index];
Button *binding = &action->bindings[index];
if (binding->source != source)
continue;
@ -174,17 +174,17 @@ static void input_unbind_code_from_action(struct input_state *input,
}
void input_state_init(struct input_state *input) {
void input_state_init(InputState *input) {
sh_new_strdup(input->action_hash);
}
void input_state_deinit(struct input_state *input) {
void input_state_deinit(InputState *input) {
shfree(input->action_hash);
}
void input_state_update(struct input_state *input) {
void input_state_update(InputState *input) {
input->keyboard_state = SDL_GetKeyboardState(NULL);
input->mouse_state = SDL_GetMouseState(&input->mouse_window_position.x,
&input->mouse_window_position.y);
@ -193,74 +193,74 @@ void input_state_update(struct input_state *input) {
&input->mouse_relative_position.y);
for (size_t i = 0; i < shlenu(input->action_hash); ++i) {
struct action *action = &input->action_hash[i].value;
Action *action = &input->action_hash[i].value;
update_action_pressed_state(input, action);
}
}
void input_bind_action_scancode(struct input_state *input,
void input_bind_action_scancode(InputState *input,
char *action_name,
SDL_Scancode scancode)
{
input_bind_code_to_action(input,
action_name,
BUTTON_SOURCE_KEYBOARD_PHYSICAL,
(union button_code) { .scancode = scancode });
(union ButtonCode) { .scancode = scancode });
}
void input_unbind_action_scancode(struct input_state *input,
void input_unbind_action_scancode(InputState *input,
char *action_name,
SDL_Scancode scancode)
{
input_unbind_code_from_action(input,
action_name,
BUTTON_SOURCE_KEYBOARD_PHYSICAL,
(union button_code) { .scancode = scancode });
(union ButtonCode) { .scancode = scancode });
}
void input_bind_action_mouse(struct input_state *input,
void input_bind_action_mouse(InputState *input,
char *action_name,
uint8_t mouse_button)
{
input_bind_code_to_action(input,
action_name,
BUTTON_SOURCE_MOUSE,
(union button_code) { .mouse_button = mouse_button});
(union ButtonCode) { .mouse_button = mouse_button});
}
void input_unbind_action_mouse(struct input_state *input,
void input_unbind_action_mouse(InputState *input,
char *action_name,
uint8_t mouse_button)
{
input_unbind_code_from_action(input,
action_name,
BUTTON_SOURCE_MOUSE,
(union button_code) { .mouse_button = mouse_button});
(union ButtonCode) { .mouse_button = mouse_button});
}
void input_add_action(struct input_state *input, char *action_name) {
void input_add_action(InputState *input, char *action_name) {
if (shgeti(input->action_hash, action_name) >= 0) {
log_warn("(%s) Action \"%s\" is already registered.", __func__, action_name);
return;
}
shput(input->action_hash, action_name, (struct action) { 0 });
shput(input->action_hash, action_name, (Action) { 0 });
}
void input_delete_action(struct input_state *input, char *action_name) {
void input_delete_action(InputState *input, char *action_name) {
if (shdel(input->action_hash, action_name) == 0)
log_warn("(%s) Action \"%s\" is not registered.", __func__, action_name);
}
bool input_is_action_pressed(struct input_state *input, char *action_name) {
struct action_hash_item *action = shgetp_null(input->action_hash, action_name);
bool input_is_action_pressed(InputState *input, char *action_name) {
ActionHashItem *action = shgetp_null(input->action_hash, action_name);
if (action == NULL) {
log_warn("(%s) Action \"%s\" does not exist.", __func__, action_name);
return false;
@ -269,8 +269,8 @@ bool input_is_action_pressed(struct input_state *input, char *action_name) {
}
bool input_is_action_just_pressed(struct input_state *input, char *action_name) {
struct action_hash_item *action = shgetp_null(input->action_hash, action_name);
bool input_is_action_just_pressed(InputState *input, char *action_name) {
ActionHashItem *action = shgetp_null(input->action_hash, action_name);
if (action == NULL) {
log_warn("(%s) Action \"%s\" does not exist.", __func__, action_name);
return false;
@ -279,8 +279,8 @@ bool input_is_action_just_pressed(struct input_state *input, char *action_name)
}
bool input_is_action_just_released(struct input_state *input, char *action_name) {
struct action_hash_item *action = shgetp_null(input->action_hash, action_name);
bool input_is_action_just_released(InputState *input, char *action_name) {
ActionHashItem *action = shgetp_null(input->action_hash, action_name);
if (action == NULL) {
log_warn("(%s) Action \"%s\" does not exist.", __func__, action_name);
return false;
@ -289,30 +289,30 @@ bool input_is_action_just_released(struct input_state *input, char *action_name)
}
t_fvec2 input_get_action_position(struct input_state *input, char *action_name) {
struct action_hash_item *action = shgetp_null(input->action_hash, action_name);
Vec2 input_get_action_position(InputState *input, char *action_name) {
ActionHashItem *action = shgetp_null(input->action_hash, action_name);
if (action == NULL) {
log_warn("(%s) Action \"%s\" does not exist.", __func__, action_name);
return (t_fvec2) { 0 };
return (Vec2) { 0 };
}
return action->value.position;
}
void input_set_mouse_captured(struct input_state *input, bool enabled) {
void input_set_mouse_captured(InputState *input, bool enabled) {
(void)input;
/* TODO: returns -1 if not supported, but like... do we care? */
SDL_SetRelativeMouseMode(enabled);
}
bool input_is_mouse_captured(struct input_state *input) {
bool input_is_mouse_captured(InputState *input) {
(void)input;
return SDL_GetRelativeMouseMode();
}
void input_reset_state(struct input_state *input) {
void input_reset_state(InputState *input) {
stbds_shfree(input->action_hash);
}