From: Lukas Krickl Date: Thu, 18 Dec 2025 22:03:29 +0000 (+0100) Subject: actors are now rendered using a near and far tile system rather than pointers X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=1e0caeff414344b7bd4d6f7d68e31f2b3a34ede1;p=gbrg%2F.git actors are now rendered using a near and far tile system rather than pointers This will help prevent stale actor data being rendered --- diff --git a/src/map.s b/src/map.s index a444b0a..04f84ac 100644 --- 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 diff --git a/src/update.s b/src/update.s index 032b91e..0ff207f 100644 --- a/src/update.s +++ b/src/update.s @@ -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 diff --git a/src/wram.s b/src/wram.s index 6305210..7787718 100644 --- a/src/wram.s +++ b/src/wram.s @@ -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 +