Rearranged things a bit in preparation for segmented 2D map packing.

This commit is contained in:
Martin Haye 2014-07-15 09:52:58 -07:00
parent df246c40c6
commit 3bbcc7ed92
4 changed files with 25 additions and 15 deletions

View File

@ -414,7 +414,7 @@ class PackPartitions
javascriptOut.println("];\n")
}
def write3DMap(buf, mapName, rows) // [ref BigBlue1_50]
def write3DMap(buf, mapName, rows, scriptModule) // [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
@ -454,6 +454,9 @@ class PackPartitions
buf.put((byte)width)
buf.put((byte)height)
// Followed by script module num
buf.put((byte)scriptModule)
// Followed by name
writeString(buf, mapName.replaceFirst(/ ?-? ?3D/, ""))
@ -565,24 +568,26 @@ class PackPartitions
def num = maps3D.size() + 1
def name = mapEl.@name ?: "map$num"
println "Packing 3D map #$num named '$name'."
packScripts(mapEl, num)
def scriptModule = packScripts(mapEl, name)
def rows = parseMap(mapEl, tileEls)
def buf = ByteBuffer.allocate(50000)
write3DMap(buf, name, rows)
write3DMap(buf, name, rows, scriptModule)
maps3D[name] = [num:num, buf:buf]
}
def packScripts(mapEl, mapNum)
def packScripts(mapEl, mapName)
{
if (!mapEl.scripts)
return
return 0
ScriptModule module = new ScriptModule()
module.packScripts(mapEl.scripts[0])
def num = mapNum + 0x20 // to distinguish from system modules
def name = "mapScript$mapNum"
def num = modules.size() + 1
def name = "mapScript$num"
println "Packing scripts for map $mapName, to module $num."
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
}
def readBinary(path)

View File

@ -750,5 +750,5 @@ strLENGTH !fill 1 ; length of string
;---------------------------
; End of the code...
;---------------------------
!align 127,0
!source "tables.i"

View File

@ -355,6 +355,7 @@ end
; General methods
def initMap()
word scriptModule
; Reset memory (our module will stay since memory manager locked it upon load)
loader(RESET_MEMORY, MAIN_MEM, 0)
@ -385,9 +386,13 @@ def initMap()
; Load everything that we just queued
loader(FINISH_LOAD, MAIN_MEM, 1) ; 1 = keep open
; Load the scripts for this map
pScripts = loader(QUEUE_LOAD, MAIN_MEM, ((mapNum+$20)<<8) | RES_TYPE_MODULE)
loader(FINISH_LOAD, MAIN_MEM, 1) ; 1 = keep open
; Load the scripts for this map, if it has any.
scriptModule = pMap->2 ; first 2 bytes are width and height, third byte is script module num
if scriptModule
pScripts = loader(QUEUE_LOAD, MAIN_MEM, (scriptModule << 8) | RES_TYPE_MODULE)
loader(FINISH_LOAD, MAIN_MEM, 1) ; 1 = keep open
*pScripts()
fin
; Start up the font engine
initFontEngine(pFont)
@ -402,7 +407,6 @@ def initMap()
; Initialize the map scripts
setWindow2()
*pScripts()
prevX = -1
prevY = -1

View File

@ -1573,6 +1573,7 @@ loadTextures: !zone
sta mapWidth ; and save it
jsr .get ; get map height
sta mapHeight ; and save it
jsr .get ; ignore script module num (it gets loaded by PLASMA code)
lda .get+1 ; current pointer is the map name
sta mapName ; save it
lda .get+2
@ -1583,9 +1584,9 @@ loadTextures: !zone
inc mapNameLen
cmp #0
bne .skip ; until end-of-string is reached (zero byte)
lda mapNameLen ; clamp length of map name
lda mapNameLen ; clamp length of map name
cmp #MAX_NAME_LEN
bcc +
bcc .notrnc
lda mapName
sta .trunc+1
lda mapName+1
@ -1594,7 +1595,7 @@ loadTextures: !zone
lda #0
.trunc sta mapName,x
stx mapNameLen
+ lda #0 ; now comes the list of textures.
.notrnc lda #0 ; now comes the list of textures.
sta txNum
.lup: jsr .get ; get texture resource number
tay ; to Y for mem manager