5 private const int MINIMUM_MOVE_DISTANCE_SQ = 2;
6 private const int INVALID = -1;
7 private const int LOOP_SOUND_HEIGHT_LIMIT = 25;
8 private const int LOOP_SOUND_COUNT = 9;
9 private const float BOUNDING_BOX_CROP_FACTOR = 0.3;
10 private const float BOUNDING_BOX_CROP_FACTOR_HEIGHT = 0.9;
11 private const int BUSH_LOOP_SOUND_COUNT_LIMIT = 4;
12 private const string ENTITY_SIZE_SIGNAL_NAME =
"EntitySize";
13 private const string SEED_SIGNAL_NAME =
"Seed";
15 [
Attribute(
"0.3",
desc:
"Ratio of bushes with insect sounds vs without")]
16 private float m_fBushCricketThreshold;
18 private int m_iEntitySizeSignalIdx;
19 private int m_iSeedSignalIdx;
22 private vector m_vCameraPosLooped;
25 private ref array<IEntity> m_aClosestEntityID = {};
28 private ref array<IEntity> m_aLoopedSoundID = {};
31 private ref array<AudioHandle> m_aLoopedSoundAudioHandle = {};
35 override void Update(
float worldTime,
vector cameraPos,
bool forceUpdate)
37 if (!forceUpdate &&
vector.DistanceSqXZ(m_vCameraPosLooped, cameraPos) < MINIMUM_MOVE_DISTANCE_SQ)
40 m_vCameraPosLooped = cameraPos;
43 UpdateClosestEntitiesArray();
49 PlayLoopedSounds(cameraPos);
53 private void StopLoopedSounds()
55 for (
int i = m_aLoopedSoundID.Count() - 1; i >= 0; i--)
57 int index = m_aClosestEntityID.Find(m_aLoopedSoundID[i]);
61 m_aLoopedSoundID.Remove(i);
63 m_aLoopedSoundAudioHandle.Remove(i);
69 private void PlayLoopedSounds(
vector cameraPos)
71 foreach(
IEntity entity: m_aClosestEntityID)
76 int index = m_aLoopedSoundID.Find(entity);
94 vector v = entity.GetOrigin();
95 int seed = v[0] * v[2];
99 if (ranGen.RandFloat01() > m_fBushCricketThreshold)
101 float sampleSelector =
Math.AbsInt(seed % 100) * 0.01;
113 Math3D.MatrixIdentity4(mat);
117 entity.GetWorldBounds(mins, maxs);
120 float BVHeight = (maxs[1] - mins[1] - foliageHight) * BOUNDING_BOX_CROP_FACTOR_HEIGHT;
123 float widthX = (maxs[0] - mins[0]) * 0.5;
124 float widthZ = (maxs[2] - mins[2]) * 0.5;
125 float BVRadius = 0.5 * (widthX + widthZ) * BOUNDING_BOX_CROP_FACTOR;
128 mat[3][0] = mins[0] + widthX;
129 mat[3][1] = mins[1] + foliageHight + 0.5 * BVHeight;
130 mat[3][2] = mins[2] + widthZ;
141 m_aLoopedSoundID.Insert(entity);
142 m_aLoopedSoundAudioHandle.Insert(audioHandle);
147 private void UpdateClosestEntitiesArray()
149 m_aClosestEntityID.Clear();
167 foliageHeight = treeClass.m_iFoliageHeight * entity.
GetScale();
168 soundType = treeClass.SoundType;
174 if (foliageHeight < 3)
176 else if (foliageHeight < 5)
178 else if (foliageHeight < 7)
188 super.OnPostInit(ambientSoundsComponent, signalsManagerComponent);
190 m_iEntitySizeSignalIdx = signalsManagerComponent.AddOrFindSignal(ENTITY_SIZE_SIGNAL_NAME);
191 m_iSeedSignalIdx = signalsManagerComponent.AddOrFindSignal(SEED_SIGNAL_NAME);