Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
effectsound.c
Go to the documentation of this file.
1
4class EffectSound : Effect
5{
10 ref ScriptInvoker Event_OnSoundWaveStarted = new ScriptInvoker();
11 ref ScriptInvoker Event_OnSoundWaveEnded = new ScriptInvoker();
12 ref ScriptInvoker Event_OnSoundFadeInStopped = new ScriptInvoker();
13 ref ScriptInvoker Event_OnSoundFadeOutStarted = new ScriptInvoker();
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
59
64 {
65 m_SoundWaveKind = WaveKind.WAVEEFFECTEX;
68 m_SoundAutodestroy = false;
69 m_SoundWaveStopping = false;
70 m_SoundFadedOut = false;
71 m_SoundDoppler = -1;
72 }
73
78 {
79
80 }
81
85 override void InitEffect()
86 {
87 super.InitEffect();
88
89 // These will be called by the sound events
92 }
93
97 override string GetDebugName()
98 {
99 string identifier;
100 if (m_SoundSetName != "")
101 {
102 identifier = m_SoundSetName;
103 }
104 else
105 {
106 identifier = "NO_SOUNDSET";
107 }
108
109 return string.Format("%1:%2", super.GetDebugName(), identifier);
110 }
111
112
113
118
124 {
125 return EffectType.SOUND;
126 }
127
132 override bool IsSound()
133 {
134 return true;
135 }
136
138
139
140
146
152 bool SoundPlayEx(out SoundParams params)
153 {
154 super.Start();
155
156 if (m_SoundSetName != "")
157 {
158 vector position = GetCurrentLocalPosition();
159
160 if ( SoundLoadEx(params) )
161 {
163 {
164 m_SoundObjectBuilder.AddEnvSoundVariables(GetPosition());
165 m_SoundObject = m_SoundObjectBuilder.BuildSoundObject();
168 }
169
170 if ( m_SoundObject )
171 {
172 SetCurrentLocalPosition(position, false);
173 m_SoundWaveObject = GetGame().GetSoundScene().Play3D( m_SoundObject, m_SoundObjectBuilder );
174 if ( !m_SoundWaveObject )
175 return false;
176
177 // Wait for header to be loaded before asking for its length, else we block the main thread
178 if (m_SoundWaveObject.IsHeaderLoaded())
180 else
181 m_SoundWaveObject.GetEvents().Event_OnSoundWaveHeaderLoaded.Insert(ValidateSoundWave);
182
183 return true;
184 }
185 else
186 {
187 SoundError("m_SoundObject is null.");
188 }
189 }
190 }
191
192 return false;
193 }
194
200 {
201 SoundParams params;
202 return SoundPlayEx(params);
203 }
204
208 override void Start()
209 {
210 SoundPlay();
211 }
212
218 {
219 super.Stop();
220
221 if ( IsSoundPlaying() )
222 {
224 {
225 m_SoundWaveStopping = true;
226 m_SoundFadedOut = false;
227 m_SoundWaveStarting = false;
229 }
230 else
231 {
232 m_SoundWaveObject.Stop();
233 }
234 }
235 else if (!IsPendingDeletion()) // not about to be destroyed
236 {
237 SoundReset();
238 }
239 }
240
244 override void Stop()
245 {
246 SoundStop();
247 }
248
252 protected void SoundReset()
253 {
254 m_IsPlaying = false;
255 m_SoundWaveIsPlaying = false;
256 m_SoundWaveStopping = false;
257 m_SoundFadedOut = false;
259 m_SoundWaveTime = 0;
262
263 if ( m_SoundWaveObject )
264 {
265 m_SoundWaveObject.Stop();
266 m_SoundWaveObject.SetVolumeRelative( m_SoundWaveVolumeMax );
267 }
268 }
269
275 {
277 }
278
282 override bool IsPlaying()
283 {
284 return IsSoundPlaying(); // Just in case, as that's what used to be the actual way to check
285 }
286
288
289
290
295
300 bool SoundLoadEx(out SoundParams params)
301 {
302 if ( !m_SoundParams || !m_SoundParams.IsValid() )
303 {
304 if (!params)
305 {
306 params = new SoundParams( m_SoundSetName );
307 }
308
309 //Print("SoundLoad is loading..");
310 m_SoundParams = params;
311 if ( !m_SoundParams.IsValid() )
312 {
313 SoundError("Invalid sound set.");
314 return false;
315 }
316
319 {
320 m_SoundObjectBuilder.AddEnvSoundVariables(GetPosition());
321 }
322
323 m_SoundObject = m_SoundObjectBuilder.BuildSoundObject();
324
325 if ( m_SoundObject )
326 {
329 }
330 else
331 {
332 SoundError("m_SoundObject is null.");
333 }
334 }
335 else
336 {
337 //Print("SoundLoad is loaded.");
338 }
339
340 return true;
341 }
342
348 {
349 SoundParams params;
350 return SoundLoadEx(params);
351 }
352
357 {
358 return m_SoundParams.IsValid();
359 }
360
365 protected void ValidateSoundWave()
366 {
368 {
369 ErrorEx(string.Format("%1 SoundWaveObject is null. SoundSet: %2", this.ToString(), m_SoundSetName));
370 return;
371 }
372
374
375 if ( SoundWaveValidation() )
376 {
377 if ( m_SoundFadeInDuration > 0 )
378 {
379 m_SoundWaveObject.SetVolumeRelative( 0 );
381 }
382
384
385 m_SoundWaveStarting = true;
386
387 AbstractWaveEvents events = m_SoundWaveObject.GetEvents();
388 events.Event_OnSoundWaveStarted.Insert( Event_OnSoundWaveStarted );
389 events.Event_OnSoundWaveEnded.Insert( Event_OnSoundWaveEnded );
390
391 UpdateEvents();
392 }
393 else
394 {
395 m_SoundWaveObject.Stop();
396 }
397 }
398
403 protected bool SoundWaveValidation()
404 {
405 bool valid = true;
406
408 {
409 SoundError("FadeIn is longer than sound wave length.");
410 valid = false;
411 }
412
414 {
415 SoundError("FadeOut is longer than sound wave length.");
416 valid = false;
417 }
418
420 {
421 SoundError("FadeIn & FadeOut are longer than sound wave length.");
422 valid = false;
423 }
424
425 return valid;
426 }
427
433 protected void UpdateEvents()
434 {
435 if ( m_SoundWaveObject )
436 {
438 }
439 else
440 {
441 SetEnableEventFrame(false);
442 }
443 }
444
446
447
448
453
460 override void Event_OnFrameUpdate(float time_delta)
461 {
462 if ( IsSoundPlaying() )
463 {
464 if (m_SoundDoppler != -1)
465 {
467 }
468 // FadeIn
470 {
471 if ( m_SoundFadeInDuration > 0 )
472 {
474
476 {
477 Event_OnSoundFadeInStopped();
479 m_SoundWaveStarting = false;
480 }
481 }
482 else
483 {
485 m_SoundWaveStarting = false;
486 }
487 }
488
489 // FadeOut
491 {
492 if ( m_SoundFadeOutDuration > 0 )
493 {
494 if ( m_SoundFadeOutInitVolume == 0 )
495 {
497 Event_OnSoundFadeOutStarted();
498 }
500 }
501 else
502 {
503 SetSoundVolume( 0 );
504 }
505
506 if ( GetSoundVolume() <= 0 )
507 {
508 if ( m_SoundWaveObject )
509 {
510 m_SoundWaveObject.Stop();
511 m_SoundWaveStopping = false;
512 m_SoundFadedOut = true;
513 }
514 }
515 }
516
517 // Counting timer here because loop play
518 m_SoundWaveTime += time_delta;
519 }
520 }
521
527 override void Event_OnRegistered(int id)
528 {
529 super.Event_OnRegistered(id);
530
532 }
533
538 override void Event_OnUnregistered()
539 {
540 super.Event_OnUnregistered();
541
543 }
544
550 {
552
553 Event_OnSoundWaveStarted.Invoke(this);
554
556 }
557
563 {
564 m_SoundWaveIsPlaying = false;
565
566 Event_OnSoundWaveEnded.Invoke(this);
567
569 }
570
576 {
577 Event_OnSoundFadeInStopped.Invoke(this);
578 }
579
585 {
586 Event_OnSoundFadeOutStarted.Invoke(this);
587 }
588
590
591
592
597
603 override void SetAutodestroy(bool auto_destroy)
604 {
605 super.SetAutodestroy(auto_destroy);
606 m_SoundAutodestroy = auto_destroy;
607 }
608
613 override bool IsAutodestroy()
614 {
615 return IsSoundAutodestroy();
616 }
617
622 void SetSoundAutodestroy(bool auto_destroy)
623 {
624 SetAutodestroy(auto_destroy);
625 }
626
632 {
633 return m_SoundAutodestroy;
634 }
635
636 override bool CanDestroy()
637 {
639 }
640
642
643
644
649
654 override void SetParent(Object parent_obj, int pivot)
655 {
656 super.SetParent(parent_obj, pivot); // ...
657
658 if (m_SoundObject)
659 {
660 m_SoundObject.SetParent(parent_obj, pivot);
661 }
662 }
663
668 override Object GetParent()
669 {
670 if (m_SoundObject)
671 return Object.Cast(m_SoundObject.GetParent());
672 else
673 return super.GetParent();
674 }
675
681 override int GetPivotIndex()
682 {
683 if (m_SoundObject)
684 return m_SoundObject.GetHierarchyPivot();
685 else
686 return super.GetPivotIndex();
687 }
688
695 {
696 if (m_SoundObject)
697 return Object.Cast(m_SoundObject.GetParent());
698 else
699 return super.GetParent(); // Yes, intentionally this one
700 }
701
707 override void SetCurrentPosition( vector pos, bool updateCached = true )
708 {
709 super.SetCurrentPosition(pos, updateCached);
710
711 if (m_SoundObject)
712 {
713 Object parent = GetParent();
714
715 if (parent)
716 pos = parent.WorldToModel(pos);
717
718 m_SoundObject.SetPosition(pos);
719 }
720 }
721
727 {
728 if (m_SoundObject)
729 return m_SoundObject.GetPosition();
730
731 if (m_ParentObject)
732 return m_ParentObject.ModelToWorld(GetPosition());
733
734 return GetPosition();
735 }
736
742 override void SetCurrentLocalPosition( vector pos, bool updateCached = true )
743 {
744 super.SetCurrentLocalPosition(pos, updateCached);
745
746 if (m_SoundObject)
747 {
748 m_SoundObject.SetPosition(pos);
749 }
750 }
751
757 {
758 Object parent = GetParent();
759
760 if (m_SoundObject)
761 {
762 //TODO(kumarjac): Create and expose 'SoundObject.GetLocalPosition'
763 if (parent)
764 return parent.WorldToModel(m_SoundObject.GetPosition());
765 else
766 return m_SoundObject.GetPosition();
767 }
768 else
769 {
770 if (parent)
771 return GetLocalPosition();
772 else
773 return GetPosition();
774 }
775
776 return vector.Zero;
777 }
778
785 {
786 m_SoundWaveKind = wave_kind;
787 }
788
794 void SetSoundSet(string snd)
795 {
796 m_SoundSetName = snd;
797 }
798
803 string GetSoundSet()
804 {
805 return m_SoundSetName;
806 }
807
812 void SetSoundLoop(bool loop)
813 {
814 m_SoundLoop = loop;
815
816 if ( m_SoundWaveObject )
817 m_SoundWaveObject.Loop( loop );
818 }
819
824 void SetEnviromentVariables(bool setEnvVariables)
825 {
826 m_SetEnvVariables = setEnvVariables;
827 }
828
835 {
836 return GetSoundWaveLength();
837 }
838
844 {
845 return m_SoundWaveLenght;
846 }
847
852 void SetSoundVolume(float volume)
853 {
854 m_SoundWaveVolume = volume;
855 if ( m_SoundWaveObject )
856 m_SoundWaveObject.SetVolumeRelative( volume );
857 }
858
864 {
865 return m_SoundWaveVolume;
866 }
867
874 void SetSoundMaxVolume(float volume)
875 {
876 m_SoundWaveVolumeMax = volume;
877 if ( m_SoundWaveObject )
878 m_SoundWaveObject.SetVolumeRelative( m_SoundWaveVolume );
879 }
880
887 {
888 return m_SoundWaveTime;
889 }
890
895 void SetSoundFadeIn(float fade_in)
896 {
897 m_SoundFadeInDuration = fade_in;
898 }
899
904 void SetSoundFadeOut(float fade_out)
905 {
906 m_SoundFadeOutDuration = fade_out;
907 }
908
913 void SetDoppler(bool setDoppler)
914 {
916 m_SoundDoppler = 0;
917 if (setDoppler)
918 {
919 m_SoundDoppler = 1;
920 }
921 }
922
924
925
926
930 protected void SoundError(string err_msg)
931 {
932 ErrorEx(string.Format("%1: SoundSetName: '%2' :: %3", this, m_SoundSetName, err_msg));
933 }
934}
Wrapper class for managing sound through SEffectManager.
Definition effectsound.c:5
void ~EffectSound()
dtor
Definition effectsound.c:77
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.
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 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:85
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.
void EffectSound()
ctor
Definition effectsound.c:63
void SetSoundLoop(bool loop)
Set if the sound loops.
float m_SoundWaveTime
Definition effectsound.c:39
float m_SoundFadeOutInitVolume
Definition effectsound.c:55
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:97
override void SetParent(Object parent_obj, int pivot)
Set parent for the sound to follow.
bool m_SoundLoop
Definition effectsound.c:32
override int GetPivotIndex()
Get parent pivot of the Effect, only valid when there is some GetParent.
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
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
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
int m_PivotIndex
Cached parent pivot id.
Definition effect.c:41
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:513
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:304
proto string ToString()
proto native CGame GetGame()
void SetEnableEventFrame(bool enable)
Enable Event_OnFrameUpdate for the effect.
Definition effect.c:282
enum ShapeType ErrorEx
bool IsPendingDeletion()
Get whether the Effect is queued up for being cleaned up.
Definition effect.c:260
ref ScriptInvoker Event_OnSoundWaveEnded
Definition sound.c:162
class AbstractSoundScene SoundObjectBuilder(SoundParams soundParams)
class JsonUndergroundAreaTriggerData GetPosition
void AbstractWave()
Definition sound.c:167
class SoundObject SoundParams(string name)
ref ScriptInvoker Event_OnSoundWaveStarted
Definition sound.c:158
WaveKind
Definition sound.c:2