From 4d3d6acd2857fe77434951503c1d59e7125bd856 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Sun, 1 Dec 2019 17:22:06 +0100 Subject: [PATCH] [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. --- th03/math/subpixel.hpp | 21 ++++++++++++++------- th03/math/subpixel.inc | 4 ++++ 2 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 th03/math/subpixel.inc diff --git a/th03/math/subpixel.hpp b/th03/math/subpixel.hpp index 3e0b5d1e..f9b3f527 100644 --- a/th03/math/subpixel.hpp +++ b/th03/math/subpixel.hpp @@ -7,30 +7,37 @@ inline subpixel_t to_sp(float screen_v) { return static_cast(screen_v * 16.0f); } -class Subpixel { +template 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(to_sp(screen_v)); } void operator -=(float screen_v) { - this->v -= to_sp(screen_v); + this->v -= static_cast(to_sp(screen_v)); } void operator =(float screen_v) { - v = to_sp(screen_v); + v = static_cast(to_sp(screen_v)); } }; -struct SPPoint { - Subpixel x, y; +template 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; +typedef SPPointBase SPPoint; +// 8-bit (Q4.4) +typedef SubpixelBase Subpixel8; +typedef SPPointBase SPPoint8; diff --git a/th03/math/subpixel.inc b/th03/math/subpixel.inc new file mode 100644 index 00000000..2c46e5ef --- /dev/null +++ b/th03/math/subpixel.inc @@ -0,0 +1,4 @@ +SPPoint8 struc + db ? ; x + db ? ; y +SPPoint8 ends