Took Copilot's advice and defined some magic numbers

This commit is contained in:
cellos51
2025-08-09 15:14:57 -04:00
parent 1ef0ce212b
commit 0dde0cb6ef
+9 -5
View File
@@ -7,6 +7,10 @@ BG_AFFINE bgaff;
AFF_SRC_EX asx = {32<<8, 64<<8, 120, 80, 0x0100, 0x0100, 0}; AFF_SRC_EX asx = {32<<8, 64<<8, 120, 80, 0x0100, 0x0100, 0};
static uint timer = 0; static uint timer = 0;
#define TOP_SCANLINE_OFFSET 228
#define ANIMATION_SPEED_DIVISOR 16
void affine_background_init() void affine_background_init()
{ {
memcpy32_tile8_with_palette_offset((u32*)&tile8_mem[AFFINE_BG_CBB], (const u32*)affine_background_gfxTiles, affine_background_gfxTilesLen/4, AFFINE_BG_PB); memcpy32_tile8_with_palette_offset((u32*)&tile8_mem[AFFINE_BG_CBB], (const u32*)affine_background_gfxTiles, affine_background_gfxTilesLen/4, AFFINE_BG_PB);
@@ -23,21 +27,21 @@ void affine_background_hblank()
// This fixes a visual issue where the top 3 pixels of the scanline are out of sync // This fixes a visual issue where the top 3 pixels of the scanline are out of sync
if (vcount >= 160) if (vcount >= 160)
{ {
vcount -= 228; vcount -= TOP_SCANLINE_OFFSET;
} }
const s32 timer_s32 = timer << 8; const s32 timer_s32 = timer << 8;
const s32 vcount_s32 = vcount << 8; const s32 vcount_s32 = vcount << 8;
const s16 vcount_s16 = vcount; const s16 vcount_s16 = vcount;
const s32 vcount_sine = lu_sin(vcount_s32 + timer_s32 / 16); // dividing the timer by 16 to make the animation slower const s32 vcount_sine = lu_sin(vcount_s32 + timer_s32 / ANIMATION_SPEED_DIVISOR); // dividing the timer by 16 to make the animation slower
asx.scr_x = 128; // 128 on x and y is an offset used to center the rotation asx.scr_x = (SCREEN_WIDTH / 2); // 128 on x and y is an offset used to center the rotation
asx.scr_y = vcount_s16 - 128; // scr_y must equal vcount otherwise the background will have no vertical difference asx.scr_y = vcount_s16 - (SCREEN_HEIGHT / 2); // scr_y must equal vcount otherwise the background will have no vertical difference
asx.tex_x = vcount_sine; asx.tex_x = vcount_sine;
asx.tex_y = vcount_sine / 64; asx.tex_y = vcount_sine / 64;
asx.sx = vcount_sine / 32; asx.sx = vcount_sine / 32;
asx.sy = vcount_sine / 16; asx.sy = vcount_sine / 16;
asx.alpha = (vcount_s32 + timer_s32) / 16; asx.alpha = vcount_sine + (timer_s32 / ANIMATION_SPEED_DIVISOR);
bg_rotscale_ex(&bgaff, &asx); bg_rotscale_ex(&bgaff, &asx);
REG_BG_AFFINE[2] = bgaff; REG_BG_AFFINE[2] = bgaff;