Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
particlesource.c
Go to the documentation of this file.
3 {
5  NONE,
11  ALL,
12 }
13 
15 enum PlayParticleFlags
16 {
18  NONE,
19  // Is just a placeholder for now
20 }
21 
23 enum StopParticleFlags
24 {
26  NONE,
28  RESET,
35  IMMEDIATE,
37  VISIBLE,
39  PAUSE,
40 }
41 
43 enum EGetParticleMode
44 {
46  FULL,
48  NO_EXT,
50  FILE,
51 }
52 
53 enum ParticlePropertiesFlags
54 {
55  NONE,
62 };
63 
65 class ParticleProperties
66 {
78  void ParticleProperties(vector localPos, int flags, Object parent = null, vector localOri = vector.Zero, Class owner = null)
79  {
80  }
81 
83  void ~ParticleProperties()
84  {
85  }
86 
91  proto Object GetParent();
92  proto Class GetOwner();
93  proto vector GetLocalPos();
94  proto vector GetLocalOri();
95  proto int GetPPFlags();
96  proto bool IsPlayOnCreation();
97  proto bool IsForceWorldRotation();
98  proto bool IsKeepParentOnEnd();
100 }
101 
102 typedef array<ref ParticleProperties> ParticlePropertiesArray;
104 
124 {
126  void ParticleSource()
127  {
128  m_ParticleEffect = this;
129  }
130 
132  void ~ParticleSource()
133  {
134  }
135 
137  override protected void ParticleInit() {}
138 
146  proto native void SetParticleAutoDestroyFlags(ParticleAutoDestroyFlags flags);
147 
151  void DisableAutoDestroy()
152  {
153  SetParticleAutoDestroyFlags(ParticleAutoDestroyFlags.NONE);
154  }
155 
160  proto native int GetParticleAutoDestroyFlags();
161 
166 
178  static ParticleSource CreateParticle( int id, vector pos, bool playOnCreation = false, Object parent = null, vector ori = vector.Zero, bool forceWorldRotation = false, Class owner = null )
179  {
180  int flags = ParticlePropertiesFlags.NONE;
181 
182  if (playOnCreation)
183  {
184  flags = flags | ParticlePropertiesFlags.PLAY_ON_CREATION;
185  }
186 
187  if (forceWorldRotation)
188  {
189  flags = flags | ParticlePropertiesFlags.FORCE_WORLD_ROT;
190  }
191 
192  return CreateParticleEx(id, pos, flags, parent, ori, owner);
193  }
194 
205  static ParticleSource CreateParticleEx( int id, vector pos, int flags = ParticlePropertiesFlags.NONE, Object parent = null, vector ori = vector.Zero, Class owner = null )
206  {
207  string particlePath = ParticleList.GetParticleFullPath(id);
208  if (particlePath == "") // There is already an error inside of ParticleList signaling this
209  {
210  ErrorEx(string.Format("Could not create ParticleSource as particle id %1 is invalid.", id));
211  return null;
212  }
213 
214  vector localPos = pos;
215 
216  if (parent)
217  pos = parent.GetPosition();
218 
219  ParticleSource p = ParticleSource.Cast( GetGame().CreateObjectEx("ParticleSource", pos, ECE_LOCAL) );
220  p.SetParticle(particlePath);
221  ParticleProperties props = new ParticleProperties(localPos, flags, parent, ori, owner);
222  p.ApplyProperties(props);
223 
224  return p;
225  }
226 
236  override static Particle CreateOnObject(
237  int particle_id,
238  Object parent_obj,
239  vector local_pos = "0 0 0",
240  vector local_ori = "0 0 0",
241  bool force_world_rotation = false )
242  {
243  return CreateParticle(particle_id, local_pos, false, parent_obj, local_ori, force_world_rotation);
244  }
245 
249  override static Particle Create( int particle_id, Object parent_obj, vector local_pos = "0 0 0", vector local_ori = "0 0 0" )
250  {
251  return CreateOnObject( particle_id, parent_obj, local_pos, local_ori);
252  }
253 
262  override static Particle CreateInWorld( int particle_id, vector global_pos, vector global_ori = "0 0 0", bool force_world_rotation = false )
263  {
264  return CreateParticle(particle_id, global_pos, false, null, global_ori, force_world_rotation);
265  }
266 
270  override static ParticleSource Create( int particle_id, vector global_pos, vector global_ori = "0 0 0" )
271  {
272  return CreateInWorld( particle_id, global_pos, global_ori );
273  }
274 
276 
277 
278 
283 
293  override 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 )
294  {
295  return CreateParticle(particle_id, local_pos, true, parent_obj, local_ori, force_world_rotation);
296  }
297 
301  override static Particle Play( int particle_id, Object parent_obj, vector local_pos = "0 0 0", vector local_ori = "0 0 0" )
302  {
303  return PlayOnObject( particle_id, parent_obj, local_pos, local_ori);
304  }
305 
312  override static Particle PlayInWorld( int particle_id, vector global_pos)
313  {
314  return CreateParticle(particle_id, global_pos, true);
315  }
316 
320  override static Particle Play( int particle_id, vector global_pos)
321  {
322  return PlayInWorld( particle_id, global_pos);
323  }
324 
326 
327 
328 
333 
339  private proto bool PlayParticleNative(int flags);
340 
346  override bool PlayParticleEx(int particle_id = -1, int flags = 0)
347  {
348  if ( particle_id > -1 )
349  {
350  // Here we can just do it directly
351  // While with the old system it will not work when the particle is already created
352  SetParticleByID(particle_id);
353  }
354 
355  return PlayParticleNative(flags);
356  }
357 
365  private proto bool StopParticleNative(int flags);
366 
372  override bool StopParticle(int flags = 0)
373  {
374  return StopParticleNative(flags);
375  }
376 
381  private proto native bool ResetParticleNative();
382 
387  override bool ResetParticle()
388  {
389  return ResetParticleNative();
390  }
391 
396  private proto native bool RestartParticleNative();
397 
402  override bool RestartParticle()
403  {
404  return RestartParticleNative();
405  }
406 
411  private proto bool IsParticlePlayingNative();
412 
417  override bool IsParticlePlaying()
418  {
419  return IsParticlePlayingNative();
420  }
421 
423 
424 
425 
430 
436  private proto native bool SetParticleNative(string path);
437 
444  private bool SetParticle(string path)
445  {
446  return SetParticleNative(path);
447  }
448 
454  bool SetParticleByID(int id)
455  {
456  return SetParticle(ParticleList.GetParticleFullPath(id));
457  }
458 
464  override void SetSource(int particle_id)
465  {
466  SetParticleByID(particle_id);
467  }
468 
470 
471 
472 
477 
484  private proto bool GetParticleNative(out string path, EGetParticleMode mode);
485 
492  bool GetParticle(out string path, EGetParticleMode mode)
493  {
494  return GetParticleNative(path, mode);
495  }
496 
501  override int GetParticleID()
502  {
503  string path;
504  if (GetParticle(path, EGetParticleMode.FILE))
505  return ParticleList.GetParticleIDByName(path);
506  else
507  return -1;
508  }
509 
516  int GetParticleIDLegacy()
517  {
518  string path;
519  if (GetParticle(path, EGetParticleMode.NO_EXT))
520  return ParticleList.GetParticleID(path);
521  else
522  return -1;
523  }
524 
526 
527 
528 
533 
540  private proto native bool ApplyPropertiesNative(ParticleProperties properties);
541 
547  bool ApplyProperties(ParticleProperties properties)
548  {
549  return ApplyPropertiesNative(properties);
550  }
551 
553 
554 
555 
560 
566  override Object GetDirectParticleEffect()
567  {
568  return this;
569  }
570 
575  override Object GetParticleParent()
576  {
577  return Object.Cast(GetParent());
578  }
579 
584  private proto bool HasActiveParticleNative();
585 
590  override bool HasActiveParticle()
591  {
592  return HasActiveParticleNative();
593  }
594 
600  private proto int GetParticleCountNative();
601 
607  override int GetParticleCount()
608  {
609  return GetParticleCountNative();
610  }
611 
616  private proto bool IsRepeatNative();
617 
622  override bool IsRepeat()
623  {
624  return IsRepeatNative();
625  }
626 
631  private proto float GetMaxLifetimeNative();
632 
637  override float GetMaxLifetime()
638  {
639  return GetMaxLifetimeNative();
640  }
641 
646  proto native Class GetOwner();
647 
652  proto native void SetOwner(Class owner);
653 
657  proto native void Orphan();
658 
660 
661 
662 
667 
672  proto native ParticleManager GetParticleManager();
673 
678  proto native int GetIndex();
679 
681 
682 
683 
688 
694  proto int GetCountID();
695 
700  proto native static int GetStaticCount();
701 
706  proto native static int GetStaticActiveCount();
707 
709 
710 
711 
718 
722  override protected void OnParticleParented(IEntity parent)
723  {
724  m_ParentObject = Object.Cast(parent);
725 
726  super.OnParticleParented(parent);
727  }
728 
732  override protected void OnParticleUnParented(IEntity parent)
733  {
734  m_ParentObject = null;
735 
736  // Since we have lost the parent, we will need to refresh the wiggle
737  // As it uses a cached local position, which is now no longer correct
738  if (!m_WiggleProcessing && IsWiggling())
739  {
740  float randomAngle = m_MaxOriWiggle;
741  float randomInterval = m_MaxOriInterval;
742  m_DefaultPos = m_DefaultWorldPos;
743  m_DefaultOri = m_DefaultWorldOri;
744 
745  StopWiggle();
746  SetWiggle(randomAngle, randomInterval);
747  }
748 
749  super.OnParticleUnParented(parent);
750  }
751 
755  override protected void OnParticleStop()
756  {
757  if (IsWiggling())
758  {
759  StopWiggle();
760  delete m_RandomizeOri;
761  }
762 
763  super.OnParticleStop();
764  }
765 
767 
768 
769 
774 
783  override void AddAsChild(Object parent, vector local_pos = "0 0 0", vector local_ori = "0 0 0", bool force_rotation_to_world = false)
784  {
785  int flags = ParticlePropertiesFlags.NONE;
786 
787  if (force_rotation_to_world)
788  flags = ParticlePropertiesFlags.FORCE_WORLD_ROT;
789 
790  ParticleProperties props = new ParticleProperties(local_pos, flags, parent, local_ori);
791  ApplyProperties(props);
792  }
793 
795 
796 
797 
802 
808  override void SetParticleParam(int parameter_id, float value )
809  {
810  SetParticleParm(this, -1, parameter_id, value);
811  }
812 
819  override void SetParameter(int emitter, int parameter, float value)
820  {
821  SetParticleParm(this, emitter, parameter, value);
822  }
823 
830  override void GetParameter(int emitter, int parameter, out float value)
831  {
832  GetParticleParm(this, emitter, parameter, value);
833  }
834 
841  override float GetParameterEx(int emitter, int parameter)
842  {
843  float value;
844  GetParticleParm(this, emitter, parameter, value);
845  return value;
846  }
847 
853  override void ScaleParticleParamFromOriginal(int parameter_id, float coef )
854  {
855  int emitors = GetParticleEmitorCount(this);
856  for (int i = 0; i < emitors; ++i)
857  {
858  float value;
859  GetParticleParmOriginal(this, i, parameter_id, value);
860  SetParticleParm(this, i, parameter_id, value * coef);
861  }
862  }
863 
869  override void ScaleParticleParam(int parameter_id, float coef )
870  {
871  int emitors = GetParticleEmitorCount(this);
872  for (int i = 0; i < emitors; ++i)
873  {
874  float value;
875  GetParticleParm(this, i, parameter_id, value);
876  SetParticleParm(this, i, parameter_id, value * coef);
877  }
878  }
879 
886  override void IncrementParticleParamFromOriginal(int parameter_id, float value )
887  {
888  int emitors = GetParticleEmitorCount(this);
889  for (int i = 0; i < emitors; ++i)
890  {
891  float param;
892  GetParticleParmOriginal(this, i, parameter_id, param);
893  SetParticleParm(this, i, parameter_id, param + value);
894  }
895  }
896 
903  override void IncrementParticleParam(int parameter_id, float value )
904  {
905  int emitors = GetParticleEmitorCount(this);
906  for (int i = 0; i < emitors; ++i)
907  {
908  float param;
909  GetParticleParm(this, i, parameter_id, param);
910  SetParticleParm(this, i, parameter_id, param + value);
911  }
912  }
913 
915 
916 
917 
922 
929  override void SetWiggle(float random_angle, float random_interval)
930  {
931  if (random_angle != 0 || random_interval != 0)
932  {
933  if (IsWiggling())
934  {
935  m_MaxOriWiggle = random_angle;
936  m_MaxOriInterval = random_interval;
937  return;
938  }
939 
940  // We need the position to be accurate before storing it
941  Update();
942 
943  // These are only ever used within the Wiggle API
944  // To restore the properties after wiggling
945  // So let's only set them within the Wiggle API c:
946 
947  m_DefaultPos = GetLocalPosition();
948  m_DefaultOri = GetLocalYawPitchRoll();
949  m_DefaultWorldPos = GetWorldPosition();
950  m_DefaultWorldOri = GetYawPitchRoll();
951  m_ForceOrientationRelativeToWorld = IsHierarchyPositionOnly();
952  }
953 
954  super.SetWiggle(random_angle, random_interval);
955  }
956 
960  override void StopWiggle()
961  {
962  bool wiggling = IsWiggling();
963 
964  super.StopWiggle();
965 
966  if (wiggling)
967  {
968  // Restore pre-wiggle orientation
969  int flags = ParticlePropertiesFlags.NONE;
970 
971  if (m_ForceOrientationRelativeToWorld)
972  flags = ParticlePropertiesFlags.FORCE_WORLD_ROT;
973 
974  ParticleProperties prop = new ParticleProperties(m_DefaultPos, flags, GetParticleParent(), m_DefaultOri, GetOwner());
975  ApplyProperties(prop);
976  }
977  }
978 
982  override private void RandomizeOrientation()
983  {
984  if (ToDelete())
985  return;
986 
987  m_WiggleProcessing = true;
988 
989  if ( !m_RandomizeOri.IsRunning() )
990  m_RandomizeOri.Run( Math.RandomFloat(0, m_MaxOriInterval) , this, "RandomizeOrientation", null, false);
991 
992  int flags = ParticlePropertiesFlags.NONE;
993 
994  if (m_ForceOrientationRelativeToWorld)
995  flags = ParticlePropertiesFlags.FORCE_WORLD_ROT;
996 
997  ParticleProperties prop = new ParticleProperties(m_DefaultPos, flags, GetParticleParent(), m_DefaultOri + RandWiggleVector(), GetOwner());
998  ApplyProperties(prop);
999 
1000  m_WiggleProcessing = false;
1001  }
1002 
1004 
1005 
1006 
1011 
1013  override private void UpdateState() { ErrorEx("Should not be in use on ParticleSource."); }
1014 
1016  override private void DestroyParticleEffect() { ErrorEx("Should not be in use on ParticleSource."); }
1017 
1019  override private void CreateParticleEffect() { ErrorEx("Should not be in use on ParticleSource."); }
1020 
1022  override protected void EOnFrame(IEntity other, float timeSlice) { ErrorEx("Should not be in use on ParticleSource."); }
1023 
1025  override private void OnCheckAutoDelete() { ErrorEx("Should not be in use on ParticleSource."); }
1026 
1028  override private void OnToDelete() { ErrorEx("Should not be in use on ParticleSource."); }
1029 
1031 }
GetGame
proto native CGame GetGame()
ON_STOP
@ ON_STOP
Destroy when particle stops.
Definition: particlesource.c:9
ON_END
@ ON_END
Destroy when the Particle ends (looping particle never ends)
Definition: particlesource.c:7
particle_id
int particle_id
Definition: smokesimulation.c:3
Particle
Legacy way of using particles in the game.
Definition: particle.c:6
FULL
enum ParticleAutoDestroyFlags FULL
Mode for GetParticle.
FILE
enum ParticleAutoDestroyFlags FILE
Filename only ("smoking_barrel_small")
GetParticleEmitorCount
proto int GetParticleEmitorCount(notnull IEntity ent)
PLAY_ON_CREATION
enum ParticleAutoDestroyFlags PLAY_ON_CREATION
Makes the particle start playing immediately after being created.
m_ParentObject
protected Object m_ParentObject
Cached parent.
Definition: effect.c:39
ErrorEx
enum ShapeType ErrorEx
IEntity
Definition: enentity.c:164
ParticleSourceArray
array< ParticleSource > ParticleSourceArray
Definition: particlesource.c:103
VISIBLE
enum ParticleAutoDestroyFlags VISIBLE
Is default behaviour, but can be used in conjuction with IMMEDIATE which hides it when this flag is n...
GetParticleParmOriginal
proto void GetParticleParmOriginal(notnull IEntity ent, int emitor, EmitorParam parameter, out void value)
NONE
enum ParticleAutoDestroyFlags NONE
Flags to pass to ParticleSource.PlayParticleEx.
Definition: particlesource.c:5
ParticleList
Definition: particlelist.c:11
ParticleAutoDestroyFlags
ParticleAutoDestroyFlags
Flags to pass to ParticleSource.SetParticleAutoDestroyFlags.
Definition: particlesource.c:2
vector
Definition: enconvert.c:105
NO_EXT
enum ParticleAutoDestroyFlags NO_EXT
Full path without ext ("graphics/particles/smoking_barrel_small")
Object
Definition: objecttyped.c:1
GetLocalPosition
vector GetLocalPosition()
Get the local position of the Effect.
Definition: effect.c:486
KEEP_PARENT_ON_END
enum ParticleAutoDestroyFlags KEEP_PARENT_ON_END
By default, a particle unparents when it ends, this disables this behaviour.
IMMEDIATE
enum ParticleAutoDestroyFlags IMMEDIATE
Flag will make the particle stop immediately, taking it out of simulation and clearing VISIBLE flag.
Definition: tools.c:138
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
Update
proto native volatile void Update()
Definition: playersoundmanager.c:125
ParticleSource
Entity which has the particle instance as an ObjectComponent.
Definition: particlesource.c:123
PAUSE
enum ParticleAutoDestroyFlags PAUSE
(SPF_IMMEDIATE | SPF_VISIBLE) "Freezes" the particle while keeping it visible
SetParticleParm
proto void SetParticleParm(notnull IEntity ent, int emitor, EmitorParam parameter, void value)
GetParent
proto native Widget GetParent()
Get parent of the Effect.
Definition: effect.c:405
ECE_LOCAL
const int ECE_LOCAL
Definition: centraleconomy.c:24
RESET
enum ParticleAutoDestroyFlags RESET
Reset state after stopping.
ALL
@ ALL
ON_END | ON_STOP.
Definition: particlesource.c:11
GetParticleParm
proto void GetParticleParm(notnull IEntity ent, int emitor, EmitorParam parameter, out void value)
Math
Definition: enmath.c:6
ParticleManager
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
Definition: particlemanager.c:84
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
FORCE_WORLD_ROT
enum ParticleAutoDestroyFlags FORCE_WORLD_ROT
Only applicable when there is a parent, this will force the localOri to be in world space instead of ...
path
string path
Definition: optionselectormultistate.c:135