cangine
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | Friends | List of all members
cangine::GameObject Class Reference

Base class for everything that lives in the scene. More...

#include <game_object.hpp>

Inheritance diagram for cangine::GameObject:
Inheritance graph
[legend]

Public Member Functions

 GameObject ()
 
virtual ~GameObject ()
 
virtual void onUpdate (double deltaTime)
 Per-frame update hook.
 
virtual void onMouseEvent (const MouseEvent *e)
 Mouse event hook.
 
virtual void onDisable ()
 Called when the object becomes inactive.
 
virtual void onEnable ()
 Called when the object becomes active.
 
void destroy ()
 Marks the object for destruction by the ObjectManager.
 
template<typename T >
void appendComponent (T *component)
 Attaches an existing component to this object.
 
template<typename T >
void destroyComponent ()
 Destroys and removes the first component of a type.
 
template<typename T >
T * getComponent ()
 Returns the first attached component of a type.
 
template<typename T >
std::vector< T * > getComponents ()
 Returns all attached components of a type.
 
template<typename T , typename... Args>
T * newComponent (Args &&... args)
 Constructs a component in place and attaches it.
 
void setActive (bool a)
 Activates or deactivates the object.
 
bool isActive ()
 Reports whether the object is active.
 

Private Attributes

std::vector< IComponent * > components
 Components attached to this object.
 
bool pendingDestroy = false
 Whether the object is queued for destruction.
 
bool active = true
 Whether the object is active (updated/drawn).
 

Friends

class ObjectManager
 

Detailed Description

Base class for everything that lives in the scene.

A game object is a container of IComponent instances. It exposes a type-safe component API (appendComponent, getComponent, newComponent, ...) and lifecycle hooks (onUpdate, onMouseEvent, onEnable, onDisable) that subclasses may override. Managed by the ObjectManager.

Constructor & Destructor Documentation

◆ GameObject()

cangine::GameObject::GameObject ( )

◆ ~GameObject()

cangine::GameObject::~GameObject ( )
virtual

Member Function Documentation

◆ appendComponent()

template<typename T >
void cangine::GameObject::appendComponent ( T *  component)
inline

Attaches an existing component to this object.

Calls the component's IComponent::firstFrame once attached. Asserts if a unique component of the same type already exists.

Template Parameters
TComponent type.
Parameters
componentComponent instance to attach (ownership taken).

◆ destroy()

void cangine::GameObject::destroy ( )
inline

Marks the object for destruction by the ObjectManager.

◆ destroyComponent()

template<typename T >
void cangine::GameObject::destroyComponent ( )
inline

Destroys and removes the first component of a type.

Template Parameters
TComponent type to remove.

◆ getComponent()

template<typename T >
T * cangine::GameObject::getComponent ( )
inline

Returns the first attached component of a type.

Template Parameters
TComponent type to find.
Returns
Pointer to the component, or nullptr if none.

◆ getComponents()

template<typename T >
std::vector< T * > cangine::GameObject::getComponents ( )
inline

Returns all attached components of a type.

Template Parameters
TComponent type to find.
Returns
Vector of matching components (possibly empty).

◆ isActive()

bool cangine::GameObject::isActive ( )

Reports whether the object is active.

Returns
true if active.

◆ newComponent()

template<typename T , typename... Args>
T * cangine::GameObject::newComponent ( Args &&...  args)
inline

Constructs a component in place and attaches it.

Template Parameters
TComponent type to create.
ArgsConstructor argument types.
Parameters
argsArguments forwarded to the component's constructor.
Returns
Pointer to the newly created component.

◆ onDisable()

virtual void cangine::GameObject::onDisable ( )
inlinevirtual

Called when the object becomes inactive.

Reimplemented in cangine::Panel.

◆ onEnable()

virtual void cangine::GameObject::onEnable ( )
inlinevirtual

Called when the object becomes active.

Reimplemented in cangine::Panel.

◆ onMouseEvent()

void cangine::GameObject::onMouseEvent ( const MouseEvent *  e)
virtual

Mouse event hook.

Parameters
eThe mouse event delivered to this object.

◆ onUpdate()

void cangine::GameObject::onUpdate ( double  deltaTime)
virtual

Per-frame update hook.

Parameters
deltaTimeSeconds elapsed since the previous frame.

◆ setActive()

void cangine::GameObject::setActive ( bool  a)

Activates or deactivates the object.

Parameters
atrue to enable, false to disable.

Friends And Related Symbol Documentation

◆ ObjectManager

Member Data Documentation

◆ active

bool cangine::GameObject::active = true
private

Whether the object is active (updated/drawn).

◆ components

std::vector<IComponent*> cangine::GameObject::components
private

Components attached to this object.

◆ pendingDestroy

bool cangine::GameObject::pendingDestroy = false
private

Whether the object is queued for destruction.


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