2018-07-23 23:11:24 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline void clamp(T& current, T min, T max)
|
|
|
|
{
|
2023-08-02 17:35:35 +01:00
|
|
|
if (current < min) {
|
2018-07-23 23:11:24 +01:00
|
|
|
current = min;
|
2023-08-02 17:35:35 +01:00
|
|
|
} else if (current > max) {
|
2018-07-23 23:11:24 +01:00
|
|
|
current = max;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// List of numbers from min to max. Next is exponent times bigger than previous.
|
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
class ExponentialSeries {
|
|
|
|
public:
|
2018-07-23 23:11:24 +01:00
|
|
|
ExponentialSeries(unsigned min, unsigned max, unsigned exponent = 2)
|
|
|
|
{
|
|
|
|
m_current = m_min = min;
|
|
|
|
m_max = max;
|
|
|
|
m_exponent = exponent;
|
|
|
|
}
|
2023-08-02 17:35:35 +01:00
|
|
|
void reset() { m_current = m_min; }
|
2018-07-23 23:11:24 +01:00
|
|
|
unsigned operator()()
|
|
|
|
{
|
|
|
|
unsigned retval = m_current;
|
|
|
|
m_current *= m_exponent;
|
|
|
|
clamp(m_current, m_min, m_max);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
unsigned m_current;
|
|
|
|
unsigned m_min;
|
|
|
|
unsigned m_max;
|
|
|
|
unsigned m_exponent;
|
|
|
|
};
|