diff --git a/include/Nazara/Graphics/ParticleFunctionController.hpp b/include/Nazara/Graphics/ParticleFunctionController.hpp new file mode 100644 index 000000000..6b3c4a974 --- /dev/null +++ b/include/Nazara/Graphics/ParticleFunctionController.hpp @@ -0,0 +1,45 @@ +// Copyright (C) 2015 Jérôme Leclercq +// This file is part of the "Nazara Engine - Graphics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_PARTICLEFUNCTIONCONTROLLER_HPP +#define NAZARA_PARTICLEFUNCTIONCONTROLLER_HPP + +#include +#include +#include + +namespace Nz +{ + class ParticleFunctionController; + + using ParticleFunctionControllerConstRef = ObjectRef; + using ParticleFunctionControllerRef = ObjectRef; + + class NAZARA_GRAPHICS_API ParticleFunctionController : public ParticleController + { + public: + using Controller = std::function; + + inline ParticleFunctionController(Controller controller); + ParticleFunctionController(const ParticleFunctionController&) = default; + ~ParticleFunctionController() = default; + + void Apply(ParticleGroup& group, ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime) override final; + + inline const Controller& GetController() const; + + inline void SetController(Controller controller); + + template static ParticleFunctionControllerRef New(Args&&... args); + + private: + Controller m_controller; + }; +} + +#include + +#endif // NAZARA_PARTICLEFUNCTIONCONTROLLER_HPP diff --git a/include/Nazara/Graphics/ParticleFunctionController.inl b/include/Nazara/Graphics/ParticleFunctionController.inl new file mode 100644 index 000000000..eb4365fda --- /dev/null +++ b/include/Nazara/Graphics/ParticleFunctionController.inl @@ -0,0 +1,46 @@ +// Copyright (C) 2016 Jérôme Leclercq +// This file is part of the "Nazara Engine - Graphics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include + +namespace Nz +{ + inline ParticleFunctionController::ParticleFunctionController(Controller controller) : + m_controller(std::move(controller)) + { + } + + /*! + * \brief Gets the controller function + * + * \return Controller function responsible for particle update + */ + inline const ParticleFunctionController::Controller& ParticleFunctionController::GetController() const + { + return m_controller; + } + + /*! + * \brief Sets the controller function + * + * \remark The controller function must be valid + */ + inline void ParticleFunctionController::SetController(Controller controller) + { + m_controller = std::move(controller); + } + + template + ParticleFunctionControllerRef ParticleFunctionController::New(Args&&... args) + { + std::unique_ptr object(new ParticleFunctionController(std::forward(args)...)); + object->SetPersistent(false); + + return object.release(); + } +} + +#include diff --git a/include/Nazara/Graphics/ParticleFunctionGenerator.hpp b/include/Nazara/Graphics/ParticleFunctionGenerator.hpp new file mode 100644 index 000000000..7aa5bb9f3 --- /dev/null +++ b/include/Nazara/Graphics/ParticleFunctionGenerator.hpp @@ -0,0 +1,45 @@ +// Copyright (C) 2015 Jérôme Leclercq +// This file is part of the "Nazara Engine - Graphics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_PARTICLEFUNCTIONGENERATOR_HPP +#define NAZARA_PARTICLEFUNCTIONGENERATOR_HPP + +#include +#include +#include + +namespace Nz +{ + class ParticleFunctionGenerator; + + using ParticleFunctionGeneratorConstRef = ObjectRef; + using ParticleFunctionGeneratorRef = ObjectRef; + + class NAZARA_GRAPHICS_API ParticleFunctionGenerator : public ParticleGenerator + { + public: + using Generator = std::function; + + inline ParticleFunctionGenerator(Generator controller); + ParticleFunctionGenerator(const ParticleFunctionGenerator&) = default; + ~ParticleFunctionGenerator() = default; + + void Generate(ParticleGroup& group, ParticleMapper& mapper, unsigned int startId, unsigned int endId) override final; + + inline const Generator& GetGenerator() const; + + inline void SetGenerator(Generator generator); + + template static ParticleFunctionGeneratorRef New(Args&&... args); + + private: + Generator m_generator; + }; +} + +#include + +#endif // NAZARA_PARTICLEFUNCTIONGENERATOR_HPP diff --git a/include/Nazara/Graphics/ParticleFunctionGenerator.inl b/include/Nazara/Graphics/ParticleFunctionGenerator.inl new file mode 100644 index 000000000..9cb11683c --- /dev/null +++ b/include/Nazara/Graphics/ParticleFunctionGenerator.inl @@ -0,0 +1,46 @@ +// Copyright (C) 2016 Jérôme Leclercq +// This file is part of the "Nazara Engine - Graphics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include + +namespace Nz +{ + inline ParticleFunctionGenerator::ParticleFunctionGenerator(Generator generator) : + m_generator(std::move(generator)) + { + } + + /*! + * \brief Gets the generator function + * + * \return Generator function responsible for particle creation + */ + inline const ParticleFunctionGenerator::Generator& ParticleFunctionGenerator::GetGenerator() const + { + return m_generator; + } + + /*! + * \brief Sets the generator function + * + * \remark The generator function must be valid + */ + inline void ParticleFunctionGenerator::SetGenerator(Generator generator) + { + m_generator = std::move(generator); + } + + template + ParticleFunctionGeneratorRef ParticleFunctionGenerator::New(Args&&... args) + { + std::unique_ptr object(new ParticleFunctionGenerator(std::forward(args)...)); + object->SetPersistent(false); + + return object.release(); + } +} + +#include diff --git a/include/Nazara/Graphics/ParticleFunctionRenderer.hpp b/include/Nazara/Graphics/ParticleFunctionRenderer.hpp new file mode 100644 index 000000000..810027ae9 --- /dev/null +++ b/include/Nazara/Graphics/ParticleFunctionRenderer.hpp @@ -0,0 +1,45 @@ +// Copyright (C) 2015 Jérôme Leclercq +// This file is part of the "Nazara Engine - Graphics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_PARTICLEFUNCTIONRENDERER_HPP +#define NAZARA_PARTICLEFUNCTIONRENDERER_HPP + +#include +#include +#include + +namespace Nz +{ + class ParticleFunctionRenderer; + + using ParticleFunctionRendererConstRef = ObjectRef; + using ParticleFunctionRendererRef = ObjectRef; + + class NAZARA_GRAPHICS_API ParticleFunctionRenderer : public ParticleRenderer + { + public: + using Renderer = std::function; + + inline ParticleFunctionRenderer(Renderer renderer); + ParticleFunctionRenderer(const ParticleFunctionRenderer&) = default; + ~ParticleFunctionRenderer() = default; + + void Render(const ParticleGroup& group, const ParticleMapper& mapper, unsigned int startId, unsigned int endId, AbstractRenderQueue* renderQueue) override final; + + inline const Renderer& GetRenderer() const; + + inline void SetRenderer(Renderer renderer); + + template static ParticleFunctionRendererRef New(Args&&... args); + + private: + Renderer m_renderer; + }; +} + +#include + +#endif // NAZARA_PARTICLEFUNCTIONRENDERER_HPP diff --git a/include/Nazara/Graphics/ParticleFunctionRenderer.inl b/include/Nazara/Graphics/ParticleFunctionRenderer.inl new file mode 100644 index 000000000..cf859fbfe --- /dev/null +++ b/include/Nazara/Graphics/ParticleFunctionRenderer.inl @@ -0,0 +1,46 @@ +// Copyright (C) 2016 Jérôme Leclercq +// This file is part of the "Nazara Engine - Graphics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include + +namespace Nz +{ + inline ParticleFunctionRenderer::ParticleFunctionRenderer(Renderer renderer) : + m_renderer(std::move(renderer)) + { + } + + /*! + * \brief Gets the renderer function + * + * \return Renderer function responsible for particle rendering + */ + inline const ParticleFunctionRenderer::Renderer& ParticleFunctionRenderer::GetRenderer() const + { + return m_renderer; + } + + /*! + * \brief Sets the renderer function + * + * \remark The renderer function must be valid + */ + inline void ParticleFunctionRenderer::SetRenderer(Renderer renderer) + { + m_renderer = std::move(renderer); + } + + template + ParticleFunctionRendererRef ParticleFunctionRenderer::New(Args&&... args) + { + std::unique_ptr object(new ParticleFunctionRenderer(std::forward(args)...)); + object->SetPersistent(false); + + return object.release(); + } +} + +#include diff --git a/src/Nazara/Graphics/ParticleFunctionController.cpp b/src/Nazara/Graphics/ParticleFunctionController.cpp new file mode 100644 index 000000000..9b300f450 --- /dev/null +++ b/src/Nazara/Graphics/ParticleFunctionController.cpp @@ -0,0 +1,29 @@ +// Copyright (C) 2015 Jérôme Leclercq +// This file is part of the "Nazara Engine - Graphics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include + +namespace Nz +{ + /*! + * \ingroup graphics + * \class Nz::ParticleFunctionController + * \brief Helper class used to provide a function as a particle controller without going in the process of making a new class + */ + + /*! + * \brief Calls the controller function + * + * \param group Particle group responsible of the particles + * \param mapper Particle mapper, allowing access to the particle data + * \param startId The first ID of the particle to update (inclusive) + * \param endId The last ID of the particle to update (inclusive) + * \param elapsedTime Elapsed time in seconds since the last update + */ + void ParticleFunctionController::Apply(ParticleGroup& group, ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime) + { + m_controller(group, mapper, startId, endId, elapsedTime); + } +} diff --git a/src/Nazara/Graphics/ParticleFunctionGenerator.cpp b/src/Nazara/Graphics/ParticleFunctionGenerator.cpp new file mode 100644 index 000000000..67d43770d --- /dev/null +++ b/src/Nazara/Graphics/ParticleFunctionGenerator.cpp @@ -0,0 +1,28 @@ +// Copyright (C) 2015 Jérôme Leclercq +// This file is part of the "Nazara Engine - Graphics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include + +namespace Nz +{ + /*! + * \ingroup graphics + * \class Nz::ParticleFunctionGenerator + * \brief Helper class used to provide a function as a particle generator without going in the process of making a new class + */ + + /*! + * \brief Calls the generator function + * + * \param group Particle group responsible of the particles + * \param mapper Particle mapper, allowing access to the particle data + * \param startId The first ID of the particle to update (inclusive) + * \param endId The last ID of the particle to update (inclusive) + */ + void ParticleFunctionGenerator::Generate(ParticleGroup& group, ParticleMapper& mapper, unsigned int startId, unsigned int endId) + { + m_generator(group, mapper, startId, endId); + } +} diff --git a/src/Nazara/Graphics/ParticleFunctionRenderer.cpp b/src/Nazara/Graphics/ParticleFunctionRenderer.cpp new file mode 100644 index 000000000..36dfea3df --- /dev/null +++ b/src/Nazara/Graphics/ParticleFunctionRenderer.cpp @@ -0,0 +1,29 @@ +// Copyright (C) 2015 Jérôme Leclercq +// This file is part of the "Nazara Engine - Graphics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include + +namespace Nz +{ + /*! + * \ingroup graphics + * \class Nz::ParticleFunctionRenderer + * \brief Helper class used to provide a function as a particle renderer without going in the process of making a new class + */ + + /*! + * \brief Calls the renderer function + * + * \param group Particle group responsible of the particles + * \param mapper Particle mapper, allowing constant access to the particle data + * \param startId The first ID of the particle to update (inclusive) + * \param endId The last ID of the particle to update (inclusive) + * \param renderQueue The concerned render queue that will receive drawable informations + */ + void ParticleFunctionRenderer::Render(const ParticleGroup& group, const ParticleMapper& mapper, unsigned int startId, unsigned int endId, AbstractRenderQueue* renderQueue) + { + m_renderer(group, mapper, startId, endId, renderQueue); + } +}