actors are now rendered using a near and far tile system rather than pointers
authorLukas Krickl <lukas@krickl.dev>
Thu, 18 Dec 2025 22:03:29 +0000 (23:03 +0100)
committerLukas Krickl <lukas@krickl.dev>
Thu, 18 Dec 2025 22:03:29 +0000 (23:03 +0100)
This will help prevent stale actor data being rendered

src/map.s
src/update.s
src/wram.s

index a444b0ac176d8955d85a5958c6f58971a94583c0..04f84ac0cf2b652fbe222707a1c7e5b949625564 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -342,32 +342,20 @@ map_get_tile:
 .endscope
 #endmacro
        
-       ; writes the input tiles
-       ; act and prop into act_nearby and prop_nearby
-       ; inputs:
-       ;               hl: tile
-       ; preserves: 
-       ;               all registers
-map_write_nearby_act_prop:
-       push_all
-
-       ld de, t_act
-       add hl, de
-       
-       ; write act
-       ld a, [hl+]
-       ld [act_nearby], a
-       ld a, [hl+]
-       ld [act_nearby+1], a
-
-       ; write prop
-       ld a, [hl+]
-       ld [prop_nearby], a
-       ld a, [hl]
-       ld [prop_nearby+1], a
        
-       pop_all
-       ret
+       ; writes the nearby tile information
+       ; for tile_near, tile_far etc
+       ; inputs:
+       ;               bc: y/x coordinate
+       ;    $1: offset (0 for tile_near, 2 for tile far)
+#macro _map_write_nearby_tile
+       push af
+       ld a, b
+       ld [tile_near+$1], a
+       ld a, c
+       ld [tile_near+1+$1], a
+       pop af
+#endmacro
 
        ; counts the tiles the player can move forward
        ;       inputs:
@@ -379,6 +367,8 @@ map_write_nearby_act_prop:
        ;               tmp_map_near_right_door: 0/1 door present or not
        ;   tmp_map_far_left_door: 0/1 door present or not
        ;       tmp_map_far_right_door 0/1 door present or not
+       ;   tile_near: near tile coordinates
+       ;               tile_far: far tile coordinates
 map_full_draw_count_forward_attributes:
        xor a, a
        ld [tmp_map_forward], a
@@ -387,11 +377,13 @@ map_full_draw_count_forward_attributes:
        ld [tmp_map_far_left_door], a
        ld [tmp_map_far_right_door], a
 
-       ; clear nearby prop and act
-       ld [act_nearby], a
-       ld [act_nearby+1], a
-       ld [prop_nearby], a
-       ld [prop_nearby+1], a
+
+       ; clear tile_near and tile_far
+       ld a, 0xFF 
+       ld [tile_near], a
+       ld [tile_near+1], a
+       ld [tile_far], a
+       ld [tile_far+1], a
 
        ld a, [player+act_pos_y]
        ld b, a
@@ -405,6 +397,7 @@ map_full_draw_count_forward_attributes:
        ld a, [player+act_dir]
        and a, ACT_DIR_MASK
 
+       _map_write_nearby_tile 0
 
        ; which routine to run to find values?
        cp a, SOUTH
@@ -420,8 +413,8 @@ map_full_draw_count_forward_attributes:
        map_full_draw_write_door_state 1, 1, ret
 
        dec b ; move one tile back
+       _map_write_nearby_tile 2
        call map_get_tile
-       call map_write_nearby_act_prop
 
        map_full_draw_door_state TF_NE, TF_WE, TF_EE
        map_full_draw_write_door_state 3, 2, ret
@@ -431,8 +424,8 @@ map_full_draw_count_forward_attributes:
        map_full_draw_write_door_state 1, 1, ret
        
        inc b ; move one tile forward
+       _map_write_nearby_tile 2
        call map_get_tile
-       call map_write_nearby_act_prop
 
        map_full_draw_door_state TF_SE, TF_WE, TF_EE
        map_full_draw_write_door_state 3, 2, ret
@@ -442,8 +435,8 @@ map_full_draw_count_forward_attributes:
        map_full_draw_write_door_state 1, 1, ret
 
        inc c ; move one tile east
+       _map_write_nearby_tile 2
        call map_get_tile
-       call map_write_nearby_act_prop
 
        map_full_draw_door_state TF_EE, TF_NE, TF_SE
        map_full_draw_write_door_state 3, 2, ret
@@ -453,8 +446,8 @@ map_full_draw_count_forward_attributes:
        map_full_draw_write_door_state 1, 1, ret
 
        dec c ; move one tile west
+       _map_write_nearby_tile 2
        call map_get_tile
-       call map_write_nearby_act_prop
 
        map_full_draw_door_state TF_WE, TF_SE, TF_NE
        map_full_draw_write_door_state 3, 2, ret
index 032b91e2c7f0041e4d8281901ad6de6c5c00e7e0..0ff207fc60cfe61d6dd213e4c35cc4b526b64abc 100644 (file)
@@ -18,19 +18,33 @@ update_game:
        ; TODO: update map routine
 
        ; draw actors and props
+       ; on nearby tiles
        ; if the ptr is not NULL
-       ld a, [act_nearby]
+       ld a, [tile_far]
+       ld b, a
+       ld a, [tile_far+1]
+       ld c, a
+       call map_get_tile
+       ; hl = tile far
+       push hl
+       
+       ; load t_act
+       ld de, t_act
+       add hl, de
+       ld a, [hl+]
+       ld e, [hl]
        ld d, a
-       ld a, [act_nearby+1]
-       ld e, a
-       or a, d 
+       or a, e ; check if it is null
        call nz, act_draw_nearby
-
-       ld a, [prop_nearby]
+       pop hl
+       
+       ; load t_prop
+       ld de, t_prop
+       add hl, de
+       ld a, [hl+]
+       ld e, [hl]
        ld d, a
-       ld a, [prop_nearby+1]
-       ld e, a
-       or a, d 
+       or a, e ; check if it is null
        call nz, act_draw_nearby
 
   ret
index 6305210a773426b3b6b66cab6acceb190c5bd0a9..778771829d15fc376bf84c07936d80139c529534 100644 (file)
@@ -132,14 +132,9 @@ tmp_map_far_left_door: .adv 1
 tmp_map_far_right_door: .adv 1
 tmp_act_y: .adv 1
 tmp_act_x: .adv 1
-       
-       ; actor that is adjacent
-       ; to the players current facing
-       ; direction
-       ; populated when map is drawn
-act_nearby: .adv 2
-       ; prop actor that is adjacent 
-       ; to the current players facing direction
-       ; populated when map is drawn
-prop_nearby: .adv 2
-       
+
+       ; coordinates for up to 2 tiles
+       ; set to 0xFF if no tile is present
+tile_near: .adv 2
+tile_far: .adv 2
+