Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CameraShakeManagerComponent.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Camera", description: "Manager for camera shake.")]
2 class SCR_CameraShakeManagerComponentClass : ScriptComponentClass
3 {
4 }
5 
7 class SCR_CameraShakeManagerComponent : ScriptComponent
8 {
10  protected vector m_mShakeMatrix[4];
11  protected float m_fFovScale;
12 
14  const int CAMERA_SHAKE_INSTANCES = 16;
16 
18  ref array<ref SCR_BaseCameraShakeProgress> m_aAdditionalInstances = {};
19 
20  // Current instance of manager or null if none
21  private static SCR_CameraShakeManagerComponent s_Instance;
22 
23  //------------------------------------------------------------------------------------------------
30  static void AddCameraShake(float linearMagnitude = 1.0, float angularMagnitude = 1.0, float inTime = 0.01, float sustainTime = 0.1, float outTime = 0.24)
31  {
32  if (s_Instance)
33  s_Instance.DoAddCameraShake(linearMagnitude, angularMagnitude, inTime, sustainTime, outTime);
34  }
35 
36  //------------------------------------------------------------------------------------------------
43  void DoAddCameraShake(float linearMagnitude = 1.0, float angularMagnitude = 1.0, float inTime = 0.01, float sustainTime = 0.1, float outTime = 0.24)
44  {
45  for (int i = 0; i < CAMERA_SHAKE_INSTANCES; i++)
46  {
47  // Find first free instance that can be used
49  if (shake.IsFinished())
50  {
51  shake.SetParams(linearMagnitude, angularMagnitude, inTime, sustainTime, outTime);
52  shake.Start();
53  return;
54  }
55  }
56  }
57 
58  //------------------------------------------------------------------------------------------------
61  static void AddCameraShake(SCR_BaseCameraShakeProgress instance)
62  {
63  if (s_Instance)
64  s_Instance.DoAddCameraShake(instance);
65  }
66 
67  //------------------------------------------------------------------------------------------------
71  {
72  if (!instance)
73  {
74  Print("Invalid camera shake instance passed to manager!", LogLevel.ERROR);
75  return;
76  }
77 
78  m_aAdditionalInstances.Insert(instance);
79  instance.Start();
80  }
81 
82  //------------------------------------------------------------------------------------------------
84  static void ApplyCameraShake(inout vector matrix[4], inout float fov)
85  {
86  if (s_Instance)
87  s_Instance.DoApplyCameraShake(matrix, fov);
88  }
89 
90  //------------------------------------------------------------------------------------------------
94  void DoApplyCameraShake(inout vector matrix[4], inout float fov)
95  {
96  #ifdef ENABLE_DIAG
97  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_CHARACTER_ADDITIONAL_CAMERASHAKE_DISABLE))
98  return;
99  #endif
100 
101  Math3D.MatrixMultiply4( matrix, m_mShakeMatrix, matrix );
102  fov *= m_fFovScale;
103  }
104 
105  //------------------------------------------------------------------------------------------------
107  static void ClearCameraShake()
108  {
109  if (s_Instance)
110  s_Instance.DoClearCameraShake();
111  }
112 
113  //------------------------------------------------------------------------------------------------
116  {
117  for (int i = 0; i < CAMERA_SHAKE_INSTANCES; i++)
118  {
120  if (!shake.IsFinished())
121  shake.Clear();
122  }
123 
124  m_aAdditionalInstances.Clear();
125  }
126 
127  //------------------------------------------------------------------------------------------------
128  override void OnPostInit(IEntity owner)
129  {
130  Math3D.MatrixIdentity4(m_mShakeMatrix);
131 
132  // Skip the initialization of shake manager on headless
133  // clients and dedicated server, as the visual can be ommitted completely.
134  if (System.IsConsoleApp())
135  return;
136 
137  s_Instance = this;
138  SetEventMask(owner, EntityEvent.FRAME);
139  GenericEntity.Cast(owner).Activate();
140 
141  // Pre-cache instances
142  for (int i = 0; i < CAMERA_SHAKE_INSTANCES; i++)
143  {
145  }
146  }
147 
148  //------------------------------------------------------------------------------------------------
149  override void EOnFrame(IEntity owner, float timeSlice)
150  {
151  // Clear out matrix and FOV
152  Math3D.MatrixIdentity4(m_mShakeMatrix);
153  m_fFovScale = 1.0;
154 
155  // Update generic shakes
156  for (int i = 0; i < CAMERA_SHAKE_INSTANCES; i++)
157  {
159  if (!shake.IsFinished())
160  {
161  shake.Update(owner, timeSlice);
162  shake.Apply(m_mShakeMatrix, m_fFovScale);
163  }
164  }
165 
166  // Update custom instances
167  for (int i = 0; i < m_aAdditionalInstances.Count();)
168  {
170  if (!shake || shake.IsFinished())
171  {
172  m_aAdditionalInstances.Remove(i);
173  continue;
174  }
175 
176  ++i;
177 
178  shake.Update(owner, timeSlice);
179  shake.Apply(m_mShakeMatrix, m_fFovScale);
180  }
181 
182  super.EOnFrame(owner, timeSlice);
183 
184  // Draw diag window
185  #ifdef ENABLE_DIAG
186  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_CHARACTER_CAMERASHAKE_TEST_WINDOW))
187  {
188  DbgUI.Begin("Camera Shake");
189  {
190  float linear = 1, angular = 1, inTime = 0.01, sustainTime = 0.1, outTime = 1.0;
191  DbgUI.Text("New shake: ");
192  DbgUI.InputFloat("Linear: ", linear);
193  DbgUI.InputFloat("Angular: ", angular);
194  DbgUI.InputFloat("InTime: ", inTime);
195  DbgUI.InputFloat("SustainTime: ", sustainTime);
196  DbgUI.InputFloat("OutTime: ", outTime);
197 
198  if (DbgUI.Button("Add new shake"))
199  {
200  AddCameraShake(linear, angular, inTime, sustainTime, outTime);
201  }
202 
203  if (DbgUI.Button("Add custom shake"))
204  {
205  // Just for testing purposes
207  progress.SetParams(linear, angular, inTime, sustainTime, outTime);
208 
209  AddCameraShake(progress);
210  }
211 
212  DbgUI.Spacer(16);
213 
214  if (DbgUI.Button("Clear shake"))
215  {
216  ClearCameraShake();
217  }
218  }
219  DbgUI.End();
220  }
221  #endif
222  }
223 }
CAMERA_SHAKE_INSTANCES
const int CAMERA_SHAKE_INSTANCES
Array of pre-cached generic shakes.
Definition: SCR_CameraShakeManagerComponent.c:14
SCR_CameraShakeManagerComponentClass
Definition: SCR_CameraShakeManagerComponent.c:2
SCR_NoisyCameraShakeProgress
Definition: SCR_NoisyCameraShakeProgress.c:4
DoApplyCameraShake
void DoApplyCameraShake(inout vector matrix[4], inout float fov)
Definition: SCR_CameraShakeManagerComponent.c:94
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
SCR_BaseCameraShakeProgress
Definition: SCR_BaseCameraShakeProgress.c:4
DoClearCameraShake
void DoClearCameraShake()
Clears all existing camera shake progress(es).
Definition: SCR_CameraShakeManagerComponent.c:115
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_CameraShakeManagerComponent.c:128
DoAddCameraShake
void DoAddCameraShake(float linearMagnitude=1.0, float angularMagnitude=1.0, float inTime=0.01, float sustainTime=0.1, float outTime=0.24)
Definition: SCR_CameraShakeManagerComponent.c:43
m_aAdditionalInstances
ref array< ref SCR_BaseCameraShakeProgress > m_aAdditionalInstances
Array of custom shakes.
Definition: SCR_CameraShakeManagerComponent.c:18
EOnFrame
override void EOnFrame(IEntity owner, float timeSlice)
Definition: SCR_CameraShakeManagerComponent.c:149
m_aShakeInstances
ref SCR_NoisyCameraShakeProgress m_aShakeInstances[CAMERA_SHAKE_INSTANCES]
Definition: SCR_CameraShakeManagerComponent.c:15
m_mShakeMatrix
SCR_CameraShakeManagerComponentClass m_mShakeMatrix[4]
This manager allows adding camera shake that is updated automatically and can be applied to any trans...
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3
m_fFovScale
protected float m_fFovScale
Definition: SCR_CameraShakeManagerComponent.c:11
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180