2026-02-09 12:29:42 -08:00
|
|
|
/* Copyright (C) 2026 Wildfire Games.
|
2023-12-02 16:30:12 -08:00
|
|
|
* This file is part of 0 A.D.
|
2011-04-03 12:15:15 -07:00
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2011-04-03 12:15:15 -07:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2011-04-03 12:15:15 -07:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2023-12-02 16:30:12 -08:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2011-04-03 12:15:15 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef INCLUDED_PARTICLEEMITTERTYPE
|
|
|
|
|
#define INCLUDED_PARTICLEEMITTERTYPE
|
|
|
|
|
|
|
|
|
|
#include "graphics/Texture.h"
|
2025-07-28 11:13:46 -07:00
|
|
|
#include "lib/code_annotation.h"
|
2011-04-03 12:15:15 -07:00
|
|
|
#include "lib/file/vfs/vfs_path.h"
|
2025-07-28 11:13:46 -07:00
|
|
|
#include "lib/types.h"
|
2011-11-24 22:36:13 -08:00
|
|
|
#include "maths/BoundingBoxAligned.h"
|
2011-04-03 12:15:15 -07:00
|
|
|
|
2022-01-19 09:28:47 -08:00
|
|
|
#include <memory>
|
|
|
|
|
#include <string>
|
2025-07-28 11:13:46 -07:00
|
|
|
#include <vector>
|
2022-01-19 09:28:47 -08:00
|
|
|
|
2011-04-03 12:15:15 -07:00
|
|
|
class CParticleEmitter;
|
|
|
|
|
class CParticleManager;
|
2025-07-28 11:13:46 -07:00
|
|
|
class CVector3D;
|
2011-04-05 17:11:40 -07:00
|
|
|
class IParticleEffector;
|
2025-07-28 11:13:46 -07:00
|
|
|
class IParticleVar;
|
2011-04-03 12:15:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Particle emitter type - stores the common state data for all emitters of that
|
|
|
|
|
* type, and uses that data to update the emitter states.
|
|
|
|
|
*
|
|
|
|
|
* The data is initialised from XML files.
|
|
|
|
|
*
|
|
|
|
|
* Most of the emitter type data is represented as subclasses of IParticleVar,
|
|
|
|
|
* which will typically return a constant value or a random value each time it's
|
|
|
|
|
* evaluated. New subclasses can be added to support different random distributions,
|
|
|
|
|
* etc.
|
|
|
|
|
*/
|
|
|
|
|
class CParticleEmitterType
|
|
|
|
|
{
|
2011-04-03 13:45:43 -07:00
|
|
|
NONCOPYABLE(CParticleEmitterType); // reference member
|
2011-04-03 12:15:15 -07:00
|
|
|
public:
|
|
|
|
|
CParticleEmitterType(const VfsPath& path, CParticleManager& manager);
|
|
|
|
|
|
|
|
|
|
private:
|
2011-04-29 05:26:31 -07:00
|
|
|
friend class CModelParticleEmitter;
|
2011-04-03 12:15:15 -07:00
|
|
|
friend class CParticleEmitter;
|
|
|
|
|
friend class CParticleVarConstant;
|
|
|
|
|
friend class CParticleVarUniform;
|
|
|
|
|
friend class CParticleVarCopy;
|
2011-04-29 05:26:31 -07:00
|
|
|
friend class ParticleRenderer;
|
2011-04-03 12:15:15 -07:00
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
VAR_EMISSIONRATE,
|
|
|
|
|
VAR_LIFETIME,
|
2011-04-05 17:11:40 -07:00
|
|
|
VAR_POSITION_X,
|
|
|
|
|
VAR_POSITION_Y,
|
|
|
|
|
VAR_POSITION_Z,
|
2011-04-03 12:15:15 -07:00
|
|
|
VAR_ANGLE,
|
|
|
|
|
VAR_VELOCITY_X,
|
|
|
|
|
VAR_VELOCITY_Y,
|
|
|
|
|
VAR_VELOCITY_Z,
|
|
|
|
|
VAR_VELOCITY_ANGLE,
|
|
|
|
|
VAR_SIZE,
|
2013-12-04 09:21:59 -08:00
|
|
|
VAR_SIZE_GROWTHRATE,
|
2011-04-03 12:15:15 -07:00
|
|
|
VAR_COLOR_R,
|
|
|
|
|
VAR_COLOR_G,
|
|
|
|
|
VAR_COLOR_B,
|
|
|
|
|
VAR__MAX
|
|
|
|
|
};
|
|
|
|
|
|
2022-01-19 09:28:47 -08:00
|
|
|
enum class BlendMode
|
|
|
|
|
{
|
|
|
|
|
ADD,
|
|
|
|
|
SUBTRACT,
|
|
|
|
|
OVERLAY,
|
|
|
|
|
MULTIPLY
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-09 12:29:42 -08:00
|
|
|
enum class SortMode
|
|
|
|
|
{
|
|
|
|
|
UNSPECIFIED,
|
|
|
|
|
YOUNGEST_IN_FRONT,
|
|
|
|
|
OLDEST_IN_FRONT,
|
|
|
|
|
CLOSEST_IN_FRONT
|
|
|
|
|
};
|
|
|
|
|
|
2011-04-03 12:15:15 -07:00
|
|
|
int GetVariableID(const std::string& name);
|
|
|
|
|
|
|
|
|
|
bool LoadXML(const VfsPath& path);
|
|
|
|
|
|
2011-04-29 05:26:31 -07:00
|
|
|
/**
|
|
|
|
|
* Update the state of an emitter's particles, by a potentially long time @p dt.
|
|
|
|
|
*/
|
2011-04-03 12:15:15 -07:00
|
|
|
void UpdateEmitter(CParticleEmitter& emitter, float dt);
|
|
|
|
|
|
2011-04-29 05:26:31 -07:00
|
|
|
/**
|
|
|
|
|
* Update the state of an emitter's particles, by a short time @p dt that can
|
|
|
|
|
* be computed in a single step.
|
|
|
|
|
*/
|
|
|
|
|
void UpdateEmitterStep(CParticleEmitter& emitter, float dt);
|
|
|
|
|
|
2011-11-24 22:36:13 -08:00
|
|
|
CBoundingBoxAligned CalculateBounds(CVector3D emitterPos, CBoundingBoxAligned emittedBounds);
|
2011-04-29 05:26:31 -07:00
|
|
|
|
2011-04-03 12:15:15 -07:00
|
|
|
CTexturePtr m_Texture;
|
|
|
|
|
|
2026-02-09 12:29:42 -08:00
|
|
|
BlendMode m_BlendMode{BlendMode::ADD};
|
|
|
|
|
SortMode m_SortMode{SortMode::UNSPECIFIED};
|
2011-04-29 05:26:31 -07:00
|
|
|
bool m_StartFull;
|
2026-02-17 10:33:26 -08:00
|
|
|
bool m_UseLocalSpace{false};
|
|
|
|
|
bool m_UseRelativePosition{false}, m_UseRelativeVelocity{false};
|
|
|
|
|
|
|
|
|
|
// A non-zero vector in case of a fixed axis for the corresponding direction.
|
|
|
|
|
CVector3D m_AxisX{}, m_AxisY{};
|
|
|
|
|
bool m_UseRelativeAxisX{false}, m_UseRelativeAxisY{false};
|
|
|
|
|
|
|
|
|
|
bool m_UseVelocityAsAxisX{false};
|
2016-11-23 03:18:37 -08:00
|
|
|
|
2011-04-29 05:26:31 -07:00
|
|
|
float m_MaxLifetime;
|
2020-11-26 14:28:50 -08:00
|
|
|
u16 m_MaxParticles;
|
2011-11-24 22:36:13 -08:00
|
|
|
CBoundingBoxAligned m_MaxBounds;
|
2011-04-03 12:15:15 -07:00
|
|
|
|
2021-05-22 12:21:33 -07:00
|
|
|
typedef std::shared_ptr<IParticleVar> IParticleVarPtr;
|
2011-04-03 12:15:15 -07:00
|
|
|
std::vector<IParticleVarPtr> m_Variables;
|
|
|
|
|
|
2021-05-22 12:21:33 -07:00
|
|
|
typedef std::shared_ptr<IParticleEffector> IParticleEffectorPtr;
|
2011-04-05 17:11:40 -07:00
|
|
|
std::vector<IParticleEffectorPtr> m_Effectors;
|
|
|
|
|
|
2011-04-03 12:15:15 -07:00
|
|
|
CParticleManager& m_Manager;
|
|
|
|
|
};
|
|
|
|
|
|
2021-05-22 12:21:33 -07:00
|
|
|
typedef std::shared_ptr<CParticleEmitterType> CParticleEmitterTypePtr;
|
2011-04-03 12:15:15 -07:00
|
|
|
|
|
|
|
|
#endif // INCLUDED_PARTICLEEMITTERTYPE
|