Graphics/Particles: Add wrappers on functions controller/generator/renderer
Former-commit-id: 8a0eab88a918f901e918a81cc8a81906167eccb8 [formerly 1fea24282314656473187fd5320f36eb6d06c004] [formerly ec24ee686b68f7e684853d49772105bc5a92b5a0 [formerly e9d6783dd6dff1de2468bd0fd979b28037b1cb44]] Former-commit-id: fc6ad0e1dbf563f3b3b485fe9c7f93b35c0712bc [formerly 9cfcb29a154a3461183695df3daccbb8965eaee9] Former-commit-id: b91d72a005fdb104711fb8892b14a5f98fc29ab3
This commit is contained in:
parent
31c1ecf2d9
commit
262f4c2a87
|
|
@ -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 <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Graphics/ParticleController.hpp>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
class ParticleFunctionController;
|
||||||
|
|
||||||
|
using ParticleFunctionControllerConstRef = ObjectRef<const ParticleFunctionController>;
|
||||||
|
using ParticleFunctionControllerRef = ObjectRef<ParticleFunctionController>;
|
||||||
|
|
||||||
|
class NAZARA_GRAPHICS_API ParticleFunctionController : public ParticleController
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using Controller = std::function<void(ParticleGroup& /*group*/, ParticleMapper& /*mapper*/, unsigned int /*startId*/, unsigned int /*endId*/, float /*elapsedTime*/)>;
|
||||||
|
|
||||||
|
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<typename... Args> static ParticleFunctionControllerRef New(Args&&... args);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Controller m_controller;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Graphics/ParticleFunctionController.inl>
|
||||||
|
|
||||||
|
#endif // NAZARA_PARTICLEFUNCTIONCONTROLLER_HPP
|
||||||
|
|
@ -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 <Nazara/Graphics/ParticleFunctionController.hpp>
|
||||||
|
#include <memory>
|
||||||
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
|
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<typename... Args>
|
||||||
|
ParticleFunctionControllerRef ParticleFunctionController::New(Args&&... args)
|
||||||
|
{
|
||||||
|
std::unique_ptr<ParticleFunctionController> object(new ParticleFunctionController(std::forward<Args>(args)...));
|
||||||
|
object->SetPersistent(false);
|
||||||
|
|
||||||
|
return object.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Graphics/DebugOff.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 <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Graphics/ParticleGenerator.hpp>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
class ParticleFunctionGenerator;
|
||||||
|
|
||||||
|
using ParticleFunctionGeneratorConstRef = ObjectRef<const ParticleFunctionGenerator>;
|
||||||
|
using ParticleFunctionGeneratorRef = ObjectRef<ParticleFunctionGenerator>;
|
||||||
|
|
||||||
|
class NAZARA_GRAPHICS_API ParticleFunctionGenerator : public ParticleGenerator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using Generator = std::function<void(ParticleGroup& /*group*/, ParticleMapper& /*mapper*/, unsigned int /*startId*/, unsigned int /*endId*/)>;
|
||||||
|
|
||||||
|
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<typename... Args> static ParticleFunctionGeneratorRef New(Args&&... args);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Generator m_generator;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Graphics/ParticleFunctionGenerator.inl>
|
||||||
|
|
||||||
|
#endif // NAZARA_PARTICLEFUNCTIONGENERATOR_HPP
|
||||||
|
|
@ -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 <Nazara/Graphics/ParticleFunctionGenerator.hpp>
|
||||||
|
#include <memory>
|
||||||
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
|
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<typename... Args>
|
||||||
|
ParticleFunctionGeneratorRef ParticleFunctionGenerator::New(Args&&... args)
|
||||||
|
{
|
||||||
|
std::unique_ptr<ParticleFunctionGenerator> object(new ParticleFunctionGenerator(std::forward<Args>(args)...));
|
||||||
|
object->SetPersistent(false);
|
||||||
|
|
||||||
|
return object.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Graphics/DebugOff.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 <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Graphics/ParticleRenderer.hpp>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
class ParticleFunctionRenderer;
|
||||||
|
|
||||||
|
using ParticleFunctionRendererConstRef = ObjectRef<const ParticleFunctionRenderer>;
|
||||||
|
using ParticleFunctionRendererRef = ObjectRef<ParticleFunctionRenderer>;
|
||||||
|
|
||||||
|
class NAZARA_GRAPHICS_API ParticleFunctionRenderer : public ParticleRenderer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using Renderer = std::function<void(const ParticleGroup& /*group*/, const ParticleMapper& /*mapper*/, unsigned int /*startId*/, unsigned int /*endId*/, AbstractRenderQueue* /*renderQueue*/)>;
|
||||||
|
|
||||||
|
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<typename... Args> static ParticleFunctionRendererRef New(Args&&... args);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Renderer m_renderer;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Graphics/ParticleFunctionRenderer.inl>
|
||||||
|
|
||||||
|
#endif // NAZARA_PARTICLEFUNCTIONRENDERER_HPP
|
||||||
|
|
@ -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 <Nazara/Graphics/ParticleFunctionRenderer.hpp>
|
||||||
|
#include <memory>
|
||||||
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
|
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<typename... Args>
|
||||||
|
ParticleFunctionRendererRef ParticleFunctionRenderer::New(Args&&... args)
|
||||||
|
{
|
||||||
|
std::unique_ptr<ParticleFunctionRenderer> object(new ParticleFunctionRenderer(std::forward<Args>(args)...));
|
||||||
|
object->SetPersistent(false);
|
||||||
|
|
||||||
|
return object.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Graphics/DebugOff.hpp>
|
||||||
|
|
@ -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 <Nazara/Graphics/ParticleFunctionController.hpp>
|
||||||
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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 <Nazara/Graphics/ParticleFunctionGenerator.hpp>
|
||||||
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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 <Nazara/Graphics/ParticleFunctionRenderer.hpp>
|
||||||
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue