Skip to content

Commit

Permalink
[Maintenance] Publicly declare decimal subpixels
Browse files Browse the repository at this point in the history
They are not exclusive to Sariel after all…

Part of P0205, funded by [Anonymous] and Yanga.
  • Loading branch information
nmlgc committed Jul 17, 2022
1 parent 3259190 commit f6d264a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
16 changes: 0 additions & 16 deletions th01/main/boss/b20m.cpp
Expand Up @@ -2330,22 +2330,6 @@ void pascal near pattern_curved_spray_leftright_twice(int &frame)
}
}

// Subpixels with one decimal digit of fractional resolution?! Sure, if you
// absolutely want those precise multiples of 0.1 in your movement code...
typedef int decimal_subpixel_t;

struct DecimalSubpixel {
decimal_subpixel_t v;

pixel_t to_pixel() const {
return static_cast<pixel_t>(v / 10);
}
};

inline decimal_subpixel_t to_dsp(float pixel_v) {
return static_cast<decimal_subpixel_t>(pixel_v * 10);
}

void pascal near pattern_swaying_leaves(int &frame, int spawn_interval_or_reset)
{
enum {
Expand Down
21 changes: 21 additions & 0 deletions th01/math/subpixel.hpp
@@ -1,5 +1,6 @@
// Fixed-point format for expressing world-space coordinates, with 4 bits of
// fractional resolution.
// -------------------------------------------------------------------------

#define SUBPIXEL_HPP

Expand Down Expand Up @@ -104,3 +105,23 @@ struct SPPoint : public SPPointBase<Subpixel> {
typedef SubpixelBase<subpixel_length_8_t, subpixel_length_8_t> SubpixelLength8;
typedef SubpixelBase<char, char> Subpixel8;
typedef SPPointBase<Subpixel8> SPPoint8;
// -------------------------------------------------------------------------

// Subpixels with one decimal digit of fractional resolution?! Sure, if you
// absolutely want those precise multiples of 0.1 in your movement code...
// -------------------------------------------------------------------------

typedef int decimal_subpixel_t;

struct DecimalSubpixel {
decimal_subpixel_t v;

pixel_t to_pixel() const {
return static_cast<pixel_t>(v / 10);
}
};

inline decimal_subpixel_t to_dsp(float pixel_v) {
return static_cast<decimal_subpixel_t>(pixel_v * 10);
}
// -------------------------------------------------------------------------

0 comments on commit f6d264a

Please sign in to comment.