mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-12-22 13:33:35 +00:00
Parent and Child Deletion Improvements (#649)
* Fix timers * Update Entity.cpp * Fix timers Fix timers Remove debug logs remove _dynamic * I like to move it move it * Child Deletion Improvements * Check bounds
This commit is contained in:
parent
77d35019cc
commit
c689b3d3d1
@ -109,6 +109,11 @@ Entity::~Entity() {
|
||||
|
||||
m_Components.erase(pair.first);
|
||||
}
|
||||
|
||||
for (auto child : m_ChildEntities) {
|
||||
if (child) child->RemoveParent();
|
||||
}
|
||||
|
||||
if (m_ParentEntity) {
|
||||
m_ParentEntity->RemoveChild(this);
|
||||
}
|
||||
@ -1662,15 +1667,21 @@ void Entity::AddChild(Entity* child) {
|
||||
|
||||
void Entity::RemoveChild(Entity* child) {
|
||||
if (!child) return;
|
||||
for (auto entity = m_ChildEntities.begin(); entity != m_ChildEntities.end(); entity++) {
|
||||
if (*entity && (*entity)->GetObjectID() == child->GetObjectID()) {
|
||||
uint32_t entityPosition = 0;
|
||||
while (entityPosition < m_ChildEntities.size()) {
|
||||
if (!m_ChildEntities[entityPosition] || (m_ChildEntities[entityPosition])->GetObjectID() == child->GetObjectID()) {
|
||||
m_IsParentChildDirty = true;
|
||||
m_ChildEntities.erase(entity);
|
||||
return;
|
||||
m_ChildEntities.erase(m_ChildEntities.begin() + entityPosition);
|
||||
} else {
|
||||
entityPosition++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Entity::RemoveParent() {
|
||||
this->m_ParentEntity = nullptr;
|
||||
}
|
||||
|
||||
void Entity::AddTimer(std::string name, float time) {
|
||||
EntityTimer* timer = new EntityTimer(name, time);
|
||||
m_PendingTimers.push_back(timer);
|
||||
|
@ -144,6 +144,7 @@ public:
|
||||
|
||||
void AddChild(Entity* child);
|
||||
void RemoveChild(Entity* child);
|
||||
void RemoveParent();
|
||||
void AddTimer(std::string name, float time);
|
||||
void AddCallbackTimer(float time, std::function<void()> callback);
|
||||
bool HasTimer(const std::string& name);
|
||||
|
Loading…
Reference in New Issue
Block a user