Merge remote-tracking branch 'refs/remotes/origin/master' into enet_wip_nothing_to_see_here
This commit is contained in:
commit
2bcdfec476
|
|
@ -47,6 +47,7 @@ namespace Ndk
|
||||||
virtual void OnComponentAttached(BaseComponent& component);
|
virtual void OnComponentAttached(BaseComponent& component);
|
||||||
virtual void OnComponentDetached(BaseComponent& component);
|
virtual void OnComponentDetached(BaseComponent& component);
|
||||||
virtual void OnDetached();
|
virtual void OnDetached();
|
||||||
|
virtual void OnEntityDestruction();
|
||||||
|
|
||||||
void SetEntity(Entity* entity);
|
void SetEntity(Entity* entity);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ namespace Ndk
|
||||||
void OnComponentAttached(BaseComponent& component) override;
|
void OnComponentAttached(BaseComponent& component) override;
|
||||||
void OnComponentDetached(BaseComponent& component) override;
|
void OnComponentDetached(BaseComponent& component) override;
|
||||||
void OnDetached() override;
|
void OnDetached() override;
|
||||||
|
void OnEntityDestruction() override;
|
||||||
|
|
||||||
std::unique_ptr<Nz::RigidBody2D> m_object;
|
std::unique_ptr<Nz::RigidBody2D> m_object;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,7 @@ namespace Ndk
|
||||||
void OnComponentAttached(BaseComponent& component) override;
|
void OnComponentAttached(BaseComponent& component) override;
|
||||||
void OnComponentDetached(BaseComponent& component) override;
|
void OnComponentDetached(BaseComponent& component) override;
|
||||||
void OnDetached() override;
|
void OnDetached() override;
|
||||||
|
void OnEntityDestruction() override;
|
||||||
|
|
||||||
std::unique_ptr<Nz::RigidBody3D> m_object;
|
std::unique_ptr<Nz::RigidBody3D> m_object;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include <Nazara/Core/Bitset.hpp>
|
#include <Nazara/Core/Bitset.hpp>
|
||||||
#include <Nazara/Core/HandledObject.hpp>
|
#include <Nazara/Core/HandledObject.hpp>
|
||||||
|
#include <Nazara/Core/Signal.hpp>
|
||||||
#include <NDK/Algorithm.hpp>
|
#include <NDK/Algorithm.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
@ -65,6 +66,8 @@ namespace Ndk
|
||||||
Entity& operator=(const Entity&) = delete;
|
Entity& operator=(const Entity&) = delete;
|
||||||
Entity& operator=(Entity&&) = delete;
|
Entity& operator=(Entity&&) = delete;
|
||||||
|
|
||||||
|
NazaraSignal(OnEntityDestruction, Entity* /*entity*/);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Entity(World* world, EntityId id);
|
Entity(World* world, EntityId id);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,15 @@ namespace Ndk
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Operation to perform when the entity is destroyed and we're still attached to it
|
||||||
|
*
|
||||||
|
* \remark This is always called before the entity proper destruction, and thus its components.
|
||||||
|
*/
|
||||||
|
void BaseComponent::OnEntityDestruction()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<BaseComponent::ComponentEntry> BaseComponent::s_entries;
|
std::vector<BaseComponent::ComponentEntry> BaseComponent::s_entries;
|
||||||
std::unordered_map<ComponentId, ComponentIndex> BaseComponent::s_idToIndex;
|
std::unordered_map<ComponentId, ComponentIndex> BaseComponent::s_idToIndex;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,5 +88,11 @@ namespace Ndk
|
||||||
m_object.reset();
|
m_object.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PhysicsComponent2D::OnEntityDestruction()
|
||||||
|
{
|
||||||
|
// Kill rigidbody before entity destruction to force contact callbacks to be called while the entity is still valid
|
||||||
|
m_object.reset();
|
||||||
|
}
|
||||||
|
|
||||||
ComponentIndex PhysicsComponent2D::componentIndex;
|
ComponentIndex PhysicsComponent2D::componentIndex;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,5 +88,12 @@ namespace Ndk
|
||||||
m_object.reset();
|
m_object.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PhysicsComponent3D::OnEntityDestruction()
|
||||||
|
{
|
||||||
|
// Kill rigid body before entity destruction to force contact callbacks to be called while the entity is still valid
|
||||||
|
m_object.reset();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
ComponentIndex PhysicsComponent3D::componentIndex;
|
ComponentIndex PhysicsComponent3D::componentIndex;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -145,6 +145,13 @@ namespace Ndk
|
||||||
|
|
||||||
void Entity::Destroy()
|
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();
|
||||||
|
|
||||||
// We alert each system
|
// We alert each system
|
||||||
for (std::size_t index = m_systemBits.FindFirst(); index != m_systemBits.npos; index = m_systemBits.FindNext(index))
|
for (std::size_t index = m_systemBits.FindFirst(); index != m_systemBits.npos; index = m_systemBits.FindNext(index))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue