Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Loading...
Searching...
No Matches
notifierbase.c
Go to the documentation of this file.
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;
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
17 float m_LastMA;
18 bool m_FirstPass = true;
19
20 PluginPlayerStatus m_ModulePlayerStatus;
21
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
50 {
51 return m_Player.GetVirtualHud();
52 }
53
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
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
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();
161
162 if (m_ShowTendency)
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
bool IsTimeToTick(int current_time)
int CalculateTendency(float delta, float inctresholdlow, float inctresholdmed, float inctresholdhigh, float dectresholdlow, float dectresholdmed, float dectresholdhigh)
void HideBadge()
NotifiersManager m_Manager
Definition notifierbase.c:7
float ReadFromCyclicBuffer(int index)
PlayerBase m_Player
Definition notifierbase.c:5
void SetActive(bool state)
VirtualHud GetVirtualHud()
float GetObservedValue()
float m_LastTendency
void DisplayTendency(float delta)
void NotifierBase(NotifiersManager manager)
void AddToCyclicBuffer(float value)
const int TENDENCY_BUFFER_SIZE
Definition notifierbase.c:9
int m_TendencyBufferWriteIterator
ref Timer m_Timer1
Definition notifierbase.c:4
eBadgeLevel DetermineBadgeLevel(float value, float lvl_1, float lvl_2, float lvl_3)
int m_TendencyBufferSize
Definition notifierbase.c:8
void OnTick(float current_Time)
float m_TendencyBuffer[TENDENCY_BUFFER_SIZE]
void DisplayBadge()
int GetNotifierType()
string GetName()
bool m_ShowTendency
int m_TickIntervalLastTick
bool IsActive()
void OnTick(int currentTime)
void SmoothOutFloatValues(array< float > values)
PluginPlayerStatus m_ModulePlayerStatus
float GetDeltaAvaraged()
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
void VirtualHud(PlayerBase player)
ErrorExSeverity
Definition endebug.c:62
enum ShapeType ErrorEx
void NotifiersManager(PlayerBase player)
PluginBase GetPlugin(typename plugin_type)