Better clamping for terrain chunk compiling

This commit is contained in:
blondie7575 2023-08-04 19:37:09 -07:00
parent 49c1b08cb0
commit 92a3a9040e
2 changed files with 17 additions and 6 deletions

View File

@ -939,7 +939,7 @@ processTerrainImpactStoreContinue:
adc projectileTypes+PT_RADIUS,y adc projectileTypes+PT_RADIUS,y
adc #GAMEOBJECTWIDTH adc #GAMEOBJECTWIDTH
sta compileTerrainRowEnd sta compileTerrainRowEnd
;don't forget to clamp these to terrain edges'
lda projectileTypes+PT_RADIUS,y lda projectileTypes+PT_RADIUS,y
tay tay
phy ; We'll need the radius in a moment phy ; We'll need the radius in a moment

View File

@ -295,12 +295,19 @@ compileTerrainDone:
; Trashes A,Y, SCRATCHL, PARAML0, PARAML1 ; Trashes A,Y, SCRATCHL, PARAML0, PARAML1
; ;
compileTerrainChunk: compileTerrainChunk:
ldy #0
tya ; Be extra safe and make sure Y is never negative or we'll spray RAM with terrain data ; Clamp chunk to left and right terrain edges
lda compileTerrainRowStart
bmi compileTerrainChunkClampZero bmi compileTerrainChunkClampZero
ldx #MAXTERRAINHEIGHT-1
compileTerrainChunkClampResume:
lda compileTerrainRowEnd
cmp #TERRAINWIDTH
bcs compileTerrainChunkClampHigh
compileTerrainChunkResume: compileTerrainChunkResume:
ldy #0
ldx #MAXTERRAINHEIGHT-1
stx SCRATCHL stx SCRATCHL
sty PARAML0 sty PARAML0
@ -329,9 +336,13 @@ compileTerrainChunkDone:
rts rts
compileTerrainChunkClampZero: compileTerrainChunkClampZero:
ldy #0 stz compileTerrainRowStart
bra compileTerrainChunkResume bra compileTerrainChunkClampResume
compileTerrainChunkClampHigh:
lda #TERRAINWIDTH-1
sta compileTerrainRowEnd
bra compileTerrainChunkResume
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; compileTerrainRow ; compileTerrainRow