Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AmbientSoundsComponent.c
Go to the documentation of this file.
1 enum EQueryType // TODO: SCR_EQueryType
2 {
9  Building,
10 }
11 
12 [EntityEditorProps(category: "GameScripted/Sound", description: "THIS IS THE SCRIPT DESCRIPTION.", color: "0 0 255 255")]
13 class SCR_AmbientSoundsComponentClass : AmbientSoundsComponentClass
14 {
15 }
16 
17 class SCR_AmbientSoundsComponent : AmbientSoundsComponent
18 {
19  [Attribute()]
20  ref array<ref SCR_AmbientSoundsEffect> m_aAmbientSoundsEffect;
21 
22  // Components
23  private SignalsManagerComponent m_LocalSignalsManager;
24 
25  // Constants
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;
35 
36  // Timers
37  private float m_fQueryTimer;
38  private float m_fUpdateTimer;
39 
40  // Misc
41  private ChimeraWorld m_World;
42  private float m_fWorldTime;
43  private vector m_vCameraPosFrame;
44  private vector m_vCameraPosQuery;
45  private vector m_vCameraPosLoopedSound;
46 
47  // Looped sounds pool
48  private ref array<ref SCR_AudioHandleLoop> m_aAudioHandleLoop = {};
49 
51  private ref array<int> m_aQueryTypeCount = {};
52 
53  //------------------------------------------------------------------------------------------------
55  private void HandleQueryEntities()
56  {
57  // Limit processing by time and moved distance
58  if (m_fWorldTime < m_fQueryTimer)
59  return;
60 
61  if (vector.DistanceSqXZ(m_vCameraPosQuery, m_vCameraPosFrame) < QUERY_MINIMUM_MOVE_DISTANCE_SQ)
62  return;
63 
64  m_fQueryTimer = m_fWorldTime + QUERY_PROCESSING_INTERVAL;
65  m_vCameraPosQuery = m_vCameraPosFrame;
66 
67  // Get new query values
68  QueryAmbientSoundsBySphere(QUERY_RADIUS);
69  GetAmbientSoundsCountPerType(m_aQueryTypeCount);
70  }
71 
72  //------------------------------------------------------------------------------------------------
74  EQueryType GetDominantTree()
75  {
76  if (m_aQueryTypeCount[EQueryType.TreeLeafy] + m_aQueryTypeCount[EQueryType.TreeConifer] == 0)
77  return INVALID;
78 
79  if (m_aQueryTypeCount[EQueryType.TreeLeafy] > m_aQueryTypeCount[EQueryType.TreeConifer])
80  return EQueryType.TreeLeafy;
81 
82  return EQueryType.TreeConifer;
83  }
84 
85  //------------------------------------------------------------------------------------------------
90  static float GetPoint(float x, Curve curve)
91  {
92  if (x <= curve[0][0])
93  return curve[0][1];
94 
95  int lastIdx = curve.Count() - 1;
96 
97  if (x >= curve[lastIdx][0])
98  return curve[lastIdx][1];
99 
100  int i;
101  for (i = 1; i < lastIdx; i++)
102  {
103  if (curve[i][0] > x)
104  break;
105  }
106 
107  if (curve[i-1][1] == curve[i][1])
108  return curve[i][1];
109  else
110  return Math.Lerp(curve[i-1][1], curve[i][1], (x - curve[i-1][0]) / (curve[i][0] - curve[i-1][0]));
111  }
112 
113  //------------------------------------------------------------------------------------------------
118  SCR_AudioHandleLoop SoundEventLooped(string soundEvent, vector transformation[4])
119  {
120  SCR_AudioHandleLoop audioHandleLoop = new SCR_AudioHandleLoop;
121 
122  audioHandleLoop.m_aMat = transformation;
123  audioHandleLoop.m_sSoundEvent = soundEvent;
124 
125  m_aAudioHandleLoop.Insert(audioHandleLoop);
126 
127  return audioHandleLoop;
128  }
129 
130  //------------------------------------------------------------------------------------------------
133  void TerminateLooped(SCR_AudioHandleLoop audioHandleLoop)
134  {
135  if (!audioHandleLoop)
136  return;
137 
138  Terminate(audioHandleLoop.m_AudioHandle);
139  m_aAudioHandleLoop.RemoveItem(audioHandleLoop);
140  }
141 
142  //------------------------------------------------------------------------------------------------
143  private void UpdateLoopedSounds()
144  {
145  foreach (SCR_AudioHandleLoop audioHandleLoop : m_aAudioHandleLoop)
146  {
147  if (IsFinishedPlaying(audioHandleLoop.m_AudioHandle))
148  audioHandleLoop.m_AudioHandle = SoundEventTransform(audioHandleLoop.m_sSoundEvent, audioHandleLoop.m_aMat);
149  }
150  }
151 
152  //------------------------------------------------------------------------------------------------
153  override void UpdateSoundJob(IEntity owner, float timeSlice)
154  {
155  super.UpdateSoundJob(owner, timeSlice);
156 
157  m_vCameraPosFrame = GetCameraOrigin();
158  m_fWorldTime = m_World.GetWorldTime();
159 
160  // Update effects
161  if (m_fWorldTime > m_fUpdateTimer)
162  {
163  // Handle looped sounds
164  if (vector.DistanceSqXZ(m_vCameraPosLoopedSound, m_vCameraPosFrame) > LOOPED_SOUND_MINIMUM_MOVE_DISTANCE_SQ)
165  {
166  m_vCameraPosLoopedSound = m_vCameraPosFrame;
167  UpdateLoopedSounds()
168  }
169 
170  foreach (SCR_AmbientSoundsEffect ambientSoundsEffect : m_aAmbientSoundsEffect)
171  {
172  ambientSoundsEffect.Update(m_fWorldTime, m_vCameraPosFrame);
173  }
174 
175  m_fUpdateTimer = m_fWorldTime + UPDATE_PROCESSING_INTERVAL;
176  }
177 
178  HandleQueryEntities();
179 
180 #ifdef ENABLE_DIAG
181  foreach (SCR_AmbientSoundsEffect ambientSoundsEffect : m_aAmbientSoundsEffect)
182  {
183  ambientSoundsEffect.UpdateDebug(m_fWorldTime);
184  }
185 
186  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_SOUNDS_RELOAD_AMBIENT_SOUNDS_CONFIGS))
187  {
188  foreach (SCR_AmbientSoundsEffect ambientSoundsEffect : m_aAmbientSoundsEffect)
189  {
190  ambientSoundsEffect.ReloadConfig();
191  }
192 
193  DiagMenu.SetValue(SCR_DebugMenuID.DEBUGUI_SOUNDS_RELOAD_AMBIENT_SOUNDS_CONFIGS, false);
194  }
195 #endif
196  }
197 
198  //------------------------------------------------------------------------------------------------
199  override void OnPostInit(IEntity owner)
200  {
201  super.OnPostInit(owner);
202 
203  // Get world
204  m_World = GetGame().GetWorld();
205  if (!m_World)
206  {
207  SetScriptedMethodsCall(false);
208  return;
209  }
210 
211  // Get local signals component
212  m_LocalSignalsManager = SignalsManagerComponent.Cast(owner.FindComponent(SignalsManagerComponent));
214  {
215  SetScriptedMethodsCall(false);
216  Print("AUDIO: SCR_AmbientSoundsComponent: Missing SignalsManagerComponent", LogLevel.WARNING);
217  return;
218  }
219 
220  foreach (SCR_AmbientSoundsEffect ambientSoundsEffect : m_aAmbientSoundsEffect)
221  {
222  ambientSoundsEffect.OnPostInit(this, m_LocalSignalsManager);
223  }
224  }
225 
226  //------------------------------------------------------------------------------------------------
227  override void OnInit(IEntity owner)
228  {
229  super.OnInit(owner);
230 
231  m_World.RegisterEntityToBeUpdatedWhileGameIsPaused(owner);
232 
233  foreach (SCR_AmbientSoundsEffect ambientSoundsEffect : m_aAmbientSoundsEffect)
234  {
235  ambientSoundsEffect.OnInit();
236  }
237  }
238 
239  //------------------------------------------------------------------------------------------------
240  // constructor
244  void SCR_AmbientSoundsComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
245  {
247 
248  m_aQueryTypeCount.Resize(QUERY_TYPES);
249 
250 #ifdef ENABLE_DIAG
251  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_SOUNDS_RELOAD_AMBIENT_SOUNDS_CONFIGS, "", "Reload AmbientSounds Conf", "Sounds");
252 #endif
253  }
254 
255  //------------------------------------------------------------------------------------------------
256  // destructor
258  {
259  if (m_World)
260  m_World.UnregisterEntityToBeUpdatedWhileGameIsPaused(GetOwner());
261 
262 #ifdef ENABLE_DIAG
263  DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_SOUNDS_RELOAD_AMBIENT_SOUNDS_CONFIGS);
264 #endif
265  }
266 }
GetCameraOrigin
proto external vector GetCameraOrigin()
ChimeraWorld
Definition: ChimeraWorld.c:12
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
EQueryType
EQueryType
Definition: SCR_AmbientSoundsComponent.c:1
TreeLeafy
TreeLeafy
Definition: SCR_AmbientSoundsComponent.c:3
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
QueryAmbientSoundsBySphere
AmbientSoundsComponentClass SoundComponentClass QueryAmbientSoundsBySphere(float radius, EQueryEntitiesFlags queryFlags=EQueryEntitiesFlags.ALL)
Building
Building
Definition: SCR_AmbientSoundsComponent.c:8
Attribute
typedef Attribute
Post-process effect of scripted camera.
INVALID
@ INVALID
Missing components, or obstruction test was not possible.
Definition: SCR_CharacterRankComponent.c:326
m_LocalSignalsManager
protected SignalsManagerComponent m_LocalSignalsManager
Definition: SCR_PositionalInsectType.c:15
TreeBush
TreeBush
Definition: SCR_AmbientSoundsComponent.c:2
TreeStump
TreeStump
Definition: SCR_AmbientSoundsComponent.c:6
SCR_AmbientSoundsComponent
Definition: SCR_AmbientSoundsComponent.c:17
m_World
protected BaseWorld m_World
Definition: SCR_PreviewEntityEditorUIComponent.c:46
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SoundEventTransform
proto external AudioHandle SoundEventTransform(string eventName, vector transf[])
Play a sound from a set transformation.
TreeLeafyDomestic
TreeLeafyDomestic
Definition: SCR_AmbientSoundsComponent.c:4
TreeWithered
TreeWithered
Definition: SCR_AmbientSoundsComponent.c:7
GetAmbientSoundsCountPerType
proto external void GetAmbientSoundsCountPerType(out notnull array< int > count)
SCR_AudioHandleLoop
Definition: SCR_AudioHandleLoop.c:2
AmbientSoundsComponentClass
Definition: AmbientSoundsComponent.c:12
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3
SetScriptedMethodsCall
proto external void SetScriptedMethodsCall(bool state)
Set flag for script callbacks.
SCR_AmbientSoundsEffect
Definition: SCR_AmbientSoundsEffect.c:2
TreeConifer
TreeConifer
Definition: SCR_AmbientSoundsComponent.c:5
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180