18 #include "precompiled.h"
33 #include <boost/random/uniform_real.hpp>
218 virtual void Evaluate(std::vector<SParticle>& particles,
float dt) = 0;
236 virtual void Evaluate(std::vector<SParticle>& particles,
float dt)
240 for (
size_t i = 0; i < particles.size(); ++i)
241 particles[i].velocity += dv;
291 m_MaxBounds[0].Y = std::min(0.f, vmin.
Y*m_MaxLifetime + 0.5f*accel.
Y*m_MaxLifetime*m_MaxLifetime);
292 m_MaxBounds[0].Z = std::min(0.f, vmin.
Z*m_MaxLifetime + 0.5f*accel.
Z*m_MaxLifetime*m_MaxLifetime);
293 m_MaxBounds[1].X = std::max(0.f, vmax.
X*m_MaxLifetime + 0.5f*accel.
X*m_MaxLifetime*m_MaxLifetime);
294 m_MaxBounds[1].Y = std::max(0.f, vmax.
Y*m_MaxLifetime + 0.5f*accel.
Y*m_MaxLifetime*m_MaxLifetime);
295 m_MaxBounds[1].Z = std::max(0.f, vmax.
Z*m_MaxLifetime + 0.5f*accel.
Z*m_MaxLifetime*m_MaxLifetime);
297 if (accel.
X && 0 < -vmin.
X/accel.
X && -vmin.
X/accel.
X < m_MaxLifetime)
299 if (accel.
Y && 0 < -vmin.
Y/accel.
Y && -vmin.
Y/accel.
Y < m_MaxLifetime)
301 if (accel.
Z && 0 < -vmin.
Z/accel.
Z && -vmin.
Z/accel.
Z < m_MaxLifetime)
303 if (accel.
X && 0 < -vmax.
X/accel.
X && -vmax.
X/accel.
X < m_MaxLifetime)
305 if (accel.
Y && 0 < -vmax.
Y/accel.
Y && -vmax.
Y/accel.
Y < m_MaxLifetime)
307 if (accel.
Z && 0 < -vmax.
Z/accel.
Z && -vmax.
Z/accel.
Z < m_MaxLifetime)
327 if (name ==
"size")
return VAR_SIZE;
331 LOGWARNING(L
"Particle sets unknown variable '%hs'", name.c_str());
368 #define EL(x) int el_##x = XeroFile.GetElementID(#x)
369 #define AT(x) int at_##x = XeroFile.GetAttributeID(#x)
395 if (Child.GetNodeName() == el_texture)
398 textureProps.
SetWrap(GL_CLAMP_TO_EDGE);
401 else if (Child.GetNodeName() == el_blend)
403 CStr mode = Child.GetAttributes().GetNamedItem(at_mode);
410 else if (mode ==
"subtract")
416 else if (mode ==
"over")
422 else if (mode ==
"multiply")
429 else if (Child.GetNodeName() == el_start_full)
433 else if (Child.GetNodeName() == el_constant)
435 int id =
GetVariableID(Child.GetAttributes().GetNamedItem(at_name));
439 Child.GetAttributes().GetNamedItem(at_value).ToFloat()
443 else if (Child.GetNodeName() == el_uniform)
445 int id =
GetVariableID(Child.GetAttributes().GetNamedItem(at_name));
448 float min = Child.GetAttributes().GetNamedItem(at_min).ToFloat();
449 float max = Child.GetAttributes().GetNamedItem(at_max).ToFloat();
457 else if (Child.GetNodeName() == el_copy)
459 int id =
GetVariableID(Child.GetAttributes().GetNamedItem(at_name));
460 int from =
GetVariableID(Child.GetAttributes().GetNamedItem(at_from));
461 if (
id != -1 && from != -1)
464 else if (Child.GetNodeName() == el_expr)
466 int id =
GetVariableID(Child.GetAttributes().GetNamedItem(at_name));
467 CStr from = Child.GetAttributes().GetNamedItem(at_from);
468 float mul = Child.GetAttributes().GetNamedItem(at_mul).ToFloat();
469 float max = Child.GetAttributes().GetNamedItem(at_max).ToFloat();
473 else if (Child.GetNodeName() == el_force)
475 float x = Child.GetAttributes().GetNamedItem(at_x).ToFloat();
476 float y = Child.GetAttributes().GetNamedItem(at_y).ToFloat();
477 float z = Child.GetAttributes().GetNamedItem(at_z).ToFloat();
491 const float maxStepLength = 0.2f;
497 while (dt > maxStepLength)
523 for (
int i = 0; i < newParticles; ++i)
556 for (
size_t i = 0; i < emitter.
m_Particles.size(); ++i)
572 float a = std::min(1.f-ageFrac, 5.f*ageFrac);
585 bounds[0] += emitterPos;
586 bounds[1] += emitterPos;
588 bounds += emittedBounds;
shared_ptr< IParticleEffector > IParticleEffectorPtr
virtual float Compute(CParticleEmitterType &type, CParticleEmitter &emitter)
virtual CVector3D Max()=0
Returns maximum acceleration caused by this effector.
friend class CParticleVarConstant
Particle variable that returns a constant value.
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
CParticleVarConstant(float val)
virtual float Compute(CParticleEmitterType &type, CParticleEmitter &emitter)=0
bool m_Active
Whether this emitter is still emitting new particles.
PSRETURN Load(const PIVFS &vfs, const VfsPath &filename)
Load from an XML file (with invisible XMB caching).
Particle emitter type - stores the common state data for all emitters of that type, and uses that data to update the emitter states.
const PSRETURN PSRETURN_OK
virtual void Evaluate(std::vector< SParticle > &particles, float dt)=0
Updates all particles.
virtual float Min(CParticleEmitterType &type)
Returns the minimum value that Evaluate might ever return, for computing bounds.
virtual CVector3D Max()
Returns maximum acceleration caused by this effector.
CParticleVarUniform(float min, float max)
Represents the filename and GL parameters of a texture, for passing to CTextureManager::CreateTexture...
void AddParticle(const SParticle &particle)
Push a new particle onto the ring buffer.
virtual float Min(CParticleEmitterType &type)
Returns the minimum value that Evaluate might ever return, for computing bounds.
#define XERO_ITER_EL(parent_element, child_element)
virtual float Compute(CParticleEmitterType &type, CParticleEmitter &emitter)
Particle effector that applies a constant acceleration.
std::vector< SParticle > m_Particles
friend class CParticleVarCopy
float LastValue()
Returns the last value that Evaluate returned.
Particle variable that returns a uniformly-distributed random value.
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...
virtual float Max(CParticleEmitterType &type)=0
Returns the maximum value that Evaluate might ever return, for computing bounds.
Interface for particle effectors, which get evaluated every frame to update particles.
A terrible ad-hoc attempt at handling some particular variable calculation, which really needs to be ...
shared_ptr< IParticleVar > IParticleVarPtr
virtual float Compute(CParticleEmitterType &type, CParticleEmitter &emitter)
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
friend class CParticleVarUniform
boost::mt19937 m_RNG
Random number generator shared between all particle emitters.
virtual ~IParticleEffector()
CBoundingBoxAligned CalculateBounds(CVector3D emitterPos, CBoundingBoxAligned emittedBounds)
void UpdateEmitter(CParticleEmitter &emitter, float dt)
Update the state of an emitter's particles, by a potentially long time dt.
virtual float Min(CParticleEmitterType &type)
Returns the minimum value that Evaluate might ever return, for computing bounds.
float m_EmissionRoundingError
Interface for particle state variables, which get evaluated for each newly constructed particle...
virtual void Evaluate(std::vector< SParticle > &particles, float dt)
Updates all particles.
SColor4ub(* ConvertRGBColorTo4ub)(const RGBColor &src)
CParticleVarExpr(const CStr &from, float mul, float max)
CParticleVarCopy(int from)
virtual float Max(CParticleEmitterType &type)
Returns the maximum value that Evaluate might ever return, for computing bounds.
CParticleEffectorForce(float x, float y, float z)
virtual float Min(CParticleEmitterType &type)=0
Returns the minimum value that Evaluate might ever return, for computing bounds.
virtual float Compute(CParticleEmitterType &type, CParticleEmitter &emitter)
float Evaluate(CParticleEmitter &emitter)
Computes and returns a new value.
CParticleManager & m_Manager
CBoundingBoxAligned m_MaxBounds
XMBElement GetRoot() const
void Expand(float amount)
Expand the bounding box by the given amount in every direction.
virtual float Max(CParticleEmitterType &type)
Returns the maximum value that Evaluate might ever return, for computing bounds.
virtual float Max(CParticleEmitterType &type)
Returns the maximum value that Evaluate might ever return, for computing bounds.
Particle variable that returns the same value as some other variable (assuming that variable was eval...
CParticleEmitterType(const VfsPath &path, CParticleManager &manager)
virtual float Max(CParticleEmitterType &type)
Returns the maximum value that Evaluate might ever return, for computing bounds.
std::vector< IParticleEffectorPtr > m_Effectors
virtual float Min(CParticleEmitterType &type)
Returns the minimum value that Evaluate might ever return, for computing bounds.
std::map< std::string, float > m_EntityVariables
std::vector< IParticleVarPtr > m_Variables
void SetWrap(GLint wrap)
Set wrapping mode (typically GL_REPEAT, GL_CLAMP_TO_EDGE, etc).
T clamp(T value, T min, T max)
Simulation state for a single particle.
int GetVariableID(const std::string &name)
bool LoadXML(const VfsPath &path)
CParticleEmitterTypePtr m_Type