diff --git a/SDK/include/NDK/Entity.hpp b/SDK/include/NDK/Entity.hpp index 355028fef..3cbe4785c 100644 --- a/SDK/include/NDK/Entity.hpp +++ b/SDK/include/NDK/Entity.hpp @@ -61,6 +61,7 @@ namespace Ndk void Invalidate(); inline bool IsEnabled() const; + bool IsDying() const; inline bool IsValid() const; inline void RemoveAllComponents(); diff --git a/SDK/include/NDK/World.hpp b/SDK/include/NDK/World.hpp index 9b1d4c970..98e6d87ac 100644 --- a/SDK/include/NDK/World.hpp +++ b/SDK/include/NDK/World.hpp @@ -67,6 +67,8 @@ namespace Ndk inline void KillEntity(Entity* entity); inline void KillEntities(const EntityVector& list); + inline bool IsEntityDying(const Entity* entity) const; + inline bool IsEntityDying(EntityId id) const; inline bool IsEntityValid(const Entity* entity) const; inline bool IsEntityIdValid(EntityId id) const; inline bool IsProfilerEnabled() const; diff --git a/SDK/include/NDK/World.inl b/SDK/include/NDK/World.inl index 942ce4d36..860454a0d 100644 --- a/SDK/include/NDK/World.inl +++ b/SDK/include/NDK/World.inl @@ -324,13 +324,34 @@ namespace Ndk KillEntity(entity); } + /*! + * \brief Checks whether or not an entity is dying (has been killed this update) + * \return true If the entity exists and is dying + * + * \param entity Pointer to the entity + */ + inline bool World::IsEntityDying(const Entity* entity) const + { + return entity && IsEntityDying(entity->GetId()); + } + + /*! + * \brief Checks whether or not an entity is dying (has been killed this update) + * \return true If it is the case, false if the entity is alive (and hasn't been killed yet) or if the entity id is invalid + * + * \param id Identifier of the entity + */ + inline bool World::IsEntityDying(EntityId id) const + { + return m_killedEntities.UnboundedTest(id); + } + /*! * \brief Checks whether or not an entity is valid * \return true If it is the case * * \param entity Pointer to the entity */ - inline bool World::IsEntityValid(const Entity* entity) const { return entity && entity->GetWorld() == this && IsEntityIdValid(entity->GetId()); diff --git a/SDK/src/NDK/Entity.cpp b/SDK/src/NDK/Entity.cpp index ffcce07f0..7bc81982d 100644 --- a/SDK/src/NDK/Entity.cpp +++ b/SDK/src/NDK/Entity.cpp @@ -133,13 +133,22 @@ namespace Ndk /*! * \brief Invalidates the entity */ - void Entity::Invalidate() { // We alert everyone that we have been updated m_world->Invalidate(m_id); } + + /*! + * \brief Checks if the entity has been killed this update + * \return True if the entity is currently dying and will be dead at next world refresh + */ + bool Entity::IsDying() const + { + return m_world->IsEntityDying(m_id); + } + /*! * \brief Creates the entity */ diff --git a/tests/SDK/NDK/World.cpp b/tests/SDK/NDK/World.cpp index 4d25db5f6..185717609 100644 --- a/tests/SDK/NDK/World.cpp +++ b/tests/SDK/NDK/World.cpp @@ -100,4 +100,30 @@ SCENARIO("World", "[NDK][WORLD]") } } } -} \ No newline at end of file + + GIVEN("A newly created entity") + { + Ndk::World world(false); + Ndk::EntityHandle entity = world.CreateEntity(); + + REQUIRE(entity.IsValid()); + REQUIRE(entity->IsValid()); + CHECK_FALSE(entity->IsDying()); + + WHEN("We kill it") + { + entity->Kill(); + + CHECK(entity.IsValid()); + CHECK(entity->IsValid()); + CHECK(entity->IsDying()); + + THEN("We refresh the world") + { + world.Refresh(); + + CHECK_FALSE(entity.IsValid()); + } + } + } +}