Rune Engine  Version 0.2.7-alpha
Documentation for how to make games using the Rune Engine.
gameObject.h
1 
9 #ifndef GAMEOBJECT_INCLUDE_H
10 #define GAMEOBJECT_INCLUDE_H
11 
12 #include "core.h"
13 #include "transform.h"
14 #include <typeinfo>
15 #include <Entities\component.h>
16 #include <Renderer\renderWindow.h>
17 #include <Events\subject.h>
18 #include <vector>
19 
20 namespace rune{
21 
22 class RUNE_ENGINE GameObject : public Subject
23 {
24 private:
25  //This must be a vector of pointers because of the fact that they can't be stored in a List.
26  //They can't be stored in a list because during iteration of components, getComponent would
27  //reset the list index and enter into an infinite loop.
28  std::vector<rune::Component*> objectComponents;
29 
30 public:
34  GameObject();
36  void addComponent(rune::Component&);
38  int getNumComponents(void);
39  //Create a new dynamically allocated version of this game object.
40  void instantiate(GameObject&);
42  std::vector<Component*>& getComponentList();
46  template<class classVariable>
47  classVariable* getComponent()
48  {
49 
50  for(int i = 0; i < objectComponents.size(); i++)
51  {
52 
53  if (typeid(*objectComponents[i]) == typeid(classVariable))
54  {
55 
56  return dynamic_cast<classVariable*>(objectComponents[i]);
57 
58  }
59 
60  }
61 
62  return nullptr;
63 
64  }
65 
66 };
67 }
68 
69 #endif
70 
rune::GameObject::transform
rune::Transform transform
The location, scale, and rotation of the object in the world.
Definition: gameObject.h:32
rune::Subject
A subject that can be watched for signals by observers.
Definition: subject.h:21
rune::Component
A component of a rune::GameObject, this class is used to add functionality to a object in the game wo...
Definition: component.h:23
rune::GameObject::getComponent
classVariable * getComponent()
Definition: gameObject.h:47
rune::Transform
A data structure that contains position, size, and rotation.
Definition: transform.h:23
rune
The main namespace to be used for interfacing with the engine.
Definition: animator.h:21
rune::GameObject
Entity control system main object used for all objects in the scene.
Definition: gameObject.h:23