Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AmbientSoundsComponent.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/Sound", description: "THIS IS THE SCRIPT DESCRIPTION.", color: "0 0 255 255")]
5
6class SCR_AmbientSoundsComponent : AmbientSoundsComponent
7{
8 [Attribute()]
9 ref array<ref SCR_AmbientSoundsEffect> m_aAmbientSoundsEffect;
10
11 // Components
12 private SignalsManagerComponent m_LocalSignalsManager;
13
14 // Constants
15 private const int QUERY_RADIUS = 25;
16 private const int QUERY_PROCESSING_INTERVAL = 2000;
17 private const int QUERY_MINIMUM_MOVE_DISTANCE_SQ = 2;
18 private const int INVALID = -1;
19 private const int UPDATE_PROCESSING_INTERVAL = 300;
20 private const int LOOPED_SOUND_MINIMUM_MOVE_DISTANCE_SQ = 2;
21 const int WINDSPEED_MIN = 2;
22 const int WINDSPEED_MAX = 12;
23
24 // Timers
25 private float m_fQueryTimer;
26 private float m_fUpdateTimer;
27 private bool m_bQueryRefreshNeeded;
28 private bool m_bUpdateRefreshNeeded;
29
30 // Misc
31 private ChimeraWorld m_World;
32 private float m_fWorldTime;
33 private vector m_vCameraPosFrame;
34 private vector m_vCameraPosQuery;
35 private vector m_vCameraPosLoopedSound;
36
37 // Looped sounds pool
38 private ref array<ref SCR_AudioHandleLoop> m_aAudioHandleLoop = {};
39
41 private ref array<int> m_aQueryTypeCount = {};
42
43 //------------------------------------------------------------------------------------------------
44 private override void OnRefreshNeeded()
45 {
46 m_bQueryRefreshNeeded = true;
47 }
48
49 private override void OnQueryFinished()
50 {
51 GetAmbientSoundsCountPerType(m_aQueryTypeCount);
52 m_bUpdateRefreshNeeded = true;
53 }
54
55 //------------------------------------------------------------------------------------------------
57 private void HandleQueryEntities()
58 {
59 // Limit processing by time and moved distance
60 if (m_fWorldTime < m_fQueryTimer)
61 return;
62
63 if (!m_bQueryRefreshNeeded && vector.DistanceSqXZ(m_vCameraPosQuery, m_vCameraPosFrame) < QUERY_MINIMUM_MOVE_DISTANCE_SQ)
64 return;
65
66 m_bQueryRefreshNeeded = false;
67 m_fQueryTimer = m_fWorldTime + QUERY_PROCESSING_INTERVAL;
68 m_vCameraPosQuery = m_vCameraPosFrame;
69
70 // Get new query values
71 QueryAmbientSoundsBySphere(QUERY_RADIUS);
72 }
73
74 //------------------------------------------------------------------------------------------------
76 EAmbientSoundType GetDominantTree()
77 {
78 if (m_aQueryTypeCount[EAmbientSoundType.TreeLeafy] + m_aQueryTypeCount[EAmbientSoundType.TreeConifer] == 0)
79 return INVALID;
80
81 if (m_aQueryTypeCount[EAmbientSoundType.TreeLeafy] > m_aQueryTypeCount[EAmbientSoundType.TreeConifer])
82 return EAmbientSoundType.TreeLeafy;
83
84 return EAmbientSoundType.TreeConifer;
85 }
86
87 //------------------------------------------------------------------------------------------------
92 static float GetPoint(float x, Curve curve)
93 {
94 if (x <= curve[0][0])
95 return curve[0][1];
96
97 int lastIdx = curve.Count() - 1;
98
99 if (x >= curve[lastIdx][0])
100 return curve[lastIdx][1];
101
102 int i;
103 for (i = 1; i < lastIdx; i++)
104 {
105 if (curve[i][0] > x)
106 break;
107 }
108
109 if (curve[i-1][1] == curve[i][1])
110 return curve[i][1];
111 else
112 return Math.Lerp(curve[i-1][1], curve[i][1], (x - curve[i-1][0]) / (curve[i][0] - curve[i-1][0]));
113 }
114
115 //------------------------------------------------------------------------------------------------
120 SCR_AudioHandleLoop SoundEventLooped(string soundEvent, vector transformation[4])
121 {
122 SCR_AudioHandleLoop audioHandleLoop = new SCR_AudioHandleLoop;
123
124 audioHandleLoop.m_aMat = transformation;
125 audioHandleLoop.m_sSoundEvent = soundEvent;
126
127 m_aAudioHandleLoop.Insert(audioHandleLoop);
128
129 return audioHandleLoop;
130 }
131
132 //------------------------------------------------------------------------------------------------
135 void TerminateLooped(SCR_AudioHandleLoop audioHandleLoop)
136 {
137 if (!audioHandleLoop)
138 return;
139
140 Terminate(audioHandleLoop.m_AudioHandle);
141 m_aAudioHandleLoop.RemoveItem(audioHandleLoop);
142 }
143
144 //------------------------------------------------------------------------------------------------
145 private void UpdateLoopedSounds()
146 {
147 foreach (SCR_AudioHandleLoop audioHandleLoop : m_aAudioHandleLoop)
148 {
149 if (IsFinishedPlaying(audioHandleLoop.m_AudioHandle))
150 audioHandleLoop.m_AudioHandle = SoundEventTransform(audioHandleLoop.m_sSoundEvent, audioHandleLoop.m_aMat);
151 }
152 }
153
154 //------------------------------------------------------------------------------------------------
155 override void UpdateSoundJob(IEntity owner, float timeSlice)
156 {
157 super.UpdateSoundJob(owner, timeSlice);
158
159 m_vCameraPosFrame = GetCameraOrigin();
160 m_fWorldTime = m_World.GetWorldTime();
161
162 // Update effects
163 if (m_bUpdateRefreshNeeded || m_fWorldTime > m_fUpdateTimer)
164 {
165 // Handle looped sounds
166 if (m_bUpdateRefreshNeeded || vector.DistanceSqXZ(m_vCameraPosLoopedSound, m_vCameraPosFrame) > LOOPED_SOUND_MINIMUM_MOVE_DISTANCE_SQ)
167 {
168 m_vCameraPosLoopedSound = m_vCameraPosFrame;
169 UpdateLoopedSounds()
170 }
171
172 foreach (SCR_AmbientSoundsEffect ambientSoundsEffect : m_aAmbientSoundsEffect)
173 {
174 ambientSoundsEffect.Update(m_fWorldTime, m_vCameraPosFrame, m_bUpdateRefreshNeeded);
175 }
176
177 m_fUpdateTimer = m_fWorldTime + UPDATE_PROCESSING_INTERVAL;
178
179 if (m_bUpdateRefreshNeeded)
180 m_bUpdateRefreshNeeded = false;
181 }
182
183 HandleQueryEntities();
184
185#ifdef ENABLE_DIAG
186 foreach (SCR_AmbientSoundsEffect ambientSoundsEffect : m_aAmbientSoundsEffect)
187 {
188 ambientSoundsEffect.UpdateDebug(m_fWorldTime);
189 }
190
191 if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_SOUNDS_RELOAD_AMBIENT_SOUNDS_CONFIGS))
192 {
193 foreach (SCR_AmbientSoundsEffect ambientSoundsEffect : m_aAmbientSoundsEffect)
194 {
195 ambientSoundsEffect.ReloadConfig();
196 }
197
198 DiagMenu.SetValue(SCR_DebugMenuID.DEBUGUI_SOUNDS_RELOAD_AMBIENT_SOUNDS_CONFIGS, false);
199 }
200#endif
201 }
202
203 //------------------------------------------------------------------------------------------------
204 override void OnPostInit(IEntity owner)
205 {
206 super.OnPostInit(owner);
207
208 // Get world
209 m_World = owner.GetWorld();
210 if (!m_World)
211 {
212 SetScriptedMethodsCall(false);
213 return;
214 }
215
216 // Get local signals component
217 m_LocalSignalsManager = SignalsManagerComponent.Cast(owner.FindComponent(SignalsManagerComponent));
219 {
220 SetScriptedMethodsCall(false);
221 Print("AUDIO: SCR_AmbientSoundsComponent: Missing SignalsManagerComponent", LogLevel.WARNING);
222 return;
223 }
224
225 foreach (SCR_AmbientSoundsEffect ambientSoundsEffect : m_aAmbientSoundsEffect)
226 {
227 ambientSoundsEffect.OnPostInit(this, m_LocalSignalsManager);
228 }
229 }
230
231 //------------------------------------------------------------------------------------------------
232 override void OnInit(IEntity owner)
233 {
234 super.OnInit(owner);
235
236 foreach (SCR_AmbientSoundsEffect ambientSoundsEffect : m_aAmbientSoundsEffect)
237 {
238 ambientSoundsEffect.OnInit();
239 }
240 }
241
242 //------------------------------------------------------------------------------------------------
243 // constructor
247 void SCR_AmbientSoundsComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
248 {
249 SetScriptedMethodsCall(true);
250
251 // Dummy call. Initializes m_aQueryTypeCount to the proper size.
252 GetAmbientSoundsCountPerType(m_aQueryTypeCount);
253
254#ifdef ENABLE_DIAG
255 DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_SOUNDS_RELOAD_AMBIENT_SOUNDS_CONFIGS, "", "Reload AmbientSounds Conf", "Sounds");
256#endif
257 }
258
259 //------------------------------------------------------------------------------------------------
260 // destructor
261 void ~SCR_AmbientSoundsComponent()
262 {
263#ifdef ENABLE_DIAG
264 DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_SOUNDS_RELOAD_AMBIENT_SOUNDS_CONFIGS);
265#endif
266 }
267}
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition DebugMenuID.c:4
void Terminate(bool fadeOut=true)
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
SignalsManagerComponent m_LocalSignalsManager
enum EVehicleType IEntity
proto external Managed FindComponent(typename typeName)
proto external BaseWorld GetWorld()
proto external bool IsFinishedPlaying(AudioHandle handle)
event void OnQueryFinished()
Triggered when the result of QueryAmbientSoundsBySphere query becomes available.
AmbientSoundsComponentClass SoundComponentClass QueryAmbientSoundsBySphere(float radius, EQueryEntitiesFlags queryFlags=EQueryEntitiesFlags.ALL)
EAmbientSoundType
event void OnRefreshNeeded()
Triggered when a big-enough change in the surrounding area is detected that would require an update.
proto external void GetAmbientSoundsCountPerType(out notnull array< int > count)
proto external vector GetCameraOrigin()
Returns the last camera position.
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
SCR_FieldOfViewSettings Attribute
@ INVALID
Missing components, or obstruction test was not possible.