|
Capycore Engine
0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
|
Concept to constrain types to be derived from Component. More...
#include <gameObject.h>
Public Member Functions | |
| GameObject (Scene &scene) | |
| virtual | ~GameObject ()=default |
| GameObject (const GameObject &)=delete | |
| GameObject & | operator= (const GameObject &)=delete |
| GameObject (GameObject &&)=default | |
| GameObject & | operator= (GameObject &&)=default |
| std::optional< std::reference_wrapper< GameObject > > | parent () const |
| GameObject & | parent (GameObject &parent) |
| GameObject & | parent (std::nullopt_t null_opt) |
| std::string | id () const noexcept |
| bool | is_active_in_world () const noexcept |
| Retrieves whether the GameObject is active in the world. | |
| bool | is_active () const noexcept |
| Retrieves whether the GameObject is active. | |
| void | set_inactive () noexcept |
| void | set_active () noexcept |
| void | set_active_in_world () noexcept |
| void | set_inactive_in_world () noexcept |
| GameObject & | mark_for_deletion () noexcept |
| Marks the GameObject for deletion. | |
| bool | marked_for_deletion () const noexcept |
| void | mark_dont_destroy_on_load (bool dont_destroy) noexcept |
| Sets whether the GameObject should not be destroyed on scene load. | |
| bool | dont_destroy_on_load () const noexcept |
| GameObject & | name (const std::string &name) |
| const std::string & | name () const |
| GameObject & | tag (const std::string &tag) |
| const std::string & | tag () const |
| GameObject & | prefab_type_id (const std::string &id) |
| const std::string & | prefab_type_id () const |
| GameObject & | layer (int layer) |
| int | layer () const |
| GameObject & | transform (Transform transform) |
| Transform & | transform () |
| const Transform & | transform () const |
| Scene & | scene () const noexcept |
| void | scene (Scene &scene) noexcept |
| std::vector< std::reference_wrapper< GameObject > > & | children () |
| GameObject & | add_child (GameObject &child) |
| GameObject & | remove_child (GameObject &child) |
| template<IsComponent T> | |
| std::optional< std::reference_wrapper< T > > | get_component () const noexcept |
| Get the first component of type T attached to this GameObject. | |
| template<IsComponent T> | |
| std::vector< std::reference_wrapper< T > > | get_components () const |
| Get all components of type T attached to this GameObject. | |
| template<IsComponent BS, typename B > | |
| std::optional< std::reference_wrapper< B > > | get_script () const noexcept |
| Get the first script component of base type BS with behavior of type B. | |
| std::vector< std::reference_wrapper< Component > > | get_components_all () const |
| Get all components attached to this GameObject. | |
| template<IsComponent T> | |
| std::vector< std::reference_wrapper< T > > | get_components_from_children () const |
| Get all components of type T attached to this GameObject and its children. | |
| template<IsComponent T, typename... Args> | |
| T & | add_component (Args &&... args) |
| Adds a component of type T to this GameObject. | |
| template<IsComponent T> | |
| void | remove_component (T &component) |
| Removes a component of type T from this GameObject. | |
| void | remove_all_components () |
| void | serialize (std::vector< uint8_t > &out) const |
Serialize this GameObject's own state and its components into out. The format produced is: uint16_t name_len, name bytes uint16_t tag_len, tag bytes uint8_t is_active int32_t layer uint16_t component_count for each component: uint16_t type_name_len, type_name bytes uint32_t payload_len, payload bytes. | |
| void | deserialize (const std::vector< uint8_t > &data, size_t &offset) |
Deserialize this GameObject's state and dispatch component payloads from data starting at offset. Implementations should advance offset by the number of bytes consumed. Subclasses overriding this method should call GameObject::deserialize first to keep base behavior. | |
Concept to constrain types to be derived from Component.
| T | The type to check. GameObjects can have multiple components attached to them to define their behavior and properties. |
Each GameObject has a unique identifier, a name, a tag, a layer, and a transform representing its position, rotation, and scale in the scene. GameObjects can also have parent-child relationships to form a hierarchy.
GameObjects can be marked as active or inactive, which affects whether they and their components are updated and rendered.
GameObjects can be marked for deletion, which will remove them from the scene at the end of the current update cycle.
GameObjects can be marked as "don't destroy on load", which prevents them from being destroyed when loading a new scene.
|
explicit |
|
virtualdefault |
|
delete |
|
default |
| GameObject & GameObject::add_child | ( | GameObject & | child | ) |
|
inline |
Adds a component of type T to this GameObject.
| T | The type of the component to add. Must be derived from Component |
| args | The arguments to forward to the component's constructor. |
| std::vector< std::reference_wrapper< GameObject > > & GameObject::children | ( | ) |
Deserialize this GameObject's state and dispatch component payloads from data starting at offset. Implementations should advance offset by the number of bytes consumed. Subclasses overriding this method should call GameObject::deserialize first to keep base behavior.
|
noexcept |
|
inlinenoexcept |
Get the first component of type T attached to this GameObject.
| T | The type of the component to get. Must be derived from Component |
|
inline |
Get all components of type T attached to this GameObject.
| T | The type of the component to get. Must be derived from Component |
| std::vector< std::reference_wrapper< Component > > GameObject::get_components_all | ( | ) | const |
Get all components attached to this GameObject.
|
inline |
Get all components of type T attached to this GameObject and its children.
| T | The type of the component to get. Must be derived from Component |
|
inlinenoexcept |
Get the first script component of base type BS with behavior of type B.
| BS | The base type of the script component. Must be derived from Component |
| B | The type of the behavior. |
|
noexcept |
|
noexcept |
Retrieves whether the GameObject is active.
|
noexcept |
Retrieves whether the GameObject is active in the world.
| int GameObject::layer | ( | ) | const |
| GameObject & GameObject::layer | ( | int | layer | ) |
Sets whether the GameObject should not be destroyed on scene load.
| dont_destroy | true to prevent destruction on scene load, false to |
|
noexcept |
Marks the GameObject for deletion.
|
noexcept |
| const std::string & GameObject::name | ( | ) | const |
| GameObject & GameObject::name | ( | const std::string & | name | ) |
|
delete |
|
default |
| std::optional< std::reference_wrapper< GameObject > > GameObject::parent | ( | ) | const |
| GameObject & GameObject::parent | ( | GameObject & | parent | ) |
| GameObject & GameObject::parent | ( | std::nullopt_t | null_opt | ) |
| const std::string & GameObject::prefab_type_id | ( | ) | const |
| GameObject & GameObject::prefab_type_id | ( | const std::string & | id | ) |
| void GameObject::remove_all_components | ( | ) |
| GameObject & GameObject::remove_child | ( | GameObject & | child | ) |
|
inline |
Removes a component of type T from this GameObject.
| T | The type of the component to remove. Must be derived from Component |
| component | The component to remove. @CAUTION: This will call the component's on_detach method before removing it. |
|
noexcept |
Serialize this GameObject's own state and its components into out. The format produced is: uint16_t name_len, name bytes uint16_t tag_len, tag bytes uint8_t is_active int32_t layer uint16_t component_count for each component: uint16_t type_name_len, type_name bytes uint32_t payload_len, payload bytes.
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
| const std::string & GameObject::tag | ( | ) | const |
| GameObject & GameObject::tag | ( | const std::string & | tag | ) |
| Transform & GameObject::transform | ( | ) |
| GameObject & GameObject::transform | ( | Transform | transform | ) |