|
SleakEngine 1.0.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 and its components; called once before the first Update. | |
| bool | IsActive () const |
| virtual bool | IsLight () const |
| 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 |
| 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 |
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.
Camera, Light, and its subclasses all derive from GameObject, so they are added and found the same way as anything else.
Definition at line 57 of file GameObject.hpp.
|
inline |
Definition at line 59 of file GameObject.hpp.
|
override |
Definition at line 14 of file GameObject.cpp.
| void Sleak::GameObject::AddChild | ( | GameObject * | child | ) |
Definition at line 115 of file GameObject.cpp.
|
inline |
Constructs and attaches a component of type T. Warns and no-ops if one already exists.
Definition at line 67 of file GameObject.hpp.
|
static |
Definition at line 186 of file GameObject.cpp.
|
static |
Definition at line 158 of file GameObject.cpp.
|
static |
Definition at line 200 of file GameObject.cpp.
|
static |
Built-in primitive factories, mainly for prototyping and debug scenes.
Definition at line 144 of file GameObject.cpp.
|
static |
Definition at line 172 of file GameObject.cpp.
|
static |
|
virtual |
Definition at line 52 of file GameObject.cpp.
|
inline |
Definition at line 136 of file GameObject.hpp.
|
inline |
Finds the first attached component of type T, or nullptr.
Definition at line 97 of file GameObject.hpp.
|
inline |
Definition at line 135 of file GameObject.hpp.
|
inline |
Definition at line 131 of file GameObject.hpp.
|
inline |
Definition at line 140 of file GameObject.hpp.
|
inline |
True if a component of type T is attached.
Definition at line 114 of file GameObject.hpp.
|
inline |
Definition at line 139 of file GameObject.hpp.
|
virtual |
Initializes the object and its components; called once before the first Update.
Reimplemented in Sleak::Camera.
Definition at line 30 of file GameObject.cpp.
|
inline |
Definition at line 128 of file GameObject.hpp.
|
inlinevirtual |
Reimplemented in Sleak::Light.
Definition at line 142 of file GameObject.hpp.
|
inline |
Definition at line 146 of file GameObject.hpp.
|
virtual |
Definition at line 66 of file GameObject.cpp.
|
inline |
Flags the object for deferred destruction on the next scene pass.
Definition at line 145 of file GameObject.hpp.
| void Sleak::GameObject::RemoveChild | ( | GameObject * | child | ) |
Definition at line 120 of file GameObject.cpp.
|
inline |
Destroys and detaches the first component of type T, if present.
Definition at line 83 of file GameObject.hpp.
| void Sleak::GameObject::SetActive | ( | bool | active | ) |
Enables or disables the object, firing OnEnable/OnDisable on its components.
Definition at line 80 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 99 of file GameObject.cpp.
|
inline |
Definition at line 130 of file GameObject.hpp.
|
virtual |
Reimplemented in Sleak::Camera.
Definition at line 38 of file GameObject.cpp.
|
protected |
Definition at line 157 of file GameObject.hpp.