#ifndef __GE_ENTIRY_H__ #define __GE_ENTIRY_H__ #include #include "ge_render_component.h" #include "ge_physics_component.h" #include "ge_collision_component.h" #include typedef uint16_t ge_ecs_id_t; // 支持65536个实体 #define GE_ECS_MAX 128 typedef enum { GE_COMPONENT_ACVIVE = 1 << 0, GE_COMPONENT_POSITION = 1 << 1, GE_COMPONENT_TRANSFORM = 1 << 2, // TODO not implimented GE_COMPONENT_RENDERABLE = 1 << 3, GE_COMPONENT_PHYSICS_BODY = 1 << 4, GE_COMPONENT_COLLIDER = 1 << 5, GE_COMPONENT_TIMED_LIFE = 1 << 6, // TODO not implimented } ge_ecs_mask_t; #define GE_RENDERABLE_MASK \ (GE_COMPONENT_POSITION | GE_COMPONENT_RENDERABLE) #define GE_PHYSICS_MASK \ (GE_COMPONENT_POSITION | GE_COMPONENT_PHYSICS_BODY) #define GE_COLLIDER_MASK \ (GE_COMPONENT_POSITION | GE_COMPONENT_COLLIDER) typedef struct ge_entity { int user_type; ge_ecs_id_t id; ge_ecs_mask_t component_mask; ge_vector2i_t position; ge_render_component_t renderable; ge_physics_component_t physics_body; ge_collision_component_t collision; } ge_entity_t; typedef struct { // TODO static storage to dynamic storage ge_entity_t entities[GE_ECS_MAX]; ge_ecs_id_t count; } ge_ecs_storage_t; typedef struct ge_ecs { ge_ecs_storage_t storage; } ge_ecs_t; static inline ge_ecs_id_t ge_ecs_add_entity(ge_ecs_t* ecs, ge_entity_t** entity) { ge_ecs_id_t id = ++ecs->storage.count; if (id >= GE_ECS_MAX) { return 0; } // TODO squeze the data if (entity != NULL) *entity = &ecs->storage.entities[id]; return id; } static inline ge_entity_t* ge_ecs_get_entity(ge_ecs_t* ecs, ge_ecs_id_t id) { if(id >= ecs->storage.count) { return NULL; } return &ecs->storage.entities[id]; } #endif // __GE_ENTIRY_H__