diff --git a/src/ecs.c b/src/ecs.c index 1227a57..557b156 100644 --- a/src/ecs.c +++ b/src/ecs.c @@ -12,27 +12,27 @@ int create_component(component_t *component, va_list args) return EXIT_FAILURE; } - component->component_type = va_arg(args, component_type_t); + component->type = va_arg(args, component_type_t); - switch(component->component_type) + switch(component->type) { #define COMPONENT(NAME, PREFIX, DRAW) \ case NAME: \ - component->component_init = PREFIX##_init; \ - component->component_update = PREFIX##_update; \ - component->component_draw = DRAW(PREFIX); \ - component->component_data = malloc(sizeof(PREFIX##_data_t)); \ - if(!component->component_data) \ + component->init = PREFIX##_init; \ + component->update = PREFIX##_update; \ + component->draw = DRAW(PREFIX); \ + component->data = malloc(sizeof(PREFIX##_data_t)); \ + if(!component->data) \ { \ error_printf("Failed to allocate memory : %d", errno); \ return EXIT_FAILURE; \ } \ - component->component_deleter = PREFIX##_destroy; \ + component->deleter = PREFIX##_destroy; \ break; #include "components.def" default: - error_printf("Component type doesn't exists : %d", component->component_type); + error_printf("Component type doesn't exists : %d", component->type); return EXIT_FAILURE; } @@ -47,7 +47,7 @@ inline int destroy_component(component_t *component) return EXIT_FAILURE; } - if(component->component_deleter(component)) return EXIT_FAILURE; + if(component->deleter(component)) return EXIT_FAILURE; return EXIT_SUCCESS; } @@ -89,7 +89,7 @@ component_t *entity_new_component(entity_t *entity, component_type_t component_t component->entity = entity; - if(component->component_init(component)) return NULL; + if(component->init(component)) return NULL; if(linked_list_push_front(&entity->components, component_elem)) return NULL; @@ -100,7 +100,7 @@ component_t *entity_new_component(entity_t *entity, component_type_t component_t // Arg : component_type_t component_type static inline bool condition_is_component_type(elem_t *elem, va_list args) { - return ((component_t *)elem->data)->component_type == va_arg(args, component_type_t); + return ((component_t *)elem->data)->type == va_arg(args, component_type_t); } inline component_t *entity_get_component(entity_t *entity, component_type_t component_type) @@ -122,7 +122,7 @@ inline component_t *entity_get_component(entity_t *entity, component_type_t comp static inline int action_update_component(elem_t *elem, va_list args __attribute__((unused))) { component_t *component = elem->data; - if(component->component_update(component)) return EXIT_FAILURE; + if(component->update(component)) return EXIT_FAILURE; return EXIT_SUCCESS; } @@ -139,7 +139,7 @@ inline int update_entity(entity_t *entity) static inline int action_draw_component(elem_t *elem, va_list args __attribute__((unused))) { component_t *component = elem->data; - if(component->component_draw) if(component->component_draw(component)) return EXIT_FAILURE; + if(component->draw) if(component->draw(component)) return EXIT_FAILURE; return EXIT_SUCCESS; } diff --git a/src/headers/ecs.h b/src/headers/ecs.h index 0c8319e..1f9d6e1 100644 --- a/src/headers/ecs.h +++ b/src/headers/ecs.h @@ -23,17 +23,17 @@ typedef int (*component_draw_t)(component_t *component); typedef int (*component_deleter_t)(component_t *component); typedef struct component_t { - component_init_t component_init; - component_update_t component_update; - component_draw_t component_draw; + component_init_t init; + component_update_t update; + component_draw_t draw; - void *component_data; + void *data; - component_deleter_t component_deleter; + component_deleter_t deleter; struct entity_t *entity; - component_type_t component_type; + component_type_t type; } component_t;