Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CameraShakeManagerComponent.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/Camera", description: "Manager for camera shake.")]
5
7class 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
48 SCR_NoisyCameraShakeProgress shake = m_aShakeInstances[i];
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 //------------------------------------------------------------------------------------------------
70 void DoAddCameraShake(SCR_BaseCameraShakeProgress instance)
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 //------------------------------------------------------------------------------------------------
115 void DoClearCameraShake()
116 {
117 for (int i = 0; i < CAMERA_SHAKE_INSTANCES; i++)
118 {
119 SCR_BaseCameraShakeProgress shake = m_aShakeInstances[i];
120 if (!shake.IsFinished())
121 shake.Clear();
122 }
123
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 {
144 m_aShakeInstances[i] = new SCR_NoisyCameraShakeProgress();
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 {
158 SCR_BaseCameraShakeProgress shake = m_aShakeInstances[i];
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 {
169 SCR_BaseCameraShakeProgress shake = m_aAdditionalInstances[i];
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
206 SCR_NoisyCameraShakeProgress progress = new SCR_NoisyCameraShakeProgress();
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}
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition DebugMenuID.c:4
const int CAMERA_SHAKE_INSTANCES
Array of pre-cached generic shakes.
ref array< ref SCR_BaseCameraShakeProgress > m_aAdditionalInstances
Array of custom shakes.
SCR_CameraShakeManagerComponentClass m_mShakeMatrix[4]
This manager allows adding camera shake that is updated automatically and can be applied to any trans...
ref SCR_NoisyCameraShakeProgress m_aShakeInstances[CAMERA_SHAKE_INSTANCES]
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
override void EOnFrame(IEntity owner, float timeSlice)
SCR_SpawnerSlotManagerClass s_Instance
Class used for managing changes and removals of slots present in world.
enum EVehicleType IEntity
void SetParams(float linearMagnitude, float angularMagnitude, float inTime, float sustainTime, float outTime)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
EntityEvent
Various entity events.
Definition EntityEvent.c:14