19 private bool m_MarkedForDeletion;
27 bool m_WiggleProcessing;
29 bool m_ForceOrientationRelativeToWorld;
42 float m_MaxOriInterval;
44 ref
Timer m_RandomizeOri;
55 private vector m_GlobalPosPreviousFrame;
57 static private const int MAX_EMITORS = 30;
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;
121 p.SetOrientation(global_ori);
122 p.m_ForceOrientationRelativeToWorld = force_world_rotation;
251 if ( parent && !ToDelete())
254 parent.RemoveChild(
this);
362 for (
int i = 0; i < emitors; ++i)
382 float lifetime_return = 0;
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;
429 DestroyParticleEffect();
433 CreateParticleEffect();
440 private void CreateParticleEffect()
447 ErrorEx(
"Could not play Particle as there is no valid particle id assigned.");
474 private void DestroyParticleEffect()
489 override void EOnFrame(
IEntity other,
float timeSlice)
498 void OnCheckAutoDelete()
502 if (!m_MarkedForDeletion)
516 m_MarkedForDeletion =
true;
524 if ( m_MarkedForDeletion )
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;
584 parent.AddChild(
this, -1,
false);
611 void SetParticleParam(
int parameter_id,
float value )
625 void SetParameter(
int emitter,
int parameter,
float value)
639 void GetParameter(
int emitter,
int parameter, out
float value)
653 float GetParameterEx(
int emitter,
int parameter)
663 float GetParameterOriginal(
int emitter,
int parameter)
678 void ScaleParticleParamFromOriginal(
int parameter_id,
float coef )
684 for (
int i = 0; i < emitors; ++i)
697 void ScaleParticleParam(
int parameter_id,
float coef )
703 for (
int i = 0; i < emitors; ++i)
717 void IncrementParticleParamFromOriginal(
int parameter_id,
float value )
723 for (
int i = 0; i < emitors; ++i)
737 void IncrementParticleParam(
int parameter_id,
float value )
743 for (
int i = 0; i < emitors; ++i)
765 return m_RandomizeOri && m_RandomizeOri.IsRunning();
775 void SetWiggle(
float random_angle,
float random_interval)
777 if ( random_angle != 0 || random_interval != 0 )
779 m_MaxOriWiggle = random_angle;
780 m_MaxOriInterval = random_interval;
782 if ( !m_RandomizeOri )
785 if ( !m_RandomizeOri.IsRunning() )
786 m_RandomizeOri.Run(
Math.RandomFloat(0, m_MaxOriInterval) ,
this,
"RandomizeOrientation", null,
false);
799 if ( m_RandomizeOri )
801 m_RandomizeOri.Stop();
805 m_MaxOriInterval = 0;
811 void RandomizeOrientation()
813 m_WiggleProcessing =
true;
817 if ( !m_RandomizeOri.IsRunning() )
819 m_RandomizeOri.Run(
Math.RandomFloat(0, m_MaxOriInterval) ,
this,
"RandomizeOrientation", NULL,
false);
827 m_WiggleProcessing =
false;
843 return Math.RandomFloatInclusive(-m_MaxOriWiggle, m_MaxOriWiggle);
Legacy way of using particles in the game.
bool m_IsRepeat
Whether this particle repeats.
static Particle Create(int particle_id, Object parent_obj, vector local_pos="0 0 0", vector local_ori="0 0 0")
Legacy function for backwards compatibility.
float GetMaxLifetime()
Returns the approx. max lifetime.
void ParticleInit()
Purely here so that it can be emptied in ParticleSource.
override bool StopParticle(int flags=0)
Method to tell the particle to stop playing.
void Play(int particle_id=-1)
Legacy function for backwards compatibility with 1.01 and below.
static Particle PlayOnObject(int particle_id, Object parent_obj, vector local_pos="0 0 0", vector local_ori="0 0 0", bool force_world_rotation=false)
Creates a particle emitter, attaches it on the given object and activates it.
Object m_ParticleEffect
The child object which contains the actual particle.
bool HasActiveParticle()
Returns if there is any particle active.
static Particle CreateInWorld(int particle_id, vector global_pos, vector global_ori="0 0 0", bool force_world_rotation=false)
Creates a particle emitter on the given position.
Object GetParticleParent()
Returns the parent of this Particle if there is one.
int GetParticleCount()
Returns the total count of active particles in all emitors.
static Particle PlayInWorld(int particle_id, vector global_pos)
Creates a particle emitter on the given position and activates it.
void SetSource(int particle_id)
Sets particle id.
override void PlayParticle(int particle_id=-1)
Method to tell the particle to start playing.
static Particle CreateOnObject(int particle_id, Object parent_obj, vector local_pos="0 0 0", vector local_ori="0 0 0", bool force_world_rotation=false)
Creates a particle emitter and attaches it on the given object.
override bool PlayParticleEx(int particle_id=-1, int flags=0)
Method to tell the particle to start playing.
static Particle Play(int particle_id, vector global_pos)
Legacy function for backwards compatibility with 1.01 and below.
int GetParticleID()
Gets particle id.
int m_PreviousFrame
DEPRECATED.
float m_Lifetime
Approx. remaining lifetime of particle.
vector RandWiggleVector()
Helper to get a randomized wiggle vector.
Object m_ParentObject
Parent Object the Particle is child of.
int m_ParticleID
ID from ParticleList if assigned.
bool IsRepeat()
Returns whether there is a repeating particle.
void UpdateState()
Creates/Destroys ParticleEffect child according to current state.
static Particle Play(int particle_id, Object parent_obj, vector local_pos="0 0 0", vector local_ori="0 0 0")
Legacy function for backwards compatibility with 1.01 and below.
float RandWiggleFloat()
Helper to get a randomized wiggle float value.
static Particle Create(int particle_id, vector global_pos, vector global_ori="0 0 0")
Legacy function for backwards compatibility with 1.01 and below.
void Stop()
Legacy function for backwards compatibility with 1.14 and below.
Object GetDirectParticleEffect()
Returns direct particle effect entity which is usually handled by this class 'Particle' if there is o...
bool m_IsPlaying
Whether the Effect is currently playing.
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
proto native void SetPosition(vector position)
Set the world position of the Effect.
proto native void SetFlags(ShapeFlags flags)
EntityEvent
Entity events for event-mask, or throwing event from code.
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
proto void SetParticleParm(notnull IEntity ent, int emitor, EmitorParam parameter, void value)
bool ParticleHasActive(IEntity ent)
proto void GetParticleParmOriginal(notnull IEntity ent, int emitor, EmitorParam parameter, out void value)
int ParticleGetCount(IEntity ent)
proto int GetParticleEmitorCount(notnull IEntity ent)
proto void GetParticleParm(notnull IEntity ent, int emitor, EmitorParam parameter, out void value)
class JsonUndergroundAreaTriggerData GetPosition
proto native vobject GetObject(string name)
Loads object from data, or gets it from cache. Object must be released when not used.
proto native void ReleaseObject(vobject object, int flag=0)
void OnParticleStart()
Event when the particle starts.
void OnParticleEnd()
Event when the particle ends.
void OnParticleStop()
Event when the particle stops.