Update some things.

This commit is contained in:
Signal 2026-04-06 18:30:52 -04:00
parent f215bc3742
commit f9d6e7a70a
35 changed files with 575 additions and 905 deletions

View file

@ -75,12 +75,73 @@ public:
class BaseSubsystem {
public:
Engine<BaseSubsystem> * engine = nullptr;
virtual void init() {}
virtual void reload() {}
virtual void deinit() {}
virtual void render() {}
virtual void tick() {}
};
template<typename T> requires std::integral<T> || std::floating_point<T>
class Composed {
enum ModifierType {
Add, Multiply
};
using Modifier = std::pair<ModifierType, T>;
uint64_t nextID = 0;
std::vector<Modifier> modifiers;
T _value;
public:
Composed() : Composed(T{0}) {}
Composed(T base) {
add(Add, base);
}
T value() {
return _value;
}
void recompute() {
T sum;
T fac;
for (auto [type, value] : modifiers) {
if (type == Add) {
sum += value;
} else if (type == Multiply) {
fac *= value;
}
}
_value = sum * fac;
}
uint64_t add(ModifierType type, T value) {
modifiers.emplace_back(type, value);
recompute();
return nextID++;
}
bool remove(uint64_t id) {
auto it = std::find_if(modifiers.begin(), modifiers.end(),
[id](const Modifier & m) { return m.id == id; });
if (it == modifiers.end()) return false;
modifiers.erase(it);
recompute();
return true;
}
bool update(uint64_t id, T newValue) {
auto it = std::find_if(modifiers.begin(), modifiers.end(),
[id](const Modifier& m) { return m.id == id; });
if (it == modifiers.end()) return false;
it->value = newValue;
recompute();
return true;
}
};
void log(std::string msg);
}