and now fa and fis works the same? wtf?

This commit is contained in:
minjaesong
2023-07-08 03:33:02 +09:00
parent d507d84950
commit f95bc36c98
3 changed files with 94 additions and 38 deletions

View File

@@ -788,6 +788,7 @@ fun AppUpdateListOfSavegames() {
println("Listing saved worlds...") println("Listing saved worlds...")
// create list of worlds // create list of worlds
File(worldsDir).listFiles().filter { !it.isDirectory && !it.name.contains('.') }.mapNotNull { file -> File(worldsDir).listFiles().filter { !it.isDirectory && !it.name.contains('.') }.mapNotNull { file ->
try { try {
@@ -834,7 +835,7 @@ fun AppUpdateListOfSavegames() {
null null
} }
}.sortedByDescending { it.getLastModifiedTime() }.forEachIndexed { index, it -> }.sortedByDescending { it.getLastModifiedTime() }.forEachIndexed { index, it ->
// println("${index+1}.\t${it.diskFile.absolutePath}") println("${index+1}.\t${it.diskFile.absolutePath}")
// it.rebuild() // it.rebuild()
// val jsonFile = it.getFile(SAVEGAMEINFO)!! // val jsonFile = it.getFile(SAVEGAMEINFO)!!
@@ -854,6 +855,11 @@ fun AppUpdateListOfSavegames() {
} }
} }
println("SortedPlayers...")
App.sortedPlayers.forEach {
println(it)
}
} }
/** /**

View File

@@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.graphics.glutils.FrameBuffer import com.badlogic.gdx.graphics.glutils.FrameBuffer
import net.torvald.terrarum.* import net.torvald.terrarum.*
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.ui.Movement import net.torvald.terrarum.ui.Movement
import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.Toolkit
@@ -92,39 +93,53 @@ class UILoadList(val full: UILoadSavegame) : UICanvas() {
full.changePanelTo(1) full.changePanelTo(1)
} }
private var showCalled = false
override fun show() { override fun show() {
mode1Node.parent = full.remoCon.treeRoot if (!showCalled) {
mode1Node.data = "MENU_MODE_SINGLEPLAYER : net.torvald.terrarum.modulebasegame.ui.UILoadSavegame" showCalled = true
full.remoCon.setNewRemoConContents(mode1Node) // println("UILoadList ${this.hashCode()} show called by:")
playerCells.clear() // printStackTrace(this)
try { mode1Node.parent = full.remoCon.treeRoot
full.remoCon.handler.lockToggle() mode1Node.data = "MENU_MODE_SINGLEPLAYER : net.torvald.terrarum.modulebasegame.ui.UILoadSavegame"
showSpinner = true full.remoCon.setNewRemoConContents(mode1Node)
playerCells.clear()
Thread { try {
// read savegames full.remoCon.handler.lockToggle()
var savegamesCount = 0 showSpinner = true
App.sortedPlayers.forEach { uuid ->
val x = full.uiX Thread {
val y = titleTopGradEnd + cellInterval * savegamesCount // read savegames
try { var savegamesCount = 0
playerCells.add(UIItemPlayerCells(full, x, y, uuid)) printdbg(this, "============== ${this.hashCode()} ============== ")
savegamesCount += 1 App.sortedPlayers.forEach { uuid ->
printdbg(this, "Reading player $uuid")
val x = full.uiX
val y = titleTopGradEnd + cellInterval * savegamesCount
try {
playerCells.add(UIItemPlayerCells(full, x, y, uuid))
savegamesCount += 1
}
catch (e: Throwable) {
System.err.println("[UILoadSavegame] Error while loading Player with UUID $uuid")
e.printStackTrace()
}
} }
catch (e: Throwable) { printdbg(this, "============== ${this.hashCode()} ============== ")
System.err.println("[UILoadSavegame] Error while loading Player with UUID $uuid")
e.printStackTrace()
}
}
full.remoCon.handler.unlockToggle() full.remoCon.handler.unlockToggle()
showSpinner = false showSpinner = false
}.start() }.start()
}
catch (e: UninitializedPropertyAccessException) {
}
} }
catch (e: UninitializedPropertyAccessException) {}
} }
override fun updateUI(delta: Float) { override fun updateUI(delta: Float) {
@@ -277,6 +292,7 @@ class UILoadList(val full: UILoadSavegame) : UICanvas() {
override fun hide() { override fun hide() {
playerCells.forEach { it.dispose() } playerCells.forEach { it.dispose() }
playerCells.clear() playerCells.clear()
showCalled = false
} }
override fun resize(width: Int, height: Int) { override fun resize(width: Int, height: Int) {

View File

@@ -121,6 +121,40 @@ removefile:
if (readStatus != 8) throw InternalError("Unexpected error -- EOF reached? (expected 8, got $readStatus)") if (readStatus != 8) throw InternalError("Unexpected error -- EOF reached? (expected 8, got $readStatus)")
return buffer.toInt64() return buffer.toInt64()
} }
private fun RandomAccessFile.readBytes(buffer: ByteArray): Int {
val readStatus = this.read(buffer)
return readStatus
}
private fun RandomAccessFile.readInt16(): Int {
val buffer = ByteArray(2)
val readStatus = readBytes(buffer)
if (readStatus != 2) throw InternalError("Unexpected error -- EOF reached? (expected 2, got $readStatus)")
return buffer.toInt16()
}
private fun RandomAccessFile.readInt32(): Int {
val buffer = ByteArray(4)
val readStatus = readBytes(buffer)
if (readStatus != 4) throw InternalError("Unexpected error -- EOF reached? (expected 4, got $readStatus)")
return buffer.toInt32()
}
private fun RandomAccessFile.readInt48(): Long {
val buffer = ByteArray(6)
val readStatus = readBytes(buffer)
if (readStatus != 6) throw InternalError("Unexpected error -- EOF reached? (expected 6, got $readStatus)")
return buffer.toInt48()
}
private fun RandomAccessFile.readInt24(): Int {
val buffer = ByteArray(3)
val readStatus = readBytes(buffer)
if (readStatus != 3) throw InternalError("Unexpected error -- EOF reached? (expected 3, got $readStatus)")
return buffer.toInt24()
}
private fun RandomAccessFile.readInt64(): Long {
val buffer = ByteArray(8)
val readStatus = readBytes(buffer)
if (readStatus != 8) throw InternalError("Unexpected error -- EOF reached? (expected 8, got $readStatus)")
return buffer.toInt64()
}
private fun ByteArray.toInt16(offset: Int = 0): Int { private fun ByteArray.toInt16(offset: Int = 0): Int {
return this[0 + offset].toUint().shl(8) or return this[0 + offset].toUint().shl(8) or
this[1 + offset].toUint() this[1 + offset].toUint()
@@ -162,18 +196,18 @@ removefile:
// fa = RandomAccessFile(diskFile, "rw") // fa = RandomAccessFile(diskFile, "rw")
val fis = FileInputStream(diskFile) val fa = RandomAccessFile(diskFile, "rwd")
var currentPosition = VirtualDisk.HEADER_SIZE var currentPosition = VirtualDisk.HEADER_SIZE
fis.skipNBytes(VirtualDisk.HEADER_SIZE) // skip disk header fa.seek(VirtualDisk.HEADER_SIZE) // skip disk header
println("[DiskSkimmer] rebuild ${diskFile.canonicalPath}") // println("[DiskSkimmer] rebuild ${diskFile.canonicalPath}")
val currentLength = diskFile.length() val currentLength = diskFile.length()
var ccc = 0 var ccc = 0
while (currentPosition < currentLength) { while (currentPosition < currentLength) {
val entryID = fis.readInt64() // at this point, cursor is 8 bytes past to the entry head val entryID = fa.readInt64() // at this point, cursor is 8 bytes past to the entry head
currentPosition += 8 currentPosition += 8
// fill up the offset table/ // fill up the offset table/
@@ -181,10 +215,10 @@ removefile:
// printdbg(this, "Offset $offset, entryID $entryID") // printdbg(this, "Offset $offset, entryID $entryID")
fis.readInt64() // parentID fa.readInt64() // parentID
val typeFlag = fis.read().toByte() val typeFlag = fa.read().toByte()
fis.readInt24() fa.readInt24()
fis.read(16) fa.read(16)
currentPosition += 8+4+16 currentPosition += 8+4+16
@@ -193,11 +227,11 @@ removefile:
val entrySize = when (typeFlag and 127) { val entrySize = when (typeFlag and 127) {
DiskEntry.NORMAL_FILE -> { DiskEntry.NORMAL_FILE -> {
currentPosition += 6 currentPosition += 6
fis.readInt48() fa.readInt48()
} }
DiskEntry.DIRECTORY -> { DiskEntry.DIRECTORY -> {
currentPosition += 4 currentPosition += 4
fis.readInt32().toLong() * 8L fa.readInt32().toLong() * 8L
} }
else -> 0 else -> 0
} }
@@ -205,7 +239,7 @@ removefile:
// printdbg(this, " type $typeFlag entrySize = $entrySize") // printdbg(this, " type $typeFlag entrySize = $entrySize")
currentPosition += entrySize // skips rest of the entry's actual contents currentPosition += entrySize // skips rest of the entry's actual contents
fis.skipNBytes(entrySize) fa.seek(currentPosition)
if (typeFlag > 0) { if (typeFlag > 0) {
if (entryToOffsetTable[entryID] != null) if (entryToOffsetTable[entryID] != null)
@@ -226,7 +260,7 @@ removefile:
} }
fis.close() fa.close()
initialised = true initialised = true
} }