#ifndef BUFFERED_VALUE_H #define BUFFERED_VALUE_H #include "math/Math.h" template class BufferedValue { T last; T current; public: BufferedValue(const T& t) : last(t), current(t) { } void update() { last = current; } T get(float lag) const { return Math::interpolate(last, current, lag); } template BufferedValue& operator=(const O& o) { current = o; return *this; } template BufferedValue& operator+=(const O& o) { current += o; return *this; } template BufferedValue& operator-=(const O& o) { current -= o; return *this; } template BufferedValue& operator*=(const O& o) { current *= o; return *this; } template BufferedValue& operator/=(const O& o) { current /= o; return *this; } template auto operator+(const O& o) const { return current + o; } template auto operator-(const O& o) const { return current - o; } template auto operator*(const O& o) const { return current * o; } template auto operator/(const O& o) const { return current / o; } auto operator-() const { return -current; } auto& operator[](int index) { return current[index]; } const auto& operator[](int index) const { return current[index]; } operator T&() { return current; } operator const T&() const { return current; } }; #endif