From 05af8217ff8dd6596f11011b7c81c0cd17f5e01d Mon Sep 17 00:00:00 2001 From: MeirGavish Date: Tue, 12 Aug 2025 01:59:04 +0300 Subject: [PATCH 1/4] Small affine background CBB/SBB fix --- source/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/main.c b/source/main.c index 76abc07..269fc09 100644 --- a/source/main.c +++ b/source/main.c @@ -44,7 +44,7 @@ void init() // BG1 is the main background layer REG_BG1CNT = BG_PRIO(1) | BG_CBB(MAIN_BG_CBB) | BG_SBB(MAIN_BG_SBB) | BG_8BPP; // BG2 is the affine background layer - REG_BG2CNT = BG_PRIO(2) | BG_CBB(AFFINE_BG_CBB) | BG_SBB(AFFINE_BG_CBB) | BG_8BPP | BG_WRAP | BG_AFF_32x32; + REG_BG2CNT = BG_PRIO(2) | BG_CBB(AFFINE_BG_CBB) | BG_SBB(AFFINE_BG_SBB) | BG_8BPP | BG_WRAP | BG_AFF_32x32; int win1_left = 72; int win1_top = 44; From 658b0572d9a391e15bf3822d803ee48031d9a673 Mon Sep 17 00:00:00 2001 From: MeirGavish Date: Tue, 12 Aug 2025 03:01:02 +0300 Subject: [PATCH 2/4] Removed all uses of float for optimization --- source/game.c | 2 +- source/sprite.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/source/game.c b/source/game.c index f58d644..83ef525 100644 --- a/source/game.c +++ b/source/game.c @@ -1576,7 +1576,7 @@ static void played_cards_update_loop(bool* discarded_card, int* played_selection FIXED played_x = int2fx(120); FIXED played_y = int2fx(70); - FIXED played_scale = float2fx(1.0f); + FIXED played_scale = FIX_ONE; played_x = played_x + (int2fx(played_top - i) - int2fx(played_top) / 2) * -27; diff --git a/source/sprite.c b/source/sprite.c index a93b953..fb973c3 100644 --- a/source/sprite.c +++ b/source/sprite.c @@ -145,9 +145,9 @@ void sprite_object_reset_transform(SpriteObject* sprite_object) sprite_object->y = 0; sprite_object->vx = 0; sprite_object->vy = 0; - sprite_object->tscale = float2fx(1.0f); // Target scale - sprite_object->scale = float2fx(1.0f); - sprite_object->vscale = float2fx(0.0f); + sprite_object->tscale = FIX_ONE; // Target scale + sprite_object->scale = FIX_ONE; + sprite_object->vscale = 0; sprite_object->trotation = 0; // Target rotation sprite_object->rotation = 0; sprite_object->vrotation = 0; @@ -163,7 +163,7 @@ void sprite_object_update(SpriteObject* sprite_object) sprite_object->vrotation += (sprite_object->trotation - sprite_object->rotation) / 8; // Rotate the card when it's played // set velocity to 0 if it's close enough to the target - const float epsilon = float2fx(0.01f); + const FIXED epsilon = FIX_ONE>>7; // 1/(2^7) = 1/128 = 0.0078125 if (sprite_object->vx < epsilon && sprite_object->vx > -epsilon && sprite_object->vy < epsilon && sprite_object->vy > -epsilon) { sprite_object->vx = 0; @@ -211,8 +211,8 @@ void sprite_object_update(SpriteObject* sprite_object) void sprite_object_shake(SpriteObject* sprite_object, mm_word sound_id) { - sprite_object->vscale = float2fx(0.3f); // Scale down the card when it's scored - sprite_object->vrotation = float2fx(8.0f); // Rotate the card when it's scored + sprite_object->vscale = FIX_ONE >> 2; // (1/4 = 0.25) Scale down the card when it's scored + sprite_object->vrotation = FIX_ONE << 3; // (2^3 = 8) Rotate the card when it's scored if (sound_id == UNDEFINED) return; // If no sound ID is provided, do nothing From 0e080b916e5caf704ffb9f86784adc59ff7b23c1 Mon Sep 17 00:00:00 2001 From: MeirGavish Date: Tue, 12 Aug 2025 11:40:22 +0300 Subject: [PATCH 3/4] Reverted removals of float2fx() as they're compiler-optimized but kept float optimization --- source/sprite.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/sprite.c b/source/sprite.c index fb973c3..df1e917 100644 --- a/source/sprite.c +++ b/source/sprite.c @@ -163,7 +163,7 @@ void sprite_object_update(SpriteObject* sprite_object) sprite_object->vrotation += (sprite_object->trotation - sprite_object->rotation) / 8; // Rotate the card when it's played // set velocity to 0 if it's close enough to the target - const FIXED epsilon = FIX_ONE>>7; // 1/(2^7) = 1/128 = 0.0078125 + const FIXED epsilon = float2fx(0.01f); if (sprite_object->vx < epsilon && sprite_object->vx > -epsilon && sprite_object->vy < epsilon && sprite_object->vy > -epsilon) { sprite_object->vx = 0; @@ -211,8 +211,8 @@ void sprite_object_update(SpriteObject* sprite_object) void sprite_object_shake(SpriteObject* sprite_object, mm_word sound_id) { - sprite_object->vscale = FIX_ONE >> 2; // (1/4 = 0.25) Scale down the card when it's scored - sprite_object->vrotation = FIX_ONE << 3; // (2^3 = 8) Rotate the card when it's scored + sprite_object->vscale = float2fx(0.3f); + sprite_object->vrotation = float2fx(8.0f); //Rotate the card when it's scored if (sound_id == UNDEFINED) return; // If no sound ID is provided, do nothing From 5ef7fa49aa8505c76d8500ba3d96e2511a3bcd1b Mon Sep 17 00:00:00 2001 From: MeirGavish Date: Tue, 12 Aug 2025 17:22:42 +0300 Subject: [PATCH 4/4] Added more undesired IDE artifacts to .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 542edaa..be9866f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ /build /.vs *.sln -*.vcxproj* \ No newline at end of file +*.vcxproj* +/balatro-gba/x64/**