From 28c1aff2d7b57dbd461b0bd514dcafba04cabb69 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Mon, 29 Sep 2025 06:36:30 +0200 Subject: [PATCH] actors: actor table is now split into logical groups This allows making collision detection do less work --- src/actor.s | 37 ++++++++++++++++++++++++++++++++----- src/defs.s | 9 +++++++-- src/mapobj.s | 2 +- src/player.s | 4 +++- src/wram.s | 5 ++++- 5 files changed, 47 insertions(+), 10 deletions(-) diff --git a/src/actor.s b/src/actor.s index 3e5f894..5981902 100644 --- a/src/actor.s +++ b/src/actor.s @@ -1,14 +1,29 @@ + ; same as actor_try_add + ; without inputs +actor_try_add_player_projectile: + ld hl, actors_player_projectiles + ld b, ACTS_PLAYER_PROJECTILES + jp actor_try_add + + ; same as actor_try_add + ; without inputs +actor_try_add_enemy: + ld hl, actors_enemy + ld b, ACTS_ENEMY + jp actor_try_add + ; attempts to spawna a new actor ; by searching for a free slot of type 0 + ; inputs: + ; hl: actor table + ; b: max ; returns: ; hl: free actor ptr ; hl: NULL if no slot is available ; note: memory is not cleared ; the caller will have to initialize the actor actor_try_add: - ld b, ACTS_MAX - ld hl, actors ld de, act_size @loop: ld a, [hl] ; check type @@ -236,6 +251,8 @@ actor_write_default_collider: ; tests movement against all collision rectangles ; inputs: + ; hl: actor table start + ; c: actor table length ; a: collision mask ; b: direction ; de: current actor (this actor is skipped) @@ -245,6 +262,11 @@ actor_write_default_collider: ; a == 1: collision ; hl: if collided with an actor points to the actor hit, otherwise NULL actor_test_movement: + ; save actor table info + push hl + push bc + + ; save current actor push de ld [tmp_rect_mask], a @@ -268,10 +290,11 @@ actor_test_movement: jp nz, @rect_test_loop pop de - ld b, ACTS_MAX + 1 ; +1 to include player - ; start at player actor - ld hl, player + pop bc + ld b, c ; b = actor table lenth + + pop hl ; hl = actor table @actor_test_loop: ld a, [hl] @@ -311,7 +334,11 @@ actor_test_movement: xor a, a ; no collision ret @rect_collision: + ; need to pop 3 values that were pushed + ; before rect loop pop de + pop hl + pop bc ld hl, NULL ld a, 1 ret diff --git a/src/defs.s b/src/defs.s index b77f0c4..b0b0399 100644 --- a/src/defs.s +++ b/src/defs.s @@ -13,9 +13,14 @@ #define NULL 0 -#define ACTS_MAX 16 +#define ACTS_PLAYER_PROJECTILES 3 +#define ACTS_ENEMY 6 +#define ACTS_ENEMY_PROJECTILES 6 +#define ACTS_MAX (ACTS_PLAYER_PROJECTILES + ACTS_ENEMY + ACTS_ENEMY_PROJECTILES) + + #define MAP_OBJ_MAX 32 -#define RECT_MAX 12 +#define RECT_MAX 6 #define MAP_ROW_H 16 ; pixels per row diff --git a/src/mapobj.s b/src/mapobj.s index e182f2d..8c0bd40 100644 --- a/src/mapobj.s +++ b/src/mapobj.s @@ -172,7 +172,7 @@ mo_actor_spawner: add hl, de push hl - call actor_try_add + call actor_try_add_enemy pop de ld a, h or a, l diff --git a/src/player.s b/src/player.s index 28c672b..98f2e17 100644 --- a/src/player.s +++ b/src/player.s @@ -220,6 +220,8 @@ player_try_move: ld b, a ; b = direction ld a, RF_WALL | RF_ENEMY ld de, player + ld hl, actors_enemy + ld c, ACTS_ENEMY call actor_test_movement pop bc @@ -262,7 +264,7 @@ player_draw: player_shoot: ; TODO: check player curr weapon - call actor_try_add + call actor_try_add_player_projectile ld a, h or a, l ret z diff --git a/src/wram.s b/src/wram.s index 048107a..d04901e 100644 --- a/src/wram.s +++ b/src/wram.s @@ -73,7 +73,10 @@ player_curr_weapon: .adv 1 player: .adv act_size ; actor table should follow player! -actors: .adv act_size * ACTS_MAX +actors: +actors_enemy: .adv act_size * ACTS_ENEMY +actors_enemy_projectiles: .adv act_size * ACTS_ENEMY_PROJECTILES +actors_player_projectiles: .adv act_size * ACTS_PLAYER_PROJECTILES map_objs: .adv mo_size * MAP_OBJ_MAX -- 2.30.2