Merge remote-tracking branch 'refs/remotes/origin/master' into gui

Former-commit-id: 631344e1f2517a511f0b3b877acc4e80a68c3ce5 [formerly 515910f81b988b3ff9df081d639fffd8df04bb7d] [formerly 6781a775127039b7e3fcd0f44d5fbde308dd17c4 [formerly 4690ef3819e0268f4aa8abf68e9b87fa3de4b15b]]
Former-commit-id: 9a89f053586566ee22cedfcea9c8a187256f4fc1 [formerly 67ec1747da393f855ba509fc21636bb3d91cb599]
Former-commit-id: 41f11195fa21427aa5e834f945b4d47509089c30
This commit is contained in:
Lynix
2016-08-09 13:58:57 +02:00
454 changed files with 20694 additions and 6292 deletions

View File

@@ -33,6 +33,10 @@ namespace Ndk
bool Run();
#ifndef NDK_SERVER
inline void MakeExitOnLastWindowClosed(bool exitOnClosedWindows);
#endif
inline void Quit();
Application& operator=(const Application&) = delete;

View File

@@ -61,6 +61,13 @@ namespace Ndk
return m_updateTime;
}
#ifndef NDK_SERVER
inline void Application::MakeExitOnLastWindowClosed(bool exitOnClosedWindows)
{
m_exitOnClosedWindows = exitOnClosedWindows;
}
#endif
inline void Application::Quit()
{
m_shouldQuit = true;

View File

@@ -26,7 +26,7 @@ namespace Ndk
inline ComponentIndex BaseComponent::RegisterComponent(ComponentId id, Factory factoryFunc)
{
// Nous allons rajouter notre composant à la fin
ComponentIndex index = s_entries.size();
ComponentIndex index = static_cast<ComponentIndex>(s_entries.size());
s_entries.resize(index + 1);
// On récupère et on affecte

View File

@@ -28,13 +28,11 @@ namespace Ndk
template<typename ComponentType>
ComponentIndex Component<ComponentType>::RegisterComponent(ComponentId id)
{
// Il faut que notre composant possède un constructeur par défaut (pour la factory)
static_assert(std::is_default_constructible<ComponentType>::value, "ComponentType must be default-constructible");
// On utilise les lambda pour créer une fonction factory
auto factory = []() -> BaseComponent*
{
return new ComponentType;
return nullptr; //< Temporary workaround to allow non-default-constructed components, will be updated for serialization
//return new ComponentType;
};
return BaseComponent::RegisterComponent(id, factory);

View File

@@ -1,20 +1,19 @@
// This file was automatically generated on 03 Mar 2016 at 14:09:12
// This file was automatically generated on 30 Jul 2016 at 15:29:16
#pragma once
#ifndef NDK_COMPONENTS_GLOBAL_HPP
#define NDK_COMPONENTS_GLOBAL_HPP
#include <NDK/Components/CollisionComponent.hpp>
#include <NDK/Components/NodeComponent.hpp>
#include <NDK/Components/PhysicsComponent.hpp>
#include <NDK/Components/VelocityComponent.hpp>
#ifndef NDK_SERVER
#include <NDK/Components/CameraComponent.hpp>
#include <NDK/Components/CollisionComponent.hpp>
#include <NDK/Components/GraphicsComponent.hpp>
#include <NDK/Components/LightComponent.hpp>
#include <NDK/Components/ListenerComponent.hpp>
#endif
#include <NDK/Components/NodeComponent.hpp>
#include <NDK/Components/ParticleEmitterComponent.hpp>
#include <NDK/Components/ParticleGroupComponent.hpp>
#include <NDK/Components/PhysicsComponent.hpp>
#include <NDK/Components/VelocityComponent.hpp>
#endif // NDK_COMPONENTS_GLOBAL_HPP

View File

@@ -4,6 +4,7 @@
#pragma once
#ifndef NDK_SERVER
#ifndef NDK_COMPONENTS_CAMERACOMPONENT_HPP
#define NDK_COMPONENTS_CAMERACOMPONENT_HPP
@@ -108,3 +109,4 @@ namespace Ndk
#include <NDK/Components/CameraComponent.inl>
#endif // NDK_COMPONENTS_CAMERACOMPONENT_HPP
#endif // NDK_SERVER

View File

@@ -2,17 +2,17 @@
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <NDK/Components/CameraComponent.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Math/Algorithm.hpp>
#include "CameraComponent.hpp"
namespace Ndk
{
inline CameraComponent::CameraComponent() :
m_projectionType(Nz::ProjectionType_Perspective),
m_targetRegion(0.f, 0.f, 1.f, 1.f),
m_size(0.f),
m_target(nullptr),
m_size(0.f),
m_frustumUpdated(false),
m_projectionMatrixUpdated(false),
m_viewMatrixUpdated(false),
@@ -30,8 +30,8 @@ namespace Ndk
AbstractViewer(camera),
m_projectionType(camera.m_projectionType),
m_targetRegion(camera.m_targetRegion),
m_size(camera.m_size),
m_target(nullptr),
m_size(camera.m_size),
m_frustumUpdated(false),
m_projectionMatrixUpdated(false),
m_viewMatrixUpdated(false),

View File

@@ -4,6 +4,7 @@
#pragma once
#ifndef NDK_SERVER
#ifndef NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP
#define NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP
@@ -22,6 +23,8 @@ namespace Ndk
friend class RenderSystem;
public:
using RenderableList = std::vector<Nz::InstancedRenderableRef>;
GraphicsComponent() = default;
inline GraphicsComponent(const GraphicsComponent& graphicsComponent);
~GraphicsComponent() = default;
@@ -30,16 +33,23 @@ namespace Ndk
inline void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0);
inline void Clear();
inline void Detach(const Nz::InstancedRenderableRef& renderable);
inline void EnsureBoundingVolumeUpdate() const;
inline void EnsureTransformMatrixUpdate() const;
inline void GetAttachedRenderables(RenderableList* renderables) const;
inline std::size_t GetAttachedRenderableCount() const;
inline const Nz::BoundingVolumef& GetBoundingVolume() const;
static ComponentIndex componentIndex;
private:
inline void InvalidateBoundingVolume();
void InvalidateRenderableData(const Nz::InstancedRenderable* renderable, Nz::UInt32 flags, unsigned int index);
void InvalidateRenderableData(const Nz::InstancedRenderable* renderable, Nz::UInt32 flags, std::size_t index);
inline void InvalidateRenderables();
inline void InvalidateTransformMatrix();
@@ -56,12 +66,28 @@ namespace Ndk
struct Renderable
{
Renderable(Nz::Matrix4f& transformMatrix) :
Renderable(const Nz::Matrix4f& transformMatrix) :
data(transformMatrix),
dataUpdated(false)
{
}
Renderable(Renderable&& renderable) noexcept :
data(std::move(renderable.data)),
renderable(std::move(renderable.renderable)),
dataUpdated(renderable.dataUpdated)
{
}
Renderable& operator=(Renderable&& r) noexcept
{
data = std::move(r.data);
dataUpdated = r.dataUpdated;
renderable = std::move(r.renderable);
return *this;
}
NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableInvalidateData, renderableInvalidationSlot);
mutable Nz::InstancedRenderable::InstanceData data;
@@ -80,3 +106,4 @@ namespace Ndk
#include <NDK/Components/GraphicsComponent.inl>
#endif // NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP
#endif // NDK_SERVER

View File

@@ -3,11 +3,13 @@
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <algorithm>
#include "GraphicsComponent.hpp"
namespace Ndk
{
inline GraphicsComponent::GraphicsComponent(const GraphicsComponent& graphicsComponent) :
Component(graphicsComponent),
HandledObject(graphicsComponent),
m_boundingVolume(graphicsComponent.m_boundingVolume),
m_transformMatrix(graphicsComponent.m_transformMatrix),
m_boundingVolumeUpdated(graphicsComponent.m_boundingVolumeUpdated),
@@ -41,10 +43,30 @@ namespace Ndk
r.data.renderOrder = renderOrder;
r.renderable = std::move(renderable);
r.renderableInvalidationSlot.Connect(r.renderable->OnInstancedRenderableInvalidateData, std::bind(&GraphicsComponent::InvalidateRenderableData, this, std::placeholders::_1, std::placeholders::_2, m_renderables.size()-1));
InvalidateBoundingVolume();
}
inline void GraphicsComponent::Clear()
{
m_renderables.clear();
InvalidateBoundingVolume();
}
inline void GraphicsComponent::Detach(const Nz::InstancedRenderableRef& renderable)
{
for (auto it = m_renderables.begin(); it != m_renderables.end(); ++it)
{
if (it->renderable == renderable)
{
InvalidateBoundingVolume();
m_renderables.erase(it);
break;
}
}
}
inline void GraphicsComponent::EnsureBoundingVolumeUpdate() const
{
if (!m_boundingVolumeUpdated)
@@ -57,6 +79,20 @@ namespace Ndk
UpdateTransformMatrix();
}
inline void GraphicsComponent::GetAttachedRenderables(RenderableList* renderables) const
{
NazaraAssert(renderables, "Invalid renderable list");
renderables->reserve(renderables->size() + m_renderables.size());
for (const Renderable& r : m_renderables)
renderables->push_back(r.renderable);
}
inline std::size_t GraphicsComponent::GetAttachedRenderableCount() const
{
return m_renderables.size();
}
inline const Nz::BoundingVolumef& GraphicsComponent::GetBoundingVolume() const
{
EnsureBoundingVolumeUpdate();

View File

@@ -4,6 +4,7 @@
#pragma once
#ifndef NDK_SERVER
#ifndef NDK_COMPONENTS_LIGHTCOMPONENT_HPP
#define NDK_COMPONENTS_LIGHTCOMPONENT_HPP
@@ -28,3 +29,4 @@ namespace Ndk
#include <NDK/Components/LightComponent.inl>
#endif // NDK_COMPONENTS_LIGHTCOMPONENT_HPP
#endif // NDK_SERVER

View File

@@ -4,6 +4,7 @@
#pragma once
#ifndef NDK_SERVER
#ifndef NDK_COMPONENTS_LISTENERCOMPONENT_HPP
#define NDK_COMPONENTS_LISTENERCOMPONENT_HPP
@@ -14,11 +15,11 @@ namespace Ndk
class NDK_API ListenerComponent : public Component<ListenerComponent>
{
public:
ListenerComponent();
inline ListenerComponent();
~ListenerComponent() = default;
bool IsActive() const;
void SetActive(bool active = true);
inline bool IsActive() const;
inline void SetActive(bool active = true);
static ComponentIndex componentIndex;
@@ -30,3 +31,4 @@ namespace Ndk
#include <NDK/Components/ListenerComponent.inl>
#endif // NDK_COMPONENTS_LISTENERCOMPONENT_HPP
#endif // NDK_SERVER

View File

@@ -0,0 +1,46 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#pragma once
#ifndef NDK_SERVER
#ifndef NDK_COMPONENTS_PARTICLEEMITTERCOMPONENT_HPP
#define NDK_COMPONENTS_PARTICLEEMITTERCOMPONENT_HPP
#include <Nazara/Graphics/ParticleEmitter.hpp>
#include <Nazara/Graphics/ParticleGroup.hpp>
#include <NDK/Component.hpp>
namespace Ndk
{
class NDK_API ParticleEmitterComponent : public Component<ParticleEmitterComponent>, public Nz::ParticleEmitter
{
public:
using SetupFunc = std::function<void(const EntityHandle& /*entity*/, Nz::ParticleMapper& /*mapper*/, unsigned int /*count*/)>;
inline ParticleEmitterComponent();
ParticleEmitterComponent(const ParticleEmitterComponent& emitter) = default;
ParticleEmitterComponent(ParticleEmitterComponent&& emitter) = default;
~ParticleEmitterComponent() = default;
void Enable(bool active = true);
inline bool IsActive() const;
inline void SetSetupFunc(SetupFunc func);
static ComponentIndex componentIndex;
private:
void SetupParticles(Nz::ParticleMapper& mapper, unsigned int count) const override;
SetupFunc m_setupFunc;
bool m_isActive;
};
}
#include <NDK/Components/ParticleEmitterComponent.inl>
#endif // NDK_COMPONENTS_PARTICLEEMITTERCOMPONENT_HPP
#endif // NDK_SERVER

View File

@@ -0,0 +1,28 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <NDK/Components/ParticleEmitterComponent.hpp>
namespace Ndk
{
inline ParticleEmitterComponent::ParticleEmitterComponent() :
m_isActive(true)
{
}
inline void Ndk::ParticleEmitterComponent::Enable(bool active)
{
m_isActive = active;
}
inline bool ParticleEmitterComponent::IsActive() const
{
return m_isActive;
}
inline void Ndk::ParticleEmitterComponent::SetSetupFunc(SetupFunc func)
{
m_setupFunc = std::move(func);
}
}

View File

@@ -0,0 +1,35 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#pragma once
#ifndef NDK_SERVER
#ifndef NDK_COMPONENTS_PARTICLEGROUPCOMPONENT_HPP
#define NDK_COMPONENTS_PARTICLEGROUPCOMPONENT_HPP
#include <Nazara/Graphics/ParticleGroup.hpp>
#include <NDK/Component.hpp>
namespace Ndk
{
class ParticleGroupComponent;
using ParticleGroupComponentHandle = Nz::ObjectHandle<ParticleGroupComponent>;
class NDK_API ParticleGroupComponent : public Component<ParticleGroupComponent>, public Nz::ParticleGroup
{
public:
inline ParticleGroupComponent(unsigned int maxParticleCount, Nz::ParticleLayout layout);
inline ParticleGroupComponent(unsigned int maxParticleCount, Nz::ParticleDeclarationConstRef declaration);
ParticleGroupComponent(const ParticleGroupComponent&) = default;
~ParticleGroupComponent() = default;
static ComponentIndex componentIndex;
};
}
#include <NDK/Components/ParticleGroupComponent.inl>
#endif // NDK_COMPONENTS_PARTICLEGROUPCOMPONENT_HPP
#endif // NDK_SERVER

View File

@@ -0,0 +1,17 @@
#include "ParticleGroupComponent.hpp"
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
namespace Ndk
{
inline ParticleGroupComponent::ParticleGroupComponent(unsigned int maxParticleCount, Nz::ParticleLayout layout) :
ParticleGroup(maxParticleCount, layout)
{
}
inline ParticleGroupComponent::ParticleGroupComponent(unsigned int maxParticleCount, Nz::ParticleDeclarationConstRef declaration) :
ParticleGroup(maxParticleCount, std::move(declaration))
{
}
}

View File

@@ -84,8 +84,12 @@ namespace Nz
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, FontParams* params, TypeTag<FontParams>)
{
NazaraUnused(params);
instance.CheckType(index, Nz::LuaType_Table);
// Structure is empty for now
return 1;
}
@@ -96,8 +100,8 @@ namespace Nz
params->animated = instance.CheckField<bool>("Animated", params->animated);
params->center = instance.CheckField<bool>("Center", params->center);
params->flipUVs = instance.CheckField<bool>("FlipUVs", params->flipUVs);
//params->matrix = instance.CheckField<Matrix4f>("Matrix", params->matrix);
params->optimizeIndexBuffers = instance.CheckField<bool>("OptimizeIndexBuffers", params->optimizeIndexBuffers);
params->scale = instance.CheckField<Vector3f>("Scale", params->scale);
return 1;
}
@@ -255,14 +259,14 @@ namespace Nz
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Ndk::EntityHandle* handle, TypeTag<Ndk::EntityHandle>)
{
*handle = std::move(*static_cast<Ndk::EntityHandle*>(instance.CheckUserdata(index, "Entity")));
*handle = *static_cast<Ndk::EntityHandle*>(instance.CheckUserdata(index, "Entity"));
return 1;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Ndk::WorldHandle* handle, TypeTag<Ndk::WorldHandle>)
{
*handle = std::move(*static_cast<Ndk::WorldHandle*>(instance.CheckUserdata(index, "World")));
*handle = *static_cast<Ndk::WorldHandle*>(instance.CheckUserdata(index, "World"));
return 1;
}

View File

@@ -13,11 +13,11 @@ namespace Ndk
{
class StateMachine;
class State
class NDK_API State
{
public:
State() = default;
~State() = default;
virtual ~State();
virtual void Enter(StateMachine& fsm) = 0;
virtual void Leave(StateMachine& fsm) = 0;

View File

@@ -23,6 +23,8 @@ namespace Ndk
inline void ChangeState(std::shared_ptr<State> state);
inline const std::shared_ptr<State>& GetCurrentState() const;
inline bool Update(float elapsedTime);
inline StateMachine& operator=(StateMachine&& fsm) = default;

View File

@@ -26,6 +26,11 @@ namespace Ndk
m_nextState = std::move(state);
}
inline const std::shared_ptr<State>& StateMachine::GetCurrentState() const
{
return m_currentState;
}
inline bool StateMachine::Update(float elapsedTime)
{
if (m_nextState)

View File

@@ -1,16 +1,14 @@
// This file was automatically generated on 03 Mar 2016 at 14:09:12
// This file was automatically generated on 30 Jul 2016 at 15:29:16
#pragma once
#ifndef NDK_SYSTEMS_GLOBAL_HPP
#define NDK_SYSTEMS_GLOBAL_HPP
#include <NDK/Systems/ListenerSystem.hpp>
#include <NDK/Systems/ParticleSystem.hpp>
#include <NDK/Systems/PhysicsSystem.hpp>
#include <NDK/Systems/RenderSystem.hpp>
#include <NDK/Systems/VelocitySystem.hpp>
#ifndef NDK_SERVER
#include <NDK/Systems/ListenerSystem.hpp>
#include <NDK/Systems/RenderSystem.hpp>
#endif
#endif // NDK_SYSTEMS_GLOBAL_HPP

View File

@@ -4,6 +4,7 @@
#pragma once
#ifndef NDK_SERVER
#ifndef NDK_SYSTEMS_LISTENERSYSTEM_HPP
#define NDK_SYSTEMS_LISTENERSYSTEM_HPP
@@ -27,3 +28,4 @@ namespace Ndk
#include <NDK/Systems/ListenerSystem.inl>
#endif // NDK_SYSTEMS_LISTENERSYSTEM_HPP
#endif // NDK_SERVER

View File

@@ -0,0 +1,29 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#pragma once
#ifndef NDK_SYSTEMS_PARTICLESYSTEM_HPP
#define NDK_SYSTEMS_PARTICLESYSTEM_HPP
#include <NDK/System.hpp>
namespace Ndk
{
class NDK_API ParticleSystem : public System<ParticleSystem>
{
public:
ParticleSystem();
~ParticleSystem() = default;
static SystemIndex systemIndex;
private:
void OnUpdate(float elapsedTime) override;
};
}
#include <NDK/Systems/ParticleSystem.inl>
#endif // NDK_SYSTEMS_PARTICLESYSTEM_HPP

View File

@@ -0,0 +1,3 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@@ -4,11 +4,14 @@
#pragma once
#ifndef NDK_SERVER
#ifndef NDK_SYSTEMS_RENDERSYSTEM_HPP
#define NDK_SYSTEMS_RENDERSYSTEM_HPP
#include <Nazara/Graphics/AbstractBackground.hpp>
#include <Nazara/Graphics/DeferredRenderTechnique.hpp>
#include <Nazara/Graphics/DepthRenderTechnique.hpp>
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
#include <Nazara/Renderer/RenderTexture.hpp>
#include <NDK/EntityList.hpp>
#include <NDK/System.hpp>
#include <unordered_map>
@@ -48,13 +51,20 @@ namespace Ndk
void OnEntityRemoved(Entity* entity) override;
void OnEntityValidation(Entity* entity, bool justAdded) override;
void OnUpdate(float elapsedTime) override;
void UpdateDirectionalShadowMaps(const Nz::AbstractViewer& viewer);
void UpdatePointSpotShadowMaps();
std::unique_ptr<Nz::AbstractRenderTechnique> m_renderTechnique;
EntityList m_cameras;
EntityList m_drawables;
EntityList m_directionalLights;
EntityList m_lights;
EntityList m_pointSpotLights;
EntityList m_particleGroups;
Nz::BackgroundRef m_background;
Nz::DepthRenderTechnique m_shadowTechnique;
Nz::Matrix4f m_coordinateSystemMatrix;
Nz::RenderTexture m_shadowRT;
bool m_coordinateSystemInvalidated;
};
}
@@ -62,3 +72,4 @@ namespace Ndk
#include <NDK/Systems/RenderSystem.inl>
#endif // NDK_SYSTEMS_RENDERSYSTEM_HPP
#endif // NDK_SERVER

View File

@@ -44,7 +44,7 @@ namespace Ndk
static_assert(std::is_base_of<BaseSystem, SystemType>::value, "SystemType is not a component");
// Allocation et affectation du component
std::unique_ptr<SystemType> ptr(new SystemType(std::forward(args)...));
std::unique_ptr<SystemType> ptr(new SystemType(std::forward<Args>(args)...));
return static_cast<SystemType&>(AddSystem(std::move(ptr)));
}

View File

@@ -9,7 +9,7 @@
namespace Ndk
{
void GraphicsComponent::InvalidateRenderableData(const Nz::InstancedRenderable* renderable, Nz::UInt32 flags, unsigned int index)
void GraphicsComponent::InvalidateRenderableData(const Nz::InstancedRenderable* renderable, Nz::UInt32 flags, std::size_t index)
{
NazaraAssert(index < m_renderables.size(), "Invalid renderable index");
NazaraUnused(renderable);

View File

@@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <NDK/Components/ParticleEmitterComponent.hpp>
#include <Nazara/Graphics/ParticleGroup.hpp>
namespace Ndk
{
void ParticleEmitterComponent::SetupParticles(Nz::ParticleMapper& mapper, unsigned int count) const
{
if (m_isActive && m_setupFunc)
m_setupFunc(m_entity, mapper, count);
}
ComponentIndex ParticleEmitterComponent::componentIndex;
}

View File

@@ -0,0 +1,10 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <NDK/Components/ParticleGroupComponent.hpp>
namespace Ndk
{
ComponentIndex ParticleGroupComponent::componentIndex;
}

View File

@@ -28,8 +28,8 @@ namespace Ndk
m_characterSize(24)
{
Nz::MaterialRef backgroundMaterial = Nz::Material::New();
backgroundMaterial->Enable(Nz::RendererParameter_Blend, true);
backgroundMaterial->Enable(Nz::RendererParameter_DepthBuffer, false);
backgroundMaterial->EnableBlending(true);
backgroundMaterial->EnableDepthBuffer(false);
backgroundMaterial->SetDstBlend(Nz::BlendFunc_InvSrcAlpha);
backgroundMaterial->SetSrcBlend(Nz::BlendFunc_SrcAlpha);
@@ -145,6 +145,7 @@ namespace Ndk
{
case Nz::Keyboard::Down:
case Nz::Keyboard::Up:
{
if (event.key.code == Nz::Keyboard::Up)
m_historyPosition = std::min<std::size_t>(m_commandHistory.size(), m_historyPosition + 1);
else
@@ -159,6 +160,10 @@ namespace Ndk
m_inputDrawer.SetText(s_inputPrefix + text);
m_inputTextSprite->Update(m_inputDrawer);
break;
}
default:
break;
}
break;
}

View File

@@ -51,7 +51,7 @@ namespace Ndk
BaseComponent& component = *m_components[index].get();
component.SetEntity(this);
for (unsigned int i = m_componentBits.FindFirst(); i != m_componentBits.npos; i = m_componentBits.FindNext(i))
for (std::size_t i = m_componentBits.FindFirst(); i != m_componentBits.npos; i = m_componentBits.FindNext(i))
{
if (i != index)
m_components[i]->OnComponentAttached(component);
@@ -73,8 +73,8 @@ namespace Ndk
void Entity::RemoveAllComponents()
{
for (unsigned int i = m_componentBits.FindFirst(); i != m_componentBits.npos; i = m_componentBits.FindNext(i))
RemoveComponent(i);
for (std::size_t i = m_componentBits.FindFirst(); i != m_componentBits.npos; i = m_componentBits.FindNext(i))
RemoveComponent(static_cast<ComponentIndex>(i));
NazaraAssert(m_componentBits.TestNone(), "All components should be gone");
@@ -90,7 +90,7 @@ namespace Ndk
{
// On récupère le component et on informe les composants du détachement
BaseComponent& component = *m_components[index].get();
for (unsigned int i = m_componentBits.FindFirst(); i != m_componentBits.npos; i = m_componentBits.FindNext(i))
for (std::size_t i = m_componentBits.FindFirst(); i != m_componentBits.npos; i = m_componentBits.FindNext(i))
{
if (i != index)
m_components[i]->OnComponentDetached(component);
@@ -114,7 +114,7 @@ namespace Ndk
void Entity::Destroy()
{
// On informe chaque système
for (SystemIndex index = m_systemBits.FindFirst(); index != m_systemBits.npos; index = m_systemBits.FindNext(index))
for (std::size_t index = m_systemBits.FindFirst(); index != m_systemBits.npos; index = m_systemBits.FindNext(index))
{
if (m_world->HasSystem(index))
{

View File

@@ -29,8 +29,8 @@ namespace Ndk
// SDK
application("Application"),
nodeComponent("NodeComponent"),
entityClass("Entity"),
nodeComponent("NodeComponent"),
velocityComponent("VelocityComponent"),
worldClass("World")
@@ -39,9 +39,9 @@ namespace Ndk
// Audio
musicClass("Music"),
soundClass("Sound"),
soundBuffer("SoundBuffer"),
soundEmitter("SoundEmitter"),
soundClass("Sound"),
// Graphics
instancedRenderable("InstancedRenderable"),

View File

@@ -76,6 +76,8 @@ namespace Ndk
/*********************************** Nz::SoundBuffer **********************************/
soundBuffer.SetConstructor([] (Nz::LuaInstance& lua, Nz::SoundBufferRef* instance)
{
NazaraUnused(lua);
Nz::PlacementNew(instance, Nz::SoundBuffer::New());
return true;
});
@@ -115,16 +117,16 @@ namespace Ndk
return 1;
});
soundBuffer.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& soundBuffer) -> int
soundBuffer.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance) -> int
{
Nz::StringStream stream("SoundBuffer(");
if (soundBuffer->IsValid())
if (instance->IsValid())
{
Nz::String filePath = soundBuffer->GetFilePath();
Nz::String filePath = instance->GetFilePath();
if (!filePath.IsEmpty())
stream << "File: " << filePath << ", ";
stream << "Duration: " << soundBuffer->GetDuration() / 1000.f << "s";
stream << "Duration: " << instance->GetDuration() / 1000.f << "s";
}
stream << ')';
@@ -148,17 +150,17 @@ namespace Ndk
soundEmitter.BindMethod("IsLooping", &Nz::SoundEmitter::IsLooping);
soundEmitter.BindMethod("IsSpatialized", &Nz::SoundEmitter::IsSpatialized);
soundEmitter.BindMethod("Pause", &Nz::SoundEmitter::Pause);
soundEmitter.BindMethod("Play", &Nz::SoundEmitter::Play);
soundEmitter.BindMethod("SetAttenuation", &Nz::SoundEmitter::SetAttenuation);
soundEmitter.BindMethod("SetMinDistance", &Nz::SoundEmitter::SetMinDistance);
soundEmitter.BindMethod("SetPitch", &Nz::SoundEmitter::SetPitch);
soundEmitter.BindMethod("SetPosition", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetPosition);
soundEmitter.BindMethod("SetVelocity", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetVelocity);
soundEmitter.BindMethod("SetVolume", &Nz::SoundEmitter::SetVolume);
soundEmitter.BindMethod("Stop", &Nz::SoundEmitter::Stop);
}

View File

@@ -205,7 +205,7 @@ namespace Ndk
{
case Nz::LuaType_Number:
{
long long index = lua.CheckInteger(1);
auto index = lua.CheckBoundInteger<std::size_t>(1);
if (index < 1 || index > 4)
return false;
@@ -238,9 +238,15 @@ namespace Ndk
case 'h':
lua.Push(instance.height);
return true;
default:
break;
}
break;
}
default:
break;
}
return false;
@@ -252,7 +258,7 @@ namespace Ndk
{
case Nz::LuaType_Number:
{
long long index = lua.CheckInteger(1);
auto index = lua.CheckBoundInteger<std::size_t>(1);
if (index < 1 || index > 4)
return false;
@@ -290,6 +296,9 @@ namespace Ndk
}
break;
}
default:
break;
}
return false;
@@ -313,7 +322,7 @@ namespace Ndk
Nz::PlacementNew(quaternion, *static_cast<Nz::Quaterniond*>(lua.ToUserdata(1)));
else
break;
return true;
}
@@ -389,6 +398,9 @@ namespace Ndk
case 'z':
instance.z = value;
return true;
default:
break;
}
return false;
@@ -455,9 +467,15 @@ namespace Ndk
case 'y':
lua.Push(instance.y);
return true;
default:
break;
}
break;
}
default:
break;
}
return false;
@@ -496,9 +514,15 @@ namespace Ndk
case 'y':
instance.y = value;
return true;
default:
break;
}
break;
}
default:
break;
}
return false;
@@ -513,11 +537,12 @@ namespace Ndk
case 0:
case 3:
Nz::PlacementNew(vector, lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0), lua.CheckNumber(3, 0.0));
return true;
case 1:
{
if (lua.IsOfType(1, Nz::LuaType_Number))
Nz::PlacementNew(vector, lua.CheckNumber(1), *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)));
Nz::PlacementNew(vector, lua.CheckNumber(1), *static_cast<Nz::Vector2d*>(lua.CheckUserdata(1, "Vector2")));
else if (lua.IsOfType(1, "Vector2"))
Nz::PlacementNew(vector, *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)));
else if (lua.IsOfType(1, "Vector3"))
@@ -582,9 +607,15 @@ namespace Ndk
case 'z':
lua.Push(instance.z);
return true;
default:
break;
}
break;
}
default:
break;
}
return false;
@@ -627,9 +658,15 @@ namespace Ndk
case 'z':
instance.z = value;
return true;
default:
break;
}
break;
}
default:
break;
}
return false;

View File

@@ -25,6 +25,9 @@
#include <NDK/Components/LightComponent.hpp>
#include <NDK/Components/ListenerComponent.hpp>
#include <NDK/Components/GraphicsComponent.hpp>
#include <NDK/Components/ParticleEmitterComponent.hpp>
#include <NDK/Components/ParticleGroupComponent.hpp>
#include <NDK/Systems/ParticleSystem.hpp>
#include <NDK/Systems/ListenerSystem.hpp>
#include <NDK/Systems/RenderSystem.hpp>
#endif
@@ -71,6 +74,8 @@ namespace Ndk
InitializeComponent<LightComponent>("NdkLight");
InitializeComponent<ListenerComponent>("NdkList");
InitializeComponent<GraphicsComponent>("NdkGfx");
InitializeComponent<ParticleEmitterComponent>("NdkPaEmi");
InitializeComponent<ParticleGroupComponent>("NdkPaGrp");
#endif
// Systems
@@ -84,6 +89,7 @@ namespace Ndk
#ifndef NDK_SERVER
// Client systems
InitializeSystem<ListenerSystem>();
InitializeSystem<ParticleSystem>();
InitializeSystem<RenderSystem>();
#endif
@@ -112,6 +118,12 @@ namespace Ndk
// Uninitialize the SDK
s_referenceCounter = 0;
// Components
BaseComponent::Uninitialize();
// Systems
BaseSystem::Uninitialize();
// Uninitialize the engine
#ifndef NDK_SERVER

10
SDK/src/NDK/State.cpp Normal file
View File

@@ -0,0 +1,10 @@
// Copyright (C) 2016 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <NDK/State.hpp>
namespace Ndk
{
State::~State() = default;
}

View File

@@ -0,0 +1,26 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <NDK/Systems/ParticleSystem.hpp>
#include <NDK/Components/ParticleGroupComponent.hpp>
namespace Ndk
{
ParticleSystem::ParticleSystem()
{
Requires<ParticleGroupComponent>();
}
void ParticleSystem::OnUpdate(float elapsedTime)
{
for (const Ndk::EntityHandle& entity : GetEntities())
{
ParticleGroupComponent& group = entity->GetComponent<ParticleGroupComponent>();
group.Update(elapsedTime);
}
}
SystemIndex ParticleSystem::systemIndex;
}

View File

@@ -4,10 +4,13 @@
#include <NDK/Systems/RenderSystem.hpp>
#include <Nazara/Graphics/ColorBackground.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Renderer/Renderer.hpp>
#include <NDK/Components/CameraComponent.hpp>
#include <NDK/Components/GraphicsComponent.hpp>
#include <NDK/Components/LightComponent.hpp>
#include <NDK/Components/NodeComponent.hpp>
#include <NDK/Components/ParticleGroupComponent.hpp>
namespace Ndk
{
@@ -23,8 +26,11 @@ namespace Ndk
void RenderSystem::OnEntityRemoved(Entity* entity)
{
m_cameras.Remove(entity);
m_directionalLights.Remove(entity);
m_drawables.Remove(entity);
m_lights.Remove(entity);
m_particleGroups.Remove(entity);
m_pointSpotLights.Remove(entity);
}
void RenderSystem::OnEntityValidation(Entity* entity, bool justAdded)
@@ -48,9 +54,32 @@ namespace Ndk
m_drawables.Remove(entity);
if (entity->HasComponent<LightComponent>() && entity->HasComponent<NodeComponent>())
{
LightComponent& lightComponent = entity->GetComponent<LightComponent>();
if (lightComponent.GetLightType() == Nz::LightType_Directional)
{
m_directionalLights.Insert(entity);
m_pointSpotLights.Remove(entity);
}
else
{
m_directionalLights.Remove(entity);
m_pointSpotLights.Insert(entity);
}
m_lights.Insert(entity);
}
else
{
m_directionalLights.Remove(entity);
m_lights.Remove(entity);
m_pointSpotLights.Remove(entity);
}
if (entity->HasComponent<ParticleGroupComponent>())
m_particleGroups.Insert(entity);
else
m_particleGroups.Remove(entity);
}
void RenderSystem::OnUpdate(float elapsedTime)
@@ -69,10 +98,13 @@ namespace Ndk
m_coordinateSystemInvalidated = false;
}
UpdatePointSpotShadowMaps();
for (const Ndk::EntityHandle& camera : m_cameras)
{
CameraComponent& camComponent = camera->GetComponent<CameraComponent>();
camComponent.ApplyView();
//UpdateDirectionalShadowMaps(camComponent);
Nz::AbstractRenderQueue* renderQueue = m_renderTechnique->GetRenderQueue();
renderQueue->Clear();
@@ -89,12 +121,21 @@ namespace Ndk
for (const Ndk::EntityHandle& light : m_lights)
{
LightComponent& lightComponent = light->GetComponent<LightComponent>();
NodeComponent& drawableNode = light->GetComponent<NodeComponent>();
NodeComponent& lightNode = light->GetComponent<NodeComponent>();
///TODO: Cache somehow?
lightComponent.AddToRenderQueue(renderQueue, Nz::Matrix4f::ConcatenateAffine(m_coordinateSystemMatrix, drawableNode.GetTransformMatrix()));
lightComponent.AddToRenderQueue(renderQueue, Nz::Matrix4f::ConcatenateAffine(m_coordinateSystemMatrix, lightNode.GetTransformMatrix()));
}
for (const Ndk::EntityHandle& particleGroup : m_particleGroups)
{
ParticleGroupComponent& groupComponent = particleGroup->GetComponent<ParticleGroupComponent>();
groupComponent.AddToRenderQueue(renderQueue, Nz::Matrix4f::Identity()); //< ParticleGroup doesn't use Matrix4f
}
camComponent.ApplyView();
Nz::SceneData sceneData;
sceneData.ambientColor = Nz::Color(25, 25, 25);
sceneData.background = m_background;
@@ -105,5 +146,146 @@ namespace Ndk
}
}
void RenderSystem::UpdateDirectionalShadowMaps(const Nz::AbstractViewer& viewer)
{
if (!m_shadowRT.IsValid())
m_shadowRT.Create();
Nz::SceneData dummySceneData;
dummySceneData.ambientColor = Nz::Color(0, 0, 0);
dummySceneData.background = nullptr;
dummySceneData.viewer = nullptr; //< Depth technique doesn't require any viewer
for (const Ndk::EntityHandle& light : m_directionalLights)
{
LightComponent& lightComponent = light->GetComponent<LightComponent>();
NodeComponent& lightNode = light->GetComponent<NodeComponent>();
if (!lightComponent.IsShadowCastingEnabled())
continue;
Nz::Vector2ui shadowMapSize(lightComponent.GetShadowMap()->GetSize());
m_shadowRT.AttachTexture(Nz::AttachmentPoint_Depth, 0, lightComponent.GetShadowMap());
Nz::Renderer::SetTarget(&m_shadowRT);
Nz::Renderer::SetViewport(Nz::Recti(0, 0, shadowMapSize.x, shadowMapSize.y));
Nz::AbstractRenderQueue* renderQueue = m_shadowTechnique.GetRenderQueue();
renderQueue->Clear();
///TODO: Culling
for (const Ndk::EntityHandle& drawable : m_drawables)
{
GraphicsComponent& graphicsComponent = drawable->GetComponent<GraphicsComponent>();
NodeComponent& drawableNode = drawable->GetComponent<NodeComponent>();
graphicsComponent.AddToRenderQueue(renderQueue);
}
///TODO: Cache the matrices in the light?
Nz::Renderer::SetMatrix(Nz::MatrixType_Projection, Nz::Matrix4f::Ortho(0.f, 100.f, 100.f, 0.f, 1.f, 100.f));
Nz::Renderer::SetMatrix(Nz::MatrixType_View, Nz::Matrix4f::ViewMatrix(lightNode.GetRotation() * Nz::Vector3f::Forward() * 100.f, lightNode.GetRotation()));
m_shadowTechnique.Clear(dummySceneData);
m_shadowTechnique.Draw(dummySceneData);
}
}
void RenderSystem::UpdatePointSpotShadowMaps()
{
if (!m_shadowRT.IsValid())
m_shadowRT.Create();
Nz::SceneData dummySceneData;
dummySceneData.ambientColor = Nz::Color(0, 0, 0);
dummySceneData.background = nullptr;
dummySceneData.viewer = nullptr; //< Depth technique doesn't require any viewer
for (const Ndk::EntityHandle& light : m_pointSpotLights)
{
LightComponent& lightComponent = light->GetComponent<LightComponent>();
NodeComponent& lightNode = light->GetComponent<NodeComponent>();
if (!lightComponent.IsShadowCastingEnabled())
continue;
Nz::Vector2ui shadowMapSize(lightComponent.GetShadowMap()->GetSize());
switch (lightComponent.GetLightType())
{
case Nz::LightType_Directional:
NazaraInternalError("Directional lights included in point/spot light list");
break;
case Nz::LightType_Point:
{
static Nz::Quaternionf rotations[6] =
{
Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), Nz::Vector3f::UnitX()), // nzCubemapFace_PositiveX
Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), -Nz::Vector3f::UnitX()), // nzCubemapFace_NegativeX
Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), -Nz::Vector3f::UnitY()), // nzCubemapFace_PositiveY
Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), Nz::Vector3f::UnitY()), // nzCubemapFace_NegativeY
Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), -Nz::Vector3f::UnitZ()), // nzCubemapFace_PositiveZ
Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), Nz::Vector3f::UnitZ()) // nzCubemapFace_NegativeZ
};
for (unsigned int face = 0; face < 6; ++face)
{
m_shadowRT.AttachTexture(Nz::AttachmentPoint_Depth, 0, lightComponent.GetShadowMap(), face);
Nz::Renderer::SetTarget(&m_shadowRT);
Nz::Renderer::SetViewport(Nz::Recti(0, 0, shadowMapSize.x, shadowMapSize.y));
///TODO: Cache the matrices in the light?
Nz::Renderer::SetMatrix(Nz::MatrixType_Projection, Nz::Matrix4f::Perspective(Nz::FromDegrees(90.f), 1.f, 0.1f, lightComponent.GetRadius()));
Nz::Renderer::SetMatrix(Nz::MatrixType_View, Nz::Matrix4f::ViewMatrix(lightNode.GetPosition(), rotations[face]));
Nz::AbstractRenderQueue* renderQueue = m_shadowTechnique.GetRenderQueue();
renderQueue->Clear();
///TODO: Culling
for (const Ndk::EntityHandle& drawable : m_drawables)
{
GraphicsComponent& graphicsComponent = drawable->GetComponent<GraphicsComponent>();
NodeComponent& drawableNode = drawable->GetComponent<NodeComponent>();
graphicsComponent.AddToRenderQueue(renderQueue);
}
m_shadowTechnique.Clear(dummySceneData);
m_shadowTechnique.Draw(dummySceneData);
}
break;
}
case Nz::LightType_Spot:
{
m_shadowRT.AttachTexture(Nz::AttachmentPoint_Depth, 0, lightComponent.GetShadowMap());
Nz::Renderer::SetTarget(&m_shadowRT);
Nz::Renderer::SetViewport(Nz::Recti(0, 0, shadowMapSize.x, shadowMapSize.y));
///TODO: Cache the matrices in the light?
Nz::Renderer::SetMatrix(Nz::MatrixType_Projection, Nz::Matrix4f::Perspective(lightComponent.GetOuterAngle()*2.f, 1.f, 0.1f, lightComponent.GetRadius()));
Nz::Renderer::SetMatrix(Nz::MatrixType_View, Nz::Matrix4f::ViewMatrix(lightNode.GetPosition(), lightNode.GetRotation()));
Nz::AbstractRenderQueue* renderQueue = m_shadowTechnique.GetRenderQueue();
renderQueue->Clear();
///TODO: Culling
for (const Ndk::EntityHandle& drawable : m_drawables)
{
GraphicsComponent& graphicsComponent = drawable->GetComponent<GraphicsComponent>();
NodeComponent& drawableNode = drawable->GetComponent<NodeComponent>();
graphicsComponent.AddToRenderQueue(renderQueue);
}
m_shadowTechnique.Clear(dummySceneData);
m_shadowTechnique.Draw(dummySceneData);
break;
}
}
}
}
SystemIndex RenderSystem::systemIndex;
}

View File

@@ -22,7 +22,7 @@ namespace Ndk
NodeComponent& node = entity->GetComponent<NodeComponent>();
const VelocityComponent& velocity = entity->GetComponent<VelocityComponent>();
node.Move(velocity.linearVelocity * elapsedTime);
node.Move(velocity.linearVelocity * elapsedTime, Nz::CoordSys_Global);
}
}

View File

@@ -9,6 +9,7 @@
#ifndef NDK_SERVER
#include <NDK/Systems/ListenerSystem.hpp>
#include <NDK/Systems/ParticleSystem.hpp>
#include <NDK/Systems/RenderSystem.hpp>
#endif
@@ -27,6 +28,7 @@ namespace Ndk
#ifndef NDK_SERVER
AddSystem<ListenerSystem>();
AddSystem<ParticleSystem>();
AddSystem<RenderSystem>();
#endif
}
@@ -94,7 +96,7 @@ namespace Ndk
void World::Update()
{
// Gestion des entités tuées depuis le dernier appel
for (unsigned int i = m_killedEntities.FindFirst(); i != m_killedEntities.npos; i = m_killedEntities.FindNext(i))
for (std::size_t i = m_killedEntities.FindFirst(); i != m_killedEntities.npos; i = m_killedEntities.FindNext(i))
{
EntityBlock& block = m_entities[i];
Entity& entity = block.entity;
@@ -127,7 +129,7 @@ namespace Ndk
m_killedEntities.Reset();
// Gestion des entités nécessitant une mise à jour de leurs systèmes
for (unsigned int i = m_dirtyEntities.FindFirst(); i != m_dirtyEntities.npos; i = m_dirtyEntities.FindNext(i))
for (std::size_t i = m_dirtyEntities.FindFirst(); i != m_dirtyEntities.npos; i = m_dirtyEntities.FindNext(i))
{
NazaraAssert(i < m_entities.size(), "Entity index out of range");