123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- #ifndef CORE_BUFFERED_VALUE_HPP
- #define CORE_BUFFERED_VALUE_HPP
- #include "math/Math.hpp"
- namespace Core {
- template<typename T>
- class BufferedValue final {
- 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<typename O>
- BufferedValue& operator=(const O& o) {
- current = o;
- return *this;
- }
- template<typename O>
- BufferedValue& operator+=(const O& o) {
- current += o;
- return *this;
- }
- template<typename O>
- BufferedValue& operator-=(const O& o) {
- current -= o;
- return *this;
- }
- template<typename O>
- BufferedValue& operator*=(const O& o) {
- current *= o;
- return *this;
- }
- template<typename O>
- BufferedValue& operator/=(const O& o) {
- current /= o;
- return *this;
- }
- template<typename O>
- auto operator+(const O& o) const {
- return current + o;
- }
- template<typename O>
- auto operator-(const O& o) const {
- return current - o;
- }
- template<typename O>
- auto operator*(const O& o) const {
- return current * o;
- }
- template<typename O>
- 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
|