![]() |
Shkyera Engine
Easy to use, game engine for Python
|
#include <EntityHierarchy.hpp>
Public Types | |
using | Children = std::set< Entity > |
Alias for a set of child entities. | |
Public Member Functions | |
EntityHierarchy ()=default | |
Constructs a new EntityHierarchy object. | |
~EntityHierarchy ()=default | |
Destroys the EntityHierarchy object. | |
void | attributeChild (Entity parent, Entity child) |
Attributes a child entity to a parent entity. | |
void | removeFromParent (Entity child) |
Removes a child entity from its parent. | |
std::optional< Entity > | getParent (Entity child) const |
Gets the parent of a specified child entity. | |
const Children & | getChildren (Entity parent) const |
Gets the children of a specified parent entity. | |
const auto & | getParentToChild () const |
Private Member Functions | |
bool | isAncestor (Entity entity, Entity ancestor) const |
Checks if an entity is an ancestor of another entity. | |
Private Attributes | |
std::map< Entity, Children > | _parentToChildren |
std::map< Entity, Entity > | _childToParent |
This class provides functionalities to attribute child entities to parent entities, retrieve parent entities, retrieve children of a parent entity, and manage the removal of entities from their parents. It ensures a well-defined tree structure for entity relationships with NO cyclic relations.
using shkyera::EntityHierarchy::Children = std::set<Entity> |
Alias for a set of child entities.
|
default |
Constructs a new EntityHierarchy object.
|
default |
Destroys the EntityHierarchy object.
Attributes a child entity to a parent entity.
Establishes a parent-child relationship by associating the specified child with the specified parent.
parent | The parent entity. |
child | The child entity to be attributed to the parent. |
const EntityHierarchy::Children & shkyera::EntityHierarchy::getChildren | ( | Entity | parent | ) | const |
Gets the children of a specified parent entity.
Retrieves all entities that are attributed as children of the specified parent entity.
parent | The parent entity whose children are to be retrieved. |
Gets the parent of a specified child entity.
Retrieves the parent entity of the specified child, if a parent-child relationship exists.
child | The child entity whose parent is to be retrieved. |
Checks if an entity is an ancestor of another entity.
Determines if the specified ancestor entity is an ancestor of the specified entity in the hierarchy.
entity | The entity to check. |
ancestor | The potential ancestor entity. |
Removes a child entity from its parent.
If the specified child entity has a parent, the parent-child association is removed.
child | The child entity to be removed from its parent. |