Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.36 KB | None | 0 0
  1. /// \file BehaviourMap.h
  2. /// \author plo
  3. /// \brief Makes managing large amounts of entities easier
  4. #pragma once
  5. #include "Renderer.h"
  6.  
  7. struct _World;
  8. struct _Entity;
  9.  
  10. ///< The arguments that must be present in every behaviour function
  11. #define BEHAVIOUR_ARGUMENTS Renderer* renderer, struct _World* world, struct _Entity*
  12.  
  13. /// \brief A behaviour that holds a few functions that will be executed at specific times
  14. ///
  15. /// For any of these functions you can simply use NULL and nothing will be executed. Do
  16. /// note that if the onDraw function is not NULL, the entity will not be drawn by the world
  17. /// at all and drawing the entity is now entirely on you.
  18. typedef struct {
  19.     void (*onCreation)(BEHAVIOUR_ARGUMENTS); ///< Will be executed when its added to a world using worldAddEntity
  20.     void (*onDestruction)(BEHAVIOUR_ARGUMENTS); ///< Will be executed when this is freed from a world
  21.     void (*onFrame)(BEHAVIOUR_ARGUMENTS); ///< Will be executed during each frame
  22.     void (*onDraw)(BEHAVIOUR_ARGUMENTS); ///< Will be executed in place of normal world drawing functionality
  23. } Behaviour;
  24.  
  25. /// \brief A dictionary of strings to behaviours
  26. typedef struct {
  27.     Behaviour** behaviours; ///< The behaviours
  28.     const char** names; ///< The names of the behaviours
  29.     uint32 size; ///< How many behaviours/names in this struct
  30. } BehaviourMap;
  31.  
  32. /// \brief Creates a behaviour map
  33. /// \throws ERROR_ALLOC_FAILED
  34. BehaviourMap* createBehaviourMap();
  35.  
  36. /// \brief Adds a behaviour to a behaviour map
  37. ///
  38. /// If the entity doesn't need a behaviour for onCreation, for example,
  39. /// you can just leave it as NULL and nothing will be executed on creation.
  40. ///
  41. /// \warning Strings passed to this function belong to the caller, not the map (It expects just in-code strings)
  42. /// \throws ERROR_NULL_POINTER
  43. /// \throws ERROR_REALLOC_FAILED
  44. void addBehaviourToMap(BehaviourMap* map, const char* name, void (*onCreation)(BEHAVIOUR_ARGUMENTS), void (*onDestruction)(BEHAVIOUR_ARGUMENTS), void (*onFrame)(BEHAVIOUR_ARGUMENTS), void (*onDraw)(BEHAVIOUR_ARGUMENTS));
  45.  
  46. /// \brief Grabs a behaviour struct (that still belongs to the map) from a map
  47. ///
  48. /// Contrary to other functions like this, it will not set ERROR_NULL_POINTER
  49. /// if you don't give it a map.
  50. Behaviour* getBehaviourFromMap(BehaviourMap* map, const char* name);
  51.  
  52. /// \brief Frees a behaviour map
  53. void freeBehaviourMap(BehaviourMap* map);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement