-
Notifications
You must be signed in to change notification settings - Fork 0
/
BaseValue.h
46 lines (34 loc) · 999 Bytes
/
BaseValue.h
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
44
45
46
#ifndef KALKY_BASEVALUE_H
#define KALKY_BASEVALUE_H
#include <signals.hpp>
namespace kalky {
class BaseValue {
public:
BaseValue & operator=(const BaseValue&) = delete;
BaseValue(BaseValue const &) = delete;
BaseValue() = default;
virtual ~BaseValue() {
OnValueDeleted(this);
}
fteng::signal<void(BaseValue* Value)> OnValueChanged;
fteng::signal<void(BaseValue* Value)> OnValueDeleted;
float GetValue() {
if(_isDirty)
RecalculateCachedValue();
return _cachedValue;
}
protected:
bool _isDirty = true;
float _cachedValue;
virtual void RecalculateCachedValue() = 0;
void SetValueDirty() {
_isDirty = true;
OnValueChanged(this);
}
void CacheValue(float cachedValue) {
_isDirty = false;
_cachedValue = cachedValue;
}
};
}
#endif //KALKY_BASEVALUE_H