|
SleakEngine 0.1.0
C++23 multi-backend game engine
|
#include <GameObject.hpp>
Public Member Functions | |
| GameObject (const std::string &name="GameObject") | |
| ~GameObject () override | |
| void | AddChild (GameObject *child) |
| template<typename T, typename... Args> | |
| void | AddComponent (Args &&... args) |
| Constructs and attaches a component of type T. Warns and no-ops if one already exists. | |
| virtual void | FixedUpdate (float fixedDeltaTime) |
| const List< GameObject * > & | GetChildren () const |
| template<typename T> | |
| T * | GetComponent () |
| Finds the first attached component of type T, or nullptr. | |
| GameObject * | GetParent () const |
| const std::string & | GetTag () const |
| bool | HasChildren () const |
| template<typename T> | |
| bool | HasComponent () |
| True if a component of type T is attached. | |
| bool | HasParent () const |
| virtual void | Initialize () |
| Initializes the object, components and children; repeats no-op. | |
| bool | IsActive () const |
| bool | IsInitialized () const |
| virtual bool | IsLight () const |
| bool | IsOwnedByScene () const |
| True once a scene took ownership through SceneBase::AddObject(). | |
| bool | IsPendingDestroy () const |
| virtual void | LateUpdate (float deltaTime) |
| void | MarkForDestroy () |
| Flags the object for deferred destruction on the next scene pass. | |
| void | RemoveChild (GameObject *child) |
| template<typename T> | |
| void | RemoveComponent () |
| Destroys and detaches the first component of type T, if present. | |
| void | SetActive (bool active) |
| Enables or disables the object, firing OnEnable/OnDisable on its components. | |
| void | SetParent (GameObject *parent) |
| Reparents this object, updating both the old and new parent's child lists. | |
| void | SetTag (const std::string &tag) |
| virtual void | Update (float deltaTime) |
| Public Member Functions inherited from Sleak::Object | |
| Object (const std::string &name="Object") | |
| virtual | ~Object ()=default |
| std::string | GetDebugName () const |
| Name plus unique ID, for logs where names can repeat. | |
| const std::string & | GetName () const |
| uint64_t | GetUniqueID () const |
| void | SetName (const std::string &value) |
Static Public Member Functions | |
| static GameObject * | CreateCapsule (Math::Vector3D position, int segments=16, int rings=8, float height=1, float radius=0.5) |
| static GameObject * | CreateCube (Math::Vector3D position) |
| static GameObject * | CreateCylinder (Math::Vector3D position, int segments=16, float height=1, float radius=0.5) |
| static GameObject * | CreatePlane (Math::Vector3D position, int width=100, int height=100) |
| Built-in primitive factories, mainly for prototyping and debug scenes. | |
| static GameObject * | CreateSphere (Math::Vector3D position, int stack=16, int slices=16) |
| static GameObject * | CreateTorus (Math::Vector3D position, int segments=16, int rings=8, float innerRadius=8, float outerRadius=9) |
Protected Attributes | |
| bool | bIsInitialized |
Friends | |
| class | SceneBase |
Scene entity holding components and an optional parent/child transform hierarchy. Scene owns the instance; destroy via Scene::DestroyObject().
A GameObject on its own does nothing. Behavior comes from the components attached to it: a TransformComponent for placement, a MeshComponent and MaterialComponent to be drawn, a ColliderComponent and RigidbodyComponent to be simulated, and your own Component subclasses for gameplay.
AddComponent<T>() constructs the component in place, forwarding extra arguments to its constructor after the owner pointer. Only one component of a given type is allowed per object: a second AddComponent<T>() logs a warning and does nothing. GetComponent<T>() resolves through dynamic_cast, so it also matches subclasses.
The scene that received the object through SceneBase::AddObject() owns it. Never delete a GameObject. Use SceneBase::DestroyObject() for deferred destruction, which is what you want while iterating, or SceneBase::RemoveObject() for immediate destruction.
A parent owns every child that was not itself added to a scene, so a hierarchy built with SetParent() (for example by ModelLoader) only needs its root added. Deleting a parent deletes those children too.
Camera, Light, and its subclasses all derive from GameObject, so they are added and found the same way as anything else.
Definition at line 62 of file GameObject.hpp.
|
inline |
Definition at line 64 of file GameObject.hpp.
|
override |
Definition at line 14 of file GameObject.cpp.
| void Sleak::GameObject::AddChild | ( | GameObject * | child | ) |
Definition at line 135 of file GameObject.cpp.
|
inline |
Constructs and attaches a component of type T. Warns and no-ops if one already exists.
Definition at line 72 of file GameObject.hpp.
|
static |
Definition at line 206 of file GameObject.cpp.
|
static |
Definition at line 178 of file GameObject.cpp.
|
static |
Definition at line 220 of file GameObject.cpp.
|
static |
Built-in primitive factories, mainly for prototyping and debug scenes.
Definition at line 164 of file GameObject.cpp.
|
static |
Definition at line 192 of file GameObject.cpp.
|
static |
|
virtual |
Definition at line 64 of file GameObject.cpp.
|
inline |
Definition at line 141 of file GameObject.hpp.
|
inline |
Finds the first attached component of type T, or nullptr.
Definition at line 101 of file GameObject.hpp.
|
inline |
Definition at line 140 of file GameObject.hpp.
|
inline |
Definition at line 136 of file GameObject.hpp.
|
inline |
Definition at line 145 of file GameObject.hpp.
|
inline |
True if a component of type T is attached.
Definition at line 118 of file GameObject.hpp.
|
inline |
Definition at line 144 of file GameObject.hpp.
|
virtual |
Initializes the object, components and children; repeats no-op.
Reimplemented in Sleak::Camera.
Definition at line 31 of file GameObject.cpp.
|
inline |
Definition at line 133 of file GameObject.hpp.
|
inline |
Definition at line 126 of file GameObject.hpp.
|
inlinevirtual |
Reimplemented in Sleak::Light.
Definition at line 149 of file GameObject.hpp.
|
inline |
True once a scene took ownership through SceneBase::AddObject().
Definition at line 147 of file GameObject.hpp.
|
inline |
Definition at line 153 of file GameObject.hpp.
|
virtual |
Definition at line 78 of file GameObject.cpp.
|
inline |
Flags the object for deferred destruction on the next scene pass.
Definition at line 152 of file GameObject.hpp.
| void Sleak::GameObject::RemoveChild | ( | GameObject * | child | ) |
Definition at line 140 of file GameObject.cpp.
|
inline |
Destroys and detaches the first component of type T, if present.
Definition at line 87 of file GameObject.hpp.
| void Sleak::GameObject::SetActive | ( | bool | active | ) |
Enables or disables the object, firing OnEnable/OnDisable on its components.
Definition at line 92 of file GameObject.cpp.
| void Sleak::GameObject::SetParent | ( | GameObject * | parent | ) |
Reparents this object, updating both the old and new parent's child lists.
Definition at line 111 of file GameObject.cpp.
|
inline |
Definition at line 135 of file GameObject.hpp.
|
virtual |
Reimplemented in Sleak::Camera.
Definition at line 50 of file GameObject.cpp.
|
friend |
Definition at line 183 of file GameObject.hpp.
|
protected |
Definition at line 164 of file GameObject.hpp.