Documentation for module 'NDK'

Former-commit-id: a6c2075cfbfd0eccf2b77def71c0d42684bed590 [formerly 36ece2bc6a148bde6cacf45084821d20edcd115e] [formerly 4a6988792ec026e65be6850c46dfe8ddda92a885 [formerly fd3f4f975de5c427f3adc98b220446fd255be396]]
Former-commit-id: c87fdc9483202842267c60eff3d619f0df2963bf [formerly ee35202f1b2df7ca20da5b6d8b13147f2b92c933]
Former-commit-id: dad5de1b00bb4413f7aa191ca06b7d43b659f32a
This commit is contained in:
Gawaboumga
2016-08-21 13:48:52 +02:00
parent 1e219ef819
commit 95689f46fb
75 changed files with 3374 additions and 112 deletions

103
tests/SDK/NDK/World.cpp Normal file
View 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));
}
}
}
}