#include <AverageTimeTracker/AverageTimeTracker.hpp>

void AverageTimeTracker::submitSample(double ms)
{
    recentSamples.push_back(ms);
    if (recentSamples.size() > maxSamples)
    {
        recentSamples.pop_front();
    }
}

double AverageTimeTracker::getAverage()
{
    if (recentSamples.size() == 0)
    {
        return 0.01;
    }

    double sum = 0.0;
    for (double frameTime : recentSamples)
    {
        sum += frameTime;
    }

    return sum / (double) recentSamples.size();
}