17 SCR_SoundDef m_SoundDef;
20 ref array<int> m_aRepTime;
32 void UpdateDensity(
float sampleLenght,
float worldTime)
34 float sequenceLenght = GetSequenceLenght(worldTime);
35 if (sequenceLenght == 0)
41 m_fDensity = Math.Clamp(sampleLenght * m_aRepTime.Count() / sequenceLenght, 0, 1) * 100;
48 float GetSequenceLenght(
float worldTime)
50 int size = m_aRepTime.Count();
54 return m_aRepTime[size - 1] - worldTime + m_SoundDef.m_iSampleLength;
58 protected int GetRandomInt(
int value,
int random)
63 int min = value - random;
67 return Math.RandomIntInclusive(min, value + random);
71 protected void CreateSequence(array<ref SCR_SequenceDef> sequenceDefinitions,
int idx)
75 for (
int i = 0, count = GetRandomInt(sequenceDefinition.m_iRepCount, sequenceDefinition.m_iRepCountRnd); i < count; i++)
78 m_aRepTime.Insert(GetRandomInt(sequenceDefinition.m_iRepTime, sequenceDefinition.m_iRepTimeRnd) + m_aRepTime[m_aRepTime.Count() - 1]);
82 CreateSequence(sequenceDefinitions, idxNew);
89 void UpdateRepTime(
float gameTime)
96 m_aRepTime.Insert(gameTime + GetRandomInt(m_SoundDef.m_iStartDelay, m_SoundDef.m_iStartDelayRnd));
98 if (m_SoundDef.m_aSequenceDef.Count() == 0)
99 Print(
"AmbientSoundsComponent: " +
typename.EnumToString(
ESoundName, m_SoundDef.m_eSoundName) +
" is missing sequence definition", LogLevel.WARNING);
101 CreateSequence(m_SoundDef.m_aSequenceDef, m_SoundDef.m_aSequenceDef.Count() - 1);
112 void SCR_SoundHandle(
int soundGroupIdx,
int soundTypeIdx,
int soundDefIdx, vector mat[4], array<ref SCR_SoundGroup> soundGroup,
float worldTime)
114 m_iSoundGroup = soundGroupIdx;
115 m_iSoundType = soundTypeIdx;
116 m_iSoundDef = soundDefIdx;
118 m_SoundDef = soundGroup[soundGroupIdx].m_aSoundType[soundTypeIdx].m_aSoundDef[soundDefIdx];
119 UpdateRepTime(worldTime);
120 UpdateDensity(m_SoundDef.m_iSampleLength, worldTime);