20 private ref array<ref SCR_AudioSource> m_aAudioSource = {};
22 private SoundWorld m_SoundWorld;
25 static const string G_INTERIOR_SIGNAL_NAME =
"GInterior";
26 static const string G_CURR_VEHICLE_COVERAGE_SIGNAL_NAME =
"GCurrVehicleCoverage";
27 static const string G_IS_THIRD_PERSON_CAM_SIGNAL_NAME =
"GIsThirdPersonCam";
28 static const string G_ROOM_SIZE =
"GRoomSize";
29 static const string DYNAMIC_RANGE_SIGNAL_NAME =
"DynamicRange";
30 static const string G_TINNITUS_SIGNAL_NAME =
"GTinnitus";
31 static const string IN_EDITOR_SIGNAL_NAME =
"InEditor";
34 private static int s_iGInteriorIdx;
35 private static int s_iGCurrVehicleCoverageIdx;
36 private static int s_iGIsThirdPersonCamIdx;
37 private static int s_iGRoomSizeIdx;
38 private static int s_iDynamicRangeIdx;
39 private static int s_iGTinnitusIdx;
40 private static int s_iInEditorIdx;
43 private static int s_iCreatedAudioSources;
44 private static int s_iMaxActiveAudioSources;
45 private static int s_iPlayedAudioSources;
46 private static int s_iInvalidAudioSources;
47 private static int s_iInaudibleAudioSources;
48 private static int s_iTerminateAudioSourceCalls;
49 private static int s_iCalculateInterirorAtCount;
62 s_iCreatedAudioSources++;
66 SCR_SoundDataComponent soundDataComponent = SCR_SoundDataComponent.Cast(owner.FindComponent(SCR_SoundDataComponent));
67 if (!soundDataComponent)
70 SCR_AudioSourceConfiguration audioSourceConfiguration = soundDataComponent.GetAudioSourceConfiguration(eventName);
71 if (!audioSourceConfiguration)
75 float distance = AudioSystem.IsAudible(audioSourceConfiguration.m_sSoundProject, eventName, owner.GetOrigin());
79 s_iInaudibleAudioSources++;
95 SCR_AudioSource CreateAudioSource(IEntity owner, SCR_AudioSourceConfiguration audioSourceConfiguration)
98 s_iCreatedAudioSources++;
102 float distance = AudioSystem.IsAudible(audioSourceConfiguration.m_sSoundProject, audioSourceConfiguration.m_sSoundEventName, owner.GetOrigin());
106 s_iInaudibleAudioSources++;
122 void CreateAndPlayAudioSource(IEntity owner,
string eventName)
129 PlayAudioSource(audioSource);
139 void CreateAndPlayAudioSource(IEntity owner, SCR_AudioSourceConfiguration audioSourceConfiguration)
141 SCR_AudioSource audioSource = CreateAudioSource(owner, audioSourceConfiguration);
146 PlayAudioSource(audioSource);
158 void CreateAndPlayAudioSource(IEntity owner, SCR_AudioSourceConfiguration audioSourceConfiguration, vector mat[4])
160 SCR_AudioSource audioSource = CreateAudioSource(owner, audioSourceConfiguration);
165 PlayAudioSource(audioSource, mat);
178 audioSource.SetGlobalOcclusionSignals();
182 audioSource.m_Owner.GetTransform(mat);
185 PlaySoundEvent(audioSource, mat);
199 audioSource.SetGlobalOcclusionSignals();
202 PlaySoundEvent(audioSource, mat);
211 private void PlaySoundEvent(
SCR_AudioSource audioSource, vector mat[4])
216 audioSource.SetTransformation(mat);
217 m_SoundWorld.CalculateInterirorAt(mat[3], audioSource.m_InteriorRequestCallback);
220 s_iCalculateInterirorAtCount++;
224 m_aAudioSource.Insert(audioSource);
228 audioSource.SetTransformation(mat);
231 if (audioSource.Play())
232 m_aAudioSource.Insert(audioSource);
241 void TerminateAudioSource(IEntity entity)
244 s_iTerminateAudioSourceCalls++;
247 for (
int i = m_aAudioSource.Count() - 1; i >= 0; i--)
251 if (audioSource.m_Owner == entity)
252 audioSource.Ternimate();
268 audioSource.Ternimate();
279 audioSource.Ternimate();
287 private void HandleAudioSources()
289 for (
int i = m_aAudioSource.Count() - 1; i >= 0; i--)
294 if (AudioSystem.IsSoundPlayed(audioSource.m_AudioHandle) && !audioSource.m_InteriorRequestCallback)
296 m_aAudioSource.Remove(i);
304 audioSource.UpdateTransformation();
311 audioSource.Ternimate();
312 m_aAudioSource.Remove(i);
320 int count = m_aAudioSource.Count();
321 DbgUI.Begin(
"Sound Manager");
322 DbgUI.Text(
"Active Audio Sources :" + count);
323 if (count > s_iMaxActiveAudioSources)
324 s_iMaxActiveAudioSources = count;
325 DbgUI.Text(
"Maximum Active Audio Sources :" + s_iMaxActiveAudioSources);
326 DbgUI.Text(
"Created Audio Sources :" + s_iCreatedAudioSources);
327 DbgUI.Text(
"Played Audio Sources :" + s_iPlayedAudioSources);
328 DbgUI.Text(
"Invalid Audio Sources :" + s_iInvalidAudioSources);
329 DbgUI.Text(
"Inaudible Audio Sources :" + s_iInaudibleAudioSources);
330 DbgUI.Text(
"TerminateAudioSource() Calls :" + s_iTerminateAudioSourceCalls);
331 DbgUI.Text(
"CalculateInterirorAt() Count :" + s_iCalculateInterirorAtCount);
335 if (m_aAudioSource.Count() != 0)
337 Print(
"--- " + m_aAudioSource.Count().ToString() +
" playing sound events ---");
340 Print(audioSource.m_AudioSourceConfiguration.m_sSoundEventName);
347 Resource holder = BaseContainerTools.LoadContainer(
"{A60F08955792B575}Sounds/_SharedData/Variables/GlobalVariables.conf");
351 BaseContainer baseContainer = holder.GetResource().ToBaseContainer();
355 BaseContainerList list = baseContainer.GetObjectArray(
"Variables");
359 DbgUI.Begin(
"Global Variables");
360 for (
int i = 0; i < list.Count(); i++)
362 string name = list[i].GetName();
363 DbgUI.Text(name +
": " + AudioSystem.GetVariableValue(name,
"{A60F08955792B575}Sounds/_SharedData/Variables/GlobalVariables.conf").ToString(-1,2));
374 int GetGInteriorSignalIdx()
376 return s_iGInteriorIdx;
383 int GetGCurrVehicleCoverageSignalIdx()
385 return s_iGCurrVehicleCoverageIdx;
392 int GetGIsThirdPersonCamSignalIdx()
394 return s_iGIsThirdPersonCamIdx;
403 return s_iGRoomSizeIdx;
410 protected void SetDynamicRangeSignalValue()
412 BaseContainer settings =
GetGame().GetGameUserSettings().GetModule(
"SCR_AudioSettings");
417 settings.Get(
"m_fDynamicRange", value);
420 GetGame().GetSignalsManager().SetSignalValue(s_iDynamicRangeIdx, value * 0.01 - 1);
427 protected void SetTinnitusSignalValue()
429 BaseContainer settings =
GetGame().GetGameUserSettings().GetModule(
"SCR_AudioSettings");
434 settings.Get(
"m_bGTinnitus", value);
436 GetGame().GetSignalsManager().SetSignalValue(s_iGTinnitusIdx, value);
443 protected void OnEditorOpen()
445 GetGame().GetSignalsManager().SetSignalValue(s_iInEditorIdx, 1);
451 protected void OnEditorClose()
453 GetGame().GetSignalsManager().SetSignalValue(s_iInEditorIdx, 0);
461 editorManager.GetOnOpened().Insert(OnEditorOpen);
462 editorManager.GetOnClosed().Insert(OnEditorClose);
470 editorManager.GetOnOpened().Remove(OnEditorOpen);
471 editorManager.GetOnClosed().Remove(OnEditorClose);
478 protected void EditorManagerEventsInit()
482 OnEditorManagerInit(editorManager);
486 if (editorManagerCore)
487 editorManagerCore.Event_OnEditorManagerInitOwner.Insert(OnEditorManagerInit);
495 protected void EditorManagerEventsExit()
499 OnEditorManagerExit(editorManager);
502 if (editorManagerCore)
503 editorManagerCore.Event_OnEditorManagerInitOwner.Remove(OnEditorManagerInit);
507 override void EOnPostFrame(IEntity owner,
float timeSlice)
509 HandleAudioSources();
513 override void EOnInit(IEntity owner)
516 GetGame().RegisterSoundManagerEntity(
this);
521 s_iGInteriorIdx = gameSignalsManager.AddOrFindSignal(G_INTERIOR_SIGNAL_NAME);
522 s_iGCurrVehicleCoverageIdx = gameSignalsManager.AddOrFindSignal(G_CURR_VEHICLE_COVERAGE_SIGNAL_NAME);
523 s_iGIsThirdPersonCamIdx = gameSignalsManager.AddOrFindSignal(G_IS_THIRD_PERSON_CAM_SIGNAL_NAME);
524 s_iGRoomSizeIdx = gameSignalsManager.AddOrFindSignal(G_ROOM_SIZE);
525 s_iDynamicRangeIdx = gameSignalsManager.AddOrFindSignal(DYNAMIC_RANGE_SIGNAL_NAME);
526 s_iGTinnitusIdx = gameSignalsManager.AddOrFindSignal(G_TINNITUS_SIGNAL_NAME);
527 s_iInEditorIdx = gameSignalsManager.AddOrFindSignal(IN_EDITOR_SIGNAL_NAME);
530 GetGame().OnUserSettingsChangedInvoker().Insert(SetDynamicRangeSignalValue);
531 GetGame().OnUserSettingsChangedInvoker().Insert(SetTinnitusSignalValue);
533 SetDynamicRangeSignalValue();
535 SetTinnitusSignalValue();
538 EditorManagerEventsInit();
543 m_SoundWorld = chimeraWorld.GetSoundWorld();
546 s_iCreatedAudioSources = 0;
547 s_iMaxActiveAudioSources = 0;
548 s_iPlayedAudioSources = 0;
549 s_iInvalidAudioSources = 0;
550 s_iInaudibleAudioSources = 0;
551 s_iTerminateAudioSourceCalls = 0;
552 s_iCalculateInterirorAtCount = 0;
559 SetEventMask(EntityEvent.POSTFRAME | EntityEvent.INIT);
560 SetFlags(EntityFlags.NO_TREE | EntityFlags.NO_LINK);
563 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_SOUNDS_SOUND_MANAGER,
"",
"Sound Manager",
"Sounds");
564 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_SOUNDS_GLOBAL_VARIABLES,
"",
"Global Variables",
"Sounds");
575 GetGame().OnUserSettingsChangedInvoker().Remove(SetDynamicRangeSignalValue);
578 EditorManagerEventsExit();