Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. Planet-> Vector of all Actors
  2. Actor-> Vector of all Behaviors
  3. Behaviour-> Game Logic
  4.  
  5. class Actor;
  6.  
  7. class Behaviour
  8. {
  9. protected:
  10. Actor* actor;
  11. public:
  12. string type;
  13. Behaviour();
  14. ~Behaviour();
  15. virtual void Init(); // virtual because every component needs to override them
  16. virtual void Tick();
  17. }
  18.  
  19. // Actor.h
  20. class Planet;
  21.  
  22. class Actor
  23. {
  24. private:
  25. unsigned id;
  26. string name;
  27. vector< unique_ptr< Behaviour > > allBehaviours;
  28. protected:
  29. Planet* planet;
  30. public:
  31. Actor();
  32. ~Actor();
  33. void Init(); // Go through all the behaviors and call their Inits and Ticks
  34. void Tick();
  35.  
  36. template <typename T, typename ...Args>
  37. void AddBehaviour(Args && ...args); // Creates and adds a new Behaviour of type T to the allBehaviours vector
  38.  
  39. template <typename T>
  40. T& GetBehaviour(std::string type); // Loops through all the Behaviours, and returns the Behaviour whose type is the same as type
  41.  
  42. // Actor.cpp
  43.  
  44. #include "Planet.h"
  45. #include "Behaviour.h"
  46. #include "Actor.h"
  47.  
  48. // Implement Functions
  49.  
  50. // Planet.h
  51.  
  52. class Actor;
  53.  
  54. class Planet
  55. {
  56. private:
  57. unsigned idCounter = 0;
  58. string name;
  59. vector< unique_ptr< Actor > > allActors;
  60. public:
  61. unsigned GetNewID();
  62. void Init();
  63. void Tick(); // Used to loop through all the Actors
  64.  
  65. void AddActor(Actor* newActor); // adds a new Actor to the list of all Actors
  66. void KillActor(int id); // loops through all the Actors and when it finds an Actor whose unique id is matching the id variable it erases it from the allActors vector
  67.  
  68. }
  69.  
  70. // Planet.cpp
  71.  
  72. #include "Public.h"
  73. #include "Actor.h"
  74. #include "Planet.h"
  75.  
  76. Planet::KillActor(int id){
  77. unsigned i = 0;
  78. for (auto& a : allActors) {
  79. if (a->GetID() == id)
  80. allActors.erase(allActors.begin() + i);
  81. i++;
  82. }
  83. }
  84.  
  85. // Other Functions
  86.  
  87. {
  88. // other stuff
  89. win.GetCurrentPlanet()->AddActor(this);
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement