From 5f6bc505239b1dbc5afdb096490c57d887c416eb Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Fri, 26 Sep 2025 08:48:28 +0200 Subject: [PATCH] actor: added temporary pre-calculation for rectangle points --- src/actor.s | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/wram.s | 5 +++++ 2 files changed, 62 insertions(+) diff --git a/src/actor.s b/src/actor.s index 9f8545d..aa7fad3 100644 --- a/src/actor.s +++ b/src/actor.s @@ -210,6 +210,8 @@ actor_test_movement: ld a, b ld [tmp_act_direction], a + ; a = direction + call actor_test_movement_write_points ; check all static rectangles ld hl, rectangles @@ -277,6 +279,61 @@ actor_test_movement: ; hl = actor already ld a, 1 ret + + ; writes a point to a rectangle + ; inputs: + ; hl: rectangle + ; bc: tmp_rect_points ptr + ; $1 rect_tr,bl,br,tl +#macro act_test_movement_write_point_at + push hl + push bc + call $1 + pop bc + pop hl + + ld a, d + ld [bc], a + inc bc + ld a, e + ld [bc], a + inc bc +#endmacro + + ; writes tmp rect points to + ; tmp_rect_points. only writes 2 points + ; based on the chosen direction + ; inputs: + ; a: direction + ; tmp_rect: the rectangle +actor_test_movement_write_points: + ld hl, tmp_rect + ld bc, tmp_rect_points + + cp a, DIRDOWN + jp z, @down + cp a, DIRLEFT + jp z, @left + cp a, DIRRIGHT + jp z, @right + + ; default case: up +@up: + act_test_movement_write_point_at rect_tl + act_test_movement_write_point_at rect_tr + ret +@down: + act_test_movement_write_point_at rect_bl + act_test_movement_write_point_at rect_br + ret +@right: + act_test_movement_write_point_at rect_br + act_test_movement_write_point_at rect_tr + ret +@left: + act_test_movement_write_point_at rect_bl + act_test_movement_write_point_at rect_tl + ret ; tests a single rectangle against an actor ; based on the current direction only 2 points are tested diff --git a/src/wram.s b/src/wram.s index 41420f9..5ba82e9 100644 --- a/src/wram.s +++ b/src/wram.s @@ -84,6 +84,11 @@ rectangles: .adv r_size * RECT_MAX tmp_rect: .adv r_size tmp_rect_mask: .adv 1 + ; temporary points + ; has enough space for 4 points + ; store pre-calculated points here for collision checking +tmp_rect_points: .adv 4 * 2 + ; temporary actor direction mask tmp_act_direction: .adv 1 -- 2.30.2