actors: actor table is now split into logical groups
authorLukas Krickl <lukas@krickl.dev>
Mon, 29 Sep 2025 04:36:30 +0000 (06:36 +0200)
committerLukas Krickl <lukas@krickl.dev>
Mon, 29 Sep 2025 04:36:30 +0000 (06:36 +0200)
This allows making collision detection do less work

src/actor.s
src/defs.s
src/mapobj.s
src/player.s
src/wram.s

index 3e5f8949b10b1dee503dfd1f049b707ac8c32e47..59819024f2646e5baf6fac477664b02fcb45b913 100644 (file)
@@ -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
index b77f0c41859eab6d90ed595c0d9d3d18109d2626..b0b0399f157727362e64330c4a6926c7be284bab 100644 (file)
 
 #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
 
index e182f2d28b16a282a65aa1440ab5ba171bda6dd3..8c0bd40c83ba47888c05204b2b4ef80095cfbc5d 100644 (file)
@@ -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
index 28c672b2c68e991b6b24be196ba1e08f9a47134c..98f2e17de6ed3fc51421fbbac974ab1a30eac0dd 100644 (file)
@@ -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
index 048107ad60d5d47bdc57f872385b9b853733c883..d04901ead9bb8382cfd51282d3607336e2af037f 100644 (file)
@@ -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