|
Sparkle 0.0.1
|
Hierarchical game object containing components and children. More...
#include <spk_entity.hpp>


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 | |
| Entity & | operator= (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. | |
| GameEngine * | engine () |
| Returns the owning game engine. | |
| const GameEngine * | engine () 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. | |
| Entity * | getChild (const std::wstring &p_name) |
| Returns the first child matching the name. | |
| const Entity * | getChild (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. | |
| Entity * | getChildByTag (const std::wstring &p_tag) |
| Returns the first child matching a tag. | |
| const Entity * | getChildByTag (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. | |
| 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. | |
| const 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. | |
| 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 > | |
| Entity * | parent () 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. | |
| StatefulObject & | operator= (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. | |
Hierarchical game object containing components and children.
| spk::Entity::Entity | ( | const std::wstring & | p_name, |
| Entity * | p_owner = nullptr ) |
Creates an entity with a name and optional owner.
| p_name | Entity name. |
| p_owner | Optional parent entity. |


|
overridevirtual |
Adds a child entity.
| p_child | Child to add. |
Reimplemented from spk::InherenceObject< Entity >.


|
inline |
Creates and adds a component of the given type.
| TComponentType | Component type to create. |
| TArgs | Constructor argument types. |
| p_args | Arguments forwarded to the component constructor. |


| void spk::Entity::addTag | ( | const std::wstring & | p_tag | ) |
Adds a tag to the entity.
| p_tag | Tag to add. |
|
override |
Returns children list.

|
overridevirtual |
Returns mutable children list.
Reimplemented from spk::InherenceObject< Entity >.


| size_t spk::Entity::componentCount | ( | ) | const |
Returns the number of components.
| bool spk::Entity::contains | ( | const std::wstring & | p_name | ) | const |
Checks if a child with the name exists.
| p_name | Child name. |


| bool spk::Entity::containsTag | ( | const std::wstring & | p_tag | ) | const |
Checks if a child with the tag exists.
| p_tag | Tag to match. |

| 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.
| p_tags | Tags to match. |
| p_binaryOperator | Combination operator (And/Or). |

| bool spk::Entity::containTag | ( | const std::wstring & | p_tag | ) | const |
Checks if the entity contains a tag.
| p_tag | Tag to query. |
| size_t spk::Entity::count | ( | const std::wstring & | p_name | ) | const |
Counts children matching the name.
| p_name | Child name. |


| size_t spk::Entity::countTag | ( | const std::wstring & | p_tag | ) | const |
Counts children matching a tag.
| p_tag | Tag to match. |

| 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.
| p_tags | Tags to match. |
| p_binaryOperator | Combination operator (And/Or). |

| GameEngine * spk::Entity::engine | ( | ) |
Returns the owning game engine.
| const GameEngine * spk::Entity::engine | ( | ) | const |
Returns the owning game engine.
| Entity * spk::Entity::getChild | ( | const std::wstring & | p_name | ) |
Returns the first child matching the name.
| p_name | Child name. |

| const Entity * spk::Entity::getChild | ( | const std::wstring & | p_name | ) | const |
Returns the first child matching the name.
| p_name | Child name. |

| Entity * spk::Entity::getChildByTag | ( | const std::wstring & | p_tag | ) |
Returns the first child matching a tag.
| p_tag | Tag to match. |

| const Entity * spk::Entity::getChildByTag | ( | const std::wstring & | p_tag | ) | const |
Returns the first child matching a tag.
| p_tag | Tag to match. |

| 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.
| p_tags | Tags to match. |
| p_binaryOperator | Combination operator (And/Or). |


| 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.
| p_tags | Tags to match. |
| p_binaryOperator | Combination operator (And/Or). |

| std::vector< Entity * > spk::Entity::getChildren | ( | const std::wstring & | p_name | ) |
Returns all children matching the name.
| p_name | Child name. |

| std::vector< const Entity * > spk::Entity::getChildren | ( | const std::wstring & | p_name | ) | const |
Returns all children matching the name.
| p_name | Child name. |

| std::vector< Entity * > spk::Entity::getChildrenByTag | ( | const std::wstring & | p_tag | ) |
Returns all children matching a tag.
| p_tag | Tag to match. |


| std::vector< const Entity * > spk::Entity::getChildrenByTag | ( | const std::wstring & | p_tag | ) | const |
Returns all children matching a tag.
| p_tag | Tag to match. |

| 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.
| p_tags | Tags to match. |
| p_binaryOperator | Combination operator (And/Or). |

| 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.
| p_tags | Tags to match. |
| p_binaryOperator | Combination operator (And/Or). |

|
inline |
Returns the first component matching the type and optional name.
| TComponentType | Component type to find. |
| p_name | Optional name filter. |
|
inline |
Returns the first component matching the type and optional name.
| TComponentType | Component type to find. |
| p_name | Optional name filter. |
|
inline |
Returns all components matching the type.
| TComponentType | Component type to find. |
|
inline |
Returns all components matching the type.
| TComponentType | Component type to find. |
|
finalvirtual |
Dispatches enter resize mode events to components.
| p_event | Enter resize mode event. |


|
finalvirtual |
Dispatches exit resize mode events to components.
| p_event | Exit resize mode event. |


|
finalvirtual |
Dispatches focus events to components.
| p_event | Focus event. |


|
finalvirtual |
Dispatches fullscreen events to components.
| p_event | Fullscreen event. |


|
finalvirtual |
Dispatches geometry change events to components.
| p_geometry | Updated geometry. |


|
finalvirtual |
Dispatches glyph input events to components.
| p_event | Glyph event. |


|
finalvirtual |
Dispatches key press events to components.
| p_event | Key press event. |


|
finalvirtual |
Dispatches key release events to components.
| p_event | Key release event. |


|
finalvirtual |
Dispatches maximized events to components.
| p_event | Maximized event. |


|
finalvirtual |
Dispatches mouse double click events to components.
| p_event | Mouse double click event. |


|
finalvirtual |
Dispatches mouse motion events to components.
| p_event | Mouse motion event. |


|
finalvirtual |
Dispatches mouse press events to components.
| p_event | Mouse press event. |


|
finalvirtual |
Dispatches mouse release events to components.
| p_event | Mouse release event. |


|
finalvirtual |
Dispatches mouse wheel events to components.
| p_event | Mouse wheel event. |


|
finalvirtual |
Dispatches move events to components.
| p_event | Move event. |


|
finalvirtual |
Dispatches paint events to components.
| p_event | Paint event. |


|
finalvirtual |
Dispatches quit events to components.
| p_event | Quit event. |


|
finalvirtual |
Dispatches resize events to components.
| p_event | Resize event. |


|
finalvirtual |
Dispatches update events to components.
| p_event | Update event. |


| const std::wstring & spk::Entity::name | ( | ) | const |
Returns the entity name.

| int spk::Entity::priority | ( | ) | const |
Returns the entity priority.
|
overridevirtual |
Removes a child entity.
| p_child | Child to remove. |
Reimplemented from spk::InherenceObject< Entity >.

| void spk::Entity::removeComponent | ( | const std::wstring & | p_name | ) |
Removes a component by name.
| p_name | Component name. |
| void spk::Entity::removeTag | ( | const std::wstring & | p_tag | ) |
Removes a tag from the entity.
| p_tag | Tag to remove. |
| void spk::Entity::setEngine | ( | GameEngine * | p_engine | ) |
Assigns the owning game engine.
| p_engine | Engine pointer. |


|
virtual |
Sets the entity name.
| p_name | New name. |
| void spk::Entity::setPriority | ( | const int & | p_priority | ) |
Sets the entity priority.
| p_priority | Priority value. |

| const std::set< std::wstring > & spk::Entity::tags | ( | ) | const |
Returns the set of tags.