From f4342b12c1156b9171894216d2fbe3f342908b46 Mon Sep 17 00:00:00 2001 From: Martin Haye Date: Sat, 19 Jul 2014 14:17:40 -0700 Subject: [PATCH] Now scripts have a flag of their own on the map, for speedy detection. --- .../src/org/demo/PackPartitions.groovy | 23 +++++++---- .../Apple/virtual/src/plasma/gameloop.pla | 41 +++++++++++++++---- Platform/Apple/virtual/src/raycast/render.s | 22 ++++++++-- 3 files changed, 67 insertions(+), 19 deletions(-) diff --git a/Platform/Apple/tools/PackPartitions/src/org/demo/PackPartitions.groovy b/Platform/Apple/tools/PackPartitions/src/org/demo/PackPartitions.groovy index 376eaf68..ef424e86 100644 --- a/Platform/Apple/tools/PackPartitions/src/org/demo/PackPartitions.groovy +++ b/Platform/Apple/tools/PackPartitions/src/org/demo/PackPartitions.groovy @@ -396,7 +396,7 @@ class PackPartitions javascriptOut.println("];\n") } - def write3DMap(buf, mapName, rows, scriptModule) // [ref BigBlue1_50] + def write3DMap(buf, mapName, rows, scriptModule, locationsWithTriggers) // [ref BigBlue1_50] { def width = rows[0].size() + 2 // Sentinel $FF at start and end of each row def height = rows.size() + 2 // Sentinel rows of $FF's at start and end @@ -431,6 +431,10 @@ class PackPartitions } } } + + // Make a map of all the locations with triggers + def locMap = [:] + locationsWithTriggers.each { x,y -> locMap[[x,y]] = true } // Header: width and height buf.put((byte)width) @@ -454,10 +458,12 @@ class PackPartitions (0.. + rows.eachWithIndex { row,y -> buf.put((byte)0xFF) // sentinel at start of row - row.each { tile -> - buf.put((byte)texMap[tile?.@id]) + row.eachWithIndex { tile,x -> + // Mark scripted locations with a flag + def flags = locMap.containsKey([x,y]) ? 0x20 : 0 + buf.put((byte)texMap[tile?.@id] | flags) } buf.put((byte)0xFF) // sentinel at end of row } @@ -572,10 +578,10 @@ class PackPartitions def num = maps3D.size() + 1 def name = mapEl.@name ?: "map$num" println "Packing 3D map #$num named '$name'." - def scriptModule = packScripts(mapEl, name) + def (scriptModule, locationsWithTriggers) = packScripts(mapEl, name) def rows = parseMap(mapEl, tileEls) def buf = ByteBuffer.allocate(50000) - write3DMap(buf, name, rows, scriptModule) + write3DMap(buf, name, rows, scriptModule, locationsWithTriggers) maps3D[name] = [num:num, buf:buf] } @@ -591,7 +597,7 @@ class PackPartitions modules[name] = [num:num, buf:wrapByteList(module.data)] bytecodes[name] = [num:num, buf:wrapByteList(module.bytecode)] fixups[name] = [num:num, buf:wrapByteList(module.fixups)] - return num + return [num, module.locationsWithTriggers] } def readBinary(path) @@ -1058,6 +1064,8 @@ class ScriptModule def nScripts = 0 + def locationsWithTriggers = [] + def vec_locationTrigger = 0x300 def vec_displayStr = 0x303 @@ -1217,6 +1225,7 @@ class ScriptModule script.locationTrigger.each { trig -> def x = trig.@x.toInteger() def y = trig.@y.toInteger() + locationsWithTriggers.add([x,y]) emitCodeByte(0x2A) // CB assert x >= 0 && x < 255 emitCodeByte(x) diff --git a/Platform/Apple/virtual/src/plasma/gameloop.pla b/Platform/Apple/virtual/src/plasma/gameloop.pla index ef0a9831..42e43bde 100644 --- a/Platform/Apple/virtual/src/plasma/gameloop.pla +++ b/Platform/Apple/virtual/src/plasma/gameloop.pla @@ -2,6 +2,7 @@ ; Handy constants. const FALSE = 0 const TRUE = !FALSE +const NULL = 0 ;================================================================================================== ; Fixed memory locations @@ -98,6 +99,7 @@ word locTrig_y[MAX_LOC_TRIG] word locTrig_func[MAX_LOC_TRIG] word prevX word prevY +word prevScript ; Movement amounts when walking at each angle ; Each entry consists of an X bump and a Y bump, in 8.8 fixed point @@ -307,13 +309,30 @@ asm isBlocked rts end +asm isScripted + txa + pha + bit setROM + jsr $6009 + tay + pla + tax + dex + tya + sta evalStkL,x + lda #0 + sta evalStkH,x + bit setLcRW+lcBank2 + rts +end + asm setColor txa pha bit setROM lda evalStkL,x ldy evalStkH,x - jsr $6009 + jsr $600C bit setLcRW+lcBank2 pla tax @@ -426,6 +445,7 @@ def initMap() setWindow2() prevX = -1 prevY = -1 + prevScript = -1 ; Draw the first frame renderFrame() @@ -480,13 +500,18 @@ def checkScript() if x <> prevX or y <> prevY prevX = x prevY = y - clearWindow() - for i = 0 to nLocTrig-1 - if x == locTrig_x[i] and y == locTrig_y[i] - func = locTrig_func[i] - *func() - fin - next + if prevScript + clearWindow() + fin + prevScript = NULL + if isScripted() + for i = 0 to nLocTrig-1 + if x == locTrig_x[i] and y == locTrig_y[i] + prevScript = locTrig_func[i] + *prevScript() + fin + next + fin fin end diff --git a/Platform/Apple/virtual/src/raycast/render.s b/Platform/Apple/virtual/src/raycast/render.s index 33a6c673..47947b5a 100644 --- a/Platform/Apple/virtual/src/raycast/render.s +++ b/Platform/Apple/virtual/src/raycast/render.s @@ -12,6 +12,7 @@ start: jmp initMap jmp renderFrame jmp isBlocked + jmp isScripted jmp setColor ; Conditional assembly flags @@ -297,6 +298,7 @@ castRay: !zone lda deltaDistX ; re-init X distance sta sideDistX lda (pMap),y ; check map at current X/Y position + and #$DF ; mask off script flag beq .DDA_step ; nothing there? do another step. bpl .hitX jmp .hitSprite @@ -353,6 +355,7 @@ castRay: !zone lda deltaDistY ; re-init Y distance sta sideDistY lda (pMap),y ; check map at current X/Y position + and #$DF ; mask off script flag bmi .hitSprite bne .hitY ; nothing there? do another step. jmp .DDA_step @@ -393,7 +396,7 @@ castRay: !zone and #$40 beq .notDone ; already done, don't do again txa - and #$3F + and #$1F tax jsr getTileFlags and #4 ; blocker sprite? @@ -405,7 +408,7 @@ castRay: !zone lda (pMap),y ; get back the original byte ora #$40 ; add special flag sta (pMap),y ; and store it back - and #$3F ; get just the texture number + and #$1F ; get just the texture number sta txNum ; and save it ldx nMapSprites ; get ready to store the address so we can fix the flag later cpx #MAX_SPRITES ; check for table overflow @@ -1683,20 +1686,31 @@ calcMapOrigin: !zone rts ;------------------------------------------------------------------------------- -; Retrieve the map data where the player currently is +; Check if the player's current location is an obstruction block isBlocked: !zone jsr calcMapOrigin sta pMap sty pMap+1 ldy playerX+1 lda (pMap),y + and #$1F beq + - and #$3F tax jsr getTileFlags and #2 ; flag 2 is for obstructions + rts +;------------------------------------------------------------------------------- +; Check if the player's current location has a script flag on it +isScripted: !zone + jsr calcMapOrigin + sta pMap + sty pMap+1 + ldy playerX+1 + lda (pMap),y + and #$20 + rts + ;------------------------------------------------------------------------------- ; Cast all the rays from the current player coord castAllRays: !zone