SPARK
0.1.0
A general purpose game engine written in C++.
|
A GameObject is any object in the game. It contains a list of components that provides functionality to the GameObject. More...
#include <GameObject.h>
Public Member Functions | |
GameObject (std::string name, GameObject *parent=nullptr) | |
Instantiates a new GameObject. | |
GameObject (const GameObject &other)=delete | |
GameObject (GameObject &&other) noexcept=default | |
GameObject & | operator= (const GameObject &other)=delete |
GameObject & | operator= (GameObject &&other) noexcept=default |
const lib::Uuid & | uuid () const |
Gets the UUID of the GameObject. | |
const std::string & | name () const |
Gets the name of the GameObject. | |
components::Transform * | transform () const |
Gets the transform component of the GameObject. | |
void | addComponent (Component *component, bool managed=false) |
Adds a component to the GameObject. | |
template<typename T , typename... Args> requires std::is_base_of_v<Component, T> | |
void | addComponent (Args &&... args) |
Adds a component of type T to the GameObject. | |
void | removeComponent (Component *component) |
Removes a component from the GameObject. | |
template<typename T > requires std::is_base_of_v<Component, T> | |
void | removeComponent () |
Removes a component of the given type from the GameObject. | |
template<typename T > requires std::is_base_of_v<Component, T> | |
bool | hasComponent () const |
Checks if the GameObject has a component of type T. | |
std::vector< Component * > | components () const |
Gets all the components for this GameObject. | |
template<typename T > requires std::is_base_of_v<Component, T> | |
std::vector< T * > | componentsInChildren () const |
Gets a list of components of type T in any direct child of the GameObject. | |
template<typename T > requires std::is_base_of_v<Component, T> | |
T * | component () const |
Gets a component of type T. | |
template<typename T > requires std::is_base_of_v<Component, T> | |
T * | componentInChildren () const |
Gets a component of type T in any direct child of the GameObject. | |
template<typename T > requires std::is_base_of_v<Component, T> | |
T * | componentInParent () const |
Gets a component of type T in any direct parent of the GameObject. | |
virtual void | onSpawn () |
Method called when the GameObject is spawned in the scene. | |
virtual void | onUpdate (float dt) |
Method called on every frame. | |
virtual void | onDestroyed () |
Method called when the GameObject is destroyed. | |
![]() | |
HasRtti (const HasRtti &other)=default | |
HasRtti (HasRtti &&other) noexcept=default | |
HasRtti & | operator= (const HasRtti &other)=default |
HasRtti & | operator= (HasRtti &&other) noexcept=default |
virtual RttiBase & | rttiInstance () const =0 |
![]() | |
AbstractGameObject (GameObject *parent=nullptr) | |
AbstractGameObject (const AbstractGameObject &other)=delete | |
AbstractGameObject (AbstractGameObject &&other) noexcept=default | |
AbstractGameObject & | operator= (const AbstractGameObject &other)=delete |
AbstractGameObject & | operator= (AbstractGameObject &&other) noexcept=default |
void | onSpawn () |
Method calling the corresponding method on the implementation, the children and components. | |
void | onUpdate (float dt) |
Method calling the corresponding method on the implementation, the children and components. | |
void | onDestroyed () |
Method calling the corresponding method on the implementation, the children and components. | |
![]() | |
Composite (GameObject *parent) | |
Composite (const Composite &other)=delete | |
Composite (Composite &&other) noexcept=default | |
Composite & | operator= (const Composite &other)=delete |
Composite & | operator= (Composite &&other) noexcept=default |
std::vector< GameObject * > | children () const |
GameObject * | parent () |
const GameObject * | parent () const |
GameObject * | root () |
const GameObject * | root () const |
Static Public Member Functions | |
template<typename T = GameObject, typename... Args> requires std::is_base_of_v<GameObject, T> | |
static T * | Instantiate (std::string name, GameObject *parent, Args &&... args) |
Instantiates a new GameObject. | |
static void | Destroy (GameObject *object, bool immediate=false) |
Destroys the current GameObject and all its children from the current scene. | |
static GameObject * | FindById (GameObject *root, const lib::Uuid &uuid) |
Finds a GameObject by its UUID. | |
static GameObject * | FindByName (GameObject *root, const std::string &name) |
Finds a GameObject by its name. | |
Public Attributes | |
bool | isShown = true |
A boolean indicating if the GameObject is shown in the scene. | |
A GameObject is any object in the game. It contains a list of components that provides functionality to the GameObject.
GameObjects can be parented to other GameObjects. When a GameObject is destroyed, all its children are destroyed as well with their components.
|
explicit |
Instantiates a new GameObject.
name | The name of the GameObject. |
parent | The parent of the GameObject. If nullptr, the GameObject is parented to the root GameObject. |
Use GameObject::Instantiate to instantiate a GameObject externally.
void spark::core::GameObject::addComponent | ( | Args &&... | args | ) |
Adds a component of type T to the GameObject.
T | The type of component to add. |
Args | The types of the arguments to pass to the constructor of the component. |
args | The arguments to pass to the constructor of the component. |
void spark::core::GameObject::addComponent | ( | Component * | component, |
bool | managed = false ) |
Adds a component to the GameObject.
component | A pointer to the component to add. |
managed | A boolean indicating if the component is managed by the GameObject. If true, the component will be destroyed when the GameObject is destroyed. |
|
nodiscard |
Gets a component of type T.
T | The type of component to get. |
|
nodiscard |
Gets a component of type T in any direct child of the GameObject.
T | The type of component to get. |
|
nodiscard |
Gets a component of type T in any direct parent of the GameObject.
T | The type of component to get. |
|
nodiscard |
Gets all the components for this GameObject.
|
nodiscard |
Gets a list of components of type T in any direct child of the GameObject.
T | The type of component to get. |
|
static |
Destroys the current GameObject and all its children from the current scene.
object | The object to destroy. |
immediate | true to destroy the object immediately, false to destroy it at the end of the frame. Default is false . |
|
static |
Finds a GameObject by its UUID.
root | The root GameObject to start the search from. |
uuid | The UUID of the GameObject to find. |
|
static |
Finds a GameObject by its name.
root | The root GameObject to start the search from. |
name | The name of the GameObject to find. |
|
nodiscard |
Checks if the GameObject has a component of type T.
T | The type of component to check. |
|
static |
Instantiates a new GameObject.
T | The type of GameObject to instantiate |
name | The name of the GameObject |
parent | The parent GameObject in the scene |
args | The arguments to pass to the constructor of the GameObject |
This method should only be called during the game runtime, not in editor. Use GameObject::GameObject for this.
|
nodiscard |
Gets the name of the GameObject.
|
inlinevirtual |
Method called on every frame.
dt | The time in seconds since the last frame. |
void spark::core::GameObject::removeComponent | ( | ) |
Removes a component of the given type from the GameObject.
T | The type of component to remove. |
void spark::core::GameObject::removeComponent | ( | Component * | component | ) |
Removes a component from the GameObject.
component | A pointer to the component to remove. |
|
nodiscard |
Gets the transform component of the GameObject.
|
nodiscard |
Gets the UUID of the GameObject.