10 template<
typename T,
size_t t_Size>
19 void Push(T t_Element);
38 template<
typename T,
size_t t_Size>
44 template<
typename T,
size_t t_Size>
48 const UINT32 index = m_CurrentIndex++;
49 m_Buffer[index & (m_MaxSize - 1u)] = t_Element;
52 template<
typename T,
size_t t_Size>
57 size_t Range = (m_Count < m_MaxSize ? m_Count : m_MaxSize);
58 for (
size_t i = 0; i < Range; ++i)
60 Average += m_Buffer[i];
63 return (Average / static_cast<T>(Range));
void Push(T t_Element)
Push a value onto the buffer to be calculated.
Definition: MovingAverage.hpp:45
size_t m_CurrentIndex
Index for keeping track of what part of the buffer we should be inserting into.
Definition: MovingAverage.hpp:26
size_t m_Count
Current count of things pushed to this average.
Definition: MovingAverage.hpp:29
size_t m_MaxSize
Max sample size in this moving average.
Definition: MovingAverage.hpp:32
T GetAverage() const
Get the average (Sum / num elements)
Definition: MovingAverage.hpp:53
uint32_t UINT32
Definition: FlingTypes.h:13
MovingAverage()
Definition: MovingAverage.hpp:39
A moving average can be used to calculate things like FPS.
Definition: MovingAverage.hpp:11
T m_Buffer[t_Size]
Buffer of samples used to calculate the moving average.
Definition: MovingAverage.hpp:35