Documentation for module 'NDK'
Former-commit-id: 63e1cac538c577a1f1aafa71fa7eef69a6d4daab [formerly b2d8769fd02a0e7d9c476d4ad7be1988a1fd6789] [formerly 636b5cb79bcb8da44d9aa45ba1023565bcf29f0d [formerly a2361ec2b8679d4d4ba096e543b5d4b91825dd62]] Former-commit-id: d402d35477f9db0135c553d55c401939426bf62d [formerly 607336ea0f42731e4604f3a8c2df06f3aecfc401] Former-commit-id: 69e23cd6c06723486de5e4641ce810012dac66da
This commit is contained in:
103
tests/SDK/NDK/World.cpp
Normal file
103
tests/SDK/NDK/World.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
#include <NDK/World.hpp>
|
||||
#include <NDK/Component.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
class UpdatableComponent : public Ndk::Component<UpdatableComponent>
|
||||
{
|
||||
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<UpdateSystem>
|
||||
{
|
||||
public:
|
||||
UpdateSystem()
|
||||
{
|
||||
Requires<UpdatableComponent>();
|
||||
}
|
||||
|
||||
~UpdateSystem() = default;
|
||||
|
||||
static Ndk::SystemIndex systemIndex;
|
||||
|
||||
private:
|
||||
void OnUpdate(float elapsedTime) override
|
||||
{
|
||||
for (const Ndk::EntityHandle& entity : GetEntities())
|
||||
{
|
||||
UpdatableComponent& updatable = entity->GetComponent<UpdatableComponent>();
|
||||
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<UpdateSystem>();
|
||||
|
||||
WHEN("We had a new entity with an updatable component and a system")
|
||||
{
|
||||
const Ndk::EntityHandle& entity = world.CreateEntity();
|
||||
UpdatableComponent& component = entity->AddComponent<UpdatableComponent>();
|
||||
|
||||
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<UpdateSystem>());
|
||||
const Ndk::EntityHandle& entity = world.CreateEntity();
|
||||
UpdatableComponent& component = entity->AddComponent<UpdatableComponent>();
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user