Line data Source code
1 : /* Copyright (C) 2022 Wildfire Games.
2 : * This file is part of 0 A.D.
3 : *
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.
8 : *
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.
13 : *
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/>.
16 : */
17 :
18 : #ifndef INCLUDED_PARTICLEEMITTERTYPE
19 : #define INCLUDED_PARTICLEEMITTERTYPE
20 :
21 : #include "graphics/Texture.h"
22 : #include "lib/file/vfs/vfs_path.h"
23 : #include "maths/BoundingBoxAligned.h"
24 :
25 : #include <memory>
26 : #include <string>
27 :
28 : class CVector3D;
29 : class CParticleEmitter;
30 : class CParticleManager;
31 : class IParticleVar;
32 : class IParticleEffector;
33 :
34 : /**
35 : * Particle emitter type - stores the common state data for all emitters of that
36 : * type, and uses that data to update the emitter states.
37 : *
38 : * The data is initialised from XML files.
39 : *
40 : * Most of the emitter type data is represented as subclasses of IParticleVar,
41 : * which will typically return a constant value or a random value each time it's
42 : * evaluated. New subclasses can be added to support different random distributions,
43 : * etc.
44 : */
45 0 : class CParticleEmitterType
46 : {
47 : NONCOPYABLE(CParticleEmitterType); // reference member
48 : public:
49 : CParticleEmitterType(const VfsPath& path, CParticleManager& manager);
50 :
51 : private:
52 : friend class CModelParticleEmitter;
53 : friend class CParticleEmitter;
54 : friend class CParticleVarConstant;
55 : friend class CParticleVarUniform;
56 : friend class CParticleVarCopy;
57 : friend class ParticleRenderer;
58 :
59 : enum
60 : {
61 : VAR_EMISSIONRATE,
62 : VAR_LIFETIME,
63 : VAR_POSITION_X,
64 : VAR_POSITION_Y,
65 : VAR_POSITION_Z,
66 : VAR_ANGLE,
67 : VAR_VELOCITY_X,
68 : VAR_VELOCITY_Y,
69 : VAR_VELOCITY_Z,
70 : VAR_VELOCITY_ANGLE,
71 : VAR_SIZE,
72 : VAR_SIZE_GROWTHRATE,
73 : VAR_COLOR_R,
74 : VAR_COLOR_G,
75 : VAR_COLOR_B,
76 : VAR__MAX
77 : };
78 :
79 : enum class BlendMode
80 : {
81 : ADD,
82 : SUBTRACT,
83 : OVERLAY,
84 : MULTIPLY
85 : };
86 :
87 : int GetVariableID(const std::string& name);
88 :
89 : bool LoadXML(const VfsPath& path);
90 :
91 : /**
92 : * Update the state of an emitter's particles, by a potentially long time @p dt.
93 : */
94 : void UpdateEmitter(CParticleEmitter& emitter, float dt);
95 :
96 : /**
97 : * Update the state of an emitter's particles, by a short time @p dt that can
98 : * be computed in a single step.
99 : */
100 : void UpdateEmitterStep(CParticleEmitter& emitter, float dt);
101 :
102 : CBoundingBoxAligned CalculateBounds(CVector3D emitterPos, CBoundingBoxAligned emittedBounds);
103 :
104 : CTexturePtr m_Texture;
105 :
106 : BlendMode m_BlendMode = BlendMode::ADD;
107 : bool m_StartFull;
108 : bool m_UseRelativeVelocity;
109 :
110 : float m_MaxLifetime;
111 : u16 m_MaxParticles;
112 : CBoundingBoxAligned m_MaxBounds;
113 :
114 : typedef std::shared_ptr<IParticleVar> IParticleVarPtr;
115 : std::vector<IParticleVarPtr> m_Variables;
116 :
117 : typedef std::shared_ptr<IParticleEffector> IParticleEffectorPtr;
118 : std::vector<IParticleEffectorPtr> m_Effectors;
119 :
120 : CParticleManager& m_Manager;
121 : };
122 :
123 : typedef std::shared_ptr<CParticleEmitterType> CParticleEmitterTypePtr;
124 :
125 : #endif // INCLUDED_PARTICLEEMITTERTYPE
|