Graphics/Particles: Add wrappers on functions controller/generator/renderer
Former-commit-id: b4bc65fd61d304ab9c54f5eb960ee3ee111e4199 [formerly 6dc8ec4c126ec92253fcd1488f3d450a87cd2b0b] [formerly 72c62a62a1f34b633531c8e011e697a773ba574a [formerly d2aff554d20246c1fc5b47013e3e7c136c0b51a2]] Former-commit-id: 54227b0f67e85ff186ec4ee7a3df0f3aa70193d1 [formerly 49065827d43b04e836901c05fee0542667c50683] Former-commit-id: 013776ab4b91064bb48b18822317935376062a09
This commit is contained in:
parent
e0e0ed7379
commit
c231d73f9e
|
|
@ -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