Dayz
Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Toggle main menu visibility
Loading...
Searching...
No Matches
notifierbase.c
Go to the documentation of this file.
1
class
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
}
TENDENCY_INC_LOW
const int TENDENCY_INC_LOW
Definition
_constants.c:53
TENDENCY_DEC_HIGH
const int TENDENCY_DEC_HIGH
Definition
_constants.c:58
TENDENCY_DEC_MED
const int TENDENCY_DEC_MED
Definition
_constants.c:57
TENDENCY_INC_MED
const int TENDENCY_INC_MED
Definition
_constants.c:54
TENDENCY_DEC_LOW
const int TENDENCY_DEC_LOW
Definition
_constants.c:56
TENDENCY_INC_HIGH
const int TENDENCY_INC_HIGH
Definition
_constants.c:55
TENDENCY_STABLE
const int TENDENCY_STABLE
Definition
_constants.c:52
eBadgeLevel
eBadgeLevel
Definition
_constants.c:2
NotifierBase::IsTimeToTick
bool IsTimeToTick(int current_time)
Definition
notifierbase.c:32
NotifierBase::m_Type
int m_Type
Definition
notifierbase.c:6
NotifierBase::CalculateTendency
int CalculateTendency(float delta, float inctresholdlow, float inctresholdmed, float inctresholdhigh, float dectresholdlow, float dectresholdmed, float dectresholdhigh)
Definition
notifierbase.c:166
NotifierBase::HideBadge
void HideBadge()
NotifierBase::m_Manager
NotifiersManager m_Manager
Definition
notifierbase.c:7
NotifierBase::ReadFromCyclicBuffer
float ReadFromCyclicBuffer(int index)
Definition
notifierbase.c:89
NotifierBase::m_LastMA
float m_LastMA
Definition
notifierbase.c:17
NotifierBase::m_Player
PlayerBase m_Player
Definition
notifierbase.c:5
NotifierBase::m_Active
bool m_Active
Definition
notifierbase.c:11
NotifierBase::SetActive
void SetActive(bool state)
Definition
notifierbase.c:69
NotifierBase::GetVirtualHud
VirtualHud GetVirtualHud()
Definition
notifierbase.c:49
NotifierBase::GetObservedValue
float GetObservedValue()
Definition
notifierbase.c:203
NotifierBase::m_LastTendency
float m_LastTendency
Definition
notifierbase.c:16
NotifierBase::DisplayTendency
void DisplayTendency(float delta)
NotifierBase::NotifierBase
void NotifierBase(NotifiersManager manager)
Definition
notifierbase.c:22
NotifierBase::AddToCyclicBuffer
void AddToCyclicBuffer(float value)
Definition
notifierbase.c:78
NotifierBase::TENDENCY_BUFFER_SIZE
const int TENDENCY_BUFFER_SIZE
Definition
notifierbase.c:9
NotifierBase::m_TendencyBufferWriteIterator
int m_TendencyBufferWriteIterator
Definition
notifierbase.c:15
NotifierBase::m_TickInterval
int m_TickInterval
Definition
notifierbase.c:12
NotifierBase::m_Timer1
ref Timer m_Timer1
Definition
notifierbase.c:4
NotifierBase::m_FirstPass
bool m_FirstPass
Definition
notifierbase.c:18
NotifierBase::DetermineBadgeLevel
eBadgeLevel DetermineBadgeLevel(float value, float lvl_1, float lvl_2, float lvl_3)
Definition
notifierbase.c:186
NotifierBase::m_TendencyBufferSize
int m_TendencyBufferSize
Definition
notifierbase.c:8
NotifierBase::OnTick
void OnTick(float current_Time)
Definition
notifierbase.c:147
NotifierBase::m_TendencyBuffer
float m_TendencyBuffer[TENDENCY_BUFFER_SIZE]
Definition
notifierbase.c:14
NotifierBase::m_DeltaT
float m_DeltaT
Definition
notifierbase.c:3
NotifierBase::DisplayBadge
void DisplayBadge()
NotifierBase::GetNotifierType
int GetNotifierType()
Definition
notifierbase.c:54
NotifierBase::GetName
string GetName()
Definition
notifierbase.c:59
NotifierBase::m_ShowTendency
bool m_ShowTendency
Definition
notifierbase.c:10
NotifierBase::m_TickIntervalLastTick
int m_TickIntervalLastTick
Definition
notifierbase.c:13
NotifierBase::IsActive
bool IsActive()
Definition
notifierbase.c:64
NotifierBase::OnTick
void OnTick(int currentTime)
Definition
notifierbase.c:152
NotifierBase::SmoothOutFloatValues
void SmoothOutFloatValues(array< float > values)
Definition
notifierbase.c:129
NotifierBase::m_ModulePlayerStatus
PluginPlayerStatus m_ModulePlayerStatus
Definition
notifierbase.c:20
NotifierBase::GetDeltaAvaraged
float GetDeltaAvaraged()
Definition
notifierbase.c:100
PlayerBase
Definition
playerbaseclient.c:2
Timer
Definition
dayzplayerimplement.c:39
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition
isboxcollidinggeometryproxyclasses.c:28
VirtualHud
void VirtualHud(PlayerBase player)
Definition
displaystatus.c:36
ErrorExSeverity
ErrorExSeverity
Definition
endebug.c:62
ErrorEx
enum ShapeType ErrorEx
NotifiersManager
void NotifiersManager(PlayerBase player)
Definition
notifiersmanager.c:37
GetPlugin
PluginBase GetPlugin(typename plugin_type)
Definition
pluginmanager.c:325
Games
Dayz
scripts
4_world
classes
playernotifiers
notifierbase.c
Generated by
1.17.0