From 46682c00e2c533d0559d964afd94e37473b2c6f3 Mon Sep 17 00:00:00 2001 From: Ulysse Cura Date: Wed, 5 Aug 2026 23:19:48 +0200 Subject: [PATCH] Reorganised headers to match design choices and component creation order for correct update order. --- src/components/headers/components.h | 4 ++-- src/components/headers/hitbox_component.h | 1 + src/components/headers/player_system.h | 4 ++-- src/components/headers/transform_component.h | 1 + src/components/hitbox_component.c | 2 +- src/components/physics_system.c | 2 +- src/components/player_system.c | 2 +- src/components/sprite_component.c | 4 ++-- src/components/transform_component.c | 2 +- src/game.c | 7 +++---- 10 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/components/headers/components.h b/src/components/headers/components.h index e4215a8..0558970 100644 --- a/src/components/headers/components.h +++ b/src/components/headers/components.h @@ -2,10 +2,10 @@ #define COMPONENTS_H #include "transform_component.h" -#include "hitbox_component.h" -#include "physics_system.h" #include "sprite_component.h" #include "animation_system.h" +#include "hitbox_component.h" +#include "physics_system.h" #include "player_system.h" // Add new components header file here diff --git a/src/components/headers/hitbox_component.h b/src/components/headers/hitbox_component.h index 67d1f94..b303082 100644 --- a/src/components/headers/hitbox_component.h +++ b/src/components/headers/hitbox_component.h @@ -5,6 +5,7 @@ #include "ecs.h" #include "transform_component.h" #include "vector2d.h" +#include "errors.h" typedef struct hitbox_component_data_t { transform_component_data_t *transform_component_data; diff --git a/src/components/headers/player_system.h b/src/components/headers/player_system.h index 39f1234..9ac29fa 100644 --- a/src/components/headers/player_system.h +++ b/src/components/headers/player_system.h @@ -2,9 +2,9 @@ #define PLAYER_SYSTEM_H #include "ecs.h" -#include "physics_system.h" #include "sprite_component.h" #include "animation_system.h" +#include "physics_system.h" #define PLAYER_DEFAULT_WALK_SPEED 60.0f // px / s #define PLAYER_DEFAULT_RUN_SPEED 100.0f // px / s @@ -24,9 +24,9 @@ typedef enum player_state_t { } player_state_t; typedef struct player_system_data_t { - physics_system_data_t *physics_system_data; sprite_component_data_t *sprite_component_data; animation_system_data_t *animation_system_data; + physics_system_data_t *physics_system_data; player_state_t state; player_state_t last_state; diff --git a/src/components/headers/transform_component.h b/src/components/headers/transform_component.h index 5b132a1..010ddd8 100644 --- a/src/components/headers/transform_component.h +++ b/src/components/headers/transform_component.h @@ -3,6 +3,7 @@ #include "ecs.h" #include "vector2d.h" +#include "errors.h" typedef struct transform_component_data_t { frect_t bounds; diff --git a/src/components/hitbox_component.c b/src/components/hitbox_component.c index 1a8a526..84f593d 100644 --- a/src/components/hitbox_component.c +++ b/src/components/hitbox_component.c @@ -1,8 +1,8 @@ #include "hitbox_component.h" +#include "game.h" #include "transform_component.h" #include "memory_alloc.h" -#include "game.h" // Args : frect_t bounds, double speed int hitbox_component_init(component_t *component) diff --git a/src/components/physics_system.c b/src/components/physics_system.c index e48bd6e..cc75e77 100644 --- a/src/components/physics_system.c +++ b/src/components/physics_system.c @@ -1,9 +1,9 @@ #include "physics_system.h" #include +#include "game.h" #include "vector2d.h" #include "memory_alloc.h" -#include "game.h" #include "errors.h" // Args : frect_t bounds, double speed diff --git a/src/components/player_system.c b/src/components/player_system.c index 0e7954f..2fbffc2 100644 --- a/src/components/player_system.c +++ b/src/components/player_system.c @@ -1,10 +1,10 @@ #include "player_system.h" #include "game.h" -#include "memory_alloc.h" #include "animation_system.h" #include "sprite_component.h" #include "physics_system.h" +#include "memory_alloc.h" // No args inline int player_system_init(component_t *component) diff --git a/src/components/sprite_component.c b/src/components/sprite_component.c index c579cb6..625c9d1 100644 --- a/src/components/sprite_component.c +++ b/src/components/sprite_component.c @@ -1,8 +1,8 @@ #include "sprite_component.h" -#include "memory_alloc.h" -#include "display.h" #include "game.h" +#include "display.h" +#include "memory_alloc.h" // Arg : const char *name inline int sprite_component_init(component_t *component) diff --git a/src/components/transform_component.c b/src/components/transform_component.c index 5deec28..78010a5 100644 --- a/src/components/transform_component.c +++ b/src/components/transform_component.c @@ -1,7 +1,7 @@ #include "transform_component.h" -#include "memory_alloc.h" #include "game.h" +#include "memory_alloc.h" // Args : frect_t bounds, double speed int transform_component_init(component_t *component) diff --git a/src/game.c b/src/game.c index 0f1660d..5b453b7 100644 --- a/src/game.c +++ b/src/game.c @@ -36,6 +36,8 @@ int game_init(void) .h = 32.0f }; + if(!entity_new_component(player, SPRITE_COMPONENT)) return EXIT_FAILURE; + if(!entity_new_component(player, ANIMATION_SYSTEM)) return EXIT_FAILURE; component = entity_new_component(player, HITBOX_COMPONENT); if(!component) return EXIT_FAILURE; @@ -50,8 +52,6 @@ int game_init(void) }; if(!entity_new_component(player, PHYSICS_SYSTEM)) return EXIT_FAILURE; - if(!entity_new_component(player, SPRITE_COMPONENT)) return EXIT_FAILURE; - if(!entity_new_component(player, ANIMATION_SYSTEM)) return EXIT_FAILURE; if(!entity_new_component(player, PLAYER_SYSTEM)) return EXIT_FAILURE; /* ======== Test entity ======== */ @@ -68,6 +68,7 @@ int game_init(void) .h = 32.0f }; + if(!entity_new_component(entity, SPRITE_COMPONENT)) return EXIT_FAILURE; component = entity_new_component(entity, HITBOX_COMPONENT); if(!component) return EXIT_FAILURE; @@ -81,8 +82,6 @@ int game_init(void) .y = 2.0f / 3.0f }; - if(!entity_new_component(entity, SPRITE_COMPONENT)) return EXIT_FAILURE; - game.is_running = true; return EXIT_SUCCESS;