Brunot
Loading...
Searching...
No Matches
Entity Class Reference

#include <Entity.h>

Inheritance diagram for Entity:
[legend]
Collaboration diagram for Entity:
[legend]

Public Member Functions

 Entity ()
 Entity (const Entity &other)
 ~Entity () override
auto clone () const -> std::unique_ptr< GameObject > override
 makes a copy a GameObject even if it's held polymorphically
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 onUpdate (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 for_each (std::function< void(GameObject &)> func) -> void override
 applies a function to every child.
auto for_each (std::function< void(const GameObject &)> func) const -> void override
 applies a const function to every child.
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 getParent () const -> Entity *override
auto destroy () -> void override
 Marks an GameObject to be destroyed.
auto setShouldUpdate (const bool _shouldUpdate) -> void override
 set whether the Entity, its components, and its children Entities should update every frame
auto setShouldRender (const bool _shouldRender) -> void override
 set whether the Entity, its components, and its children Entities should render every frame
auto setShouldReceiveMessages (const bool _shouldReceiveMessages) -> void override
 set whether the Entity, its components, and its children Entities should receive messages
auto pop () -> std::unique_ptr< Entity >
 Removes the Entity from the Engine tree, and gives ownership to the caller.
template<typename type>
auto GetComponent (Component::ComponentTypeEnum typeId) -> type *
 the implementation of the GetComponent Template
auto addChild (std::unique_ptr< GameObject > newChild) -> bool override
 adds either a component to the entity, or another game object as a child
auto addChild (std::unique_ptr< Entity > newChild) -> bool
auto addComponent (std::unique_ptr< Component > &&component) -> void
 takes a component pointer, and adds it to the Entity.
auto addComponent (std::unique_ptr< GameObject > component) -> bool
 Takes a pointer to a GameObject, and adds it to the Entity.
template<std::derived_from< Component > T>
auto addComponent (const T &component) -> void
 takes a component directly and adds it to the Entity.
template<std::derived_from< Component > T>
auto addComponent (std::unique_ptr< T > component) -> void
 allows adding components to objects with unique_ptrs to concrete components
auto deregisterComponents () const -> void
 deregister every component from messaging system
auto showComponentsMenu () -> void
 call showMenu() on all children
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 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 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

Protected Member Functions

auto getChildren () const -> std::shared_ptr< std::vector< GameObject * > > override
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.

Private Member Functions

auto Get (Component::ComponentTypeEnum typeId) -> Component *
auto addComponentButton () -> void
 A helper function for drawMenu() to make a button that lets you add components or entities.
auto showUpdateRenderMessagesFlagButtons () -> void
 A helper function for showMenu() to make buttons for toggling shouldRender, shouldUpdate, shouldReceiveMessages.
auto showNameInputMenu () -> void
 A helper function for showMenu() to show a input field for the entity name.

Private Attributes

ChildrenHandeler< Componentcomponents

Friends

auto to_json (json &j, const Entity &obj) ->void
auto from_json (const json &j, Entity &obj) ->void

Additional Inherited Members

Public Attributes inherited from GameObject
friend Entity
friend Node
friend ChildrenHandeler
friend Engine

Constructor & Destructor Documentation

◆ Entity() [1/2]

Entity::Entity ( )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Entity() [2/2]

Entity::Entity ( const Entity & other)
Here is the call graph for this function:

◆ ~Entity()

Entity::~Entity ( )
override
Here is the call graph for this function:

Member Function Documentation

◆ addChild() [1/2]

auto Entity::addChild ( std::unique_ptr< Entity > newChild) ->bool
Here is the call graph for this function:

◆ addChild() [2/2]

auto Entity::addChild ( std::unique_ptr< GameObject > newChild) ->bool
nodiscardoverridevirtual

adds either a component to the entity, or another game object as a child

Parameters
newChildcomponent pointer or other gameobject pointer
Returns
true if success, false otherwise

Reimplemented from GameObject.

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

◆ addComponent() [1/4]

template<std::derived_from< Component > T>
auto Entity::addComponent ( const T & component) ->void
inline

takes a component directly and adds it to the Entity.

component will be copied

Template Parameters
Tsome component
Parameters
componentthe component to take. it will be copied
Here is the call graph for this function:

◆ addComponent() [2/4]

auto Entity::addComponent ( std::unique_ptr< Component > && component) ->void

takes a component pointer, and adds it to the Entity.

this is the equivalent of calling entity->addChild(component); but, it won't fail. Useful if you have a pointer to a Component, rather that a pointer to a GameObject

See also
addChild() addComponent(std::unique_ptr)
Parameters
componenta unique pointer to a Component
Here is the caller graph for this function:

◆ addComponent() [3/4]

auto Entity::addComponent ( std::unique_ptr< GameObject > component) ->bool

Takes a pointer to a GameObject, and adds it to the Entity.

The function will fail if the GameObject isn't actually a Component

Parameters
componenta unique pointer
Returns
whether adding the component succeeded
Here is the call graph for this function:

◆ addComponent() [4/4]

template<std::derived_from< Component > T>
auto Entity::addComponent ( std::unique_ptr< T > component) ->void
inline

allows adding components to objects with unique_ptrs to concrete components

Template Parameters
Ta unique pointer to some component
Parameters
component
Here is the call graph for this function:

◆ addComponentButton()

auto Entity::addComponentButton ( ) ->void
private

A helper function for drawMenu() to make a button that lets you add components or entities.

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

◆ clone()

auto Entity::clone ( ) const->std::unique_ptr< GameObject >
overridevirtual

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:

◆ deregisterComponents()

auto Entity::deregisterComponents ( ) const->void
inline

deregister every component from messaging system

Here is the call graph for this function:

◆ destroy()

auto Entity::destroy ( ) ->void
overridevirtual

Marks an GameObject to be destroyed.

The GameObject will be actually removed when it is updated next

Reimplemented from GameObject.

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

◆ endWindow()

auto Entity::endWindow ( ) ->void
inlineoverridevirtual

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

Implements GameObject.

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

◆ for_each() [1/2]

auto Entity::for_each ( std::function< void(const GameObject &)> func) const->void
overridevirtual

applies a const function to every child.

applies to internal children, not public children. (this means that entities will only update their components, not their child entities)

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

Reimplemented from GameObject.

Here is the call graph for this function:

◆ for_each() [2/2]

auto Entity::for_each ( std::function< void(GameObject &)> func) ->void
overridevirtual

applies a function to every child.

applies to internal children, not public children. (this means that entities will only update their components, not their child entities)

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

Reimplemented from GameObject.

Here is the call graph for this function:

◆ Get()

auto Entity::Get ( Component::ComponentTypeEnum typeId) ->Component *
private
Parameters
typeIdThe type of component you want to get
Returns
A pointer to the requested component, if it exists NULL otherwise
Here is the caller graph for this function:

◆ getChildren()

auto Entity::getChildren ( ) const->std::shared_ptr< std::vector< GameObject * > >
overrideprotectedvirtual
Returns
a shared pointer to a vector of ALL of the Entities Children, Components and other Entities

Reimplemented from GameObject.

Here is the call graph for this function:

◆ GetComponent()

template<typename type>
auto Entity::GetComponent ( Component::ComponentTypeEnum typeId) ->type *
inline

the implementation of the GetComponent Template

this template is a type safe method of getting a specific component from an object. It must be declared here, in the header, otherwise linker errors occur. It calls the private Get() function to actually do the searching for the component

Template Parameters
typethe type of component to search for
Parameters
typeIdthe type of component as an enum
Returns
the component requested, typecast to its inherited class, NULL if not found
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getParent()

auto Entity::getParent ( ) const->Entity *
override
Here is the call graph for this function:

◆ load()

auto Entity::load ( Stream & stream) ->void
overridevirtual

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

Unimplemented in GameObject

Parameters
streamth::Json Object

Implements GameObject.

◆ onEnterEngine()

auto Entity::onEnterEngine ( ) ->void
overridevirtual

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()

auto Entity::onRender ( ) ->void
overridevirtual

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()

auto Entity::onUpdate ( float dt) ->void
overridevirtual

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.

Here is the call graph for this function:

◆ pop()

auto Entity::pop ( ) ->std::unique_ptr< Entity >

Removes the Entity from the Engine tree, and gives ownership to the caller.

It can now be added to other Entities Don't use this to remove Entities, instead, call entity->destroy()

Returns
an owning unique_ptr to the Entity
Here is the call graph for this function:

◆ render()

auto Entity::render ( ) ->void
overridevirtual

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()

auto Entity::save ( Stream & stream) const->void
overridevirtual

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

Unimplemented in GameObject

Parameters
streamth::Json Object

Implements GameObject.

◆ setShouldReceiveMessages()

auto Entity::setShouldReceiveMessages ( const bool _shouldReceiveMessages) ->void
overridevirtual

set whether the Entity, its components, and its children Entities should receive messages

Parameters
_shouldReceiveMessageswhether the object should receive Messages

Reimplemented from GameObject.

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

◆ setShouldRender()

auto Entity::setShouldRender ( const bool _shouldRender) ->void
overridevirtual

set whether the Entity, its components, and its children Entities should render every frame

Parameters
_shouldRenderwhether the object should render

Reimplemented from GameObject.

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

◆ setShouldUpdate()

auto Entity::setShouldUpdate ( const bool _shouldUpdate) ->void
overridevirtual

set whether the Entity, its components, and its children Entities should update every frame

Parameters
_shouldUpdatewhether the object should update

Reimplemented from GameObject.

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

◆ showComponentsMenu()

auto Entity::showComponentsMenu ( ) ->void

call showMenu() on all children

Here is the caller graph for this function:

◆ showMenu()

auto Entity::showMenu ( ) ->void
overridevirtual

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.

Here is the call graph for this function:

◆ showNameInputMenu()

void Entity::showNameInputMenu ( ) ->void
private

A helper function for showMenu() to show a input field for the entity name.

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

◆ showUpdateRenderMessagesFlagButtons()

auto Entity::showUpdateRenderMessagesFlagButtons ( ) ->void
private

A helper function for showMenu() to make buttons for toggling shouldRender, shouldUpdate, shouldReceiveMessages.

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

◆ update()

auto Entity::update ( float dt) ->void
overridevirtual

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

auto from_json ( const json & j,
Entity & obj )->void
friend

◆ to_json

auto to_json ( json & j,
const Entity & obj )->void
friend

Member Data Documentation

◆ components

ChildrenHandeler<Component> Entity::components
private

The documentation for this class was generated from the following files:
  • /home/egrazil/sites/Brunot/The House/source/Framework/Entity.h
  • /home/egrazil/sites/Brunot/The House/source/Framework/Entity.cpp