Sparkle 0.0.1
Loading...
Searching...
No Matches
spk::Entity Class Reference

Hierarchical game object containing components and children. More...

#include <spk_entity.hpp>

Inheritance diagram for spk::Entity:
Inheritance graph
Collaboration diagram for spk::Entity:
Collaboration graph

Public Types

using Contract = spk::ActivableObject::Contract
 Contract type for activation callbacks.
using Job = spk::ActivableObject::Job
 Job callback type for activation callbacks.
Public Types inherited from spk::ActivableObject
using Contract = StatefulObject<ActivationStatus>::Contract
 Subscription handle controlling callback lifetime.
using Job = StatefulObject<ActivationStatus>::Job
 Callback signature executed on activation state changes.
Public Types inherited from spk::StatefulObject< ActivationStatus >
using Contract
 Handle allowing subscribers to manage callback lifetimes.
using Job
 Callable invoked when the object transitions to a state.

Public Member Functions

 Entity (const std::wstring &p_name, Entity *p_owner=nullptr)
 Creates an entity with a name and optional owner.
 Entity ()
 Creates an unnamed entity.
 Entity (const Entity &)=delete
Entityoperator= (const Entity &)=delete
virtual void setName (const std::wstring &p_name)
 Sets the entity name.
void setPriority (const int &p_priority)
 Sets the entity priority.
void addTag (const std::wstring &p_tag)
 Adds a tag to the entity.
void removeTag (const std::wstring &p_tag)
 Removes a tag from the entity.
void clearTags ()
 Clears all tags.
bool containTag (const std::wstring &p_tag) const
 Checks if the entity contains a tag.
void setEngine (GameEngine *p_engine)
 Assigns the owning game engine.
GameEngineengine ()
 Returns the owning game engine.
const GameEngineengine () const
 Returns the owning game engine.
const std::wstring & name () const
 Returns the entity name.
const std::set< std::wstring > & tags () const
 Returns the set of tags.
int priority () const
 Returns the entity priority.
size_t componentCount () const
 Returns the number of components.
void removeAllComponents ()
 Removes all components from the entity.
void addChild (Entity *p_child) override
 Adds a child entity.
void removeChild (Entity *p_child) override
 Removes a child entity.
void clearChildren ()
 Removes all children.
std::vector< Entity * > & children () override
 Returns mutable children list.
const std::vector< Entity * > & children () const override
 Returns children list.
template<typename TComponentType, typename... TArgs>
TComponentType & addComponent (TArgs &&...p_args)
 Creates and adds a component of the given type.
void removeComponent (const std::wstring &p_name)
 Removes a component by name.
template<typename TComponentType>
TComponentType * getComponent (const std::wstring &p_name=L"")
 Returns the first component matching the type and optional name.
template<typename TComponentType>
std::vector< TComponentType * > getComponents ()
 Returns all components matching the type.
template<typename TComponentType>
const TComponentType * getComponent (const std::wstring &p_name=L"") const
 Returns the first component matching the type and optional name.
template<typename TComponentType>
std::vector< const TComponentType * > getComponents () const
 Returns all components matching the type.
virtual void handleGeometryChange (const spk::Extend2D &p_geometry) final
 Dispatches geometry change events to components.
virtual void handlePaintEvent (spk::PaintEvent &p_event) final
 Dispatches paint events to components.
virtual void handleKeyPressEvent (spk::KeyPressEvent &p_event) final
 Dispatches key press events to components.
virtual void handleKeyReleaseEvent (spk::KeyReleaseEvent &p_event) final
 Dispatches key release events to components.
virtual void handleGlyphEvent (spk::GlyphEvent &p_event) final
 Dispatches glyph input events to components.
virtual void handleMousePressEvent (spk::MousePressEvent &p_event) final
 Dispatches mouse press events to components.
virtual void handleMouseReleaseEvent (spk::MouseReleaseEvent &p_event) final
 Dispatches mouse release events to components.
virtual void handleMouseDoubleClickEvent (spk::MouseDoubleClickEvent &p_event) final
 Dispatches mouse double click events to components.
virtual void handleMouseMotionEvent (spk::MouseMotionEvent &p_event) final
 Dispatches mouse motion events to components.
virtual void handleMouseWheelEvent (spk::MouseWheelEvent &p_event) final
 Dispatches mouse wheel events to components.
virtual void handleEnterResizeModeEvent (spk::EnterResizeModeEvent &p_event) final
 Dispatches enter resize mode events to components.
virtual void handleResizeEvent (spk::ResizeEvent &p_event) final
 Dispatches resize events to components.
virtual void handleExitResizeModeEvent (spk::ExitResizeModeEvent &p_event) final
 Dispatches exit resize mode events to components.
virtual void handleQuitEvent (spk::QuitEvent &p_event) final
 Dispatches quit events to components.
virtual void handleMoveEvent (spk::MoveEvent &p_event) final
 Dispatches move events to components.
virtual void handleFullScreenModeEvent (spk::FullScreenModeEvent &p_event) final
 Dispatches fullscreen events to components.
virtual void handleMaximizedModeEvent (spk::MaximizedModeEvent &p_event) final
 Dispatches maximized events to components.
virtual void handleFocusEvent (spk::FocusEvent &p_event) final
 Dispatches focus events to components.
virtual void handleUpdateEvent (spk::UpdateEvent &p_event) final
 Dispatches update events to components.
void sortChildren ()
 Sorts children by priority.
void sortComponent ()
 Sorts components by priority.
EntitygetChild (const std::wstring &p_name)
 Returns the first child matching the name.
const EntitygetChild (const std::wstring &p_name) const
 Returns the first child matching the name.
std::vector< Entity * > getChildren (const std::wstring &p_name)
 Returns all children matching the name.
std::vector< const Entity * > getChildren (const std::wstring &p_name) const
 Returns all children matching the name.
bool contains (const std::wstring &p_name) const
 Checks if a child with the name exists.
size_t count (const std::wstring &p_name) const
 Counts children matching the name.
EntitygetChildByTag (const std::wstring &p_tag)
 Returns the first child matching a tag.
const EntitygetChildByTag (const std::wstring &p_tag) const
 Returns the first child matching a tag.
std::vector< Entity * > getChildrenByTag (const std::wstring &p_tag)
 Returns all children matching a tag.
std::vector< const Entity * > getChildrenByTag (const std::wstring &p_tag) const
 Returns all children matching a tag.
bool containsTag (const std::wstring &p_tag) const
 Checks if a child with the tag exists.
size_t countTag (const std::wstring &p_tag) const
 Counts children matching a tag.
EntitygetChildByTags (const std::span< const std::wstring > &p_tags, spk::BinaryOperator p_binaryOperator=spk::BinaryOperator::And)
 Returns the first child matching a set of tags.
const EntitygetChildByTags (const std::span< const std::wstring > &p_tags, spk::BinaryOperator p_binaryOperator=spk::BinaryOperator::And) const
 Returns the first child matching a set of tags.
std::vector< Entity * > getChildrenByTags (const std::span< const std::wstring > &p_tags, spk::BinaryOperator p_binaryOperator=spk::BinaryOperator::And)
 Returns all children matching a set of tags.
std::vector< const Entity * > getChildrenByTags (const std::span< const std::wstring > &p_tags, spk::BinaryOperator p_binaryOperator=spk::BinaryOperator::And) const
 Returns all children matching a set of tags.
bool containsTags (const std::span< const std::wstring > &p_tags, spk::BinaryOperator p_binaryOperator=spk::BinaryOperator::And) const
 Checks if a child matching all tags exists.
size_t countTags (const std::span< const std::wstring > &p_tags, spk::BinaryOperator p_binaryOperator=spk::BinaryOperator::And) const
 Counts children matching all tags.
Public Member Functions inherited from spk::InherenceObject< Entity >
Entityparent () const
 Returns the parent pointer.
void clearChildren ()
 Clears the children list and resets each child's parent pointer.
Public Member Functions inherited from spk::ActivableObject
 ActivableObject ()
 Builds a deactivated object.
 ActivableObject (ActivationStatus p_initial)
 Builds with a custom initial activation state.
void activate ()
 Sets the state to Activated.
void deactivate ()
 Sets the state to Deactivated.
void toggle ()
 Toggles between activated and deactivated states.
bool isActive () const
 Checks whether the object is currently activated.
Contract addActivationCallback (const Job &p_callback)
 Registers a callback executed when the object activates.
Contract addDeactivationCallback (const Job &p_callback)
 Registers a callback executed when the object deactivates.
Public Member Functions inherited from spk::StatefulObject< ActivationStatus >
 StatefulObject (const ActivationStatus &p_initialState)
 Builds with an initial state.
StatefulObjectoperator= (const StatefulObject &p_other)=delete
void setState (const ActivationStatus &p_newState)
 Sets a new state and triggers callbacks registered for it.
ActivationStatus state () const
 Returns the current state.
Contract addCallback (const ActivationStatus &p_state, const Job &p_callback)
 Subscribes a callback for a specific state.

Detailed Description

Hierarchical game object containing components and children.

Constructor & Destructor Documentation

◆ Entity()

spk::Entity::Entity ( const std::wstring & p_name,
Entity * p_owner = nullptr )

Creates an entity with a name and optional owner.

Parameters
p_nameEntity name.
p_ownerOptional parent entity.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ addChild()

void spk::Entity::addChild ( Entity * p_child)
overridevirtual

Adds a child entity.

Parameters
p_childChild to add.

Reimplemented from spk::InherenceObject< Entity >.

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

◆ addComponent()

template<typename TComponentType, typename... TArgs>
TComponentType & spk::Entity::addComponent ( TArgs &&... p_args)
inline

Creates and adds a component of the given type.

Template Parameters
TComponentTypeComponent type to create.
TArgsConstructor argument types.
Parameters
p_argsArguments forwarded to the component constructor.
Returns
Reference to the newly added component.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addTag()

void spk::Entity::addTag ( const std::wstring & p_tag)

Adds a tag to the entity.

Parameters
p_tagTag to add.

◆ children() [1/2]

const std::vector< Entity * > & spk::Entity::children ( ) const
override

Returns children list.

Returns
Vector of child pointers.
Here is the call graph for this function:

◆ children() [2/2]

std::vector< Entity * > & spk::Entity::children ( )
overridevirtual

Returns mutable children list.

Returns
Vector of child pointers.

Reimplemented from spk::InherenceObject< Entity >.

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

◆ componentCount()

size_t spk::Entity::componentCount ( ) const

Returns the number of components.

Returns
Component count.

◆ contains()

bool spk::Entity::contains ( const std::wstring & p_name) const

Checks if a child with the name exists.

Parameters
p_nameChild name.
Returns
True if at least one child matches.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ containsTag()

bool spk::Entity::containsTag ( const std::wstring & p_tag) const

Checks if a child with the tag exists.

Parameters
p_tagTag to match.
Returns
True if at least one child matches.
Here is the call graph for this function:

◆ containsTags()

bool spk::Entity::containsTags ( const std::span< const std::wstring > & p_tags,
spk::BinaryOperator p_binaryOperator = spk::BinaryOperator::And ) const

Checks if a child matching all tags exists.

Parameters
p_tagsTags to match.
p_binaryOperatorCombination operator (And/Or).
Returns
True if at least one child matches.
Here is the call graph for this function:

◆ containTag()

bool spk::Entity::containTag ( const std::wstring & p_tag) const

Checks if the entity contains a tag.

Parameters
p_tagTag to query.
Returns
True if the tag exists.

◆ count()

size_t spk::Entity::count ( const std::wstring & p_name) const

Counts children matching the name.

Parameters
p_nameChild name.
Returns
Number of matching children.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ countTag()

size_t spk::Entity::countTag ( const std::wstring & p_tag) const

Counts children matching a tag.

Parameters
p_tagTag to match.
Returns
Number of matching children.
Here is the call graph for this function:

◆ countTags()

size_t spk::Entity::countTags ( const std::span< const std::wstring > & p_tags,
spk::BinaryOperator p_binaryOperator = spk::BinaryOperator::And ) const

Counts children matching all tags.

Parameters
p_tagsTags to match.
p_binaryOperatorCombination operator (And/Or).
Returns
Number of matching children.
Here is the call graph for this function:

◆ engine() [1/2]

GameEngine * spk::Entity::engine ( )

Returns the owning game engine.

Returns
Engine pointer.

◆ engine() [2/2]

const GameEngine * spk::Entity::engine ( ) const

Returns the owning game engine.

Returns
Const engine pointer.

◆ getChild() [1/2]

Entity * spk::Entity::getChild ( const std::wstring & p_name)

Returns the first child matching the name.

Parameters
p_nameChild name.
Returns
Matching child or nullptr.
Here is the call graph for this function:

◆ getChild() [2/2]

const Entity * spk::Entity::getChild ( const std::wstring & p_name) const

Returns the first child matching the name.

Parameters
p_nameChild name.
Returns
Matching child or nullptr.
Here is the call graph for this function:

◆ getChildByTag() [1/2]

Entity * spk::Entity::getChildByTag ( const std::wstring & p_tag)

Returns the first child matching a tag.

Parameters
p_tagTag to match.
Returns
Matching child or nullptr.
Here is the call graph for this function:

◆ getChildByTag() [2/2]

const Entity * spk::Entity::getChildByTag ( const std::wstring & p_tag) const

Returns the first child matching a tag.

Parameters
p_tagTag to match.
Returns
Matching child or nullptr.
Here is the call graph for this function:

◆ getChildByTags() [1/2]

Entity * spk::Entity::getChildByTags ( const std::span< const std::wstring > & p_tags,
spk::BinaryOperator p_binaryOperator = spk::BinaryOperator::And )

Returns the first child matching a set of tags.

Parameters
p_tagsTags to match.
p_binaryOperatorCombination operator (And/Or).
Returns
Matching child or nullptr.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getChildByTags() [2/2]

const Entity * spk::Entity::getChildByTags ( const std::span< const std::wstring > & p_tags,
spk::BinaryOperator p_binaryOperator = spk::BinaryOperator::And ) const

Returns the first child matching a set of tags.

Parameters
p_tagsTags to match.
p_binaryOperatorCombination operator (And/Or).
Returns
Matching child or nullptr.
Here is the call graph for this function:

◆ getChildren() [1/2]

std::vector< Entity * > spk::Entity::getChildren ( const std::wstring & p_name)

Returns all children matching the name.

Parameters
p_nameChild name.
Returns
Vector of matching children.
Here is the call graph for this function:

◆ getChildren() [2/2]

std::vector< const Entity * > spk::Entity::getChildren ( const std::wstring & p_name) const

Returns all children matching the name.

Parameters
p_nameChild name.
Returns
Vector of matching children.
Here is the call graph for this function:

◆ getChildrenByTag() [1/2]

std::vector< Entity * > spk::Entity::getChildrenByTag ( const std::wstring & p_tag)

Returns all children matching a tag.

Parameters
p_tagTag to match.
Returns
Vector of matching children.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getChildrenByTag() [2/2]

std::vector< const Entity * > spk::Entity::getChildrenByTag ( const std::wstring & p_tag) const

Returns all children matching a tag.

Parameters
p_tagTag to match.
Returns
Vector of matching children.
Here is the call graph for this function:

◆ getChildrenByTags() [1/2]

std::vector< Entity * > spk::Entity::getChildrenByTags ( const std::span< const std::wstring > & p_tags,
spk::BinaryOperator p_binaryOperator = spk::BinaryOperator::And )

Returns all children matching a set of tags.

Parameters
p_tagsTags to match.
p_binaryOperatorCombination operator (And/Or).
Returns
Vector of matching children.
Here is the call graph for this function:

◆ getChildrenByTags() [2/2]

std::vector< const Entity * > spk::Entity::getChildrenByTags ( const std::span< const std::wstring > & p_tags,
spk::BinaryOperator p_binaryOperator = spk::BinaryOperator::And ) const

Returns all children matching a set of tags.

Parameters
p_tagsTags to match.
p_binaryOperatorCombination operator (And/Or).
Returns
Vector of matching children.
Here is the call graph for this function:

◆ getComponent() [1/2]

template<typename TComponentType>
TComponentType * spk::Entity::getComponent ( const std::wstring & p_name = L"")
inline

Returns the first component matching the type and optional name.

Template Parameters
TComponentTypeComponent type to find.
Parameters
p_nameOptional name filter.
Returns
Pointer to the component or nullptr.

◆ getComponent() [2/2]

template<typename TComponentType>
const TComponentType * spk::Entity::getComponent ( const std::wstring & p_name = L"") const
inline

Returns the first component matching the type and optional name.

Template Parameters
TComponentTypeComponent type to find.
Parameters
p_nameOptional name filter.
Returns
Pointer to the component or nullptr.

◆ getComponents() [1/2]

template<typename TComponentType>
std::vector< TComponentType * > spk::Entity::getComponents ( )
inline

Returns all components matching the type.

Template Parameters
TComponentTypeComponent type to find.
Returns
Vector of matching components.

◆ getComponents() [2/2]

template<typename TComponentType>
std::vector< const TComponentType * > spk::Entity::getComponents ( ) const
inline

Returns all components matching the type.

Template Parameters
TComponentTypeComponent type to find.
Returns
Vector of matching components.

◆ handleEnterResizeModeEvent()

void spk::Entity::handleEnterResizeModeEvent ( spk::EnterResizeModeEvent & p_event)
finalvirtual

Dispatches enter resize mode events to components.

Parameters
p_eventEnter resize mode event.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleExitResizeModeEvent()

void spk::Entity::handleExitResizeModeEvent ( spk::ExitResizeModeEvent & p_event)
finalvirtual

Dispatches exit resize mode events to components.

Parameters
p_eventExit resize mode event.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleFocusEvent()

void spk::Entity::handleFocusEvent ( spk::FocusEvent & p_event)
finalvirtual

Dispatches focus events to components.

Parameters
p_eventFocus event.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleFullScreenModeEvent()

void spk::Entity::handleFullScreenModeEvent ( spk::FullScreenModeEvent & p_event)
finalvirtual

Dispatches fullscreen events to components.

Parameters
p_eventFullscreen event.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleGeometryChange()

void spk::Entity::handleGeometryChange ( const spk::Extend2D & p_geometry)
finalvirtual

Dispatches geometry change events to components.

Parameters
p_geometryUpdated geometry.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleGlyphEvent()

void spk::Entity::handleGlyphEvent ( spk::GlyphEvent & p_event)
finalvirtual

Dispatches glyph input events to components.

Parameters
p_eventGlyph event.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleKeyPressEvent()

void spk::Entity::handleKeyPressEvent ( spk::KeyPressEvent & p_event)
finalvirtual

Dispatches key press events to components.

Parameters
p_eventKey press event.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleKeyReleaseEvent()

void spk::Entity::handleKeyReleaseEvent ( spk::KeyReleaseEvent & p_event)
finalvirtual

Dispatches key release events to components.

Parameters
p_eventKey release event.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleMaximizedModeEvent()

void spk::Entity::handleMaximizedModeEvent ( spk::MaximizedModeEvent & p_event)
finalvirtual

Dispatches maximized events to components.

Parameters
p_eventMaximized event.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleMouseDoubleClickEvent()

void spk::Entity::handleMouseDoubleClickEvent ( spk::MouseDoubleClickEvent & p_event)
finalvirtual

Dispatches mouse double click events to components.

Parameters
p_eventMouse double click event.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleMouseMotionEvent()

void spk::Entity::handleMouseMotionEvent ( spk::MouseMotionEvent & p_event)
finalvirtual

Dispatches mouse motion events to components.

Parameters
p_eventMouse motion event.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleMousePressEvent()

void spk::Entity::handleMousePressEvent ( spk::MousePressEvent & p_event)
finalvirtual

Dispatches mouse press events to components.

Parameters
p_eventMouse press event.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleMouseReleaseEvent()

void spk::Entity::handleMouseReleaseEvent ( spk::MouseReleaseEvent & p_event)
finalvirtual

Dispatches mouse release events to components.

Parameters
p_eventMouse release event.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleMouseWheelEvent()

void spk::Entity::handleMouseWheelEvent ( spk::MouseWheelEvent & p_event)
finalvirtual

Dispatches mouse wheel events to components.

Parameters
p_eventMouse wheel event.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleMoveEvent()

void spk::Entity::handleMoveEvent ( spk::MoveEvent & p_event)
finalvirtual

Dispatches move events to components.

Parameters
p_eventMove event.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handlePaintEvent()

void spk::Entity::handlePaintEvent ( spk::PaintEvent & p_event)
finalvirtual

Dispatches paint events to components.

Parameters
p_eventPaint event.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleQuitEvent()

void spk::Entity::handleQuitEvent ( spk::QuitEvent & p_event)
finalvirtual

Dispatches quit events to components.

Parameters
p_eventQuit event.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleResizeEvent()

void spk::Entity::handleResizeEvent ( spk::ResizeEvent & p_event)
finalvirtual

Dispatches resize events to components.

Parameters
p_eventResize event.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleUpdateEvent()

void spk::Entity::handleUpdateEvent ( spk::UpdateEvent & p_event)
finalvirtual

Dispatches update events to components.

Parameters
p_eventUpdate event.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ name()

const std::wstring & spk::Entity::name ( ) const

Returns the entity name.

Returns
Name string.
Here is the caller graph for this function:

◆ priority()

int spk::Entity::priority ( ) const

Returns the entity priority.

Returns
Priority value.

◆ removeChild()

void spk::Entity::removeChild ( Entity * p_child)
overridevirtual

Removes a child entity.

Parameters
p_childChild to remove.

Reimplemented from spk::InherenceObject< Entity >.

Here is the call graph for this function:

◆ removeComponent()

void spk::Entity::removeComponent ( const std::wstring & p_name)

Removes a component by name.

Parameters
p_nameComponent name.

◆ removeTag()

void spk::Entity::removeTag ( const std::wstring & p_tag)

Removes a tag from the entity.

Parameters
p_tagTag to remove.

◆ setEngine()

void spk::Entity::setEngine ( GameEngine * p_engine)

Assigns the owning game engine.

Parameters
p_engineEngine pointer.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setName()

void spk::Entity::setName ( const std::wstring & p_name)
virtual

Sets the entity name.

Parameters
p_nameNew name.

◆ setPriority()

void spk::Entity::setPriority ( const int & p_priority)

Sets the entity priority.

Parameters
p_priorityPriority value.
Here is the call graph for this function:

◆ tags()

const std::set< std::wstring > & spk::Entity::tags ( ) const

Returns the set of tags.

Returns
Tag set.

The documentation for this class was generated from the following files:
  • includes/structure/engine/spk_entity.hpp
  • srcs/structure/engine/spk_entity.cpp