DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
EffectSound.c
Go to the documentation of this file.
1
5{
15
25
32 protected string m_SoundSetName;
33 protected bool m_SoundLoop;
34 protected bool m_SetEnvVariables;
35 protected bool m_SoundAutodestroy;
36 protected bool m_SoundWaveIsPlaying;
37 protected float m_SoundWaveLenght;
38 protected float m_SoundWaveVolume;
39 protected float m_SoundWaveVolumeMax;
40 protected float m_SoundWaveTime;
42
47 protected bool m_SoundWaveStarting;
48 protected bool m_SoundWaveStopping;
49
50 protected float m_SoundFadeInDuration;
51
52 protected float m_SoundFadeOutStartTime;
53 protected float m_SoundFadeOutDuration;
54 protected float m_SoundFadeOutInitVolume;
56
57
58
63 {
64 m_SoundWaveKind = WaveKind.WAVEEFFECTEX;
67 m_SoundAutodestroy = false;
68 m_SoundWaveStopping = false;
69 }
70
75 {
76
77 }
78
82 override void InitEffect()
83 {
84 super.InitEffect();
85
86 // These will be called by the sound events
89 }
90
94 override string GetDebugName()
95 {
96 string identifier;
97 if (m_SoundSetName != "")
98 {
99 identifier = m_SoundSetName;
100 }
101 else
102 {
103 identifier = "NO_SOUNDSET";
104 }
105
106 return string.Format("%1:%2", super.GetDebugName(), identifier);
107 }
108
109
110
115
121 {
122 return EffectType.SOUND;
123 }
124
129 override bool IsSound()
130 {
131 return true;
132 }
133
135
136
137
143
149 bool SoundPlayEx(out SoundParams params)
150 {
151 super.Start();
152
153 if (m_SoundSetName != "")
154 {
155 if ( SoundLoadEx(params) )
156 {
158 {
162 }
163
164 if ( m_SoundObject )
165 {
168 if( !m_SoundWaveObject )
169 return false;
170
171 // Wait for header to be loaded before asking for its length, else we block the main thread
174 else
175 m_SoundWaveObject.GetEvents().Event_OnSoundWaveHeaderLoaded.Insert(ValidateSoundWave);
176
177 return true;
178 }
179 else
180 {
181 SoundError("m_SoundObject is null.");
182 }
183 }
184 }
185
186 return false;
187 }
188
194 {
195 SoundParams params;
196 return SoundPlayEx(params);
197 }
198
202 override void Start()
203 {
204 SoundPlay();
205 }
206
212 {
213 super.Stop();
214
215 if ( IsSoundPlaying() )
216 {
218 {
219 m_SoundWaveStopping = true;
220 m_SoundWaveStarting = false;
222 }
223 else
224 {
226 }
227 }
228 else
229 {
230 SoundReset();
231 }
232 }
233
237 override void Stop()
238 {
239 SoundStop();
240 }
241
245 protected void SoundReset()
246 {
247 m_IsPlaying = false;
248 m_SoundWaveIsPlaying = false;
250 m_SoundWaveTime = 0;
253
254 if ( m_SoundWaveObject )
255 {
258 }
259 }
260
266 {
268 }
269
273 override bool IsPlaying()
274 {
275 return IsSoundPlaying(); // Just in case, as that's what used to be the actual way to check
276 }
277
279
280
281
286
291 bool SoundLoadEx(out SoundParams params)
292 {
294 {
295 if (!params)
296 {
297 params = new SoundParams( m_SoundSetName );
298 }
299
300 //Print("SoundLoad is loading..");
301 m_SoundParams = params;
302 if ( !m_SoundParams.IsValid() )
303 {
304 SoundError("Invalid sound set.");
305 return false;
306 }
307
310 {
312 }
313
315
316 if ( m_SoundObject )
317 {
319 }
320 else
321 {
322 SoundError("m_SoundObject is null.");
323 }
324 }
325 else
326 {
327 //Print("SoundLoad is loaded.");
328 }
329
330 return true;
331 }
332
338 {
339 SoundParams params;
340 return SoundLoadEx(params);
341 }
342
347 {
348 return m_SoundParams.IsValid();
349 }
350
355 protected void ValidateSoundWave()
356 {
358
359 if ( SoundWaveValidation() )
360 {
361 if ( m_SoundFadeInDuration > 0 )
362 {
365 }
366
368
369 m_SoundWaveStarting = true;
370
371 AbstractWaveEvents events = m_SoundWaveObject.GetEvents();
372 events.Event_OnSoundWaveStarted.Insert( Event_OnSoundWaveStarted );
373 events.Event_OnSoundWaveEnded.Insert( Event_OnSoundWaveEnded );
374
375 UpdateEvents();
376 }
377 else
378 {
380 }
381 }
382
387 protected bool SoundWaveValidation()
388 {
389 bool valid = true;
390
392 {
393 SoundError("FadeIn is longer than sound wave length.");
394 valid = false;
395 }
396
398 {
399 SoundError("FadeOut is longer than sound wave length.");
400 valid = false;
401 }
402
404 {
405 SoundError("FadeIn & FadeOut are longer than sound wave length.");
406 valid = false;
407 }
408
409 return valid;
410 }
411
417 protected void UpdateEvents()
418 {
419 if ( m_SoundWaveObject )
420 {
422 }
423 else
424 {
425 SetEnableEventFrame(false);
426 }
427 }
428
430
431
432
437
444 override void Event_OnFrameUpdate(float time_delta)
445 {
446 if ( IsSoundPlaying() )
447 {
448 // Make the sound follow the parent
449 if ( m_SoundParent )
450 {
452 }
453
454 // FadeIn
456 {
457 if ( m_SoundFadeInDuration > 0 )
458 {
460
462 {
465 m_SoundWaveStarting = false;
466 }
467 }
468 else
469 {
471 m_SoundWaveStarting = false;
472 }
473 }
474
475 // FadeOut
477 {
478 if ( m_SoundFadeOutDuration > 0 )
479 {
480 if ( m_SoundFadeOutInitVolume == 0 )
481 {
484 }
486 }
487 else
488 {
489 SetSoundVolume( 0 );
490 }
491
492 if ( GetSoundVolume() <= 0 )
493 {
494 if ( m_SoundWaveObject )
495 {
497 }
498 }
499 }
500
501 // Counting timer here because loop play
502 m_SoundWaveTime += time_delta;
503 }
504 }
505
511 override void Event_OnRegistered(int id)
512 {
513 super.Event_OnRegistered(id);
514
516 }
517
522 override void Event_OnUnregistered()
523 {
524 super.Event_OnUnregistered();
525
527 }
528
534 {
536
538
540 }
541
547 {
548 m_SoundWaveIsPlaying = false;
549
551
553 }
554
560 {
562 }
563
569 {
571 }
572
574
575
576
581
587 override void SetAutodestroy(bool auto_destroy)
588 {
589 super.SetAutodestroy(auto_destroy);
590 m_SoundAutodestroy = auto_destroy;
591 }
592
597 override bool IsAutodestroy()
598 {
599 return IsSoundAutodestroy();
600 }
601
606 void SetSoundAutodestroy(bool auto_destroy)
607 {
608 SetAutodestroy(auto_destroy);
609 }
610
616 {
617 return m_SoundAutodestroy;
618 }
619
621
622
623
628
635 override void SetParent(Object parent_obj)
636 {
637 super.SetParent(parent_obj); // ...
638 m_SoundParent = parent_obj; // ......
639 }
640
645 override Object GetParent()
646 {
647 // .........
648 if (m_SoundParent)
649 return m_SoundParent;
650 else
651 return super.GetParent();
652 }
653
661 override void SetCurrentParent(Object parent_obj, bool updateCached = true)
662 {
663 super.SetCurrentParent(parent_obj, updateCached); // ...
664 m_SoundParent = parent_obj; // ......
665 }
666
673 {
674 // .........
675 if (m_SoundParent)
676 return m_SoundParent;
677 else
678 return super.GetParent(); // Yes, intentionally this one
679 }
680
686 override void SetCurrentPosition( vector pos, bool updateCached = true )
687 {
688 super.SetCurrentPosition(pos, updateCached);
689
690 if (m_SoundObject)
691 m_SoundObject.SetPosition(pos);
692 }
693
699 {
700 if (m_SoundObject)
701 return m_SoundObject.GetPosition();
702 else
703 return super.GetCurrentPosition();
704 }
705
711 override void SetCurrentLocalPosition( vector pos, bool updateCached = true )
712 {
713 super.SetCurrentLocalPosition(pos, updateCached);
714
715 if (m_SoundObject)
716 {
717 Object parent = GetParent();
718
719 if (parent)
720 m_SoundObject.SetPosition(parent.ModelToWorld(pos));
721 else
722 m_SoundObject.SetPosition(pos);
723 }
724 }
725
731 {
732 if (m_SoundObject)
733 {
734 Object parent = GetParent();
735
736 if (parent)
737 return parent.WorldToModel(m_SoundObject.GetPosition());
738 else
739 return m_SoundObject.GetPosition();
740 }
741 else
742 return super.GetCurrentLocalPosition();
743 }
744
751 {
752 m_SoundWaveKind = wave_kind;
753 }
754
760 void SetSoundSet(string snd)
761 {
762 m_SoundSetName = snd;
763 }
764
769 string GetSoundSet()
770 {
771 return m_SoundSetName;
772 }
773
778 void SetSoundLoop(bool loop)
779 {
780 m_SoundLoop = loop;
781
782 if ( m_SoundWaveObject )
783 m_SoundWaveObject.Loop( loop );
784 }
785
790 void SetEnviromentVariables(bool setEnvVariables)
791 {
792 m_SetEnvVariables = setEnvVariables;
793 }
794
801 {
802 return GetSoundWaveLength();
803 }
804
810 {
811 return m_SoundWaveLenght;
812 }
813
818 void SetSoundVolume(float volume)
819 {
820 m_SoundWaveVolume = volume;
821 if ( m_SoundWaveObject )
823 }
824
830 {
831 return m_SoundWaveVolume;
832 }
833
840 void SetSoundMaxVolume(float volume)
841 {
842 m_SoundWaveVolumeMax = volume;
843 if ( m_SoundWaveObject )
845 }
846
853 {
854 return m_SoundWaveTime;
855 }
856
861 void SetSoundFadeIn(float fade_in)
862 {
863 m_SoundFadeInDuration = fade_in;
864 }
865
870 void SetSoundFadeOut(float fade_out)
871 {
872 m_SoundFadeOutDuration = fade_out;
873 }
874
876
877
878
882 protected void SoundError(string err_msg)
883 {
884 ErrorEx(string.Format("%1: SoundSetName: '%2' :: %3", this, m_SoundSetName, err_msg));
885 }
886}
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
protected bool m_IsPlaying
Whether the Effect is currently playing.
Definition Effect.c:37
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:477
ref ScriptInvoker Event_OnStopped
Event used when Stop was called.
Definition Effect.c:23
void Effect()
ctor
Definition Effect.c:70
Event_OnStarted
Event used when Start was called.
Definition Effect.c:291
WaveKind
Definition Sound.c:2
class SoundObjectBuilder SoundObject(SoundParams soundParams)
class JsonUndergroundAreaTriggerData GetPosition
proto void Loop(bool setLoop)
proto void SetVolumeRelative(float value)
proto bool IsHeaderLoaded()
AbstractWaveEvents GetEvents()
Definition Sound.c:135
proto void Stop()
proto float GetLength()
WARNING: Blocking! Waits for header to load.
proto native AbstractSoundScene GetSoundScene()
Wrapper class for managing sound through SEffectManager.
Definition EffectSound.c:5
protected ref SoundObject m_SoundObject
Definition EffectSound.c:22
void SetEnviromentVariables(bool setEnvVariables)
Sets whether UpdateEnvSoundControllers needs to be called during Loading.
void ~EffectSound()
dtor
Definition EffectSound.c:74
ref ScriptInvoker Event_OnSoundFadeOutStarted
Definition EffectSound.c:13
bool SoundPlay()
Plays sound.
override string GetDebugName()
Override when getting debug information.
Definition EffectSound.c:94
protected void SoundReset()
Resets EffectSound.
ref ScriptInvoker Event_OnSoundWaveEnded
Definition EffectSound.c:11
protected float m_SoundWaveTime
Definition EffectSound.c:40
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.
protected bool m_SoundWaveIsPlaying
Definition EffectSound.c:36
void SetSoundSet(string snd)
Set soundset for the sound.
protected AbstractWave m_SoundWaveObject
Definition EffectSound.c:23
override void SetCurrentParent(Object parent_obj, bool updateCached=true)
Set parent for the sound to follow.
override void InitEffect()
init
Definition EffectSound.c:82
protected float m_SoundWaveVolume
Definition EffectSound.c:38
void Event_OnSoundWaveStarted()
Event called when sound starts playing.
void Event_OnSoundFadeOutStarted()
Event called when sound fade out starts.
protected float m_SoundFadeOutDuration
Definition EffectSound.c:53
protected bool m_SoundWaveStopping
Definition EffectSound.c:48
bool IsSoundPlaying()
Get whether EffectSound is currently playing.
bool SoundLoad()
Loads in the sound when it is requested for playing.
void SetSoundVolume(float volume)
Set the RELATIVE volume for the sound.
void SetSoundMaxVolume(float volume)
Set the sound max volume.
override void Start()
Plays sound.
bool SoundLoadEx(out SoundParams params)
Loads in the sound when it is requested for playing through 'SoundPlayEx'.
override bool IsSound()
Check whether the Effect is EffectSound without casting.
protected bool m_SetEnvVariables
Definition EffectSound.c:34
override vector GetCurrentPosition()
Get the current world position of the managed sound.
protected float m_SoundFadeInDuration
Definition EffectSound.c:50
protected float m_SoundFadeOutInitVolume
Definition EffectSound.c:54
protected bool m_SoundLoop
Definition EffectSound.c:33
bool IsSoundAutodestroy()
Get whether EffectSound automatically cleans up when sound stops.
override vector GetCurrentLocalPosition()
Get the current local position of the managed sound.
protected void UpdateEvents()
Enables the frame event on the EffectSound.
void SetSoundFadeOut(float fade_out)
Set the sound fade out duration.
float GetSoundWaveLenght()
Get the sound wave length.
string GetSoundSet()
Get soundset for the sound.
void SetSoundWaveKind(WaveKind wave_kind)
Set WaveKind for the sound.
protected Object m_SoundParent
Definition EffectSound.c:30
protected ref SoundObjectBuilder m_SoundObjectBuilder
Definition EffectSound.c:21
void SetSoundAutodestroy(bool auto_destroy)
Sets whether EffectSound automatically cleans up when sound stops.
protected bool m_SoundWaveStarting
Definition EffectSound.c:47
protected float m_SoundWaveLenght
Definition EffectSound.c:37
float GetSoundWaveTime()
Get the time since EffectSound started playing.
override void Stop()
Stops sound.
ref ScriptInvoker Event_OnSoundFadeInStopped
Definition EffectSound.c:12
protected float m_SoundWaveVolumeMax
Definition EffectSound.c:39
protected void SoundError(string err_msg)
Helper for throwing sound errors.
void EffectSound()
ctor
Definition EffectSound.c:62
void Event_OnSoundFadeInStopped()
Event called when sound fade in stops.
override void Event_OnFrameUpdate(float time_delta)
Event called on frame when enabled by SetEnableEventFrame(true)
override void Event_OnRegistered(int id)
Event called from SEffectManager when the Effect is registered.
override Object GetParent()
Get parent for the EffectSound.
protected ref SoundParams m_SoundParams
Definition EffectSound.c:20
override Object GetCurrentParent()
Get parent for the EffectSound.
override void SetParent(Object parent_obj)
Set parent for the sound to follow.
bool IsSoundValid()
Helper for checking if params are valid.
protected void ValidateSoundWave()
Gets called to fill in the necessary data when the header has finished loading.
override bool IsAutodestroy()
Get whether Effect automatically cleans up when it stops.
protected string m_SoundSetName
Definition EffectSound.c:32
float GetSoundWaveLength()
Get the sound wave length.
protected float m_SoundFadeOutStartTime
Definition EffectSound.c:52
void SoundStop()
Stops sound.
override void SetCurrentLocalPosition(vector pos, bool updateCached=true)
Set the current local position of the managed sound.
void SetSoundFadeIn(float fade_in)
Set the sound fade in duration.
bool SoundPlayEx(out SoundParams params)
Plays sound.
ref ScriptInvoker Event_OnSoundWaveStarted
Definition EffectSound.c:10
float GetSoundVolume()
Get the RELATIVE volume set by 'SetSoundVolume'.
override void SetAutodestroy(bool auto_destroy)
Sets whether Effect automatically cleans up when it stops.
override EffectType GetEffectType()
Get what type of effect the Effect is.
void SetSoundLoop(bool loop)
Set if the sound loops.
protected bool m_SoundAutodestroy
Definition EffectSound.c:35
override bool IsPlaying()
Returns true when the effect is playing, false otherwise.
void Event_OnSoundWaveEnded()
Event called when sound stops playing.
protected WaveKind m_SoundWaveKind
Definition EffectSound.c:31
protected bool SoundWaveValidation()
Validation of fade settings.
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
proto bool Remove(func fn, int flags=EScriptInvokerRemoveFlags.ALL)
remove specific call from list
proto void Invoke(void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
invoke call on all inserted methods with given arguments
proto bool Insert(func fn, int flags=EScriptInvokerInsertFlags.IMMEDIATE)
insert method to list
proto native void UpdateEnvSoundControllers(vector position)
SoundObject BuildSoundObject()
Definition Sound.c:49
proto native bool IsValid()
proto native CGame GetGame()
void SetEnableEventFrame(bool enable)
Enable Event_OnFrameUpdate for the effect.
Definition Effect.c:269
enum ShapeType ErrorEx
static proto string Format(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
Gets n-th character from string.