8#include "components/ComponentType.hpp"
13struct GameObject :
public std::enable_shared_from_this<GameObject> {
18 std::weak_ptr<GameObject> GetThisPtr() {
return weak_from_this(); }
24 virtual void Update(
float dt);
31 template <
typename T>
void AddComponent(std::shared_ptr<T> component);
37 void AddChild(std::shared_ptr<GameObject> child);
52 bool Intersects(std::shared_ptr<GameObject> e);
57 std::map<ComponentType, std::shared_ptr<Component>> mComponents;
58 bool mRenderable{
true};
59 std::vector<std::shared_ptr<GameObject>> mChildren;
Definition Component.hpp:17
Main unit of gameplay which contains and updated components.
Definition GameObject.hpp:13
std::shared_ptr< T > GetComponent()
Retrieves an existing component of the specified type, or nullptr if there is none.
Definition GameObject.cpp:61
std::shared_ptr< GameObject > GetChildAtIndex(size_t idx)
Definition GameObject.cpp:82
void AddComponent(std::shared_ptr< T > component)
Adds a component of the specified type.
Definition GameObject.cpp:54
virtual void Input()
Refreshes input for all components and children each frame.
Definition GameObject.cpp:21
virtual void Render()
Renders all components and children.
Definition GameObject.cpp:41
bool Intersects(std::shared_ptr< GameObject > e)
Definition GameObject.cpp:90
virtual void Update(float dt)
Runs Update on all components and children.
Definition GameObject.cpp:31
void SetRenderable(bool renderable)
Definition GameObject.cpp:86
bool IsRenderable() const
Queries if this GameObject can be rendered.
Definition GameObject.cpp:88
void AddChild(std::shared_ptr< GameObject > child)
Adds a child GameObject to this GameObject.
Definition GameObject.cpp:78