20 ref array<ref SCR_AmbientSoundsEffect> m_aAmbientSoundsEffect;
23 private SignalsManagerComponent m_LocalSignalsManager;
26 private const int QUERY_RADIUS = 25;
27 private const int QUERY_PROCESSING_INTERVAL = 2000;
28 private const int QUERY_MINIMUM_MOVE_DISTANCE_SQ = 2;
29 private const int QUERY_TYPES = 7;
30 private const int INVALID = -1;
31 const int WINDSPEED_MIN = 2;
32 const int WINDSPEED_MAX = 12;
33 private const int UPDATE_PROCESSING_INTERVAL = 300;
34 private const int LOOPED_SOUND_MINIMUM_MOVE_DISTANCE_SQ = 2;
37 private float m_fQueryTimer;
38 private float m_fUpdateTimer;
42 private float m_fWorldTime;
43 private vector m_vCameraPosFrame;
44 private vector m_vCameraPosQuery;
45 private vector m_vCameraPosLoopedSound;
48 private ref array<ref SCR_AudioHandleLoop> m_aAudioHandleLoop = {};
51 private ref array<int> m_aQueryTypeCount = {};
55 private void HandleQueryEntities()
58 if (m_fWorldTime < m_fQueryTimer)
61 if (vector.DistanceSqXZ(m_vCameraPosQuery, m_vCameraPosFrame) < QUERY_MINIMUM_MOVE_DISTANCE_SQ)
64 m_fQueryTimer = m_fWorldTime + QUERY_PROCESSING_INTERVAL;
65 m_vCameraPosQuery = m_vCameraPosFrame;
90 static float GetPoint(
float x, Curve curve)
95 int lastIdx = curve.Count() - 1;
97 if (x >= curve[lastIdx][0])
98 return curve[lastIdx][1];
101 for (i = 1; i < lastIdx; i++)
107 if (curve[i-1][1] == curve[i][1])
110 return Math.Lerp(curve[i-1][1], curve[i][1], (x - curve[i-1][0]) / (curve[i][0] - curve[i-1][0]));
122 audioHandleLoop.m_aMat = transformation;
123 audioHandleLoop.m_sSoundEvent = soundEvent;
125 m_aAudioHandleLoop.Insert(audioHandleLoop);
127 return audioHandleLoop;
135 if (!audioHandleLoop)
138 Terminate(audioHandleLoop.m_AudioHandle);
139 m_aAudioHandleLoop.RemoveItem(audioHandleLoop);
143 private void UpdateLoopedSounds()
147 if (IsFinishedPlaying(audioHandleLoop.m_AudioHandle))
148 audioHandleLoop.m_AudioHandle =
SoundEventTransform(audioHandleLoop.m_sSoundEvent, audioHandleLoop.m_aMat);
153 override void UpdateSoundJob(IEntity owner,
float timeSlice)
155 super.UpdateSoundJob(owner, timeSlice);
158 m_fWorldTime =
m_World.GetWorldTime();
161 if (m_fWorldTime > m_fUpdateTimer)
164 if (vector.DistanceSqXZ(m_vCameraPosLoopedSound, m_vCameraPosFrame) > LOOPED_SOUND_MINIMUM_MOVE_DISTANCE_SQ)
166 m_vCameraPosLoopedSound = m_vCameraPosFrame;
172 ambientSoundsEffect.Update(m_fWorldTime, m_vCameraPosFrame);
175 m_fUpdateTimer = m_fWorldTime + UPDATE_PROCESSING_INTERVAL;
178 HandleQueryEntities();
183 ambientSoundsEffect.UpdateDebug(m_fWorldTime);
186 if (DiagMenu.GetBool(
SCR_DebugMenuID.DEBUGUI_SOUNDS_RELOAD_AMBIENT_SOUNDS_CONFIGS))
190 ambientSoundsEffect.ReloadConfig();
193 DiagMenu.SetValue(
SCR_DebugMenuID.DEBUGUI_SOUNDS_RELOAD_AMBIENT_SOUNDS_CONFIGS,
false);
199 override void OnPostInit(IEntity owner)
201 super.OnPostInit(owner);
216 Print(
"AUDIO: SCR_AmbientSoundsComponent: Missing SignalsManagerComponent", LogLevel.WARNING);
227 override void OnInit(IEntity owner)
231 m_World.RegisterEntityToBeUpdatedWhileGameIsPaused(owner);
235 ambientSoundsEffect.OnInit();
248 m_aQueryTypeCount.Resize(QUERY_TYPES);
251 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_SOUNDS_RELOAD_AMBIENT_SOUNDS_CONFIGS,
"",
"Reload AmbientSounds Conf",
"Sounds");
263 DiagMenu.Unregister(
SCR_DebugMenuID.DEBUGUI_SOUNDS_RELOAD_AMBIENT_SOUNDS_CONFIGS);