Sdk/Entity: Add OnEntityDestruction callback

This commit is contained in:
Lynix 2017-03-03 17:52:19 +01:00
parent 605e5c2fd0
commit 3fe54ff777
2 changed files with 6 additions and 0 deletions

View File

@ -9,6 +9,7 @@
#include <Nazara/Core/Bitset.hpp>
#include <Nazara/Core/HandledObject.hpp>
#include <Nazara/Core/Signal.hpp>
#include <NDK/Algorithm.hpp>
#include <memory>
#include <vector>
@ -65,6 +66,8 @@ namespace Ndk
Entity& operator=(const Entity&) = delete;
Entity& operator=(Entity&&) = delete;
NazaraSignal(OnEntityDestruction, Entity* /*entity*/);
private:
Entity(World* world, EntityId id);

View File

@ -145,6 +145,9 @@ namespace Ndk
void Entity::Destroy()
{
OnEntityDestruction(this);
OnEntityDestruction.Clear();
// We prepare components for entity destruction (some components needs this to handle some final callbacks while the entity is still valid)
for (std::size_t i = m_componentBits.FindFirst(); i != m_componentBits.npos; i = m_componentBits.FindNext(i))
m_components[i]->OnEntityDestruction();