This code computes the field of view starting from (center) in a tile based map.
_hidden_map holds the actual map
_clear_map holds the map as seen from center
Could this code be faster ?
Does anyone have any FoV faster algorithm ?
global drawline
global _hidden_map,_clear_map
global center
wallchr equ 'X'
doorchr equ '#'
global viewsegments
MAPW equ 20
MAPH equ 20
psect text,class=CODE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Input:
; center points to the center of the FoV
;Output:
; compute the FoV in 8 octants (split in 4 quadrants)
viewsegments:
ld bc,-MAPW+1 ; segment 1
ld de,(center)
call segxloopinc
ld de,(center)
call segyloopdec
ld bc,MAPW+1 ; segment 2
ld de,(center)
call segxloopinc
ld de,(center)
call segyloopinc
ld bc,MAPW-1 ; segment 3
ld de,(center)
call segxloopdec
ld de,(center)
call segyloopinc
ld bc,-MAPW-1 ; segment 4
ld de,(center)
call segxloopdec
ld de,(center)
jp segyloopdec
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
segxloopinc:
1:
ld a,(de)
ld hl,-_hidden_map+_clear_map
add hl,de
ld (hl),a
cp wallchr ; view blocking characters
ret z
cp doorchr
ret z
push de
call drawline
pop de
inc de
jp 1b
segxloopdec:
1:
ld a,(de)
ld hl,-_hidden_map+_clear_map
add hl,de
ld (hl),a
cp wallchr ; view blocking characters
ret z
cp doorchr
ret z
push de
call drawline
pop de
dec de
jp 1b
segyloopinc:
1:
ld hl,MAPW
add hl,de
ld a,(hl)
ex de,hl
ld hl,-_hidden_map+_clear_map
add hl,de
ld (hl),a
cp wallchr ; view blocking characters
ret z
cp doorchr
ret z
push de
call drawline
pop de
jp 1b
segyloopdec:
1:
ld hl,-MAPW
add hl,de
ld a,(hl)
ex de,hl
ld hl,-_hidden_map+_clear_map
add hl,de
ld (hl),a
cp wallchr ; view blocking characters
ret z
cp doorchr
ret z
push de
call drawline
pop de
jp 1b
where I have also:
global drawline
global _hidden_map,_clear_map
MAPW equ 20
MAPH equ 20
psect text,class=CODE
wallchr equ 'X'
doorchr equ '#'
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Input :
; DE = pointer in _hidden_map to (x-coordinate,y-coordinate)
;- draw one line-of-sight
drawline:
1: ex de,hl
add hl,bc
ld a,(hl)
ex de,hl
ld hl,-_hidden_map+_clear_map
add hl,de
ld (hl),a
cp wallchr ; view blocking characters
ret z
cp doorchr
ret z
jp 1b
!login ou Inscrivez-vous pour poster
