Pyrogenesis trunk
ParticleEmitterType.h
Go to the documentation of this file.
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"
24
25#include <memory>
26#include <string>
27
28class CVector3D;
31class IParticleVar;
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 */
46{
47 NONCOPYABLE(CParticleEmitterType); // reference member
48public:
49 CParticleEmitterType(const VfsPath& path, CParticleManager& manager);
50
51private:
53 friend class CParticleEmitter;
55 friend class CParticleVarUniform;
56 friend class CParticleVarCopy;
57 friend class ParticleRenderer;
58
59 enum
60 {
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
103
105
109
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
121};
122
123typedef std::shared_ptr<CParticleEmitterType> CParticleEmitterTypePtr;
124
125#endif // INCLUDED_PARTICLEEMITTERTYPE
#define ADD(position)
std::shared_ptr< CParticleEmitterType > CParticleEmitterTypePtr
Definition: ParticleEmitterType.h:123
Definition: BoundingBoxAligned.h:34
Particle emitter model, for attaching emitters as props on other models.
Definition: ParticleEmitter.h:189
Particle emitter type - stores the common state data for all emitters of that type,...
Definition: ParticleEmitterType.h:46
CParticleManager & m_Manager
Definition: ParticleEmitterType.h:120
bool m_UseRelativeVelocity
Definition: ParticleEmitterType.h:108
CBoundingBoxAligned m_MaxBounds
Definition: ParticleEmitterType.h:112
std::shared_ptr< IParticleEffector > IParticleEffectorPtr
Definition: ParticleEmitterType.h:117
CBoundingBoxAligned CalculateBounds(CVector3D emitterPos, CBoundingBoxAligned emittedBounds)
Definition: ParticleEmitterType.cpp:582
BlendMode
Definition: ParticleEmitterType.h:80
NONCOPYABLE(CParticleEmitterType)
bool LoadXML(const VfsPath &path)
Definition: ParticleEmitterType.cpp:335
int GetVariableID(const std::string &name)
Definition: ParticleEmitterType.cpp:314
u16 m_MaxParticles
Definition: ParticleEmitterType.h:111
@ VAR_LIFETIME
Definition: ParticleEmitterType.h:62
@ VAR_COLOR_R
Definition: ParticleEmitterType.h:73
@ VAR_VELOCITY_ANGLE
Definition: ParticleEmitterType.h:70
@ VAR_COLOR_G
Definition: ParticleEmitterType.h:74
@ VAR_VELOCITY_X
Definition: ParticleEmitterType.h:67
@ VAR_EMISSIONRATE
Definition: ParticleEmitterType.h:61
@ VAR_POSITION_X
Definition: ParticleEmitterType.h:63
@ VAR_SIZE
Definition: ParticleEmitterType.h:71
@ VAR_VELOCITY_Z
Definition: ParticleEmitterType.h:69
@ VAR__MAX
Definition: ParticleEmitterType.h:76
@ VAR_SIZE_GROWTHRATE
Definition: ParticleEmitterType.h:72
@ VAR_COLOR_B
Definition: ParticleEmitterType.h:75
@ VAR_POSITION_Z
Definition: ParticleEmitterType.h:65
@ VAR_POSITION_Y
Definition: ParticleEmitterType.h:64
@ VAR_ANGLE
Definition: ParticleEmitterType.h:66
@ VAR_VELOCITY_Y
Definition: ParticleEmitterType.h:68
BlendMode m_BlendMode
Definition: ParticleEmitterType.h:106
std::vector< IParticleEffectorPtr > m_Effectors
Definition: ParticleEmitterType.h:118
CTexturePtr m_Texture
Definition: ParticleEmitterType.h:104
bool m_StartFull
Definition: ParticleEmitterType.h:107
std::shared_ptr< IParticleVar > IParticleVarPtr
Definition: ParticleEmitterType.h:114
void UpdateEmitterStep(CParticleEmitter &emitter, float dt)
Update the state of an emitter's particles, by a short time dt that can be computed in a single step.
Definition: ParticleEmitterType.cpp:494
std::vector< IParticleVarPtr > m_Variables
Definition: ParticleEmitterType.h:115
CParticleEmitterType(const VfsPath &path, CParticleManager &manager)
Definition: ParticleEmitterType.cpp:255
void UpdateEmitter(CParticleEmitter &emitter, float dt)
Update the state of an emitter's particles, by a potentially long time dt.
Definition: ParticleEmitterType.cpp:473
float m_MaxLifetime
Definition: ParticleEmitterType.h:110
Particle emitter.
Definition: ParticleEmitter.h:69
Definition: ParticleManager.h:31
Particle variable that returns a constant value.
Definition: ParticleEmitterType.cpp:83
Particle variable that returns the same value as some other variable (assuming that variable was eval...
Definition: ParticleEmitterType.cpp:145
Particle variable that returns a uniformly-distributed random value.
Definition: ParticleEmitterType.cpp:113
Definition: Vector3D.h:31
Interface for particle effectors, which get evaluated every frame to update particles.
Definition: ParticleEmitterType.cpp:211
Interface for particle state variables, which get evaluated for each newly constructed particle.
Definition: ParticleEmitterType.cpp:40
Render particles.
Definition: ParticleRenderer.h:31
Definition: path.h:80
std::shared_ptr< CTexture > CTexturePtr
Definition: Texture.h:23
uint16_t u16
Definition: types.h:38