Sdk: Integrate particles
Former-commit-id: 48dac6b378c45130c43f5b8214a7b13a35cf06d1 [formerly c874b77869e750df33a1e77fdb40747b543b2efa] Former-commit-id: a2c06e5f2b0fe3dd1c74ce2835436a7219260bf8
This commit is contained in:
59
SDK/src/NDK/Components/ParticleEmitterComponent.cpp
Normal file
59
SDK/src/NDK/Components/ParticleEmitterComponent.cpp
Normal 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;
|
||||
}
|
||||
10
SDK/src/NDK/Components/ParticleGroupComponent.cpp
Normal file
10
SDK/src/NDK/Components/ParticleGroupComponent.cpp
Normal 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;
|
||||
}
|
||||
@@ -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
|
||||
|
||||
|
||||
26
SDK/src/NDK/Systems/ParticleSystem.cpp
Normal file
26
SDK/src/NDK/Systems/ParticleSystem.cpp
Normal 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;
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Components/LightComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/Components/ParticleGroupComponent.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
@@ -25,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)
|
||||
@@ -71,6 +75,11 @@ namespace Ndk
|
||||
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)
|
||||
@@ -118,6 +127,13 @@ namespace Ndk
|
||||
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;
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user