DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
PPEManager.c
Go to the documentation of this file.
1
3{
4 static ref PPEManager m_Manager;
5
6 static void CreateManagerStatic()
7 {
8 if (m_Manager)
9 {
10 Debug.Log("PPEManagerStatic | CreateManagerStatic - PPEManager already exists");
11 return;
12 }
13
15 }
16
18 {
19 if (m_Manager)
20 {
21 m_Manager.Cleanup();
22 delete m_Manager;
23 }
24 }
25
28 {
29 return m_Manager;
30 }
31}
32
53class PPEManager extends Managed
54{
55 const int CAMERA_ID = 0;
56
57 protected bool m_ManagerInitialized;
58 protected ref map<int, ref PPEClassBase> m_PPEClassMap; //contains sorted postprocess classes, IDs in 'PostProcessEffectType' // <MaterialID,<material_class>>
59 protected ref map<int, ref array<int>> m_PPEMaterialUpdateQueueMap; //multiple levels of update queues, to allow for multiple dependent updates during same frame (greedy?)
61 protected ref array<ref PPERequesterBase> m_ExistingPostprocessRequests; //which requests are active overall. Does not have to be updating ATM!
62 protected ref array<ref PPERequesterBase> m_UpdatingRequests; //which requests are currently updating and processing
63
65 {
67 PPERequesterBank.Init();
68 }
69
70 void Cleanup()
71 {
72 PPERequesterBank.Cleanup();
73
75 {
78 m_UpdatingRequests.Clear();
79 m_PPEClassMap.Clear();
80 }
81 }
82
84 void Init()
85 {
86 //DbgPrnt("PPEDebug | PPEManager | m_ManagerInitialized: " + m_ManagerInitialized);
88 {
94
95 GetGame().GetUpdateQueue(CALL_CATEGORY_GUI).Insert(this.Update); //can be safely and easily 'disabled' here
96 m_ManagerInitialized = true;
97 }
98 }
99
101 protected void InitPPEManagerClassMap()
102 {
103 if (m_PPEClassMap)
104 {
105 delete m_PPEClassMap;
106 }
108
109 RegisterPPEClass(new PPENone()); //dummy
134 }
135
137 protected void RegisterPPEClass(PPEClassBase material_class)
138 {
139 m_PPEClassMap.Set(material_class.GetPostProcessEffectID(), material_class);
140 }
141
143 {
144 //DbgPrnt("DataVerification | m_ColorTarget | SendMaterialValueData: " + PPERequestParamDataColor.Cast(data).m_ColorTarget[0] + "/" + PPERequestParamDataColor.Cast(data).m_ColorTarget[1] + "/" + PPERequestParamDataColor.Cast(data).m_ColorTarget[2] + "/" + PPERequestParamDataColor.Cast(data).m_ColorTarget[3]);
145 PPEClassBase mat_class = m_PPEClassMap.Get(data.GetMaterialID());
146 mat_class.InsertParamValueData(data);
147 SetMaterialParamUpdating(data.GetMaterialID(),data.GetParameterID(),PPEConstants.DEPENDENCY_ORDER_BASE);
148 }
149
151 void SetMaterialParamUpdating(int material_id, int parameter_id, int order)
152 {
153 if ( order > PPEConstants.DEPENDENCY_ORDER_HIGHEST )
154 {
155 //DbgPrnt("PPEDebug | PPEManager - SetMaterialParamUpdating | Order higher than max, ignoring! | mat/par/ord: " + material_id + "/" + parameter_id + "/" + order);
156 return;
157 }
158
159 PPEClassBase mat_class = m_PPEClassMap.Get(material_id);
160
161 //DbgPrnt("PPEDebug | PPEManager - SetMaterialParamUpdating | mat/par: " + material_id + "/" + parameter_id);
162 //insert material into queue
163 if ( !m_PPEMaterialUpdateQueueMap.Contains(order) )
165
166 int found = m_PPEMaterialUpdateQueueMap.Get(order).Find(material_id);
167 if ( found == -1 )
168 {
169 m_PPEMaterialUpdateQueueMap.Get(order).Insert(material_id);
170 }
171
172 mat_class.SetParameterUpdating(order,parameter_id);
173 }
174
176 void RemoveMaterialUpdating(int material_id, int order = 0)
177 {
178 if ( m_PPEMaterialUpdateQueueMap.Contains(order) )
179 {
180 m_PPEMaterialUpdateQueueMap.Get(order).RemoveItem(material_id);
181
182 if ( m_PPEMaterialUpdateQueueMap.Get(order).Count() == 0)
183 m_PPEMaterialUpdateQueueMap.Remove(order);
184 }
185 }
186
187 protected void ClearMaterialUpdating()
188 {
190 }
191
193 void SetRequestActive(PPERequesterBase request, bool active)
194 {
195 int found = m_ExistingPostprocessRequests.Find(request);
196 if ( active && found == -1 )
197 {
198 m_ExistingPostprocessRequests.Insert(request);
199 }
200 else if ( !active && found > -1 ) //should always be found in this case, redundant?
201 {
202 //RemoveActiveRequestFromMaterials(request);
203
204 m_ExistingPostprocessRequests.Remove(found);
205 }
206 }
207
209 void SetRequestUpdating(PPERequesterBase request, bool active)
210 {
212 {
213 Debug.Log("PPEManager | SetRequestUpdating | !m_UpdatingRequests");
214 return;
215 }
216
217 int idx = m_UpdatingRequests.Find(request);
218
219 if ( active && idx == -1 )
220 {
221 m_UpdatingRequests.Insert(request);
222 }
223 else if ( !active && idx > -1 )
224 {
225 m_UpdatingRequests.Remove(idx);
226 }
227 }
228
229 // Just a getter
230 bool GetExistingRequester(typename req, out PPERequesterBase ret)
231 {
232 int idx = m_ExistingPostprocessRequests.Find(PPERequesterBank.GetRequester(req));
233 if (idx > -1)
234 {
235 ret = m_ExistingPostprocessRequests.Get(idx);
236 return true;
237 }
238 return false;
239 }
240
246 {
247 int count = req.GetActiveRequestStructure().Count();
248 int mat_id;
249 for (int i = 0; i < count; i++)
250 {
251 mat_id = req.GetActiveRequestStructure().GetKey(i);
252 PPEClassBase mat_class = m_PPEClassMap.Get(mat_id);
253 mat_class.RemoveRequest(req.GetRequesterIDX());
254 }
255 }
256
258 protected void RequestsCleanup()
259 {
260 }
261
263 void InsertUpdatedMaterial(int mat_id)
264 {
265 if ( m_UpdatedMaterials.Find(mat_id) == -1 )
266 m_UpdatedMaterials.Insert(mat_id);
267 }
268
269 //---------//
270 //PROCESSING
271 //---------//
272 protected void ProcessRequesterUpdates(float timeslice)
273 {
275 for (int i = 0; i < m_UpdatingRequests.Count(); i++)
276 {
277 //DbgPrnt("PPEDebug | ProcessRequesterUpdates | m_UpdatingRequests[i]: " + m_UpdatingRequests[i]);
278 req = m_UpdatingRequests.Get(i);
279 if (req)
280 req.OnUpdate(timeslice);
281 }
282 }
283
284 protected void ProcessMaterialUpdates(float timeslice)
285 {
286 for (int i = 0; i < m_PPEMaterialUpdateQueueMap.Count(); i++) //orders (levels?)
287 {
288 //DbgPrnt("PPEDebug | ProcessMaterialUpdates | GetKey " + i + ": " + m_PPEMaterialUpdateQueueMap.GetKey(i));
289 //DbgPrnt("PPEDebug | ProcessMaterialUpdates | GetElement - count " + i + ": " + m_PPEMaterialUpdateQueueMap.GetElement(i).Count());
290
291 for (int j = 0; j < m_PPEMaterialUpdateQueueMap.GetElement(i).Count(); j++)
292 {
293 PPEClassBase mat_class = m_PPEClassMap.Get(m_PPEMaterialUpdateQueueMap.GetElement(i).Get(j));
294 mat_class.OnUpdate(timeslice,i);
295 }
296 }
297 }
298
300 {
301 int material_id;
302 for (int i = 0; i < m_UpdatedMaterials.Count(); i++)
303 {
304 material_id = m_UpdatedMaterials.Get(i);
305 PPEClassBase mat_class = m_PPEClassMap.Get(material_id);
306 mat_class.ApplyValueChanges();
307 }
308
309 m_UpdatedMaterials.Clear();
311 }
312
313 void Update(float timeslice)
314 {
316 return;
317
318 ProcessRequesterUpdates(timeslice);
319 ProcessMaterialUpdates(timeslice);
321 RequestsCleanup(); //unused
322 }
323
325 Param GetPostProcessDefaultValues(int material, int parameter)
326 {
327 PPEClassBase mat_class = m_PPEClassMap.Get(material);
328 return mat_class.GetParameterCommandData(parameter).GetDefaultValues();
329 }
330
332 Param GetPostProcessCurrentValues(int material, int parameter)
333 {
334 PPEClassBase mat_class = m_PPEClassMap.Get(material);
335 return mat_class.GetParameterCommandData(parameter).GetCurrentValues();
336 }
337
338 //TODO - certain C++ events may change the actual material path with a graphics option changes. Reflect this on script-side!
339 //Currently only SSAY/HBAO affected...welp.
341 void ChangePPEMaterial(PostProcessPrioritiesCamera priority, PostProcessEffectType type, string path, bool scriptside_only)
342 {
343 if (m_PPEClassMap.Contains(type))
344 {
345 PPEClassBase mat_class = m_PPEClassMap.Get(type);
346 typename name = mat_class.Type();
347 PPEClassBase postprocess_capsule = PPEClassBase.Cast(name.Spawn());
348 postprocess_capsule.ChangeMaterialPathUsed(path);
349
350 if (postprocess_capsule.GetMaterial() == 0x0)
351 {
352 Debug.Log("PPEManager | Invalid material path " + path + " used for " + name );
353 return;
354 }
355
356 //m_PPEClassMap.Remove(type);
357 m_PPEClassMap.Set(type,postprocess_capsule);
358 }
359
360 //can be sent script-side only to adapt to c++ options changes
361 if (!scriptside_only)
363 }
364
366 void StopAllEffects(int mask = 0)
367 {
369 {
371 {
372 if (requester.GetCategoryMask() & mask)
373 {
374 requester.Stop();
375 }
376 }
377 }
378 }
379
380 void DbgPrnt(string text)
381 {
382 //Debug.Log(""+text);
383 }
384};
PostProcessPrioritiesCamera
PPE type priorities, C++ based. DO NOT CHANGE ORDER! Used only when calling 'SetCameraPostProcessEffe...
Definition PPEConstants.c:3
void DbgPrnt(string text)
Definition PPEManager.c:380
protected void InitPPEManagerClassMap()
Ordered by 'PostProcessEffectType' for easy access through the same enum; ID saved all the same.
Definition PPEManager.c:101
protected ref map< int, ref PPEClassBase > m_PPEClassMap
Definition PPEManager.c:58
void PPEManager()
Definition PPEManager.c:64
protected void RegisterPPEClass(PPEClassBase material_class)
Registeres material class and creates data structure within.
Definition PPEManager.c:137
void SetRequestActive(PPERequesterBase request, bool active)
Marks requester as 'active'. Currently indistinguiishable from 'updating' requester,...
Definition PPEManager.c:193
void InsertUpdatedMaterial(int mat_id)
Marks material class as updated and values to be set in the course of update - 'ProcessApplyValueChan...
Definition PPEManager.c:263
protected ref array< ref PPERequesterBase > m_UpdatingRequests
Definition PPEManager.c:62
class PPEManagerStatic CAMERA_ID
protected void ClearMaterialUpdating()
Definition PPEManager.c:187
protected void RequestsCleanup()
Unused cleanup method, should it be ever needed.
Definition PPEManager.c:258
protected void ProcessMaterialUpdates(float timeslice)
Definition PPEManager.c:284
protected ref array< ref PPERequesterBase > m_ExistingPostprocessRequests
Definition PPEManager.c:61
Param GetPostProcessDefaultValues(int material, int parameter)
Returns default values as Param. See 'PPEConstants' file for various typedefs used.
Definition PPEManager.c:325
void ChangePPEMaterial(PostProcessPrioritiesCamera priority, PostProcessEffectType type, string path, bool scriptside_only)
Changes material file associated with the script material class. Will be used very rarely,...
Definition PPEManager.c:341
void SetMaterialParamUpdating(int material_id, int parameter_id, int order)
Queues material/parameter to update (once)
Definition PPEManager.c:151
void SendMaterialValueData(PPERequestParamDataBase data)
Definition PPEManager.c:142
protected ref map< int, ref array< int > > m_PPEMaterialUpdateQueueMap
Definition PPEManager.c:59
protected void RemoveActiveRequestFromMaterials(PPERequesterBase req)
Definition PPEManager.c:245
void RemoveMaterialUpdating(int material_id, int order=0)
Currently unused, requests remain in the hierarchy and are used when needed (slightly faster than con...
Definition PPEManager.c:176
void SetRequestUpdating(PPERequesterBase request, bool active)
Marks requester as 'updating' and to be processed on manager update.
Definition PPEManager.c:209
bool GetExistingRequester(typename req, out PPERequesterBase ret)
Definition PPEManager.c:230
Param GetPostProcessCurrentValues(int material, int parameter)
Returns current values as Param. See 'PPEConstants' file for various typedefs used.
Definition PPEManager.c:332
protected ref array< int > m_UpdatedMaterials
Definition PPEManager.c:60
protected bool m_ManagerInitialized
Definition PPEManager.c:57
protected void ProcessApplyValueChanges()
Definition PPEManager.c:299
protected void ProcessRequesterUpdates(float timeslice)
Definition PPEManager.c:272
string name
override ScriptInvoker GetUpdateQueue(int call_category)
Definition DayZGame.c:1158
Definition Debug.c:14
static void Log(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message with normal prio.
Definition Debug.c:133
TODO doc.
Definition EnScript.c:118
static void Init()
static void Cleanup()
ChromAber - PostProcessEffectType.ChromAber.
Definition PPEChromAber.c:3
Created once, on manager init. Script-side representation of C++ material class, separate handling.
Material GetMaterial()
int GetPostProcessEffectID()
Overriden in all material classes!
void InsertParamValueData(PPERequestParamDataBase request_data)
Distributes requester data to the material class structure and links them to appropriate parameter.
void SetParameterUpdating(int order, int parameter_id)
Queue specific parameter of this material to update.
void ChangeMaterialPathUsed(string path)
PPEMatClassParameterCommandData GetParameterCommandData(int parameter_idx)
Some PP effects are handled as hard-coded exceptions, outside of material system. Default == PPEExcep...
void RemoveRequest(int req_idx)
unused, see 'RemoveActiveRequestFromMaterials' for more info
void OnUpdate(float timeslice, int order)
generic update method, take care when overriding!
ColorGrading - PostProcessEffectType.ColorGrading.
Colors - PostProcessEffectType.Colors.
Definition PPEColors.c:4
DOF postprocess, does not directly use materials.
Definition PPEDOF.c:6
DepthOfField - PostProcessEffectType.DepthOfField.
DynamicBlur - PostProcessEffectType.DynamicBlur.
EV postprocess, does not directly use materials.
Eye Accomodation postprocess, does not directly use materials.
FXAA - PostProcessEffectType.FXAA.
Definition PPEFXAA.c:3
FilmGrain - PostProcessEffectType.FilmGrain.
Definition PPEFilmGrain.c:7
GaussFilter - PostProcessEffectType.GaussFilter.
Glow - PostProcessEffectType.Glow.
Definition PPEGlow.c:8
GodRays - PostProcessEffectType.GodRays.
Definition PPEGodRays.c:3
HBAO - PostProcessEffectType.HBAO.
Definition PPEHBAO.c:4
g_Game.NightVissionLightParams, does not directly use materials. Controls light multiplication and fi...
Static component of PPE manager, used to hold the instance.
Definition PPEManager.c:3
static PPEManager GetPPEManager()
Returns the manager instance singleton.
Definition PPEManager.c:27
static ref PPEManager m_Manager
Definition PPEManager.c:4
static void CreateManagerStatic()
Definition PPEManager.c:6
static void DestroyManagerStatic()
Definition PPEManager.c:17
Param GetCurrentValues()
Careful, only actual values, WITHOUT string.
Param GetDefaultValues()
Careful, formating is such, that param1 is ALWAYS string, containing parameter name,...
Median - PostProcessEffectType.Median.
Definition PPEMedian.c:4
Dummy class - PostProcessEffectType.None.
Definition PPENone.c:3
RadialBlur - PostProcessEffectType.RadialBlur.
Rain - PostProcessEffectType.Rain.
Definition PPERain.c:3
Data for one material parameter, requester side.
map< int, ref map< int, ref PPERequestParamDataBase > > GetActiveRequestStructure()
void OnUpdate(float delta)
int GetRequesterIDX()
Returns requester index.
Rotation Blur.
Definition PPERotBlur.c:3
SMAA - PostProcessEffectType.SMAA.
Definition PPESMAA.c:3
SSAO - PostProcessEffectType.SSAO.
Definition PPESSAO.c:3
SunMask - PostProcessEffectType.SunMask.
Definition PPESunMask.c:4
UnderWater - PostProcessEffectType.UnderWater.
WetDistort - PostProcessEffectType.WetDistort.
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition param.c:12
proto bool Insert(func fn, int flags=EScriptInvokerInsertFlags.IMMEDIATE)
insert method to list
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
PostProcessEffectType
Post-process effect type.
Definition EnWorld.c:72
proto native void SetCameraPostProcessEffect(int cam, int priority, PostProcessEffectType type, string materialPath)
const int CALL_CATEGORY_GUI
Definition tools.c:9
proto native volatile void Update()