Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_SoundHandle.c
Go to the documentation of this file.
1[BaseContainerProps(configRoot: true)]
3{
5 vector m_aMat[4];
6
8 int m_iSoundGroup;
9
11 int m_iSoundType;
12
14 int m_iSoundDef;
15
17 SCR_SoundDef m_SoundDef;
18
20 ref array<int> m_aRepTime;
21
23 int m_iRepTimeIdx;
24
26 float m_fDensity;
27
28 //------------------------------------------------------------------------------------------------
32 void UpdateDensity(float sampleLenght, float worldTime)
33 {
34 float sequenceLenght = GetSequenceLenght(worldTime);
35 if (sequenceLenght == 0)
36 {
37 m_fDensity = 0;
38 return;
39 }
40
41 m_fDensity = Math.Clamp(sampleLenght * m_aRepTime.Count() / sequenceLenght, 0, 1) * 100;
42
43#ifdef ENABLE_DIAG
44 if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_SOUNDS_RANDOM_POSITIONAL_SOUNDS))
45 {
46 const string eventName = typename.EnumToString(ESoundName, m_SoundDef.m_eSoundName);
47
48 Print(eventName + ": Density = " + m_fDensity.ToString());
49 }
50#endif
51 }
52
53 //------------------------------------------------------------------------------------------------
57 float GetSequenceLenght(float worldTime)
58 {
59 int size = m_aRepTime.Count();
60 if (size == 0)
61 return 0;
62 else
63 return m_aRepTime[size - 1] - worldTime + m_SoundDef.m_iSampleLength;
64 }
65
66 //------------------------------------------------------------------------------------------------
67 protected int GetRandomInt(int value, int random)
68 {
69 if (random == 0)
70 return value;
71
72 int randomValue = value + Math.RandomFloat(-random, random);
73 if (randomValue < 1)
74 randomValue = 1;
75
76 return randomValue;
77 }
78
79 //------------------------------------------------------------------------------------------------
80 protected void CreateSequence(array<ref SCR_SequenceDef> sequenceDefinitions, int idx)
81 {
82 SCR_SequenceDef sequenceDefinition = sequenceDefinitions[idx];
83
84 for (int i = 0, count = GetRandomInt(sequenceDefinition.m_iRepCount, sequenceDefinition.m_iRepCountRnd); i < count; i++)
85 {
86 if (i > 0)
87 m_aRepTime.Insert(GetRandomInt(sequenceDefinition.m_iRepTime, sequenceDefinition.m_iRepTimeRnd) + m_aRepTime[m_aRepTime.Count() - 1]);
88
89 int idxNew = idx - 1;
90 if (idxNew >= 0)
91 CreateSequence(sequenceDefinitions, idxNew);
92 }
93 }
94
95 //------------------------------------------------------------------------------------------------
98 void UpdateRepTime(float gameTime)
99 {
100 if (m_aRepTime)
101 m_aRepTime.Clear();
102 else
103 m_aRepTime = {};
104
105 m_aRepTime.Insert(gameTime + GetRandomInt(m_SoundDef.m_iStartDelay, m_SoundDef.m_iStartDelayRnd));
106
107 if (m_SoundDef.m_aSequenceDef.Count() == 0)
108 Print("AmbientSoundsComponent: " + typename.EnumToString(ESoundName, m_SoundDef.m_eSoundName) + " is missing sequence definition", LogLevel.WARNING);
109 else
110 CreateSequence(m_SoundDef.m_aSequenceDef, m_SoundDef.m_aSequenceDef.Count() - 1);
111 }
112
113 //------------------------------------------------------------------------------------------------
114 // constructor
121 void SCR_SoundHandle(int soundGroupIdx, int soundTypeIdx, int soundDefIdx, vector mat[4], array<ref SCR_SoundGroup> soundGroup, float worldTime)
122 {
123 m_iSoundGroup = soundGroupIdx;
124 m_iSoundType = soundTypeIdx;
125 m_iSoundDef = soundDefIdx;
126 m_aMat = mat;
127 m_SoundDef = soundGroup[soundGroupIdx].m_aSoundType[soundTypeIdx].m_aSoundDef[soundDefIdx];
128 UpdateRepTime(worldTime);
129 UpdateDensity(m_SoundDef.m_iSampleLength, worldTime);
130 }
131}
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition DebugMenuID.c:4
int size
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
ESoundName
Definition SCR_SoundDef.c:2
Diagnostic and developer menu system.
Definition DiagMenu.c:18
Definition Math.c:13
void CreateSequence(array< ref SCR_SequenceDef > sequenceDefinitions, int idx)
void UpdateRepTime(float gameTime)
int GetRandomInt(int value, int random)
void SCR_SoundHandle(int soundGroupIdx, int soundTypeIdx, int soundDefIdx, vector mat[4], array< ref SCR_SoundGroup > soundGroup, float worldTime)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14