mirror of
https://github.com/nmlgc/ReC98.git
synced 2025-02-26 20:55:09 +00:00
[Maintenance] Move the Subpixel class to a separate header, under TH03
Part of P0061, funded by Touhou Patch Center.
This commit is contained in:
parent
04d24ccf1c
commit
bb6b0f1cc3
36
th03/math/subpixel.hpp
Normal file
36
th03/math/subpixel.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
// Fixed-point format for expressing world-space coordinates, with 4 bits of
|
||||
// fractional resolution.
|
||||
|
||||
typedef int subpixel_t;
|
||||
|
||||
inline subpixel_t to_sp(float screen_v) {
|
||||
return static_cast<subpixel_t>(screen_v * 16.0f);
|
||||
}
|
||||
|
||||
class Subpixel {
|
||||
public:
|
||||
// Code generation will require direct access to v, if performing
|
||||
// arithmetic with a local variable...
|
||||
subpixel_t v;
|
||||
|
||||
void operator +=(float screen_v) {
|
||||
this->v += to_sp(screen_v);
|
||||
}
|
||||
|
||||
void operator -=(float screen_v) {
|
||||
this->v -= to_sp(screen_v);
|
||||
}
|
||||
|
||||
void operator =(float screen_v) {
|
||||
v = to_sp(screen_v);
|
||||
}
|
||||
};
|
||||
|
||||
struct SPPoint {
|
||||
Subpixel x, y;
|
||||
|
||||
void set(float screen_x, float screen_y) {
|
||||
x = screen_x;
|
||||
y = screen_y;
|
||||
}
|
||||
};
|
@ -7,39 +7,7 @@
|
||||
|
||||
/// Math
|
||||
/// ----
|
||||
typedef int subpixel_t;
|
||||
|
||||
inline subpixel_t to_sp(float screen_v) {
|
||||
return static_cast<subpixel_t>(screen_v * 16.0f);
|
||||
}
|
||||
|
||||
class Subpixel {
|
||||
public:
|
||||
// Code generation will require direct access to v, if performing
|
||||
// arithmetic with a local variable...
|
||||
subpixel_t v;
|
||||
|
||||
void operator +=(float screen_v) {
|
||||
this->v += to_sp(screen_v);
|
||||
}
|
||||
|
||||
void operator -=(float screen_v) {
|
||||
this->v -= to_sp(screen_v);
|
||||
}
|
||||
|
||||
void operator =(float screen_v) {
|
||||
v = to_sp(screen_v);
|
||||
}
|
||||
};
|
||||
|
||||
struct SPPoint {
|
||||
Subpixel x, y;
|
||||
|
||||
void set(float screen_x, float screen_y) {
|
||||
x = screen_x;
|
||||
y = screen_y;
|
||||
}
|
||||
};
|
||||
#include "th03/math/subpixel.hpp"
|
||||
|
||||
typedef struct {
|
||||
SPPoint cur;
|
||||
|
Loading…
x
Reference in New Issue
Block a user