61 m_pendingDestroy(false), m_parent(nullptr) {}
66 template<
typename T,
typename... Args>
68 static_assert(std::is_base_of<Component, T>::value,
"T must derive from Component!");
78 Components.add(std::move(newComponent));
84 static_assert(std::is_base_of<Component, T>::value,
"T must derive from Component!");
86 for (
size_t i = 0; i < Components.GetSize(); ++i) {
87 if (
dynamic_cast<T*
>(Components[i].get()) !=
nullptr) {
88 Components[i]->OnDestroy();
98 static_assert(std::is_base_of_v<Component, T>,
99 "T must derive from Component!");
101 for (
size_t i = 0; i < Components.GetSize(); ++i) {
103 if (!rawPtr)
continue;
105 T* component =
dynamic_cast<T*
>(rawPtr);
106 if (component)
return component;
113 template <
typename T>
115 static_assert(std::is_base_of_v<Component, T>,
116 "T must derive from Component!");
121 virtual void Initialize();
122 virtual void Update(
float deltaTime);
123 virtual void FixedUpdate(
float fixedDeltaTime);
124 virtual void LateUpdate(
float deltaTime);
127 void SetActive(
bool active);
130 void SetTag(
const std::string& tag) { m_tag = tag; }
131 const std::string&
GetTag()
const {
return m_tag; }
142 virtual bool IsLight()
const {
return false; }
161 bool m_pendingDestroy;
162 std::string m_tag =
"Untagged";
171 void DestroyComponents();
bool HasComponent()
True if a component of type T is attached.
GameObject * GetParent() const
void AddComponent(Args &&... args)
Constructs and attaches a component of type T. Warns and no-ops if one already exists.
const List< GameObject * > & GetChildren() const
void MarkForDestroy()
Flags the object for deferred destruction on the next scene pass.
bool IsPendingDestroy() const
virtual bool IsLight() const
T * GetComponent()
Finds the first attached component of type T, or nullptr.
void SetTag(const std::string &tag)
GameObject(const std::string &name="GameObject")
static GameObject * CreateTorus(Math::Vector3D position, int segments=16, int rings=8, float innerRadius=8, float outerRadius=9)
const std::string & GetTag() const
void RemoveComponent()
Destroys and detaches the first component of type T, if present.
Implements a dynamic array-like list for storing and managing a collection of elements.
Object(const std::string &name="Object")
Vectors, matrices, quaternions, colors, AABBs, and random helpers.
Root namespace for everything the engine exposes.