From d9a203c522d2b5b0dc561670f9b74ceaaa47acbe Mon Sep 17 00:00:00 2001 From: Martin Haye Date: Fri, 13 Jun 2014 13:10:38 -0700 Subject: [PATCH] Sprite fixes, and workaround for Outlaw NPE. --- .../badvision/outlaweditor/data/TileMap.java | 13 +++-- .../nbproject/genfiles.properties | 4 +- .../PackPartitions/nbproject/groovy-build.xml | 2 +- Platform/Apple/virtual/src/include/debug.i | 37 +++++++++---- Platform/Apple/virtual/src/raycast/render.i | 2 +- Platform/Apple/virtual/src/raycast/render.s | 52 ++++++++++++++----- 6 files changed, 76 insertions(+), 34 deletions(-) diff --git a/OutlawEditor/src/main/java/org/badvision/outlaweditor/data/TileMap.java b/OutlawEditor/src/main/java/org/badvision/outlaweditor/data/TileMap.java index 7d660873..db5c8763 100644 --- a/OutlawEditor/src/main/java/org/badvision/outlaweditor/data/TileMap.java +++ b/OutlawEditor/src/main/java/org/badvision/outlaweditor/data/TileMap.java @@ -149,11 +149,14 @@ public class TileMap extends ArrayList> implements Serializable width = 0; height = 0; Set unknownTiles = new HashSet<>(); - m.getScripts().getScript().forEach( - s -> s.getLocationTrigger().forEach( - l -> registerLocationScript(l.getX(), l.getY(), s) - ) - ); + Map.Scripts scripts = m.getScripts(); + if (scripts != null) { + scripts.getScript().forEach( + s -> s.getLocationTrigger().forEach( + l -> registerLocationScript(l.getX(), l.getY(), s) + ) + ); + } m.getChunk().forEach( c-> { int y = c.getY(); for (JAXBElement> row : c.getRow()) { diff --git a/Platform/Apple/tools/PackPartitions/nbproject/genfiles.properties b/Platform/Apple/tools/PackPartitions/nbproject/genfiles.properties index ef2f6791..950df06d 100644 --- a/Platform/Apple/tools/PackPartitions/nbproject/genfiles.properties +++ b/Platform/Apple/tools/PackPartitions/nbproject/genfiles.properties @@ -7,5 +7,5 @@ nbproject/build-impl.xml.data.CRC32=69409762 nbproject/build-impl.xml.script.CRC32=12156ac0 nbproject/build-impl.xml.stylesheet.CRC32=cdba79fa@1.68.1.46 nbproject/groovy-build.xml.data.CRC32=f3c1938b -nbproject/groovy-build.xml.script.CRC32=629135a5 -nbproject/groovy-build.xml.stylesheet.CRC32=919c82d5@1.4.1 +nbproject/groovy-build.xml.script.CRC32=66297360 +nbproject/groovy-build.xml.stylesheet.CRC32=28d0e1f2@1.7.1 diff --git a/Platform/Apple/tools/PackPartitions/nbproject/groovy-build.xml b/Platform/Apple/tools/PackPartitions/nbproject/groovy-build.xml index a15403dd..c93e3df2 100644 --- a/Platform/Apple/tools/PackPartitions/nbproject/groovy-build.xml +++ b/Platform/Apple/tools/PackPartitions/nbproject/groovy-build.xml @@ -23,7 +23,7 @@ - + diff --git a/Platform/Apple/virtual/src/include/debug.i b/Platform/Apple/virtual/src/include/debug.i index a0339640..cf7124a0 100644 --- a/Platform/Apple/virtual/src/include/debug.i +++ b/Platform/Apple/virtual/src/include/debug.i @@ -12,6 +12,11 @@ jsr _prSpace } +!macro prChr chr { + jsr _writeStr + !byte chr, 0 +} + !macro prA { jsr _prA jsr _prSpace @@ -79,7 +84,7 @@ _getStackByte !zone { ; Support to print a string following the JSR, in high or low bit ASCII, ; terminated by zero. If the string has a period "." it will be followed ; automatically by a carriage return. Preserves all registers. -_writeStr: !zone +_writeStr: !zone { jsr iosave tsx .loop: jsr _getStackByte @@ -90,13 +95,15 @@ _writeStr: !zone jsr crout jmp .loop .done: jmp iorest +} -_prByte: !zone +_prByte: !zone { jsr iosave ldy #0 ; fall through to _prShared... +} -_prShared: !zone +_prShared: !zone { tsx jsr _getStackByte sta .ld+1 @@ -108,8 +115,9 @@ _prShared: !zone bpl .ld +prSpace jmp iorest - -_prSpace: +} + +_prSpace: !zone { php pha lda #$A0 @@ -117,21 +125,24 @@ _prSpace: pla plp rts +} -_prWord: !zone +_prWord: !zone { jsr iosave ldy #1 bne _prShared ; always taken +} -_prA: !zone +_prA: !zone { php pha jsr prbyte pla plp rts +} -_prX: !zone +_prX: !zone { php pha txa @@ -139,8 +150,9 @@ _prX: !zone pla plp rts +} -_prY: !zone +_prY: !zone { php pha tya @@ -148,16 +160,19 @@ _prY: !zone pla plp rts +} -_crout: !zone +_crout: !zone { php pha jsr crout pla plp rts +} -_waitKey: !zone +_waitKey: !zone { jsr iosave jsr rdkey jmp iorest +} \ No newline at end of file diff --git a/Platform/Apple/virtual/src/raycast/render.i b/Platform/Apple/virtual/src/raycast/render.i index c8ecd23d..ca2a2fac 100644 --- a/Platform/Apple/virtual/src/raycast/render.i +++ b/Platform/Apple/virtual/src/raycast/render.i @@ -62,7 +62,7 @@ bSgnCosT = $91 bSgnDx = $92 bSgnDy = $93 bSgnRy = $94 -__unused95 = $95 +_unused95 = $95 wLogSinT = $96 wLogCosT = $98 wLogDx = $9A diff --git a/Platform/Apple/virtual/src/raycast/render.s b/Platform/Apple/virtual/src/raycast/render.s index 43d7d2ef..eee5e041 100644 --- a/Platform/Apple/virtual/src/raycast/render.s +++ b/Platform/Apple/virtual/src/raycast/render.s @@ -26,8 +26,10 @@ DEBUG_COLUMN = 0 !source "../include/fontEngine.i" ; Local constants -MAX_SPRITES = 16 ; max # sprites visible at once +MAX_SPRITES = 64 ; max # sprites visible at once NUM_COLS = 63 +SPRITE_DIST_LIMIT = 6 +SPRITE_CT_LIMIT = 4 ; Starting position and dir. Eventually this will come from the map PLAYER_START_X = $280 ; 1.5 @@ -49,7 +51,7 @@ frontBuf: !byte 0 ; (value 0 or 1) mapHeader: !word 0 ; map with header first mapBase: !word 0 ; first byte after the header mapRayOrigin: !word 0 -mapNum: !byte 1 +mapNum: !byte 4 mapName: !word 0 ; pointer to map name mapNameLen: !byte 0 ; length of map name nMapSprites: !byte 0 ; number of sprite entries on map to fix up @@ -431,7 +433,9 @@ castRay: !zone ldx nMapSprites ; get ready to store the address so we can fix the flag later cpx #MAX_SPRITES ; check for table overflow bne + - brk ; ack! too many sprites + lda #'S' + sta $7F7 ; quickly note it on the text screen + bne .spriteDone ; and skip this sprite (always taken) + tya ; Y reg indexes the map clc adc pMap ; add to map pointer @@ -661,12 +665,17 @@ spriteCalc: !zone inc bSgnDx ; flip sign bit for output jsr .negYX ; negate to get absolute value + tya ; lo byte in A where log2 wants it - jsr log2_w_w ; wants A=lo, X=Hi + cpx #SPRITE_DIST_LIMIT ; too far away? + bmi + + !if DEBUG { +prStr : !text "Sprite is too far away (X).",0 } + clc + rts ++ jsr log2_w_w ; wants A=lo, X=Hi sta wLogDx stx wLogDx+1 ; Calculate wLogDy = log2_w_w(spriteY - playerY), as abs value and a sign bit - lda spriteY ; calculate spriteX - playerX + lda spriteY ; calculate spriteY - playerY sec sbc playerY tay ; stash lo byte @@ -677,7 +686,12 @@ spriteCalc: !zone inc bSgnDy ; flip sign bit for output jsr .negYX ; negate to get absolute value + tya ; lo byte in A where log2 wants it - jsr log2_w_w ; wants A=lo, X=Hi + cpx #SPRITE_DIST_LIMIT ; too far away? + bmi + + !if DEBUG { +prStr : !text "Sprite is too far away (Y).",0 } + clc + rts ++ jsr log2_w_w ; wants A=lo, X=Hi sta wLogDy stx wLogDy+1 @@ -698,7 +712,7 @@ spriteCalc: !zone eor bSgnCosT ; multiply the two sign bits together beq + ; if result is clear, no negation jsr .negYX ; negate -+ sty wRx ; save partial result ++ sty wRx ; save partial result stx wRx+1 lda wLogDy ; start with lo byte clc @@ -716,7 +730,7 @@ spriteCalc: !zone jsr .negYX ; negate + tya clc - adc wRx ; add to partial result + adc wRx ; add to partial result sta wRx txa adc wRx+1 ; also hi byte @@ -747,7 +761,7 @@ spriteCalc: !zone eor bSgnSinT ; multiply the two sign bits together beq + ; if result is clear, no negation jsr .negYX ; negate -+ sty wRy ; save partial result ++ sty wRy ; save partial result stx wRy+1 lda wLogDy ; start with lo byte clc @@ -764,7 +778,7 @@ spriteCalc: !zone jsr .negYX ; negate + tya clc - adc wRy ; add to partial result + adc wRy ; add to partial result tay txa adc wRy+1 ; also hi byte @@ -772,7 +786,7 @@ spriteCalc: !zone bpl + ; if already positive, skip negation jsr .negYX ; negate to get abs value inc bSgnRy ; and update sign bit -+ sty wRy ; save result (we may not actually need to do this, but it helps w/ debug) ++ sty wRy ; save result (we may not actually need to do this, but it helps w/ debug) stx wRy+1 tya ; get lo byte where it needs to be for log2 jsr log2_w_w ; calculate the log of wRy @@ -1084,15 +1098,19 @@ drawSprite: !zone + sta screenCol lda #$80 ; fractional byte of txColumn pha -.lup lda screenCol - cmp #NUM_COLS +.lup ldx screenCol + cpx #NUM_COLS bcs .done + inc spriteCtBuf,x ; count sprites in this column + lda spriteCtBuf,x ; and check it + cmp #SPRITE_CT_LIMIT ; limit to 4 sprites per column + bcs .skip ldy lineCt ; column height lda depth ; depth index jsr saveLink ; save height and depth, link in to column data lda txColumn ; also save the column number sta txColBuf,x - inc screenCol ; next column on screen +.skip inc screenCol ; next column on screen pla ; fractional byte clc adc wTxColBump ; advance lo byte @@ -1132,6 +1150,7 @@ saveLink: !zone sta firstLink,x .store2 tax ; switch to the new link's area now bne + + +prChr 'L' brk ; ack! ran out of link space -- too much complexity on screen + tya sta linkBuf,x @@ -1688,6 +1707,7 @@ loadTextures: !zone inx ; get ready for next texture cpx #MAX_TEXTURES bne + + +prChr 'T' brk ; barf out if too many textures + stx txNum jmp .lup @@ -1744,6 +1764,7 @@ castAllRays: !zone txa ldx #NUM_COLS-1 - sta firstLink,x + sta spriteCtBuf,x dex bpl - @@ -2072,6 +2093,7 @@ main: !zone ldx mapName+1 jsr printCSTR ; play text in the big window on the top right +!if 0 { jsr set_window2 jsr clearWINDOW jsr printSCSTR @@ -2089,6 +2111,7 @@ main: !zone !raw "wink. Perhaps",13 !raw "it's your lucky" !raw "day?",0 +} ; play characters in the little window on the bottom right jsr set_window3 jsr clearWINDOW @@ -3284,6 +3307,7 @@ txColBuf: !fill 256 heightBuf: !fill 256 depthBuf: !fill 256 linkBuf: !fill 256 +spriteCtBuf: !fill 256 firstLink: !fill NUM_COLS ; Active sprite restore addresses