Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
ppematclassesbase.c
Go to the documentation of this file.
1 class PPEClassBase
3 {
4  protected PPEManager m_Manager;
5  protected string m_MaterialPath = "";
6  protected Material m_Material;
7 
8  protected ref map<int, ref array<int>> m_ParameterUpdateQueueMap;
9  protected ref array<int> m_ParameterRemovalQueue;
10  protected ref array<int> m_UpdatedParameters;
11 
12  protected ref map<int,ref PPEMatClassParameterCommandData> m_MaterialParamMapStructure; //<param_idx, <ParamData>>
13 
14  void PPEClassBase(string mat_path_override = "")
15  {
16  Init(mat_path_override);
17  CreateMaterial();
18  CreateDataStructure();
19  RegisterMaterialParameters();
20  }
21 
22  protected void Init(string mat_path_override = "")
23  {
24  if (mat_path_override != "")
25  {
26  m_MaterialPath = mat_path_override;
27  }
28  else
29  {
30  m_MaterialPath = GetDefaultMaterialPath();
31  }
32  m_Manager = PPEManagerStatic.GetPPEManager();
33  }
34 
35  protected void CreateMaterial()
36  {
37  if (m_MaterialPath != "")
38  m_Material = GetGame().GetWorld().GetMaterial(m_MaterialPath);
39  }
40 
41  Material GetMaterial()
42  {
43  return m_Material;
44  }
45 
46  //do not override!
47  protected void CreateDataStructure()
48  {
49  m_MaterialParamMapStructure = new map<int,ref PPEMatClassParameterCommandData>;
50  //m_ParameterUpdateQueue = new array<int>;
51  m_ParameterUpdateQueueMap = new map<int, ref array<int>>;
52  m_ParameterRemovalQueue = new array<int>;
53  m_UpdatedParameters = new array<int>;
54  }
55 
57  protected void RegisterMaterialParameters();
58 
59  protected void RegisterParameterScalarBool(int idx, string parameter_name, bool default_value)
60  {
61  PPETemplateDefBool p = new PPETemplateDefBool(parameter_name,default_value);
62  PPEMatClassParameterBool parameter_data = new PPEMatClassParameterBool(GetPostProcessEffectID(),idx,this);
63  parameter_data.RegisterDefaults(p);
64  m_MaterialParamMapStructure.Set(idx, parameter_data);
65  }
66 
67  protected void RegisterParameterScalarInt(int idx, string parameter_name, int default_value, int min, int max)
68  {
69  PPETemplateDefInt p = new PPETemplateDefInt(parameter_name,default_value,min,max);
70 
71  PPEMatClassParameterInt parameter_data = new PPEMatClassParameterInt(GetPostProcessEffectID(),idx,this);
72  parameter_data.RegisterDefaults(p);
73  m_MaterialParamMapStructure.Set(idx, parameter_data);
74  }
75 
77  protected void RegisterParameterScalarFloat(int idx, string parameter_name, float default_value, float min, float max)
78  {
79  PPETemplateDefFloat p = new PPETemplateDefFloat(parameter_name,default_value,min,max);
80 
81  PPEMatClassParameterFloat parameter_data = new PPEMatClassParameterFloat(GetPostProcessEffectID(),idx,this);
82  parameter_data.RegisterDefaults(p);
83  m_MaterialParamMapStructure.Set(idx, parameter_data);
84  }
85 
87  protected void RegisterParameterScalarFloatEx(int idx, string parameter_name, float default_value, float min, float max, typename type)
88  {
89  PPETemplateDefFloat p = new PPETemplateDefFloat(parameter_name,default_value,min,max);
90 
91  PPEMatClassParameterFloat parameter_data;
92  bool boo = Class.CastTo(parameter_data,type.Spawn());
93  //Print("RegisterParameterColorEx: " + boo );
94  parameter_data.RegisterDefaults(p);
95  parameter_data.SetMaterialIndex(GetPostProcessEffectID());
96  parameter_data.SetParameterIndex(idx);
97  parameter_data.SetParent(this);
98  m_MaterialParamMapStructure.Set(idx, parameter_data);
99  }
100 
102  protected void RegisterParameterColor(int idx, string parameter_name, float r, float g, float b, float a)
103  {
104  PPETemplateDefColor p = new PPETemplateDefColor(parameter_name,r,g,b,a);
105  PPEMatClassParameterColor parameter_data = new PPEMatClassParameterColor(GetPostProcessEffectID(),idx,this);
106  parameter_data.RegisterDefaults(p);
107  m_MaterialParamMapStructure.Set(idx, parameter_data);
108  }
109 
111  protected void RegisterParameterColorEx(int idx, string parameter_name, float r, float g, float b, float a, typename type)
112  {
113  PPETemplateDefColor p = new PPETemplateDefColor(parameter_name,r,g,b,a);
114  PPEMatClassParameterColor parameter_data;
115  bool boo = Class.CastTo(parameter_data,type.Spawn());
116  //Print("RegisterParameterColorEx: " + boo );
117  parameter_data.RegisterDefaults(p);
118  parameter_data.SetMaterialIndex(GetPostProcessEffectID());
119  parameter_data.SetParameterIndex(idx);
120  parameter_data.SetParent(this);
121  m_MaterialParamMapStructure.Set(idx, parameter_data);
122  }
123 
124  protected void RegisterParameterVector(int idx, string parameter_name, array<float> default_values) //needs to be compatible with every type of vector (vector2 to vector4), hence array<float>...
125  {
126  PPETemplateDefVector p = new PPETemplateDefVector(parameter_name,default_values);
127  PPEMatClassParameterVector parameter_data = new PPEMatClassParameterVector(GetPostProcessEffectID(),idx,this);
128  parameter_data.RegisterDefaults(p);
129  m_MaterialParamMapStructure.Set(idx, parameter_data);
130  }
131 
132  //TEXTURE and RESOURCE types are not overridable during runtime..currently unused and unhandled
133  protected void RegisterParameterTexture(int idx, string parameter_name, string default_path)
134  {
135  PPETemplateDefTexture p = new PPETemplateDefTexture(parameter_name,default_path);
136  PPEMatClassParameterTexture parameter_data = new PPEMatClassParameterTexture(GetPostProcessEffectID(),idx,this);
137  parameter_data.RegisterDefaults(p);
138  m_MaterialParamMapStructure.Set(idx, parameter_data);
139  }
140 
141  protected void RegisterParameterResource(int idx, string parameter_name, string default_path)
142  {
143  PPETemplateDefResource p = new PPETemplateDefResource(parameter_name,default_path);
144  PPEMatClassParameterResource parameter_data = new PPEMatClassParameterResource(GetPostProcessEffectID(),idx,this);
145  parameter_data.RegisterDefaults(p);
146  m_MaterialParamMapStructure.Set(idx, parameter_data);
147  }
148 
149  //------------------------------------------------------------------------------------
151  void InsertParamValueData(PPERequestParamDataBase request_data)
152  {
154  bool exists = m_MaterialParamMapStructure.Find(request_data.GetParameterID(),param_data);
155  if ( !exists )
156  {
157  Error("PPEClassBase | InsertParamValueData | mat/par/req: " + GetPostProcessEffectID() + "/" + request_data.GetParameterID() + "/" + request_data.GetRequesterIDX() + " not registered in m_MaterialParamMapStructure!");
158  return;
159  }
160 
161  request_data.SetDataActive(true);
162  request_data.SetUpdatingDataValues(true); //marks request data as updating
163  param_data.InsertRequestData(request_data);//<request_ID, data>
164 
165  //DbgPrnt("PPEDebug | InsertParamValueData | mat/par/req: " + GetPostProcessEffectID() + "/" + request_data.GetParameterID() + "/" + request_data.GetRequesterIDX() + " | requester: " + request_data.m_Requester);
166  }
167 
168  //TODO - rework
170  void RemoveRequest(int req_idx)
171  {
172  /*for (int i = 0; i < m_ActiveMaterialRequestMap.Count(); i++)
173  {
174  ActiveParameterRequestsMap dbg = m_ActiveMaterialRequestMap.Get(i);
175  //DbgPrnt("PPEDebug | dbg size: " + dbg.Count());
176 
177  if ( m_ActiveMaterialRequestMap.Get(i).Contains(req_idx) )
178  {
179  m_ActiveMaterialRequestMap.Get(i).Remove(req_idx);
180 
181  dbg = m_ActiveMaterialRequestMap.Get(i);
182 
183  if ( !m_ActiveMaterialRequestMap.Get(i) || m_ActiveMaterialRequestMap.Get(i).Count() < 1 )
184  {
185  if (m_ParameterUpdateQueue.IsValidIndex(i))
186  {
187  DbgPrnt("PPEDebug | PPEClassBase - RemoveRequest | Removing: " + i);
188  DbgPrnt("PPEDebug | PPEClassBase - RemoveRequest | exit 4 - last request removal");
189  m_ParameterRemovalQueue.Insert(m_ParameterUpdateQueue.Get(i));
190  }
191  else
192  DbgPrnt("PPEDebug | PPEClassBase - RemoveRequest | Update queue no. " + i + " already removed!");
193  }
194  }
195  //Adds to update one more time
196  m_Manager.SetMaterialParamUpdating(GetPostProcessEffectID(),i);
197  }*/
198  }
199 
201  void OnUpdate(float timeslice, int order)
202  {
203  int parameter_idx = -1;
204  //DbgPrnt("PPEDebug | PPEClassBase - OnUpdate | mat_id: " + GetPostProcessEffectID());
205 
206  if ( m_ParameterUpdateQueueMap.Contains(order) )
207  {
208  //Print(m_ParameterUpdateQueueMap.Get(order));
209  for ( int i = 0; i < m_ParameterUpdateQueueMap.Get(order).Count(); i++ )
210  {
211  //DbgPrnt("PPEDebug | PPEClassBase - OnUpdate | parameter_idx: " + m_ParameterUpdateQueue.Get(i));
212  Param p_values; //TODO - move to material classes?
213  bool setting_defaults = false;
214  parameter_idx = m_ParameterUpdateQueueMap.Get(order).Get(i);
215  m_MaterialParamMapStructure.Get(parameter_idx).Update(timeslice,p_values,setting_defaults,order);
216 
217  InsertUpdatedParameter(parameter_idx);
218  }
219  m_Manager.InsertUpdatedMaterial(GetPostProcessEffectID());
220 
221  ParamUpdateQueueCleanup(order);
222  }
223  /*if ( !m_ParameterUpdateQueueMap.Contains(order) || m_ParameterUpdateQueueMap.Get(order).Count() < 1 )
224  m_Manager.RemoveMaterialUpdating(GetPostProcessEffectID(),order); //stops material from updating when no parameters are.*/
225  }
226 
228  void SetFinalParameterValue(int parameter_idx)
229  {
230  int var_type = GetParameterCommandData(parameter_idx).GetParameterVarType();
231  Param values = GetParameterCommandData(parameter_idx).GetCurrentValues();
232 
233  switch (var_type)
234  {
235  case PPEConstants.VAR_TYPE_BOOL:
236  bool value_var_bool = Param1<bool>.Cast(values).param1;
237 
238  m_Material.SetParamByIndex(parameter_idx,value_var_bool);
239  //Print("DebugValues | PPEConstants.VAR_TYPE_BOOL | bool val: " + value_var_bool);
240  break;
241 
242  case PPEConstants.VAR_TYPE_INT:
243  int value_var_int = Param1<int>.Cast(values).param1;
244 
245  m_Material.SetParamByIndex(parameter_idx,value_var_int);
246  //Print("DebugValues | PPEConstants.VAR_TYPE_BOOL | bool val: " + value_var_bool);
247  break;
248 
249  case PPEConstants.VAR_TYPE_FLOAT:
250  float value_var_float = Param1<float>.Cast(values).param1;
251 
252  m_Material.SetParamByIndex(parameter_idx,value_var_float);
253  //Print("DebugValues | PPEConstants.VAR_TYPE_FLOAT | float val: " + value_var_float);
254  break;
255 
256  case PPEConstants.VAR_TYPE_COLOR:
257  float color[4] = {0,0,0,0};
258  color[0] = Param4<float,float,float,float>.Cast(values).param1;
259  color[1] = Param4<float,float,float,float>.Cast(values).param2;
260  color[2] = Param4<float,float,float,float>.Cast(values).param3;
261  color[3] = Param4<float,float,float,float>.Cast(values).param4;
262 
263  m_Material.SetParamByIndex(parameter_idx,color);
264  //Print("DebugValues | PPEConstants.VAR_TYPE_COLOR | color val:: " + color[0] + " " + color[1] + " " + color[2] + " " + color[3]);
265  break;
266  }
267  }
268 
269  void ApplyValueChanges()
270  {
271  int parameter_id;
272  for (int i = 0; i < m_UpdatedParameters.Count(); i++)
273  {
274  parameter_id = m_UpdatedParameters.Get(i);
275  SetFinalParameterValue(parameter_id);
276  }
277 
278  m_UpdatedParameters.Clear();
279  }
280 
281  protected void InsertUpdatedParameter(int mat_id)
282  {
283  if ( m_UpdatedParameters.Find(mat_id) == -1 )
284  m_UpdatedParameters.Insert(mat_id);
285  }
286 
288  void ParamUpdateRemove(int parameter_idx)
289  {
290  if ( m_ParameterRemovalQueue.Find(parameter_idx) == -1 )
291  m_ParameterRemovalQueue.Insert(parameter_idx);
292  }
293 
295  void SetParameterUpdating(int order, int parameter_id)
296  {
297  if ( !m_ParameterUpdateQueueMap.Contains(order) )
298  {
299  m_ParameterUpdateQueueMap.Set(order,new array<int>);
300  }
301 
302  if ( m_ParameterUpdateQueueMap.Get(order).Find(parameter_id) == -1 )
303  {
304  m_ParameterUpdateQueueMap.Get(order).Insert(parameter_id);
305  }
306  }
307 
308  protected void ParamUpdateQueueCleanup(int order)
309  {
310  //DbgPrnt("PPEDebug | PPEClassBase - ParamUpdateQueueCleanup | mat_id: " + GetPostProcessEffectID() + " | UpdateQueue count: " + m_ParameterUpdateQueue.Count());
311  //DbgPrnt("PPEDebug | PPEClassBase - ParamUpdateQueueCleanup | mat_id: " + GetPostProcessEffectID() + " | RemovalQueue count: " + m_ParameterRemovalQueue.Count());
312  for ( int i = 0; i < m_ParameterUpdateQueueMap.Get(order).Count(); i++ )
313  {
314  if ( m_ParameterRemovalQueue.Find(m_ParameterUpdateQueueMap.Get(order).Get(i)) != -1 )
315  {
316  //DbgPrnt("PPEDebug | PPEClassBase - ParamUpdateQueueCleanup | removing update of: " + m_ParameterUpdateQueue.Get(i));
317  //m_ParameterUpdateQueue.RemoveItem(m_ParameterUpdateQueue.Get(i));
318  }
319  }
320  m_ParameterUpdateQueueMap.Get(order).Clear();
321  }
322 
324  string GetDefaultMaterialPath();
325 
326  void ChangeMaterialPathUsed(string path)
327  {
328  m_MaterialPath = path;
329  m_Material = null;
330  CreateMaterial();
331  }
332 
333  string GetCurrentMaterialPath()
334  {
335  return m_MaterialPath;
336  }
337 
339  int GetPostProcessEffectID()
340  {
341  return PostProcessEffectType.None;
342  }
343 
345  /*int GetExceptionID()
346  {
347  return PPEExceptions.NONE;
348  }*/
349 
350  PPEMatClassParameterCommandData GetParameterCommandData(int parameter_idx)
351  {
352  return m_MaterialParamMapStructure.Get(parameter_idx);
353  }
354 
355 #ifdef DEVELOPER
356  //Debug//
357  //-----//
358  /*void DumpMap()
359  {
360  DbgPrnt("PPEClassDebug | m_ActiveMaterialRequestMap COUNT: " + m_ActiveMaterialRequestMap.Count());
361  for (int i = 0; i < m_ActiveMaterialRequestMap.Count(); i++)
362  {
363  DbgPrnt("PPEClassDebug | m_ActiveRequest#: " + i);
364  //ActiveMaterialRequests request = m_ActiveMaterialRequestMap.Get(i);
365  DbgPrnt("PPEClassDebug | request: " + request);
366  for (int j = 0; j < request.Count(); j++)
367  {
368  DbgPrnt("PPEClassDebug | request#: " + j);
369  array<bool,float,int,int> values = request.Get(j);
370  foreach (auto val : values)
371  {
372  DbgPrnt("PPEClassDebug | relative: " + val);
373  }
374  }
375  }
376  DbgPrnt("------------");
377  }*/
378 #endif
379 
380  void DbgPrnt(string text)
381  {
382  //Debug.Log(""+text);
383  }
384 };
Param2
Definition: ppeconstants.c:66
PostProcessEffectType
PostProcessEffectType
Post-process effect type.
Definition: enworld.c:71
GetGame
proto native CGame GetGame()
PPETemplateDefVector
Param2< string, ref array< float > > PPETemplateDefVector
Definition: ppeconstants.c:89
PPETemplateDefResource
Param2< string, string > PPETemplateDefResource
Definition: ppeconstants.c:91
PPEClassBase
Created once, on manager init. Script-side representation of C++ material class, separate handling.
Definition: ppematclassesbase.c:2
Error
void Error(string err)
Messagebox with error message.
Definition: endebug.c:90
Param
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition: param.c:11
m_Manager
ModifiersManager m_Manager
Definition: modifierbase.c:12
PPETemplateDefColor
Param5< string, float, float, float, float > PPETemplateDefColor
Definition: ppeconstants.c:87
PPEMatClassParameterCommandData
Definition: ppematclassparameterbool.c:1
PPETemplateDefBool
Param2 PPETemplateDefBool
PPEManager
void PPEManager()
Definition: ppemanager.c:64
PPETemplateDefInt
Param4< string, int, int, int > PPETemplateDefInt
Definition: ppeconstants.c:85
PPEManagerStatic
Static component of PPE manager, used to hold the instance.
Definition: ppemanager.c:2
PPETemplateDefTexture
Param2< string, string > PPETemplateDefTexture
Definition: ppeconstants.c:90
map
map
Definition: controlsxboxnew.c:3
PPEMatClassParameterColor
Definition: ppematclassparametercolor.c:317
Material
Definition: proto.c:267
PPERequestParamDataBase
Data for one material parameter, requester side.
Definition: pperequestdata.c:2
PPEMatClassParameterFloat
void PPEMatClassParameterFloat(int mat_idx, int parameter_idx, PPEClassBase parent)
Definition: ppematclassparameterfloat.c:9
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
PPEMatClassParameterColor
void PPEMatClassParameterColor(int mat_idx, int parameter_idx, PPEClassBase parent)
Definition: ppematclassparametercolor.c:48
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
Count
@ Count
Definition: randomgeneratorsyncmanager.c:7
path
string path
Definition: optionselectormultistate.c:135
PPETemplateDefFloat
Param4< string, float, float, float > PPETemplateDefFloat
Definition: ppeconstants.c:86