writing savemode to the savegame binary

This commit is contained in:
minjaesong
2021-09-29 17:34:26 +09:00
parent 60a8382f93
commit 7ddde8e4f0
7 changed files with 24 additions and 9 deletions

View File

@@ -291,6 +291,8 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
// by doing this, whatever the "possession" the player had will be broken by the game load
actorNowPlaying = getActorByID(Terrarum.PLAYER_REF_ID) as IngamePlayer
makeSavegameBackupCopy() // don't put it on the postInit() or render(); postInitForNewGame calls this function on the savegamewriter's callback
}
private fun postInitForNewGame() {
@@ -314,7 +316,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
// make initial savefile
WriteSavegame.immediate(savegameArchive, getSaveFileMain(), this) {
makeSavegameBackupCopy()
makeSavegameBackupCopy() // don't put it on the postInit() or render(); must be called using callback
}
}

View File

@@ -53,7 +53,7 @@ object Quicksave : ConsoleCommand {
override fun execute(args: Array<String>) {
val ingame = Terrarum.ingame!! as TerrarumIngame
WriteSavegame.quick(ingame.savegameArchive, ingame.getSaveFileMain(), ingame) {
WriteSavegame.quick(ingame.savegameArchive, ingame.getSaveFileMain(), ingame, false) {
}
}

View File

@@ -359,7 +359,8 @@ class UIItemDemoSaveCells(
// file size
App.fontSmallNumbers.draw(batch, "${disk.usedBytes.ushr(10)} KiB", x + 3f, y + height - 16f)
// savegame name
App.fontGame.draw(batch, disk.getDiskNameString(Common.CHARSET), x + 3f, y + 1f)
val diskName = disk.getDiskNameString(Common.CHARSET)
App.fontGame.draw(batch, diskName + "${if (disk.saveMode % 2 == 1) "*" else ""}", x + 3f, y + 1f)
super.render(batch, camera)
batch.color = Color.WHITE

View File

@@ -8,6 +8,7 @@ import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.modulebasegame.IngameRenderer
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.realestate.LandUtil
import net.torvald.terrarum.toInt
import net.torvald.terrarum.tvda.*
import java.io.File
import java.util.zip.GZIPOutputStream
@@ -15,7 +16,7 @@ import java.util.zip.GZIPOutputStream
/**
* Created by minjaesong on 2021-09-29.
*/
class QuickSaveThread(val disk: VirtualDisk, val file: File, val ingame: TerrarumIngame, val hasThumbnail: Boolean, val callback: () -> Unit) : Runnable {
class QuickSaveThread(val disk: VirtualDisk, val file: File, val ingame: TerrarumIngame, val hasThumbnail: Boolean, val isAuto: Boolean, val callback: () -> Unit) : Runnable {
/**
* Will happily overwrite existing entry
@@ -130,14 +131,14 @@ class QuickSaveThread(val disk: VirtualDisk, val file: File, val ingame: Terraru
skimmer.rewriteDirectories()
skimmer.injectDiskCRC(disk.hashCode())
skimmer.setSaveMode(1 + 2 * isAuto.toInt())
Echo ("${ccW}Game saved with size of $ccG${file.length()}$ccW bytes")
if (hasThumbnail) IngameRenderer.fboRGBexportedLatch = false
WriteSavegame.savingStatus = 255
ingame.modifiedChunks.forEach { it.clear() }
ingame.clearModifiedChunks()
callback()
}

View File

@@ -68,7 +68,7 @@ object WriteSavegame {
// use field 'savingStatus' to know when the saving is done
}
fun quick(disk: VirtualDisk, file: File, ingame: TerrarumIngame, callback: () -> Unit = {}) {
fun quick(disk: VirtualDisk, file: File, ingame: TerrarumIngame, isAuto: Boolean, callback: () -> Unit = {}) {
savingStatus = 0
Echo("Quicksave queued")
@@ -88,7 +88,7 @@ object WriteSavegame {
}
IngameRenderer.fboRGBexportRequested = true
val savingThread = Thread(QuickSaveThread(disk, file, ingame, true, callback), "TerrarumBasegameGameSaveThread")
val savingThread = Thread(QuickSaveThread(disk, file, ingame, true, isAuto, callback), "TerrarumBasegameGameSaveThread")
savingThread.start()
// it is caller's job to keep the game paused or keep a "save in progress" ui up

View File

@@ -301,6 +301,11 @@ removefile:
}
}
fun setSaveMode(bits: Int) {
fa.seek(49L)
fa.writeByte(bits)
}
///////////////////////////////////////////////////////
// THESE ARE METHODS TO SUPPORT ON-LINE MODIFICATION //
///////////////////////////////////////////////////////

View File

@@ -64,7 +64,10 @@ Version 254 is a customised version of TEVD tailored to be used as a savegame fo
Int8 0xFE
Int8 Disk properties flag 1
0th bit: readonly
Int8[15] Extra info bytes
Int8 Save type
0th bit: unset - full save; set - quick save
1st bit: set - generated by autosave
Int8[14] Extra info bytes
Unit8[236] Rest of the long disk name (268 bytes total)
(Header size: 300 bytes)
@@ -127,6 +130,9 @@ class VirtualDisk(
var isReadOnly: Boolean
set(value) { extraInfoBytes[0] = (extraInfoBytes[0] and 0xFE.toByte()) or value.toBit() }
get() = capacity == 0L || (extraInfoBytes.size > 0 && extraInfoBytes[0].and(1) == 1.toByte())
var saveMode: Int
set(value) { extraInfoBytes[1] = value.toByte() }
get() = extraInfoBytes[1].toUint()
fun getDiskNameString(charset: Charset) = diskName.toCanonicalString(charset)
val root: DiskEntry
get() = entries[0]!!