1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-08 09:37:53 +00:00
OpenMW/components/misc/budgetmeasurement.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

46 lines
1.3 KiB
C++
Raw Normal View History

#ifndef OPENMW_COMPONENTS_MISC_BUDGETMEASUREMENT_H
#define OPENMW_COMPONENTS_MISC_BUDGETMEASUREMENT_H
2022-08-15 21:04:54 +00:00
#include <array>
#include <cstddef>
namespace Misc
{
class BudgetMeasurement
{
std::array<float, 4> mBudgetHistory;
std::array<unsigned int, 4> mBudgetStepCount;
2022-09-22 18:26:05 +00:00
public:
BudgetMeasurement(const float default_expense)
2022-09-22 18:26:05 +00:00
{
mBudgetHistory = { default_expense, default_expense, default_expense, default_expense };
mBudgetStepCount = { 1, 1, 1, 1 };
2022-09-22 18:26:05 +00:00
}
void reset(const float default_expense)
2022-09-22 18:26:05 +00:00
{
mBudgetHistory = { default_expense, default_expense, default_expense, default_expense };
mBudgetStepCount = { 1, 1, 1, 1 };
2022-09-22 18:26:05 +00:00
}
void update(double delta, unsigned int stepCount, size_t cursor)
2022-09-22 18:26:05 +00:00
{
mBudgetHistory[cursor % 4] = delta;
mBudgetStepCount[cursor % 4] = stepCount;
2022-09-22 18:26:05 +00:00
}
double get() const
2022-09-22 18:26:05 +00:00
{
float sum = (mBudgetHistory[0] + mBudgetHistory[1] + mBudgetHistory[2] + mBudgetHistory[3]);
unsigned int stepCountSum
= (mBudgetStepCount[0] + mBudgetStepCount[1] + mBudgetStepCount[2] + mBudgetStepCount[3]);
return sum / float(stepCountSum);
}
};
}
#endif