Files
comaps/libs/drape_frontend/gui/scale_fps_helper.hpp
Konstantin Pastbin bfffa1fff4 Format all C++ and Java code via clang-format
Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
2025-08-17 14:32:37 +07:00

54 lines
1.2 KiB
C++

#pragma once
#include "base/timer.hpp"
#include <cstdint>
namespace gui
{
class ScaleFpsHelper
{
public:
uint32_t GetFps() const
{
if (m_frameTime == 0.0)
return 0;
return static_cast<uint32_t>(1.0 / m_frameTime);
}
bool IsPaused() const { return m_isPaused; }
void SetFrameTime(double frameTime, bool isActiveFrame)
{
m_isPaused = !isActiveFrame;
m_framesCounter++;
m_aggregatedFrameTime += frameTime;
double constexpr kAggregationPeriod = 0.5;
if (m_isPaused || m_fpsAggregationTimer.ElapsedSeconds() >= kAggregationPeriod)
{
m_frameTime = m_aggregatedFrameTime / m_framesCounter;
m_aggregatedFrameTime = 0.0;
m_framesCounter = 0;
m_fpsAggregationTimer.Reset();
}
}
int GetScale() const { return m_scale; }
void SetScale(int scale) { m_scale = scale; }
void SetVisible(bool isVisible) { m_isVisible = isVisible; }
bool IsVisible() const { return m_isVisible; }
private:
double m_frameTime = 0.0;
int m_scale = 1;
bool m_isVisible = false;
base::Timer m_fpsAggregationTimer;
double m_aggregatedFrameTime = 0.0;
uint32_t m_framesCounter = 1;
bool m_isPaused = false;
};
} // namespace gui