summaryrefslogtreecommitdiffstats
path: root/api/logic/ExponentialSeries.h
blob: a9487f0a3bcd48b2cf9e2dc6714c96dfbc5d4425 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

#pragma once

template <typename T>
inline void clamp(T& current, T min, T max)
{
    if (current < min)
    {
        current = min;
    }
    else if(current > max)
    {
        current = max;
    }
}

// List of numbers from min to max. Next is exponent times bigger than previous.

class ExponentialSeries
{
public:
    ExponentialSeries(unsigned min, unsigned max, unsigned exponent = 2)
    {
        m_current = m_min = min;
        m_max = max;
        m_exponent = exponent;
    }
    void reset()
    {
        m_current = m_min;
    }
    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;
};