From: Lukas Krickl Date: Thu, 15 Jan 2026 07:47:14 +0000 (+0100) Subject: map: wip recursive flood map uncover marker X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=8fd66211205472588a39f5329fe24fb89f2bac6a;p=gbrg%2F.git map: wip recursive flood map uncover marker --- diff --git a/src/defs.s b/src/defs.s index df9709b..0e23edf 100644 --- a/src/defs.s +++ b/src/defs.s @@ -126,6 +126,9 @@ .de TT_DOOR, 1 ; wall inside of a room .de TT_INNER_WALL, 1 + ; this marks the end of a room + ; doors turn into this tile type +.de TT_ROOM_END, 1 ; tile flags0 diff --git a/src/map.s b/src/map.s index 0ee3ffc..3aebd16 100644 --- a/src/map.s +++ b/src/map.s @@ -32,6 +32,8 @@ map_load: call lcd_on call vblank_wait call enableinterrupts + + call map_uncover_player call map_full_draw call update_render @@ -281,7 +283,7 @@ map_set_visible_row: ; hl = tile ld a, [hl] - or a, TF0_VISIBLE | TF0_UNCOVERED + or a, TF0_VISIBLE ld [hl], a @skip: @@ -480,15 +482,16 @@ map_full_draw: ret ; marks a single tile + ; recursively calls mark until walls are hit + ; returns when a wall is hit, or a tile has already been marked, or TT_ROOM_END tile is seen ; inputs: ; b/c: y/x - ; returns: - ; a: 1 -> is wall - ; a: 0 -> is not wall -_map_uncover_mark: + ; map_mark_flag: flag to set/check for + ; preserves: + ; bc +_map_mark: push bc call map_get_tile - pop bc ld a, [hl+] ; check type ; hl = flags @@ -498,28 +501,59 @@ _map_uncover_mark: cp a, TT_DOOR jr z, @mark_but_exit REL + cp a, TT_WALL + jr z, @mark_but_exit REL + + cp a, TT_ROOM_END + jr z, @mark_but_exit REL + ld a, [hl] and a, TF0_WALL - jr z, @mark REL - - ; wall - ld a, 1 - ret + jr nz, @mark_but_exit REL @mark: - ld a, [hl] - or a, TF0_UNCOVERED + ld a, [map_mark_flag] + ; is the flag already set + ld b, [hl] + and a, b + jr nz, @exit REL ; bail if alrady set + + ld b, [hl] + ld a, [map_mark_flag] + or a, b + ld [hl], a - - ; not wall - ld a, 0 + +@mark_adjacent: + pop bc + push bc + dec b ; tile up + call _map_mark + + pop bc + push bc + inc b ; tile down + call _map_mark + + pop bc + push bc + dec c ; tile left + call _map_mark + + pop bc + push bc + inc c ; tile right + call _map_mark + +@exit: + pop bc ret @mark_but_exit: - ld a, [hl] - or a, TF0_UNCOVERED + ld b, [hl] + ld a, [map_mark_flag] + or a, b ld [hl], a - ; wall - ld a, 1 + pop bc ret ; same as map uncover @@ -536,58 +570,9 @@ map_uncover_player: ; inputs: ; b/c: y/x coordinate to start at map_uncover: - - ; 1) go up until we hit a wall that is not an internal wall type -@find_top: - push bc - call map_get_tile - ld a, [hl+] ; get type - - cp a, TT_INNER_WALL - jr z, @next_find_top REL - - cp a, TT_DOOR - jr z, @next_find_top REL - - ; hl = flags0 - ld a, [hl] - and a, TF0_WALL - jr nz, @done_find_top REL -@next_find_top: - pop bc - dec b ; y-- - jr @find_top REL -@done_find_top: - pop bc - inc b ; go one down again to get the last non-wall tile - - ; now bc == top y / x -@mark_all: - push bc -@mark_left: - ; now go as far left as possible (until wall is hit) - call _map_uncover_mark - dec c ; x-- - cp a, 0 - jr z, @mark_left REL - pop bc - - ; then as far right as possible (until wall is hit) - push bc -@mark_right: - ; now go as far left as possible (until wall is hit) - call _map_uncover_mark - inc c ; x++ - cp a, 0 - jr z, @mark_right REL - pop bc - - ; then y++ - inc b - call _map_uncover_mark - cp a, 0 ; is it a wall? - jr z, @mark_all REL ; again! - + ld a, TF0_UNCOVERED + ld [map_mark_flag], a + call _map_mark ret ; nop map rotuine diff --git a/src/player.s b/src/player.s index 17b98b9..0bc8247 100644 --- a/src/player.s +++ b/src/player.s @@ -189,13 +189,13 @@ player_collided: ret @open_door: - ld a, TT_FLOOR + ld a, TT_ROOM_END ld [de], a ld hl, t_flags0 add hl, de ; clear all flags - xor a, a + ld a, TF0_UNCOVERED ld [hl], a call map_full_draw diff --git a/src/tiles.s b/src/tiles.s index 03be90f..66a2d3b 100644 --- a/src/tiles.s +++ b/src/tiles.s @@ -17,12 +17,16 @@ tile_floor: tile_door: tiledef TT_DOOR, TF0_WALL, 0, 0 +tile_room_end: + tiledef TT_FLOOR, 0, 0, 1 + ; table of map tiles -> actual tile defs tile_table: dw tile_wall dw tile_floor dw tile_door dw tile_inner_wall + dw tile_room_end ; map of tile type to gfx ; this is the base tile @@ -41,4 +45,6 @@ tile_gfx_table: .db 0x03 ; inner wall .db 0x01 + ; room end + .db 0x02 diff --git a/src/wram.s b/src/wram.s index 4cf50f2..efadecb 100644 --- a/src/wram.s +++ b/src/wram.s @@ -128,6 +128,8 @@ col_tile: .adv 2 col_y: .adv 1 col_x: .adv 1 +map_mark_flag: .adv 1 + #ifdef DEBUG_CANARY render_canary: .adv 4 #endif