mirror of
https://github.com/badvision/lawless-legends.git
synced 2024-08-02 15:29:00 +00:00
Implemented printf for handy debugging, and now generating a map index for the 2D sections.
This commit is contained in:
parent
56897dd67d
commit
a835321b5f
@ -413,6 +413,13 @@ class PackPartitions
|
||||
|
||||
def buffers = new ByteBuffer[nVertSections][nHorzSections]
|
||||
def sectionNums = new int[nVertSections][nHorzSections]
|
||||
|
||||
// Start the map index, which will list all the section numbers.
|
||||
def indexBuf = ByteBuffer.allocate(512)
|
||||
def indexNum = maps2D.size() + 1
|
||||
maps2D[mapName] = [num:indexNum, buf:indexBuf]
|
||||
indexBuf.put((byte)nHorzSections)
|
||||
indexBuf.put((byte)nVertSections)
|
||||
|
||||
// Allocate a buffer and assign a map number to each section.
|
||||
(0..<nVertSections).each { vsect ->
|
||||
@ -423,9 +430,14 @@ class PackPartitions
|
||||
sectionNums[vsect][hsect] = num
|
||||
def sectName = "$mapName-$hsect-$vsect"
|
||||
maps2D[sectName] = [num:num, buf:buf]
|
||||
indexBuf.put((byte)num)
|
||||
}
|
||||
}
|
||||
|
||||
// Finish the index buffer with the map name
|
||||
writeString(indexBuf, mapName.replaceFirst(/ ?-? ?2D/, ""))
|
||||
|
||||
// Now create each map section
|
||||
(0..<nVertSections).each { vsect ->
|
||||
(0..<nHorzSections).each { hsect ->
|
||||
|
||||
|
@ -113,10 +113,6 @@ byte prevMapNum
|
||||
byte prevMapIs3D
|
||||
byte redraw
|
||||
byte titleLoaded = FALSE
|
||||
byte cacheSky, cacheGround
|
||||
word cacheX, cacheY
|
||||
byte cacheDir
|
||||
byte resetLocFromCache = FALSE
|
||||
byte textDrawn = FALSE
|
||||
|
||||
// Movement amounts when walking at each angle
|
||||
@ -562,9 +558,20 @@ def fatal(msg)
|
||||
loader(FATAL_ERROR, MAIN_MEM, msg)
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Print a signed decimal word
|
||||
def printDec(n)
|
||||
if n < 0; printChar('-'); n = -n; fin
|
||||
if n > 9999; printChar('0' + n/10000); n = n%10000; fin
|
||||
if n > 999; printChar('0' + n/1000); n = n%1000; fin
|
||||
if n > 99; printChar('0' + n/100); n = n%100; fin
|
||||
if n > 9; printChar('0' + n/10); n = n%10; fin
|
||||
printChar('0' + n)
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Print a formatted string a'la C printf, with up to four parameters.
|
||||
def printf2(str, arg1, arg2)
|
||||
def printf4(str, arg1, arg2, arg3, arg4)
|
||||
word pos
|
||||
word curArg
|
||||
word p
|
||||
@ -578,20 +585,25 @@ def printf2(str, arg1, arg2)
|
||||
p = str + pos + 2
|
||||
when ^p
|
||||
is 'x'
|
||||
printHex(*curArg)
|
||||
break
|
||||
printHex(*curArg); break
|
||||
is 'd'
|
||||
printDec(*curArg); break
|
||||
is 's'
|
||||
puts(*curArg); break
|
||||
is '%'
|
||||
printChar('%')
|
||||
break
|
||||
printChar('%'); break
|
||||
otherwise
|
||||
printHex(^p)
|
||||
fatal("Unknown % code")
|
||||
printHex(^p); fatal("Unknown % code")
|
||||
wend
|
||||
curArg = curArg + 2
|
||||
pos = pos + 2
|
||||
loop
|
||||
end
|
||||
|
||||
def printf1(str, arg1); printf4(str, arg1, 0, 0, 0); end
|
||||
def printf2(str, arg1, arg2); printf4(str, arg1, arg2, 0, 0); end
|
||||
def printf3(str, arg1, arg2, arg3); printf4(str, arg1, arg2, arg3, 0); end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Get a keystroke and convert it to upper case
|
||||
def getUpperKey()
|
||||
@ -690,7 +702,7 @@ end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Load code and data, set up everything to display a 3D map
|
||||
def initMap3D()
|
||||
def initMap3D(x, y, dir)
|
||||
word scriptModule
|
||||
|
||||
// Set up the command table
|
||||
@ -750,24 +762,10 @@ def initMap3D()
|
||||
prevX = -1
|
||||
prevY = -1
|
||||
triggerTbl = NULL
|
||||
prevMapNum = mapNum
|
||||
prevMapIs3D = mapIs3D
|
||||
if pScripts
|
||||
*pScripts()
|
||||
fin
|
||||
|
||||
// If we're returning to a map, resume from where the player left off
|
||||
if resetLocFromCache
|
||||
*playerX = cacheX
|
||||
*playerY = cacheY
|
||||
^playerDir = cacheDir
|
||||
prevX = playerX.1 - 1
|
||||
prevY = playerY.1 - 1
|
||||
setSky(cacheSky)
|
||||
setGround(cacheGround)
|
||||
resetLocFromCache = FALSE
|
||||
fin
|
||||
|
||||
// Draw the first frame
|
||||
renderFrame()
|
||||
redraw = FALSE
|
||||
@ -776,7 +774,6 @@ end
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Load code and data, set up everything to display a 2D map
|
||||
def initMap2D()
|
||||
word scriptModule
|
||||
|
||||
// Set up the command table
|
||||
initCmds2D()
|
||||
@ -809,8 +806,6 @@ def initMap2D()
|
||||
prevX = -1
|
||||
prevY = -1
|
||||
triggerTbl = NULL
|
||||
prevMapNum = mapNum
|
||||
prevMapIs3D = mapIs3D
|
||||
|
||||
// Start up the tile engine
|
||||
initDisplayEngine(mapNum)
|
||||
@ -822,12 +817,14 @@ end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Set up mapNum (2D or 3D depending on state of is3DMap)
|
||||
def initMap()
|
||||
def initMap(x, y, dir)
|
||||
if mapIs3D
|
||||
initMap3D()
|
||||
initMap3D(x, y, dir)
|
||||
else
|
||||
initMap2D()
|
||||
initMap2D(x, y, dir)
|
||||
fin
|
||||
prevMapNum = mapNum
|
||||
prevMapIs3D = mapIs3D
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -904,9 +901,7 @@ end
|
||||
def checkScripts()
|
||||
word x
|
||||
word y
|
||||
if !triggerTbl
|
||||
return
|
||||
fin
|
||||
if !triggerTbl; return; fin
|
||||
if mapIs3D
|
||||
x = playerX.1 - 1
|
||||
y = playerY.1 - 1
|
||||
@ -923,12 +918,12 @@ def checkScripts()
|
||||
fin
|
||||
if isScripted()
|
||||
callScripts(x, y)
|
||||
if (mapNum <> prevMapNum) or (mapIs3D <> prevMapIs3D)
|
||||
flipToFirstPage()
|
||||
initMap()
|
||||
fin
|
||||
fin
|
||||
fin
|
||||
if (mapNum <> prevMapNum) or (mapIs3D <> prevMapIs3D)
|
||||
flipToFirstPage()
|
||||
initMap()
|
||||
fin
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -1010,23 +1005,6 @@ def moveWest()
|
||||
move2D(-1, 0)
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Switch to a new map (2D or 3D)
|
||||
def setMap(is3D, num)
|
||||
// save player state if we're coming *from* the over-map
|
||||
if mapNum == OVERMAP_NUM and mapIs3D == OVERMAP_IS_3D
|
||||
cacheX = *playerX
|
||||
cacheY = *playerY
|
||||
cacheDir = ^playerDir
|
||||
cacheSky = skyNum
|
||||
cacheGround = groundNum
|
||||
else
|
||||
resetLocFromCache = TRUE
|
||||
fin
|
||||
mapIs3D = is3D
|
||||
mapNum = num
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Switch to next map in the current 2D or 3D mode.
|
||||
def nextMap()
|
||||
@ -1038,16 +1016,19 @@ def nextMap()
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Jump to a new map location (and in 3D mode, point in the given direction)
|
||||
// Jump to a new map location (and point in the given direction)
|
||||
def teleport(x, y, dir)
|
||||
*playerX = ((x+1)<<8) | $80
|
||||
*playerY = ((y+1)<<8) | $80
|
||||
prevX = x
|
||||
prevY = y
|
||||
clearWindow()
|
||||
textDrawn = FALSE
|
||||
^playerDir = dir
|
||||
redraw = TRUE
|
||||
nextX = x
|
||||
nextY = y
|
||||
nextDir = dir
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Switch to a new map (2D or 3D)
|
||||
def setMap(is3D, num, x, y, dir)
|
||||
mapIs3D = is3D
|
||||
mapNum = num
|
||||
teleport(x, y, dir)
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -1147,7 +1128,6 @@ end
|
||||
// Load and display the title screen.
|
||||
def loadTitle()
|
||||
puts("Loading Lawless Legends.\n")
|
||||
printf2("Test %x and %x...\n", $1001, $2002)
|
||||
|
||||
// Load the title screen
|
||||
puts("Loading title screen.\n")
|
||||
|
Loading…
Reference in New Issue
Block a user