37#include "scene/Component.h"
72 auto iter = m_creators.find(typeName);
73 if (iter == m_creators.end())
77 return iter->second->CreateGameObject();
81 std::unordered_map<std::string, std::unique_ptr<ObjectCreatorBase>> m_creators;
124 template<
typename T,
typename =
typename std::enable_if_t<std::is_base_of_v<Component, T>>>
127 usize typeId = Component::StaticTypeId<T>();
129 for (
auto &component : m_components)
131 if (component->GetTypeId() == typeId)
133 return static_cast<T *
>(component.get());
210 const std::vector<std::unique_ptr<GameObject>> &
GetChildren()
const {
return m_children; }
213 const std::vector<std::unique_ptr<Component>> &
GetComponents()
const {
return m_components; }
219 std::vector<std::unique_ptr<GameObject>> m_children;
220 std::vector<std::unique_ptr<Component>> m_components;
224 Scene *m_scene =
nullptr;
225 bool m_isAlive =
true;
228 quat m_rotation =
quat(1.0f, 0.0f, 0.0f, 0.0f);
230 bool m_active =
true;
235#define GAMEOBJECT(ObjectClass) \
237 static void Register() \
239 mnd::GameObjectFactory::GetInstance().RegisterObject<ObjectClass>(std::string(#ObjectClass)); \
Engine-wide primitive type aliases and GLM math imports.
GameObject * CreateGameObject(const std::string &typeName)
void RegisterObject(const std::string &name)
static GameObjectFactory & GetInstance()
Node in the scene graph: a named transform that owns components and children.
const vec3 & GetScale() const
void SetName(const str &name)
Sets the display name (used by FindChildByName).
bool IsAlive() const
Returns false after MarkForDestroy() is called.
const std::vector< std::unique_ptr< Component > > & GetComponents() const
Editor access: iterate attached components (non-owning).
virtual void Update(f32 deltaTime)
Update this object and all its components and children recursively.
const vec3 & GetPosition() const
void SetActive(bool active)
Show/hide this object (and stop Update calls).
vec3 GetWorldPosition() const
Extract the world-space position from GetWorldTransform().
void SetPosition(const vec3 &pos)
static GameObject * LoadGLTF(const std::string &path, Scene *scene)
Load a GLTF / GLB file and build a matching GameObject hierarchy.
const str & GetName() const
Returns the object's display name.
void MarkForDestroy()
Flag this object for removal at end of frame.
mat4 GetLocalTransform() const
Compute the local transform matrix (TRS order).
void SetWorldRotation(const quat &rot)
void SetRotation(const quat &rot)
virtual ~GameObject()=default
void AddComponent(Component *component)
Attach a component to this object (takes ownership).
void SetScale(const vec3 &scale)
bool SetParent(GameObject *parent)
Re-parent this object in the scene hierarchy.
const quat & GetRotation() const
GameObject * GetParent()
Returns the parent node, or nullptr for root objects.
bool IsActive() const
Returns false if the object is hidden.
GameObject * FindChildByName(const std::string &name)
Depth-first search for a child with the given name.
Scene * GetScene()
Returns the Scene that owns this object.
const std::vector< std::unique_ptr< GameObject > > & GetChildren() const
Editor access: iterate immediate children (non-owning).
T * GetComponent()
Find and return the first component of type T attached to this object.
mat4 GetWorldTransform() const
Compute the world transform by walking up the parent chain.
void SetWorldPosition(const vec3 &pos)
virtual void LoadProperties(const nlohmann::json &json)
Container for the entire game object graph.
glm::mat4 mat4
4×4 column-major float matrix (model/view/projection).
glm::vec3 vec3
3-component float vector (e.g. world position, RGB colour, normals).
glm::quat quat
Unit quaternion for rotation (avoids gimbal lock).
std::string str
Convenience alias for std::string.
float f32
32-bit IEEE float — the standard GL scalar type.
size_t usize
Platform-native unsigned size type.
virtual ~ObjectCreatorBase()=default
virtual GameObject * CreateGameObject()=0
GameObject * CreateGameObject() override