// Fixed-point format for expressing world-space coordinates, with 4 bits of // fractional resolution. #define PIXEL_NONE (-999) typedef int subpixel_t; #define TO_SP(v) \ (v << 4) inline subpixel_t to_sp(float pixel_v) { return static_cast(pixel_v * 16.0f); } template class SubpixelBase { public: typedef SubpixelBase SelfType; // Code generation will require direct access to v, if performing // arithmetic with a local variable... SubpixelType v; SubpixelType operator +(float pixel_v) { return (this->v + static_cast(to_sp(pixel_v))); } SubpixelType operator -(const SelfType &other) { return (this->v - other.v); } void operator +=(float pixel_v) { this->v += static_cast(to_sp(pixel_v)); } void operator -=(float pixel_v) { this->v -= static_cast(to_sp(pixel_v)); } // No overloads of `operator =()`, since the class needs to be trivially // copyable. void set(float pixel_v) { v = static_cast(to_sp(pixel_v)); } void set(const PixelType &pixel_v) { v = static_cast(TO_SP(pixel_v)); } PixelType to_pixel() const { return static_cast(v >> 4); } PixelType to_pixel_slow() const { // MODDERS: Delete return (v / 16); } operator SubpixelType() const { return v; } static SubpixelType None() { return static_cast(TO_SP(PIXEL_NONE)); } }; template struct SPPointBase { T x, y; void set(float screen_x, float screen_y) { x.set(screen_x); y.set(screen_y); } }; // 16-bit (Q12.4) typedef SubpixelBase Subpixel; typedef SPPointBase SPPoint; // 8-bit (Q4.4) typedef SubpixelBase SubpixelLength8; typedef SubpixelBase Subpixel8; typedef SPPointBase SPPoint8;