Brunot
Loading...
Searching...
No Matches
ChildrenHandeler< C > Class Template Reference

A container for child objects. More...

#include <ChildrenHandeler.h>

Inheritance diagram for ChildrenHandeler< C >:
[legend]
Collaboration diagram for ChildrenHandeler< C >:
[legend]

Public Member Functions

 ChildrenHandeler ()
 default constructor for ChildrenHandeler
 ChildrenHandeler (const ChildrenHandeler &other)
 deep copy of ChildrenHandeler
auto operator= (const ChildrenHandeler &other) -> ChildrenHandeler &
 Copy assignment operator.
 ChildrenHandeler (ChildrenHandeler &&other) noexcept
 Move Constructor.
auto operator= (ChildrenHandeler &&other) noexcept -> ChildrenHandeler &
 move assignment operator
 ~ChildrenHandeler () override=default
 default dtor.
auto showMenu () -> void override
 Called before update each frame, for calling ImGui editor code relevant to the gameObject.
auto update (float dt) -> void override
 called once every frame.
auto endWindow () -> void override
 currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
auto render () -> void override
 called every frame after update has been called for every object.
auto onRender () -> void override
 called every frame after update has been called for every object.
auto onEnterEngine () -> void override
 hook that is called when a GameObject enters the Engine tree.
auto load (Stream &stream) -> void override
 Implementations will load the state of a GameObject from a th::Json Object.
auto save (Stream &stream) const -> void override
 Implementations will load the state of a GameObject to a th::Json object.
auto clone () const -> std::unique_ptr< GameObject > override
 makes a copy a GameObject even if it's held polymorphically
auto setShouldUpdate (const bool _shouldUpdate) -> void override
 set whether the GameObject should update every frame, and whether all of it's children should update every frame
auto setShouldRender (const bool _shouldRender) -> void override
 set whether the GameObject should render every frame, and whether all of it's children should render every frame
auto setShouldReceiveMessages (const bool _shouldReceiveMessages) -> void override
 set whether the GameObject should Receive Messags, and whether all of it's children should receive messages
auto add (std::unique_ptr< C > newChild) -> void
auto for_each (std::function< void(C &)> func) -> void
 applies a function to every child.
auto for_each (std::function< void(const C &)> func) const -> void
 applies a function to every child.
auto for_each (std::function< void(GameObject &)> func) -> void
 applies a function to every child.
auto for_each (std::function< void(const GameObject &)> func) const -> void override
 applies a function to every child.
auto find (std::function< bool(C &)> predicate) -> C *
 Returns pointer to child object.
auto count () -> size_t
auto getChildren () const -> std::shared_ptr< std::vector< GameObject * > > override
 gets a vector of a GameObjects public (i.e.
auto getChildrenRange () const -> std::shared_ptr< std::vector< GameObject * > >
 A function designed for Paths to use, for getting a list of all children, in a manageable format.
auto pop (Key key) -> std::unique_ptr< C >
 Removes a Child from the list, transferring ownership to the Caller.
auto setParents (GameObject &parent) -> void
 Set's all managed objects parent to one passed in.
Public Member Functions inherited from GameObject
 GameObject (std::string typeName, gobj::Type parentType, gobj::Type type)
 constructor for gameobject.
virtual ~GameObject ()
 destructor for GameObject.
 GameObject (const GameObject &other)
 Copy Constructor.
auto operator= (const GameObject &other) -> GameObject &
 copy assignment operator
 GameObject (GameObject &&other) noexcept
 Move constructor.
auto operator= (GameObject &&other) noexcept -> GameObject &
 Move assignment operator.
virtual auto destroy () -> void
 Marks an GameObject to be destroyed.
virtual auto getParent () const -> GameObject *
 Gets the parent of a GameObject.
virtual auto parentTo (GameObject *newParent) -> bool
 Sets the GameObject as a child of another GameObject.
auto getInternalParent () const -> GameObject *
 returns the actual owning parent of the GameObject
virtual auto addChild (std::unique_ptr< GameObject > newChild) -> bool
 Adds a child to a GameObject.
virtual auto getKey () const -> Key
 Generates a unique Key that corresponds to the GameObject.
auto destroyed () const -> bool
auto getUUID () const -> gobj::UUID
auto isUUID (gobj::UUID compareUUID) const -> bool
auto getName () const -> const std::string &
 Gets the type of the object as a string.
auto getNickname () const -> const std::string &
 Gets the nickname (custom, writable name) of a GameObject.
void calculateFormattedName () const
auto getFormattedName () const -> const std::string &
 combines a GameObjects Type, Nickname, and UUID into one string, for use with logging.
auto nameEquals (const std::string &compareString) const -> bool
 check whether a GameObjects typeName is equivilent to a given string.
auto isType (gobj::Type otherType) const -> bool
 check whether the GameObject is the same as a given type.
auto getObjectType () const -> gobj::Type
 gets the internal type of the GameObject, as an enum
auto setNickname (const std::string &newNickname) -> void
 sets the GameObjects nickname.
auto updates () const -> bool
auto renders () const -> bool
auto receivesMessages () const -> bool
auto isActive () const -> bool
auto setActive (const bool shouldBeActive) -> void
 set the GameObject should update, render, and receive messages

Private Member Functions

auto onUpdate (float dt) -> void override
 called once every frame.

Private Attributes

std::map< Key, std::unique_ptr< C > > children
 A map that olds unique pointers to child objects, and a key that organizes them.

Friends

template<typename C>
auto to_json (json &j, const ChildrenHandeler< C > &ch) ->void
template<typename C>
auto from_json (const json &j, ChildrenHandeler< C > &ch) ->void
auto from_json (const json &j, ChildrenHandeler< C > &ch) ->void

Additional Inherited Members

Public Attributes inherited from GameObject
friend Entity
friend Node
friend ChildrenHandeler
friend Engine
Protected Member Functions inherited from GameObject
auto setInternalParent (GameObject *parent) -> bool
 sets the internal parent of a GameObject directly, avoiding abstractions provided by ParentTo().
auto getGameObjectJson () const -> json
 Used for serializing GameObjects.
auto setGameObjectJson (const json &stream) -> void
 used for deserializing GameObjects
auto checkAddToSceneHook () -> void
 Determine if the GameObject was recently added to the engine, and if it was, call onEngineEnter.

Detailed Description

template<class C = Component>
class ChildrenHandeler< C >

A container for child objects.

ChildrenHandeler provides functionality for adding, removing, finding, etc. to children. contextually, children means a child in the node graph specifically children in the Node graph. Currently, the two places where ChildrenHandeler is used are by Entity and Node

Template Parameters
CThe type that ChildrenHandeler holds

Constructor & Destructor Documentation

◆ ChildrenHandeler() [1/3]

template<class C = Component>
ChildrenHandeler< C >::ChildrenHandeler ( )
inline

default constructor for ChildrenHandeler

Here is the caller graph for this function:

◆ ChildrenHandeler() [2/3]

template<class C = Component>
ChildrenHandeler< C >::ChildrenHandeler ( const ChildrenHandeler< C > & other)
inline

deep copy of ChildrenHandeler

Parameters
otherobject to copy
Returns
Here is the call graph for this function:

◆ ChildrenHandeler() [3/3]

template<class C = Component>
ChildrenHandeler< C >::ChildrenHandeler ( ChildrenHandeler< C > && other)
inlinenoexcept

Move Constructor.

Parameters
otherChildrenhandeler to move
Here is the call graph for this function:

◆ ~ChildrenHandeler()

template<class C = Component>
ChildrenHandeler< C >::~ChildrenHandeler ( )
overridedefault

default dtor.

Overridden to ensure proper destruction

Member Function Documentation

◆ add()

template<class C = Component>
auto ChildrenHandeler< C >::add ( std::unique_ptr< C > newChild) ->void
inline

◆ clone()

template<class C = Component>
auto ChildrenHandeler< C >::clone ( ) const->std::unique_ptr< GameObject >
inlineoverridevirtual

makes a copy a GameObject even if it's held polymorphically

Warning
When overriding this function, make sure to set the parents object to this
Returns
a unique_ptr to a new stack allocated object that is a copy of the object

Implements GameObject.

Here is the call graph for this function:

◆ count()

template<class C = Component>
auto ChildrenHandeler< C >::count ( ) ->size_t
inline

◆ endWindow()

template<class C = Component>
auto ChildrenHandeler< C >::endWindow ( ) ->void
inlineoverridevirtual

currently unused, but intended to but was assumed to be necessary for a proper ImGui editor

Implements GameObject.

◆ find()

template<class C = Component>
auto ChildrenHandeler< C >::find ( std::function< bool(C &)> predicate) ->C *
inline

Returns pointer to child object.

Parameters
functionthat returns true for object defined
Returns
A pointer to the found object, or nullptr if no object was found

◆ for_each() [1/4]

template<class C = Component>
auto ChildrenHandeler< C >::for_each ( std::function< void(C &)> func) ->void
inline

applies a function to every child.

Parameters
funca function that takes a C reference, and does some operation on it

◆ for_each() [2/4]

template<class C = Component>
auto ChildrenHandeler< C >::for_each ( std::function< void(const C &)> func) const->void
inline

applies a function to every child.

Parameters
funca function that takes a C reference, and does some operation on it

◆ for_each() [3/4]

template<class C = Component>
auto ChildrenHandeler< C >::for_each ( std::function< void(const GameObject &)> func) const->void
inlineoverridevirtual

applies a function to every child.

Parameters
funca function that takes a C reference, and does some operation on it

Reimplemented from GameObject.

Here is the call graph for this function:

◆ for_each() [4/4]

template<class C = Component>
auto ChildrenHandeler< C >::for_each ( std::function< void(GameObject &)> func) ->void
inlinevirtual

applies a function to every child.

Parameters
funca function that takes a C reference, and does some operation on it

Reimplemented from GameObject.

Here is the call graph for this function:

◆ getChildren()

template<class C = Component>
auto ChildrenHandeler< C >::getChildren ( ) const->std::shared_ptr< std::vector< GameObject * > >
inlineoverridevirtual

gets a vector of a GameObjects public (i.e.

Entity s Entity and Component children)

Returns
a shared pointer to a vector of GameObject pointers, pointing to ALL of a GameObjects Public Children

Reimplemented from GameObject.

Here is the call graph for this function:

◆ getChildrenRange()

template<class C = Component>
auto ChildrenHandeler< C >::getChildrenRange ( ) const->std::shared_ptr< std::vector< GameObject * > >
inline

A function designed for Paths to use, for getting a list of all children, in a manageable format.

Returns
shared pointer to vector of pointers to all the children that ChildrenHandeler owns

@TODO if this hits performance too much, optimize it by setting a dirty flag

Here is the call graph for this function:
Here is the caller graph for this function:

◆ load()

template<class C = Component>
auto ChildrenHandeler< C >::load ( Stream & stream) ->void
inlineoverridevirtual

Implementations will load the state of a GameObject from a th::Json Object.

Unimplemented in GameObject

Parameters
streamth::Json Object

Implements GameObject.

◆ onEnterEngine()

template<class C = Component>
auto ChildrenHandeler< C >::onEnterEngine ( ) ->void
inlineoverridevirtual

hook that is called when a GameObject enters the Engine tree.

The hook is called immedietly after a gameobject's parent is called. Functionality may not be correct if an object was removed from the engine then re-added

Reimplemented from GameObject.

◆ onRender()

template<class C = Component>
auto ChildrenHandeler< C >::onRender ( ) ->void
inlineoverridevirtual

called every frame after update has been called for every object.

Generally used for rendering an object to the screen, when applicable. Unimplemented in GameObject

Implements GameObject.

◆ onUpdate()

template<class C = Component>
auto ChildrenHandeler< C >::onUpdate ( float dt) ->void
inlineoverrideprivatevirtual

called once every frame.

Generally used for timers, movement, condition checks, etc. Unimplemented in GameObject

Parameters
dtthe time in seconds that has elapsed

Implements GameObject.

◆ operator=() [1/2]

template<class C = Component>
auto ChildrenHandeler< C >::operator= ( ChildrenHandeler< C > && other) ->ChildrenHandeler &
inlinenoexcept

move assignment operator

Todo
: make ChildrenHandeler use copy swap for assignment
Parameters
otherChildrenHandeler to move
Returns
reference to ChildrenHandeler copied to, to allow chaining
Here is the call graph for this function:

◆ operator=() [2/2]

template<class C = Component>
auto ChildrenHandeler< C >::operator= ( const ChildrenHandeler< C > & other) ->ChildrenHandeler &
inline

Copy assignment operator.

Deep copies everything in the other ChildrenHandeler

Parameters
otherChildrenHandeler to copy
Returns
a reference to the ChildrenHandeler copied to
Here is the call graph for this function:

◆ pop()

template<class C = Component>
auto ChildrenHandeler< C >::pop ( Key key) ->std::unique_ptr< C >
inline

Removes a Child from the list, transferring ownership to the Caller.

Parameters
keythe Key of the Child to remove
Returns
an owning pointer to the child
Here is the call graph for this function:

◆ render()

template<class C = Component>
auto ChildrenHandeler< C >::render ( ) ->void
inlineoverridevirtual

called every frame after update has been called for every object.

Generally used for rendering an object to the screen, when applicable. override to ensure proper rendering of children that may be active calls onRender for implementation by concrete classes make sure you call GameObject::Update() when overriding

Reimplemented from GameObject.

Here is the call graph for this function:

◆ save()

template<class C = Component>
auto ChildrenHandeler< C >::save ( Stream & stream) const->void
inlineoverridevirtual

Implementations will load the state of a GameObject to a th::Json object.

Unimplemented in GameObject

Parameters
streamth::Json Object

Implements GameObject.

◆ setParents()

template<class C = Component>
auto ChildrenHandeler< C >::setParents ( GameObject & parent) ->void
inline

Set's all managed objects parent to one passed in.

Parameters
parentthe parent to set
Here is the call graph for this function:

◆ setShouldReceiveMessages()

template<class C = Component>
auto ChildrenHandeler< C >::setShouldReceiveMessages ( const bool _shouldReceiveMessages) ->void
inlineoverridevirtual

set whether the GameObject should Receive Messags, and whether all of it's children should receive messages

Parameters
_shouldReceiveMessageswhether the GameObject should receive messages

Reimplemented from GameObject.

Here is the call graph for this function:

◆ setShouldRender()

template<class C = Component>
auto ChildrenHandeler< C >::setShouldRender ( const bool _shouldRender) ->void
inlineoverridevirtual

set whether the GameObject should render every frame, and whether all of it's children should render every frame

Parameters
_shouldRenderwhether the GameObject should Render

Reimplemented from GameObject.

Here is the call graph for this function:

◆ setShouldUpdate()

template<class C = Component>
auto ChildrenHandeler< C >::setShouldUpdate ( const bool _shouldUpdate) ->void
inlineoverridevirtual

set whether the GameObject should update every frame, and whether all of it's children should update every frame

Parameters
_shouldUpdatewhether the object should update

Reimplemented from GameObject.

Here is the call graph for this function:

◆ showMenu()

template<class C = Component>
auto ChildrenHandeler< C >::showMenu ( ) ->void
inlineoverridevirtual

Called before update each frame, for calling ImGui editor code relevant to the gameObject.

virtual because we might need to destroy other things too, like parent node for entity Has a empty definition in GameObject, so it may be overriden, but doesn't have to be.

Reimplemented from GameObject.

◆ update()

template<class C = Component>
auto ChildrenHandeler< C >::update ( float dt) ->void
inlineoverridevirtual

called once every frame.

Generally used for timers, movement, condition checks, etc. calls onUpdate for implementation by concrete classes. override to properly call children make sure you call GameObject::Update() when overriding

Parameters
dtthe time in seconds that has elapsed

Reimplemented from GameObject.

Here is the call graph for this function:

◆ from_json [1/2]

template<class C = Component>
auto from_json ( const json & j,
ChildrenHandeler< C > & ch )->void
friend

there should be no default implementation for this template needs to the cpp from_json

◆ from_json [2/2]

template<class C = Component>
template<typename C>
auto from_json ( const json & j,
ChildrenHandeler< C > & ch )->void
friend

there should be no default implementation for this template needs to the cpp from_json

◆ to_json

template<class C = Component>
template<typename C>
auto to_json ( json & j,
const ChildrenHandeler< C > & ch )->void
friend

Member Data Documentation

◆ children

template<class C = Component>
std::map<Key, std::unique_ptr<C> > ChildrenHandeler< C >::children
private

A map that olds unique pointers to child objects, and a key that organizes them.


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