21 EntityHierarchy::EntityHierarchy(
const string&
id): id(id)
35 for (
auto entity:
entities)
delete entity;
40 for (
const auto& [childEntityId, childEntity]: entityHierarchyLevel->
children)
deleteHierarchy(childEntity, depth + 1);
41 delete entityHierarchyLevel;
60 if (_entity == entity) {
61 Console::println(
"EntityHierarchy::addEntity(): " + entity->
getId() +
": entity already added!");
81 if (parentEntityHierarchyLevel ==
nullptr) {
82 Console::println(
"EntityHierarchy::addEntity(): parent '" + parentId +
"': not found");
94 if (entityHierarchyLevel ==
nullptr || entityHierarchyLevel->parent ==
nullptr) {
99 vector<string> children;
100 for (
const auto& [childEntityId, childEntity]: entityHierarchyLevel->children) children.push_back(childEntityId);
104 auto entity = entityHierarchyLevel->entity;
108 auto entityHierarchyLevelIt = entityHierarchyLevel->parent->children.find(
id);
109 if (entityHierarchyLevelIt != entityHierarchyLevel->parent->children.end()) {
110 delete entityHierarchyLevelIt->second;
111 entityHierarchyLevel->parent->children.erase(entityHierarchyLevelIt);
125 if (parentEntityHierarchyLevel ==
nullptr) {
128 for (
const auto& [childEntityId, childEntity]: parentEntityHierarchyLevel->children) {
129 entities.push_back(childEntity->entity);
138 for (
const auto& [childEntityId, childEntity]: entityHierarchyLevel->
children) {
139 auto entity = childEntity->entity;
140 entity->setParentTransform(levelParentTransform);
142 if (firstEntity ==
true) {
149 for (
const auto& [childEntityId, childEntity]: entityHierarchyLevel->
children) {
150 updateHierarchy(levelParentTransform, childEntity, depth + 1, firstEntity);
171 auto firstEntity =
true;
185 auto firstEntity =
true;
192 if (this->enabled ==
enabled)
return;
215 if (this->frustumCulling ==
true) {
245 for (
auto entity:
entities) entity->initialize();
void set(float r, float g, float b, float a)
Sets this color by its components.
unique_ptr< Partition > partition
void updateEntityRegistration(Entity *entity)
Updates registration of engine by performing deregisterEntity() and registerEntity()
void deregisterEntity(Entity *entity)
Removes a entity from internal lists, those entities can also be sub entities from entity hierarchy o...
void removeEntityFromLists(Entity *entity)
Remove entity.
void registerEntity(Entity *entity)
Adds a entity to internal lists, those entities can also be sub entities from entity hierarchy or par...
Entity hierarchy to be used with engine class.
void updateHierarchy(const Transform &parentTransform, EntityHierarchyLevel *entityHierarchyLevel, int depth, bool &firstEntity)
Update hierarchy from given entity hierarchy level ongoing.
void dispose() override
Dispose this entity.
Transform parentTransform
BoundingBox worldBoundingBox
void initialize() override
Initiates this entity.
void update() override
Update transform.
void addEntity(Entity *entity, const string &parentId=string())
Adds a entity to the hierarchy.
Matrix4x4 entityTransformMatrix
void setTransform(const Transform &transform) override
Set transform.
void deleteHierarchy(EntityHierarchyLevel *entityHierarchyLevel, int depth)
Delete hierarchy from given entity hierarchy level ongoing.
EntityHierarchyLevel entityRoot
vector< Entity * > entities
EntityHierarchyLevel * getEntityHierarchyLevel(const string &id)
Get entity hierarchy level by given entity id.
const vector< Entity * > query(const string &parentId=string())
Query sub entities of parent entity.
void removeEntity(const string &id)
Removes a entity from hierarchy by given unique entity id.
void setFrustumCulling(bool frustumCulling) override
Set frustum culling.
void setEngine(Engine *engine) override
Set up engine.
Entity * getEntity(const string &id)
void setEnabled(bool enabled) override
Enable/disable rendering.
Matrix4x4 entityTransformMatrixInverted
bool isFrustumCulling() override
virtual ~EntityHierarchy()
Destructor.
void setRenderer(Renderer *renderer) override
Set up renderer.
virtual void setRenderer(Renderer *renderer)=0
Set up renderer.
virtual const string & getId()=0
virtual void setEngine(Engine *engine)=0
Set up engine.
virtual void setEffectColorMul(const Color4 &effectColorMul)=0
Set effect color that will be multiplied with fragment color.
virtual const Transform & getTransform() const =0
virtual void initialize()=0
Initiates this entity.
virtual void setContributesShadows(bool contributesShadows)=0
Enable/disable contributes shadows.
void setParentEntity(Entity *entity)
Set parent entity, needs to be called before adding to engine.
virtual void setPickable(bool pickable)=0
Set this entity pickable.
virtual void setReceivesShadows(bool receivesShadows)=0
Enable/disable receives shadows.
virtual void setEffectColorAdd(const Color4 &effectColorAdd)=0
Set effect color that will be added to fragment color.
Object to be used with engine class.
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
void extend(BoundingBox *boundingBox)
Extend bounding box with given bounding box.
void fromBoundingVolumeWithTransformMatrix(BoundingBox *original, const Matrix4x4 &transformMatrix)
Create bounding volume from given original(of same type) with applied transform matrix.
void update()
Updates this bounding box.
Matrix4x4 clone() const
Clones this matrix.
Matrix4x4 & identity()
Creates identity matrix.
Matrix4x4 & invert()
Inverts this matrix.
unordered_map< string, EntityHierarchyLevel * > children