mirror of
https://github.com/zeldaret/ss
synced 2026-08-05 17:43:38 -04:00
Match the single-counter TUs
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
#ifndef COUNTER_H
|
||||
#define COUNTER_H
|
||||
|
||||
#include <common.h>
|
||||
|
||||
class Counter {
|
||||
public:
|
||||
Counter(u16 id): counterId(id) {}
|
||||
// No vtable, this class appears to be header-only
|
||||
virtual ~Counter() {};
|
||||
/* 8016cc40 */ virtual s32 checkedAdd(s32 num) {
|
||||
s32 uncommitted = getUncommittedValue();
|
||||
s32 max = getMax();
|
||||
s32 result = uncommitted + num;
|
||||
if (result < 0) {
|
||||
setValue(0);
|
||||
} else if (result < max) {
|
||||
setValue(result);
|
||||
} else {
|
||||
setValue(max);
|
||||
}
|
||||
|
||||
if (result < 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return result <= max ? 0 : (result - max);
|
||||
}
|
||||
virtual u16 getCommittedValue() {
|
||||
return 0;
|
||||
}
|
||||
virtual u16 getMax() = 0;
|
||||
virtual u16 getUncommittedValue() {
|
||||
return 0;
|
||||
}
|
||||
virtual void setValue(u16 num) {
|
||||
return;
|
||||
}
|
||||
|
||||
u16 counterId;
|
||||
};
|
||||
|
||||
#endif COUNTER_H
|
||||
Reference in New Issue
Block a user