Globalized components ref in components.
This commit is contained in:
parent
7db6164deb
commit
bcdff91d09
|
|
@ -1 +1 @@
|
||||||
Subproject commit a7e3c16ad932e45dcd8efacdf496546e01102bba
|
Subproject commit eb01fd4d2b5034228938b5d5b54785111efd4908
|
||||||
|
|
@ -1,20 +1,22 @@
|
||||||
#include "animation_system.h"
|
#include "animation_system.h"
|
||||||
|
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
#include "ecs.h"
|
||||||
|
#include "sprite_component.h"
|
||||||
|
#include "vector2d.h"
|
||||||
#include "memory_alloc.h"
|
#include "memory_alloc.h"
|
||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
|
|
||||||
int animation_system_init(component_t *component)
|
int animation_system_init(component_t *system)
|
||||||
{
|
{
|
||||||
animation_system_data_t *system_data = component->data;
|
animation_system_data_t *system_data = system->data;
|
||||||
|
|
||||||
component_t *sprite_component = entity_get_component(component->entity, SPRITE_COMPONENT);
|
system_data->sprite_component = entity_get_component(system->entity, SPRITE_COMPONENT);
|
||||||
if(!sprite_component)
|
if(!system_data->sprite_component)
|
||||||
{
|
{
|
||||||
error_printf("Animation system require a sprite component.");
|
error_printf("Animation system require a sprite component.");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
system_data->sprite_component_data = sprite_component->data;
|
|
||||||
|
|
||||||
linked_list_init(&system_data->frames, sizeof(rect_t), NULL, NULL);
|
linked_list_init(&system_data->frames, sizeof(rect_t), NULL, NULL);
|
||||||
|
|
||||||
|
|
@ -23,9 +25,10 @@ int animation_system_init(component_t *component)
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int animation_system_update(component_t *component)
|
int animation_system_update(component_t *system)
|
||||||
{
|
{
|
||||||
animation_system_data_t *system_data = component->data;
|
animation_system_data_t *system_data = system->data;
|
||||||
|
sprite_component_data_t *sprite_component_data = system_data->sprite_component->data;
|
||||||
|
|
||||||
if(system_data->play)
|
if(system_data->play)
|
||||||
{
|
{
|
||||||
|
|
@ -71,15 +74,15 @@ int animation_system_update(component_t *component)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
system_data->sprite_component_data->src_rect = *(rect_t *)system_data->current_frame->data;
|
sprite_component_data->src_rect = *(rect_t *)system_data->current_frame->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int animation_system_destroy(component_t *component)
|
inline int animation_system_destroy(component_t *system)
|
||||||
{
|
{
|
||||||
animation_system_data_t *system_data = component->data;
|
animation_system_data_t *system_data = system->data;
|
||||||
|
|
||||||
if(linked_list_exit(&system_data->frames)) return_failure_int;
|
if(linked_list_exit(&system_data->frames)) return_failure_int;
|
||||||
|
|
||||||
|
|
@ -88,9 +91,10 @@ inline int animation_system_destroy(component_t *component)
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int animation_system_apply_changes(animation_system_data_t *system_data)
|
inline int animation_system_apply_changes(component_t *system)
|
||||||
{
|
{
|
||||||
sprite_component_data_t *sprite_component_data = system_data->sprite_component_data;
|
animation_system_data_t *system_data = system->data;
|
||||||
|
sprite_component_data_t *sprite_component_data = system_data->sprite_component->data;
|
||||||
|
|
||||||
if(linked_list_clear(&system_data->frames)) return_failure_int;
|
if(linked_list_clear(&system_data->frames)) return_failure_int;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
#include "ecs.h"
|
||||||
#include "animation_system.h"
|
#include "animation_system.h"
|
||||||
#include "hitbox_component.h"
|
#include "hitbox_component.h"
|
||||||
#include "event_bus.h"
|
#include "event_bus.h"
|
||||||
|
|
@ -12,21 +13,19 @@ inline int door_component_init(component_t *component)
|
||||||
{
|
{
|
||||||
door_component_data_t *component_data = component->data;
|
door_component_data_t *component_data = component->data;
|
||||||
|
|
||||||
component_t *animation_system = entity_get_component(component->entity, ANIMATION_SYSTEM);
|
component_data->animation_system = entity_get_component(component->entity, ANIMATION_SYSTEM);
|
||||||
if(!animation_system)
|
if(!component_data->animation_system)
|
||||||
{
|
{
|
||||||
error_printf("Door component require an animation system.");
|
error_printf("Door component require an animation system.");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
component_data->animation_system_data = animation_system->data;
|
|
||||||
|
|
||||||
component_t *hitbox_component = entity_get_component(component->entity, HITBOX_COMPONENT);
|
component_data->hitbox_component = entity_get_component(component->entity, HITBOX_COMPONENT);
|
||||||
if(!hitbox_component)
|
if(!component_data->hitbox_component)
|
||||||
{
|
{
|
||||||
error_printf("Door component require an hitbox component.");
|
error_printf("Door component require an hitbox component.");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
component_data->hitbox_component_data = hitbox_component->data;
|
|
||||||
|
|
||||||
component_data->last_state = false;
|
component_data->last_state = false;
|
||||||
|
|
||||||
|
|
@ -36,8 +35,8 @@ inline int door_component_init(component_t *component)
|
||||||
inline int door_component_update(component_t *component)
|
inline int door_component_update(component_t *component)
|
||||||
{
|
{
|
||||||
door_component_data_t *component_data = component->data;
|
door_component_data_t *component_data = component->data;
|
||||||
animation_system_data_t *animation_system_data = component_data->animation_system_data;
|
animation_system_data_t *animation_system_data = component_data->animation_system->data;
|
||||||
hitbox_component_data_t *hitbox_component_data = component_data->hitbox_component_data;
|
hitbox_component_data_t *hitbox_component_data = component_data->hitbox_component->data;
|
||||||
|
|
||||||
if(component_data->state != component_data->last_state)
|
if(component_data->state != component_data->last_state)
|
||||||
{
|
{
|
||||||
|
|
@ -61,28 +60,22 @@ inline int door_component_destroy(component_t *component)
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event arg : size_t state, Subscription arg : entity_t *entity
|
// Event arg : size_t state, Subscription data : entity_t *entity
|
||||||
static inline int door_component_callback(void *event_arg, void *subscription_data)
|
static inline int door_component_callback(void *event_arg, void *subscription_data)
|
||||||
{
|
{
|
||||||
const entity_t *entity = subscription_data;
|
const component_t *component = subscription_data;
|
||||||
|
door_component_data_t *component_data = component->data;
|
||||||
component_t *door_component = entity_get_component(entity, DOOR_COMPONENT);
|
|
||||||
if(!door_component)
|
|
||||||
{
|
|
||||||
error_printf("Failed to get door component.");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
door_component_data_t *component_data = door_component->data;
|
|
||||||
|
|
||||||
component_data->state = *(size_t *)event_arg;
|
component_data->state = *(size_t *)event_arg;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int door_component_subscribe(door_component_data_t *component_data, entity_t *entity)
|
inline int door_component_subscribe(component_t *component)
|
||||||
{
|
{
|
||||||
if(event_bus_subscribe(component_data->topic_id, door_component_callback, entity)) return_failure_int;
|
door_component_data_t *component_data = component->data;
|
||||||
|
|
||||||
|
if(event_bus_subscribe(component_data->topic_id, door_component_callback, component)) return_failure_int;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,9 @@
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "ecs.h"
|
#include "ecs.h"
|
||||||
#include "sprite_component.h"
|
|
||||||
|
|
||||||
typedef struct animation_system_data_t {
|
typedef struct animation_system_data_t {
|
||||||
sprite_component_data_t *sprite_component_data;
|
component_t *sprite_component;
|
||||||
|
|
||||||
size_t nb_frames;
|
size_t nb_frames;
|
||||||
linked_list_t frames;
|
linked_list_t frames;
|
||||||
|
|
@ -22,10 +21,10 @@ typedef struct animation_system_data_t {
|
||||||
bool reverse :1;
|
bool reverse :1;
|
||||||
} animation_system_data_t;
|
} animation_system_data_t;
|
||||||
|
|
||||||
int animation_system_init(component_t *component);
|
int animation_system_init(component_t *system);
|
||||||
int animation_system_update(component_t *component);
|
int animation_system_update(component_t *system);
|
||||||
int animation_system_destroy(component_t *component);
|
int animation_system_destroy(component_t *system);
|
||||||
|
|
||||||
int animation_system_apply_changes(animation_system_data_t *system_data);
|
int animation_system_apply_changes(component_t *system);
|
||||||
|
|
||||||
#endif // SPRITE_COMPONENT_H
|
#endif // SPRITE_COMPONENT_H
|
||||||
|
|
@ -2,15 +2,13 @@
|
||||||
#define DOOR_COMPONENT_H
|
#define DOOR_COMPONENT_H
|
||||||
|
|
||||||
#include "ecs.h"
|
#include "ecs.h"
|
||||||
#include "animation_system.h"
|
|
||||||
#include "hitbox_component.h"
|
|
||||||
|
|
||||||
#define BARRED_DOOR_DEFAULT_ANIMATION_SPEED 30
|
#define BARRED_DOOR_DEFAULT_ANIMATION_SPEED 30
|
||||||
#define WOODEN_DOOR_DEFAULT_ANIMATION_SPEED 100
|
#define WOODEN_DOOR_DEFAULT_ANIMATION_SPEED 100
|
||||||
|
|
||||||
typedef struct door_component_data_t {
|
typedef struct door_component_data_t {
|
||||||
animation_system_data_t *animation_system_data;
|
component_t *animation_system;
|
||||||
hitbox_component_data_t *hitbox_component_data;
|
component_t *hitbox_component;
|
||||||
|
|
||||||
bool state;
|
bool state;
|
||||||
bool last_state;
|
bool last_state;
|
||||||
|
|
@ -22,6 +20,6 @@ int door_component_init(component_t *component);
|
||||||
int door_component_update(component_t *component);
|
int door_component_update(component_t *component);
|
||||||
int door_component_destroy(component_t *component);
|
int door_component_destroy(component_t *component);
|
||||||
|
|
||||||
int door_component_subscribe(door_component_data_t *component_data, entity_t *entity);
|
int door_component_subscribe(component_t *component);
|
||||||
|
|
||||||
#endif // DOOR_COMPONENT_H
|
#endif // DOOR_COMPONENT_H
|
||||||
|
|
@ -3,12 +3,11 @@
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "ecs.h"
|
#include "ecs.h"
|
||||||
#include "transform_component.h"
|
|
||||||
#include "vector2d.h"
|
#include "vector2d.h"
|
||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
|
|
||||||
typedef struct hitbox_component_data_t {
|
typedef struct hitbox_component_data_t {
|
||||||
transform_component_data_t *transform_component_data;
|
component_t *transform_component;
|
||||||
|
|
||||||
fvector2d_t position;
|
fvector2d_t position;
|
||||||
fvector2d_t scale;
|
fvector2d_t scale;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
#define INTERACT_COMPONENT_H
|
#define INTERACT_COMPONENT_H
|
||||||
|
|
||||||
#include "ecs.h"
|
#include "ecs.h"
|
||||||
#include "transform_component.h"
|
|
||||||
#include "vector2d.h"
|
#include "vector2d.h"
|
||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
|
|
||||||
|
|
@ -11,7 +10,7 @@ typedef enum interact_type_t {
|
||||||
} interact_type_t;
|
} interact_type_t;
|
||||||
|
|
||||||
typedef struct interact_component_data_t {
|
typedef struct interact_component_data_t {
|
||||||
transform_component_data_t *transform_component_data;
|
component_t *transform_component;
|
||||||
|
|
||||||
fvector2d_t position;
|
fvector2d_t position;
|
||||||
fvector2d_t scale;
|
fvector2d_t scale;
|
||||||
|
|
@ -31,7 +30,7 @@ int interact_component_draw(const component_t *component);
|
||||||
#endif // DEBUG >= 2
|
#endif // DEBUG >= 2
|
||||||
int interact_component_destroy(component_t *component);
|
int interact_component_destroy(component_t *component);
|
||||||
|
|
||||||
int interact_component_interact(interact_component_data_t *component_data);
|
int interact_component_interact(component_t *component);
|
||||||
int interact_component_modify_topic_id(interact_component_data_t *component_data, size_t id);
|
int interact_component_modify_topic_id(component_t *component, size_t id);
|
||||||
|
|
||||||
#endif // TRANSFORM_COMPONENT_H
|
#endif // TRANSFORM_COMPONENT_H
|
||||||
|
|
@ -2,13 +2,12 @@
|
||||||
#define LEVER_COMPONENT_H
|
#define LEVER_COMPONENT_H
|
||||||
|
|
||||||
#include "ecs.h"
|
#include "ecs.h"
|
||||||
#include "animation_system.h"
|
|
||||||
#include "vector2d.h"
|
#include "vector2d.h"
|
||||||
|
|
||||||
#define LEVER_DEFAULT_ANIMATION_SPEED 100
|
#define LEVER_DEFAULT_ANIMATION_SPEED 100
|
||||||
|
|
||||||
typedef struct lever_component_data_t {
|
typedef struct lever_component_data_t {
|
||||||
animation_system_data_t *animation_system_data;
|
component_t *animation_system;
|
||||||
|
|
||||||
bool state;
|
bool state;
|
||||||
bool last_state;
|
bool last_state;
|
||||||
|
|
@ -20,6 +19,6 @@ int lever_component_init(component_t *component);
|
||||||
int lever_component_update(component_t *component);
|
int lever_component_update(component_t *component);
|
||||||
int lever_component_destroy(component_t *component);
|
int lever_component_destroy(component_t *component);
|
||||||
|
|
||||||
int lever_component_subscribe(lever_component_data_t *component_data, entity_t *entity);
|
int lever_component_subscribe(component_t *component);
|
||||||
|
|
||||||
#endif // LEVER_COMPONENT_H
|
#endif // LEVER_COMPONENT_H
|
||||||
|
|
@ -2,13 +2,11 @@
|
||||||
#define PHYSICS_SYSTEM_H
|
#define PHYSICS_SYSTEM_H
|
||||||
|
|
||||||
#include "ecs.h"
|
#include "ecs.h"
|
||||||
#include "transform_component.h"
|
|
||||||
#include "hitbox_component.h"
|
|
||||||
#include "vector2d.h"
|
#include "vector2d.h"
|
||||||
|
|
||||||
typedef struct physics_system_data_t {
|
typedef struct physics_system_data_t {
|
||||||
transform_component_data_t *transform_component_data;
|
component_t *transform_component;
|
||||||
hitbox_component_data_t *hitbox_component_data;
|
component_t *hitbox_component;
|
||||||
|
|
||||||
fvector2d_t target_velocity;
|
fvector2d_t target_velocity;
|
||||||
fvector2d_t velocity;
|
fvector2d_t velocity;
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,6 @@
|
||||||
#define PLAYER_SYSTEM_H
|
#define PLAYER_SYSTEM_H
|
||||||
|
|
||||||
#include "ecs.h"
|
#include "ecs.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_WALK_SPEED 60.0f // px / s
|
||||||
#define PLAYER_DEFAULT_RUN_SPEED 100.0f // px / s
|
#define PLAYER_DEFAULT_RUN_SPEED 100.0f // px / s
|
||||||
|
|
@ -24,9 +21,9 @@ typedef enum player_state_t {
|
||||||
} player_state_t;
|
} player_state_t;
|
||||||
|
|
||||||
typedef struct player_system_data_t {
|
typedef struct player_system_data_t {
|
||||||
sprite_component_data_t *sprite_component_data;
|
component_t *sprite_component;
|
||||||
animation_system_data_t *animation_system_data;
|
component_t *animation_system;
|
||||||
physics_system_data_t *physics_system_data;
|
component_t *physics_system;
|
||||||
|
|
||||||
player_state_t state;
|
player_state_t state;
|
||||||
player_state_t last_state;
|
player_state_t last_state;
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,12 @@
|
||||||
#define SPRITE_COMPONENT_H
|
#define SPRITE_COMPONENT_H
|
||||||
|
|
||||||
#include "ecs.h"
|
#include "ecs.h"
|
||||||
#include "transform_component.h"
|
|
||||||
#include "asset_manager.h"
|
#include "asset_manager.h"
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
|
#include "vector2d.h"
|
||||||
|
|
||||||
typedef struct sprite_component_data_t {
|
typedef struct sprite_component_data_t {
|
||||||
transform_component_data_t *transform_component_data;
|
component_t *transform_component;
|
||||||
|
|
||||||
texture_t *texture;
|
texture_t *texture;
|
||||||
rect_t src_rect;
|
rect_t src_rect;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include "hitbox_component.h"
|
#include "hitbox_component.h"
|
||||||
|
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
#include "ecs.h"
|
||||||
#include "transform_component.h"
|
#include "transform_component.h"
|
||||||
#include "memory_alloc.h"
|
#include "memory_alloc.h"
|
||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
|
|
@ -9,13 +10,12 @@ inline int hitbox_component_init(component_t *component)
|
||||||
{
|
{
|
||||||
hitbox_component_data_t *component_data = component->data;
|
hitbox_component_data_t *component_data = component->data;
|
||||||
|
|
||||||
component_t *transform_component = entity_get_component(component->entity, TRANSFORM_COMPONENT);
|
component_data->transform_component = entity_get_component(component->entity, TRANSFORM_COMPONENT);
|
||||||
if(!transform_component)
|
if(!component_data->transform_component)
|
||||||
{
|
{
|
||||||
error_printf("Hitbox component require a transform component.");
|
error_printf("Hitbox component require a transform component.");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
component_data->transform_component_data = transform_component->data;
|
|
||||||
|
|
||||||
component_data->position = (fvector2d_t) {
|
component_data->position = (fvector2d_t) {
|
||||||
.x = 0.0f,
|
.x = 0.0f,
|
||||||
|
|
@ -35,7 +35,7 @@ inline int hitbox_component_init(component_t *component)
|
||||||
inline int hitbox_component_update(component_t *component)
|
inline int hitbox_component_update(component_t *component)
|
||||||
{
|
{
|
||||||
hitbox_component_data_t *component_data = component->data;
|
hitbox_component_data_t *component_data = component->data;
|
||||||
const transform_component_data_t *transform_component_data = component_data->transform_component_data;
|
const transform_component_data_t *transform_component_data = component_data->transform_component->data;
|
||||||
|
|
||||||
component_data->bounds.x = transform_component_data->bounds.x + transform_component_data->bounds.w * component_data->position.x;
|
component_data->bounds.x = transform_component_data->bounds.x + transform_component_data->bounds.w * component_data->position.x;
|
||||||
component_data->bounds.y = transform_component_data->bounds.y + transform_component_data->bounds.h * component_data->position.y;
|
component_data->bounds.y = transform_component_data->bounds.y + transform_component_data->bounds.h * component_data->position.y;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
#include "interact_component.h"
|
#include "interact_component.h"
|
||||||
|
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
#include "ecs.h"
|
||||||
|
#include "transform_component.h"
|
||||||
#include "event_bus.h"
|
#include "event_bus.h"
|
||||||
#include "memory_alloc.h"
|
#include "memory_alloc.h"
|
||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
|
|
@ -9,13 +11,12 @@ inline int interact_component_init(component_t *component)
|
||||||
{
|
{
|
||||||
interact_component_data_t *component_data = component->data;
|
interact_component_data_t *component_data = component->data;
|
||||||
|
|
||||||
component_t *transform_component = entity_get_component(component->entity, TRANSFORM_COMPONENT);
|
component_data->transform_component = entity_get_component(component->entity, TRANSFORM_COMPONENT);
|
||||||
if(!transform_component)
|
if(!component_data->transform_component)
|
||||||
{
|
{
|
||||||
error_printf("Hitbox component require a transform component.");
|
error_printf("Hitbox component require a transform component.");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
component_data->transform_component_data = transform_component->data;
|
|
||||||
|
|
||||||
component_data->position = (fvector2d_t) {
|
component_data->position = (fvector2d_t) {
|
||||||
.x = 0.0f,
|
.x = 0.0f,
|
||||||
|
|
@ -38,7 +39,7 @@ inline int interact_component_init(component_t *component)
|
||||||
inline int interact_component_update(component_t *component)
|
inline int interact_component_update(component_t *component)
|
||||||
{
|
{
|
||||||
interact_component_data_t *component_data = component->data;
|
interact_component_data_t *component_data = component->data;
|
||||||
const transform_component_data_t *transform_component_data = component_data->transform_component_data;
|
const transform_component_data_t *transform_component_data = component_data->transform_component->data;
|
||||||
|
|
||||||
component_data->bounds.x = transform_component_data->bounds.x + transform_component_data->bounds.w * component_data->position.x;
|
component_data->bounds.x = transform_component_data->bounds.x + transform_component_data->bounds.w * component_data->position.x;
|
||||||
component_data->bounds.y = transform_component_data->bounds.y + transform_component_data->bounds.h * component_data->position.y;
|
component_data->bounds.y = transform_component_data->bounds.y + transform_component_data->bounds.h * component_data->position.y;
|
||||||
|
|
@ -70,8 +71,10 @@ inline int interact_component_destroy(component_t *component)
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int interact_component_interact(interact_component_data_t *component_data)
|
inline int interact_component_interact(component_t *component)
|
||||||
{
|
{
|
||||||
|
interact_component_data_t *component_data = component->data;
|
||||||
|
|
||||||
switch(component_data->type)
|
switch(component_data->type)
|
||||||
{
|
{
|
||||||
case INTERACT_TOGGLE:
|
case INTERACT_TOGGLE:
|
||||||
|
|
@ -88,8 +91,10 @@ inline int interact_component_interact(interact_component_data_t *component_data
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int interact_component_modify_topic_id(interact_component_data_t *component_data, size_t id)
|
inline int interact_component_modify_topic_id(component_t *component, size_t id)
|
||||||
{
|
{
|
||||||
|
interact_component_data_t *component_data = component->data;
|
||||||
|
|
||||||
if(event_bus_change_topic_id(component_data->topic_id, id)) return_failure_int;
|
if(event_bus_change_topic_id(component_data->topic_id, id)) return_failure_int;
|
||||||
|
|
||||||
component_data->topic_id = id;
|
component_data->topic_id = id;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
#include "ecs.h"
|
||||||
#include "animation_system.h"
|
#include "animation_system.h"
|
||||||
#include "interact_component.h"
|
#include "interact_component.h"
|
||||||
#include "event_bus.h"
|
#include "event_bus.h"
|
||||||
|
|
@ -12,13 +13,12 @@ inline int lever_component_init(component_t *component)
|
||||||
{
|
{
|
||||||
lever_component_data_t *component_data = component->data;
|
lever_component_data_t *component_data = component->data;
|
||||||
|
|
||||||
component_t *animation_system = entity_get_component(component->entity, ANIMATION_SYSTEM);
|
component_data->animation_system = entity_get_component(component->entity, ANIMATION_SYSTEM);
|
||||||
if(!animation_system)
|
if(!component_data->animation_system)
|
||||||
{
|
{
|
||||||
error_printf("Lever component require an animation system.");
|
error_printf("Lever component require an animation system.");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
component_data->animation_system_data = animation_system->data;
|
|
||||||
|
|
||||||
component_data->last_state = false;
|
component_data->last_state = false;
|
||||||
|
|
||||||
|
|
@ -28,7 +28,7 @@ inline int lever_component_init(component_t *component)
|
||||||
inline int lever_component_update(component_t *component)
|
inline int lever_component_update(component_t *component)
|
||||||
{
|
{
|
||||||
lever_component_data_t *component_data = component->data;
|
lever_component_data_t *component_data = component->data;
|
||||||
animation_system_data_t *animation_system_data = component_data->animation_system_data;
|
animation_system_data_t *animation_system_data = component_data->animation_system->data;
|
||||||
|
|
||||||
if(component_data->state != component_data->last_state)
|
if(component_data->state != component_data->last_state)
|
||||||
{
|
{
|
||||||
|
|
@ -50,28 +50,22 @@ inline int lever_component_destroy(component_t *component)
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event arg : size_t state, Subscription arg : entity_t *entity
|
// Event arg : size_t state, Subscription data : component_t *component
|
||||||
static inline int lever_component_callback(void *event_arg, void *subscription_data)
|
static inline int lever_component_callback(void *event_arg, void *subscription_data)
|
||||||
{
|
{
|
||||||
const entity_t *entity = subscription_data;
|
const component_t *component = subscription_data;
|
||||||
|
lever_component_data_t *component_data = component->data;
|
||||||
component_t *lever_component = entity_get_component(entity, LEVER_COMPONENT);
|
|
||||||
if(!lever_component)
|
|
||||||
{
|
|
||||||
error_printf("Failed to get lever component.");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
lever_component_data_t *component_data = lever_component->data;
|
|
||||||
|
|
||||||
component_data->state = *(size_t *)event_arg;
|
component_data->state = *(size_t *)event_arg;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int lever_component_subscribe(lever_component_data_t *component_data, entity_t *entity)
|
inline int lever_component_subscribe(component_t *component)
|
||||||
{
|
{
|
||||||
if(event_bus_subscribe(component_data->topic_id, lever_component_callback, entity)) return_failure_int;
|
lever_component_data_t *component_data = component->data;
|
||||||
|
|
||||||
|
if(event_bus_subscribe(component_data->topic_id, lever_component_callback, component)) return_failure_int;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
#include "physics_system.h"
|
#include "physics_system.h"
|
||||||
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
#include "ecs.h"
|
||||||
|
#include "transform_component.h"
|
||||||
|
#include "hitbox_component.h"
|
||||||
#include "vector2d.h"
|
#include "vector2d.h"
|
||||||
#include "memory_alloc.h"
|
#include "memory_alloc.h"
|
||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
|
|
@ -10,21 +12,19 @@ inline int physics_system_init(component_t *component)
|
||||||
{
|
{
|
||||||
physics_system_data_t *system_data = component->data;
|
physics_system_data_t *system_data = component->data;
|
||||||
|
|
||||||
component_t *transform_component = entity_get_component(component->entity, TRANSFORM_COMPONENT);
|
system_data->transform_component = entity_get_component(component->entity, TRANSFORM_COMPONENT);
|
||||||
if(!transform_component)
|
if(!system_data->transform_component)
|
||||||
{
|
{
|
||||||
error_printf("Physics system require a transform component.");
|
error_printf("Physics system require a transform component.");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
system_data->transform_component_data = transform_component->data;
|
|
||||||
|
|
||||||
component_t *hitbox_component = entity_get_component(component->entity, HITBOX_COMPONENT);
|
system_data->hitbox_component = entity_get_component(component->entity, HITBOX_COMPONENT);
|
||||||
if(!hitbox_component)
|
if(!system_data->hitbox_component)
|
||||||
{
|
{
|
||||||
error_printf("Physics system require an hitbox component.");
|
error_printf("Physics system require an hitbox component.");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
system_data->hitbox_component_data = hitbox_component->data;
|
|
||||||
|
|
||||||
system_data->target_velocity = (fvector2d_t) {
|
system_data->target_velocity = (fvector2d_t) {
|
||||||
.x = 0.0f,
|
.x = 0.0f,
|
||||||
|
|
@ -49,8 +49,8 @@ static int action_detect_solve_entities_collision(elem_t *elem, void *arg);
|
||||||
int physics_system_update(component_t *component)
|
int physics_system_update(component_t *component)
|
||||||
{
|
{
|
||||||
physics_system_data_t *system_data = component->data;
|
physics_system_data_t *system_data = component->data;
|
||||||
transform_component_data_t *transform_component_data = system_data->transform_component_data;
|
transform_component_data_t *transform_component_data = system_data->transform_component->data;
|
||||||
hitbox_component_data_t *hitbox_component_data = system_data->hitbox_component_data;
|
hitbox_component_data_t *hitbox_component_data = system_data->hitbox_component->data;
|
||||||
|
|
||||||
system_data->velocity.x = lerp(system_data->velocity.x, system_data->target_velocity.x, system_data->smoothing_factor);
|
system_data->velocity.x = lerp(system_data->velocity.x, system_data->target_velocity.x, system_data->smoothing_factor);
|
||||||
system_data->velocity.y = lerp(system_data->velocity.y, system_data->target_velocity.y, system_data->smoothing_factor);
|
system_data->velocity.y = lerp(system_data->velocity.y, system_data->target_velocity.y, system_data->smoothing_factor);
|
||||||
|
|
@ -76,7 +76,11 @@ inline int physics_system_destroy(component_t *component)
|
||||||
static inline int action_detect_solve_entities_collision(elem_t *elem, void *arg)
|
static inline int action_detect_solve_entities_collision(elem_t *elem, void *arg)
|
||||||
{
|
{
|
||||||
component_t *physics_system = arg;
|
component_t *physics_system = arg;
|
||||||
|
|
||||||
physics_system_data_t *system_data = physics_system->data;
|
physics_system_data_t *system_data = physics_system->data;
|
||||||
|
transform_component_data_t * transform_component_data = system_data->transform_component->data;
|
||||||
|
hitbox_component_data_t *hitbox_component_data = system_data->hitbox_component->data;
|
||||||
|
|
||||||
const entity_t *target_entity = elem->data;
|
const entity_t *target_entity = elem->data;
|
||||||
|
|
||||||
if(target_entity->id == physics_system->entity->id)
|
if(target_entity->id == physics_system->entity->id)
|
||||||
|
|
@ -87,13 +91,12 @@ static inline int action_detect_solve_entities_collision(elem_t *elem, void *arg
|
||||||
const component_t *target_hitbox_component = entity_get_component(target_entity, HITBOX_COMPONENT);
|
const component_t *target_hitbox_component = entity_get_component(target_entity, HITBOX_COMPONENT);
|
||||||
if(!target_hitbox_component) return EXIT_SUCCESS;
|
if(!target_hitbox_component) return EXIT_SUCCESS;
|
||||||
|
|
||||||
if(!((hitbox_component_data_t *)target_hitbox_component->data)->activated)
|
const hitbox_component_data_t *target_hitbox_component_data = target_hitbox_component->data;
|
||||||
{
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
const frect_t *hitbox_bounds = &system_data->hitbox_component_data->bounds;
|
if(!target_hitbox_component_data->activated) return EXIT_SUCCESS;
|
||||||
const frect_t *target_hitbox_bounds = &((hitbox_component_data_t *)target_hitbox_component->data)->bounds;
|
|
||||||
|
const frect_t *hitbox_bounds = &hitbox_component_data->bounds;
|
||||||
|
const frect_t *target_hitbox_bounds = &target_hitbox_component_data->bounds;
|
||||||
frect_t intersect_frect;
|
frect_t intersect_frect;
|
||||||
|
|
||||||
if(intersect_frect(hitbox_bounds, target_hitbox_bounds, &intersect_frect))
|
if(intersect_frect(hitbox_bounds, target_hitbox_bounds, &intersect_frect))
|
||||||
|
|
@ -105,12 +108,12 @@ static inline int action_detect_solve_entities_collision(elem_t *elem, void *arg
|
||||||
|
|
||||||
if(left_correction < right_correction)
|
if(left_correction < right_correction)
|
||||||
{
|
{
|
||||||
system_data->transform_component_data->bounds.x -= left_correction;
|
transform_component_data->bounds.x -= left_correction;
|
||||||
if(system_data->velocity.x > 0.0f) system_data->velocity.x = 0.0f;
|
if(system_data->velocity.x > 0.0f) system_data->velocity.x = 0.0f;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
system_data->transform_component_data->bounds.x += right_correction;
|
transform_component_data->bounds.x += right_correction;
|
||||||
if(system_data->velocity.x < 0.0f) system_data->velocity.x = 0.0f;
|
if(system_data->velocity.x < 0.0f) system_data->velocity.x = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -121,12 +124,12 @@ static inline int action_detect_solve_entities_collision(elem_t *elem, void *arg
|
||||||
|
|
||||||
if(top_correction < bottom_correction)
|
if(top_correction < bottom_correction)
|
||||||
{
|
{
|
||||||
system_data->transform_component_data->bounds.y -= top_correction;
|
transform_component_data->bounds.y -= top_correction;
|
||||||
if(system_data->velocity.y > 0.0f) system_data->velocity.y = 0.0f;
|
if(system_data->velocity.y > 0.0f) system_data->velocity.y = 0.0f;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
system_data->transform_component_data->bounds.y += bottom_correction;
|
transform_component_data->bounds.y += bottom_correction;
|
||||||
if(system_data->velocity.y < 0.0f) system_data->velocity.y = 0.0f;
|
if(system_data->velocity.y < 0.0f) system_data->velocity.y = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
#include "player_system.h"
|
#include "player_system.h"
|
||||||
|
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
#include "ecs.h"
|
||||||
#include "sprite_component.h"
|
#include "sprite_component.h"
|
||||||
#include "animation_system.h"
|
#include "animation_system.h"
|
||||||
#include "interact_component.h"
|
#include "interact_component.h"
|
||||||
#include "physics_system.h"
|
#include "physics_system.h"
|
||||||
|
#include "hitbox_component.h"
|
||||||
#include "memory_alloc.h"
|
#include "memory_alloc.h"
|
||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
|
|
||||||
|
|
@ -12,29 +14,26 @@ inline int player_system_init(component_t *component)
|
||||||
{
|
{
|
||||||
player_system_data_t *system_data = component->data;
|
player_system_data_t *system_data = component->data;
|
||||||
|
|
||||||
component_t *sprite_component = entity_get_component(component->entity, SPRITE_COMPONENT);
|
system_data->sprite_component = entity_get_component(component->entity, SPRITE_COMPONENT);
|
||||||
if(!sprite_component)
|
if(!system_data->sprite_component)
|
||||||
{
|
{
|
||||||
error_printf("Player system require a sprite component.");
|
error_printf("Player system require a sprite component.");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
system_data->sprite_component_data = sprite_component->data;
|
|
||||||
|
|
||||||
component_t *animation_system = entity_get_component(component->entity, ANIMATION_SYSTEM);
|
system_data->animation_system = entity_get_component(component->entity, ANIMATION_SYSTEM);
|
||||||
if(!animation_system)
|
if(!system_data->animation_system)
|
||||||
{
|
{
|
||||||
error_printf("Player system require an animation system.");
|
error_printf("Player system require an animation system.");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
system_data->animation_system_data = animation_system->data;
|
|
||||||
|
|
||||||
component_t *physics_system = entity_get_component(component->entity, PHYSICS_SYSTEM);
|
system_data->physics_system = entity_get_component(component->entity, PHYSICS_SYSTEM);
|
||||||
if(!physics_system)
|
if(!system_data->physics_system)
|
||||||
{
|
{
|
||||||
error_printf("Player system require a physics system.");
|
error_printf("Player system require a physics system.");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
system_data->physics_system_data = physics_system->data;
|
|
||||||
|
|
||||||
system_data->state = PLAYER_MOVING;
|
system_data->state = PLAYER_MOVING;
|
||||||
|
|
||||||
|
|
@ -99,7 +98,7 @@ static inline void player_system_get_inputs(player_system_data_t *system_data)
|
||||||
|
|
||||||
static inline void player_system_set_velocity(player_system_data_t *system_data)
|
static inline void player_system_set_velocity(player_system_data_t *system_data)
|
||||||
{
|
{
|
||||||
physics_system_data_t *physics_system_data = system_data->physics_system_data;
|
physics_system_data_t *physics_system_data = system_data->physics_system->data;
|
||||||
|
|
||||||
if((system_data->state & PLAYER_MOVING) != (system_data->last_state & PLAYER_MOVING))
|
if((system_data->state & PLAYER_MOVING) != (system_data->last_state & PLAYER_MOVING))
|
||||||
{
|
{
|
||||||
|
|
@ -118,9 +117,9 @@ static inline void player_system_set_velocity(player_system_data_t *system_data)
|
||||||
|
|
||||||
static inline int player_system_set_animation_and_speed(player_system_data_t *system_data)
|
static inline int player_system_set_animation_and_speed(player_system_data_t *system_data)
|
||||||
{
|
{
|
||||||
animation_system_data_t *animation_system_data = system_data->animation_system_data;
|
animation_system_data_t *animation_system_data = system_data->animation_system->data;
|
||||||
sprite_component_data_t *sprite_component_data = system_data->sprite_component_data;
|
sprite_component_data_t *sprite_component_data = system_data->sprite_component->data;
|
||||||
physics_system_data_t *physics_system_data = system_data->physics_system_data;
|
physics_system_data_t *physics_system_data = system_data->physics_system->data;
|
||||||
|
|
||||||
if(system_data->state & PLAYER_MOVING_LEFT) sprite_component_data->flip = true;
|
if(system_data->state & PLAYER_MOVING_LEFT) sprite_component_data->flip = true;
|
||||||
if(system_data->state & PLAYER_MOVING_RIGHT) sprite_component_data->flip = false;
|
if(system_data->state & PLAYER_MOVING_RIGHT) sprite_component_data->flip = false;
|
||||||
|
|
@ -140,7 +139,7 @@ static inline int player_system_set_animation_and_speed(player_system_data_t *sy
|
||||||
animation_system_data->nb_frames = 8;
|
animation_system_data->nb_frames = 8;
|
||||||
animation_system_data->current_frame_nb = 0;
|
animation_system_data->current_frame_nb = 0;
|
||||||
animation_system_data->frame_delay_ms = PLAYER_DEFAULT_RUN_ANIMATION_SPEED;
|
animation_system_data->frame_delay_ms = PLAYER_DEFAULT_RUN_ANIMATION_SPEED;
|
||||||
if(animation_system_apply_changes(animation_system_data)) return_failure_int;
|
if(animation_system_apply_changes(system_data->animation_system)) return_failure_int;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -154,7 +153,7 @@ static inline int player_system_set_animation_and_speed(player_system_data_t *sy
|
||||||
animation_system_data->nb_frames = 4;
|
animation_system_data->nb_frames = 4;
|
||||||
animation_system_data->current_frame_nb = 0;
|
animation_system_data->current_frame_nb = 0;
|
||||||
animation_system_data->frame_delay_ms = PLAYER_DEFAULT_WALK_ANIMATION_SPEED;
|
animation_system_data->frame_delay_ms = PLAYER_DEFAULT_WALK_ANIMATION_SPEED;
|
||||||
if(animation_system_apply_changes(animation_system_data)) return_failure_int;
|
if(animation_system_apply_changes(system_data->animation_system)) return_failure_int;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(!(system_data->state & PLAYER_MOVING) && (system_data->last_state & PLAYER_MOVING))
|
else if(!(system_data->state & PLAYER_MOVING) && (system_data->last_state & PLAYER_MOVING))
|
||||||
|
|
@ -167,7 +166,7 @@ static inline int player_system_set_animation_and_speed(player_system_data_t *sy
|
||||||
animation_system_data->nb_frames = 4;
|
animation_system_data->nb_frames = 4;
|
||||||
animation_system_data->current_frame_nb = 0;
|
animation_system_data->current_frame_nb = 0;
|
||||||
animation_system_data->frame_delay_ms = PLAYER_DEFAULT_IDLE_ANIMATION_SPEED;
|
animation_system_data->frame_delay_ms = PLAYER_DEFAULT_IDLE_ANIMATION_SPEED;
|
||||||
if(animation_system_apply_changes(animation_system_data)) return_failure_int;
|
if(animation_system_apply_changes(system_data->animation_system)) return_failure_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
@ -176,10 +175,12 @@ static inline int player_system_set_animation_and_speed(player_system_data_t *sy
|
||||||
// Args : player_system_data_t *system_data
|
// Args : player_system_data_t *system_data
|
||||||
static inline int action_detect_activate_interact(elem_t *elem, void *arg)
|
static inline int action_detect_activate_interact(elem_t *elem, void *arg)
|
||||||
{
|
{
|
||||||
const entity_t *target_entity = elem->data;
|
entity_t *target_entity = elem->data;
|
||||||
const player_system_data_t *system_data = arg;
|
|
||||||
|
|
||||||
const component_t *target_interact_component = entity_get_component(target_entity, INTERACT_COMPONENT);
|
const player_system_data_t *system_data = arg;
|
||||||
|
physics_system_data_t *physics_system_data = system_data->physics_system->data;
|
||||||
|
|
||||||
|
component_t *target_interact_component = entity_get_component(target_entity, INTERACT_COMPONENT);
|
||||||
if(!target_interact_component) return EXIT_SUCCESS;
|
if(!target_interact_component) return EXIT_SUCCESS;
|
||||||
|
|
||||||
interact_component_data_t *target_interact_component_data = target_interact_component->data;
|
interact_component_data_t *target_interact_component_data = target_interact_component->data;
|
||||||
|
|
@ -189,12 +190,12 @@ static inline int action_detect_activate_interact(elem_t *elem, void *arg)
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
const frect_t *hitbox_bounds = &system_data->physics_system_data->hitbox_component_data->bounds;
|
const frect_t *hitbox_bounds = &((hitbox_component_data_t *)physics_system_data->hitbox_component->data)->bounds;
|
||||||
const frect_t *target_interact_bounds = &target_interact_component_data->bounds;
|
const frect_t *target_interact_bounds = &target_interact_component_data->bounds;
|
||||||
|
|
||||||
if(fhas_intersection(hitbox_bounds, target_interact_bounds))
|
if(fhas_intersection(hitbox_bounds, target_interact_bounds))
|
||||||
{
|
{
|
||||||
if(interact_component_interact(target_interact_component_data)) return_failure_int;
|
if(interact_component_interact(target_interact_component)) return_failure_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,24 @@
|
||||||
#include "sprite_component.h"
|
#include "sprite_component.h"
|
||||||
|
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
#include "ecs.h"
|
||||||
|
#include "transform_component.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "memory_alloc.h"
|
#include "memory_alloc.h"
|
||||||
|
#include "errors.h"
|
||||||
|
|
||||||
inline int sprite_component_init(component_t *component)
|
inline int sprite_component_init(component_t *component)
|
||||||
{
|
{
|
||||||
sprite_component_data_t *component_data = component->data;
|
sprite_component_data_t *component_data = component->data;
|
||||||
|
|
||||||
component_t * transform_component = entity_get_component(component->entity, TRANSFORM_COMPONENT);
|
component_data->transform_component = entity_get_component(component->entity, TRANSFORM_COMPONENT);
|
||||||
if(!transform_component)
|
if(!component_data->transform_component)
|
||||||
{
|
{
|
||||||
error_printf("Sprite component require a transform component.");
|
error_printf("Sprite component require a transform component.");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
component_data->transform_component_data = transform_component->data;
|
|
||||||
|
|
||||||
transform_component_data_t *transform_component_data = component_data->transform_component_data;
|
transform_component_data_t *transform_component_data = component_data->transform_component->data;
|
||||||
|
|
||||||
frect_to_rect(&transform_component_data->bounds, &component_data->src_rect);
|
frect_to_rect(&transform_component_data->bounds, &component_data->src_rect);
|
||||||
component_data->src_rect.x = 0;
|
component_data->src_rect.x = 0;
|
||||||
|
|
@ -30,7 +32,7 @@ inline int sprite_component_init(component_t *component)
|
||||||
inline int sprite_component_update(component_t *component)
|
inline int sprite_component_update(component_t *component)
|
||||||
{
|
{
|
||||||
sprite_component_data_t *component_data = component->data;
|
sprite_component_data_t *component_data = component->data;
|
||||||
transform_component_data_t *transform_component_data = component_data->transform_component_data;
|
transform_component_data_t *transform_component_data = component_data->transform_component->data;
|
||||||
|
|
||||||
component_data->dst_rect = transform_component_data->bounds;
|
component_data->dst_rect = transform_component_data->bounds;
|
||||||
component->entity->draw_priority = transform_component_data->bounds.y + transform_component_data->bounds.h;
|
component->entity->draw_priority = transform_component_data->bounds.y + transform_component_data->bounds.h;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include "transform_component.h"
|
#include "transform_component.h"
|
||||||
|
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
#include "ecs.h"
|
||||||
#include "memory_alloc.h"
|
#include "memory_alloc.h"
|
||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
|
|
||||||
|
|
|
||||||
16
src/game.c
16
src/game.c
|
|
@ -64,7 +64,7 @@ int game_init(void)
|
||||||
|
|
||||||
animation_system_data->current_frame_nb = 0;
|
animation_system_data->current_frame_nb = 0;
|
||||||
animation_system_data->nb_frames = 4;
|
animation_system_data->nb_frames = 4;
|
||||||
if(animation_system_apply_changes(animation_system_data)) return_failure_int;
|
if(animation_system_apply_changes(animation_system)) return_failure_int;
|
||||||
|
|
||||||
animation_system_data->play = true;
|
animation_system_data->play = true;
|
||||||
animation_system_data->loop = true;
|
animation_system_data->loop = true;
|
||||||
|
|
@ -137,7 +137,7 @@ int game_init(void)
|
||||||
animation_system_data->loop = false;
|
animation_system_data->loop = false;
|
||||||
animation_system_data->reverse = false;
|
animation_system_data->reverse = false;
|
||||||
|
|
||||||
if(animation_system_apply_changes(animation_system_data)) return_failure_int;
|
if(animation_system_apply_changes(animation_system)) return_failure_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
@ -176,7 +176,7 @@ int game_init(void)
|
||||||
interact_component_data->type = INTERACT_TOGGLE;
|
interact_component_data->type = INTERACT_TOGGLE;
|
||||||
interact_component_data->state = 0;
|
interact_component_data->state = 0;
|
||||||
|
|
||||||
interact_component_modify_topic_id(interact_component_data, 0);
|
interact_component_modify_topic_id(interact_component, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -189,7 +189,7 @@ int game_init(void)
|
||||||
lever_component_data->topic_id = 0;
|
lever_component_data->topic_id = 0;
|
||||||
lever_component_data->state = false;
|
lever_component_data->state = false;
|
||||||
|
|
||||||
lever_component_subscribe(lever_component_data, lever_entity);
|
lever_component_subscribe(lever_component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -238,7 +238,7 @@ int game_init(void)
|
||||||
animation_system_data->loop = false;
|
animation_system_data->loop = false;
|
||||||
animation_system_data->reverse = false;
|
animation_system_data->reverse = false;
|
||||||
|
|
||||||
if(animation_system_apply_changes(animation_system->data)) return_failure_int;
|
if(animation_system_apply_changes(animation_system)) return_failure_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
@ -267,7 +267,7 @@ int game_init(void)
|
||||||
door_component_data->topic_id = 0;
|
door_component_data->topic_id = 0;
|
||||||
door_component_data->state = false;
|
door_component_data->state = false;
|
||||||
|
|
||||||
door_component_subscribe(door_component_data, door_entity);
|
door_component_subscribe(door_component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -316,7 +316,7 @@ int game_init(void)
|
||||||
animation_system_data->loop = false;
|
animation_system_data->loop = false;
|
||||||
animation_system_data->reverse = false;
|
animation_system_data->reverse = false;
|
||||||
|
|
||||||
if(animation_system_apply_changes(animation_system->data)) return_failure_int;
|
if(animation_system_apply_changes(animation_system)) return_failure_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
@ -345,7 +345,7 @@ int game_init(void)
|
||||||
door_component_data->topic_id = 0;
|
door_component_data->topic_id = 0;
|
||||||
door_component_data->state = false;
|
door_component_data->state = false;
|
||||||
|
|
||||||
door_component_subscribe(door_component_data, door2_entity);
|
door_component_subscribe(door_component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue