ENABLE_RENDER_STATISTICS -> FPS averaged to last second

This commit is contained in:
enricoturri1966 2020-12-08 11:43:00 +01:00
parent 1185ec9d2a
commit bf3786be59
2 changed files with 23 additions and 16 deletions

View file

@ -320,11 +320,22 @@ class GLCanvas3D
};
#if ENABLE_RENDER_STATISTICS
struct RenderStats
class RenderStats
{
long long last_frame;
std::queue<std::pair<long long, long long>> m_frames;
long long m_curr_total{ 0 };
RenderStats() : last_frame(0) {}
public:
void add_frame(long long frame) {
long long now = wxGetLocalTimeMillis().GetValue();
if (!m_frames.empty() && now - m_frames.front().first > 1000) {
m_curr_total -= m_frames.front().second;
m_frames.pop();
}
m_curr_total += frame;
m_frames.push({ now, frame });
}
long long get_average() const { return m_frames.empty() ? 0 : m_curr_total / m_frames.size(); }
};
#endif // ENABLE_RENDER_STATISTICS