#include #include #include namespace { class UpdatableComponent : public Ndk::Component { public: bool IsUpdated() { return m_updated; } void SetUpdated() { m_updated = true; } static Ndk::ComponentIndex componentIndex; private: bool m_updated = false; }; Ndk::ComponentIndex UpdatableComponent::componentIndex; class UpdateSystem : public Ndk::System { public: UpdateSystem() { Requires(); } ~UpdateSystem() = default; static Ndk::SystemIndex systemIndex; private: void OnUpdate(float /*elapsedTime*/) override { for (const Ndk::EntityHandle& entity : GetEntities()) { UpdatableComponent& updatable = entity->GetComponent(); updatable.SetUpdated(); } } }; Ndk::SystemIndex UpdateSystem::systemIndex; } SCENARIO("Entity", "[NDK][ENTITY]") { GIVEN("A world & an entity") { Ndk::World world(false); Ndk::BaseSystem& system = world.AddSystem(); Ndk::EntityHandle entity = world.CreateEntity(); WHEN("We add our UpdateComponent") { UpdatableComponent& updatableComponent = entity->AddComponent(); CHECK(!updatableComponent.IsUpdated()); THEN("Update the world should update the entity's component") { world.Update(1.f); UpdatableComponent& updatableComponentGet = entity->GetComponent(); CHECK(updatableComponentGet.IsUpdated()); } THEN("Update the world should not update the entity's component if it's disabled") { entity->Enable(false); world.Update(1.f); UpdatableComponent& updatableComponentGet = entity->GetComponent(); CHECK(!updatableComponentGet.IsUpdated()); } THEN("We can remove its component") { entity->RemoveComponent(Ndk::GetComponentIndex()); world.Update(1.f); CHECK(!entity->HasComponent()); } } WHEN("We kill our entity") { entity->Kill(); world.Update(1.f); THEN("It's no more valid") { CHECK(!world.IsEntityValid(entity)); } } } }