mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
and now fa and fis works the same? wtf?
This commit is contained in:
@@ -788,6 +788,7 @@ fun AppUpdateListOfSavegames() {
|
||||
|
||||
println("Listing saved worlds...")
|
||||
|
||||
|
||||
// create list of worlds
|
||||
File(worldsDir).listFiles().filter { !it.isDirectory && !it.name.contains('.') }.mapNotNull { file ->
|
||||
try {
|
||||
@@ -834,7 +835,7 @@ fun AppUpdateListOfSavegames() {
|
||||
null
|
||||
}
|
||||
}.sortedByDescending { it.getLastModifiedTime() }.forEachIndexed { index, it ->
|
||||
// println("${index+1}.\t${it.diskFile.absolutePath}")
|
||||
println("${index+1}.\t${it.diskFile.absolutePath}")
|
||||
// it.rebuild()
|
||||
|
||||
// val jsonFile = it.getFile(SAVEGAMEINFO)!!
|
||||
@@ -854,6 +855,11 @@ fun AppUpdateListOfSavegames() {
|
||||
}
|
||||
}
|
||||
|
||||
println("SortedPlayers...")
|
||||
App.sortedPlayers.forEach {
|
||||
println(it)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.ui.Movement
|
||||
import net.torvald.terrarum.ui.Toolkit
|
||||
@@ -92,39 +93,53 @@ class UILoadList(val full: UILoadSavegame) : UICanvas() {
|
||||
full.changePanelTo(1)
|
||||
}
|
||||
|
||||
private var showCalled = false
|
||||
|
||||
override fun show() {
|
||||
mode1Node.parent = full.remoCon.treeRoot
|
||||
mode1Node.data = "MENU_MODE_SINGLEPLAYER : net.torvald.terrarum.modulebasegame.ui.UILoadSavegame"
|
||||
full.remoCon.setNewRemoConContents(mode1Node)
|
||||
playerCells.clear()
|
||||
if (!showCalled) {
|
||||
showCalled = true
|
||||
// println("UILoadList ${this.hashCode()} show called by:")
|
||||
// printStackTrace(this)
|
||||
|
||||
try {
|
||||
full.remoCon.handler.lockToggle()
|
||||
showSpinner = true
|
||||
mode1Node.parent = full.remoCon.treeRoot
|
||||
mode1Node.data = "MENU_MODE_SINGLEPLAYER : net.torvald.terrarum.modulebasegame.ui.UILoadSavegame"
|
||||
full.remoCon.setNewRemoConContents(mode1Node)
|
||||
playerCells.clear()
|
||||
|
||||
Thread {
|
||||
// read savegames
|
||||
var savegamesCount = 0
|
||||
App.sortedPlayers.forEach { uuid ->
|
||||
val x = full.uiX
|
||||
val y = titleTopGradEnd + cellInterval * savegamesCount
|
||||
try {
|
||||
playerCells.add(UIItemPlayerCells(full, x, y, uuid))
|
||||
savegamesCount += 1
|
||||
try {
|
||||
full.remoCon.handler.lockToggle()
|
||||
showSpinner = true
|
||||
|
||||
Thread {
|
||||
// read savegames
|
||||
var savegamesCount = 0
|
||||
printdbg(this, "============== ${this.hashCode()} ============== ")
|
||||
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) {
|
||||
System.err.println("[UILoadSavegame] Error while loading Player with UUID $uuid")
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
printdbg(this, "============== ${this.hashCode()} ============== ")
|
||||
|
||||
|
||||
full.remoCon.handler.unlockToggle()
|
||||
showSpinner = false
|
||||
}.start()
|
||||
full.remoCon.handler.unlockToggle()
|
||||
showSpinner = false
|
||||
}.start()
|
||||
|
||||
}
|
||||
catch (e: UninitializedPropertyAccessException) {
|
||||
}
|
||||
}
|
||||
catch (e: UninitializedPropertyAccessException) {}
|
||||
}
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
@@ -277,6 +292,7 @@ class UILoadList(val full: UILoadSavegame) : UICanvas() {
|
||||
override fun hide() {
|
||||
playerCells.forEach { it.dispose() }
|
||||
playerCells.clear()
|
||||
showCalled = false
|
||||
}
|
||||
|
||||
override fun resize(width: Int, height: Int) {
|
||||
|
||||
@@ -121,6 +121,40 @@ removefile:
|
||||
if (readStatus != 8) throw InternalError("Unexpected error -- EOF reached? (expected 8, got $readStatus)")
|
||||
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 {
|
||||
return this[0 + offset].toUint().shl(8) or
|
||||
this[1 + offset].toUint()
|
||||
@@ -162,18 +196,18 @@ removefile:
|
||||
|
||||
// fa = RandomAccessFile(diskFile, "rw")
|
||||
|
||||
val fis = FileInputStream(diskFile)
|
||||
val fa = RandomAccessFile(diskFile, "rwd")
|
||||
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()
|
||||
var ccc = 0
|
||||
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
|
||||
|
||||
// fill up the offset table/
|
||||
@@ -181,10 +215,10 @@ removefile:
|
||||
|
||||
// printdbg(this, "Offset $offset, entryID $entryID")
|
||||
|
||||
fis.readInt64() // parentID
|
||||
val typeFlag = fis.read().toByte()
|
||||
fis.readInt24()
|
||||
fis.read(16)
|
||||
fa.readInt64() // parentID
|
||||
val typeFlag = fa.read().toByte()
|
||||
fa.readInt24()
|
||||
fa.read(16)
|
||||
|
||||
currentPosition += 8+4+16
|
||||
|
||||
@@ -193,11 +227,11 @@ removefile:
|
||||
val entrySize = when (typeFlag and 127) {
|
||||
DiskEntry.NORMAL_FILE -> {
|
||||
currentPosition += 6
|
||||
fis.readInt48()
|
||||
fa.readInt48()
|
||||
}
|
||||
DiskEntry.DIRECTORY -> {
|
||||
currentPosition += 4
|
||||
fis.readInt32().toLong() * 8L
|
||||
fa.readInt32().toLong() * 8L
|
||||
}
|
||||
else -> 0
|
||||
}
|
||||
@@ -205,7 +239,7 @@ removefile:
|
||||
// printdbg(this, " type $typeFlag entrySize = $entrySize")
|
||||
|
||||
currentPosition += entrySize // skips rest of the entry's actual contents
|
||||
fis.skipNBytes(entrySize)
|
||||
fa.seek(currentPosition)
|
||||
|
||||
if (typeFlag > 0) {
|
||||
if (entryToOffsetTable[entryID] != null)
|
||||
@@ -226,7 +260,7 @@ removefile:
|
||||
|
||||
}
|
||||
|
||||
fis.close()
|
||||
fa.close()
|
||||
initialised = true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user