diff --git a/Platform/Apple/tools/PackPartitions/src/org/badvision/A2PackPartitions.groovy b/Platform/Apple/tools/PackPartitions/src/org/badvision/A2PackPartitions.groovy index ccb1836a..9c736001 100644 --- a/Platform/Apple/tools/PackPartitions/src/org/badvision/A2PackPartitions.groovy +++ b/Platform/Apple/tools/PackPartitions/src/org/badvision/A2PackPartitions.groovy @@ -203,11 +203,15 @@ class A2PackPartitions } } - def calcImageHash(imgEl) + def calcImagesHash(imgEls) { - def data = imgEl.displayData?.find { it.@platform == "AppleII" } - assert data : "image '${imgEl.@name}' missing AppleII platform data" - byte[] bytes = MessageDigest.getInstance("MD5").digest(data.toString().getBytes()) + def md = MessageDigest.getInstance("MD5") + imgEls.each { imgEl -> + def data = imgEl.displayData?.find { it.@platform == "AppleII" } + assert data : "image '$name' missing AppleII platform data" + md.update(data.toString().getBytes()) + } + byte[] bytes = MessageDigest.getInstance("MD5").digest() return DatatypeConverter.printHexBinary(bytes) } @@ -751,14 +755,18 @@ class A2PackPartitions def packTexture(imgEl) { - def name = stripName(imgEl.@name) - def hash = calcImageHash(imgEl) - if (!grabFromCache("texture", textures, name, hash)) { + def (name, animFrameNum, animFlags) = decodeImageName(imgEl.@name ?: "img$num") + name = stripName(name) + withContext("texture '$name'") { + if (!textures.containsKey(name)) { + def num = textures.size() + 1 + textures[name] = [num:num, anim:new AnimBuf()] + } def pixels = parseTexture(imgEl) calcTransparency(pixels) def buf = ByteBuffer.allocate(50000) writeTexture(buf, pixels) - addToCache("texture", textures, name, hash, buf) + textures[name].anim.addImage(animFrameNum, animFlags, buf) } } @@ -1746,7 +1754,6 @@ class A2PackPartitions def xmlLastMod = xmlPath.lastModified() // Pre-pack the data for each tile - println "Packing images." dataIn.tile.each { packTile(it) } @@ -1785,7 +1792,9 @@ class A2PackPartitions assert uiFrameImgs.size() == 2 : "Need exactly 2 UI frames, found ${uiFramesImgs.size()} instead." // Pack each image, which has the side-effect of filling in the image name map. - if (!grabEntireFromCache("frames", frames, xmlLastMod)) { + def hash = calcImagesHash(titleImgs + uiFrameImgs + fullscreenImgs) + if (!grabEntireFromCache("frames", frames, hash)) { + println "Packing frame images." titleImgs.each { image -> packFrameImage(image) } uiFrameImgs.each { image -> packFrameImage(image) } fullscreenImgs.each { image -> packFrameImage(image) } @@ -1793,16 +1802,29 @@ class A2PackPartitions frame.buf = frame.anim.pack() frame.anim = null } - addEntireToCache("frames", frames, xmlLastMod) + addEntireToCache("frames", frames, hash) } - textureImgs.each { image -> packTexture(image) } - if (!grabEntireFromCache("portraits", portraits, xmlLastMod)) { + + hash = calcImagesHash(textureImgs) + if (!grabEntireFromCache("textures", textures, hash)) { + println "Packing textures." + textureImgs.each { image -> packTexture(image) } + textures.each { name, texture -> + texture.buf = texture.anim.pack() + texture.anim = null + } + addEntireToCache("textures", textures, hash) + } + + hash = calcImagesHash(portraitImgs) + if (!grabEntireFromCache("portraits", portraits, hash)) { + println "Packing portraits." portraitImgs.each { image -> packPortrait(image) } portraits.each { name, portrait -> portrait.buf = portrait.anim.pack() portrait.anim = null } - addEntireToCache("portraits", portraits, xmlLastMod) + addEntireToCache("portraits", portraits, hash) } // Number all the maps and record them with names @@ -2493,7 +2515,7 @@ end animFrameNum = m[0][2].toInteger() animFlags = m[0][3].toLowerCase() } - return [name, animFrameNum, animFlags] + return [name.trim(), animFrameNum, animFlags] } def dataGen(xmlPath) diff --git a/Platform/Apple/virtual/src/core/mem.s b/Platform/Apple/virtual/src/core/mem.s index b6b798c9..cf224430 100644 --- a/Platform/Apple/virtual/src/core/mem.s +++ b/Platform/Apple/virtual/src/core/mem.s @@ -3016,6 +3016,8 @@ advanceAnims: !zone { beq .anim ; found an animated resource type cmp #RES_TYPE_SCREEN beq .anim + cmp #RES_TYPE_TEXTURE + beq .anim bne .next ; not animated; skip .anim lda tSegAdrLo,x ; pointer to start of resource sta pTmp diff --git a/Platform/Apple/virtual/src/plasma/gameloop.pla b/Platform/Apple/virtual/src/plasma/gameloop.pla index 84881075..957658e0 100644 --- a/Platform/Apple/virtual/src/plasma/gameloop.pla +++ b/Platform/Apple/virtual/src/plasma/gameloop.pla @@ -1283,8 +1283,10 @@ end def loadMainFrameImg() mmgr(START_LOAD, 1) // partition 1 is where code lives loadFrameImg(mapIs3D+2) - auxMmgr(FREE_MEMORY, curFullscreenImg) - curFullscreenImg = NULL + if curFullscreenImg + auxMmgr(FREE_MEMORY, curFullscreenImg) + curFullscreenImg = NULL + fin end /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1349,6 +1351,11 @@ def initMap(x, y, dir) doRender() fin + // Assume there might be animations until we learn otherwise + anyAnims = TRUE // for now; might get cleared if we discover otherwise on advance + animDirCt = 1 + animPauseCt = ANIM_PAUSE_MAX + // Populate script handlers for the current square, so that leave handlers will trigger right. scanScripts(x, y) @@ -1712,6 +1719,8 @@ def showAnimFrame() elsif curFullscreenImg blit(curFullscreenImg + 2, $2000, 192, 40) // the +2 is to skip anim hdr offset needRender = FALSE // suppress display of map for this frame + elsif mapIs3D + render() fin end diff --git a/Platform/Apple/virtual/src/raycast/render.s b/Platform/Apple/virtual/src/raycast/render.s index 10a4d172..2d071744 100644 --- a/Platform/Apple/virtual/src/raycast/render.s +++ b/Platform/Apple/virtual/src/raycast/render.s @@ -1250,8 +1250,11 @@ drawRay: !zone ldx txNum dex ; translate tex 1..4 to 0..3 lda texAddrLo,x + clc + adc #2 ; skip over offset to animation header sta pTex lda texAddrHi,x + adc #0 sta pTex+1 ; jump to the unrolled expansion code for the selected height !if DEBUG >= 2 { +prStr : !text "Calling expansion code.",0 }