DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
Particle.c
См. документацию.
1
7{
12
13 protected int m_ParticleID;
15 protected float m_Lifetime;
17 protected bool m_IsRepeat;
19 private bool m_MarkedForDeletion;
21
26
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
88 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 )
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();
94 Particle p = CreateInWorld(particle_id, global_pos, Vector(0,0,0), force_world_rotation);
95 p.AddAsChild(parent_obj, local_pos, local_ori, force_world_rotation);
96 p.m_DefaultOri = local_ori;
97
98 return p;
99 }
100
104 static Particle Create( int particle_id, Object parent_obj, vector local_pos = "0 0 0", vector local_ori = "0 0 0" )
105 {
106 return CreateOnObject( particle_id, parent_obj, local_pos, local_ori);
107 }
108
117 static Particle CreateInWorld( int particle_id, vector global_pos, vector global_ori = "0 0 0", bool force_world_rotation = false )
118 {
119 Particle p = Particle.Cast( GetGame().CreateObjectEx("Particle", global_pos, ECE_LOCAL) );
121 p.SetOrientation(global_ori);
122 p.m_ForceOrientationRelativeToWorld = force_world_rotation;
123 return p;
124 }
125
129 static Particle Create( int particle_id, vector global_pos, vector global_ori = "0 0 0" )
130 {
131 return CreateInWorld( particle_id, global_pos, global_ori );
132 }
133
135
136
137
142
152 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 )
153 {
154 Particle p = CreateOnObject(particle_id, parent_obj, local_pos, local_ori, force_world_rotation);
155 p.PlayParticle();
156
157 return p;
158 }
159
163 static Particle Play( int particle_id, Object parent_obj, vector local_pos = "0 0 0", vector local_ori = "0 0 0" )
164 {
165 return PlayOnObject( particle_id, parent_obj, local_pos, local_ori);
166 }
167
174 static Particle PlayInWorld( int particle_id, vector global_pos)
175 {
176 Particle p = CreateInWorld(particle_id, global_pos);
177 p.PlayParticle();
178
179 return p;
180 }
181
185 static Particle Play( int particle_id, vector global_pos)
186 {
187 return PlayInWorld( particle_id, global_pos);
188 }
189
191
192
193
198
203 override void PlayParticle(int particle_id = -1)
204 {
206 }
207
215 override bool PlayParticleEx(int particle_id = -1, int flags = 0)
216 {
217 if ( particle_id > -1 )
218 {
220 }
221
223
224 UpdateState();
225
226 return true;
227 }
228
233 void Play(int particle_id = -1)
234 {
236 }
237
245 override bool StopParticle(int flags = 0)
246 {
248
249 // Without the following we might get an error when a particle parent is despawned client-side.
250 Object parent = Object.Cast( GetParent() );
251 if ( parent && !ToDelete())
252 {
253 vector world_pos = GetPosition();
254 parent.RemoveChild(this);
255 SetPosition(world_pos);
256 }
257
258 UpdateState();
259
260 return true;
261 }
262
266 void Stop()
267 {
268 StopParticle();
269 }
270
272
273
274
279
286 {
288 }
289
298 {
299 return m_ParticleID;
300 }
301
311
317 {
318 return m_ParentObject;
319 }
320
326 {
328 {
330 }
331
332 return false;
333 }
334
341 {
343 {
345 }
346
347 return 0;
348 }
349
354 bool IsRepeat()
355 {
357 {
358 bool repeat = false;
359
361
362 for (int i = 0; i < emitors; ++i)
363 {
364 GetParticleParm(m_ParticleEffect, i, EmitorParam.REPEAT, repeat);
365
366 if (repeat)
367 {
368 return true;
369 }
370 }
371 }
372
373 return false;
374 }
375
381 {
382 float lifetime_return = 0;
383
385 {
386 float lifetime_min = 0;
387 float lifetime_random = 0;
388 float effect_time = 0;
389
390 float lifetime_sum = 0;
391
393
394 for (int i = 0; i < emitors; ++i)
395 {
396 GetParticleParm(m_ParticleEffect, i, EmitorParam.LIFETIME, lifetime_min);
397 GetParticleParm(m_ParticleEffect, i, EmitorParam.LIFETIME_RND, lifetime_random);
398 GetParticleParm(m_ParticleEffect, i, EmitorParam.EFFECT_TIME, effect_time);
399
400 lifetime_sum = lifetime_min + lifetime_random + effect_time;
401
402 if ( lifetime_sum > lifetime_return )
403 {
404 lifetime_return = lifetime_sum;
405 }
406 }
407 }
408
409 return lifetime_return;
410 }
411
413
414
415
420
425 protected void UpdateState()
426 {
427 if ( m_IsPlaying == false && m_ParticleEffect)
428 {
430 }
431 else if ( m_IsPlaying == true && m_ParticleEffect == null )
432 {
434 }
435 }
436
440 private void CreateParticleEffect()
441 {
442 if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() )
443 {
445 if (fullPath == "")
446 {
447 ErrorEx("Could not play Particle as there is no valid particle id assigned.");
448 m_IsPlaying = false;
449 return;
450 }
451
452 if ( m_ParticleEffect == null )
453 {
454 m_ParticleEffect = GetGame().CreateObjectEx("#particlesourceenf", vector.Zero, ECE_LOCAL); // particle source must be lowercase!
455 }
456
458
459 vobject vobj = GetObject( fullPath );
460 m_ParticleEffect.SetObject(vobj, "");
461 ReleaseObject(vobj);
462
465 }
466 }
467
475 {
476 if ( m_ParticleEffect && GetGame() )
477 {
478 SetParameter(-1, EmitorParam.LIFETIME, 0);
479 SetParameter(-1, EmitorParam.LIFETIME_RND, 0);
480 SetParameter(-1, EmitorParam.REPEAT, 0);
481
482 m_IsRepeat = false;
483 }
484 }
485
489 override void EOnFrame(IEntity other, float timeSlice)
490 {
491 m_Lifetime -= timeSlice;
493 }
494
499 {
500 if (m_Lifetime <= 0)
501 {
503 {
504 m_IsRepeat = IsRepeat(); // It is possible that the REPEAT flag was changed during lifetime, so it needs to be checked again.
505
506 if ( m_IsRepeat )
507 {
509 }
510 else
511 {
513
514 if ( GetParticleCount() == 0 )
515 {
516 m_MarkedForDeletion = true;
517 OnToDelete();
519 }
520 }
521 }
522 else
523 {
525 {
527 {
528 m_ParticleEffect.Delete();
529 m_ParticleEffect = null;
530 }
531
532 Delete();
533 }
534 }
535 }
536 }
537
541 private void OnToDelete()
542 {
543
544 }
545
547
548
549
554
563 void AddAsChild(Object parent, vector local_pos = "0 0 0", vector local_ori = "0 0 0", bool force_rotation_to_world = false)
564 {
565 if (ToDelete())
566 return;
567
568 if (parent)
569 {
570 // AddAsChild method is sometimes called from a timer.
571 // Due to that it is necesarry to use ToDelete() here to check if the parent object is flagged for deletion or not on client,
572 // because sometimes this code is executed before the parent's destructor from where this would normally be handled.
573 if (!parent.ToDelete())
574 {
575 SetPosition(local_pos);
576 SetOrientation(local_ori);
577 m_ParentObject = parent;
578 m_DefaultPos = local_pos;
579 m_ForceOrientationRelativeToWorld = force_rotation_to_world;
580
583
584 parent.AddChild(this, -1, false);
585 }
586 }
587 else
588 {
589 if (m_ParentObject && !m_ParentObject.ToDelete())
590 {
591 m_ParentObject.RemoveChild(this, true);
592 m_ParentObject = null;
593 }
594 }
595 }
596
598
599
600
605
611 void SetParticleParam(int parameter_id, float value )
612 {
613 if (!m_ParticleEffect)
614 return;
615
616 SetParticleParm(m_ParticleEffect, -1, parameter_id, value);
617 }
618
625 void SetParameter(int emitter, int parameter, float value)
626 {
627 if (!m_ParticleEffect)
628 return;
629
630 SetParticleParm(m_ParticleEffect, emitter, parameter, value);
631 }
632
639 void GetParameter(int emitter, int parameter, out float value)
640 {
641 if (!m_ParticleEffect)
642 return;
643
644 GetParticleParm(m_ParticleEffect, emitter, parameter, value);
645 }
646
653 float GetParameterEx(int emitter, int parameter)
654 {
655 if (!m_ParticleEffect)
656 return 0;
657
658 float value;
659 GetParticleParm(m_ParticleEffect, emitter, parameter, value);
660 return value;
661 }
662
663 float GetParameterOriginal(int emitter, int parameter)
664 {
665 if (!m_ParticleEffect)
666 return 0;
667
668 float value;
669 GetParticleParmOriginal(m_ParticleEffect, emitter, parameter, value);
670 return value;
671 }
672
678 void ScaleParticleParamFromOriginal(int parameter_id, float coef )
679 {
680 if (!m_ParticleEffect)
681 return;
682
684 for (int i = 0; i < emitors; ++i)
685 {
686 float value;
687 GetParticleParmOriginal(m_ParticleEffect, i, parameter_id, value);
688 SetParticleParm(m_ParticleEffect, i, parameter_id, value * coef);
689 }
690 }
691
697 void ScaleParticleParam(int parameter_id, float coef )
698 {
699 if (!m_ParticleEffect)
700 return;
701
703 for (int i = 0; i < emitors; ++i)
704 {
705 float value;
706 GetParticleParm(m_ParticleEffect, i, parameter_id, value);
707 SetParticleParm(m_ParticleEffect, i, parameter_id, value * coef);
708 }
709 }
710
717 void IncrementParticleParamFromOriginal(int parameter_id, float value )
718 {
719 if (!m_ParticleEffect)
720 return;
721
723 for (int i = 0; i < emitors; ++i)
724 {
725 float param;
726 GetParticleParmOriginal(m_ParticleEffect, i, parameter_id, param);
727 SetParticleParm(m_ParticleEffect, i, parameter_id, param + value);
728 }
729 }
730
737 void IncrementParticleParam(int parameter_id, float value )
738 {
739 if (!m_ParticleEffect)
740 return;
741
743 for (int i = 0; i < emitors; ++i)
744 {
745 float param;
746 GetParticleParm(m_ParticleEffect, i, parameter_id, param);
747 SetParticleParm(m_ParticleEffect, i, parameter_id, param + value);
748 }
749 }
750
752
753
754
759
764 {
765 return m_RandomizeOri && m_RandomizeOri.IsRunning();
766 }
767
775 void SetWiggle(float random_angle, float random_interval)
776 {
777 if ( random_angle != 0 || random_interval != 0 )
778 {
779 m_MaxOriWiggle = random_angle;
780 m_MaxOriInterval = random_interval;
781
782 if ( !m_RandomizeOri )
784
785 if ( !m_RandomizeOri.IsRunning() ) // Makes sure the timer is NOT running already
786 m_RandomizeOri.Run( Math.RandomFloat(0, m_MaxOriInterval) , this, "RandomizeOrientation", null, false);
787 }
788 else
789 {
790 StopWiggle();
791 }
792 }
793
798 {
799 if ( m_RandomizeOri )
800 {
801 m_RandomizeOri.Stop();
802 }
803
804 m_MaxOriWiggle = 0;
806 }
807
812 {
813 m_WiggleProcessing = true;
814
815 if (m_ParentObject)
816 {
817 if ( !m_RandomizeOri.IsRunning() )
818 {
819 m_RandomizeOri.Run( Math.RandomFloat(0, m_MaxOriInterval) , this, "RandomizeOrientation", NULL, false);
820 }
821
822 Object old_parent = m_ParentObject;
823 AddAsChild( null );
825 }
826
827 m_WiggleProcessing = false;
828 }
829
834 {
836 }
837
841 protected float RandWiggleFloat()
842 {
844 }
845
847}
Object GetObject()
Определения ActionTargets.c:122
const int ECE_LOCAL
Определения CentralEconomy.c:24
bool m_IsPlaying
Whether the Effect is currently playing.
Определения Effect.c:37
void ParticleBase()
ctor
Определения ParticleBase.c:71
void OnParticleStart()
Event when the particle starts.
Определения ParticleBase.c:179
void OnParticleEnd()
Event when the particle ends.
Определения ParticleBase.c:206
void OnParticleStop()
Event when the particle stops.
Определения ParticleBase.c:188
int particle_id
Определения SmokeSimulation.c:28
proto native Object CreateObjectEx(string type, vector pos, int iFlags, int iRotation=RF_DEFAULT)
Creates object of certain type.
Определения EnEntity.c:165
Определения EnMath.c:7
Определения ObjectTyped.c:2
bool m_IsRepeat
Whether this particle repeats.
Определения 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.
Определения Particle.c:104
float GetMaxLifetime()
Returns the approx. max lifetime.
Определения Particle.c:380
float GetParameterOriginal(int emitter, int parameter)
Определения Particle.c:663
bool m_MarkedForDeletion
Whether this particle is queued for deletion.
Определения Particle.c:19
void Particle()
ctor
Определения Particle.c:61
void SetWiggle(float random_angle, float random_interval)
Makes the particle change direction by random_angle every random_interval seconds.
Определения Particle.c:775
vector m_GlobalPosPreviousFrame
DEPRECATED.
Определения Particle.c:55
void ParticleInit()
Purely here so that it can be emptied in ParticleSource.
Определения Particle.c:67
vector m_DefaultPos
Used for Wiggle API, to restore after unparenting.
Определения Particle.c:33
override bool StopParticle(int flags=0)
Method to tell the particle to stop playing.
Определения Particle.c:245
void Play(int particle_id=-1)
Legacy function for backwards compatibility with 1.01 and below.
Определения Particle.c:233
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.
Определения Particle.c:152
Object m_ParticleEffect
The child object which contains the actual particle.
Определения Particle.c:50
bool HasActiveParticle()
Returns if there is any particle active.
Определения Particle.c:325
vector m_DefaultWorldOri
Used for Wiggle API, to restore after unparenting.
Определения Particle.c:35
void ScaleParticleParamFromOriginal(int parameter_id, float coef)
Scales the given parameter on all emitors relatively to their ORIGINAL value.
Определения Particle.c:678
vector m_DefaultOri
Used for Wiggle API, to restore after unparenting.
Определения 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.
Определения Particle.c:117
Object GetParticleParent()
Returns the parent of this Particle if there is one.
Определения Particle.c:316
bool m_ForceOrientationRelativeToWorld
Used for Wiggle API, to restore after unparenting.
Определения Particle.c:29
int GetParticleCount()
Returns the total count of active particles in all emitors.
Определения Particle.c:340
static Particle PlayInWorld(int particle_id, vector global_pos)
Creates a particle emitter on the given position and activates it.
Определения Particle.c:174
void SetSource(int particle_id)
Sets particle id.
Определения Particle.c:285
void ScaleParticleParam(int parameter_id, float coef)
Scales the given parameter on all emitors relatively to their CURRENT value.
Определения Particle.c:697
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...
Определения Particle.c:563
override void PlayParticle(int particle_id=-1)
Method to tell the particle to start playing.
Определения Particle.c:203
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.
Определения Particle.c:88
bool m_WiggleProcessing
Used for Wiggle API, to signal that wiggle API is currently doing work.
Определения Particle.c:27
override bool PlayParticleEx(int particle_id=-1, int flags=0)
Method to tell the particle to start playing.
Определения Particle.c:215
const int MAX_EMITORS
DEPRECATED.
Определения Particle.c:57
void SetParticleParam(int parameter_id, float value)
Set the value of a parameter of all emitors in the particle.
Определения Particle.c:611
static Particle Play(int particle_id, vector global_pos)
Legacy function for backwards compatibility with 1.01 and below.
Определения Particle.c:185
int GetParticleID()
Gets particle id.
Определения Particle.c:297
void OnCheckAutoDelete()
Creates ParticleEffect child, called from UpdateState.
Определения Particle.c:498
void CreateParticleEffect()
Creates ParticleEffect child, called from UpdateState.
Определения Particle.c:440
int m_PreviousFrame
DEPRECATED.
Определения Particle.c:53
vector m_DefaultWorldPos
Used for Wiggle API, to restore after unparenting.
Определения Particle.c:37
void SetParameter(int emitter, int parameter, float value)
Set the value of a parameter of an emitor in the particle.
Определения Particle.c:625
float m_Lifetime
Approx. remaining lifetime of particle.
Определения Particle.c:15
void DestroyParticleEffect()
Destroys ParticleEffect child, called from UpdateState.
Определения Particle.c:474
vector RandWiggleVector()
Helper to get a randomized wiggle vector.
Определения Particle.c:833
Object m_ParentObject
Parent Object the Particle is child of.
Определения Particle.c:48
int m_ParticleID
ID from ParticleList if assigned.
Определения Particle.c:13
void GetParameter(int emitter, int parameter, out float value)
Get the value of a parameter of an emitor in the particle.
Определения Particle.c:639
void RandomizeOrientation()
Randomizes a new orientation and applies it.
Определения Particle.c:811
bool IsRepeat()
Returns whether there is a repeating particle.
Определения Particle.c:354
float GetParameterEx(int emitter, int parameter)
Get the value of a parameter of an emitor in the particle.
Определения Particle.c:653
void UpdateState()
Creates/Destroys ParticleEffect child according to current state.
Определения Particle.c:425
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.
Определения Particle.c:163
float m_MaxOriWiggle
Used for Wiggle API, Wiggle room [-m_MaxOriWiggle, m_MaxOriWiggle].
Определения Particle.c:40
float m_MaxOriInterval
Used for Wiggle API, Interval for wiggling [0, m_MaxOriInterval[.
Определения Particle.c:42
float RandWiggleFloat()
Helper to get a randomized wiggle float value.
Определения Particle.c:841
void OnToDelete()
Called before deletion from OnCheckAutoDelete.
Определения Particle.c:541
void IncrementParticleParamFromOriginal(int parameter_id, float value)
Increments the value of the given parameter relatively from the ORIGINAL value.
Определения Particle.c:717
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.
Определения Particle.c:129
override void EOnFrame(IEntity other, float timeSlice)
OnFrame update event decrementing the stored approx. lifetime and checking for deletion.
Определения Particle.c:489
void StopWiggle()
Stops randomized wiggle.
Определения Particle.c:797
void Stop()
Legacy function for backwards compatibility with 1.14 and below.
Определения Particle.c:266
Object GetDirectParticleEffect()
Returns direct particle effect entity which is usually handled by this class 'Particle' if there is o...
Определения Particle.c:307
ref Timer m_RandomizeOri
Used for Wiggle API, calls the Wiggle functionality.
Определения Particle.c:44
void IncrementParticleParam(int parameter_id, float value)
Increments the value of the given parameter relatively from the CURRENT value.
Определения Particle.c:737
bool IsWiggling()
Checks if particle is currently wiggling.
Определения Particle.c:763
static string GetParticleFullPath(int particle_id)
Returns particle's full path (with .ptc suffix) based on its ID.
Определения ParticleList.c:485
Определения ParticleList.c:12
Определения DayZPlayerImplement.c:63
static const vector Zero
Определения EnConvert.c:110
Определения EnConvert.c:106
Определения proto.c:49
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
Определения EnDebug.c:90
enum ShapeType ErrorEx
proto native void SetPosition(vector position)
Set the world position of the Effect.
Определения Effect.c:438
proto native void SetFlags(ShapeFlags flags)
EntityEvent
Entity events for event-mask, or throwing event from code.
Определения EnEntity.c:45
EntityFlags
Entity flags.
Определения EnEntity.c:115
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].
Определения 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)
Определения EnVisual.c:210
proto void GetParticleParmOriginal(notnull IEntity ent, int emitor, EmitorParam parameter, out void value)
int ParticleGetCount(IEntity ent)
Определения EnVisual.c:205
proto int GetParticleEmitorCount(notnull IEntity ent)
EmitorParam
Определения EnVisual.c:114
proto void GetParticleParm(notnull IEntity ent, int emitor, EmitorParam parameter, out void value)
class JsonUndergroundAreaTriggerData GetPosition
Определения UndergroundAreaLoader.c:9
const int CALL_CATEGORY_GAMEPLAY
Определения tools.c:10
proto native void ReleaseObject(vobject object, int flag=0)
proto native Widget GetParent()
Get parent of the Effect.
Определения Effect.c:407
proto native void AddChild(Widget child, bool immedUpdate=true)