[Decompilation] Templatize subpixels to offer both 16-bit and 8-bit variants

Yup, TH03 actually uses a 4.4 fixed-point format.

Part of P0061, funded by Touhou Patch Center.
This commit is contained in:
nmlgc 2019-12-01 17:22:06 +01:00
parent bb6b0f1cc3
commit 4d3d6acd28
2 changed files with 18 additions and 7 deletions

View File

@ -7,30 +7,37 @@ inline subpixel_t to_sp(float screen_v) {
return static_cast<subpixel_t>(screen_v * 16.0f);
}
class Subpixel {
template <class T> class SubpixelBase {
public:
// Code generation will require direct access to v, if performing
// arithmetic with a local variable...
subpixel_t v;
T v;
void operator +=(float screen_v) {
this->v += to_sp(screen_v);
this->v += static_cast<T>(to_sp(screen_v));
}
void operator -=(float screen_v) {
this->v -= to_sp(screen_v);
this->v -= static_cast<T>(to_sp(screen_v));
}
void operator =(float screen_v) {
v = to_sp(screen_v);
v = static_cast<T>(to_sp(screen_v));
}
};
struct SPPoint {
Subpixel x, y;
template <class T> struct SPPointBase {
T x, y;
void set(float screen_x, float screen_y) {
x = screen_x;
y = screen_y;
}
};
// 16-bit (Q12.4)
typedef SubpixelBase<subpixel_t> Subpixel;
typedef SPPointBase<Subpixel> SPPoint;
// 8-bit (Q4.4)
typedef SubpixelBase<char> Subpixel8;
typedef SPPointBase<Subpixel8> SPPoint8;

4
th03/math/subpixel.inc Normal file
View File

@ -0,0 +1,4 @@
SPPoint8 struc
db ? ; x
db ? ; y
SPPoint8 ends