[Maintenance] Add a new typedef for unsigned Q4.4 values

Part of P0185, funded by [Anonymous], -Tom-, and Blue Bolt.
This commit is contained in:
nmlgc 2022-02-27 00:36:22 +01:00
parent 3850f8aafb
commit 360e07a413
7 changed files with 21 additions and 20 deletions

View File

@ -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<subpixel_t>(pixel_v * SUBPIXEL_FACTOR);
}
inline unsigned char to_sp8(float pixel_v) {
return static_cast<unsigned char>(to_sp(pixel_v));
inline subpixel_length_8_t to_sp8(float pixel_v) {
return static_cast<subpixel_length_8_t>(to_sp(pixel_v));
}
template <class SubpixelType, class PixelType> class SubpixelBase {
@ -100,6 +101,6 @@ struct SPPoint : public SPPointBase<Subpixel> {
};
// 8-bit (Q4.4)
typedef SubpixelBase<unsigned char, unsigned char> SubpixelLength8;
typedef SubpixelBase<subpixel_length_8_t, subpixel_length_8_t> SubpixelLength8;
typedef SubpixelBase<char, char> Subpixel8;
typedef SPPointBase<Subpixel8> SPPoint8;

View File

@ -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<bullet_move_state_t>(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);

View File

@ -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;

View File

@ -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,

View File

@ -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;

View File

@ -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;
}

View File

@ -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
);