Sdk: Integrate particles

Former-commit-id: fa4474b434340d15363ff2ffc91b58d2df3a62fc [formerly 8a52795fc49a847e7b558425fc03915b21139521]
Former-commit-id: ac159c0cf652699400f720ef6fdad0fbf649308f
This commit is contained in:
Lynix 2016-07-30 15:51:46 +02:00
parent e6a4bcca0d
commit 70ee053f3f
15 changed files with 272 additions and 2 deletions

View File

@ -1,4 +1,4 @@
// This file was automatically generated on 01 Jun 2016 at 13:11:09 // This file was automatically generated on 30 Jul 2016 at 15:29:16
#pragma once #pragma once
@ -11,6 +11,8 @@
#include <NDK/Components/LightComponent.hpp> #include <NDK/Components/LightComponent.hpp>
#include <NDK/Components/ListenerComponent.hpp> #include <NDK/Components/ListenerComponent.hpp>
#include <NDK/Components/NodeComponent.hpp> #include <NDK/Components/NodeComponent.hpp>
#include <NDK/Components/ParticleEmitterComponent.hpp>
#include <NDK/Components/ParticleGroupComponent.hpp>
#include <NDK/Components/PhysicsComponent.hpp> #include <NDK/Components/PhysicsComponent.hpp>
#include <NDK/Components/VelocityComponent.hpp> #include <NDK/Components/VelocityComponent.hpp>

View File

@ -0,0 +1,45 @@
// 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 <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*/)>;
ParticleEmitterComponent(Nz::ParticleGroup* group);
ParticleEmitterComponent(const ParticleEmitterComponent& emitter);
~ParticleEmitterComponent();
inline bool IsActive() const;
void SetActive(bool active = true);
void SetGroup(Nz::ParticleGroup* group);
inline void SetSetupFunc(SetupFunc func);
static ComponentIndex componentIndex;
private:
void SetupParticles(Nz::ParticleMapper& mapper, unsigned int count) const override;
SetupFunc m_setupFunc;
Nz::ParticleGroup* m_particleGroup;
bool m_isActive;
};
}
#include <NDK/Components/ParticleEmitterComponent.inl>
#endif // NDK_COMPONENTS_PARTICLEEMITTERCOMPONENT_HPP
#endif // NDK_SERVER

View File

@ -0,0 +1,18 @@
// 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 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

@ -1,4 +1,4 @@
// This file was automatically generated on 01 Jun 2016 at 13:11:09 // This file was automatically generated on 30 Jul 2016 at 15:29:16
#pragma once #pragma once
@ -6,6 +6,7 @@
#define NDK_SYSTEMS_GLOBAL_HPP #define NDK_SYSTEMS_GLOBAL_HPP
#include <NDK/Systems/ListenerSystem.hpp> #include <NDK/Systems/ListenerSystem.hpp>
#include <NDK/Systems/ParticleSystem.hpp>
#include <NDK/Systems/PhysicsSystem.hpp> #include <NDK/Systems/PhysicsSystem.hpp>
#include <NDK/Systems/RenderSystem.hpp> #include <NDK/Systems/RenderSystem.hpp>
#include <NDK/Systems/VelocitySystem.hpp> #include <NDK/Systems/VelocitySystem.hpp>

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

@ -60,6 +60,7 @@ namespace Ndk
EntityList m_directionalLights; EntityList m_directionalLights;
EntityList m_lights; EntityList m_lights;
EntityList m_pointSpotLights; EntityList m_pointSpotLights;
EntityList m_particleGroups;
Nz::BackgroundRef m_background; Nz::BackgroundRef m_background;
Nz::DepthRenderTechnique m_shadowTechnique; Nz::DepthRenderTechnique m_shadowTechnique;
Nz::Matrix4f m_coordinateSystemMatrix; Nz::Matrix4f m_coordinateSystemMatrix;

View File

@ -0,0 +1,59 @@
// 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
{
ParticleEmitterComponent::ParticleEmitterComponent(Nz::ParticleGroup* group) :
m_particleGroup(group),
m_isActive(true)
{
if (m_particleGroup)
m_particleGroup->AddEmitter(this);
}
ParticleEmitterComponent::ParticleEmitterComponent(const ParticleEmitterComponent& emitter) :
m_particleGroup(emitter.m_particleGroup),
m_isActive(emitter.m_isActive)
{
if (m_isActive)
m_particleGroup->AddEmitter(this);
}
ParticleEmitterComponent::~ParticleEmitterComponent()
{
m_particleGroup->RemoveEmitter(this);
}
inline void Ndk::ParticleEmitterComponent::SetActive(bool active)
{
if (m_isActive != active)
{
if (active)
m_particleGroup->AddEmitter(this);
else
m_particleGroup->RemoveEmitter(this);
}
}
void ParticleEmitterComponent::SetGroup(Nz::ParticleGroup* group)
{
if (m_particleGroup)
m_particleGroup->RemoveEmitter(this);
m_particleGroup = group;
if (m_particleGroup && m_isActive)
m_particleGroup = group;
}
inline void ParticleEmitterComponent::SetupParticles(Nz::ParticleMapper& mapper, unsigned int count) const
{
if (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

@ -25,6 +25,9 @@
#include <NDK/Components/LightComponent.hpp> #include <NDK/Components/LightComponent.hpp>
#include <NDK/Components/ListenerComponent.hpp> #include <NDK/Components/ListenerComponent.hpp>
#include <NDK/Components/GraphicsComponent.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/ListenerSystem.hpp>
#include <NDK/Systems/RenderSystem.hpp> #include <NDK/Systems/RenderSystem.hpp>
#endif #endif
@ -71,6 +74,8 @@ namespace Ndk
InitializeComponent<LightComponent>("NdkLight"); InitializeComponent<LightComponent>("NdkLight");
InitializeComponent<ListenerComponent>("NdkList"); InitializeComponent<ListenerComponent>("NdkList");
InitializeComponent<GraphicsComponent>("NdkGfx"); InitializeComponent<GraphicsComponent>("NdkGfx");
InitializeComponent<ParticleEmitterComponent>("NdkPaEmi");
InitializeComponent<ParticleGroupComponent>("NdkPaGrp");
#endif #endif
// Systems // Systems
@ -84,6 +89,7 @@ namespace Ndk
#ifndef NDK_SERVER #ifndef NDK_SERVER
// Client systems // Client systems
InitializeSystem<ListenerSystem>(); InitializeSystem<ListenerSystem>();
InitializeSystem<ParticleSystem>();
InitializeSystem<RenderSystem>(); InitializeSystem<RenderSystem>();
#endif #endif

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

@ -10,6 +10,7 @@
#include <NDK/Components/GraphicsComponent.hpp> #include <NDK/Components/GraphicsComponent.hpp>
#include <NDK/Components/LightComponent.hpp> #include <NDK/Components/LightComponent.hpp>
#include <NDK/Components/NodeComponent.hpp> #include <NDK/Components/NodeComponent.hpp>
#include <NDK/Components/ParticleGroupComponent.hpp>
namespace Ndk namespace Ndk
{ {
@ -25,8 +26,11 @@ namespace Ndk
void RenderSystem::OnEntityRemoved(Entity* entity) void RenderSystem::OnEntityRemoved(Entity* entity)
{ {
m_cameras.Remove(entity); m_cameras.Remove(entity);
m_directionalLights.Remove(entity);
m_drawables.Remove(entity); m_drawables.Remove(entity);
m_lights.Remove(entity); m_lights.Remove(entity);
m_particleGroups.Remove(entity);
m_pointSpotLights.Remove(entity);
} }
void RenderSystem::OnEntityValidation(Entity* entity, bool justAdded) void RenderSystem::OnEntityValidation(Entity* entity, bool justAdded)
@ -71,6 +75,11 @@ namespace Ndk
m_lights.Remove(entity); m_lights.Remove(entity);
m_pointSpotLights.Remove(entity); m_pointSpotLights.Remove(entity);
} }
if (entity->HasComponent<ParticleGroupComponent>())
m_particleGroups.Insert(entity);
else
m_particleGroups.Remove(entity);
} }
void RenderSystem::OnUpdate(float elapsedTime) void RenderSystem::OnUpdate(float elapsedTime)
@ -118,6 +127,13 @@ namespace Ndk
lightComponent.AddToRenderQueue(renderQueue, Nz::Matrix4f::ConcatenateAffine(m_coordinateSystemMatrix, lightNode.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(); camComponent.ApplyView();
Nz::SceneData sceneData; Nz::SceneData sceneData;

View File

@ -9,6 +9,7 @@
#ifndef NDK_SERVER #ifndef NDK_SERVER
#include <NDK/Systems/ListenerSystem.hpp> #include <NDK/Systems/ListenerSystem.hpp>
#include <NDK/Systems/ParticleSystem.hpp>
#include <NDK/Systems/RenderSystem.hpp> #include <NDK/Systems/RenderSystem.hpp>
#endif #endif
@ -27,6 +28,7 @@ namespace Ndk
#ifndef NDK_SERVER #ifndef NDK_SERVER
AddSystem<ListenerSystem>(); AddSystem<ListenerSystem>();
AddSystem<ParticleSystem>();
AddSystem<RenderSystem>(); AddSystem<RenderSystem>();
#endif #endif
} }