DayZ 1.30
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
EffectSound.c
См. документацию.
1
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
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 {
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 {
173 m_SoundWaveObject = g_Game.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();
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 {
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 {
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 if (m_SoundFadeInDuration > 0)
553 {
555 }
556
557 Event_OnSoundWaveStarted.Invoke(this);
558
560 }
561
567 {
568 m_SoundWaveIsPlaying = false;
569
570 Event_OnSoundWaveEnded.Invoke(this);
571
573 }
574
580 {
581 Event_OnSoundFadeInStopped.Invoke(this);
582 }
583
589 {
590 Event_OnSoundFadeOutStarted.Invoke(this);
591 }
592
594
595
596
601
607 override void SetAutodestroy(bool auto_destroy)
608 {
609 super.SetAutodestroy(auto_destroy);
610 m_SoundAutodestroy = auto_destroy;
611 }
612
617 override bool IsAutodestroy()
618 {
619 return IsSoundAutodestroy();
620 }
621
626 void SetSoundAutodestroy(bool auto_destroy)
627 {
628 SetAutodestroy(auto_destroy);
629 }
630
636 {
637 return m_SoundAutodestroy;
638 }
639
640 override bool CanDestroy()
641 {
643 }
644
646
647
648
653
658 override void SetParent(Object parent_obj, int pivot)
659 {
660 super.SetParent(parent_obj, pivot); // ...
661
662 if (m_SoundObject)
663 {
664 m_SoundObject.SetParent(parent_obj, pivot);
665 }
666 }
667
672 override Object GetParent()
673 {
674 if (m_SoundObject)
675 return Object.Cast(m_SoundObject.GetParent());
676 else
677 return super.GetParent();
678 }
679
685 override int GetPivotIndex()
686 {
687 if (m_SoundObject)
688 return m_SoundObject.GetHierarchyPivot();
689 else
690 return super.GetPivotIndex();
691 }
692
699 {
700 if (m_SoundObject)
701 return Object.Cast(m_SoundObject.GetParent());
702 else
703 return super.GetParent(); // Yes, intentionally this one
704 }
705
711 override void SetCurrentPosition( vector pos, bool updateCached = true )
712 {
713 super.SetCurrentPosition(pos, updateCached);
714
715 if (m_SoundObject)
716 {
717 Object parent = GetParent();
718
719 if (parent)
720 pos = parent.WorldToModel(pos);
721
722 m_SoundObject.SetPosition(pos);
723 }
724 }
725
731 {
732 if (m_SoundObject)
733 return m_SoundObject.GetPosition();
734
735 if (m_ParentObject)
736 return m_ParentObject.ModelToWorld(GetPosition());
737
738 return GetPosition();
739 }
740
746 override void SetCurrentLocalPosition( vector pos, bool updateCached = true )
747 {
748 super.SetCurrentLocalPosition(pos, updateCached);
749
750 if (m_SoundObject)
751 {
752 m_SoundObject.SetPosition(pos);
753 }
754 }
755
761 {
762 Object parent = GetParent();
763
764 if (m_SoundObject)
765 {
766 //TODO(kumarjac): Create and expose 'SoundObject.GetLocalPosition'
767 if (parent)
768 return parent.WorldToModel(m_SoundObject.GetPosition());
769 else
770 return m_SoundObject.GetPosition();
771 }
772 else
773 {
774 if (parent)
775 return GetLocalPosition();
776 else
777 return GetPosition();
778 }
779
780 return vector.Zero;
781 }
782
789 {
790 m_SoundWaveKind = wave_kind;
791 }
792
798 void SetSoundSet(string snd)
799 {
800 m_SoundSetName = snd;
801 }
802
807 string GetSoundSet()
808 {
809 return m_SoundSetName;
810 }
811
816 void SetSoundLoop(bool loop)
817 {
818 m_SoundLoop = loop;
819
820 if ( m_SoundWaveObject )
821 m_SoundWaveObject.Loop( loop );
822 }
823
828 void SetEnviromentVariables(bool setEnvVariables)
829 {
830 m_SetEnvVariables = setEnvVariables;
831 }
832
839 {
840 return GetSoundWaveLength();
841 }
842
848 {
849 return m_SoundWaveLenght;
850 }
851
856 void SetSoundVolume(float volume)
857 {
858 m_SoundWaveVolume = volume;
859 if ( m_SoundWaveObject )
860 m_SoundWaveObject.SetVolumeRelative( volume );
861 }
862
868 {
869 return m_SoundWaveVolume;
870 }
871
878 void SetSoundMaxVolume(float volume)
879 {
880 m_SoundWaveVolumeMax = volume;
881 if ( m_SoundWaveObject )
882 m_SoundWaveObject.SetVolumeRelative( m_SoundWaveVolume );
883 }
884
891 {
892 return m_SoundWaveTime;
893 }
894
899 void SetSoundFadeIn(float fade_in)
900 {
901 m_SoundFadeInDuration = fade_in;
902 }
903
908 void SetSoundFadeOut(float fade_out)
909 {
910 m_SoundFadeOutDuration = fade_out;
911 }
912
917 void SetDoppler(bool setDoppler)
918 {
920 m_SoundDoppler = 0;
921 if (setDoppler)
922 {
923 m_SoundDoppler = 1;
924 }
925 }
926
928
929
930
934 protected void SoundError(string err_msg)
935 {
936 ErrorEx(string.Format("%1: SoundSetName: '%2' :: %3", this, m_SoundSetName, err_msg));
937 }
938}
DayZGame g_Game
Определения DayZGame.c:4074
vector position
Определения DustKickupEffects.c:20
bool m_IsPlaying
Whether the Effect is currently playing.
Определения Effect.c:37
Object m_ParentObject
Cached parent.
Определения Effect.c:39
ref ScriptInvoker Event_OnEffectStarted
Event used when the actual effect started playing.
Определения Effect.c:24
EffectType
Enum to determine what type of effect the Effect is.
Определения Effect.c:3
int m_PivotIndex
Cached parent pivot id.
Определения Effect.c:41
ref ScriptInvoker Event_OnEffectEnded
Event used when the actual effect stopped playing.
Определения Effect.c:25
vector GetLocalPosition()
Get the local position of the Effect.
Определения Effect.c:513
ref ScriptInvoker Event_OnStopped
Event used when Stop was called.
Определения Effect.c:23
void Effect()
ctor
Определения Effect.c:72
Event_OnStarted
Event used when Start was called.
Определения Effect.c:304
proto string ToString()
WaveKind
Определения Sound.c:2
Определения Sound.c:147
void ~EffectSound()
dtor
Определения EffectSound.c:77
bool SoundLoadEx(out SoundParams params)
Loads in the sound when it is requested for playing through 'SoundPlayEx'.
Определения EffectSound.c:300
override void SetCurrentLocalPosition(vector pos, bool updateCached=true)
Set the current local position of the managed sound.
Определения EffectSound.c:746
void SetSoundSet(string snd)
Set soundset for the sound.
Определения EffectSound.c:798
void Event_OnSoundWaveEnded()
Event called when sound stops playing.
Определения EffectSound.c:566
override vector GetCurrentLocalPosition()
Get the current local position of the managed sound.
Определения EffectSound.c:760
override bool IsPlaying()
Returns true when the effect is playing, false otherwise.
Определения EffectSound.c:282
ref SoundParams m_SoundParams
Определения EffectSound.c:20
bool m_SetEnvVariables
Определения EffectSound.c:33
void UpdateEvents()
Enables the frame event on the EffectSound.
Определения EffectSound.c:433
ref ScriptInvoker Event_OnSoundWaveStarted
Определения EffectSound.c:10
string m_SoundSetName
Определения EffectSound.c:31
override void Start()
Plays sound.
Определения EffectSound.c:208
override void SetAutodestroy(bool auto_destroy)
Sets whether Effect automatically cleans up when it stops.
Определения EffectSound.c:607
void SetSoundAutodestroy(bool auto_destroy)
Sets whether EffectSound automatically cleans up when sound stops.
Определения EffectSound.c:626
override Object GetParent()
Get parent for the EffectSound.
Определения EffectSound.c:672
float m_SoundWaveVolume
Определения EffectSound.c:37
float GetSoundWaveLenght()
Get the sound wave length.
Определения EffectSound.c:838
float GetSoundVolume()
Get the RELATIVE volume set by 'SetSoundVolume'.
Определения EffectSound.c:867
float m_SoundFadeInDuration
Определения EffectSound.c:51
void SoundError(string err_msg)
Helper for throwing sound errors.
Определения EffectSound.c:934
void SetSoundMaxVolume(float volume)
Set the sound max volume.
Определения EffectSound.c:878
void SoundReset()
Resets EffectSound.
Определения EffectSound.c:252
AbstractWave m_SoundWaveObject
Определения EffectSound.c:23
string GetSoundSet()
Get soundset for the sound.
Определения EffectSound.c:807
WaveKind m_SoundWaveKind
Определения EffectSound.c:30
override void Event_OnRegistered(int id)
Event called from SEffectManager when the Effect is registered.
Определения EffectSound.c:527
void SetDoppler(bool setDoppler)
Set if the sound has the doppler effect enabled.
Определения EffectSound.c:917
override void InitEffect()
init
Определения EffectSound.c:85
bool m_SoundWaveIsPlaying
Определения EffectSound.c:35
override vector GetCurrentPosition()
Get the current world position of the managed sound.
Определения EffectSound.c:730
bool SoundPlayEx(out SoundParams params)
Plays sound.
Определения EffectSound.c:152
ref ScriptInvoker Event_OnSoundFadeOutStarted
Определения EffectSound.c:13
void EffectSound()
ctor
Определения EffectSound.c:63
void SetSoundLoop(bool loop)
Set if the sound loops.
Определения EffectSound.c:816
float m_SoundWaveTime
Определения EffectSound.c:39
float m_SoundFadeOutInitVolume
Определения EffectSound.c:55
ref ScriptInvoker Event_OnSoundFadeInStopped
Определения EffectSound.c:12
float m_SoundWaveLenght
Определения EffectSound.c:36
void ValidateSoundWave()
Gets called to fill in the necessary data when the header has finished loading.
Определения EffectSound.c:365
override void Event_OnFrameUpdate(float time_delta)
Event called on frame when enabled by SetEnableEventFrame(true)
Определения EffectSound.c:460
override Object GetCurrentParent()
Get parent for the EffectSound.
Определения EffectSound.c:698
void Event_OnSoundFadeOutStarted()
Event called when sound fade out starts.
Определения EffectSound.c:588
void SetSoundVolume(float volume)
Set the RELATIVE volume for the sound.
Определения EffectSound.c:856
bool m_SoundAutodestroy
Определения EffectSound.c:34
override EffectType GetEffectType()
Get what type of effect the Effect is.
Определения EffectSound.c:123
bool SoundLoad()
Loads in the sound when it is requested for playing.
Определения EffectSound.c:347
void SetSoundFadeIn(float fade_in)
Set the sound fade in duration.
Определения EffectSound.c:899
override void Stop()
Stops sound.
Определения EffectSound.c:244
void Event_OnSoundFadeInStopped()
Event called when sound fade in stops.
Определения EffectSound.c:579
override bool IsSound()
Check whether the Effect is EffectSound without casting.
Определения EffectSound.c:132
override bool CanDestroy()
Определения EffectSound.c:640
void SetSoundWaveKind(WaveKind wave_kind)
Set WaveKind for the sound.
Определения EffectSound.c:788
void SetSoundFadeOut(float fade_out)
Set the sound fade out duration.
Определения EffectSound.c:908
float m_SoundFadeOutStartTime
Определения EffectSound.c:53
bool IsSoundPlaying()
Get whether EffectSound is currently playing.
Определения EffectSound.c:274
float GetSoundWaveLength()
Get the sound wave length.
Определения EffectSound.c:847
void SetEnviromentVariables(bool setEnvVariables)
Sets whether AddEnvSoundVariables needs to be called during Loading.
Определения EffectSound.c:828
bool m_SoundWaveStarting
Определения EffectSound.c:47
int m_SoundDoppler
Определения EffectSound.c:40
override bool IsAutodestroy()
Get whether Effect automatically cleans up when it stops.
Определения EffectSound.c:617
bool SoundWaveValidation()
Validation of fade settings.
Определения EffectSound.c:403
void Event_OnSoundWaveStarted()
Event called when sound starts playing.
Определения EffectSound.c:549
bool IsSoundValid()
Helper for checking if params are valid.
Определения EffectSound.c:356
ref SoundObjectBuilder m_SoundObjectBuilder
Определения EffectSound.c:21
float m_SoundFadeOutDuration
Определения EffectSound.c:54
override string GetDebugName()
Override when getting debug information.
Определения EffectSound.c:97
override void SetParent(Object parent_obj, int pivot)
Set parent for the sound to follow.
Определения EffectSound.c:658
bool m_SoundLoop
Определения EffectSound.c:32
override int GetPivotIndex()
Get parent pivot of the Effect, only valid when there is some GetParent.
Определения EffectSound.c:685
bool m_SoundFadedOut
Определения EffectSound.c:49
bool IsSoundAutodestroy()
Get whether EffectSound automatically cleans up when sound stops.
Определения EffectSound.c:635
ref SoundObject m_SoundObject
Определения EffectSound.c:22
ref ScriptInvoker Event_OnSoundWaveEnded
Определения EffectSound.c:11
bool SoundPlay()
Plays sound.
Определения EffectSound.c:199
override void SetCurrentPosition(vector pos, bool updateCached=true)
Set the world position of the managed sound.
Определения EffectSound.c:711
override void Event_OnUnregistered()
Event called from SEffectManager when the Effect is unregistered.
Определения EffectSound.c:538
float m_SoundWaveVolumeMax
Определения EffectSound.c:38
bool m_SoundWaveStopping
Определения EffectSound.c:48
void SoundStop()
Stops sound.
Определения EffectSound.c:217
float GetSoundWaveTime()
Get the time since EffectSound started playing.
Определения EffectSound.c:890
Определения ObjectTyped.c:2
static void Event_OnSoundWaveEnded(EffectSound effect_sound)
Event called from EffectSound.Event_OnSoundWaveEnded.
Определения EffectManager.c:477
Manager class for managing Effect (EffectParticle, EffectSound)
Определения EffectManager.c:6
proto bool Insert(func fn, int flags=EScriptInvokerInsertFlags.IMMEDIATE)
insert method to list
ScriptInvoker Class provide list of callbacks usage:
Определения 2_GameLib/DayZ/tools.c:116
Определения Sound.c:112
static const vector Zero
Определения EnConvert.c:123
Определения EnConvert.c:119
void SetEnableEventFrame(bool enable)
Enable Event_OnFrameUpdate for the effect.
Определения Effect.c:282
enum ShapeType ErrorEx
bool IsPendingDeletion()
Get whether the Effect is queued up for being cleaned up.
Определения Effect.c:260
ref ScriptInvoker Event_OnSoundWaveEnded
Определения Sound.c:152
class AbstractSoundScene SoundObjectBuilder(SoundParams soundParams)
vector GetPosition()
Get the world position of the Effect.
Определения Effect.c:473
void AbstractWave()
Определения Sound.c:167
class SoundObject SoundParams(string name)
ref ScriptInvoker Event_OnSoundWaveStarted
Определения Sound.c:148
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.