level.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #pragma once
  2. #include <stddef.h>
  3. #include "entity.h"
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. typedef struct GameManager GameManager;
  8. typedef struct {
  9. void (*alloc)(Level* level, GameManager* manager, void* context);
  10. void (*free)(Level* level, GameManager* manager, void* context);
  11. void (*start)(Level* level, GameManager* manager, void* context);
  12. void (*stop)(Level* level, GameManager* manager, void* context);
  13. size_t context_size;
  14. } LevelBehaviour;
  15. /**
  16. * @brief Remove all entities from the level
  17. *
  18. * @param level level instance
  19. */
  20. void level_clear(Level* level);
  21. /**
  22. * @brief Add an entity to the level
  23. *
  24. * @param level level instance
  25. * @param behaviour entity behaviour
  26. * @return Entity*
  27. */
  28. Entity* level_add_entity(Level* level, const EntityDescription* behaviour);
  29. /**
  30. * @brief Remove an entity from the level
  31. *
  32. * @param level level instance
  33. * @param entity entity to remove
  34. */
  35. void level_remove_entity(Level* level, Entity* entity);
  36. /**
  37. * @brief Send an event to all entities of a certain type in the level
  38. *
  39. * @param level level instance
  40. * @param sender entity that sends the event
  41. * @param receiver_desc entity description that will receive the event, NULL for all entities
  42. * @param type event type
  43. * @param value event value
  44. */
  45. void level_send_event(
  46. Level* level,
  47. Entity* sender,
  48. const EntityDescription* receiver_desc,
  49. uint32_t type,
  50. EntityEventValue value);
  51. /**
  52. * @brief Get the count of entities of a certain type in the level, or all entities if description is NULL
  53. *
  54. * @param level level instance
  55. * @param description entity description, NULL for all entities
  56. * @return size_t entity count
  57. */
  58. size_t level_entity_count(const Level* level, const EntityDescription* description);
  59. /**
  60. * @brief Get an entity of a certain type in the level
  61. * Returns NULL if the index is out of bounds
  62. *
  63. * @param level level instance
  64. * @param description entity description, NULL for all entities
  65. * @param index entity index
  66. * @return Entity* entity
  67. */
  68. Entity* level_entity_get(const Level* level, const EntityDescription* description, size_t index);
  69. /**
  70. * @brief Get the context of the level
  71. *
  72. * @param level level instance
  73. * @return void* context
  74. */
  75. void* level_context_get(Level* level);
  76. #ifdef __cplusplus
  77. }
  78. #endif