Fix infinite loop detection when placing players randomly on the newer random map...
[0ad.git] / source / graphics / ParticleEmitterType.h
blobfa76a3131990de8d84c15152089fcab3c13f9663
1 /* Copyright (C) 2011 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef INCLUDED_PARTICLEEMITTERTYPE
19 #define INCLUDED_PARTICLEEMITTERTYPE
21 #include "graphics/Texture.h"
22 #include "lib/ogl.h"
23 #include "lib/file/vfs/vfs_path.h"
24 #include "maths/BoundingBoxAligned.h"
26 class CVector3D;
27 class CParticleEmitter;
28 class CParticleManager;
29 class IParticleVar;
30 class IParticleEffector;
32 /**
33 * Particle emitter type - stores the common state data for all emitters of that
34 * type, and uses that data to update the emitter states.
36 * The data is initialised from XML files.
38 * Most of the emitter type data is represented as subclasses of IParticleVar,
39 * which will typically return a constant value or a random value each time it's
40 * evaluated. New subclasses can be added to support different random distributions,
41 * etc.
43 class CParticleEmitterType
45 NONCOPYABLE(CParticleEmitterType); // reference member
46 public:
47 CParticleEmitterType(const VfsPath& path, CParticleManager& manager);
49 private:
50 friend class CModelParticleEmitter;
51 friend class CParticleEmitter;
52 friend class CParticleVarConstant;
53 friend class CParticleVarUniform;
54 friend class CParticleVarCopy;
55 friend class ParticleRenderer;
57 enum
59 VAR_EMISSIONRATE,
60 VAR_LIFETIME,
61 VAR_POSITION_X,
62 VAR_POSITION_Y,
63 VAR_POSITION_Z,
64 VAR_ANGLE,
65 VAR_VELOCITY_X,
66 VAR_VELOCITY_Y,
67 VAR_VELOCITY_Z,
68 VAR_VELOCITY_ANGLE,
69 VAR_SIZE,
70 VAR_SIZE_GROWTHRATE,
71 VAR_COLOR_R,
72 VAR_COLOR_G,
73 VAR_COLOR_B,
74 VAR__MAX
77 int GetVariableID(const std::string& name);
79 bool LoadXML(const VfsPath& path);
81 /**
82 * Update the state of an emitter's particles, by a potentially long time @p dt.
84 void UpdateEmitter(CParticleEmitter& emitter, float dt);
86 /**
87 * Update the state of an emitter's particles, by a short time @p dt that can
88 * be computed in a single step.
90 void UpdateEmitterStep(CParticleEmitter& emitter, float dt);
92 CBoundingBoxAligned CalculateBounds(CVector3D emitterPos, CBoundingBoxAligned emittedBounds);
94 CTexturePtr m_Texture;
96 GLenum m_BlendEquation;
97 GLenum m_BlendFuncSrc;
98 GLenum m_BlendFuncDst;
99 bool m_StartFull;
100 bool m_UseRelativeVelocity;
102 float m_MaxLifetime;
103 size_t m_MaxParticles;
104 CBoundingBoxAligned m_MaxBounds;
106 typedef shared_ptr<IParticleVar> IParticleVarPtr;
107 std::vector<IParticleVarPtr> m_Variables;
109 typedef shared_ptr<IParticleEffector> IParticleEffectorPtr;
110 std::vector<IParticleEffectorPtr> m_Effectors;
112 CParticleManager& m_Manager;
115 typedef shared_ptr<CParticleEmitterType> CParticleEmitterTypePtr;
117 #endif // INCLUDED_PARTICLEEMITTERTYPE