12 protected int m_ParticleID;
15 protected float m_Lifetime;
17 protected bool m_IsRepeat;
19 private bool m_MarkedForDeletion;
26 bool m_WiggleProcessing;
29 bool m_ForceOrientationRelativeToWorld;
42 float m_MaxOriInterval;
44 ref
Timer m_RandomizeOri;
48 protected Object m_ParentObject;
50 protected Object m_ParticleEffect;
53 protected int m_PreviousFrame;
55 private vector m_GlobalPosPreviousFrame;
57 static private const int MAX_EMITORS = 30;
67 protected void ParticleInit()
91 Error(
"ERROR when creating a particle! Parameter parent_obj is NULL!");
93 vector global_pos = parent_obj.GetPosition();
95 p.AddAsChild(parent_obj, local_pos, local_ori, force_world_rotation);
96 p.m_DefaultOri = local_ori;
106 return CreateOnObject(
particle_id, parent_obj, local_pos, local_ori);
121 p.SetOrientation(global_ori);
122 p.m_ForceOrientationRelativeToWorld = force_world_rotation;
131 return CreateInWorld(
particle_id, global_pos, global_ori );
154 Particle p = CreateOnObject(
particle_id, parent_obj, local_pos, local_ori, force_world_rotation);
165 return PlayOnObject(
particle_id, parent_obj, local_pos, local_ori);
215 override bool PlayParticleEx(
int particle_id = -1,
int flags = 0)
245 override bool StopParticle(
int flags = 0)
251 if ( parent && !ToDelete())
254 parent.RemoveChild(
this);
307 Object GetDirectParticleEffect()
309 return m_ParticleEffect;
316 Object GetParticleParent()
325 bool HasActiveParticle()
327 if (m_ParticleEffect)
340 int GetParticleCount()
342 if (m_ParticleEffect)
356 if (m_ParticleEffect)
362 for (
int i = 0; i < emitors; ++i)
380 float GetMaxLifetime()
382 float lifetime_return = 0;
384 if (m_ParticleEffect)
386 float lifetime_min = 0;
387 float lifetime_random = 0;
388 float effect_time = 0;
390 float lifetime_sum = 0;
394 for (
int i = 0; i < emitors; ++i)
400 lifetime_sum = lifetime_min + lifetime_random + effect_time;
402 if ( lifetime_sum > lifetime_return )
404 lifetime_return = lifetime_sum;
409 return lifetime_return;
425 protected void UpdateState()
429 DestroyParticleEffect();
431 else if (
m_IsPlaying ==
true && m_ParticleEffect ==
null )
433 CreateParticleEffect();
440 private void CreateParticleEffect()
444 string fullPath =
ParticleList.GetParticleFullPath(m_ParticleID);
447 ErrorEx(
"Could not play Particle as there is no valid particle id assigned.");
452 if ( m_ParticleEffect ==
null )
457 AddChild(m_ParticleEffect, -1, m_ForceOrientationRelativeToWorld);
460 m_ParticleEffect.SetObject(vobj,
"");
463 m_IsRepeat = IsRepeat();
474 private void DestroyParticleEffect()
476 if ( m_ParticleEffect &&
GetGame() )
489 override void EOnFrame(
IEntity other,
float timeSlice)
498 void OnCheckAutoDelete()
502 if (!m_MarkedForDeletion)
504 m_IsRepeat = IsRepeat();
514 if ( GetParticleCount() == 0 )
516 m_MarkedForDeletion =
true;
524 if ( m_MarkedForDeletion )
526 if (m_ParticleEffect)
528 m_ParticleEffect.Delete();
529 m_ParticleEffect =
null;
541 private void OnToDelete()
563 void AddAsChild(
Object parent,
vector local_pos =
"0 0 0",
vector local_ori =
"0 0 0",
bool force_rotation_to_world =
false)
573 if (!parent.ToDelete())
576 SetOrientation(local_ori);
578 m_DefaultPos = local_pos;
579 m_ForceOrientationRelativeToWorld = force_rotation_to_world;
581 if (m_ParticleEffect)
582 AddChild(m_ParticleEffect, -1, m_ForceOrientationRelativeToWorld);
584 parent.AddChild(
this, -1,
false);
611 void SetParticleParam(
int parameter_id,
float value )
613 if (!m_ParticleEffect)
625 void SetParameter(
int emitter,
int parameter,
float value)
627 if (!m_ParticleEffect)
639 void GetParameter(
int emitter,
int parameter, out
float value)
641 if (!m_ParticleEffect)
653 float GetParameterEx(
int emitter,
int parameter)
655 if (!m_ParticleEffect)
668 void ScaleParticleParamFromOriginal(
int parameter_id,
float coef )
670 if (!m_ParticleEffect)
674 for (
int i = 0; i < emitors; ++i)
687 void ScaleParticleParam(
int parameter_id,
float coef )
689 if (!m_ParticleEffect)
693 for (
int i = 0; i < emitors; ++i)
707 void IncrementParticleParamFromOriginal(
int parameter_id,
float value )
709 if (!m_ParticleEffect)
713 for (
int i = 0; i < emitors; ++i)
727 void IncrementParticleParam(
int parameter_id,
float value )
729 if (!m_ParticleEffect)
733 for (
int i = 0; i < emitors; ++i)
755 return m_RandomizeOri && m_RandomizeOri.IsRunning();
765 void SetWiggle(
float random_angle,
float random_interval)
767 if ( random_angle != 0 || random_interval != 0 )
769 m_MaxOriWiggle = random_angle;
770 m_MaxOriInterval = random_interval;
772 if ( !m_RandomizeOri )
775 if ( !m_RandomizeOri.IsRunning() )
776 m_RandomizeOri.Run(
Math.RandomFloat(0, m_MaxOriInterval) ,
this,
"RandomizeOrientation",
null,
false);
789 if ( m_RandomizeOri )
791 m_RandomizeOri.Stop();
795 m_MaxOriInterval = 0;
801 void RandomizeOrientation()
803 m_WiggleProcessing =
true;
807 if ( !m_RandomizeOri.IsRunning() )
809 m_RandomizeOri.Run(
Math.RandomFloat(0, m_MaxOriInterval) ,
this,
"RandomizeOrientation", NULL,
false);
814 AddAsChild( old_parent, m_DefaultPos, m_DefaultOri + RandWiggleVector() );
817 m_WiggleProcessing =
false;
823 protected vector RandWiggleVector()
825 return Vector( RandWiggleFloat(), RandWiggleFloat(), RandWiggleFloat() );
831 protected float RandWiggleFloat()
833 return Math.RandomFloatInclusive(-m_MaxOriWiggle, m_MaxOriWiggle);