DayZ 1.24
Loading...
Searching...
No Matches
Particle.c
Go to the documentation of this file.
1
6class Particle : ParticleBase
7{
13 protected int m_ParticleID;
15 protected float m_Lifetime;
17 protected bool m_IsRepeat;
19 private bool m_MarkedForDeletion;
21
38
46
51
53 protected int m_PreviousFrame;
57 static private const int MAX_EMITORS = 30;
58
59
61 void Particle()
62 {
64 }
65
67 protected void ParticleInit()
68 {
69 SetFlags(EntityFlags.VISIBLE, true);
70 SetEventMask(EntityEvent.INIT);
71 SetEventMask(EntityEvent.FRAME);
72 }
73
78
89 {
90 if (!parent_obj)
91 Error("ERROR when creating a particle! Parameter parent_obj is NULL!");
92
93 vector global_pos = parent_obj.GetPosition();
96 p.m_DefaultOri = local_ori;
97
98 return p;
99 }
100
108
118 {
119 Particle p = Particle.Cast(GetGame().CreateObjectEx("Particle", global_pos, ECE_LOCAL));
120 p.SetSource(particle_id);
121 p.SetOrientation(global_ori);
122 p.m_ForceOrientationRelativeToWorld = force_world_rotation;
123 return p;
124 }
125
133
135
136
141
152 {
154 p.PlayParticle();
155
156 return p;
157 }
158
166
174 {
176 p.PlayParticle();
177
178 return p;
179 }
180
188
190
191
196
201 override void PlayParticle(int particle_id = -1)
202 {
204 }
205
213 override bool PlayParticleEx(int particle_id = -1, int flags = 0)
214 {
215 if (particle_id > -1)
217
219
220 UpdateState();
221
222 return true;
223 }
224
229 void Play(int particle_id = -1)
230 {
232 }
233
241 override bool StopParticle(int flags = 0)
242 {
244
245 // Without the following we might get an error when a particle parent is despawned client-side.
246 Object parent = Object.Cast(GetParent());
247 if (parent && !ToDelete())
248 {
250 parent.RemoveChild(this);
252 }
253
254 UpdateState();
255
256 return true;
257 }
258
262 void Stop()
263 {
264 StopParticle();
265 }
266
268
269
274
281 {
283 }
284
293 {
294 return m_ParticleID;
295 }
296
306
312 {
313 return m_ParentObject;
314 }
315
321 {
324
325 return false;
326 }
327
334 {
337
338 return 0;
339 }
340
345 bool IsRepeat()
346 {
348 {
349 bool repeat = false;
350
352
353 for (int i = 0; i < emitors; ++i)
354 {
356
357 if (repeat)
358 return true;
359 }
360 }
361
362 return false;
363 }
364
370 {
371 float lifetime_return = 0;
372
374 {
375 float lifetime_min = 0;
376 float lifetime_random = 0;
377 float effect_time = 0;
378
379 float lifetime_sum = 0;
380
382
383 for (int i = 0; i < emitors; ++i)
384 {
388
390
393 }
394 }
395
396 return lifetime_return;
397 }
398
400
401
406
411 protected void UpdateState()
412 {
413 if (m_IsPlaying == false && m_ParticleEffect)
415 else if (m_IsPlaying == true && m_ParticleEffect == null)
417 }
418
422 private void CreateParticleEffect()
423 {
424 if (!GetGame().IsServer() || !GetGame().IsMultiplayer())
425 {
427 if (fullPath == "")
428 {
429 ErrorEx("Could not play Particle as there is no valid particle id assigned.");
430 m_IsPlaying = false;
431 return;
432 }
433
434 if (m_ParticleEffect == null)
435 {
436 m_ParticleEffect = GetGame().CreateObjectEx("#particlesourceenf", vector.Zero, ECE_LOCAL); // particle source must be lowercase!
437 }
438
440
442 m_ParticleEffect.SetObject(vobj, "");
444
447 }
448 }
449
457 {
458 if (m_ParticleEffect && GetGame())
459 {
460 SetParameter(-1, EmitorParam.LIFETIME, 0);
461 SetParameter(-1, EmitorParam.LIFETIME_RND, 0);
462 SetParameter(-1, EmitorParam.REPEAT, 0);
463
464 m_IsRepeat = false;
465 }
466 }
467
471 override void EOnFrame(IEntity other, float timeSlice)
472 {
475 }
476
481 {
482 if (m_Lifetime <= 0)
483 {
485 {
486 m_IsRepeat = IsRepeat(); // It is possible that the REPEAT flag was changed during lifetime, so it needs to be checked again.
487
488 if (m_IsRepeat)
490 else
491 {
493
494 if (GetParticleCount() == 0)
495 {
496 m_MarkedForDeletion = true;
497 OnToDelete();
499 }
500 }
501 }
502 else
503 {
505 {
507 {
508 m_ParticleEffect.Delete();
510 }
511
512 Delete();
513 }
514 }
515 }
516 }
517
521 private void OnToDelete()
522 {
523
524 }
525
527
528
533
542 void AddAsChild(Object parent, vector local_pos = "0 0 0", vector local_ori = "0 0 0", bool force_rotation_to_world = false)
543 {
544 if (ToDelete())
545 return;
546
547 if (parent)
548 {
549 // AddAsChild method is sometimes called from a timer.
550 // Due to that it is necesarry to use ToDelete() here to check if the parent object is flagged for deletion or not on client,
551 // because sometimes this code is executed before the parent's destructor from where this would normally be handled.
552 if (!parent.ToDelete())
553 {
555 SetOrientation(local_ori);
556 m_ParentObject = parent;
559
562
563 parent.AddChild(this, -1, false);
564 }
565 }
566 else
567 {
568 if (m_ParentObject && !m_ParentObject.ToDelete())
569 {
570 m_ParentObject.RemoveChild(this, true);
572 }
573 }
574 }
575
577
578
583
590 {
591 if (!m_ParticleEffect)
592 return;
593
595 }
596
603 void SetParameter(int emitter, int parameter, float value)
604 {
605 if (!m_ParticleEffect)
606 return;
607
609 }
610
617 void GetParameter(int emitter, int parameter, out float value)
618 {
619 if (!m_ParticleEffect)
620 return;
621
623 }
624
632 {
633 if (!m_ParticleEffect)
634 return 0;
635
636 float value;
638 return value;
639 }
640
647 {
648 if (!m_ParticleEffect)
649 return;
650
652 for (int i = 0; i < emitors; ++i)
653 {
654 float value;
657 }
658 }
659
665 void ScaleParticleParam(int parameter_id, float coef)
666 {
667 if (!m_ParticleEffect)
668 return;
669
671 for (int i = 0; i < emitors; ++i)
672 {
673 float value;
676 }
677 }
678
698
706 {
707 if (!m_ParticleEffect)
708 return;
709
711 for (int i = 0; i < emitors; ++i)
712 {
713 float param;
716 }
717 }
718
720
721
726
731 {
732 return m_RandomizeOri && m_RandomizeOri.IsRunning();
733 }
734
743 {
744 if (random_angle != 0 || random_interval != 0)
745 {
748
749 if (!m_RandomizeOri)
751
752 if (!m_RandomizeOri.IsRunning()) // Makes sure the timer is NOT running already
753 m_RandomizeOri.Run(Math.RandomFloat(0, m_MaxOriInterval), this, "RandomizeOrientation", null, false);
754 }
755 else
756 StopWiggle();
757 }
758
763 {
764 if (m_RandomizeOri)
765 m_RandomizeOri.Stop();
766
767 m_MaxOriWiggle = 0;
769 }
770
775 {
776 m_WiggleProcessing = true;
777
778 if (m_ParentObject)
779 {
780 if (!m_RandomizeOri.IsRunning())
781 m_RandomizeOri.Run(Math.RandomFloat(0, m_MaxOriInterval), this, "RandomizeOrientation", NULL, false);
782
786 }
787
788 m_WiggleProcessing = false;
789 }
790
795 {
797 }
798
802 protected float RandWiggleFloat()
803 {
805 }
806
808}
Object GetObject()
const int ECE_LOCAL
bool m_IsPlaying
Whether the Effect is currently playing.
Definition Effect.c:37
void OnParticleStart()
Event when the particle starts.
void OnParticleEnd()
Event when the particle ends.
void OnParticleStop()
Event when the particle stops.
int particle_id
class JsonUndergroundAreaTriggerData GetPosition
Definition EnMath.c:7
Legacy way of using particles in the game.
Definition Particle.c:7
bool m_IsRepeat
Whether this particle repeats.
Definition Particle.c:17
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.
Definition Particle.c:104
float GetMaxLifetime()
Returns the approx. max lifetime.
Definition Particle.c:369
bool m_MarkedForDeletion
Whether this particle is queued for deletion.
Definition Particle.c:19
void Particle()
ctor
Definition Particle.c:61
void SetWiggle(float random_angle, float random_interval)
Makes the particle change direction by random_angle every random_interval seconds.
Definition Particle.c:742
vector m_GlobalPosPreviousFrame
DEPRECATED.
Definition Particle.c:55
void ParticleInit()
Purely here so that it can be emptied in ParticleSource.
Definition Particle.c:67
vector m_DefaultPos
Used for Wiggle API, to restore after unparenting.
Definition Particle.c:33
override bool StopParticle(int flags=0)
Method to tell the particle to stop playing.
Definition Particle.c:241
void Play(int particle_id=-1)
Legacy function for backwards compatibility with 1.01 and below.
Definition Particle.c:229
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.
Definition Particle.c:151
Object m_ParticleEffect
The child object which contains the actual particle.
Definition Particle.c:50
bool HasActiveParticle()
Returns if there is any particle active.
Definition Particle.c:320
vector m_DefaultWorldOri
Used for Wiggle API, to restore after unparenting.
Definition Particle.c:35
void ScaleParticleParamFromOriginal(int parameter_id, float coef)
Scales the given parameter on all emitors relatively to their ORIGINAL value.
Definition Particle.c:646
vector m_DefaultOri
Used for Wiggle API, to restore after unparenting.
Definition Particle.c:31
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.
Definition Particle.c:117
Object GetParticleParent()
Returns the parent of this Particle if there is one.
Definition Particle.c:311
bool m_ForceOrientationRelativeToWorld
Used for Wiggle API, to restore after unparenting.
Definition Particle.c:29
int GetParticleCount()
Returns the total count of active particles in all emitors.
Definition Particle.c:333
static Particle PlayInWorld(int particle_id, vector global_pos)
Creates a particle emitter on the given position and activates it.
Definition Particle.c:173
void SetSource(int particle_id)
Sets particle id.
Definition Particle.c:280
void ScaleParticleParam(int parameter_id, float coef)
Scales the given parameter on all emitors relatively to their CURRENT value.
Definition Particle.c:665
void AddAsChild(Object parent, vector local_pos="0 0 0", vector local_ori="0 0 0", bool force_rotation_to_world=false)
Attaches this particle onto some object. If null value is provided then the particle will be detached...
Definition Particle.c:542
override void PlayParticle(int particle_id=-1)
Method to tell the particle to start playing.
Definition Particle.c:201
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.
Definition Particle.c:88
bool m_WiggleProcessing
Used for Wiggle API, to signal that wiggle API is currently doing work.
Definition Particle.c:27
override bool PlayParticleEx(int particle_id=-1, int flags=0)
Method to tell the particle to start playing.
Definition Particle.c:213
const int MAX_EMITORS
DEPRECATED.
Definition Particle.c:57
void SetParticleParam(int parameter_id, float value)
Set the value of a parameter of all emitors in the particle.
Definition Particle.c:589
static Particle Play(int particle_id, vector global_pos)
Legacy function for backwards compatibility with 1.01 and below.
Definition Particle.c:184
int GetParticleID()
Gets particle id.
Definition Particle.c:292
void OnCheckAutoDelete()
Creates ParticleEffect child, called from UpdateState.
Definition Particle.c:480
void CreateParticleEffect()
Creates ParticleEffect child, called from UpdateState.
Definition Particle.c:422
int m_PreviousFrame
DEPRECATED.
Definition Particle.c:53
vector m_DefaultWorldPos
Used for Wiggle API, to restore after unparenting.
Definition Particle.c:37
void SetParameter(int emitter, int parameter, float value)
Set the value of a parameter of an emitor in the particle.
Definition Particle.c:603
float m_Lifetime
Approx. remaining lifetime of particle.
Definition Particle.c:15
void DestroyParticleEffect()
Destroys ParticleEffect child, called from UpdateState.
Definition Particle.c:456
vector RandWiggleVector()
Helper to get a randomized wiggle vector.
Definition Particle.c:794
Object m_ParentObject
Parent Object the Particle is child of.
Definition Particle.c:48
int m_ParticleID
ID from ParticleList if assigned.
Definition Particle.c:13
void GetParameter(int emitter, int parameter, out float value)
Get the value of a parameter of an emitor in the particle.
Definition Particle.c:617
void RandomizeOrientation()
Randomizes a new orientation and applies it.
Definition Particle.c:774
bool IsRepeat()
Returns whether there is a repeating particle.
Definition Particle.c:345
float GetParameterEx(int emitter, int parameter)
Get the value of a parameter of an emitor in the particle.
Definition Particle.c:631
void UpdateState()
Creates/Destroys ParticleEffect child according to current state.
Definition Particle.c:411
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.
Definition Particle.c:162
float m_MaxOriWiggle
Used for Wiggle API, Wiggle room [-m_MaxOriWiggle, m_MaxOriWiggle].
Definition Particle.c:40
float m_MaxOriInterval
Used for Wiggle API, Interval for wiggling [0, m_MaxOriInterval[.
Definition Particle.c:42
float RandWiggleFloat()
Helper to get a randomized wiggle float value.
Definition Particle.c:802
void OnToDelete()
Called before deletion from OnCheckAutoDelete.
Definition Particle.c:521
void IncrementParticleParamFromOriginal(int parameter_id, float value)
Increments the value of the given parameter relatively from the ORIGINAL value.
Definition Particle.c:685
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.
Definition Particle.c:129
override void EOnFrame(IEntity other, float timeSlice)
OnFrame update event decrementing the stored approx. lifetime and checking for deletion.
Definition Particle.c:471
void StopWiggle()
Stops randomized wiggle.
Definition Particle.c:762
void Stop()
Legacy function for backwards compatibility with 1.14 and below.
Definition Particle.c:262
Object GetDirectParticleEffect()
Returns direct particle effect entity which is usually handled by this class 'Particle' if there is o...
Definition Particle.c:302
ref Timer m_RandomizeOri
Used for Wiggle API, calls the Wiggle functionality.
Definition Particle.c:44
void IncrementParticleParam(int parameter_id, float value)
Increments the value of the given parameter relatively from the CURRENT value.
Definition Particle.c:705
bool IsWiggling()
Checks if particle is currently wiggling.
Definition Particle.c:730
static string GetParticleFullPath(int particle_id)
Returns particle's full path (with .ptc suffix) based on its ID.
static const vector Zero
Definition EnConvert.c:110
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
enum ShapeType ErrorEx
proto native void SetPosition(vector position)
Set the world position of the Effect.
Definition Effect.c:420
proto native void SetFlags(ShapeFlags flags)
EntityEvent
Entity events for event-mask, or throwing event from code.
Definition EnEntity.c:44
EntityFlags
Entity flags.
Definition EnEntity.c:114
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static float RandomFloatInclusive(float min, float max)
Returns a random float number between and min [inclusive] and max [inclusive].
Definition EnMath.c:106
static proto float RandomFloat(float min, float max)
Returns a random float number between and min[inclusive] and max[exclusive].
proto void SetParticleParm(notnull IEntity ent, int emitor, EmitorParam parameter, void value)
bool ParticleHasActive(IEntity ent)
Definition EnVisual.c:210
proto void GetParticleParmOriginal(notnull IEntity ent, int emitor, EmitorParam parameter, out void value)
int ParticleGetCount(IEntity ent)
Definition EnVisual.c:205
proto int GetParticleEmitorCount(notnull IEntity ent)
EmitorParam
Definition EnVisual.c:114
proto void GetParticleParm(notnull IEntity ent, int emitor, EmitorParam parameter, out void value)
const int CALL_CATEGORY_GAMEPLAY
Definition tools.c:10
proto native void ReleaseObject(vobject object, int flag=0)
proto native Widget GetParent()
Get parent of the Effect.
Definition Effect.c:389
proto native void AddChild(Widget child, bool immedUpdate=true)