Dayz Explorer 1.29.162510
Loading...
Searching...
No Matches
notifierbase.c
Go to the documentation of this file.
1class NotifierBase
2{
3 float m_DeltaT; // time in seconds since the last tick
4 ref Timer m_Timer1; // timer which can be used for whatever
5 PlayerBase m_Player; //the player this Notifier belongs to
6 int m_Type;
7 NotifiersManager m_Manager;
8 int m_TendencyBufferSize = 3;//for best results, this should be somewhat aligned with modifier frequency
9 const int TENDENCY_BUFFER_SIZE = 30;//this needs to be bigger or same size as buffer size of any invidual buffer size
10 bool m_ShowTendency;
11 bool m_Active;
12 int m_TickInterval;
13 int m_TickIntervalLastTick;
14 float m_TendencyBuffer[TENDENCY_BUFFER_SIZE];
15 int m_TendencyBufferWriteIterator;
16 float m_LastTendency;
17 float m_LastMA;
18 bool m_FirstPass = true;
19
20 PluginPlayerStatus m_ModulePlayerStatus;
21
22 void NotifierBase(NotifiersManager manager)
23 {
24 m_ModulePlayerStatus = PluginPlayerStatus.Cast(GetPlugin(PluginPlayerStatus));
25 m_Active = true;
26 m_Manager = manager;
27 m_Player = manager.GetPlayer();
28 m_TickInterval = 1000;
29 manager.RegisterItself(GetNotifierType(), this);
30 }
31
32 bool IsTimeToTick(int current_time)
33 {
34 int tickTime = (m_TickIntervalLastTick + m_TickInterval);
35 bool tick = (current_time >= tickTime);
36 #ifdef DIAG_NOTIFIER_LOGS
37 ErrorEx(string.Format("Tick time for notifier %1 is %2 | Current time= %3.", this, tickTime, current_time), ErrorExSeverity.INFO);
38 if (tick)
39 {
40 float timePassed = (current_time - m_TickIntervalLastTick) / 1000.0;
41 float expectedInterval = m_TickInterval / 1000.0;
42 float drift = (current_time - tickTime) / 1000.0;
43 ErrorEx(string.Format("Notifier %1 updated after %2s (expected: %3s, drift: +%4s)", this, timePassed, expectedInterval, drift), ErrorExSeverity.INFO);
44 }
45 #endif
46 return tick;
47 }
48
49 VirtualHud GetVirtualHud()
50 {
51 return m_Player.GetVirtualHud();
52 }
53
54 int GetNotifierType()
55 {
56 return m_Type;
57 }
58
59 string GetName()
60 {
61 return this.ClassName() + " Notifier";
62 }
63
64 bool IsActive()
65 {
66 return m_Active;
67 }
68
69 void SetActive(bool state)
70 {
71 m_Active = state;
72 if (!state)
73 HideBadge();
74 }
75
76 void DisplayTendency(float delta);
77
78 void AddToCyclicBuffer(float value)//for tendency
79 {
80 m_TendencyBuffer[m_TendencyBufferWriteIterator] = value;
81 ++m_TendencyBufferWriteIterator;
82 if (m_TendencyBufferWriteIterator == m_TendencyBufferSize)
83 {
84 m_TendencyBufferWriteIterator = 0;
85 m_ShowTendency = true;
86 }
87 }
88
89 float ReadFromCyclicBuffer(int index)
90 {
91 int indx = m_TendencyBufferWriteIterator + index;
92 if ( indx >= m_TendencyBufferSize)
93 {
94 indx = indx - m_TendencyBufferSize;
95 }
96
97 return m_TendencyBuffer[indx];
98 }
99
100 float GetDeltaAvaraged() //for tendency
101 {
102 array<float> values = new array<float>();
103 for (int i = 0; i < m_TendencyBufferSize; ++i)
104 {
105 values.Insert(ReadFromCyclicBuffer(i));
106 }
107
108 float valuesSum = 0;
109
110 int nValues = values.Count();
111 for (i = 0; i < nValues; ++i)
112 {
113 valuesSum += values.Get(i);
114 }
115
116 float sma = valuesSum / m_TendencyBufferSize;
117 if (m_FirstPass)
118 {
119 m_LastMA = sma;
120 m_FirstPass = false;
121 }
122
123 float tnd = sma - m_LastMA;
124 m_LastMA = sma;
125
126 return tnd;
127 }
128
129 void SmoothOutFloatValues(array<float> values)
130 {
131 float value1;
132 float value2;
133 int nValues = values.Count();
134 for (int i = 0; i < nValues - 1; i++)
135 {
136 value1 = values.Get(i);
137 value2 = values.Get(i + 1);
138 float average = (value1 + value2) / 2;
139 values.Set(i, average);
140 values.Set(i + 1, average);
141 }
142
143 int index = nValues - 1;
144 values.Set(index, value2);
145 }
146
147 void OnTick(float current_Time)
148 {
149 OnTick((int)current_Time);
150 }
151
152 void OnTick(int currentTime)
153 {
154 #ifdef DIAG_NOTIFIER_LOGS
155 ErrorEx(string.Format("Set last tick interval time on notifier %1 | Time= %2.", m_TickIntervalLastTick, currentTime), ErrorExSeverity.INFO);
156 #endif
157 m_TickIntervalLastTick = currentTime;
158
159 DisplayBadge();
160 AddToCyclicBuffer(GetObservedValue());
161
162 if (m_ShowTendency)
163 DisplayTendency(GetDeltaAvaraged());
164 }
165
166 protected int CalculateTendency(float delta, float inctresholdlow, float inctresholdmed, float inctresholdhigh, float dectresholdlow, float dectresholdmed, float dectresholdhigh)
167 {
168 int tendency = TENDENCY_STABLE;
169 if (delta > inctresholdhigh)
170 tendency = TENDENCY_INC_HIGH;
171 else if (delta > inctresholdmed)
172 tendency = TENDENCY_INC_MED;
173 else if (delta > inctresholdlow)
174 tendency = TENDENCY_INC_LOW;
175 else if (delta < dectresholdhigh)
176 tendency = TENDENCY_DEC_HIGH;
177 else if (delta < dectresholdmed)
178 tendency = TENDENCY_DEC_MED;
179 else if (delta < dectresholdlow)
180 tendency = TENDENCY_DEC_LOW;
181
182 return tendency;
183 }
184
185
186 protected eBadgeLevel DetermineBadgeLevel(float value, float lvl_1, float lvl_2, float lvl_3)
187 {
188 eBadgeLevel level = eBadgeLevel.NONE;
189 if (value >= lvl_3)
190 level = eBadgeLevel.THIRD;
191 else if (value >= lvl_2)
192 level = eBadgeLevel.SECOND;
193 else if (value >= lvl_1)
194 level = eBadgeLevel.FIRST;
195
196 return level;
197 }
198
199
200 protected void DisplayBadge();
201 protected void HideBadge();
202
203 protected float GetObservedValue()
204 {
205 return 0.0;
206 }
207}
const int TENDENCY_INC_LOW
Definition _constants.c:53
const int TENDENCY_DEC_HIGH
Definition _constants.c:58
const int TENDENCY_DEC_MED
Definition _constants.c:57
const int TENDENCY_INC_MED
Definition _constants.c:54
const int TENDENCY_DEC_LOW
Definition _constants.c:56
const int TENDENCY_INC_HIGH
Definition _constants.c:55
const int TENDENCY_STABLE
Definition _constants.c:52
eBadgeLevel
Definition _constants.c:2
eBadgeLevel DetermineBadgeLevel(float value, float lvl_1, float lvl_2, float lvl_3)
int CalculateTendency(float delta, float inctresholdlow, float inctresholdmed, float inctresholdhigh, float dectresholdlow, float dectresholdmed, float dectresholdhigh)
void HideBadge()
void DisplayBadge()
float GetObservedValue()
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
void VirtualHud(PlayerBase player)
ErrorExSeverity
Definition endebug.c:62
enum ShapeType ErrorEx
proto string GetName()
Suite class name getter. Strictly for UI porposes!
Definition syncedvalue.c:50
bool IsActive()
PluginBase GetPlugin(typename plugin_type)
void SetActive()
Definition trapbase.c:404