level.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 the context of the level
  61. *
  62. * @param level level instance
  63. * @return void* context
  64. */
  65. void* level_context_get(Level* level);
  66. #ifdef __cplusplus
  67. }
  68. #endif