StevEngine
StevEngine is a customizable C++ game engine.
Loading...
Searching...
No Matches
StevEngine::GameObject Class Referencefinal

Core game object class. More...

#include <main/GameObject.hpp>

Public Member Functions

Utilities::ID Id () const
 Get object's unique ID.
 
Utilities::Vector3 GetPosition () const
 Get local position.
 
Utilities::Quaternion GetRotation () const
 Get local rotation.
 
Utilities::Vector3 GetScale () const
 Get local scale.
 
void SetPosition (Utilities::Vector3 position, bool announce=true)
 Set local position.
 
void SetRotation (Utilities::Quaternion rotation, bool announce=true)
 Set local rotation.
 
void SetScale (Utilities::Vector3 scale, bool announce=true)
 Set local scale.
 
void SetTransform (Utilities::Vector3 position, Utilities::Quaternion rotation, Utilities::Vector3 scale, bool announce=true)
 Set full local transform.
 
Utilities::Vector3 GetWorldPosition () const
 Get world position.
 
Utilities::Quaternion GetWorldRotation () const
 Get world rotation.
 
Utilities::Vector3 GetWorldScale () const
 Get world scale.
 
 ~GameObject ()
 
Utilities::Stream Export (Utilities::StreamType type) const
 Serialize object to a stream.
 
void Import (Utilities::Stream &stream)
 Load object from serialized data.
 
 GameObject (Utilities::ID id, std::string name, std::string scene)
 Should never be called directly, use Scene::CreateObject.
 
template<typename EventType>
Utilities::ID Subscribe (EventFunction< EventType > handler, bool allowFromChild=true)
 Subscribe to object events.
 
template<typename EventType>
void Publish (const EventType &event)
 Publish an event.
 
void Unsubscribe (const std::string eventId, const Utilities::ID handlerId)
 Unsubscribe from events.
 
int AddChild (const Utilities::ID &gameObjectID)
 Add child object.
 
void RemoveChild (int index)
 Remove child at index.
 
GameObjectGetChild (int index) const
 Get child object.
 
uint32_t GetChildCount () const
 Get number of children.
 
bool HasParent () const
 Check if object has a parent.
 
GameObjectGetParent () const
 Get parent object.
 
SceneGetScene () const
 Get containing Scene.
 
template<class T>
requires std::is_base_of_v<Component, T>
T * GetComponent (bool log=true)
 Get component of specified type.
 
template<class T>
std::enable_if< std::is_base_of< Component, T >::value, std::vector< T * > >::type GetAllComponents ()
 Get all components of specified type.
 
std::vector< Component * > GetAllComponents () const
 Get all components of any type.
 
template<class T>
requires std::is_base_of_v<Component,T>
std::vector< T * > GetAllComponentsInChildren ()
 Get components of type from this object and all children.
 
template<class T>
requires std::is_base_of_v<Component,T>
T * AddComponent (T *component)
 Add component to object.
 
template<class T>
requires std::is_base_of_v<Component,T>
void RemoveAllComponents ()
 Remove all components of specified type.
 
template<class T>
requires std::is_base_of_v<Component,T>
void RemoveComponent (T *component)
 Remove specific component instance.
 

Public Attributes

std::string name
 Object name/label.
 

Friends

class SceneManager
 
class Scene
 

Detailed Description

Core game object class.

Base class for all entities in the game world. Handles transform hierarchy, component management, and event propagation.

Constructor & Destructor Documentation

◆ ~GameObject()

StevEngine::GameObject::~GameObject ( )

Log::Normal(std::format("Destroying object with id {}", id), true);

◆ GameObject()

StevEngine::GameObject::GameObject ( Utilities::ID id,
std::string name,
std::string scene )

Should never be called directly, use Scene::CreateObject.

Constructs a GameObject with the specified properties.

Member Function Documentation

◆ AddChild()

int StevEngine::GameObject::AddChild ( const Utilities::ID & gameObjectID)

Add child object.

Parameters
gameObjectIDID of child object
Returns
Index of new child

◆ AddComponent()

template<class T>
requires std::is_base_of_v<Component,T>
T * StevEngine::GameObject::AddComponent ( T * component)
inline

Add component to object.

Template Parameters
TComponent type to add
Parameters
componentComponent instance to add
Returns
Pointer to added component or nullptr if failed

◆ Export()

Utilities::Stream StevEngine::GameObject::Export ( Utilities::StreamType type) const

Serialize object to a stream.

Parameters
typeType of stream to export to
Returns
Stream containing serialized object data

◆ GetAllComponents() [1/2]

template<class T>
std::enable_if< std::is_base_of< Component, T >::value, std::vector< T * > >::type StevEngine::GameObject::GetAllComponents ( )
inline

Get all components of specified type.

Template Parameters
TComponent type to get
Returns
Vector of matching components

◆ GetAllComponents() [2/2]

std::vector< Component * > StevEngine::GameObject::GetAllComponents ( ) const
inline

Get all components of any type.

Returns
Vector of all components

◆ GetAllComponentsInChildren()

template<class T>
requires std::is_base_of_v<Component,T>
std::vector< T * > StevEngine::GameObject::GetAllComponentsInChildren ( )
inline

Get components of type from this object and all children.

Template Parameters
TComponent type to get
Returns
Vector of matching components

◆ GetChild()

GameObject & StevEngine::GameObject::GetChild ( int index) const

Get child object.

Parameters
indexChild index
Returns
Pointer to child object

◆ GetChildCount()

uint32_t StevEngine::GameObject::GetChildCount ( ) const

Get number of children.

Returns
Child count

◆ GetComponent()

template<class T>
requires std::is_base_of_v<Component, T>
T * StevEngine::GameObject::GetComponent ( bool log = true)
inline

Get component of specified type.

Template Parameters
TComponent type to get
Parameters
logWhether to log if component not found
Returns
Pointer to component or nullptr if not found

◆ GetParent()

GameObject & StevEngine::GameObject::GetParent ( ) const

Get parent object.

Returns
Pointer to parent object

◆ GetPosition()

Utilities::Vector3 StevEngine::GameObject::GetPosition ( ) const

Get local position.

Returns
Local position vector

◆ GetRotation()

Utilities::Quaternion StevEngine::GameObject::GetRotation ( ) const

Get local rotation.

Returns
Local rotation quaternion

◆ GetScale()

Utilities::Vector3 StevEngine::GameObject::GetScale ( ) const

Get local scale.

Returns
Local scale vector

◆ GetScene()

Scene & StevEngine::GameObject::GetScene ( ) const

Get containing Scene.

Returns
Pointer to containing Scene

◆ GetWorldPosition()

Utilities::Vector3 StevEngine::GameObject::GetWorldPosition ( ) const

Get world position.

Returns
World space position

◆ GetWorldRotation()

Utilities::Quaternion StevEngine::GameObject::GetWorldRotation ( ) const

Get world rotation.

Returns
World space rotation

◆ GetWorldScale()

Utilities::Vector3 StevEngine::GameObject::GetWorldScale ( ) const

Get world scale.

Returns
World space scale

◆ HasParent()

bool StevEngine::GameObject::HasParent ( ) const
inline

Check if object has a parent.

Returns
true if object has a parent, otherwise false

◆ Id()

Utilities::ID StevEngine::GameObject::Id ( ) const
inline

Get object's unique ID.

Returns
Unique identifier

◆ Import()

void StevEngine::GameObject::Import ( Utilities::Stream & stream)

Load object from serialized data.

Parameters
streamStream containing serialized object data

◆ Publish()

template<typename EventType>
void StevEngine::GameObject::Publish ( const EventType & event)
inline

Publish an event.

Template Parameters
EventTypeType of event to publish
Parameters
eventEvent to publish

◆ RemoveAllComponents()

template<class T>
requires std::is_base_of_v<Component,T>
void StevEngine::GameObject::RemoveAllComponents ( )
inline

Remove all components of specified type.

Template Parameters
TComponent type to remove

delete *i;

◆ RemoveChild()

void StevEngine::GameObject::RemoveChild ( int index)

Remove child at index.

Parameters
indexIndex of child to remove

◆ RemoveComponent()

template<class T>
requires std::is_base_of_v<Component,T>
void StevEngine::GameObject::RemoveComponent ( T * component)
inline

Remove specific component instance.

Template Parameters
TComponent type to remove
Parameters
componentPointer to component to remove

◆ SetPosition()

void StevEngine::GameObject::SetPosition ( Utilities::Vector3 position,
bool announce = true )

Set local position.

Parameters
positionNew position
announceWhether to trigger transform event

◆ SetRotation()

void StevEngine::GameObject::SetRotation ( Utilities::Quaternion rotation,
bool announce = true )

Set local rotation.

Parameters
rotationNew rotation
announceWhether to trigger transform event

◆ SetScale()

void StevEngine::GameObject::SetScale ( Utilities::Vector3 scale,
bool announce = true )

Set local scale.

Parameters
scaleNew scale
announceWhether to trigger transform event

◆ SetTransform()

void StevEngine::GameObject::SetTransform ( Utilities::Vector3 position,
Utilities::Quaternion rotation,
Utilities::Vector3 scale,
bool announce = true )

Set full local transform.

Parameters
positionNew position
rotationNew rotation
scaleNew scale
announceWhether to trigger transform event

◆ Subscribe()

template<typename EventType>
Utilities::ID StevEngine::GameObject::Subscribe ( EventFunction< EventType > handler,
bool allowFromChild = true )
inline

Subscribe to object events.

Template Parameters
EventTypeType of event to subscribe to
Parameters
handlerFunction to handle event
allowFromChildWhether to receive events from children
Returns
Subscription ID

◆ Unsubscribe()

void StevEngine::GameObject::Unsubscribe ( const std::string eventId,
const Utilities::ID handlerId )
inline

Unsubscribe from events.

Parameters
eventIdEvent type identifier
handlerIdHandler ID to unsubscribe

The documentation for this class was generated from the following files: