c_api_entity.h - Engine C API Reference

c_api_entity.h
  1. #pragma once
  2. #include "c_api_types.h"
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. /* Manages the lifetime of an entity. */
  7. struct EntityManagerApi
  8. {
  9. EntityRef (*create)(const void *owner);
  10. void (*destroy)(EntityRef entity);
  11. int (*is_alive)(EntityRef entity);
  12. EntityRef (*spawn)(WorldPtr world, uint64_t entity_name_id64, const char *optional_debug_entity_name, ConstMatrix4x4Ptr transform);
  13. };
  14. /* Opaque struct representing the component api extension. */
  15. struct ComponentExtensionApi;
  16. /* Component property api. */
  17. typedef struct ComponentPropertyApi {
  18. /* Set component propery value. */
  19. void (*set_property)(ComponentPtr component, Instance i, EntityPropertyKey key, struct EntityPropertyValue value);
  20. /* Get component property value. */
  21. struct EntityPropertyValue (*get_property)(ComponentPtr component, Instance i, EntityPropertyKey key, struct AllocatorObject *temp_allocator);
  22. } ComponentPropertyApi;
  23. /* Component Api. */
  24. typedef struct ComponentApi
  25. {
  26. /* Gets type name of the entity component. */
  27. uint32_t (*type_name)();
  28. /* Gets the component manager for the specified world. */
  29. ComponentPtr (*component)(void *owner);
  30. /* Creates a new component instance. */
  31. Instance (*create)(ComponentPtr component, EntityRef entity, InstanceId instance_id);
  32. /* Destroy component instance. */
  33. void (*destroy)(ComponentPtr component, Instance i);
  34. /* Destroy all instances of the entity. */
  35. void (*destroy_all)(ComponentPtr component, EntityRef entity);
  36. /* Gets the component instance from the specified component id. */
  37. Instance (*lookup_instance)(ComponentPtr component, EntityRef entity, InstanceId id);
  38. /* Gets the component instance id from the specified component instance. */
  39. struct EntityInstanceId (*lookup_instance_id)(ComponentPtr component, Instance i);
  40. /* Spawn component. */
  41. void (*spawn)(ComponentPtr component, const EntityRef *entities, unsigned num_intances, const unsigned *entity_indicies, const unsigned *instance_ids, const char *data);
  42. /* Set entity parent. */
  43. void (*set_parent)(ComponentPtr component, const EntityRef *entities, unsigned num_entities, const unsigned *parent_index);
  44. /* Called when the entity as been fully constructed and spawned. */
  45. void (*spawned)(ComponentPtr component, const EntityRef *entities, unsigned num_entities);
  46. /* Gets the first component instance for the entity. */
  47. Instance (*first_instance)(ComponentPtr component, EntityRef entity);
  48. /* Gets the next component instance. */
  49. Instance (*next_instance)(ComponentPtr component, Instance i);
  50. /* Gets the component property api. */
  51. ComponentPropertyApi *(*get_property_api)();
  52. /*
  53. Retrieves a pointer to the component type specific API.
  54. To use this cast the ComponentExtensionApi pointer to to the relevant definition represented in it's header file.
  55. */
  56. struct ComponentExtensionApi *(*get_extension_api)();
  57. } ComponentApi;
  58. typedef ComponentApi *ComponentApiPtr;
  59. struct EntityCApi
  60. {
  61. struct EntityManagerApi* Manager;
  62. /*
  63. Retrieves a pointer to the Component API registered with the specified name.
  64. To use the member functions of the specified Component API cast the ComponentApiPtr to the relevant definition represented in it's header file."
  65. */
  66. ComponentApiPtr (*component_api)(uint32_t name_id32);
  67. /* Registers a pointer to a component api with the specified name, the caller is responsible for keeping it allocated. */
  68. void (*register_component_api)(uint32_t name_id32, ComponentApiPtr component_api);
  69. /* Returns true (1) if a component api with the specified name has already been registered. */
  70. int (*has_component_api)(uint32_t name_id32);
  71. /* Unregisters a component struct with the specified name. */
  72. void (*unregister_component_api)(uint32_t name_id32);
  73. /* Registers the entity component to the specified world. */
  74. void (*register_entity_component)(WorldPtr world_pointer, ComponentPtr component, struct ComponentApi *component_api);
  75. /* Unregisters the entity component from the specified world. */
  76. void (*unregister_entity_component)(WorldPtr world_pointer, ComponentPtr component);
  77. };
  78. #ifdef __cplusplus
  79. }
  80. #endif