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;
8 const int UPDATE_TIME = 10;
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;
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;
41 void Update(
float timeslice)
46 if (m_ProcessComponents)
48 if (m_ProcessingFinished)
50 m_LiquidAmountCoef = DetermineAmountCoef();
51 if (m_LiquidAmountCoef == 0)
58 m_ProcessingFinished = ProcessBatch();
60 if (m_ProcessingFinished)
70 HandleChangedComponents();
73 m_ProcessComponents = m_Update;
81 protected bool ProcessBatch()
84 int count = m_ActiveComponents.Count();
85 int target = (
int)
Math.Clamp(m_NextToProcessIdx + UPDATE_BATCH_SIZE,0,count);
87 for (m_NextToProcessIdx; m_NextToProcessIdx < target; m_NextToProcessIdx++)
89 if (m_ActiveComponents[m_NextToProcessIdx])
90 m_ActiveComponents[m_NextToProcessIdx].OnUpdate(
m_UpdateTimer, m_LiquidAmountCoef);
92 m_CleanupQueue.Insert(m_NextToProcessIdx);
95 ret = target == count;
98 m_NextToProcessIdx = 0;
104 protected void Cleanup()
106 int count = m_CleanupQueue.Count();
110 for (
int i = count - 1; i > -1; i--)
112 m_ActiveComponents.Remove(m_CleanupQueue[i]);
114 m_CleanupQueue.Clear();
117 protected void Reset()
119 m_ProcessComponents =
false;
120 m_ProcessingFinished =
true;
124 protected void HandleChangedComponents()
127 int count = m_ChangedQueue.Count();
130 for (
int i = 0; i < count; i++)
142 idx = m_ActiveComponents.Find(
component);
144 m_ActiveComponents.Remove(idx);
147 m_ChangedQueue.Clear();
150 protected void CheckUpdating()
152 m_Update = m_ActiveComponents.Count() != 0;
155 float GetLiquidAmountCoef()
157 return m_LiquidAmountCoef;
161 float DetermineAmountCoef()
163 return GetGame().GetWeather().GetRain().GetActual();