| 1 |
#pragma once |
| 2 |
|
| 3 |
#include "imodule.h" |
| 4 |
#include "irenderable.h" |
| 5 |
#include "ideclmanager.h" |
| 6 |
|
| 7 |
#include <functional> |
| 8 |
#include <sigc++/signal.h> |
| 9 |
|
| 10 |
class RenderSystem; |
| 11 |
class Matrix4; |
| 12 |
template<typename Element> class BasicVector3; |
| 13 |
typedef BasicVector3<double> Vector3; |
| 14 |
class AABB; |
| 15 |
|
| 16 |
namespace scene |
| 17 |
{ |
| 18 |
class INode; |
| 19 |
typedef std::shared_ptr<INode> INodePtr; |
| 20 |
} |
| 21 |
|
| 22 |
/// Classes related to storage and rendering of particle systems |
| 23 |
namespace particles |
| 24 |
{ |
| 25 |
|
| 26 |
// see iparticlestage.h for definition |
| 27 |
class IStageDef; |
| 28 |
|
| 29 |
// see iparticlenode.h for definition |
| 30 |
class IParticleNode; |
| 31 |
typedef std::shared_ptr<IParticleNode> IParticleNodePtr; |
| 32 |
|
| 33 |
/** |
| 34 |
* \brief |
| 35 |
* Definition of a particle system. |
| 36 |
* |
| 37 |
* Each particle system is made up of one or more particle stages, information |
| 38 |
* about which is provided via the IStageDef interface. |
| 39 |
*/ |
| 40 |
class IParticleDef : |
| 41 |
public decl::IDeclaration |
| 42 |
{ |
| 43 |
public: |
| 44 |
using Ptr = std::shared_ptr<IParticleDef>; |
| 45 |
|
| 46 |
virtual ~IParticleDef() {} |
| 47 |
|
| 48 |
virtual void setFilename(const std::string& filename) = 0; |
| 49 |
|
| 50 |
/** |
| 51 |
* Set/get the depth hack flag |
| 52 |
*/ |
| 53 |
virtual float getDepthHack() = 0; |
| 54 |
virtual void setDepthHack(float value) = 0; |
| 55 |
|
| 56 |
/// Returns the number of stages for this particle system. |
| 57 |
virtual std::size_t getNumStages() = 0; |
| 58 |
|
| 59 |
/// Get a stage definition from the particle definition |
| 60 |
virtual const std::shared_ptr<IStageDef>& getStage(std::size_t stageNum) = 0; |
| 61 |
|
| 62 |
/** |
| 63 |
* Add a new stage to this particle, returns the index of the new stage. |
| 64 |
*/ |
| 65 |
virtual std::size_t addParticleStage() = 0; |
| 66 |
|
| 67 |
/** |
| 68 |
* Removes the stage with the given index. |
| 69 |
*/ |
| 70 |
virtual void removeParticleStage(std::size_t index) = 0; |
| 71 |
|
| 72 |
/** |
| 73 |
* Swaps the location of the two given particle stages. After this step the |
| 74 |
* particle stage at <index> will be at <index2> and vice versa. |
| 75 |
* If one of the indices is out of bounds (or both indices are equal) nothing will happen. |
| 76 |
*/ |
| 77 |
virtual void swapParticleStages(std::size_t index, std::size_t index2) = 0; |
| 78 |
|
| 79 |
/// Signal emitted when some aspect of the particle def has changed |
| 80 |
virtual sigc::signal<void>& signal_changed() = 0; |
| 81 |
|
| 82 |
// Comparison operator - particle defs are considered equal if all properties (except the name!), |
| 83 |
// number of stages and stage contents are the equal |
| 84 |
virtual bool isEqualTo(const Ptr& other) = 0; |
| 85 |
|
| 86 |
// Copies all properties from the other particle, overwriting this one |
| 87 |
// Note: Name, filename and observers are not copied |
| 88 |
virtual void copyFrom(const Ptr& other) = 0; |
| 89 |
}; |
| 90 |
|
| 91 |
/** |
| 92 |
* A renderable particle, which is capable of compiling the |
| 93 |
* particle system into actual geometry usable for the backend rendersystem. |
| 94 |
* |
| 95 |
* As it derives from Renderable, this object can be added to a RenderableCollector |
| 96 |
* during the front-end render phase. |
| 97 |
*/ |
| 98 |
class IRenderableParticle : |
| 99 |
public Renderable |
| 100 |
{ |
| 101 |
public: |
| 102 |
/** |
| 103 |
* Update the particle geometry using the given rendersystem. |
| 104 |
* The rendersystem is needed for acquiring the shaders and |
| 105 |
* the current render time. |
| 106 |
* |
| 107 |
* @viewRotation: the matrix to orient themselves to the viewer. |
| 108 |
* @localToWorld: the combined transform of local to world coordinates |
| 109 |
* @entity: the parent entity |
| 110 |
*/ |
| 111 |
virtual void update(const Matrix4& viewRotation, const Matrix4& localToWorld, IRenderEntity* entity) = 0; |
| 112 |
|
| 113 |
/** |
| 114 |
* Get the particle definition used by this renderable. |
| 115 |
*/ |
| 116 |
virtual const IParticleDef::Ptr& getParticleDef() const = 0; |
| 117 |
|
| 118 |
/** |
| 119 |
* Set the particle definition. You'll need to call update() after |
| 120 |
* setting a new particle def. |
| 121 |
*/ |
| 122 |
virtual void setParticleDef(const IParticleDef::Ptr& def) = 0; |
| 123 |
|
| 124 |
/** |
| 125 |
* greebo: Particles have a main direction, usually defined by the |
| 126 |
* emitter's rotation. For a stand-alone particle (without emitter) |
| 127 |
* this direction defaults to <0,0,1>, but can be overridden here. |
| 128 |
*/ |
| 129 |
virtual void setMainDirection(const Vector3& direction) = 0; |
| 130 |
|
| 131 |
/** |
| 132 |
* Set the colour needed by the particle system when the setting |
| 133 |
* "use entity colour" is activated. |
| 134 |
*/ |
| 135 |
virtual void setEntityColour(const Vector3& colour) = 0; |
| 136 |
|
| 137 |
/** |
| 138 |
* Returns the bounding box taken by the entirety of quads in this particle. |
| 139 |
* Make sure to call this after the update() method, as getAABB() will |
| 140 |
* calculate and return the bounds at the time passed to update(). |
| 141 |
*/ |
| 142 |
virtual const AABB& getBounds() = 0; |
| 143 |
}; |
| 144 |
typedef std::shared_ptr<IRenderableParticle> IRenderableParticlePtr; |
| 145 |
|
| 146 |
/** |
| 147 |
* Callback for evaluation particle defs. |
| 148 |
*/ |
| 149 |
typedef std::function< void (const IParticleDef&) > ParticleDefVisitor; |
| 150 |
|
| 151 |
/// Inteface for the particles manager |
| 152 |
class IParticlesManager : |
| 153 |
public RegisterableModule |
| 154 |
{ |
| 155 |
public: |
| 156 |
|
| 157 |
/// Signal emitted when particle definitions are reloaded |
| 158 |
virtual sigc::signal<void>& signal_particlesReloaded() = 0; |
| 159 |
|
| 160 |
/// Enumerate each particle def. |
| 161 |
virtual void forEachParticleDef(const ParticleDefVisitor&) = 0; |
| 162 |
|
| 163 |
/// Return the definition object for the given named particle system |
| 164 |
virtual IParticleDef::Ptr getDefByName(const std::string& name) = 0; |
| 165 |
|
| 166 |
// Finds or creates the particle def with the given name, always returns non-NULL |
| 167 |
virtual IParticleDef::Ptr findOrInsertParticleDef(const std::string& name) = 0; |
| 168 |
|
| 169 |
// Removes the named particle definition from the storage |
| 170 |
virtual void removeParticleDef(const std::string& name) = 0; |
| 171 |
|
| 172 |
/** |
| 173 |
* Create a renderable particle, which is capable of compiling the |
| 174 |
* particle system into actual geometry usable for the backend rendersystem. |
| 175 |
* |
| 176 |
* @returns: the renderable particle instance or NULL if the named particle was not found. |
| 177 |
*/ |
| 178 |
virtual IRenderableParticlePtr getRenderableParticle(const std::string& name) = 0; |
| 179 |
|
| 180 |
/// Create and return a particle node for the named particle system |
| 181 |
virtual IParticleNodePtr createParticleNode(const std::string& name) = 0; |
| 182 |
|
| 183 |
/** |
| 184 |
* Writes the named particle declaration to the file it is associated with, |
| 185 |
* replacing any existing declaration with the same name in that file. |
| 186 |
* Any other particle declarations that happen to be declared in the same file |
| 187 |
* will be preserved. |
| 188 |
* |
| 189 |
* If the associated file is stored in a PK4, a copy is written to the current |
| 190 |
* fs_game ("mod") folder and that file is used for the save operation. |
| 191 |
* No other particle declaration will be removed from the copied file. |
| 192 |
* |
| 193 |
* Note: this method does not check if the named particle system is already |
| 194 |
* defined in a different file. |
| 195 |
* |
| 196 |
* throws a std::runtime_error on any failure. |
| 197 |
*/ |
| 198 |
virtual void saveParticleDef(const std::string& particle) = 0; |
| 199 |
}; |
| 200 |
|
| 201 |
} // namespace |
| 202 |
|
| 203 |
constexpr const char* const MODULE_PARTICLESMANAGER = "ParticlesManager"; |
| 204 |
|
| 205 |
// Accessor |
| 206 |
inline particles::IParticlesManager& GlobalParticlesManager() |
| 207 |
{ |
| 208 |
static module::InstanceReference<particles::IParticlesManager> _reference(MODULE_PARTICLESMANAGER); |
| 209 |
return _reference; |
| 210 |
} |