polyadvent

A game engine from scratch in C
git clone git://jb55.com/polyadvent
Log | Files | Refs | README

entity.h (1363B)


      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 
     13 enum entity_flags {
     14   ENT_IS_PLAYER     = 1 << 0,
     15   ENT_INVISIBLE     = 1 << 1,
     16   ENT_CASTS_SHADOWS = 1 << 2,
     17   ENT_ON_GROUND     = 1 << 3,
     18 };
     19 
     20 struct entity {
     21     node_id node_id;
     22     model_id model_id;
     23     u32 flags;
     24     float velocity[3];
     25     float accel[3];
     26 };
     27 
     28 typedef struct resource_id entity_id;
     29 
     30 struct entity *init_entity(struct entity *, node_id *id);
     31 void destroy_entities();
     32 struct resource_manager *_internal_get_entity_system();
     33 void destroy_entity(entity_id *);
     34 void init_entity_system();
     35 struct entity *get_entity(entity_id *);
     36 const char *entity_label(struct entity *);
     37 struct entity *get_all_entities(u32 *count, entity_id **ids);
     38 struct entity *new_entity_(entity_id *);
     39 struct entity *new_entity_with_node(entity_id *, node_id *);
     40 struct entity *new_debug_entity(entity_id *, float *pos);
     41 void destroy_entity_system();
     42 
     43 static inline struct entity *static_entities()
     44 {
     45     return (struct entity*)_internal_get_entity_system()->resources;
     46 }
     47 
     48 static inline struct entity *new_entity(entity_id *id)
     49 {
     50     if (id)
     51         assert((int)id->index == -1 && "error: " __FILE__ ":" STRIZE(__LINE__) " missing init_id or already initialized");
     52     return new_entity_(id);
     53 }
     54 
     55 #endif /* ENTITY_H */