Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
ppematclassparametercolor.c
Go to the documentation of this file.
1 
3 {
4  protected ref array<float> m_Values;
5  protected int m_Operator;
6 
7  void ColorValuesData(ref array<float> values, int operator)
8  {
10  m_Values.Copy(values);
11  m_Operator = operator;
12  }
13 
14  void SetValues(ref array<float> values)
15  {
16  m_Values.Copy(values);
17  }
18 
19  array<float> GetValues()
20  {
21  return m_Values;
22  }
23 
24  void SetOperator(int operator)
25  {
26  m_Operator = operator;
27  }
28 
29  int GetOperator()
30  {
31  return m_Operator;
32  }
33 }
34 
36 {
37  const int VALUE_RED = 0;
38  const int VALUE_GREEN = 1;
39  const int VALUE_BLUE = 2;
40  const int VALUE_ALPHA = 3;
41  const int VALUES_COUNT = 4; //rgba
42 
44  protected ref map<int,ref ColorValuesData> m_LayerInfo; //<priority,<<values>,operator>>
45 
46  float m_ColorDefaults[4];
47 
48  void PPEMatClassParameterColor(int mat_idx, int parameter_idx, PPEClassBase parent)
49  {
51  }
52 
53  override void InitDefaults()
54  {
55  m_Color = PPETemplateDefColor.Cast(m_Defaults);
56  m_ColorDefaults = {m_Color.param2,m_Color.param3,m_Color.param4,m_Color.param5};
57  }
58 
59  override void InitCuttent()
60  {
61  m_CurrentValues = new Param4<float,float,float,float>(m_ColorDefaults[0],m_ColorDefaults[1],m_ColorDefaults[2],m_ColorDefaults[3]);
62  }
63 
64  override int GetParameterVarType()
65  {
66  return PPEConstants.VAR_TYPE_COLOR;
67  }
68 
69  override void Update(float timeslice, out Param p_total, out bool setting_defaults, int order)
70  {
71  super.Update(timeslice,p_total,setting_defaults,order);
72 
73  int active_request_count = 0;
74 
75  PPERequestParamDataColor req_data;
76 
77  bool setting_value_zero = false;
78 
79  array<float> color_values_total = {0.0,0.0,0.0,0.0};
80  array<float> color_values_temp = {0.0,0.0,0.0,0.0};
81  bool color_total_override_set = false;
82 
83  // param creation
84  if (p_total == null)
85  {
86  p_total = new Param4<float,float,float,float>(0.0,0.0,0.0,0.0);
87  }
88 
89  if (m_RequestMap.Count() > 0)
90  {
91  m_LayerInfo.Clear();
92  }
93  else
94  {
95  //DbgPrnt("m_RequestMap.Count() is zero! Using default values. | mat/par: " + m_MaterialIndex + "/" + m_ParameterIndex);
96  SetParameterValueDefault(p_total); //TODO - redundant?
97  m_Parent.ParamUpdateRemove(m_ParameterIndex);
98  return;
99  }
100 
101  //get target values, evaluate active and priority conditions, and insert into arrays to later process
102  for ( int i = 0; i < m_RequestMap.Count(); i++ )
103  {
104  req_data = PPERequestParamDataColor.Cast(m_RequestMap.GetElement(i));
105 
106  if (req_data == null)
107  {
108  Error("PPEMatClassParameterColor | req_data not found! | " + this + " | mat/par: " + m_MaterialIndex + "/" + m_ParameterIndex);
109  continue;
110  }
111 
112  setting_value_zero = req_data.IsSettingDefaultValues();
113 
114  //skips "zero value" defaults
115  if (setting_value_zero && !req_data.GetUpdatingDataValues() && !req_data.IsDataActive())
116  {
117  //DbgPrnt("Is Default, not updating | idx: " + i + " | mat/par/req: " + m_MaterialIndex + "/" + m_ParameterIndex + "/" + req_data.GetRequesterIDX());
118  continue;
119  }
120 
121  active_request_count++; //something is active, though not necessarily setting new values
122 
123  //evaluation
124  //--------------------------------
125  req_data.m_ColorLast = req_data.m_ColorCurrent;
126 
127  if (!req_data.GetUpdatingDataValues() && req_data.IsDataActive()) //set to exact value, not updating anymore
128  {
129  color_values_temp.Copy(req_data.m_ColorCurrent); //already converted from before?
130  PrepareLayerInfo(req_data.GetPriorityLayer(),{color_values_temp[0],color_values_temp[1],color_values_temp[2],color_values_temp[3]},req_data.GetInteractionMask());
131  //DbgPrnt("PPEDebug | PPEMatClassParameterColor - UpdateParameterValues | !req_data.m_UpdatingData | mat/par/req: " + m_MaterialIndex + "/" + m_ParameterIndex + "/" + req_data.GetRequesterIDX() + " | not updating, addaing current values into mix: " + req_data.m_ColorCurrent[0] + "," + req_data.m_ColorCurrent[1] + "," + req_data.m_ColorCurrent[2] + "," + req_data.m_ColorCurrent[3]);
132  continue;
133  }
134 
135  if (setting_value_zero)
136  {
137  req_data.m_ColorTarget = {0.0,0.0,0.0,0.0}; //color_defaults;
138  //DbgPrnt("PPEDebug | PPEMatClassParameterColor - UpdateParameterValues | !data.m_DefaultTargetSet | mat/par/req: " + m_MaterialIndex + "/" + m_ParameterIndex + "/" + req_data.GetRequesterIDX() + " | req_data.m_FloatTarget: " + req_data.m_FloatTarget);
139  }
140 
141  //DbgPrnt("PPEDebug | PPEMatClassParameterColor - UpdateParameterValues | mat/par/req: " + m_MaterialIndex + "/" + m_ParameterIndex + "/" + req_data.GetRequesterIDX());
142  req_data.SetUpdatingDataValues(false);
143  if (setting_value_zero)
144  {
145  req_data.SetDataActive(false);
146  //RemovePriorityInfo(req_data.GetPriorityLayer()); //redundant?
147  }
148  else
149  {
150  color_values_temp.Copy(req_data.m_ColorTarget);
151  PrepareLayerInfo(req_data.GetPriorityLayer(),{color_values_temp[0],color_values_temp[1],color_values_temp[2],color_values_temp[3]},req_data.GetInteractionMask());
152  }
153 
154  req_data.m_ColorCurrent.Copy(color_values_temp);
155  //DbgPrnt("PPEDebug | PPEMatClassParameterColor - UpdateParameterValues | current: " + req_data.m_ColorCurrent);
156  }
157 
158  //---------------------------
159  //MASK handling and calculation
160  array<float> values;
161  int operator = -1;
162  bool override_active = false;
163 
164  color_values_total = {m_ColorDefaults[0],m_ColorDefaults[1],m_ColorDefaults[2],m_ColorDefaults[3]};
165 
166  for ( i = 0; i < m_LayerInfo.Count(); i++ )
167  {
168  if ( override_active )
169  break;
170 
171  values = m_LayerInfo.Get(m_CommandLayersArray.Get(i)).GetValues();
172  operator = m_LayerInfo.Get(m_CommandLayersArray.Get(i)).GetOperator();
173 
174  switch (operator)
175  {
176  case PPOperators.LOWEST:
177  color_values_total[VALUE_RED] = Math.Min(color_values_total[VALUE_RED], values[VALUE_RED]);
178  color_values_total[VALUE_GREEN] = Math.Min(color_values_total[VALUE_GREEN], values[VALUE_GREEN]);
179  color_values_total[VALUE_BLUE] = Math.Min(color_values_total[VALUE_BLUE], values[VALUE_BLUE]);
180  color_values_total[VALUE_ALPHA] = Math.Min(color_values_total[VALUE_ALPHA], values[VALUE_ALPHA]);
181  break;
182 
183  case PPOperators.HIGHEST:
184  color_values_total[VALUE_RED] = Math.Max(color_values_total[VALUE_RED], values[VALUE_RED]);
185  color_values_total[VALUE_GREEN] = Math.Max(color_values_total[VALUE_GREEN], values[VALUE_GREEN]);
186  color_values_total[VALUE_BLUE] = Math.Max(color_values_total[VALUE_BLUE], values[VALUE_BLUE]);
187  color_values_total[VALUE_ALPHA] = Math.Max(color_values_total[VALUE_ALPHA], values[VALUE_ALPHA]);
188  break;
189 
190  case PPOperators.ADD_RELATIVE:
191  case PPOperators.ADD:
192  color_values_total[VALUE_RED] = color_values_total[VALUE_RED] + values[VALUE_RED];
193  color_values_total[VALUE_GREEN] = color_values_total[VALUE_GREEN] + values[VALUE_GREEN];
194  color_values_total[VALUE_BLUE] = color_values_total[VALUE_BLUE] + values[VALUE_BLUE];
195  color_values_total[VALUE_ALPHA] = color_values_total[VALUE_ALPHA] + values[VALUE_ALPHA];
196  break;
197 
198  /*case PPOperators.ADD_RELATIVE: //no known max values, unusable!
199  float_value_total = (1 - float_value_total) * value + float_value_total;
200  break;*/
201 
202  case PPOperators.SUBSTRACT_RELATIVE:
203  case PPOperators.SUBSTRACT:
204  color_values_total[VALUE_RED] = color_values_total[VALUE_RED] - values[VALUE_RED];
205  color_values_total[VALUE_GREEN] = color_values_total[VALUE_GREEN] - values[VALUE_GREEN];
206  color_values_total[VALUE_BLUE] = color_values_total[VALUE_BLUE] - values[VALUE_BLUE];
207  color_values_total[VALUE_ALPHA] = color_values_total[VALUE_ALPHA] - values[VALUE_ALPHA];
208  break;
209 
210  /*case PPOperators.SUBSTRACT_RELATIVE: //no known max values, unusable!
211  float_value_total = float_value_total - value * float_value_total;
212  break;*/
213 
214  case PPOperators.SUBSTRACT_REVERSE_RELATIVE:
215  case PPOperators.SUBSTRACT_REVERSE:
216  color_values_total[VALUE_RED] = values[VALUE_RED] - color_values_total[VALUE_RED];
217  color_values_total[VALUE_GREEN] = values[VALUE_GREEN] - color_values_total[VALUE_GREEN];
218  color_values_total[VALUE_BLUE] = values[VALUE_BLUE] - color_values_total[VALUE_BLUE];
219  color_values_total[VALUE_ALPHA] = values[VALUE_ALPHA] - color_values_total[VALUE_ALPHA];
220  break;
221 
222  /*case PPOperators.SUBSTRACT_REVERSE_RELATIVE: //no known max values, unusable!
223  float_value_total = value * float_value_total - float_value_total;
224  break;*/
225 
226  case PPOperators.MULTIPLICATIVE:
227  color_values_total[VALUE_RED] = color_values_total[VALUE_RED] * values[VALUE_RED];
228  color_values_total[VALUE_GREEN] = color_values_total[VALUE_GREEN] * values[VALUE_GREEN];
229  color_values_total[VALUE_BLUE] = color_values_total[VALUE_BLUE] * values[VALUE_BLUE];
230  color_values_total[VALUE_ALPHA] = color_values_total[VALUE_ALPHA] * values[VALUE_ALPHA];
231  break;
232 
233  case PPOperators.OVERRIDE:
234  color_values_total.Copy(values);
235  break;
236 
237  case PPOperators.SET:
238  color_values_total.Copy(values);
239  break;
240  }
241 
242  //DbgPrnt("m_LayerInfo | color_values_total pre-clamp: " + color_values_total[VALUE_RED] + "/" + color_values_total[VALUE_GREEN] + "/" + color_values_total[VALUE_BLUE] + "/" + color_values_total[VALUE_ALPHA] + " | i: " + i);
243  if ( operator == PPOperators.OVERRIDE )
244  {
245  //DbgPrnt("m_LayerInfo | PPOperators.OVERRIDE at: " + i);
246  override_active = true;
247  }
248 
249  //RemovePriorityInfo(m_CommandLayersArray.Get(i));
250  }
251 
252  m_CommandLayersArray.Clear();
253 
254  if ( m_MaterialIndex == 15 && m_ParameterIndex == 21 )
255  {
256  //Print("m_MaterialIndex: " + m_MaterialIndex + "|m_ParameterIndex: " + m_ParameterIndex);
257  //Print("PPEMatClassParameterColor values: " + color_values_total[0] + " " + color_values_total[1] + " " + color_values_total[2] + " " + color_values_total[3]);
258  }
259 
260  //TODO - consider moving this up, if possible
261  if ( active_request_count <= 0 )
262  {
263  SetParameterValueDefault(p_total);
264  }
265  else
266  {
267  Param4<float,float,float,float>.Cast(p_total).param1 = color_values_total[0];
268  Param4<float,float,float,float>.Cast(p_total).param2 = color_values_total[1];
269  Param4<float,float,float,float>.Cast(p_total).param3 = color_values_total[2];
270  Param4<float,float,float,float>.Cast(p_total).param4 = color_values_total[3];
271  }
272 
273  //DbgPrnt("PPEDebug | PPEMatClassParameterColor - UpdateParameterValues | mat/par/req: " + m_MaterialIndex + "/" + m_ParameterIndex + "/" + req_data.GetRequesterIDX() + " | parameter update end, removing from queue");
274  m_Parent.ParamUpdateRemove(m_ParameterIndex);
275 
276  ModifyResultValues(p_total);
277 
278  m_CurrentValues = p_total;
279  }
280 
282  void PrepareLayerInfo(int layer, ref array<float> values, int operator)
283  {
284  ColorValuesData tmp;
285  if (m_LayerInfo.Contains(layer))
286  {
287  tmp = m_LayerInfo.Get(layer);
288  tmp.SetValues(values);
289  tmp.SetOperator(operator);
290  }
291  else
292  {
293  tmp = new ColorValuesData(values,operator);
294  }
295 
296  m_LayerInfo.Set(layer,tmp);
297  AddPriorityInfo(layer);
298  }
299 
300  override void SetParameterValueDefault(inout Param p_total)
301  {
302  if (!p_total)
303  {
304  p_total = new Param4<float,float,float,float>(m_ColorDefaults[0],m_ColorDefaults[1],m_ColorDefaults[2],m_ColorDefaults[3]);
305  }
306  else
307  {
308  Param4<float,float,float,float>.Cast(p_total).param1 = m_ColorDefaults[0];
309  Param4<float,float,float,float>.Cast(p_total).param2 = m_ColorDefaults[1];
310  Param4<float,float,float,float>.Cast(p_total).param3 = m_ColorDefaults[2];
311  Param4<float,float,float,float>.Cast(p_total).param4 = m_ColorDefaults[3];
312  }
313  m_CurrentValues = p_total;
314  }
315 }
316 
317 class PPEMatClassParameterColorColorization extends PPEMatClassParameterColor
318 {
319  override void ModifyResultValues(inout Param result_values)
320  {
321  super.ModifyResultValues(result_values);
322 
323  //saturation-dependency handling
324  Param par = PPEManagerStatic.GetPPEManager().GetPostProcessCurrentValues(PostProcessEffectType.Glow,PPEGlow.PARAM_SATURATION);
325  float saturation_coef = Param1<float>.Cast(par).param1;
326 
327  float r = Param4<float,float,float,float>.Cast(result_values).param1;
328  float g = Param4<float,float,float,float>.Cast(result_values).param2;
329  float b = Param4<float,float,float,float>.Cast(result_values).param3;
330  float a = Param4<float,float,float,float>.Cast(result_values).param4;
331 
332  float highest_channel = Math.Max(Math.Max(r,g),b);
333  saturation_coef = Easing.EaseOutSine(saturation_coef);
334 
335  r = Math.Lerp(highest_channel,r,saturation_coef);
336  g = Math.Lerp(highest_channel,g,saturation_coef);
337  b = Math.Lerp(highest_channel,b,saturation_coef);
338  a = Math.Lerp(m_ColorDefaults[3],a,saturation_coef);
339  //
340 
341  Param4<float,float,float,float>.Cast(result_values).param1 = r;
342  Param4<float,float,float,float>.Cast(result_values).param2 = g;
343  Param4<float,float,float,float>.Cast(result_values).param3 = b;
344  Param4<float,float,float,float>.Cast(result_values).param4 = a;
345  }
346 }
PostProcessEffectType
PostProcessEffectType
Post-process effect type.
Definition: enworld.c:71
VALUES_COUNT
const int VALUES_COUNT
Definition: ppematclassparametercolor.c:41
m_LayerInfo
protected ref map< int, ref ColorValuesData > m_LayerInfo
Definition: ppematclassparametercolor.c:44
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
VALUE_BLUE
const int VALUE_BLUE
Definition: ppematclassparametercolor.c:39
Update
override void Update(float timeslice, out Param p_total, out bool setting_defaults, int order)
Definition: ppematclassparametercolor.c:69
PPETemplateDefColor
Param5< string, float, float, float, float > PPETemplateDefColor
Definition: ppeconstants.c:87
PPEMatClassParameterCommandData
Definition: ppematclassparameterbool.c:1
Managed
TODO doc.
Definition: enscript.c:117
SetParameterValueDefault
override void SetParameterValueDefault(inout Param p_total)
Definition: ppematclassparametercolor.c:300
m_ColorDefaults
float m_ColorDefaults[4]
Definition: ppematclassparametercolor.c:46
m_Parent
protected Widget m_Parent
Definition: sizetochild.c:92
Easing
Input value between 0 and 1, returns value adjusted by easing, no automatic clamping of input(do your...
Definition: easing.c:2
VALUE_RED
ColorValuesData VALUE_RED
PPEManagerStatic
Static component of PPE manager, used to hold the instance.
Definition: ppemanager.c:2
map
map
Definition: controlsxboxnew.c:3
PPEMatClassParameterColor
Definition: ppematclassparametercolor.c:317
GetParameterVarType
override int GetParameterVarType()
Definition: ppematclassparametercolor.c:64
InitCuttent
override void InitCuttent()
Definition: ppematclassparametercolor.c:59
m_Color
protected PPETemplateDefColor m_Color
Definition: ppematclassparametercolor.c:43
PPEGlow
Glow - PostProcessEffectType.Glow.
Definition: ppeglow.c:7
VALUE_ALPHA
const int VALUE_ALPHA
Definition: ppematclassparametercolor.c:40
array< float >
PrepareLayerInfo
void PrepareLayerInfo(int layer, ref array< float > values, int operator)
Fills relative values into arrays/member variables.
Definition: ppematclassparametercolor.c:282
PPEMatClassParameterColor
void PPEMatClassParameterColor(int mat_idx, int parameter_idx, PPEClassBase parent)
Definition: ppematclassparametercolor.c:48
m_Values
ref array< string > m_Values
names parsed from m_Pairs
Definition: universaltemperaturesource.c:207
PPOperators
PPOperators
PP operators, specify operation between subsequent layers.
Definition: ppeconstants.c:51
InitDefaults
override void InitDefaults()
Definition: ppematclassparametercolor.c:53
VALUE_GREEN
const int VALUE_GREEN
Definition: ppematclassparametercolor.c:38
Math
Definition: enmath.c:6
ColorValuesData
Definition: ppematclassparametercolor.c:2