Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
effect.c
Go to the documentation of this file.
1 enum EffectType
3 {
5  NONE,
7  SOUND,
9  PARTICLE,
10 }
11 
16 class Effect : Managed
17 {
27 
32  protected bool m_IsAutodestroy;
35  protected bool m_IsPendingDeletion;
37  protected bool m_IsPlaying;
41  protected vector m_Position;
43 
48  protected int m_ID;
51  protected bool m_IsRegistered;
53 
59  protected vector m_LocalPos;
62  protected vector m_LocalOri;
64 
65 
66 
70  void Effect()
71  {
72  if (GetGame().IsDedicatedServer())
73  {
74  ErrorEx("Created Effect on server.", ErrorExSeverity.WARNING);
75  }
76 
77  InitEffect();
78  }
79 
83  void ~Effect()
84  {
85  // Safety
86  if ( IsRegistered() )
87  SEffectManager.EffectUnregister(GetID());
88 
89  // Certain effects need to be stopped to clean up properly
90  Stop();
91 
92  // Another safety
93  SetEnableEventFrame(false);
94  }
95 
99  void InitEffect()
100  {
104  }
105 
106 
111 
117  {
118  return EffectType.NONE;
119  }
120 
125  bool IsSound()
126  {
127  return false;
128  }
129 
134  bool IsParticle()
135  {
136  return false;
137  }
138 
140 
141 
142 
148 
153  void Start()
154  {
155  // It is already playing!
156  if (IsPlaying())
157  return;
158 
159  Event_OnStarted();
160  // I can't call this from inside the method with same name
161  // because that method is often overriden without super......
162  Event_OnStarted.Invoke(this);
163  }
164 
171  {
172 
173  }
174 
179  void Stop()
180  {
181  // It is not playing!
182  if (!IsPlaying())
183  return;
184 
185  Event_OnStopped();
186  // Yes, that event is new, but let's keep up some consistency
187  Event_OnStopped.Invoke(this);
188  }
189 
193  bool IsPlaying()
194  {
195  return m_IsPlaying;
196  }
197 
199 
200 
201 
206 
212  protected void Destroy()
213  {
214  // Already queued
215  if (IsPendingDeletion())
216  return;
217 
218  // Mark it to prevent queuing it up multiple times or get stuck in a call loop
219  m_IsPendingDeletion = true;
220 
221  // Stop it, so that the effects can clean up themselves
222  // Since if for example this is EffectParticle and the particle is looping
223  // It NEEDS to be stopped to clean up the Particle
224  Stop();
225 
226  // Queue up the destroying, as we should not do it while we are accessing it here
227  if (GetGame())
228  {
229  GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).Call(SEffectManager.DestroyEffect, this);
230  }
231  }
232 
238  void SetAutodestroy(bool auto_destroy)
239  {
240  m_IsAutodestroy = auto_destroy;
241  }
242 
248  {
249  return m_IsAutodestroy;
250  }
251 
257  {
258  return m_IsPendingDeletion;
259  }
260 
265  bool CanDestroy()
266  {
267  return true;
268  }
269 
271 
272 
273 
278  void SetEnableEventFrame(bool enable)
279  {
280  if ( enable )
281  {
282  SEffectManager.Event_OnFrameUpdate.Insert(Event_OnFrameUpdate);
283  }
284  else
285  {
286  SEffectManager.Event_OnFrameUpdate.Remove(Event_OnFrameUpdate);
287  }
288  }
289 
290 
291 
296 
301  {
302  // Override this method for own use
303  }
304 
308  void Event_OnStopped()
309  {
310  // Override this method for own use
311  }
312 
316  void Event_OnEffectStarted()
317  {
318  m_IsPlaying = true;
319 
320  Event_OnEffectStarted.Invoke(this);
321  }
322 
326  void Event_OnEffectEnded()
327  {
328  m_IsPlaying = false;
329 
330  Event_OnEffectEnded.Invoke(this);
331 
332  if ( IsAutodestroy() )
333  {
334  Destroy();
335  }
336  }
337 
343  void Event_OnFrameUpdate(float time_delta)
344  {
345  // Override this method for own use
346  }
347 
353  void Event_OnRegistered(int id)
354  {
355  SetID(id);
356  m_IsRegistered = true;
357  }
358 
364  {
365  SetID(SEffectManager.INVALID_ID);
366  m_IsRegistered = false;
367  }
368 
375  {
376 
377  }
378 
380 
381 
382 
387 
394  void SetParent(Object parent_obj)
395  {
396  m_ParentObject = parent_obj;
397  }
398 
406  {
407  return m_ParentObject;
408  }
409 
416  void SetCurrentParent( Object parent_obj, bool updateCached = true )
417  {
418  if (updateCached)
419  SetParent(parent_obj);
420  }
421 
427  {
428  return null;
429  }
430 
436  void SetPosition( vector pos )
437  {
438  m_Position = pos;
439  }
440 
447  {
448  return m_Position;
449  }
450 
456  void SetCurrentPosition( vector pos, bool updateCached = true )
457  {
458  if (updateCached)
459  SetPosition(pos);
460  }
461 
467  {
468  return vector.Zero;
469  }
470 
477  {
478  m_LocalPos = pos;
479  }
480 
487  {
488  return m_LocalPos;
489  }
490 
496  void SetCurrentLocalPosition( vector pos, bool updateCached = true )
497  {
498  if (updateCached)
499  SetLocalPosition(pos);
500  }
501 
507  {
508  return vector.Zero;
509  }
510 
512 
513 
514 
519 
525  protected void SetID(int id)
526  {
527  m_ID = id;
528  }
529 
534  int GetID()
535  {
536  return m_ID;
537  }
538 
544  {
545  return m_IsRegistered;
546  }
547 
549 
550 
551 
558 
564  {
565  SetParent(obj);
566  }
567 
573  {
574  return GetParent();
575  }
576 
582  {
583  SetLocalPosition(pos);
584  }
585 
591  {
592  return GetLocalPosition();
593  }
594 
602  {
603  m_LocalOri = ori;
604  }
605 
612  {
613  return m_LocalOri;
614  }
615 
617 }
GetGame
proto native CGame GetGame()
Event_OnUnregistered
void Event_OnUnregistered()
Event called from SEffectManager when the Effect is unregistered.
Definition: effect.c:363
InitEffect
void InitEffect()
init
Definition: effect.c:99
EffectType
EffectType
Enum to determine what type of effect the Effect is.
Definition: effect.c:2
GetAttachedLocalOri
vector GetAttachedLocalOri()
Get the local orientation set by SetAttachedLocalOri.
Definition: effect.c:611
m_LocalPos
protected vector m_LocalPos
Cached local pos.
Definition: effect.c:60
m_IsPlaying
protected bool m_IsPlaying
Whether the Effect is currently playing.
Definition: effect.c:37
CALL_CATEGORY_GAMEPLAY
const int CALL_CATEGORY_GAMEPLAY
Definition: tools.c:10
SetAttachmentParent
void SetAttachmentParent(Object obj)
Set parent for the Effect.
Definition: effect.c:563
SOUND
SOUND
EffectSound.
Definition: effect.c:22
Event_OnFrameUpdate
void Event_OnFrameUpdate(float time_delta)
Event called on frame when enabled by SetEnableEventFrame(true)
Definition: effect.c:343
GetCurrentParent
Object GetCurrentParent()
Get the current parent of the managed Effect.
Definition: effect.c:426
GetCurrentPosition
vector GetCurrentPosition()
Get the current world position of the managed effect.
Definition: effect.c:466
GetCurrentLocalPosition
vector GetCurrentLocalPosition()
Get the current local position of the managed effect.
Definition: effect.c:506
GetEffectType
EffectType GetEffectType()
Get what type of effect the Effect is.
Definition: effect.c:116
m_Position
protected vector m_Position
Cached world position.
Definition: effect.c:41
GetPosition
vector GetPosition()
Get the world position of the Effect.
Definition: effect.c:446
m_IsPendingDeletion
protected bool m_IsPendingDeletion
Whether the Destroy process has already been called.
Definition: effect.c:35
Managed
TODO doc.
Definition: enscript.c:117
IsAutodestroy
bool IsAutodestroy()
Get whether Effect automatically cleans up when it stops.
Definition: effect.c:247
SetID
protected void SetID(int id)
Set the ID registered in SEffectManager.
Definition: effect.c:525
m_ParentObject
protected Object m_ParentObject
Cached parent.
Definition: effect.c:39
OnCheckUpdate
void OnCheckUpdate()
Event used when EffectParticle.CheckLifeSpan was called (DEPRECATED)
Definition: effect.c:374
SetAttachedLocalPos
void SetAttachedLocalPos(vector pos)
Set local pos for the Effect relative to the parent.
Definition: effect.c:581
SetEnableEventFrame
void SetEnableEventFrame(bool enable)
Enable Event_OnFrameUpdate for the effect.
Definition: effect.c:278
ErrorEx
enum ShapeType ErrorEx
SetAttachedLocalOri
void SetAttachedLocalOri(vector ori)
Set local orientation for the Effectparticle to attach to when the Effect is started.
Definition: effect.c:601
vector
Definition: enconvert.c:105
Effect
void Effect()
ctor
Definition: effect.c:70
IsParticle
bool IsParticle()
Check whether the Effect is EffectParticle without casting.
Definition: effect.c:134
GetID
int GetID()
Get the ID registered in SEffectManager.
Definition: effect.c:534
Destroy
protected void Destroy()
Cleans up the Effect, including unregistering if needed.
Definition: effect.c:212
SetCurrentParent
void SetCurrentParent(Object parent_obj, bool updateCached=true)
Set current parent of the managed effect.
Definition: effect.c:416
ErrorExSeverity
ErrorExSeverity
Definition: endebug.c:61
Object
Definition: objecttyped.c:1
PARTICLE
PARTICLE
EffectParticle.
Definition: effect.c:24
GetAttachedLocalPos
vector GetAttachedLocalPos()
Get the local pos set by SetAttachedLocalPos.
Definition: effect.c:590
IsPlaying
bool IsPlaying()
Returns true when the Effect is playing, false otherwise.
Definition: effect.c:193
GetLocalPosition
vector GetLocalPosition()
Get the local position of the Effect.
Definition: effect.c:486
IsRegistered
bool IsRegistered()
Get whether this Effect is registered in SEffectManager.
Definition: effect.c:543
Event_OnRegistered
void Event_OnRegistered(int id)
Event called from SEffectManager when the Effect is registered.
Definition: effect.c:353
SetAutodestroy
void SetAutodestroy(bool auto_destroy)
Sets whether Effect automatically cleans up when it stops.
Definition: effect.c:238
Event_OnStopped
ref ScriptInvoker Event_OnStopped
Event used when Stop was called.
Definition: effect.c:23
Event_OnEffectEnded
ref ScriptInvoker Event_OnEffectEnded
Event used when the actual effect stopped playing.
Definition: effect.c:25
IsSound
bool IsSound()
Check whether the Effect is EffectSound without casting.
Definition: effect.c:125
SetCurrentLocalPosition
void SetCurrentLocalPosition(vector pos, bool updateCached=true)
Set the current local position of the managed effect.
Definition: effect.c:496
SetPosition
void SetPosition(vector pos)
Set the world position of the Effect.
Definition: effect.c:436
CanDestroy
bool CanDestroy()
Get whether the Effect can be destroyed right now.
Definition: effect.c:265
Event_OnEffectStarted
ref ScriptInvoker Event_OnEffectStarted
Event used when the actual effect started playing.
Definition: effect.c:24
GetParent
Object GetParent()
Get parent of the Effect.
Definition: effect.c:405
m_IsAutodestroy
protected bool m_IsAutodestroy
Whether the Effect cleans up after itself when stopped.
Definition: effect.c:33
NONE
NONE
Plain Effect base.
Definition: effect.c:20
IsPendingDeletion
bool IsPendingDeletion()
Get whether the Effect is queued up for being cleaned up.
Definition: effect.c:256
Event_OnStarted
Event_OnStarted
Event used when Start was called.
Definition: effect.c:300
SetParent
void SetParent(Object parent_obj)
Set parent of the Effect.
Definition: effect.c:394
m_IsRegistered
protected bool m_IsRegistered
Whether the effect is registered in SEffectManager.
Definition: effect.c:51
SetCurrentPosition
void SetCurrentPosition(vector pos, bool updateCached=true)
Set the current world position of the managed effect.
Definition: effect.c:456
m_LocalOri
protected vector m_LocalOri
Local orientation set by SetAttachedLocalOri, only used by EffectParticle.
Definition: effect.c:62
SetLocalPosition
void SetLocalPosition(vector pos)
Set the local position of the Effect.
Definition: effect.c:476
ValidateStart
void ValidateStart()
Validation whether an effect truly started playing or if the Effect should stop as none is present.
Definition: effect.c:170
Start
void Start()
Plays all elements this effects consists of.
Definition: effect.c:153
SEffectManager
Manager class for managing Effect (EffectParticle, EffectSound)
Definition: effectmanager.c:5
m_ID
protected int m_ID
ID of effect, given by SEffectManager when registered (automatically done when playing through it)
Definition: effect.c:49
GetAttachmentParent
Object GetAttachmentParent()
Get the parent set by SetAttachmentParent.
Definition: effect.c:572
Stop
void Stop()
Stops all elements this effect consists of.
Definition: effect.c:179
~Effect
void ~Effect()
dtor
Definition: effect.c:83
ScriptInvoker
ScriptInvoker Class provide list of callbacks usage:
Definition: tools.c:115