19 private ref array<ref SCR_RandomPositionalSoundsDef> m_aRandomPositionalSoundsDef;
21 [
Attribute(
"", UIWidgets.ResourceNamePicker,
desc:
"SoundInfo to ambient groups selector config",
params:
"conf")]
22 private ResourceName m_TerrainDefinitionResource;
24 [
Attribute(
"", UIWidgets.ResourceNamePicker,
desc:
"Daytime curves config",
params:
"conf")]
25 private ResourceName m_DayTimeCurveResource;
27 [
Attribute(
"", UIWidgets.ResourceNamePicker,
desc:
"Wind modifier curves config",
params:
"conf")]
28 private ResourceName m_WindCurveResource;
31 private ref array<ref SCR_SoundGroup> m_aSoundGroup = {};
32 private ref array<ref SCR_SpawnDef> m_aSpawnDef = {};
33 private ref array<ref SCR_TerrainDef> m_aTerrainDef;
34 private ref array<ref SCR_DayTimeCurveDef> m_aDayTimeCurve;
35 private ref array<ref SCR_WindCurveDef> m_aWindModifier;
40 private SoundWorld m_SoundWorld;
44 private const int TREE_LEAFY_HEIGHT_LIMIT = 10;
45 private const int TREE_CONIFER_HEIGHT_LIMIT = 12;
46 private const int LAKE_AREA_LIMIT = 100000;
47 private const int COAST_HIGHT_LIMIT = 3;
48 private const int GLOBAL_MODIFIERS_UPDATE_TIME = 10000;
49 private const string SUN_ANGLE_SIGNAL_NAME =
"SunAngle";
50 private const string SOUND_NAME_SIGNAL_NAME =
"SoundName";
52 private const string RAIN_INTENSITY_SIGNAL_NAME =
"RainIntensity";
53 private const string WIND_SPEED_SIGNAL_NAME =
"WindSpeed";
54 private const string ENVIRONMENT_TYPE_SIGNAL_NAME =
"EnvironmentType";
57 private int m_iSunAngleSignalIdx;
58 private int m_iSoundNameSignalIdx;
60 private int m_iRainIntensitySignalIdx;
61 private int m_iWindSpeedSignalIdx;
62 private int m_iEnvironmentTypeSignalIdx;
64 private int m_iUpdatedSoundGroupIdx;
65 private int m_iEnvironmentTypeSignalValue;
66 private float m_fGlobalModifiersTimer;
67 private ref array<int> m_aDensity = {};
68 private ref array<float> m_aDensityModifier = {};
69 private ref array<int> m_aAngleOffset = {};
73 private ref array<ref SCR_SoundHandle> m_aSoundHandle = {};
77 override void Update(
float worldTime, vector cameraPos)
82 ProcessSoundGroups(worldTime, cameraPos);
83 UpdateSoundSequence(worldTime, cameraPos);
85 if (worldTime > m_fGlobalModifiersTimer)
87 UpdateGlobalModifiers();
88 RemoveSoundsBasedOnTimeAndWeather();
89 m_fGlobalModifiersTimer = worldTime + GLOBAL_MODIFIERS_UPDATE_TIME;
97 if (DiagMenu.GetBool(
SCR_DebugMenuID.DEBUGUI_SOUNDS_RANDOM_POSITIONAL_SOUNDS))
99 AmbientSignalsDebug();
100 RandomPositionalSoundDebug(worldTime);
108 private void ProcessSoundGroups(
float worldTime, vector cameraPos)
110 UpdateSoundGroup(worldTime, cameraPos, m_iUpdatedSoundGroupIdx);
112 m_iUpdatedSoundGroupIdx ++;
113 if (m_iUpdatedSoundGroupIdx < m_aSoundGroup.Count())
116 m_iUpdatedSoundGroupIdx = 0;
118 RemoveOutOfRangeSound(cameraPos);
124 private void RemoveSoundsBasedOnTimeAndWeather()
126 for (
int i = m_aSoundHandle.Count() - 1; i >= 0; i--)
130 if (m_aDayTimeCurveValue[soundHandle.m_SoundDef.m_eDayTimeCurve] == 0 || m_aDensityModifier[soundHandle.m_iSoundGroup] == 0)
131 m_aSoundHandle.Remove(i);
137 private void UpdateGlobalModifiers()
148 foreach (
int i, SCR_SpawnDef spawnDef : m_aSpawnDef)
151 modifier = modifier *
SCR_AmbientSoundsComponent.GetPoint(m_GlobalSignalsManager.GetSignalValue(m_iRainIntensitySignalIdx), spawnDef.m_RainModifier);
152 m_aDensityModifier[i] = modifier * m_aWindCurveValue[spawnDef.m_eWindModifier];
163 private int GetDensityMax(
int soundGroup)
166 return m_aSpawnDef[soundGroup].m_iMeadowDensityMax;
168 return m_aSpawnDef[soundGroup].m_iForestDensityMax;
170 return m_aSpawnDef[soundGroup].m_iHousesDensityMax;
172 return m_aSpawnDef[soundGroup].m_iSeaDensityMax;
176 private void UpdateSoundSequence(
float worldTime, vector cameraPos)
178 for (
int i = m_aSoundHandle.Count() - 1; i >= 0; i--)
182 if (worldTime > soundHandle.m_aRepTime[soundHandle.m_iRepTimeIdx])
185 if (m_iSoundNameSignalIdx !=
INVALID)
193 m_AmbientSoundsComponent.SoundEventTransform(m_aSoundGroup[soundHandle.m_iSoundGroup].m_sSoundEvent, soundHandle.m_aMat);
196 soundHandle.m_SoundDef.m_iCount++;
200 soundHandle.m_iRepTimeIdx ++;
201 if (soundHandle.m_aRepTime.Count() == soundHandle.m_iRepTimeIdx)
202 m_aSoundHandle.Remove(i);
208 private void RemoveOutOfRangeSound(vector cameraPos)
210 for (
int i = m_aSoundHandle.Count() - 1; i >= 0; i--)
213 SCR_SpawnDef spawnDef = m_aSpawnDef[soundHandle.m_iSoundGroup];
215 if (!Math.IsInRange(vector.Distance(cameraPos, soundHandle.m_aMat[3]), spawnDef.m_iPlayDistMin, spawnDef.m_iPlayDistMax))
216 m_aSoundHandle.Remove(i);
225 private void UpdateSoundGroup(
float worldTime, vector camPos,
int soundGroup)
228 if (m_aDensity[soundGroup] >= GetDensityMax(soundGroup) * m_aDensityModifier[soundGroup])
235 ESpawnMethod spawhMethod = m_aSoundGroup[soundGroup].m_eSpawnMethod;
248 vPos = GetRandomPositionOnEntity(tree);
250 else if (treeSoundType ==
EQueryType.TreeLeafy)
257 vPos = GetRandomPositionOnEntity(tree);
262 vPos = GenerateRandomPosition(soundGroup, camPos);
263 soundType = GetTerrainTypeFromTerrain(vPos);
267 vPos = GenerateRandomPosition(soundGroup, camPos);
268 soundType = GetSoundMapTypeFromTerrain(vPos);
275 int soundDef = GetRandomSoundDef(m_aSoundGroup[soundGroup].m_aSoundType[soundType], worldTime);
282 Math3D.MatrixIdentity4(mat);
286 m_aSoundHandle.Insert(soundHandle);
289 float timeOfDayFactor = m_aDayTimeCurveValue[soundHandle.m_SoundDef.m_eDayTimeCurve];
290 timeOfDayFactor = (1 - Math.Clamp(timeOfDayFactor, 0, 1));
291 timeOfDayFactor = Math.Pow(timeOfDayFactor, 3) * 4 + 1;
293 if (soundHandle.m_SoundDef.m_bAddSequenceLength)
294 soundHandle.m_SoundDef.m_fCoolDownEnd = worldTime + soundHandle.GetSequenceLenght(worldTime) + soundHandle.m_SoundDef.m_iCoolDown * timeOfDayFactor;
296 soundHandle.m_SoundDef.m_fCoolDownEnd = worldTime + soundHandle.m_SoundDef.m_iCoolDown * timeOfDayFactor;
300 private vector GenerateRandomPosition(
int soundGroup, vector camPos)
303 float angle = m_aAngleOffset[soundGroup] * 36;
305 m_aAngleOffset[soundGroup] = m_aAngleOffset[soundGroup] + 1;
306 if (m_aAngleOffset[soundGroup] > 9)
307 m_aAngleOffset[soundGroup] = 0;
309 float fDist = m_aSpawnDef[soundGroup].m_iSpawnDist;
310 vector vPos = vector.FromYaw(angle) * fDist;
312 return vPos + camPos;
316 private int GetRandomSoundDef(
SCR_SoundType soundType,
float worldTime)
318 int size = soundType.m_aSoundDef.Count();
322 int offset = Math.RandomIntInclusive(0, size - 1);
324 for (
int i = 0; i < size; i++)
326 int idx = i + offset;
330 if (m_aDayTimeCurveValue[soundType.m_aSoundDef[idx].m_eDayTimeCurve] > 0 && soundType.m_aSoundDef[idx].m_fCoolDownEnd < worldTime)
340 foreach(SCR_TerrainDef terrainDef : m_aTerrainDef)
342 if (soundInfo >= terrainDef.m_iRangeMin && soundInfo < terrainDef.m_iRangeMax)
343 return terrainDef.m_eTerrainType;
350 private ESoundMapType GetSoundMapTypeFromTerrain(inout vector worldPos)
353 float surfaceHeight =
m_World.GetSurfaceY(worldPos[0], worldPos[2]);
354 worldPos[1] = surfaceHeight;
358 float waterSurfaceY = GetWaterSurfaceY(worldPos, waterSurfaceType, lakeArea);
360 switch (waterSurfaceType)
364 m_SoundWorld =
m_World.GetSoundWorld();
369 float sea, forest, city, meadow;
370 m_SoundWorld.GetMapValuesAtPos(worldPos, sea, forest, city, meadow);
373 float vals[] = { meadow, forest, city, sea };
376 for (
int i = 1; i < 4; i++)
394 if (lakeArea > LAKE_AREA_LIMIT)
396 worldPos[1] = waterSurfaceY;
408 private ETerrainType GetTerrainTypeFromTerrain(inout vector worldPos)
411 float surfaceHeight =
m_World.GetSurfaceY(worldPos[0], worldPos[2]);
412 worldPos[1] = surfaceHeight;
415 if (Math.AbsFloat(worldPos[1]) < COAST_HIGHT_LIMIT)
420 float waterSurfaceY = GetWaterSurfaceY(worldPos, waterSurfaceType, lakeArea);
422 switch (waterSurfaceType)
431 return GetTerrainType(soundInfo);
440 if (lakeArea > LAKE_AREA_LIMIT)
442 worldPos[1] = waterSurfaceY;
454 private float GetWaterSurfaceY(vector worldPos, out
EWaterSurfaceType waterSurfaceType, out
float lakeArea)
456 vector waterSurfacePos;
457 vector transformWS[4];
460 ChimeraWorldUtils.TryGetWaterSurface(
m_World, worldPos, waterSurfacePos, waterSurfaceType, transformWS, obbExtents);
461 lakeArea = obbExtents[0] * obbExtents[2];
463 return waterSurfacePos[1];
467 private vector GetRandomPositionOnEntity(IEntity entity)
470 entity.GetWorldBounds(mins, maxs);
475 pos = entity.GetOrigin();
478 pos[1] = pos[1] + (maxs[1] - mins[1]) * Math.RandomFloatInclusive(0.5, 1);
484 private void UpdateDensity()
488 m_aDensity[soundHandle.m_iSoundGroup] = m_aDensity[soundHandle.m_iSoundGroup] + soundHandle.m_fDensity;
491 for (
int i = 0, count = m_aSpawnDef.Count(); i < count; i++)
493 m_aDensity[i] = m_aDensity[i] * 0.5;
498 private float Interpolate01(
float in,
float Xmin,
float Xmax)
506 return (in - Xmin) / (Xmax - Xmin);
510 private void UpdateSignlsIdx()
517 m_iRainIntensitySignalIdx = m_GlobalSignalsManager.AddOrFindSignal(RAIN_INTENSITY_SIGNAL_NAME);
518 m_iWindSpeedSignalIdx = m_GlobalSignalsManager.AddOrFindSignal(WIND_SPEED_SIGNAL_NAME);
526 SCR_SoundGroup soundGrop;
527 if (def.m_SoundGroupResource !=
string.Empty)
529 Resource holder = BaseContainerTools.LoadContainer(def.m_SoundGroupResource);
531 soundGrop = SCR_SoundGroup.Cast(BaseContainerTools.CreateInstanceFromContainer(holder.GetResource().ToBaseContainer()));
536 ambientSoundsComponent.SetScriptedMethodsCall(
false);
537 Print(
"AUDIO: SCR_AmbientSoundsComponent: Missing Ambience Sound Gropu Config", LogLevel.WARNING);
541 m_aSoundGroup.Insert(soundGrop);
544 SCR_SpawnDef spawnDef;
545 if (def.m_SpawnDefResource !=
string.Empty)
547 Resource holder = BaseContainerTools.LoadContainer(def.m_SpawnDefResource);
549 spawnDef = SCR_SpawnDef.Cast(BaseContainerTools.CreateInstanceFromContainer(holder.GetResource().ToBaseContainer()));
554 ambientSoundsComponent.SetScriptedMethodsCall(
false);
555 Print(
"AUDIO: SCR_AmbientSoundsComponent: Missing Spawn Definition Config", LogLevel.WARNING);
559 m_aSpawnDef.Insert(spawnDef);
564 if (m_TerrainDefinitionResource !=
string.Empty)
566 Resource holder = BaseContainerTools.LoadContainer(m_TerrainDefinitionResource);
568 soundTerrainDefinitionConfig =
SCR_TerrainDefConfig.Cast(BaseContainerTools.CreateInstanceFromContainer(holder.GetResource().ToBaseContainer()));
571 if (!soundTerrainDefinitionConfig)
573 ambientSoundsComponent.SetScriptedMethodsCall(
false);
574 Print(
"AUDIO: SCR_AmbientSoundsComponent: Missing Sound Definition Terrain Config", LogLevel.WARNING);
578 m_aTerrainDef = soundTerrainDefinitionConfig.m_aTerrainDef;
582 if (m_DayTimeCurveResource !=
string.Empty)
584 Resource holder = BaseContainerTools.LoadContainer(m_DayTimeCurveResource);
586 ambientSoundsDayTimeCurveDefinitionConfig =
SCR_DayTimeCurveDefConfig.Cast(BaseContainerTools.CreateInstanceFromContainer(holder.GetResource().ToBaseContainer()));
589 if (!ambientSoundsDayTimeCurveDefinitionConfig)
591 ambientSoundsComponent.SetScriptedMethodsCall(
false);
592 Print(
"AUDIO: SCR_AmbientSoundsComponent: Missing Daytime Curve Deffinition Config", LogLevel.WARNING);
596 m_aDayTimeCurve = ambientSoundsDayTimeCurveDefinitionConfig.m_aDayTimeCurve;
600 if (m_WindCurveResource !=
string.Empty)
602 Resource holder = BaseContainerTools.LoadContainer(m_WindCurveResource);
604 ambientSoundsWindDefinitionConfig =
SCR_WindCurveDefConfig.Cast(BaseContainerTools.CreateInstanceFromContainer(holder.GetResource().ToBaseContainer()));
607 if (!ambientSoundsWindDefinitionConfig)
609 ambientSoundsComponent.SetScriptedMethodsCall(
false);
610 Print(
"AUDIO: SCR_AmbientSoundsComponent: Missing Wind Curve Definition Config", LogLevel.WARNING);
614 m_aWindModifier = ambientSoundsWindDefinitionConfig.m_aWindModifier;
619 private const int STRING_LENGTH = 25;
620 private const int PANEL_WIDTH = 20;
621 private const int PANEL_HEIGHT = 20;
625 void AmbientSignalsDebug()
627 DbgUI.Begin(
"Ambient Sounds Signals", 178, 0);
628 DbgUI.Text(SUN_ANGLE_SIGNAL_NAME +
": " +
m_LocalSignalsManager.GetSignalValue(m_iSunAngleSignalIdx).ToString());
629 DbgUI.Text(SOUND_NAME_SIGNAL_NAME +
": " +
m_LocalSignalsManager.GetSignalValue(m_iSoundNameSignalIdx).ToString());
631 DbgUI.Text(
"Environent Type : " +
typename.EnumToString(
EEnvironmentType, m_iEnvironmentTypeSignalValue));
639 DbgUI.Begin(
"Density", 420, 0);
640 for (
int i = 0, count = m_aSpawnDef.Count(); i < count; i++)
642 DbgUI.Text(m_aSoundGroup[i].m_sSoundEvent +
": " + m_aDensity[i].ToString() +
" / " + (Math.Round(GetDensityMax(i) * m_aDensityModifier[i])).ToString());
650 void RandomPositionalSoundDebug(
float worldTime)
652 int defaultColor = ARGB(255, 50, 50, 50);
653 int blackColor = ARGB(255, 0, 0, 0);
654 int availableColor = ARGB(255, 0, 0, 255);
655 int playingColor = ARGB(255, 255, 255, 0);
656 int wrongTimeColor = ARGB(255, 125, 125, 125);
657 int inCooldownColor = ARGB(255, 255, 0, 255);
659 DbgUI.Begin(
"Random Ambient Sounds", 0, 185);
661 DbgUI.Panel(
"av", PANEL_WIDTH, PANEL_HEIGHT, availableColor);
663 DbgUI.Text(
"Available");
665 DbgUI.Panel(
"pl", PANEL_WIDTH, PANEL_HEIGHT, playingColor);
667 DbgUI.Text(
"Playing");
669 DbgUI.Panel(
"wt", PANEL_WIDTH, PANEL_HEIGHT, wrongTimeColor);
671 DbgUI.Text(
"WrongTime");
673 DbgUI.Panel(
"in", PANEL_WIDTH, PANEL_HEIGHT, inCooldownColor);
675 DbgUI.Text(
"InCooldown");
677 for (
int soundGroup = 0; soundGroup < m_aSpawnDef.Count(); soundGroup++)
680 string name = m_aSoundGroup[soundGroup].m_sSoundEvent;
681 name = NormalizeLength(name);
682 name = soundGroup.ToString() +
". " + name;
686 int playingCount = 0;
688 bool bSoundTypeChecked =
false;
689 DbgUI.Check(name, bSoundTypeChecked);
691 for (
int i = 0; i < m_aSoundHandle.Count(); i++)
693 if (m_aSoundHandle[i].m_iSoundGroup == soundGroup)
697 for (
int i = 0; i < limitCount; i++)
699 int color = defaultColor;
701 if (i < playingCount)
703 color = playingColor;
707 DbgUI.Panel(soundGroup.ToString() +
"." + i.ToString(), PANEL_WIDTH, PANEL_HEIGHT, color);
710 if (bSoundTypeChecked)
712 int soundTypeCount = m_aSoundGroup[soundGroup].m_aSoundType.Count();
714 for (
int soundType = 0; soundType < soundTypeCount; soundType++)
717 string soundTypeName;
718 if (m_aSoundGroup[soundGroup].m_eSpawnMethod ==
ESpawnMethod.ENTITY)
721 soundTypeName =
"CONIFER";
723 soundTypeName =
"LEAFY";
725 else if (m_aSoundGroup[soundGroup].m_eSpawnMethod ==
ESpawnMethod.TERRAIN)
726 soundTypeName =
typename.EnumToString(
ETerrainType, soundType);
728 soundTypeName =
typename.EnumToString(
ESoundMapType, soundType);
730 soundTypeName = NormalizeLength(soundTypeName);
732 DbgUI.Panel(soundGroup.ToString() + soundType.ToString(), PANEL_WIDTH, PANEL_HEIGHT, blackColor);
734 bool bSoundGroupChecked =
false;
735 DbgUI.Check(soundGroup.ToString() +
"." + soundType.ToString() +
". " + soundTypeName, bSoundGroupChecked);
738 int size = m_aSoundGroup[soundGroup].m_aSoundType[soundType].m_aSoundDef.Count();
740 for (
int idx = 0; idx < size; idx++)
742 if (m_aDayTimeCurveValue[m_aSoundGroup[soundGroup].m_aSoundType[soundType].m_aSoundDef[idx].m_eDayTimeCurve] > 0 && m_aSoundGroup[soundGroup].m_aSoundType[soundType].m_aSoundDef[idx].m_fCoolDownEnd < worldTime)
746 DbgUI.Text(soundGroup.ToString() +
"." + soundType.ToString() +
". " +
"Available :" + available.ToString() +
" of (" + m_aSoundGroup[soundGroup].m_aSoundType[soundType].m_aSoundDef.Count() +
")");
748 if (bSoundGroupChecked)
750 int soundDefCount = m_aSoundGroup[soundGroup].m_aSoundType[soundType].m_aSoundDef.Count();
752 for (
int soundDef = 0; soundDef < soundDefCount; soundDef++)
754 int color = defaultColor;
755 string aditionalInfo =
"";
762 if (m_aSoundGroup[soundGroup].m_aSoundType[soundType].m_aSoundDef[soundDef].m_fCoolDownEnd > worldTime)
764 color = inCooldownColor;
765 aditionalInfo =
" | Coldown ends in : " + Math.Round((m_aSoundGroup[soundGroup].m_aSoundType[soundType].m_aSoundDef[soundDef].m_fCoolDownEnd - worldTime) * 0.001).ToString();
767 float timeOfDayFactor = m_aDayTimeCurveValue[m_aSoundGroup[soundGroup].m_aSoundType[soundType].m_aSoundDef[soundDef].m_eDayTimeCurve];
768 timeOfDayFactor = (1 - Math.Clamp(timeOfDayFactor, 0, 1));
769 timeOfDayFactor = Math.Pow(timeOfDayFactor, 3) * 4 + 1;
770 timeOfDayFactor = Math.Round(timeOfDayFactor * 100) * 0.01;
772 aditionalInfo = aditionalInfo +
" | TFactor : " + timeOfDayFactor.ToString();
776 if (m_aDayTimeCurveValue[m_aSoundGroup[soundGroup].m_aSoundType[soundType].m_aSoundDef[soundDef].m_eDayTimeCurve] <= 0)
777 color = wrongTimeColor;
780 if (m_aDayTimeCurveValue[m_aSoundGroup[soundGroup].m_aSoundType[soundType].m_aSoundDef[soundDef].m_eDayTimeCurve] > 0 && m_aSoundGroup[soundGroup].m_aSoundType[soundType].m_aSoundDef[soundDef].m_fCoolDownEnd <= worldTime)
781 color = availableColor;
783 DbgUI.Panel(soundGroup.ToString() +
"." + soundType.ToString() +
"." + soundDef.ToString(), PANEL_WIDTH * 2 + 5, PANEL_HEIGHT, color);
789 string soundDefinitionName =
typename.EnumToString(
ESoundName, m_aSoundGroup[soundGroup].m_aSoundType[soundType].m_aSoundDef[soundDef].m_eSoundName);
790 soundDefinitionName = NormalizeLength(soundDefinitionName);
792 DbgUI.Text(soundGroup.ToString() +
"." + soundType.ToString() +
"." + soundDef.ToString() +
". " + soundDefinitionName +
" ");
798 int instanceCount = 0;
799 float playbackEnd = 0;
803 if (sh.m_iSoundGroup == soundGroup && sh.m_iSoundType == soundType && sh.m_iSoundDef == soundDef)
807 if (playbackEnd < Math.Round(sh.m_aRepTime[sh.m_aRepTime.Count() - 1] - worldTime))
809 playbackEnd = Math.Round(sh.m_aRepTime[sh.m_aRepTime.Count() - 1] - worldTime);
814 playbackEnd = Math.Round(playbackEnd * 0.001);
818 aditionalInfo = aditionalInfo +
" | Playback ends in : " + playbackEnd.ToString();
821 for (
int j = 0; j < instanceCount; j++)
824 DbgUI.Panel(soundGroup.ToString() +
"." + soundType.ToString() +
"." + soundDef.ToString() +
"Play" + j.ToString(), PANEL_WIDTH, PANEL_HEIGHT, playingColor);
832 DbgUI.Text(aditionalInfo);
843 private string NormalizeLength(
string name)
845 int length = name.Length();
848 if (length <= STRING_LENGTH)
850 for (
int i = 0; i < (STRING_LENGTH - length); i++)
856 s = s.Substring(0, STRING_LENGTH * 0.5 - 2) +
"...." + s.Substring(length - STRING_LENGTH * 0.5, STRING_LENGTH * 0.5);
862 override void ReloadConfig()
864 super.ReloadConfig();
866 m_aSoundGroup.Clear();
871 SCR_SoundGroup soundGrop;
872 if (def.m_SoundGroupResource !=
string.Empty)
874 Resource holder = BaseContainerTools.LoadContainer(def.m_SoundGroupResource);
876 soundGrop = SCR_SoundGroup.Cast(BaseContainerTools.CreateInstanceFromContainer(holder.GetResource().ToBaseContainer()));
880 m_aSoundGroup.Insert(soundGrop);
883 SCR_SpawnDef spawnDef;
884 if (def.m_SpawnDefResource !=
string.Empty)
886 Resource holder = BaseContainerTools.LoadContainer(def.m_SpawnDefResource);
888 spawnDef = SCR_SpawnDef.Cast(BaseContainerTools.CreateInstanceFromContainer(holder.GetResource().ToBaseContainer()));
892 m_aSpawnDef.Insert(spawnDef);
897 if (m_TerrainDefinitionResource !=
string.Empty)
899 Resource holder = BaseContainerTools.LoadContainer(m_TerrainDefinitionResource);
901 soundTerrainDefinitionConfig =
SCR_TerrainDefConfig.Cast(BaseContainerTools.CreateInstanceFromContainer(holder.GetResource().ToBaseContainer()));
904 if (soundTerrainDefinitionConfig)
905 m_aTerrainDef = soundTerrainDefinitionConfig.m_aTerrainDef;
909 if (m_DayTimeCurveResource !=
string.Empty)
911 Resource holder = BaseContainerTools.LoadContainer(m_DayTimeCurveResource);
913 ambientSoundsDayTimeCurveDefinitionConfig =
SCR_DayTimeCurveDefConfig.Cast(BaseContainerTools.CreateInstanceFromContainer(holder.GetResource().ToBaseContainer()));
916 if (!ambientSoundsDayTimeCurveDefinitionConfig)
917 m_aDayTimeCurve = ambientSoundsDayTimeCurveDefinitionConfig.m_aDayTimeCurve;
921 if (m_WindCurveResource !=
string.Empty)
923 Resource holder = BaseContainerTools.LoadContainer(m_WindCurveResource);
925 ambientSoundsWindDefinitionConfig =
SCR_WindCurveDefConfig.Cast(BaseContainerTools.CreateInstanceFromContainer(holder.GetResource().ToBaseContainer()));
928 if (ambientSoundsWindDefinitionConfig)
929 m_aWindModifier = ambientSoundsWindDefinitionConfig.m_aWindModifier;
931 m_aSoundHandle.Clear();
937 DbgUI.Begin(
"Play Sound", 0, 0);
942 float distanceFactor = 0.15;
943 DbgUI.InputInt(
"Sound Group:", soundGroup, 50);
944 DbgUI.InputInt(
"Sound Type :", soundType, 50);
945 DbgUI.InputInt(
"Sound Def :", soundDef, 50);
946 DbgUI.InputFloat(
"Dist Factor:", distanceFactor, 50);
948 bool play = DbgUI.Button(
"Play");
950 bool clear = DbgUI.Button(
"Clear");
955 if (soundGroup >= m_aSoundGroup.Count() || soundType >= m_aSoundGroup[soundGroup].m_aSoundType.Count() || soundDef >= m_aSoundGroup[soundGroup].m_aSoundType[soundType].m_aSoundDef.Count())
960 GetGame().GetCameraManager().CurrentCamera().GetTransform(mat);
964 float angle = yaw.ToYaw();
966 yaw = vector.FromYaw(angle);
969 float dist = Math.Lerp(m_aSpawnDef[soundGroup].m_iPlayDistMin, m_aSpawnDef[soundGroup].m_iPlayDistMax, distanceFactor);
970 mat[3] = mat[3] + yaw * dist;
974 m_aSoundHandle.Insert(soundHandle);
978 m_aSoundHandle.Clear();
988 super.OnPostInit(ambientSoundsComponent, signalsManagerComponent);
990 LoadConfigs(ambientSoundsComponent);
993 m_GlobalSignalsManager =
GetGame().GetSignalsManager();
996 int count = m_aSpawnDef.Count();
997 m_aDensity.Resize(count);
998 m_aAngleOffset.Resize(count);
999 m_aDensityModifier.Resize(count);
1005 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_SOUNDS_RANDOM_POSITIONAL_SOUNDS,
"",
"Random Ambient Sounds",
"Sounds");
1014 UpdateGlobalModifiers();
1019 void ~SCR_RandomPositionalSounds()
1022 if (DiagMenu.GetBool(
SCR_DebugMenuID.DEBUGUI_SOUNDS_RANDOM_POSITIONAL_SOUNDS))
1024 foreach (SCR_SoundGroup soundGroup : m_aSoundGroup)
1028 foreach (SCR_SoundDef soundDef : soundType.m_aSoundDef)
1030 Print(
typename.EnumToString(
ESoundName, soundDef.m_eSoundName) +
": " + soundDef.m_iCount, LogLevel.NORMAL);
1036 DiagMenu.Unregister(
SCR_DebugMenuID.DEBUGUI_SOUNDS_RANDOM_POSITIONAL_SOUNDS);