entity.h (1401B)
1 2 #ifndef ENTITY_H 3 #define ENTITY_H 4 5 #include "node.h" 6 #include "model.h" 7 #include "id.h" 8 #include "util.h" 9 #include <assert.h> 10 11 #define MAX_ENTITIES 10048 12 #define ENTITY_DATA_SIZE 128 13 14 enum entity_flags { 15 ENT_IS_PLAYER = 1 << 0, 16 ENT_INVISIBLE = 1 << 1, 17 ENT_CASTS_SHADOWS = 1 << 2, 18 ENT_ON_GROUND = 1 << 3, 19 }; 20 21 struct entity { 22 struct node_id node_id; 23 struct model_id model_id; 24 u32 flags; 25 u32 type; 26 float velocity[3]; // move into entity components 27 float accel[3]; 28 u8 data[ENTITY_DATA_SIZE]; 29 }; 30 31 struct entity_id { 32 struct resource_id id; 33 }; 34 35 struct entity *init_entity(struct entity *, struct node_id *id); 36 void destroy_entities(); 37 void destroy_entity(struct entity_id *); 38 void init_entity_system(); 39 struct entity *get_entity(struct entity_id *); 40 const char *entity_label(struct entity *); 41 struct entity *get_all_entities(u32 *count, struct entity_id **ids); 42 struct entity *new_entity_with_node(struct entity_id *, struct node_id *); 43 struct entity *new_debug_entity(struct entity_id *, float *pos); 44 void destroy_entity_system(); 45 46 static inline struct entity *new_entity_(struct entity_id *id) { 47 return new_entity_with_node(id, NULL); 48 } 49 50 static inline struct entity *new_entity(struct entity_id *id) 51 { 52 if (id) 53 assert((int)id->id.index == -1 && 54 "error: " __FILE__ ":" STRIZE(__LINE__) " missing init_id or already initialized"); 55 return new_entity_(id); 56 } 57 58 #endif /* ENTITY_H */