Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
itemsoundhandler.c
Go to the documentation of this file.
2{
3 float m_FadeIn = 0;
4 float m_FadeOut = 0;
5 bool m_Loop = false;
6}
7
8/*
9Provides functionality to start item related sound from server and synchronize it to clients
10Useful in situations where unique animation can't be used to bind the sound
11
12Steps to add new item sound:
13 1) Add new sound ID to SoundConstants class
14 2) Override InitItemSounds() method on subject item to link the new sound ID to a soundset
15 2.5) Generally soundset is retreived by adding override to the subject item class, but retreiving from config or using other means could also be used here
16 3) Start sound using ItemBase::StartItemSoundServer(int id) called from server side
17 3.5) For looped sounds which do not end on their own, use ItemBase::StopItemSoundServer(int id)
18
19Limitations:
20 Avoid starting two sounds at the same time using this handler as just single variable is used for synchronization (can be solved by secondary synch var if need arises)
21
22*/
24{
25 protected ItemBase m_Parent;
26
30
32 {
33 m_Parent = parent;
34 Init();
35 }
36
38 {
39 if (!m_PlayingSounds)
40 return;
41
42 foreach (EffectSound sound : m_PlayingSounds)
43 {
44 if (sound)
45 sound.SoundStop();
46 }
47 }
48
55
57 {
58 string soundSet = m_AvailableSoundsets.Get(id);
59 if (soundSet == string.Empty)
60 {
61 Debug.Log("Attempting to play soundID " + id + " without defined soundset. Item: " + m_Parent.GetType());
62 return;
63 }
64
65 if (m_PlayingSounds.Get(id)) // already playing
66 return;
67
68 EffectSound sound;
69 SoundParameters params = m_SoundParamsMap.Get(id);
70 if (params)
71 sound = SEffectManager.PlaySoundCachedParams(soundSet, m_Parent.GetPosition(), params.m_FadeIn, params.m_FadeOut, params.m_Loop);
72 else
73 sound = SEffectManager.PlaySound(soundSet, m_Parent.GetPosition());
74
75 if (sound)
76 sound.SetAutodestroy(true);
77 else
78 Debug.Log("Null when creating sound from set: " + soundSet + " Item: " + m_Parent.GetType() );
79
80 m_PlayingSounds.Insert(id, sound);
81 }
82
84 {
85 if (GetGame().IsDedicatedServer())
86 return;
87
88 EffectSound sound = m_PlayingSounds.Get(id);
89 if (sound)
90 {
91 sound.SetSoundFadeOut(0.1);
92 sound.SoundStop();
93 }
94
95 m_PlayingSounds.Remove(id);
96 }
97
98 void AddSound(int sound, string soundset, SoundParameters params = null)
99 {
100 m_AvailableSoundsets.Insert(sound, soundset);
101
102 if (params)
103 m_SoundParamsMap.Insert(sound, params);
104 }
105}
Definition debug.c:2
Wrapper class for managing sound through SEffectManager.
Definition effectsound.c:5
override void SetAutodestroy(bool auto_destroy)
Sets whether Effect automatically cleans up when it stops.
void SetSoundFadeOut(float fade_out)
Set the sound fade out duration.
void SoundStop()
Stops sound.
TODO doc.
Definition enscript.c:118
Manager class for managing Effect (EffectParticle, EffectSound)
static EffectSound PlaySoundCachedParams(string sound_set, vector position, float play_fade_in=0, float stop_fade_out=0, bool loop=false)
Create and play an EffectSound, using or creating cached SoundParams.
static EffectSound PlaySound(string sound_set, vector position, float play_fade_in=0, float stop_fade_out=0, bool loop=false)
Create and play an EffectSound.
override Widget Init()
Definition dayzgame.c:127
proto native CGame GetGame()
Empty
Definition hand_states.c:14
void PlayItemSoundClient(int id)
ref map< int, string > m_AvailableSoundsets
void ~ItemSoundHandler()
void AddSound(int sound, string soundset, SoundParameters params=null)
void ItemSoundHandler(ItemBase parent)
void StopItemSoundClient(int id)
ref map< int, ref EffectSound > m_PlayingSounds
ref map< int, ref SoundParameters > m_SoundParamsMap
Widget m_Parent
Definition sizetochild.c:92