DayZ 1.30
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
NotifiersManager.c
См. документацию.
1//#define DIAG_NOTIFIER_LOGS
2
26
28{
29 static const int MAX_COUNT = 64;
30
36 string m_System = "Notifiers";
37
39 private int m_LastPolledIndex = 0;
40
42 private ref array<int> m_NotifierIDs = new array<int>();
43
48
50 {
51 m_Player = player;
55
56 for (int i = 0; i < MAX_COUNT; i++)
57 {
58 m_ImmediatePending[i] = false;
59 }
60
61 Init();
62 }
63
64 void Init()
65 {
66 m_Notifiers.Insert(new HealthNotfr(this));
67 m_Notifiers.Insert(new HungerNotfr(this));
68 m_Notifiers.Insert(new ThirstNotfr(this));
69 m_Notifiers.Insert(new StuffedNotfr(this));
70 m_Notifiers.Insert(new SickNotfr(this));
71 m_Notifiers.Insert(new WetnessNotfr(this));
72 m_Notifiers.Insert(new WarmthNotfr(this));
73 m_Notifiers.Insert(new FeverNotfr(this));
74 m_Notifiers.Insert(new BloodNotfr(this));
75 m_Notifiers.Insert(new PillsNotfr(this));
76 m_Notifiers.Insert(new FracturedLegNotfr(this));
77 m_Notifiers.Insert(new InjuredLegNotfr(this));
78 }
79
80 protected bool IsNotifierIDValid(int notifier_id)
81 {
82 return notifier_id >= 0 && notifier_id < MAX_COUNT;
83 }
84
85 void RegisterItself(int notifier_id, NotifierBase modifier)
86 {
87 if (!IsNotifierIDValid(notifier_id))
88 {
89 ErrorEx("Out of bounds for notifier id: " + notifier_id, ErrorExSeverity.ERROR);
90 return;
91 }
92
93 m_NotifiersStatic[notifier_id] = modifier;
94
95 if (m_NotifierIDs.Find(notifier_id) == -1)
96 {
97 m_NotifierIDs.Insert(notifier_id);
98 }
99
100 #ifdef DIAG_NOTIFIER_LOGS
101 ErrorEx(string.Format("Added notifier %1 with id=%2", modifier, notifier_id), ErrorExSeverity.INFO);
102 #endif
103 }
104
106 {
107 return m_Player;
108 }
109
111 {
112 if (!m_VirtualHud)
113 {
114 m_VirtualHud = m_Player.GetVirtualHud();
115 }
116
117 return m_VirtualHud;
118 }
119
121 {
122 if (!IsNotifierIDValid(type))
123 {
124 #ifdef DIAG_NOTIFIER_LOGS
125 ErrorEx(string.Format("Invalid notifier id requested: %1.", type), ErrorExSeverity.ERROR);
126 #endif
127 return null;
128 }
129
130 return m_NotifiersStatic[type];
131 }
132
133 bool HasNotifier(int type)
134 {
135 return FindNotifier(type) != null;
136 }
137
138 bool IsNotifierActive(int type)
139 {
140 NotifierBase notifier = FindNotifier(type);
141 if (!notifier)
142 return false;
143
144 return notifier.IsActive();
145 }
146
147 protected void ClearImmediatePending(int notifier_id)
148 {
149 if (!IsNotifierIDValid(notifier_id))
150 return;
151
152 m_ImmediatePending[notifier_id] = false;
153 }
154
155 void RequestImmediateUpdate(int notifier_id)
156 {
157 if (!IsNotifierIDValid(notifier_id))
158 return;
159
160 NotifierBase notifier = FindNotifier(notifier_id);
161 if (!notifier || !notifier.IsActive())
162 return;
163
164 if (m_ImmediatePending[notifier_id])
165 return;
166
167 m_ImmediatePending[notifier_id] = true;
168 m_ImmediateNotifierIDs.Insert(notifier_id);
169
170 #ifdef DIAG_NOTIFIER_LOGS
171 ErrorEx(string.Format("Queued immediate notifier update for id=%1.", notifier_id), ErrorExSeverity.INFO);
172 #endif
173 }
174
175 bool SetNotifierActive(int notifier_id, bool state, bool immediate = false)
176 {
177 NotifierBase notifier = FindNotifier(notifier_id);
178 if (!notifier)
179 {
180 #ifdef DIAG_NOTIFIER_LOGS
181 ErrorEx(string.Format("SetNotifierActive failed, notifier %1 not found.", notifier_id), ErrorExSeverity.ERROR);
182 #endif
183 return false;
184 }
185
186 bool changed = (notifier.IsActive() != state);
187
188 notifier.SetActive(state);
189
190 if (!state)
191 {
192 ClearImmediatePending(notifier_id);
193 }
194 else if (changed && immediate)
195 {
196 RequestImmediateUpdate(notifier_id);
197 }
198
199 return changed;
200 }
201
202 void ActivateByType(int notifier, bool triggerEvent = true)
203 {
205 SetNotifierActive(notifier, true, triggerEvent);
206 }
207
208 void DeactivateByType(int notifier, bool triggerEvent = true)
209 {
210 SetNotifierActive(notifier, false, false);
211 }
212
213 protected bool ProcessImmediateNotifier(int currentTime)
214 {
215 while (m_ImmediateNotifierIDs.Count() > 0)
216 {
217 int lastIndex = m_ImmediateNotifierIDs.Count() - 1;
218 int notifierID = m_ImmediateNotifierIDs.Get(lastIndex);
219 m_ImmediateNotifierIDs.Remove(lastIndex);
220 m_ImmediatePending[notifierID] = false;
221
222 NotifierBase currentNotifier = m_NotifiersStatic[notifierID];
223 if (!currentNotifier || !currentNotifier.IsActive())
224 {
225 #ifdef DIAG_NOTIFIER_LOGS
226 ErrorEx(string.Format("Skipping immediate notifier id=%1 (missing or inactive).", notifierID), ErrorExSeverity.INFO);
227 #endif
228 continue;
229 }
230
231 #ifdef DIAG_NOTIFIER_LOGS
232 ErrorEx(string.Format("Immediate tick for notifier %1 with ID %2.", currentNotifier, notifierID), ErrorExSeverity.INFO);
233 #endif
234
235 currentNotifier.OnTick(currentTime);
236 return true;
237 }
238
239 return false;
240 }
241
242 protected void TickSingleNotifier(int currentTime)
243 {
244 int notifierCount = m_NotifierIDs.Count();
245
246 #ifdef DIAG_NOTIFIER_LOGS
247 if (notifierCount == 0)
248 {
249 ErrorEx("Notifier count is 0", ErrorExSeverity.ERROR);
250 return;
251 }
252 #endif
253
254 if (m_LastPolledIndex >= notifierCount)
255 {
256 #ifdef DIAG_NOTIFIER_LOGS
257 ErrorEx(string.Format("Last poll index is %1 and notifier id count is %2. Reset poll index.", m_LastPolledIndex, notifierCount), ErrorExSeverity.INFO);
258 #endif
260 }
261
262 int notifierID = m_NotifierIDs[m_LastPolledIndex];
263
264 #ifdef DIAG_NOTIFIER_LOGS
265 ErrorEx(string.Format("Got notifier ID %1 for poll index %2.", notifierID, m_LastPolledIndex), ErrorExSeverity.INFO);
266 #endif
267
268 NotifierBase currentNotifier = m_NotifiersStatic[notifierID];
269
270 if (currentNotifier && currentNotifier.IsActive())
271 {
272 #ifdef DIAG_NOTIFIER_LOGS
273 ErrorEx(string.Format("Got notifier %1 with ID %2.", currentNotifier, notifierID), ErrorExSeverity.INFO);
274 #endif
275
276 if (currentNotifier.IsTimeToTick(currentTime))
277 {
278 #ifdef DIAG_NOTIFIER_LOGS
279 ErrorEx(string.Format("Time to tick notifier %1.", currentNotifier), ErrorExSeverity.INFO);
280 #endif
281 currentNotifier.OnTick(currentTime);
282 }
283 #ifdef DIAG_NOTIFIER_LOGS
284 else
285 {
286 ErrorEx(string.Format("Skip tick of notifier %1 ..", currentNotifier), ErrorExSeverity.INFO);
287 }
288 #endif
289 }
290 #ifdef DIAG_NOTIFIER_LOGS
291 else
292 {
293 if (!currentNotifier)
294 ErrorEx(string.Format("Could not get any notifier with ID %1.", notifierID), ErrorExSeverity.ERROR);
295 else
296 ErrorEx(string.Format("Could get notifier %1 with ID %2 but notifier is inactive!", currentNotifier, notifierID), ErrorExSeverity.INFO);
297 }
298 #endif
299
301 }
302
304 {
305 if (!GetPlayer().IsPlayerSelected())
306 return;
307
309 }
310
312 {
313 int currentTime = g_Game.GetTime();
314
316 if (ProcessImmediateNotifier(currentTime))
317 return;
318
319 TickSingleNotifier(currentTime);
320 }
321}
DayZGame g_Game
Определения DayZGame.c:4074
override Widget Init()
Определения DayZGame.c:127
void VirtualHud(PlayerBase player)
Определения DisplayStatus.c:36
DayZPlayer m_Player
Определения Hand_Events.c:42
PlayerBase GetPlayer()
Определения ModifierBase.c:51
string m_System
the manager instance
Определения ModifierBase.c:12
bool IsNotifierActive(int type)
Определения NotifiersManager.c:138
void NotifiersManager(PlayerBase player)
Определения NotifiersManager.c:49
ref VirtualHud m_VirtualHud
Определения NotifiersManager.c:34
eNotifiers
Определения NotifiersManager.c:4
@ NTF_HEALTHY
Определения NotifiersManager.c:5
@ NTF_HEARTBEAT
Определения NotifiersManager.c:19
@ NTF_BLOOD
Определения NotifiersManager.c:14
@ NTF_THIRSTY
Определения NotifiersManager.c:8
@ NTF_STAMINA
Определения NotifiersManager.c:16
@ NTF_LEGS
Определения NotifiersManager.c:21
@ NTF_FRACTURE
Определения NotifiersManager.c:20
@ NTF_STUFFED
Определения NotifiersManager.c:9
@ NTF_WETNESS
Определения NotifiersManager.c:11
@ NTF_COUNT
Определения NotifiersManager.c:23
@ NTF_PILLS
Определения NotifiersManager.c:18
@ NTF_SICK
Определения NotifiersManager.c:10
@ NTF_WARMTH
Определения NotifiersManager.c:12
@ NTF_FEVERISH
Определения NotifiersManager.c:13
@ NTF_LIVES
Определения NotifiersManager.c:15
@ NTF_BLEEDISH
Определения NotifiersManager.c:6
@ NTF_HUNGRY
Определения NotifiersManager.c:7
void OnScheduledTick()
Определения NotifiersManager.c:303
void ClearImmediatePending(int notifier_id)
Определения NotifiersManager.c:147
bool SetNotifierActive(int notifier_id, bool state, bool immediate=false)
Определения NotifiersManager.c:175
ref array< int > m_NotifierIDs
Notifier ids in registration order.
Определения NotifiersManager.c:42
bool m_ImmediatePending[MAX_COUNT]
Определения NotifiersManager.c:47
VirtualHud GetVirtualHud()
Определения NotifiersManager.c:110
void TickNotifiers()
Определения NotifiersManager.c:311
int m_MinTickTime
Определения NotifiersManager.c:35
NotifierBase FindNotifier(int type)
Определения NotifiersManager.c:120
bool HasNotifier(int type)
Определения NotifiersManager.c:133
enum eNotifiers MAX_COUNT
ref array< int > m_ImmediateNotifierIDs
Определения NotifiersManager.c:46
NotifierBase m_NotifiersStatic[MAX_COUNT]
Определения NotifiersManager.c:32
bool IsNotifierIDValid(int notifier_id)
Определения NotifiersManager.c:80
void DeactivateByType(int notifier, bool triggerEvent=true)
Определения NotifiersManager.c:208
void TickSingleNotifier(int currentTime)
Определения NotifiersManager.c:242
ref array< ref NotifierBase > m_Notifiers
Определения NotifiersManager.c:31
void RegisterItself(int notifier_id, NotifierBase modifier)
Определения NotifiersManager.c:85
int m_LastPolledIndex
Round-robin index.
Определения NotifiersManager.c:39
void RequestImmediateUpdate(int notifier_id)
Определения NotifiersManager.c:155
bool ProcessImmediateNotifier(int currentTime)
Определения NotifiersManager.c:213
void ActivateByType(int notifier, bool triggerEvent=true)
Определения NotifiersManager.c:202
Определения BloodNotfr.c:2
Определения FeverNotfr.c:2
Определения HealthNotfr.c:2
Определения HungerNotfr.c:2
Определения InjuredLegNotfr.c:2
void SetActive(bool state)
Определения NotifierBase.c:66
void OnTick(float current_time)
Определения NotifierBase.c:144
bool IsActive()
Определения NotifierBase.c:61
bool IsTimeToTick(int current_time)
Определения NotifierBase.c:29
Определения NotifierBase.c:2
Определения PillsNotfr.c:2
Определения PlayerBaseClient.c:2
Определения SickNotfr.c:2
Определения StuffedNotfr.c:2
Определения ThirstNotfr.c:2
Определения WarmthNotfr.c:2
Определения WetnessNotfr.c:2
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
ErrorExSeverity
Определения EnDebug.c:62
enum ShapeType ErrorEx
const int MIN_TICK_NOTIFIERS
Определения 3_Game/DayZ/constants.c:359