centity.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. *** :: Entity ::
  3. ***
  4. *** Interface for interacting with Entities in virtual world
  5. ***
  6. *** An entity is any form of persistent object in the world.
  7. *** These can be created, destoryed or interacted with.
  8. ***
  9. **/
  10. #ifndef centity_h
  11. #define centity_h
  12. #include "cengine.h"
  13. typedef void entity;
  14. void entity_init(void);
  15. void entity_finish(void);
  16. #define entity_handler(type, new, del) entity_handler_cast(typeid(type), (void*(*)())new , (void(*)(void*))del)
  17. void entity_handler_cast(int type_id, void* entity_new() , void entity_del(void* entity));
  18. /* Create, get and destroy entities */
  19. #define entity_new(fmt, type, ...) (type*)entity_new_type_id(fmt, typeid(type), ##__VA_ARGS__)
  20. #define entity_get_as(fmt, type, ...) ((type*)entity_get_as_type_id(fmt, typeid(type)), ##__VA_ARGS__)
  21. bool entity_exists(char* fmt, ...);
  22. entity* entity_get(char* fmt, ...);
  23. entity* entity_get_as_type_id(char* fmt, int type_id, ...);
  24. entity* entity_new_type_id(char* fmt, int type_id, ...);
  25. void entity_delete(char* fmt, ...);
  26. /* Get the name or typename from an entity */
  27. char* entity_name(entity* e);
  28. char* entity_typename(entity* a);
  29. /* Get the number of a certain entity type */
  30. #define entity_type_count(type) entity_type_count_type_id(typeid(type))
  31. int entity_type_count_type_id(int type_id);
  32. /* Create or get multiple entities of a certain type */
  33. #define entities_new(name_format, count, type) entities_new_type_id(name_format, count, typeid(type))
  34. #define entities_get(out, returned, type) entities_get_type_id((entity**)out, returned, typeid(type))
  35. /* Argument 'name_format' should contain '%i' for created index */
  36. void entities_new_type_id(const char* name_format, int count, int type_id);
  37. void entities_get_type_id(entity** out, int* returned, int type_id);
  38. #endif