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

GameStateManager class. More...

#include <GameState.hpp>

Inheritance diagram for Aspen::GameState::GameStateManager:
Aspen::Object::Object

Public Member Functions

 GameStateManager (Object *parent=nullptr, std::string name="GameStateManager")
 Constructor Derived classes should call this in their constructors' initialization list. More...
 
template<typename T >
GameStateLoadState (bool active=false)
 Loads the given GameState derived class as a new state. More...
 
GameStateGetState (unsigned i)
 Gets the state at the given index. More...
 
GameStateGetState (std::string name)
 Gets the state with the given state name. More...
 
void UnloadAllStates ()
 Unloads all child states.
 
void UnloadState (unsigned i)
 Unloads the state with the given index. More...
 
void UnloadState (GameState *state)
 Unloads the given state. More...
 
void UnloadState (std::string name)
 Unloads the state with the given state name. More...
 
bool SetCurrentState (unsigned i)
 Sets the current state to the one at the given index Deactivates all other states. More...
 
bool SetCurrentState (GameState *state)
 Sets the current state to the one provided Deactivates all other states. More...
 
bool SetCurrentState (std::string name)
 Sets the current state to the one with the given state name Deactivates all other states. More...
 
bool ActivateState (unsigned i)
 Activates the current state to the one at the given index. More...
 
bool ActivateState (GameState *state)
 Activates the current state to the one provided. More...
 
bool ActivateState (std::string name)
 Activates the current state to the one with the given state name. More...
 
bool DeactivateState (unsigned i)
 Deactivates the current state to the one at the given index. More...
 
bool DeactivateState (GameState *state)
 Deactivates the current state to the one provided. More...
 
bool DeactivateState (std::string name)
 Deactivates the current state to the one with the given state name. More...
 
- Public Member Functions inherited from Aspen::Object::Object
 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.
 

Additional Inherited Members

- Protected Member Functions inherited from Aspen::Object::Object
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 inherited from Aspen::Object::Object
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 inherited from Aspen::Object::Object
static int _count
 Total number of Objects in existence.
 

Detailed Description

Constructor & Destructor Documentation

◆ GameStateManager()

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

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

Parameters
parentParent Object to be passed to Object constructor
nameObject name Set by derived classes to a string representation of their type

Member Function Documentation

◆ ActivateState() [1/3]

bool Aspen::GameState::GameStateManager::ActivateState ( unsigned  i)

Activates the current state to the one at the given index.

Parameters
iIndex to activate

◆ ActivateState() [2/3]

bool Aspen::GameState::GameStateManager::ActivateState ( GameState state)

Activates the current state to the one provided.

Parameters
stateState to activate

◆ ActivateState() [3/3]

bool Aspen::GameState::GameStateManager::ActivateState ( std::string  name)

Activates the current state to the one with the given state name.

Parameters
nameState name to activate

◆ DeactivateState() [1/3]

bool Aspen::GameState::GameStateManager::DeactivateState ( unsigned  i)

Deactivates the current state to the one at the given index.

Parameters
iIndex to deactivate

◆ DeactivateState() [2/3]

bool Aspen::GameState::GameStateManager::DeactivateState ( GameState state)

Deactivates the current state to the one provided.

Parameters
stateState to deactivate

◆ DeactivateState() [3/3]

bool Aspen::GameState::GameStateManager::DeactivateState ( std::string  name)

Deactivates the current state to the one with the given state name.

Parameters
nameState name to deactivate

◆ GetState() [1/2]

GameState* Aspen::GameState::GameStateManager::GetState ( unsigned  i)

Gets the state at the given index.

Parameters
iIndex to get
Returns
GameState child at the given index

◆ GetState() [2/2]

GameState* Aspen::GameState::GameStateManager::GetState ( std::string  name)

Gets the state with the given state name.

Parameters
nameState name to get
Returns
GameState child with the given state name

◆ LoadState()

template<typename T >
GameState* Aspen::GameState::GameStateManager::LoadState ( bool  active = false)
inline

Loads the given GameState derived class as a new state.

Template Parameters
Tderived GameState
Parameters
activeDetermines if the state is loaded active
Returns
Loaded state nullptr if no state was loaded

◆ SetCurrentState() [1/3]

bool Aspen::GameState::GameStateManager::SetCurrentState ( unsigned  i)

Sets the current state to the one at the given index Deactivates all other states.

Parameters
iIndex to select

◆ SetCurrentState() [2/3]

bool Aspen::GameState::GameStateManager::SetCurrentState ( GameState state)

Sets the current state to the one provided Deactivates all other states.

Parameters
stateState to select

◆ SetCurrentState() [3/3]

bool Aspen::GameState::GameStateManager::SetCurrentState ( std::string  name)

Sets the current state to the one with the given state name Deactivates all other states.

Parameters
nameState name to select

◆ UnloadState() [1/3]

void Aspen::GameState::GameStateManager::UnloadState ( unsigned  i)

Unloads the state with the given index.

Parameters
iIndex to unload

◆ UnloadState() [2/3]

void Aspen::GameState::GameStateManager::UnloadState ( GameState state)

Unloads the given state.

Parameters
stateState to unload

◆ UnloadState() [3/3]

void Aspen::GameState::GameStateManager::UnloadState ( std::string  name)

Unloads the state with the given state name.

Parameters
nameState name to unload

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