#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("World", "[NDK][WORLD]") { GIVEN("A brave new world and the update system") { Ndk::World world; Ndk::BaseSystem& system = world.AddSystem(); WHEN("We had a new entity with an updatable component and a system") { const Ndk::EntityHandle& entity = world.CreateEntity(); UpdatableComponent& component = entity->AddComponent(); THEN("We can get our entity and our system") { const Ndk::EntityHandle& fetchedEntity = world.GetEntity(entity->GetId()); REQUIRE(fetchedEntity->GetWorld() == &world); } THEN("We can clone it") { const Ndk::EntityHandle& clone = world.CloneEntity(entity->GetId()); REQUIRE(world.IsEntityValid(clone)); } } AND_WHEN("We update our world with our entity") { REQUIRE(&world.GetSystem(UpdateSystem::systemIndex) == &world.GetSystem()); Ndk::EntityHandle entity = world.CreateEntity(); UpdatableComponent& component = entity->AddComponent(); THEN("Our entity component must be updated") { world.Update(1.f); REQUIRE(component.IsUpdated()); } THEN("We kill our entity") { REQUIRE(entity->IsValid()); world.KillEntity(entity); world.Update(1.f); REQUIRE(!world.IsEntityValid(entity)); } } } }