7 NotifiersManager m_Manager;
8 int m_TendencyBufferSize = 3;
9 const int TENDENCY_BUFFER_SIZE = 30;
13 int m_TickIntervalLastTick;
14 float m_TendencyBuffer[TENDENCY_BUFFER_SIZE];
15 int m_TendencyBufferWriteIterator;
18 bool m_FirstPass =
true;
20 PluginPlayerStatus m_ModulePlayerStatus;
22 void NotifierBase(NotifiersManager manager)
24 m_ModulePlayerStatus = PluginPlayerStatus.Cast(
GetPlugin(PluginPlayerStatus));
27 m_Player = manager.GetPlayer();
28 m_TickInterval = 1000;
29 manager.RegisterItself(GetNotifierType(),
this);
32 bool IsTimeToTick(
int current_time)
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);
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);
51 return m_Player.GetVirtualHud();
61 return this.ClassName() +
" Notifier";
76 void DisplayTendency(
float delta);
78 void AddToCyclicBuffer(
float value)
80 m_TendencyBuffer[m_TendencyBufferWriteIterator] = value;
81 ++m_TendencyBufferWriteIterator;
82 if (m_TendencyBufferWriteIterator == m_TendencyBufferSize)
84 m_TendencyBufferWriteIterator = 0;
85 m_ShowTendency =
true;
89 float ReadFromCyclicBuffer(
int index)
91 int indx = m_TendencyBufferWriteIterator + index;
92 if ( indx >= m_TendencyBufferSize)
94 indx = indx - m_TendencyBufferSize;
97 return m_TendencyBuffer[indx];
100 float GetDeltaAvaraged()
103 for (
int i = 0; i < m_TendencyBufferSize; ++i)
105 values.Insert(ReadFromCyclicBuffer(i));
110 int nValues = values.Count();
111 for (i = 0; i < nValues; ++i)
113 valuesSum += values.Get(i);
116 float sma = valuesSum / m_TendencyBufferSize;
123 float tnd = sma - m_LastMA;
133 int nValues = values.Count();
134 for (
int i = 0; i < nValues - 1; i++)
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);
143 int index = nValues - 1;
144 values.Set(index, value2);
147 void OnTick(
float current_Time)
149 OnTick((
int)current_Time);
152 void OnTick(
int currentTime)
154 #ifdef DIAG_NOTIFIER_LOGS
155 ErrorEx(
string.Format(
"Set last tick interval time on notifier %1 | Time= %2.", m_TickIntervalLastTick, currentTime),
ErrorExSeverity.INFO);
157 m_TickIntervalLastTick = currentTime;
163 DisplayTendency(GetDeltaAvaraged());
166 protected int CalculateTendency(
float delta,
float inctresholdlow,
float inctresholdmed,
float inctresholdhigh,
float dectresholdlow,
float dectresholdmed,
float dectresholdhigh)
169 if (delta > inctresholdhigh)
171 else if (delta > inctresholdmed)
173 else if (delta > inctresholdlow)
175 else if (delta < dectresholdhigh)
177 else if (delta < dectresholdmed)
179 else if (delta < dectresholdlow)
191 else if (value >= lvl_2)
193 else if (value >= lvl_1)
int CalculateTendency(float delta, float inctresholdlow, float inctresholdmed, float inctresholdhigh, float dectresholdlow, float dectresholdmed, float dectresholdhigh)