Remove Graphics module and fix compilation

This commit is contained in:
Jérôme Leclercq
2020-08-27 19:43:31 +02:00
parent bc92d030ed
commit 2a875c8bdc
283 changed files with 16 additions and 32474 deletions

View File

@@ -1,33 +0,0 @@
#include <Nazara/Graphics/Billboard.hpp>
#include <Catch/catch.hpp>
SCENARIO("Billboard", "[GRAPHICS][BILLBOARD]")
{
GIVEN("A default billboard")
{
Nz::Billboard billboard;
WHEN("We assign it to another")
{
Nz::MaterialRef materialRef = Nz::Material::LoadFromFile("resources/Engine/Graphics/Nazara.png");
Nz::Color materialColor = materialRef->GetDiffuseColor();
Nz::BillboardRef otherBillboard = Nz::Billboard::New(materialRef);
billboard = *otherBillboard;
THEN("The old one has the same properties than the new one")
{
REQUIRE(billboard.GetColor() == materialColor);
REQUIRE(billboard.GetMaterial().Get() == materialRef.Get());
REQUIRE(billboard.GetRotation().value == Approx(0.f));
REQUIRE(billboard.GetSize() == Nz::Vector2f(64.f, 64.f)); // Default sizes
}
THEN("We set it with our new material and ask for its real size")
{
billboard.SetMaterial(materialRef, true);
REQUIRE(billboard.GetSize() == Nz::Vector2f(765.f, 212.f)); // Nazara.png sizes
}
}
}
}

View File

@@ -1,20 +0,0 @@
#include <Nazara/Graphics/ColorBackground.hpp>
#include <Catch/catch.hpp>
SCENARIO("ColorBackground", "[GRAPHICS][COLORBACKGROUND]")
{
GIVEN("A default color background")
{
Nz::ColorBackground colorBackground;
WHEN("We assign it a color")
{
colorBackground.SetColor(Nz::Color::Red);
THEN("We can get it")
{
REQUIRE(colorBackground.GetColor() == Nz::Color::Red);
}
}
}
}

View File

@@ -1,29 +0,0 @@
#include <Nazara/Graphics/DeferredRenderTechnique.hpp>
#include <Catch/catch.hpp>
SCENARIO("DeferredRenderTechnique", "[GRAPHICS][DEFERREDRENDERTECHNIQUE]")
{
GIVEN("A default deferred render technique")
{
Nz::DeferredRenderTechnique deferredRenderTechnique;
WHEN("We can disable a pass")
{
REQUIRE(deferredRenderTechnique.IsPassEnabled(Nz::RenderPassType::RenderPassType_AA, 0));
deferredRenderTechnique.EnablePass(Nz::RenderPassType::RenderPassType_AA, 0, false);
THEN("It is disabled")
{
REQUIRE(!deferredRenderTechnique.IsPassEnabled(Nz::RenderPassType::RenderPassType_AA, 0));
}
AND_THEN("We reset it, it is disabled and not the same as the old one")
{
Nz::DeferredRenderPass* oldPass = deferredRenderTechnique.GetPass(Nz::RenderPassType::RenderPassType_AA, 0);
deferredRenderTechnique.ResetPass(Nz::RenderPassType::RenderPassType_AA, 0);
REQUIRE(!deferredRenderTechnique.IsPassEnabled(Nz::RenderPassType::RenderPassType_AA, 0));
REQUIRE(deferredRenderTechnique.GetPass(Nz::RenderPassType::RenderPassType_AA, 0) != oldPass);
}
}
}
}

View File

@@ -1,31 +0,0 @@
#include <Nazara/Graphics/Light.hpp>
#include <Catch/catch.hpp>
SCENARIO("Light", "[GRAPHICS][LIGHT]")
{
GIVEN("Different light")
{
Nz::Light directionalLight(Nz::LightType_Directional);
Nz::Light pointLight(Nz::LightType_Point);
Nz::Light spotLight(Nz::LightType_Spot);
WHEN("We try to cull")
{
Nz::Frustumf frustum;
frustum.Build(90.f, 16.f / 9.f, 1.f, 1000.f, Nz::Vector3f::Zero(), Nz::Vector3f::UnitX());
Nz::Matrix4f Unit3InX = Nz::Matrix4f::Translate(Nz::Vector3f::UnitX() * 3.f);
Nz::Matrix4f rotationTowardsY = Unit3InX * Nz::Matrix4f::Rotate(Nz::EulerAnglesf(Nz::FromDegrees(90.f), 0.f, 0.f).ToQuaternion());
THEN("These results are expected")
{
REQUIRE(directionalLight.Cull(frustum, Unit3InX));
REQUIRE(pointLight.Cull(frustum, Unit3InX));
REQUIRE(!spotLight.Cull(frustum, Unit3InX));
REQUIRE(directionalLight.Cull(frustum, rotationTowardsY));
REQUIRE(pointLight.Cull(frustum, rotationTowardsY));
REQUIRE(!spotLight.Cull(frustum, rotationTowardsY));
}
}
}
}

View File

@@ -1,27 +0,0 @@
#include <Nazara/Graphics/Model.hpp>
#include <Catch/catch.hpp>
SCENARIO("Model", "[GRAPHICS][MODEL]")
{
GIVEN("The standford dragon model")
{
WHEN("We get general informations")
{
THEN("These results are expected")
{
Nz::ModelParameters params;
params.mesh.optimizeIndexBuffers = false;
Nz::ModelRef model = Nz::Model::LoadFromFile("resources/Engine/Graphics/dragon_recon/dragon_vrip_res4.obj", params);
REQUIRE(model);
REQUIRE(model->GetMaterialCount() == 1);
REQUIRE(model->GetSkin() == 0);
REQUIRE(model->GetSkinCount() == 1);
Nz::Material* material = model->GetMaterial(0);
REQUIRE(material->GetAmbientColor() == Nz::Color::Black);
}
}
}
}

View File

@@ -1,29 +0,0 @@
#include <Nazara/Graphics/ParticleDeclaration.hpp>
#include <Catch/catch.hpp>
SCENARIO("ParticleDeclaration", "[GRAPHICS][PARTICLEDECLARATION]")
{
GIVEN("A particle declaration of a model")
{
Nz::ParticleDeclaration* particleDeclaration = Nz::ParticleDeclaration::Get(Nz::ParticleLayout_Model);
WHEN("We disable a component")
{
bool enabled;
Nz::ComponentType type;
std::size_t offset;
particleDeclaration->GetComponent(Nz::ParticleComponent_Position, &enabled, &type, &offset);
REQUIRE(enabled);
std::size_t oldStride = particleDeclaration->GetStride();
particleDeclaration->DisableComponent(Nz::ParticleComponent_Position);
REQUIRE(oldStride != particleDeclaration->GetStride());
THEN("We can enable it and the stride is back")
{
particleDeclaration->EnableComponent(Nz::ParticleComponent_Position, type, offset);
REQUIRE(oldStride == particleDeclaration->GetStride());
}
}
}
}

View File

@@ -1,103 +0,0 @@
#include <Nazara/Graphics/ParticleGroup.hpp>
#include <Catch/catch.hpp>
#include <Nazara/Core/SparsePtr.hpp>
#include <Nazara/Graphics/ParticleMapper.hpp>
class TestParticleController : public Nz::ParticleController
{
public:
// Be aware that the interval is [startId, endId] and NOT [startId, endId)
void Apply(Nz::ParticleGroup& system, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime) override
{
Nz::SparsePtr<Nz::Vector3f> positionPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Position);
Nz::SparsePtr<Nz::Vector3f> velocityPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Velocity);
Nz::SparsePtr<float> lifePtr = mapper.GetComponentPtr<float>(Nz::ParticleComponent_Life);
for (unsigned int i = startId; i <= endId; ++i)
{
Nz::Vector3f& particlePosition = positionPtr[i];
Nz::Vector3f& particleVelocity = velocityPtr[i];
float& particleLife = lifePtr[i];
particleLife -= elapsedTime;
if (particleLife <= 0.f)
system.KillParticle(i);
}
}
};
class TestParticleEmitter : public Nz::ParticleEmitter
{
public:
~TestParticleEmitter() override = default;
void Emit(Nz::ParticleGroup& system, float /*elapsedTime*/) const override
{
system.GenerateParticles(GetEmissionCount());
}
private:
void SetupParticles(Nz::ParticleMapper& /*mapper*/, unsigned int /*count*/) const override
{
}
};
class TestParticleGenerator : public Nz::ParticleGenerator
{
public:
~TestParticleGenerator() override = default;
// Be aware that the interval is [startId, endId] and NOT [startId, endId)
void Generate(Nz::ParticleGroup& /*system*/, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId) override
{
Nz::SparsePtr<Nz::Vector3f> positionPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Position);
Nz::SparsePtr<Nz::Vector3f> velocityPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Velocity);
Nz::SparsePtr<float> lifePtr = mapper.GetComponentPtr<float>(Nz::ParticleComponent_Life);
for (unsigned int i = startId; i <= endId; ++i)
{
Nz::Vector3f& particlePosition = positionPtr[i];
Nz::Vector3f& particleVelocity = velocityPtr[i];
float& particleLife = lifePtr[i];
particlePosition = Nz::Vector3f::Zero();
particleVelocity = Nz::Vector3f::UnitX();
particleLife = 1.3f;
}
}
};
SCENARIO("ParticleGroup", "[GRAPHICS][PARTICLEGROUP]")
{
GIVEN("A particle system of maximum 10 billboards with its generators")
{
// These need to be alive longer than the particle system
TestParticleController particleController;
TestParticleGenerator particleGenerator;
Nz::ParticleGroup particleGroup(10, Nz::ParticleLayout_Billboard);
particleGroup.AddController(&particleController);
TestParticleEmitter particleEmitter;
particleEmitter.SetEmissionCount(10);
particleGroup.AddEmitter(&particleEmitter);
particleGroup.AddGenerator(&particleGenerator);
WHEN("We update to generate 10 particles")
{
particleGroup.Update(1.f);
THEN("There must be 10 particles")
{
REQUIRE(particleGroup.GetParticleCount() == 10);
}
AND_THEN("We update to make them die")
{
particleGroup.Update(2.f);
REQUIRE(particleGroup.GetParticleCount() == 0);
}
}
}
}

View File

@@ -1,47 +0,0 @@
#include <Nazara/Graphics/RenderTechniques.hpp>
#include <Catch/catch.hpp>
#include <Nazara/Graphics/AbstractRenderTechnique.hpp>
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
SCENARIO("RenderTechniques", "[GRAPHICS][RENDERTECHNIQUES]")
{
GIVEN("Nothing")
{
WHEN("We try to get a technique")
{
THEN("We should get it")
{
std::unique_ptr<Nz::AbstractRenderTechnique> forwardByEnum(Nz::RenderTechniques::GetByEnum(Nz::RenderTechniqueType_BasicForward));
REQUIRE(forwardByEnum->GetType() == Nz::RenderTechniqueType_BasicForward);
std::unique_ptr<Nz::AbstractRenderTechnique> forwardByIndex(Nz::RenderTechniques::GetByIndex(1));
REQUIRE(forwardByIndex->GetType() == Nz::RenderTechniqueType_BasicForward);
std::unique_ptr<Nz::AbstractRenderTechnique> forwardByName(Nz::RenderTechniques::GetByName(Nz::RenderTechniques::ToString(Nz::RenderTechniqueType_BasicForward)));
REQUIRE(forwardByName->GetType() == Nz::RenderTechniqueType_BasicForward);
}
THEN("We can register a render technique")
{
unsigned int previousCount = Nz::RenderTechniques::GetCount();
Nz::RenderTechniques::Register("test", 23, []() -> Nz::AbstractRenderTechnique* {
return new Nz::ForwardRenderTechnique;
});
REQUIRE(previousCount < Nz::RenderTechniques::GetCount());
std::unique_ptr<Nz::AbstractRenderTechnique> forwardByRanking(Nz::RenderTechniques::GetByRanking(23));
REQUIRE(forwardByRanking->GetType() == Nz::RenderTechniqueType_BasicForward);
std::unique_ptr<Nz::AbstractRenderTechnique> forwardByName(Nz::RenderTechniques::GetByName("test"));
REQUIRE(forwardByName->GetType() == Nz::RenderTechniqueType_BasicForward);
Nz::RenderTechniques::Unregister("test");
REQUIRE(previousCount == Nz::RenderTechniques::GetCount());
}
}
}
}

View File

@@ -1,25 +0,0 @@
#include <Nazara/Graphics/SkeletalModel.hpp>
#include <Catch/catch.hpp>
SCENARIO("SkeletalModel", "[GRAPHICS][SKELETALMODEL]")
{
GIVEN("A default skeletal model")
{
WHEN("We can load the bob lamp")
{
Nz::AnimationRef animation = Nz::Animation::LoadFromFile("resources/Engine/Graphics/Bob lamp/bob_lamp_update.md5anim");
Nz::SkeletalModelRef skeletalModel = Nz::StaticRefCast<Nz::SkeletalModel>(Nz::SkeletalModel::LoadFromFile("resources/Engine/Graphics/Bob lamp/bob_lamp_update.md5mesh"));
REQUIRE(skeletalModel);
REQUIRE(animation);
skeletalModel->SetAnimation(animation);
THEN("We can enable its animation")
{
REQUIRE(skeletalModel->HasAnimation());
skeletalModel->EnableAnimation(true);
skeletalModel->AdvanceAnimation(0.10f);
REQUIRE(skeletalModel->IsAnimationEnabled());
}
}
}
}

View File

@@ -1,24 +0,0 @@
#include <Nazara/Graphics/SkyboxBackground.hpp>
#include <Catch/catch.hpp>
SCENARIO("SkyboxBackground", "[GRAPHICS][SKYBOXBACKGROUND]")
{
GIVEN("A skybox background with a loaded image")
{
Nz::TextureRef textureRef = Nz::Texture::LoadCubemapFromFile("resources/Engine/Graphics/skybox.png");
Nz::SkyboxBackgroundRef skyboxBackgroundRef = Nz::SkyboxBackground::New(textureRef);
WHEN("We assign it parameters")
{
skyboxBackgroundRef->SetMovementOffset(Nz::Vector3f::Unit());
skyboxBackgroundRef->SetMovementScale(1.f);
THEN("We can get it")
{
REQUIRE(skyboxBackgroundRef->GetMovementOffset() == Nz::Vector3f::Unit());
REQUIRE(skyboxBackgroundRef->GetMovementScale() == Approx(1.f));
REQUIRE(skyboxBackgroundRef->GetTexture().Get() == textureRef.Get());
}
}
}
}

View File

@@ -1,19 +0,0 @@
#include <Nazara/Graphics/TextureBackground.hpp>
#include <Catch/catch.hpp>
SCENARIO("TextureBackground", "[GRAPHICS][TEXTUREBACKGROUND]")
{
GIVEN("A default texture background")
{
Nz::TextureRef textureRef = Nz::Texture::LoadFromFile("resources/Engine/Graphics/skybox.png");
Nz::TextureBackgroundRef textureBackgroundRef = Nz::TextureBackground::New(textureRef);
WHEN("We assign it parameters")
{
THEN("We can get it")
{
REQUIRE(textureBackgroundRef->GetTexture().Get() == textureRef.Get());
}
}
}
}

View File

@@ -1,81 +0,0 @@
#include <Nazara/Graphics/ColorBackground.hpp>
#include <Nazara/Renderer/RenderWindow.hpp>
#include <NazaraSDK/Application.hpp>
#include <NazaraSDK/StateMachine.hpp>
#include <NazaraSDK/World.hpp>
#include <NazaraSDK/Components/CameraComponent.hpp>
#include <NazaraSDK/Components/NodeComponent.hpp>
#include <NazaraSDK/Systems/RenderSystem.hpp>
#include "EventHandler/StateContext.hpp"
#include "EventHandler/StateFactory.hpp"
#include <Catch/catch.hpp>
Ndk::EntityHandle AddCamera(Ndk::World& world, Nz::RenderWindow& window);
/*!
Known issues on Linux:
- There is no real double click event in X11
- Should always the key be repeated in key pressed mode ?
- No smooth wheel, only 1.f or -1.f
- Modify dimension of window updates position (which is not wrong)
- Text entered is never repeated
*/
SCENARIO("EventHandler", "[PLATFORM][EVENTHANDLER][INTERACTIVE][.]")
{
GIVEN("An application")
{
Ndk::Application& app = *Ndk::Application::Instance();
auto& window = app.AddWindow<Nz::RenderWindow>();
if (!window.Create(Nz::VideoMode(1024, 768, 32), "EventHandler"))
{
NazaraError("Failed to create window. See NazaraLog.log for further informations");
REQUIRE(false);
}
window.EnableVerticalSync(true);
auto& world = app.AddWorld();
auto camera = AddCamera(world, window);
StateContext context(window, world);
StateFactory::Initialize(context);
Ndk::StateMachine fsm(StateFactory::Get(EventStatus::Menu));
Nz::Clock elapsedTimeClock;
while (app.Run())
{
window.Display();
float elapsedTime = elapsedTimeClock.Restart() / 1'000'000;
if (!fsm.Update(elapsedTime))
{
NazaraError("Failed to update state machine.");
REQUIRE(false);
}
}
StateFactory::Uninitialize();
REQUIRE(true);
}
}
Ndk::EntityHandle AddCamera(Ndk::World& world, Nz::RenderWindow& window)
{
Ndk::EntityHandle view = world.CreateEntity();
auto& node = view->AddComponent<Ndk::NodeComponent>();
node.SetPosition(Nz::Vector3f::Zero());
auto& cam = view->AddComponent<Ndk::CameraComponent>();
cam.SetProjectionType(Nz::ProjectionType_Orthogonal); // 2D
cam.SetTarget(&window);
world.GetSystem<Ndk::RenderSystem>().SetGlobalUp(Nz::Vector3f::Down());
world.GetSystem<Ndk::RenderSystem>().SetDefaultBackground(Nz::ColorBackground::New(Nz::Color::Black));
return view;
}

View File

@@ -1,39 +0,0 @@
#include "BaseState.hpp"
#include "StateContext.hpp"
#include "StateFactory.hpp"
#include <Nazara/Renderer/RenderWindow.hpp>
#include <NazaraSDK/StateMachine.hpp>
BaseState::BaseState(StateContext& context) :
State(),
m_context(context),
m_text(context)
{
}
BaseState::~BaseState()
{
}
void BaseState::Enter(Ndk::StateMachine& /*fsm*/)
{
m_text.SetVisible(true);
DrawMenu();
}
void BaseState::Leave(Ndk::StateMachine& /*fsm*/)
{
m_text.SetVisible(false);
}
bool BaseState::Update(Ndk::StateMachine& /*fsm*/, float /*elapsedTime*/)
{
return true;
}
void BaseState::DrawMenu()
{
m_text.SetContent("This shouldn't be visible\nM for Menu");
}

View File

@@ -1,31 +0,0 @@
#ifndef BASESTATE_HPP
#define BASESTATE_HPP
#include "Text.hpp"
#include <Nazara/Platform/EventHandler.hpp>
#include <NazaraSDK/State.hpp>
class StateContext;
class BaseState : public Ndk::State
{
public:
BaseState(StateContext& stateContext);
virtual ~BaseState();
virtual void Enter(Ndk::StateMachine& fsm) override;
virtual void Leave(Ndk::StateMachine& fsm) override;
virtual bool Update(Ndk::StateMachine& fsm, float elapsedTime) override;
protected:
virtual void DrawMenu();
StateContext& m_context;
Text m_text;
};
#endif // BASESTATE_HPP

View File

@@ -1,93 +0,0 @@
#include "EventState.hpp"
#include "StateContext.hpp"
#include "StateFactory.hpp"
#include <Nazara/Renderer/RenderWindow.hpp>
#include <NazaraSDK/StateMachine.hpp>
EventState::EventState(StateContext& context) :
BaseState(context),
m_count(0)
{
}
void EventState::Enter(Ndk::StateMachine& fsm)
{
BaseState::Enter(fsm);
Nz::EventHandler& eventHandler = m_context.window.GetEventHandler();
m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key)
{
if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift)
{
fsm.ChangeState(StateFactory::Get(EventStatus::Menu));
}
});
m_eventSlot.Connect(eventHandler.OnEvent, [&] (const Nz::EventHandler*, const Nz::WindowEvent& event)
{
AddEvent(event);
++m_count;
});
}
void EventState::AddEvent(const Nz::WindowEvent& event)
{
if (m_events.size() > 9)
m_events.pop_front();
m_events.push_back(Nz::String::Number(m_count) + " - " + ToString(event));
Nz::String content;
for (auto&& currentEvent : m_events)
{
content += currentEvent + "\n";
}
content += "\nM for Menu";
m_text.SetContent(content, 36);
}
void EventState::DrawMenu()
{
m_text.SetContent("Do whathever you want, this text should change !\nM for Menu");
}
Nz::String EventState::ToString(const Nz::WindowEvent& event) const
{
switch (event.type)
{
case Nz::WindowEventType_GainedFocus:
return "WindowEventType_GainedFocus";
case Nz::WindowEventType_LostFocus:
return "WindowEventType_LostFocus";
case Nz::WindowEventType_KeyPressed:
return "WindowEventType_KeyPressed";
case Nz::WindowEventType_KeyReleased:
return "WindowEventType_KeyReleased";
case Nz::WindowEventType_MouseButtonDoubleClicked:
return "WindowEventType_MouseButtonDoubleClicked";
case Nz::WindowEventType_MouseButtonPressed:
return "WindowEventType_MouseButtonPressed";
case Nz::WindowEventType_MouseButtonReleased:
return "WindowEventType_MouseButtonReleased";
case Nz::WindowEventType_MouseEntered:
return "WindowEventType_MouseEntered";
case Nz::WindowEventType_MouseLeft:
return "WindowEventType_MouseLeft";
case Nz::WindowEventType_MouseMoved:
return "WindowEventType_MouseMoved";
case Nz::WindowEventType_MouseWheelMoved:
return "WindowEventType_MouseWheelMoved";
case Nz::WindowEventType_Moved:
return "WindowEventType_Moved";
case Nz::WindowEventType_Quit:
return "WindowEventType_Quit";
case Nz::WindowEventType_Resized:
return "WindowEventType_Resized";
case Nz::WindowEventType_TextEntered:
return "WindowEventType_TextEntered";
default:
return "Not handled";
}
}

View File

@@ -1,30 +0,0 @@
#ifndef __EVENTSTATE_HPP__
#define __EVENTSTATE_HPP__
#include "BaseState.hpp"
#include <deque>
class StateContext;
class EventState : public BaseState
{
public:
EventState(StateContext& stateContext);
void Enter(Ndk::StateMachine& fsm) override;
private:
void AddEvent(const Nz::WindowEvent& event);
void DrawMenu() override;
Nz::String ToString(const Nz::WindowEvent& event) const;
std::deque<Nz::String> m_events;
int m_count;
NazaraSlot(Nz::EventHandler, OnEvent, m_eventSlot);
NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot);
};
#endif // __EVENTSTATE_HPP__

View File

@@ -1,41 +0,0 @@
#include "FocusState.hpp"
#include "StateContext.hpp"
#include "StateFactory.hpp"
#include <Nazara/Renderer/RenderWindow.hpp>
#include <NazaraSDK/StateMachine.hpp>
FocusState::FocusState(StateContext& context) :
BaseState(context)
{
}
void FocusState::Enter(Ndk::StateMachine& fsm)
{
BaseState::Enter(fsm);
Nz::EventHandler& eventHandler = m_context.window.GetEventHandler();
m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key)
{
if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift)
{
fsm.ChangeState(StateFactory::Get(EventStatus::Menu));
}
});
m_gainedFocusSlot.Connect(eventHandler.OnGainedFocus, [&] (const Nz::EventHandler*)
{
m_text.SetContent("GAINED\nM for Menu");
});
m_lostFocusSlot.Connect(eventHandler.OnLostFocus, [&] (const Nz::EventHandler*)
{
m_text.SetContent("LOST\nM for Menu");
});
}
void FocusState::DrawMenu()
{
m_text.SetContent("Click outside the windows, this text should change !\nM for Menu");
}

View File

@@ -1,23 +0,0 @@
#ifndef __FOCUSSTATE_HPP__
#define __FOCUSSTATE_HPP__
#include "BaseState.hpp"
class StateContext;
class FocusState : public BaseState
{
public:
FocusState(StateContext& stateContext);
void Enter(Ndk::StateMachine& fsm) override;
private:
void DrawMenu() override;
NazaraSlot(Nz::EventHandler, OnGainedFocus, m_gainedFocusSlot);
NazaraSlot(Nz::EventHandler, OnLostFocus, m_lostFocusSlot);
NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot);
};
#endif // __FOCUSSTATE_HPP__

View File

@@ -1,77 +0,0 @@
#include "KeyState.hpp"
#include "StateContext.hpp"
#include "StateFactory.hpp"
#include <Nazara/Renderer/RenderWindow.hpp>
#include <NazaraSDK/StateMachine.hpp>
KeyState::KeyState(StateContext& context) :
BaseState(context),
m_keyStatus(KeyStatus::Pressed)
{
}
void KeyState::Enter(Ndk::StateMachine& fsm)
{
BaseState::Enter(fsm);
Nz::EventHandler& eventHandler = m_context.window.GetEventHandler();
m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key)
{
ManageInput(KeyStatus::Pressed, key, fsm);
});
m_keyReleasedSlot.Connect(eventHandler.OnKeyReleased, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key)
{
ManageInput(KeyStatus::Released, key, fsm);
});
}
void KeyState::DrawMenu()
{
m_text.SetContent("Clic on a key, this text should change !\nN for alternating event\nM for Menu");
}
void KeyState::ManageInput(KeyStatus /*isKeyPressed*/, const Nz::WindowEvent::KeyEvent& key, Ndk::StateMachine& fsm)
{
if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift)
fsm.ChangeState(StateFactory::Get(EventStatus::Menu));
else if (key.virtualKey == Nz::Keyboard::VKey::N && key.shift)
{
if (m_keyStatus == KeyStatus::Pressed)
m_keyStatus = KeyStatus::Released;
else
m_keyStatus = KeyStatus::Pressed;
}
else
{
Nz::String content;
if (m_keyStatus == KeyStatus::Pressed)
content = "Pressed: ";
else
content = "Released: ";
Nz::String keyName = Nz::Keyboard::GetKeyName(key.virtualKey) + " (" + Nz::Keyboard::GetKeyName(key.scancode) + ")";
if (keyName.IsEmpty())
{
m_text.SetContent("Unknown\nM for Menu");
}
else
{
content += keyName;
if (key.alt)
content += " alt";
if (key.control)
content += " control";
if (key.repeated)
content += " repeated";
if (key.shift)
content += " shift";
if (key.system)
content += " system";
m_text.SetContent(content + "\nM for Menu");
}
}
}

View File

@@ -1,31 +0,0 @@
#ifndef __KEYSTATE_HPP__
#define __KEYSTATE_HPP__
#include "BaseState.hpp"
class StateContext;
enum class KeyStatus
{
Pressed,
Released
};
class KeyState : public BaseState
{
public:
KeyState(StateContext& stateContext);
void Enter(Ndk::StateMachine& fsm) override;
private:
void DrawMenu() override;
void ManageInput(KeyStatus isKeyPressed, const Nz::WindowEvent::KeyEvent& key, Ndk::StateMachine& fsm);
KeyStatus m_keyStatus;
NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot);
NazaraSlot(Nz::EventHandler, OnKeyReleased, m_keyReleasedSlot);
};
#endif // __KEYSTATE_HPP__

View File

@@ -1,47 +0,0 @@
#include "MenuState.hpp"
#include "StateContext.hpp"
#include "StateFactory.hpp"
#include <Nazara/Renderer/RenderWindow.hpp>
#include <NazaraSDK/StateMachine.hpp>
MenuState::MenuState(StateContext& context) :
BaseState(context),
m_selectedNextState(-1)
{
}
void MenuState::Enter(Ndk::StateMachine& fsm)
{
BaseState::Enter(fsm);
Nz::EventHandler& eventHandler = m_context.window.GetEventHandler();
m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [this] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key)
{
if (key.virtualKey >= Nz::Keyboard::VKey::A && key.virtualKey < static_cast<Nz::Keyboard::VKey>(static_cast<int>(Nz::Keyboard::VKey::A) + static_cast<int>(EventStatus::Max) - 1))
{
m_selectedNextState = static_cast<int>(key.virtualKey) - static_cast<int>(Nz::Keyboard::VKey::A);
}
});
}
void MenuState::Leave(Ndk::StateMachine& fsm)
{
BaseState::Leave(fsm);
m_selectedNextState = -1;
}
bool MenuState::Update(Ndk::StateMachine& fsm, float /*elapsedTime*/)
{
if (m_selectedNextState != -1) {
fsm.ChangeState(StateFactory::Get(m_selectedNextState + 1));
}
return true;
}
void MenuState::DrawMenu()
{
m_text.SetContent("a. Event\nb. Focus\nc. Key\nd. Mouse click\ne. Mouse enter\nf. Mouse move\ng. Text enter\nh. Window modification");
}

View File

@@ -1,26 +0,0 @@
#ifndef __MENUSTATE_HPP__
#define __MENUSTATE_HPP__
#include "BaseState.hpp"
class StateContext;
class MenuState : public BaseState
{
public:
MenuState(StateContext& stateContext);
void Enter(Ndk::StateMachine& fsm) override;
void Leave(Ndk::StateMachine& fsm) override;
bool Update(Ndk::StateMachine& fsm, float elapsedTime) override;
private:
void DrawMenu() override;
NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot);
int m_selectedNextState;
};
#endif // __MENUSTATE_HPP__

View File

@@ -1,81 +0,0 @@
#include "MouseClickState.hpp"
#include "StateContext.hpp"
#include "StateFactory.hpp"
#include <Nazara/Renderer/RenderWindow.hpp>
#include <NazaraSDK/StateMachine.hpp>
MouseClickState::MouseClickState(StateContext& context) :
BaseState(context)
{
}
void MouseClickState::Enter(Ndk::StateMachine& fsm)
{
BaseState::Enter(fsm);
Nz::EventHandler& eventHandler = m_context.window.GetEventHandler();
m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key)
{
if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift)
{
fsm.ChangeState(StateFactory::Get(EventStatus::Menu));
}
});
m_mouseButtonDoubleClickedSlot.Connect(eventHandler.OnMouseButtonDoubleClicked, [&] (const Nz::EventHandler*, const Nz::WindowEvent::MouseButtonEvent& mouse)
{
ManageInput(MouseStatus::DoubleClick, mouse, fsm);
});
m_mouseButtonPressedSlot.Connect(eventHandler.OnMouseButtonPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::MouseButtonEvent& mouse)
{
ManageInput(MouseStatus::Pressed, mouse, fsm);
});
m_mouseButtonReleasedSlot.Connect(eventHandler.OnMouseButtonReleased, [&] (const Nz::EventHandler*, const Nz::WindowEvent::MouseButtonEvent& mouse)
{
ManageInput(MouseStatus::Released, mouse, fsm);
});
}
void MouseClickState::DrawMenu()
{
m_text.SetContent("Click in the windows, this text should change !\nM for Menu");
}
void MouseClickState::ManageInput(MouseStatus mouseStatus, const Nz::WindowEvent::MouseButtonEvent& mouse, Ndk::StateMachine& /*fsm*/)
{
Nz::String content;
if (mouseStatus == MouseStatus::Pressed)
content = "Pressed: ";
else if (mouseStatus == MouseStatus::Released)
content = "Released: ";
else
content = "Double clicked: ";
switch (mouse.button)
{
case Nz::Mouse::Left:
content += "Left";
break;
case Nz::Mouse::Middle:
content += "Middle";
break;
case Nz::Mouse::Right:
content += "Right";
break;
case Nz::Mouse::XButton1:
content += "XButton1";
break;
case Nz::Mouse::XButton2:
content += "XButton2";
break;
default:
content += "Unknown";
break;
}
m_text.SetContent(content + "\nM for Menu");
}

View File

@@ -1,33 +0,0 @@
#ifndef __MOUSECLICKSTATE_HPP__
#define __MOUSECLICKSTATE_HPP__
#include "BaseState.hpp"
class StateContext;
enum class MouseStatus
{
DoubleClick,
Pressed,
Released
};
class MouseClickState : public BaseState
{
public:
MouseClickState(StateContext& stateContext);
void Enter(Ndk::StateMachine& fsm) override;
private:
void DrawMenu() override;
void ManageInput(MouseStatus mouseStatus, const Nz::WindowEvent::MouseButtonEvent& mouse, Ndk::StateMachine& fsm);
NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot);
NazaraSlot(Nz::EventHandler, OnMouseButtonDoubleClicked, m_mouseButtonDoubleClickedSlot);
NazaraSlot(Nz::EventHandler, OnMouseButtonPressed, m_mouseButtonPressedSlot);
NazaraSlot(Nz::EventHandler, OnMouseButtonReleased, m_mouseButtonReleasedSlot);
};
#endif // __MOUSECLICKSTATE_HPP__

View File

@@ -1,41 +0,0 @@
#include "MouseEnterState.hpp"
#include "StateContext.hpp"
#include "StateFactory.hpp"
#include <Nazara/Renderer/RenderWindow.hpp>
#include <NazaraSDK/StateMachine.hpp>
MouseEnterState::MouseEnterState(StateContext& context) :
BaseState(context)
{
}
void MouseEnterState::Enter(Ndk::StateMachine& fsm)
{
BaseState::Enter(fsm);
Nz::EventHandler& eventHandler = m_context.window.GetEventHandler();
m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key)
{
if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift)
{
fsm.ChangeState(StateFactory::Get(EventStatus::Menu));
}
});
m_mouseEnteredSlot.Connect(eventHandler.OnMouseEntered, [&] (const Nz::EventHandler*)
{
m_text.SetContent("Entered\nM for Menu");
});
m_mouseLeftSlot.Connect(eventHandler.OnMouseLeft, [&] (const Nz::EventHandler*)
{
m_text.SetContent("Left\nM for Menu");
});
}
void MouseEnterState::DrawMenu()
{
m_text.SetContent("Move your mouse outside the windows, this text should change !\nM for Menu");
}

View File

@@ -1,23 +0,0 @@
#ifndef __MOUSEENTERSTATE_HPP__
#define __MOUSEENTERSTATE_HPP__
#include "BaseState.hpp"
class StateContext;
class MouseEnterState : public BaseState
{
public:
MouseEnterState(StateContext& stateContext);
void Enter(Ndk::StateMachine& fsm) override;
private:
void DrawMenu() override;
NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot);
NazaraSlot(Nz::EventHandler, OnMouseEntered, m_mouseEnteredSlot);
NazaraSlot(Nz::EventHandler, OnMouseLeft, m_mouseLeftSlot);
};
#endif // __MOUSEENTERSTATE_HPP__

View File

@@ -1,41 +0,0 @@
#include "MouseMoveState.hpp"
#include "StateContext.hpp"
#include "StateFactory.hpp"
#include <Nazara/Renderer/RenderWindow.hpp>
#include <NazaraSDK/StateMachine.hpp>
MouseMoveState::MouseMoveState(StateContext& context) :
BaseState(context)
{
}
void MouseMoveState::Enter(Ndk::StateMachine& fsm)
{
BaseState::Enter(fsm);
Nz::EventHandler& eventHandler = m_context.window.GetEventHandler();
m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key)
{
if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift)
{
fsm.ChangeState(StateFactory::Get(EventStatus::Menu));
}
});
m_mouseMovedSlot.Connect(eventHandler.OnMouseMoved, [&] (const Nz::EventHandler*, const Nz::WindowEvent::MouseMoveEvent& event)
{
m_text.SetContent("Position(" + Nz::String::Number(event.x) + ", " + Nz::String::Number(event.y) + ") delta: (" + Nz::String::Number(event.deltaX) + ", " + Nz::String::Number(event.deltaY) + ") \nM for Menu");
});
m_mouseWheelMovedSlot.Connect(eventHandler.OnMouseWheelMoved, [&] (const Nz::EventHandler*, const Nz::WindowEvent::MouseWheelEvent& event)
{
m_text.SetContent("Wheel delta: " + Nz::String::Number(event.delta) + "\nM for Menu");
});
}
void MouseMoveState::DrawMenu()
{
m_text.SetContent("Move your mouse or your wheel, this text should change !\nM for Menu");
}

View File

@@ -1,23 +0,0 @@
#ifndef __MOUSEMOVESTATE_HPP__
#define __MOUSEMOVESTATE_HPP__
#include "BaseState.hpp"
class StateContext;
class MouseMoveState : public BaseState
{
public:
MouseMoveState(StateContext& stateContext);
void Enter(Ndk::StateMachine& fsm) override;
private:
void DrawMenu() override;
NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot);
NazaraSlot(Nz::EventHandler, OnMouseMoved, m_mouseMovedSlot);
NazaraSlot(Nz::EventHandler, OnMouseWheelMoved, m_mouseWheelMovedSlot);
};
#endif // __MOUSEMOVESTATE_HPP__

View File

@@ -1,7 +0,0 @@
#include "StateContext.hpp"
StateContext::StateContext(Nz::RenderWindow& windowContext, Ndk::World& worldContext) :
window(windowContext),
world(worldContext)
{
}

View File

@@ -1,23 +0,0 @@
#ifndef __STATECONTEXT_HPP__
#define __STATECONTEXT_HPP__
namespace Ndk
{
class World;
}
namespace Nz
{
class RenderWindow;
}
class StateContext
{
public:
StateContext(Nz::RenderWindow& window, Ndk::World& world);
Nz::RenderWindow& window;
Ndk::World& world;
};
#endif // __STATECONTEXT_HPP__

View File

@@ -1,46 +0,0 @@
#include "StateFactory.hpp"
#include "MenuState.hpp"
#include "EventState.hpp"
#include "FocusState.hpp"
#include "KeyState.hpp"
#include "MouseClickState.hpp"
#include "MouseEnterState.hpp"
#include "MouseMoveState.hpp"
#include "TextEnterState.hpp"
#include "WindowModificationState.hpp"
std::shared_ptr<Ndk::State> StateFactory::Get(EventStatus state)
{
return s_states[state];
}
std::shared_ptr<Ndk::State> StateFactory::Get(unsigned int state)
{
NazaraAssert(state < s_states.size(), "State out of range");
auto it = s_states.begin();
std::advance(it, state);
return it->second;
}
bool StateFactory::Initialize(StateContext& context)
{
s_states.emplace(std::make_pair(EventStatus::Menu, std::make_shared<MenuState>(context)));
s_states.emplace(std::make_pair(EventStatus::Event, std::make_shared<EventState>(context)));
s_states.emplace(std::make_pair(EventStatus::Focus, std::make_shared<FocusState>(context)));
s_states.emplace(std::make_pair(EventStatus::Key, std::make_shared<KeyState>(context)));
s_states.emplace(std::make_pair(EventStatus::MouseClick, std::make_shared<MouseClickState>(context)));
s_states.emplace(std::make_pair(EventStatus::MouseEnter, std::make_shared<MouseEnterState>(context)));
s_states.emplace(std::make_pair(EventStatus::MouseMove, std::make_shared<MouseMoveState>(context)));
s_states.emplace(std::make_pair(EventStatus::TextEnter, std::make_shared<TextEnterState>(context)));
s_states.emplace(std::make_pair(EventStatus::WindowModification, std::make_shared<WindowModificationState>(context)));
return true;
}
void StateFactory::Uninitialize()
{
s_states.clear();
}
std::map<EventStatus, std::shared_ptr<Ndk::State>> StateFactory::s_states;

View File

@@ -1,42 +0,0 @@
#ifndef __STATEFACTORY_HPP__
#define __STATEFACTORY_HPP__
#include <NazaraSDK/State.hpp>
#include <map>
#include <memory>
class StateContext;
enum class EventStatus
{
Min = 0,
Menu,
Event,
Focus,
Key,
MouseClick,
MouseEnter,
MouseMove,
TextEnter,
WindowModification,
Max = WindowModification
};
class StateFactory
{
public:
static std::shared_ptr<Ndk::State> Get(EventStatus state);
static std::shared_ptr<Ndk::State> Get(unsigned int state);
static bool Initialize(StateContext& stateContext);
static void Uninitialize();
private:
static std::map<EventStatus, std::shared_ptr<Ndk::State>> s_states;
};
#endif // __STATEFACTORY_HPP__

View File

@@ -1,35 +0,0 @@
#include "Text.hpp"
#include <Nazara/Renderer/RenderWindow.hpp>
#include <Nazara/Utility/SimpleTextDrawer.hpp>
#include <NazaraSDK/StateMachine.hpp>
#include <NazaraSDK/World.hpp>
#include <NazaraSDK/Components/GraphicsComponent.hpp>
#include <NazaraSDK/Components/NodeComponent.hpp>
Text::Text(StateContext& stateContext) :
m_context(stateContext)
{
m_text = m_context.world.CreateEntity();
m_text->AddComponent<Ndk::NodeComponent>();
Ndk::GraphicsComponent& graphicsComponent = m_text->AddComponent<Ndk::GraphicsComponent>();
m_textSprite = Nz::TextSprite::New();
graphicsComponent.Attach(m_textSprite);
}
Text::~Text()
{
m_textSprite->Clear();
m_text->Kill();
}
void Text::SetContent(const Nz::String& string, unsigned int size)
{
m_textSprite->Update(Nz::SimpleTextDrawer::Draw(string, size));
}
void Text::SetVisible(bool shouldBeVisible)
{
m_text->Enable(shouldBeVisible);
}

View File

@@ -1,23 +0,0 @@
#ifndef __TEXT_HPP__
#define __TEXT_HPP__
#include <Nazara/Graphics/TextSprite.hpp>
#include <NazaraSDK/Entity.hpp>
#include "StateContext.hpp"
class Text
{
public:
Text(StateContext& context);
~Text();
void SetContent(const Nz::String& string, unsigned int size = 36);
void SetVisible(bool shouldBeVisible = true);
private:
StateContext& m_context;
Ndk::EntityHandle m_text;
Nz::TextSpriteRef m_textSprite;
};
#endif // __TEXT_HPP__

View File

@@ -1,39 +0,0 @@
#include "TextEnterState.hpp"
#include "StateContext.hpp"
#include "StateFactory.hpp"
#include <Nazara/Renderer/RenderWindow.hpp>
#include <NazaraSDK/StateMachine.hpp>
TextEnterState::TextEnterState(StateContext& context) :
BaseState(context)
{
}
void TextEnterState::Enter(Ndk::StateMachine& fsm)
{
BaseState::Enter(fsm);
Nz::EventHandler& eventHandler = m_context.window.GetEventHandler();
m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key)
{
if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift)
{
fsm.ChangeState(StateFactory::Get(EventStatus::Menu));
}
});
m_textEnteredSlot.Connect(eventHandler.OnTextEntered, [&] (const Nz::EventHandler*, const Nz::WindowEvent::TextEvent& event)
{
Nz::String content = "Character: " + Nz::String::Unicode(event.character);
if (event.repeated)
content += " repeated";
m_text.SetContent(content + "\nM for Menu");
});
}
void TextEnterState::DrawMenu()
{
m_text.SetContent("Enter some text, this text should change !\nM for Menu");
}

View File

@@ -1,22 +0,0 @@
#ifndef __TEXTENTERSTATE_HPP__
#define __TEXTENTERSTATE_HPP__
#include "BaseState.hpp"
class StateContext;
class TextEnterState : public BaseState
{
public:
TextEnterState(StateContext& stateContext);
void Enter(Ndk::StateMachine& fsm) override;
private:
void DrawMenu() override;
NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot);
NazaraSlot(Nz::EventHandler, OnTextEntered, m_textEnteredSlot);
};
#endif // __TEXTENTERSTATE_HPP__

View File

@@ -1,41 +0,0 @@
#include "WindowModificationState.hpp"
#include "StateContext.hpp"
#include "StateFactory.hpp"
#include <Nazara/Renderer/RenderWindow.hpp>
#include <NazaraSDK/StateMachine.hpp>
WindowModificationState::WindowModificationState(StateContext& context) :
BaseState(context)
{
}
void WindowModificationState::Enter(Ndk::StateMachine& fsm)
{
BaseState::Enter(fsm);
Nz::EventHandler& eventHandler = m_context.window.GetEventHandler();
m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key)
{
if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift)
{
fsm.ChangeState(StateFactory::Get(EventStatus::Menu));
}
});
m_movedSlot.Connect(eventHandler.OnMoved, [&] (const Nz::EventHandler*, const Nz::WindowEvent::PositionEvent& event)
{
m_text.SetContent("Position(" + Nz::String::Number(event.x) + ", " + Nz::String::Number(event.y) + ")\nM for Menu");
});
m_resizedSlot.Connect(eventHandler.OnResized, [&] (const Nz::EventHandler*, const Nz::WindowEvent::SizeEvent& event)
{
m_text.SetContent("Size(" + Nz::String::Number(event.width) + ", " + Nz::String::Number(event.height) + ")\nM for Menu");
});
}
void WindowModificationState::DrawMenu()
{
m_text.SetContent("Move the window or resize it, this text should change !\nM for Menu");
}

View File

@@ -1,23 +0,0 @@
#ifndef __WINDOWMODIFICATIONSTATE_HPP__
#define __WINDOWMODIFICATIONSTATE_HPP__
#include "BaseState.hpp"
class StateContext;
class WindowModificationState : public BaseState
{
public:
WindowModificationState(StateContext& stateContext);
void Enter(Ndk::StateMachine& fsm) override;
private:
void DrawMenu() override;
NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot);
NazaraSlot(Nz::EventHandler, OnMoved, m_movedSlot);
NazaraSlot(Nz::EventHandler, OnResized, m_resizedSlot);
};
#endif // __WINDOWMODIFICATIONSTATE_HPP__

View File

@@ -1,119 +0,0 @@
#include <NazaraSDK/Systems/RenderSystem.hpp>
#include <NazaraSDK/World.hpp>
#include <NazaraSDK/Components.hpp>
#include <NazaraSDK/Systems/PhysicsSystem2D.hpp>
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
#include <Nazara/Graphics/Sprite.hpp>
#include <Catch/catch.hpp>
void CompareAABB(const Nz::Rectf& aabb, const Nz::Boxf& box);
SCENARIO("RenderSystem", "[NDK][RenderSystem]")
{
GIVEN("A world with a camera, a drawable, a light and some particles")
{
Ndk::World world;
const Ndk::EntityHandle& cameraEntity = world.CreateEntity();
Ndk::CameraComponent& cameraComponentCamera = cameraEntity->AddComponent<Ndk::CameraComponent>();
Ndk::NodeComponent& nodeComponentCamera = cameraEntity->AddComponent<Ndk::NodeComponent>();
const Ndk::EntityHandle& drawableEntity = world.CreateEntity();
Ndk::GraphicsComponent& graphicsComponentDrawable = drawableEntity->AddComponent<Ndk::GraphicsComponent>();
Nz::SpriteRef sprite = Nz::Sprite::New();
graphicsComponentDrawable.Attach(sprite);
Ndk::NodeComponent& nodeComponentDrawable = drawableEntity->AddComponent<Ndk::NodeComponent>();
const Ndk::EntityHandle& lightEntity = world.CreateEntity();
Ndk::LightComponent& lightComponentLight = lightEntity->AddComponent<Ndk::LightComponent>();
Ndk::NodeComponent& nodeComponentLight = lightEntity->AddComponent<Ndk::NodeComponent>();
const Ndk::EntityHandle& particlesEntity = world.CreateEntity();
Ndk::ParticleGroupComponent& particleGroupComponentParticles = particlesEntity->AddComponent<Ndk::ParticleGroupComponent>(1, Nz::ParticleLayout_Sprite);
WHEN("We change the render technique to ForwardRenderTechnique")
{
Ndk::RenderSystem& renderSystem = world.GetSystem<Ndk::RenderSystem>();
renderSystem.ChangeRenderTechnique<Nz::ForwardRenderTechnique>();
THEN("The render system should be ForwardRenderTechnique")
{
REQUIRE(renderSystem.GetRenderTechnique().GetType() == Nz::RenderTechniqueType_BasicForward);
}
}
}
GIVEN("A world with 2D coordinates (upper-left) and an entity with graphics and physics")
{
Ndk::World world;
world.GetSystem<Ndk::RenderSystem>().SetGlobalUp(Nz::Vector3f::Down());
const Ndk::EntityHandle& entity = world.CreateEntity();
Nz::Vector2f position(3.f, 4.f);
Ndk::NodeComponent& nodeComponent = entity->AddComponent<Ndk::NodeComponent>();
nodeComponent.SetPosition(position);
Nz::Vector2f dimensions(1.f, 2.f);
Ndk::GraphicsComponent& graphicsComponent = entity->AddComponent<Ndk::GraphicsComponent>();
Nz::SpriteRef sprite = Nz::Sprite::New();
sprite->SetSize(dimensions);
graphicsComponent.Attach(sprite);
Nz::Rectf aabb(Nz::Vector2f::Zero(), dimensions);
Nz::BoxCollider2DRef boxCollider2D = Nz::BoxCollider2D::New(aabb);
entity->AddComponent<Ndk::CollisionComponent2D>(boxCollider2D);
Ndk::PhysicsComponent2D& physicsComponent2D = entity->AddComponent<Ndk::PhysicsComponent2D>();
world.GetSystem<Ndk::PhysicsSystem2D>().SetFixedUpdateRate(30.f);
world.Update(1.f);
WHEN("We move it")
{
Nz::Vector2f velocity = Nz::Vector2f::UnitY();
physicsComponent2D.SetVelocity(velocity);
world.Update(1.f);
THEN("Graphics and physics should be synchronised")
{
CHECK(nodeComponent.GetPosition() == position + velocity);
CHECK(physicsComponent2D.GetAABB() == aabb.Translate(position + velocity));
CompareAABB(physicsComponent2D.GetAABB(), graphicsComponent.GetAABB());
}
}
WHEN("We set an angular velocity")
{
Nz::RadianAnglef angularSpeed = Nz::RadianAnglef::FromDegrees(90.f);
physicsComponent2D.SetAngularVelocity(angularSpeed);
world.Update(1.f);
THEN("We expect those to be true")
{
CHECK(physicsComponent2D.GetAngularVelocity() == angularSpeed);
CHECK(physicsComponent2D.GetRotation() == angularSpeed);
CHECK(physicsComponent2D.GetAABB() == Nz::Rectf(2.5f, 4.5f, 2.f, 1.f));
CompareAABB(physicsComponent2D.GetAABB(), graphicsComponent.GetAABB());
world.Update(1.f);
CHECK(physicsComponent2D.GetRotation() == 2.f * angularSpeed);
CHECK(physicsComponent2D.GetAABB() == Nz::Rectf(3.f, 4.0f, 1.f, 2.f));
CompareAABB(physicsComponent2D.GetAABB(), graphicsComponent.GetAABB());
world.Update(1.f);
CHECK(physicsComponent2D.GetRotation() == 3.f * angularSpeed);
CHECK(physicsComponent2D.GetAABB() == Nz::Rectf(2.5f, 4.5f, 2.f, 1.f));
CompareAABB(physicsComponent2D.GetAABB(), graphicsComponent.GetAABB());
world.Update(1.f);
CHECK(physicsComponent2D.GetRotation() == 4.f * angularSpeed);
}
}
}
}
void CompareAABB(const Nz::Rectf& aabb, const Nz::Boxf& box)
{
CHECK(aabb.x == Approx(box.x));
CHECK(aabb.y == Approx(box.y));
CHECK(aabb.width == Approx(box.width));
CHECK(aabb.height == Approx(box.height));
}