diff --git a/th01/math/subpixel.hpp b/th01/math/subpixel.hpp index 468a3987..d4864469 100644 --- a/th01/math/subpixel.hpp +++ b/th01/math/subpixel.hpp @@ -5,6 +5,7 @@ #define PIXEL_NONE (-999) +typedef uint8_t subpixel_length_8_t; typedef int subpixel_t; static const subpixel_t SUBPIXEL_FACTOR = 16; @@ -24,8 +25,8 @@ inline subpixel_t to_sp(float pixel_v) { return static_cast(pixel_v * SUBPIXEL_FACTOR); } -inline unsigned char to_sp8(float pixel_v) { - return static_cast(to_sp(pixel_v)); +inline subpixel_length_8_t to_sp8(float pixel_v) { + return static_cast(to_sp(pixel_v)); } template class SubpixelBase { @@ -100,6 +101,6 @@ struct SPPoint : public SPPointBase { }; // 8-bit (Q4.4) -typedef SubpixelBase SubpixelLength8; +typedef SubpixelBase SubpixelLength8; typedef SubpixelBase Subpixel8; typedef SPPointBase SPPoint8; diff --git a/th04/main/bullet/add.cpp b/th04/main/bullet/add.cpp index 11b96598..29554260 100644 --- a/th04/main/bullet/add.cpp +++ b/th04/main/bullet/add.cpp @@ -21,7 +21,7 @@ void near tune_for_easy(void) switch(tmpl.group) { case BG_STACK: case BG_STACK_AIMED: - tmpl.delta.stack_speed -= (tmpl.delta.stack_speed / 4); + tmpl.delta.stack_speed.v -= (tmpl.delta.stack_speed.v / 4); if(tmpl.count >= 2) { tmpl.count--; } @@ -48,17 +48,17 @@ void near tune_for_hard(void) case BG_SINGLE_AIMED: tmpl.group = BG_STACK_AIMED; tmpl.count = 2; - tmpl.delta.stack_speed = to_sp(0.375f); + tmpl.delta.stack_speed.set(0.375f); break; case BG_SINGLE: tmpl.group = BG_STACK; tmpl.count = 2; - tmpl.delta.stack_speed = to_sp(0.375f); + tmpl.delta.stack_speed.set(0.375f); break; case BG_STACK: case BG_STACK_AIMED: - tmpl.delta.stack_speed += (tmpl.delta.stack_speed / 2); + tmpl.delta.stack_speed.v += (tmpl.delta.stack_speed.v / 2); break; case BG_SPREAD: @@ -98,7 +98,7 @@ void near tune_for_lunatic(void) case BG_STACK: case BG_STACK_AIMED: - tmpl.delta.stack_speed += (tmpl.delta.stack_speed / 2); + tmpl.delta.stack_speed.v += (tmpl.delta.stack_speed.v / 2); tmpl.count++; break; @@ -188,7 +188,7 @@ void pascal near bullet_template_tune_lunatic(void) void pascal near bullets_add_regular_easy(void) { - unsigned char speed; + subpixel_length_8_t speed; unsigned char count; if(bullet_zap.active) { @@ -202,7 +202,7 @@ void pascal near bullets_add_regular_easy(void) } inline void keep_speed_from_being_mutated_when_calling(nearfunc_t_near func) { - unsigned char speed = bullet_template.speed.v; + subpixel_length_8_t speed = bullet_template.speed.v; func(); bullet_template.speed.v = speed; } @@ -274,7 +274,7 @@ void near bullets_add_special_fixedspeed(void) bool16 pascal near bullet_velocity_and_angle_set(int group_i) { int angle = 0x00; - unsigned char speed; + subpixel_length_8_t speed; bool done; // Due to this default, invalid group values lead to the spawn functions @@ -550,7 +550,7 @@ void pascal near bullets_add_regular_raw(void) bullet->flag = 1; bullet->move_state = static_cast(move_state); bullet->ax.slowdown_time = BMS_SLOWDOWN_FRAMES; - bullet->dx.slowdown_speed_delta = ( + bullet->dx.slowdown_speed_delta.v = ( to_sp8(BMS_SLOWDOWN_BASE_SPEED) - bullet_template.speed ); bullet_init_from_template(bullet, group_done, group_i, spawn_state); diff --git a/th04/main/bullet/bullet.hpp b/th04/main/bullet/bullet.hpp index 93f48316..1659295a 100644 --- a/th04/main/bullet/bullet.hpp +++ b/th04/main/bullet/bullet.hpp @@ -138,8 +138,8 @@ struct bullet_t { union { // Difference between [speed_final] and the BMS_SLOWDOWN_BASE_SPEED. // Always positive for BMS_SLOWDOWN bullets. - unsigned char slowdown_speed_delta; // with BMS_SLOWDOWN - bullet_special_angle_t angle; // with BMS_SPECIAL + SubpixelLength8 slowdown_speed_delta; // with BMS_SLOWDOWN + bullet_special_angle_t angle; // with BMS_SPECIAL } dx; int patnum; diff --git a/th04/main/bullet/types.h b/th04/main/bullet/types.h index 69a426ae..4c36e64e 100644 --- a/th04/main/bullet/types.h +++ b/th04/main/bullet/types.h @@ -1,8 +1,6 @@ typedef union { unsigned char spread_angle; - // In subpixels, obviously, but pre-C++11 doesn't let us use any of the - // Subpixel classes with their custom assignment operators in a union... - unsigned char stack_speed; + SubpixelLength8 stack_speed; } bullet_template_delta_t; // All _AIMED groups define the 0° [angle] as the current player position, diff --git a/th04/main/bullet/update.cpp b/th04/main/bullet/update.cpp index a71611d8..381fa418 100644 --- a/th04/main/bullet/update.cpp +++ b/th04/main/bullet/update.cpp @@ -309,7 +309,7 @@ void bullets_update(void) } else if(bullet->move_state == BMS_SLOWDOWN) { bullet->ax.slowdown_time--; bullet->speed_cur.v = (bullet->speed_final.v + (( - bullet->ax.slowdown_time * bullet->dx.slowdown_speed_delta + bullet->ax.slowdown_time * bullet->dx.slowdown_speed_delta.v ) / BMS_SLOWDOWN_FRAMES)); if(bullet->ax.slowdown_time == 0) { bullet->speed_cur = bullet->speed_final; diff --git a/th05/main/bullet/clip.cpp b/th05/main/bullet/clip.cpp index 27afd343..9e184e51 100644 --- a/th05/main/bullet/clip.cpp +++ b/th05/main/bullet/clip.cpp @@ -50,7 +50,7 @@ clipped: } if(!group_fixedspeed) { - bullet_template.speed = playperf_speedtune(bullet_template.speed); + bullet_template.speed.v = playperf_speedtune(bullet_template.speed.v); } return false; } diff --git a/th05/main/playperf.hpp b/th05/main/playperf.hpp index 701b10d3..dbfc33f1 100644 --- a/th05/main/playperf.hpp +++ b/th05/main/playperf.hpp @@ -1,4 +1,6 @@ #include "th04/main/playperf.hpp" // Returns [speed] tuned based on [playperf]. -SubpixelLength8 __fastcall near playperf_speedtune(unsigned char speed); +subpixel_length_8_t __fastcall near playperf_speedtune( + subpixel_length_8_t speed +);