18 const unsigned index = GetNextComponentIndex();
20 if (index != InvalidComponentIndex)
22 components[ index ].handle = T::New();
23 components[ index ].type = T::Type();
24 GetComponent< T >()->gameObject =
this;
31 for (
unsigned i = 0; i < nextFreeComponentIndex; ++i)
33 if (components[ i ].type == T::Type())
35 GetComponent< T >()->gameObject =
nullptr;
36 components[ i ].handle = 0;
37 components[ i ].type = -1;
46 for (
const auto& component : components)
48 if (T::Type() == component.type)
50 return T::Get( component.handle );
67 void SetName(
const char* aName ) { name = aName; }
76 const std::string&
GetName()
const {
return name; }
79 void SetLayer(
unsigned aLayer ) { layer = aLayer; }
94 unsigned GetNextComponentIndex();
96 static const int MaxComponents = 10;
97 unsigned nextFreeComponentIndex = 0;
98 ComponentEntry components[ MaxComponents ];
101 bool isEnabled =
true;
const std::string & GetName() const
Definition: GameObject.hpp:76
void SetName(const char *aName)
Definition: GameObject.hpp:67
void RemoveComponent()
Remove a component from the game object.
Definition: GameObject.hpp:29
unsigned GetLayer() const
Definition: GameObject.hpp:82
static const unsigned InvalidComponentIndex
Invalid component index.
Definition: GameObject.hpp:13
Definition: AudioClip.hpp:4
GameObject & operator=(const GameObject &go)
void SetLayer(unsigned aLayer)
Definition: GameObject.hpp:79
void AddComponent()
Adds a component into the game object. There can be multiple components of the same type...
Definition: GameObject.hpp:16
void SetEnabled(bool enabled)
Definition: GameObject.hpp:70
GameObject()=default
Constructor.
std::string GetSerialized() const
GameObject is composed of components that define its behavior.
Definition: GameObject.hpp:9
T * GetComponent() const
Definition: GameObject.hpp:44