Aspen
2D C++ Class-Based Object Oriented Game Engine
Aspen::Object::Object Class Reference

General base class Allows for parent/child relationship trees. More...

#include <Object.hpp>

Inheritance diagram for Aspen::Object::Object:
Aspen::Audio::Audio Aspen::Audio::Music Aspen::Audio::SoundEffect Aspen::Controller::PlayerController_8Way Aspen::Controller::PlayerController_Sidescroller Aspen::Debug::Debug Aspen::Engine::Engine Aspen::Event::EventHandler Aspen::Event::EventListener Aspen::GameState::GameState Aspen::GameState::GameStateManager Aspen::Graphics::Animation Aspen::Graphics::Camera Aspen::Graphics::FontCache Aspen::Graphics::Geometry Aspen::Graphics::Graphics Aspen::Graphics::Sprite Aspen::Graphics::UI::Button Aspen::Graphics::UI::Text Aspen::Input::Axis Aspen::Physics::Collider Aspen::Physics::Physics Aspen::Physics::Rigidbody Aspen::Time::Time Aspen::Transform::Transform

Public Member Functions

 Object (Object *parent=nullptr, std::string name="Object")
 Constructor Derived classes should call this in their constructors' initialization list. More...
 
virtual ~Object ()
 Destructor This will End and then delete all child Objects.
 
const ObjectParent () const
 Gets the parent of this Object. More...
 
ObjectParent ()
 Gets the parent of this Object. More...
 
const ObjectRoot () const
 Gets the root Object of the parent/child tree this Object is a part of. More...
 
ObjectRoot ()
 Gets the root Object of the parent/child tree this Object is a part of. More...
 
Transform::TransformGetTransform ()
 Gets the first child Transform::Transform. More...
 
const Transform::TransformGetTransform () const
 Gets the first child Transform::Transform. More...
 
Physics::ColliderGetCollider ()
 Gets the first child Physics::Collider. More...
 
const Physics::ColliderGetCollider () const
 Gets the first child Physics::Collider. More...
 
Physics::RigidbodyGetRigidbody ()
 Gets the first child Physics::Rigidbody. More...
 
const Physics::RigidbodyGetRigidbody () const
 Gets the first child Physics::Rigidbody. More...
 
virtual void operator() ()
 Updates this object and all of its children Derived classes should call or reimplement this at some point in their operator() This won't run if the Object isn't Active.
 
void AddChild (Object *child)
 Adds child to this Object's list of children This will also set child's _parent to this This will do nothing if child is already in the list of children Useful for adding an already created Object as a child or passing in the return operator new with parameters. More...
 
template<typename T >
T * CreateChild ()
 Creates a new child of type T Useful for creating an object with no constructor parameters and/or modifying it later. More...
 
template<typename T >
T * CreateChild (std::string name)
 Creates a new child of type T Useful for creating an object with no constructor parameters and/or modifying it later. More...
 
void RemoveChild (Object *child)
 Removes child from this Object's list of children This will also set child's _parent to nullptr This will do nothing if child is not in the Object's list of children. More...
 
void RemoveChild (unsigned index)
 Removes the child at index from this Object's list of children This will also set the child's _parent to nullptr This will do nothing if index is out of range of the Object's list of children. More...
 
Objectoperator[] (unsigned index)
 Gets the child at index from this Object's list of children. More...
 
int operator[] (Object *child)
 Gets the index of a given child in this Object's list of children. More...
 
ObjectGetLastChild ()
 Gets the youngest child from this Object's list of children. More...
 
int ParentCount ()
 Determines the generation of this object in the parent/child tree. More...
 
template<typename T >
T * FindAncestorOfType () const
 Finds the closest ancestor Object of a type applicable to that which was requested. More...
 
template<typename T >
const T * FindChildOfType () const
 Finds the first child Object of a type applicable to that which was requested. More...
 
template<typename T >
T * FindChildOfType ()
 Finds the first child Object of a type applicable to that which was requested. More...
 
template<typename T >
const std::vector< T * > FindChildrenOfType () const
 Finds all children Objects of a type applicable to that which was requested. More...
 
template<typename T >
std::vector< T * > FindChildrenOfType ()
 Finds all children Objects of a type applicable to that which was requested. More...
 
template<typename T >
const std::vector< T * > FindDescendentsOfType () const
 Recursively finds all descendent Objects of a type applicable to that which was requested. More...
 
template<typename T >
std::vector< T * > FindDescendentsOfType ()
 Recursively finds all descendent Objects of a type applicable to that which was requested. More...
 
const bool & Valid () const
 Determines if the Object is valid. More...
 
bool Active () const
 Determines if the Object is active. More...
 
void SetActive (bool active)
 Sets active status of the object Triggers OnActivate or OnDeactivate appropriately. More...
 
void Activate ()
 Activates the object Triggers OnActivate appropriately.
 
void Deactivate ()
 Deactivates the object Triggers OnDeactivate appropriately.
 
 operator bool () const
 Converts Object to bool by calling Valid Example: ``` Object o; while (o) o(); ```.
 
virtual void End ()
 Shuts down and invalidates Object and all of its children An invalid child Object will be deleted by their parent after they update.
 
void PrintTree (Log::Log &log) const
 Uses Log::Log to print the parent/children tree of this Object. More...
 
void PrintTree () const
 Uses Log::Log to print the parent/children tree of this Object Uses Log::Debug.
 
std::string Name () const
 Gets the Object's name. More...
 
unsigned ChildrenCount () const
 Determines the number of immediate children the Object has. More...
 
std::vector< Object * > & Children ()
 Gets the list of Objects that are children of this Object. More...
 
bool HasAncestor (const Object *other) const
 Determines if the provided Object is an ancestor of this Object. More...
 
virtual void PopulateDebugger ()
 Fills out the Debugger if it exists with this Object's information Derived classes should call their base class's version of this method.
 
virtual void OnStart ()
 Run when the Object is created.
 
virtual void OnActivate ()
 Run when the Object is activated Run after OnStart.
 
virtual void OnUpdate ()
 Run every frame.
 
virtual void OnEarlyUpdate ()
 Run before OnUpdate.
 
virtual void OnLateUpdate ()
 Run after OnUpdate.
 
virtual void OnDeactivate ()
 Run when the Object is deactivated Run before OnEnd.
 
virtual void OnEnd ()
 Run when the Object is ended/destroyed.
 
virtual void OnCollision (Physics::Collision c)
 Run when a collision occurs. More...
 
virtual void OnMouseEnter ()
 Run when the mouse enters the Object.
 
virtual void OnMouseOver ()
 Run while the mouse is over the Object.
 
virtual void OnMouseExit ()
 Run when the mouse leaves the Object.
 
virtual void OnMouseClick ()
 Run when the mouse is clicked while over the Object.
 
virtual void OnMouseRelease ()
 Run when the mouse is released while over the Object.
 

Protected Member Functions

void SetParent (Object *parent)
 Sets _parent to the given Object Used by AddChild, CreateChild, etc.
 
void TriggerOnStart ()
 Runs OnStart if the object is currently active for the first time.
 
void TriggerOnActivate ()
 Runs OnActivate if the object is currently active.
 
void TriggerOnDeactivate ()
 Runs OnDeactivate if the object is currently active (being deactivated)
 

Protected Attributes

const std::string _name
 Name of object.
 
Object_parent
 Parent/owner of this Object.
 
std::vector< Object * > _children
 List of children Objects.
 
bool _valid
 Determines if the Object is valid Derived classes can set this to false in their Constructors if they couldn't be created properly.
 
bool _active
 Determines if the Object is currently updated.
 
bool _started
 Determines if the Object has been started Set to true during the first update.
 
Transform::Transform_transform
 First child Transform::Transform.
 
Physics::Collider_collider
 First child Physics::Collider.
 
Physics::Rigidbody_rigidbody
 First child Physics::Rigidbody.
 

Static Protected Attributes

static int _count
 Total number of Objects in existence.
 

Detailed Description

General base class Allows for parent/child relationship trees.

Constructor & Destructor Documentation

◆ Object()

Aspen::Object::Object::Object ( Object parent = nullptr,
std::string  name = "Object" 
)

Constructor Derived classes should call this in their constructors' initialization list.

Parameters
parentParent Object creating this Object
nameObject name Set by derived classes to a string representation of their type

Member Function Documentation

◆ Active()

bool Aspen::Object::Object::Active ( ) const

Determines if the Object is active.

Returns
True if both valid and active False otherwise

◆ AddChild()

void Aspen::Object::Object::AddChild ( Object child)

Adds child to this Object's list of children This will also set child's _parent to this This will do nothing if child is already in the list of children Useful for adding an already created Object as a child or passing in the return operator new with parameters.

Parameters
childObject to add to list of children

◆ Children()

std::vector<Object *>& Aspen::Object::Object::Children ( )

Gets the list of Objects that are children of this Object.

Returns
Children owned by the Object

◆ ChildrenCount()

unsigned Aspen::Object::Object::ChildrenCount ( ) const

Determines the number of immediate children the Object has.

Returns
Number of children owned by the Object

◆ CreateChild() [1/2]

template<typename T >
T* Aspen::Object::Object::CreateChild ( )
inline

Creates a new child of type T Useful for creating an object with no constructor parameters and/or modifying it later.

Template Parameters
TType of child to create Must inherit Object
Returns
Newly created Object

◆ CreateChild() [2/2]

template<typename T >
T* Aspen::Object::Object::CreateChild ( std::string  name)
inline

Creates a new child of type T Useful for creating an object with no constructor parameters and/or modifying it later.

Template Parameters
TType of child to create Must inherit Object
Parameters
nameName of the new object
Returns
Newly created Object

◆ FindAncestorOfType()

template<typename T >
T* Aspen::Object::Object::FindAncestorOfType ( ) const
inline

Finds the closest ancestor Object of a type applicable to that which was requested.

Template Parameters
TType of child to find Must inherit Object
Returns
The closest ancestor of type T If no ancestors match the given type, nullptr is returned If class A : public Object and class B : public A, then FindObjectOfType<A>() will return whichever was added earliest - A* or B* - as an A*

◆ FindChildOfType() [1/2]

template<typename T >
const T* Aspen::Object::Object::FindChildOfType ( ) const
inline

Finds the first child Object of a type applicable to that which was requested.

Template Parameters
TType of child to find Must inherit Object
Returns
The first child of type T If no children match the given type, nullptr is returned If class A : public Object and class B : public A, then FindObjectOfType<A>() will return whichever was added earliest - A* or B* - as an A*

◆ FindChildOfType() [2/2]

template<typename T >
T* Aspen::Object::Object::FindChildOfType ( )
inline

Finds the first child Object of a type applicable to that which was requested.

Template Parameters
TType of child to find Must inherit Object
Returns
The first child of type T If no children match the given type, nullptr is returned If class A : public Object and class B : public A, then FindObjectOfType<A>() will return whichever was added earliest - A* or B* - as an A*

◆ FindChildrenOfType() [1/2]

template<typename T >
const std::vector<T *> Aspen::Object::Object::FindChildrenOfType ( ) const
inline

Finds all children Objects of a type applicable to that which was requested.

Template Parameters
TType of children to find Must inherit Object
Returns
All children of type T If no children match the given type, nullptr is returned If class A : public Object and class B : public A, then FindObjectOfType<A>() will return both A* and B* as A*

◆ FindChildrenOfType() [2/2]

template<typename T >
std::vector<T *> Aspen::Object::Object::FindChildrenOfType ( )
inline

Finds all children Objects of a type applicable to that which was requested.

Template Parameters
TType of children to find Must inherit Object
Returns
All children of type T If no children match the given type, nullptr is returned If class A : public Object and class B : public A, then FindObjectOfType<A>() will return both A* and B* as A*

◆ FindDescendentsOfType() [1/2]

template<typename T >
const std::vector<T *> Aspen::Object::Object::FindDescendentsOfType ( ) const
inline

Recursively finds all descendent Objects of a type applicable to that which was requested.

Template Parameters
TType of descendent to find Must inherit Object
Returns
All children of type T If no descendents match the given type, an empty vector is returned If class A : public Object and class B : public A, then FindObjectOfType<A>() will return both A* and B* as A*

◆ FindDescendentsOfType() [2/2]

template<typename T >
std::vector<T *> Aspen::Object::Object::FindDescendentsOfType ( )
inline

Recursively finds all descendent Objects of a type applicable to that which was requested.

Template Parameters
TType of descendent to find Must inherit Object
Returns
All children of type T If no descendents match the given type, an empty vector is returned If class A : public Object and class B : public A, then FindObjectOfType<A>() will return both A* and B* as A*

◆ GetCollider() [1/2]

Physics::Collider* Aspen::Object::Object::GetCollider ( )

Gets the first child Physics::Collider.

Returns
Child Collider

◆ GetCollider() [2/2]

const Physics::Collider* Aspen::Object::Object::GetCollider ( ) const

Gets the first child Physics::Collider.

Returns
Child Collider

◆ GetLastChild()

Object* Aspen::Object::Object::GetLastChild ( )

Gets the youngest child from this Object's list of children.

Returns
Last child of Object This will return nullptr if the Object has no children

◆ GetRigidbody() [1/2]

Physics::Rigidbody* Aspen::Object::Object::GetRigidbody ( )

Gets the first child Physics::Rigidbody.

Returns
Child Rigidbody

◆ GetRigidbody() [2/2]

const Physics::Rigidbody* Aspen::Object::Object::GetRigidbody ( ) const

Gets the first child Physics::Rigidbody.

Returns
Child Rigidbody

◆ GetTransform() [1/2]

Transform::Transform* Aspen::Object::Object::GetTransform ( )

Gets the first child Transform::Transform.

Returns
Child Transform

◆ GetTransform() [2/2]

const Transform::Transform* Aspen::Object::Object::GetTransform ( ) const

Gets the first child Transform::Transform.

Returns
Child Transform

◆ HasAncestor()

bool Aspen::Object::Object::HasAncestor ( const Object other) const

Determines if the provided Object is an ancestor of this Object.

Parameters
otherPotential ancestor of this Object
Returns
True if other is an ancestor of this Object False otherwise

◆ Name()

std::string Aspen::Object::Object::Name ( ) const

Gets the Object's name.

Returns
Object name

◆ OnCollision()

virtual void Aspen::Object::Object::OnCollision ( Physics::Collision  c)
virtual

Run when a collision occurs.

Parameters
cCollision that occured

◆ operator[]() [1/2]

Object* Aspen::Object::Object::operator[] ( unsigned  index)

Gets the child at index from this Object's list of children.

Parameters
indexIndex of child Object to get
Returns
Child object at index from this Object's list of children This will return nullptr if index is out of range of the Object's list of children

◆ operator[]() [2/2]

int Aspen::Object::Object::operator[] ( Object child)

Gets the index of a given child in this Object's list of children.

Parameters
childChild Object to get the index of
Returns
Index of child This will return -1 if child is not in the Object's list of children

◆ Parent() [1/2]

const Object* Aspen::Object::Object::Parent ( ) const

Gets the parent of this Object.

Returns
_parent

◆ Parent() [2/2]

Object* Aspen::Object::Object::Parent ( )

Gets the parent of this Object.

Returns
_parent

◆ ParentCount()

int Aspen::Object::Object::ParentCount ( )

Determines the generation of this object in the parent/child tree.

Returns
Generation index of this Object (0 = root)

◆ PrintTree()

void Aspen::Object::Object::PrintTree ( Log::Log log) const

Uses Log::Log to print the parent/children tree of this Object.

Parameters
logLog::Log to use

◆ RemoveChild() [1/2]

void Aspen::Object::Object::RemoveChild ( Object child)

Removes child from this Object's list of children This will also set child's _parent to nullptr This will do nothing if child is not in the Object's list of children.

Parameters
childObject to remove from list of children

◆ RemoveChild() [2/2]

void Aspen::Object::Object::RemoveChild ( unsigned  index)

Removes the child at index from this Object's list of children This will also set the child's _parent to nullptr This will do nothing if index is out of range of the Object's list of children.

Parameters
indexIndex of Object to remove from list of children

◆ Root() [1/2]

const Object* Aspen::Object::Object::Root ( ) const

Gets the root Object of the parent/child tree this Object is a part of.

Returns
Root Object of this Object's tree

◆ Root() [2/2]

Object* Aspen::Object::Object::Root ( )

Gets the root Object of the parent/child tree this Object is a part of.

Returns
Root Object of this Object's tree

◆ SetActive()

void Aspen::Object::Object::SetActive ( bool  active)

Sets active status of the object Triggers OnActivate or OnDeactivate appropriately.

Parameters
activeNew active status

◆ Valid()

const bool& Aspen::Object::Object::Valid ( ) const

Determines if the Object is valid.

Returns
Const reference to _valid

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