Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
rainprocurementhandler.c
Go to the documentation of this file.
2 {
3  protected MissionBaseWorld m_Mission;
4  protected ref set<RainProcurementComponentBase> m_ActiveComponents;
5  protected ref set<RainProcurementComponentBase> m_ChangedQueue;
6  protected ref set<int> m_CleanupQueue;
7  protected const int UPDATE_BATCH_SIZE = 20; //Tweak this to adjust max batch size
8  const int UPDATE_TIME = 10; //seconds
9  protected bool m_Update;
10  protected bool m_ProcessComponents;
11  protected bool m_ProcessingFinished;
12  protected int m_NextToProcessIdx;
13  protected float m_UpdateTimer;
14  protected float m_LiquidAmountCoef;
15 
17  {
19  m_Update = false;
20  m_ProcessComponents = false;
21  m_ProcessingFinished = true;
22  m_ActiveComponents = new set<RainProcurementComponentBase>;
23  m_ChangedQueue = new set<RainProcurementComponentBase>;
24  m_CleanupQueue = new set<int>;
25  m_NextToProcessIdx = 0;
26  m_UpdateTimer = 0;
27  }
28 
30  {
31  m_ChangedQueue.Insert(component);
32  m_Update = true;
33  }
34 
36  {
37  m_ChangedQueue.Insert(component);
38  m_Update = true;
39  }
40 
41  void Update(float timeslice)
42  {
43  if (!m_Update)
44  return;
45 
46  if (m_ProcessComponents)
47  {
48  if (m_ProcessingFinished) //do on start and after the batch is finished
49  {
50  m_LiquidAmountCoef = DetermineAmountCoef();
51  if (m_LiquidAmountCoef == 0) //skip processing when not raining
52  {
53  Reset();
54  return;
55  }
56  }
57 
58  m_ProcessingFinished = ProcessBatch();
59 
60  if (m_ProcessingFinished)
61  {
62  Reset();
63  }
64  }
65  else
66  {
67  m_UpdateTimer += timeslice;
68  if (m_UpdateTimer >= UPDATE_TIME)
69  {
70  HandleChangedComponents();
71  Cleanup();
72  CheckUpdating();
73  m_ProcessComponents = m_Update;
74  if (!m_Update)
75  Reset();
76  }
77  }
78  }
79 
81  protected bool ProcessBatch()
82  {
83  bool ret = false;
84  int count = m_ActiveComponents.Count();
85  int target = (int)Math.Clamp(m_NextToProcessIdx + UPDATE_BATCH_SIZE,0,count);
86 
87  for (m_NextToProcessIdx; m_NextToProcessIdx < target; m_NextToProcessIdx++)
88  {
89  if (m_ActiveComponents[m_NextToProcessIdx])
90  m_ActiveComponents[m_NextToProcessIdx].OnUpdate(m_UpdateTimer, m_LiquidAmountCoef);
91  else
92  m_CleanupQueue.Insert(m_NextToProcessIdx);
93  }
94 
95  ret = target == count;
96  if (ret)
97  {
98  m_NextToProcessIdx = 0;
99  }
100 
101  return ret;
102  }
103 
104  protected void Cleanup()
105  {
106  int count = m_CleanupQueue.Count();
107  if (count == 0)
108  return;
109 
110  for (int i = count - 1; i > -1; i--)
111  {
112  m_ActiveComponents.Remove(m_CleanupQueue[i]);
113  }
114  m_CleanupQueue.Clear();
115  }
116 
117  protected void Reset()
118  {
119  m_ProcessComponents = false;
120  m_ProcessingFinished = true;
121  m_UpdateTimer = 0;
122  }
123 
124  protected void HandleChangedComponents()
125  {
127  int count = m_ChangedQueue.Count();
128  int idx;
129 
130  for (int i = 0; i < count; i++)
131  {
132  component = m_ChangedQueue[i];
133  if (!component)
134  continue;
135 
136  if (component.IsActive())
137  {
138  m_ActiveComponents.Insert(component);
139  }
140  else
141  {
142  idx = m_ActiveComponents.Find(component);
143  if (idx != -1)
144  m_ActiveComponents.Remove(idx);
145  }
146  }
147  m_ChangedQueue.Clear();
148  }
149 
150  protected void CheckUpdating()
151  {
152  m_Update = m_ActiveComponents.Count() != 0;
153  }
154 
155  float GetLiquidAmountCoef()
156  {
157  return m_LiquidAmountCoef;
158  }
159 
161  float DetermineAmountCoef()
162  {
163  return GetGame().GetWeather().GetRain().GetActual();
164  }
165 };
GetGame
proto native CGame GetGame()
mission
Mission mission
Definition: displaystatus.c:28
Managed
TODO doc.
Definition: enscript.c:117
component
class BoxCollidingParams component
ComponentInfo for BoxCollidingResult.
MissionBaseWorld
Definition: missionbase.c:1
m_Mission
protected Mission m_Mission
Definition: dayzplayermeleefightlogic_lightheavy.c:23
RainProcurementComponentBase
Definition: rainprocurementcomponent.c:1
RainProcurementHandler
Definition: rainprocurementhandler.c:1
int
Param3 int
Math
Definition: enmath.c:6
m_UpdateTimer
protected ref Timer m_UpdateTimer
Definition: radialmenu.c:20