DayZ 1.24
Loading...
Searching...
No Matches
EffectSound.c
Go to the documentation of this file.
1
4class EffectSound : Effect
5{
15
25
31 protected string m_SoundSetName;
32 protected bool m_SoundLoop;
33 protected bool m_SetEnvVariables;
34 protected bool m_SoundAutodestroy;
35 protected bool m_SoundWaveIsPlaying;
36 protected float m_SoundWaveLenght;
37 protected float m_SoundWaveVolume;
38 protected float m_SoundWaveVolumeMax;
39 protected float m_SoundWaveTime;
40 protected int m_SoundDoppler;
42
47 protected bool m_SoundWaveStarting;
48 protected bool m_SoundWaveStopping;
49 protected bool m_SoundFadedOut;
50
51 protected float m_SoundFadeInDuration;
52
53 protected float m_SoundFadeOutStartTime;
54 protected float m_SoundFadeOutDuration;
55 protected float m_SoundFadeOutInitVolume;
57
58
63 {
64 m_SoundWaveKind = WaveKind.WAVEEFFECTEX;
67 m_SoundAutodestroy = false;
68 m_SoundWaveStopping = false;
69 m_SoundFadedOut = false;
70 m_SoundDoppler = -1;
71 }
72
77 {
78
79 }
80
84 override void InitEffect()
85 {
86 super.InitEffect();
87
88 // These will be called by the sound events
91 }
92
96 override string GetDebugName()
97 {
98 string identifier;
99 if (m_SoundSetName != "")
101 else
102 identifier = "NO_SOUNDSET";
103
104 return string.Format("%1:%2", super.GetDebugName(), identifier);
105 }
106
107
112
118 {
119 return EffectType.SOUND;
120 }
121
126 override bool IsSound()
127 {
128 return true;
129 }
130
132
133
139
146 {
147 super.Start();
148
149 if (m_SoundSetName != "")
150 {
152
153 if (SoundLoadEx(params))
154 {
156 {
157 m_SoundObjectBuilder.AddEnvSoundVariables(GetPosition());
158 m_SoundObject = m_SoundObjectBuilder.BuildSoundObject();
160 m_SoundObject.SetParent(m_ParentObject);
161 }
162
163 if (m_SoundObject)
164 {
166 m_SoundWaveObject = GetGame().GetSoundScene().Play3D(m_SoundObject, m_SoundObjectBuilder);
168 return false;
169
170 // Wait for header to be loaded before asking for its length, else we block the main thread
173 else
174 m_SoundWaveObject.GetEvents().Event_OnSoundWaveHeaderLoaded.Insert(ValidateSoundWave);
175
176 return true;
177 }
178 else
179 SoundError("m_SoundObject is null.");
180 }
181 }
182
183 return false;
184 }
185
191 {
193 return SoundPlayEx(params);
194 }
195
199 override void Start()
200 {
201 SoundPlay();
202 }
203
209 {
210 super.Stop();
211
212 if (IsSoundPlaying())
213 {
215 {
216 m_SoundWaveStopping = true;
217 m_SoundFadedOut = false;
218 m_SoundWaveStarting = false;
220 }
221 else
223 }
224 else
225 SoundReset();
226 }
227
231 override void Stop()
232 {
233 SoundStop();
234 }
235
256
262 {
264 }
265
269 override bool IsPlaying()
270 {
271 return IsSoundPlaying(); // Just in case, as that's what used to be the actual way to check
272 }
273
275
276
281
287 {
288 if (!m_SoundParams || !m_SoundParams.IsValid())
289 {
290 if (!params)
292
293 //Print("SoundLoad is loading..");
295 if (!m_SoundParams.IsValid())
296 {
297 SoundError("Invalid sound set.");
298 return false;
299 }
300
303 m_SoundObjectBuilder.AddEnvSoundVariables(GetPosition());
304
305 m_SoundObject = m_SoundObjectBuilder.BuildSoundObject();
306
307 if (m_SoundObject)
308 {
310 m_SoundObject.SetParent(m_ParentObject);
311 }
312 else
313 SoundError("m_SoundObject is null.");
314 }
315 else
316 {
317 //Print("SoundLoad is loaded.");
318 }
319
320 return true;
321 }
322
328 {
330 return SoundLoadEx(params);
331 }
332
337 {
338 return m_SoundParams.IsValid();
339 }
340
345 protected void ValidateSoundWave()
346 {
348
350 {
351 if (m_SoundFadeInDuration > 0)
352 {
355 }
356
358
359 m_SoundWaveStarting = true;
360
362 events.Event_OnSoundWaveStarted.Insert(Event_OnSoundWaveStarted);
363 events.Event_OnSoundWaveEnded.Insert(Event_OnSoundWaveEnded);
364
365 UpdateEvents();
366 }
367 else
369 }
370
375 protected bool SoundWaveValidation()
376 {
377 bool valid = true;
378
380 {
381 SoundError("FadeIn is longer than sound wave length.");
382 valid = false;
383 }
384
386 {
387 SoundError("FadeOut is longer than sound wave length.");
388 valid = false;
389 }
390
392 {
393 SoundError("FadeIn & FadeOut are longer than sound wave length.");
394 valid = false;
395 }
396
397 return valid;
398 }
399
405 protected void UpdateEvents()
406 {
409 else
410 SetEnableEventFrame(false);
411 }
412
414
415
420
427 override void Event_OnFrameUpdate(float time_delta)
428 {
429 if (IsSoundPlaying())
430 {
431 if (m_SoundDoppler != -1)
433 // FadeIn
435 {
436 if (m_SoundFadeInDuration > 0)
437 {
439
441 {
444 m_SoundWaveStarting = false;
445 }
446 }
447 else
448 {
450 m_SoundWaveStarting = false;
451 }
452 }
453
454 // FadeOut
456 {
458 {
460 {
463 }
465 }
466 else
468
469 if (GetSoundVolume() <= 0)
470 {
472 {
474 m_SoundWaveStopping = false;
475 m_SoundFadedOut = true;
476 }
477 }
478 }
479
480 // Counting timer here because loop play
482 }
483 }
484
490 override void Event_OnRegistered(int id)
491 {
492 super.Event_OnRegistered(id);
493
495 }
496
501 override void Event_OnUnregistered()
502 {
503 super.Event_OnUnregistered();
504
506 }
507
513 {
515
516 Event_OnSoundWaveStarted.Invoke(this);
517
519 }
520
526 {
527 m_SoundWaveIsPlaying = false;
528
529 Event_OnSoundWaveEnded.Invoke(this);
530
532 }
533
539 {
540 Event_OnSoundFadeInStopped.Invoke(this);
541 }
542
548 {
549 Event_OnSoundFadeOutStarted.Invoke(this);
550 }
551
553
554
559
565 override void SetAutodestroy(bool auto_destroy)
566 {
567 super.SetAutodestroy(auto_destroy);
569 }
570
575 override bool IsAutodestroy()
576 {
577 return IsSoundAutodestroy();
578 }
579
588
594 {
595 return m_SoundAutodestroy;
596 }
597
598 override bool CanDestroy()
599 {
601 }
602
604
605
610
616 {
617 super.SetParent(parent_obj); // ...
618
619 if (m_SoundObject)
620 m_SoundObject.SetParent(parent_obj);
621 }
622
627 override Object GetParent()
628 {
629 if (m_SoundObject)
630 return Object.Cast(m_SoundObject.GetParent());
631 else
632 return super.GetParent();
633 }
634
641 {
642 if (m_SoundObject)
643 return Object.Cast(m_SoundObject.GetParent());
644 else
645 return super.GetParent(); // Yes, intentionally this one
646 }
647
653 override void SetCurrentPosition(vector pos, bool updateCached = true)
654 {
655 super.SetCurrentPosition(pos, updateCached);
656
657 if (m_SoundObject)
658 {
659 Object parent = GetParent();
660
661 if (parent)
662 pos = parent.WorldToModel(pos);
663
664 m_SoundObject.SetPosition(pos);
665 }
666 }
667
673 {
674 if (m_SoundObject)
675 return m_SoundObject.GetPosition();
676
677 if (m_ParentObject)
678 return m_ParentObject.ModelToWorld(GetPosition());
679
680 return GetPosition();
681 }
682
688 override void SetCurrentLocalPosition(vector pos, bool updateCached = true)
689 {
690 super.SetCurrentLocalPosition(pos, updateCached);
691
692 if (m_SoundObject)
693 m_SoundObject.SetPosition(pos);
694 }
695
701 {
702 Object parent = GetParent();
703
704 if (m_SoundObject)
705 {
706 //TODO(kumarjac): Create and expose 'SoundObject.GetLocalPosition'
707 if (parent)
708 return parent.WorldToModel(m_SoundObject.GetPosition());
709 else
710 return m_SoundObject.GetPosition();
711 }
712 else
713 {
714 if (parent)
715 return GetLocalPosition();
716 else
717 return GetPosition();
718 }
719
720 return vector.Zero;
721 }
722
732
738 void SetSoundSet(string snd)
739 {
741 }
742
747 string GetSoundSet()
748 {
749 return m_SoundSetName;
750 }
751
757 {
759
762 }
763
772
779 {
780 return GetSoundWaveLength();
781 }
782
788 {
789 return m_SoundWaveLenght;
790 }
791
802
808 {
809 return m_SoundWaveVolume;
810 }
811
824
831 {
832 return m_SoundWaveTime;
833 }
834
840 {
842 }
843
852
858 {
860 m_SoundDoppler = 0;
861 if (setDoppler)
862 m_SoundDoppler = 1;
863 }
864
866
867
871 protected void SoundError(string err_msg)
872 {
873 ErrorEx(string.Format("%1: SoundSetName: '%2' :: %3", this, m_SoundSetName, err_msg));
874 }
875}
bool m_IsPlaying
Whether the Effect is currently playing.
Definition Effect.c:37
Object m_ParentObject
Cached parent.
Definition Effect.c:39
ref ScriptInvoker Event_OnEffectStarted
Event used when the actual effect started playing.
Definition Effect.c:24
EffectType
Enum to determine what type of effect the Effect is.
Definition Effect.c:3
ref ScriptInvoker Event_OnEffectEnded
Event used when the actual effect stopped playing.
Definition Effect.c:25
vector GetLocalPosition()
Get the local position of the Effect.
Definition Effect.c:470
ref ScriptInvoker Event_OnStopped
Event used when Stop was called.
Definition Effect.c:23
Event_OnStarted
Event used when Start was called.
Definition Effect.c:287
WaveKind
Definition Sound.c:2
class SoundObjectBuilder SoundObject(SoundParams soundParams)
void SoundObjectBuilder(SoundParams soundParams)
class JsonUndergroundAreaTriggerData GetPosition
proto bool IsHeaderLoaded()
proto float GetLength()
WARNING: Blocking! Waits for header to load.
proto void Loop(bool setLoop)
AbstractWaveEvents GetEvents()
Definition Sound.c:164
proto void Stop()
proto void SetVolumeRelative(float value)
proto void SetDoppler(bool setDoppler)
Wrapper class for managing sound through SEffectManager.
Definition EffectSound.c:5
void ~EffectSound()
dtor
Definition EffectSound.c:76
bool SoundLoadEx(out SoundParams params)
Loads in the sound when it is requested for playing through 'SoundPlayEx'.
override void SetCurrentLocalPosition(vector pos, bool updateCached=true)
Set the current local position of the managed sound.
void SetSoundSet(string snd)
Set soundset for the sound.
void Event_OnSoundWaveEnded()
Event called when sound stops playing.
override vector GetCurrentLocalPosition()
Get the current local position of the managed sound.
override bool IsPlaying()
Returns true when the effect is playing, false otherwise.
ref SoundParams m_SoundParams
Definition EffectSound.c:20
bool m_SetEnvVariables
Definition EffectSound.c:33
void UpdateEvents()
Enables the frame event on the EffectSound.
ref ScriptInvoker Event_OnSoundWaveStarted
Definition EffectSound.c:10
string m_SoundSetName
Definition EffectSound.c:31
override void Start()
Plays sound.
override void SetAutodestroy(bool auto_destroy)
Sets whether Effect automatically cleans up when it stops.
void SetSoundAutodestroy(bool auto_destroy)
Sets whether EffectSound automatically cleans up when sound stops.
override void SetParent(Object parent_obj)
Set parent for the sound to follow.
override Object GetParent()
Get parent for the EffectSound.
float m_SoundWaveVolume
Definition EffectSound.c:37
float GetSoundWaveLenght()
Get the sound wave length.
float GetSoundVolume()
Get the RELATIVE volume set by 'SetSoundVolume'.
float m_SoundFadeInDuration
Definition EffectSound.c:51
void SoundError(string err_msg)
Helper for throwing sound errors.
void SetSoundMaxVolume(float volume)
Set the sound max volume.
void SoundReset()
Resets EffectSound.
AbstractWave m_SoundWaveObject
Definition EffectSound.c:23
string GetSoundSet()
Get soundset for the sound.
WaveKind m_SoundWaveKind
Definition EffectSound.c:30
override void Event_OnRegistered(int id)
Event called from SEffectManager when the Effect is registered.
void SetDoppler(bool setDoppler)
Set if the sound has the doppler effect enabled.
override void InitEffect()
init
Definition EffectSound.c:84
bool m_SoundWaveIsPlaying
Definition EffectSound.c:35
override vector GetCurrentPosition()
Get the current world position of the managed sound.
bool SoundPlayEx(out SoundParams params)
Plays sound.
ref ScriptInvoker Event_OnSoundFadeOutStarted
Definition EffectSound.c:13
void EffectSound()
ctor
Definition EffectSound.c:62
void SetSoundLoop(bool loop)
Set if the sound loops.
float m_SoundWaveTime
Definition EffectSound.c:39
float m_SoundFadeOutInitVolume
Definition EffectSound.c:55
ref ScriptInvoker Event_OnSoundFadeInStopped
Definition EffectSound.c:12
float m_SoundWaveLenght
Definition EffectSound.c:36
void ValidateSoundWave()
Gets called to fill in the necessary data when the header has finished loading.
override void Event_OnFrameUpdate(float time_delta)
Event called on frame when enabled by SetEnableEventFrame(true)
override Object GetCurrentParent()
Get parent for the EffectSound.
void Event_OnSoundFadeOutStarted()
Event called when sound fade out starts.
void SetSoundVolume(float volume)
Set the RELATIVE volume for the sound.
bool m_SoundAutodestroy
Definition EffectSound.c:34
override EffectType GetEffectType()
Get what type of effect the Effect is.
bool SoundLoad()
Loads in the sound when it is requested for playing.
void SetSoundFadeIn(float fade_in)
Set the sound fade in duration.
override void Stop()
Stops sound.
void Event_OnSoundFadeInStopped()
Event called when sound fade in stops.
override bool IsSound()
Check whether the Effect is EffectSound without casting.
override bool CanDestroy()
void SetSoundWaveKind(WaveKind wave_kind)
Set WaveKind for the sound.
void SetSoundFadeOut(float fade_out)
Set the sound fade out duration.
float m_SoundFadeOutStartTime
Definition EffectSound.c:53
bool IsSoundPlaying()
Get whether EffectSound is currently playing.
float GetSoundWaveLength()
Get the sound wave length.
void SetEnviromentVariables(bool setEnvVariables)
Sets whether AddEnvSoundVariables needs to be called during Loading.
bool m_SoundWaveStarting
Definition EffectSound.c:47
int m_SoundDoppler
Definition EffectSound.c:40
override bool IsAutodestroy()
Get whether Effect automatically cleans up when it stops.
bool SoundWaveValidation()
Validation of fade settings.
void Event_OnSoundWaveStarted()
Event called when sound starts playing.
bool IsSoundValid()
Helper for checking if params are valid.
ref SoundObjectBuilder m_SoundObjectBuilder
Definition EffectSound.c:21
float m_SoundFadeOutDuration
Definition EffectSound.c:54
override string GetDebugName()
Override when getting debug information.
Definition EffectSound.c:96
bool m_SoundLoop
Definition EffectSound.c:32
bool m_SoundFadedOut
Definition EffectSound.c:49
bool IsSoundAutodestroy()
Get whether EffectSound automatically cleans up when sound stops.
ref SoundObject m_SoundObject
Definition EffectSound.c:22
ref ScriptInvoker Event_OnSoundWaveEnded
Definition EffectSound.c:11
bool SoundPlay()
Plays sound.
override void SetCurrentPosition(vector pos, bool updateCached=true)
Set the world position of the managed sound.
override void Event_OnUnregistered()
Event called from SEffectManager when the Effect is unregistered.
float m_SoundWaveVolumeMax
Definition EffectSound.c:38
bool m_SoundWaveStopping
Definition EffectSound.c:48
void SoundStop()
Stops sound.
float GetSoundWaveTime()
Get the time since EffectSound started playing.
Manager class for managing Effect (EffectParticle, EffectSound)
static void Event_OnSoundWaveEnded(EffectSound effect_sound)
Event called from EffectSound.Event_OnSoundWaveEnded.
ScriptInvoker Class provide list of callbacks usage:
Definition tools.c:116
static const vector Zero
Definition EnConvert.c:110
proto native CGame GetGame()
void SetEnableEventFrame(bool enable)
Enable Event_OnFrameUpdate for the effect.
Definition Effect.c:270
enum ShapeType ErrorEx