From 0e30924bb16f729b1ba574c2248110ecd6ca359d Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Wed, 1 Oct 2025 22:18:42 +0200 Subject: [PATCH] rectangle collision: Removed redundant point comparisons --- src/rectangle.s | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/rectangle.s b/src/rectangle.s index 99d3a10..6bedb4e 100644 --- a/src/rectangle.s +++ b/src/rectangle.s @@ -165,8 +165,6 @@ rect_point_test: ; load bottom left point ld a, [hl+] - ; TODO: remove use of d2 - ld [d2], a ; save y in d2 ld d, a ; d = y ld a, [hl+] ld e, a ; e = x @@ -191,13 +189,11 @@ rect_point_test: ld d, a ; d = top left y pop hl + ; x was already tested in bottom left + ld a, b ; compare y points cp a, d jr c, @no_collision REL - ld a, c ; compare x position - cp a, e - jr c, @no_collision REL - ; top right @@ -208,6 +204,8 @@ rect_point_test: capoverflow ld e, a + ; top right has unique x and y positions + ld a, b ; compare y cp a, d jr c, @no_collision REL @@ -218,17 +216,12 @@ rect_point_test: ; bottom right - ; remove height from y - ; to get bottom right point - ld a, [d2] ; d2 = original y point - ld d, a + ; original y position was already tested in bottom left + ; x positions was already tested in top right - ld a, b ; compare y - cp a, d - jr nc, @no_collision REL - ld a, c ; compare x - cp a, e - jr nc, @no_collision REL + ; all other missing x/y checks have + ; already been performed in previous points + ; e.g. original y is tested in bottom left @collision: ld a, 1 -- 2.30.2