mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-12-23 05:53:34 +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);
|
m_Components.erase(pair.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto child : m_ChildEntities) {
|
||||||
|
if (child) child->RemoveParent();
|
||||||
|
}
|
||||||
|
|
||||||
if (m_ParentEntity) {
|
if (m_ParentEntity) {
|
||||||
m_ParentEntity->RemoveChild(this);
|
m_ParentEntity->RemoveChild(this);
|
||||||
}
|
}
|
||||||
@ -1662,15 +1667,21 @@ void Entity::AddChild(Entity* child) {
|
|||||||
|
|
||||||
void Entity::RemoveChild(Entity* child) {
|
void Entity::RemoveChild(Entity* child) {
|
||||||
if (!child) return;
|
if (!child) return;
|
||||||
for (auto entity = m_ChildEntities.begin(); entity != m_ChildEntities.end(); entity++) {
|
uint32_t entityPosition = 0;
|
||||||
if (*entity && (*entity)->GetObjectID() == child->GetObjectID()) {
|
while (entityPosition < m_ChildEntities.size()) {
|
||||||
|
if (!m_ChildEntities[entityPosition] || (m_ChildEntities[entityPosition])->GetObjectID() == child->GetObjectID()) {
|
||||||
m_IsParentChildDirty = true;
|
m_IsParentChildDirty = true;
|
||||||
m_ChildEntities.erase(entity);
|
m_ChildEntities.erase(m_ChildEntities.begin() + entityPosition);
|
||||||
return;
|
} else {
|
||||||
|
entityPosition++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Entity::RemoveParent() {
|
||||||
|
this->m_ParentEntity = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void Entity::AddTimer(std::string name, float time) {
|
void Entity::AddTimer(std::string name, float time) {
|
||||||
EntityTimer* timer = new EntityTimer(name, time);
|
EntityTimer* timer = new EntityTimer(name, time);
|
||||||
m_PendingTimers.push_back(timer);
|
m_PendingTimers.push_back(timer);
|
||||||
|
@ -144,6 +144,7 @@ public:
|
|||||||
|
|
||||||
void AddChild(Entity* child);
|
void AddChild(Entity* child);
|
||||||
void RemoveChild(Entity* child);
|
void RemoveChild(Entity* child);
|
||||||
|
void RemoveParent();
|
||||||
void AddTimer(std::string name, float time);
|
void AddTimer(std::string name, float time);
|
||||||
void AddCallbackTimer(float time, std::function<void()> callback);
|
void AddCallbackTimer(float time, std::function<void()> callback);
|
||||||
bool HasTimer(const std::string& name);
|
bool HasTimer(const std::string& name);
|
||||||
|
Loading…
Reference in New Issue
Block a user