mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 10:04:05 +09:00
writing savemode to the savegame binary
This commit is contained in:
@@ -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
|
// by doing this, whatever the "possession" the player had will be broken by the game load
|
||||||
actorNowPlaying = getActorByID(Terrarum.PLAYER_REF_ID) as IngamePlayer
|
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() {
|
private fun postInitForNewGame() {
|
||||||
@@ -314,7 +316,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
// make initial savefile
|
// make initial savefile
|
||||||
WriteSavegame.immediate(savegameArchive, getSaveFileMain(), this) {
|
WriteSavegame.immediate(savegameArchive, getSaveFileMain(), this) {
|
||||||
makeSavegameBackupCopy()
|
makeSavegameBackupCopy() // don't put it on the postInit() or render(); must be called using callback
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ object Quicksave : ConsoleCommand {
|
|||||||
override fun execute(args: Array<String>) {
|
override fun execute(args: Array<String>) {
|
||||||
val ingame = Terrarum.ingame!! as TerrarumIngame
|
val ingame = Terrarum.ingame!! as TerrarumIngame
|
||||||
|
|
||||||
WriteSavegame.quick(ingame.savegameArchive, ingame.getSaveFileMain(), ingame) {
|
WriteSavegame.quick(ingame.savegameArchive, ingame.getSaveFileMain(), ingame, false) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -359,7 +359,8 @@ class UIItemDemoSaveCells(
|
|||||||
// file size
|
// file size
|
||||||
App.fontSmallNumbers.draw(batch, "${disk.usedBytes.ushr(10)} KiB", x + 3f, y + height - 16f)
|
App.fontSmallNumbers.draw(batch, "${disk.usedBytes.ushr(10)} KiB", x + 3f, y + height - 16f)
|
||||||
// savegame name
|
// 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)
|
super.render(batch, camera)
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import net.torvald.terrarum.console.Echo
|
|||||||
import net.torvald.terrarum.modulebasegame.IngameRenderer
|
import net.torvald.terrarum.modulebasegame.IngameRenderer
|
||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||||
import net.torvald.terrarum.realestate.LandUtil
|
import net.torvald.terrarum.realestate.LandUtil
|
||||||
|
import net.torvald.terrarum.toInt
|
||||||
import net.torvald.terrarum.tvda.*
|
import net.torvald.terrarum.tvda.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.zip.GZIPOutputStream
|
import java.util.zip.GZIPOutputStream
|
||||||
@@ -15,7 +16,7 @@ import java.util.zip.GZIPOutputStream
|
|||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2021-09-29.
|
* 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
|
* Will happily overwrite existing entry
|
||||||
@@ -130,14 +131,14 @@ class QuickSaveThread(val disk: VirtualDisk, val file: File, val ingame: Terraru
|
|||||||
|
|
||||||
skimmer.rewriteDirectories()
|
skimmer.rewriteDirectories()
|
||||||
skimmer.injectDiskCRC(disk.hashCode())
|
skimmer.injectDiskCRC(disk.hashCode())
|
||||||
|
skimmer.setSaveMode(1 + 2 * isAuto.toInt())
|
||||||
|
|
||||||
Echo ("${ccW}Game saved with size of $ccG${file.length()}$ccW bytes")
|
Echo ("${ccW}Game saved with size of $ccG${file.length()}$ccW bytes")
|
||||||
|
|
||||||
|
|
||||||
if (hasThumbnail) IngameRenderer.fboRGBexportedLatch = false
|
if (hasThumbnail) IngameRenderer.fboRGBexportedLatch = false
|
||||||
WriteSavegame.savingStatus = 255
|
WriteSavegame.savingStatus = 255
|
||||||
ingame.modifiedChunks.forEach { it.clear() }
|
ingame.clearModifiedChunks()
|
||||||
|
|
||||||
callback()
|
callback()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ object WriteSavegame {
|
|||||||
// use field 'savingStatus' to know when the saving is done
|
// 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
|
savingStatus = 0
|
||||||
|
|
||||||
Echo("Quicksave queued")
|
Echo("Quicksave queued")
|
||||||
@@ -88,7 +88,7 @@ object WriteSavegame {
|
|||||||
}
|
}
|
||||||
IngameRenderer.fboRGBexportRequested = true
|
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()
|
savingThread.start()
|
||||||
|
|
||||||
// it is caller's job to keep the game paused or keep a "save in progress" ui up
|
// it is caller's job to keep the game paused or keep a "save in progress" ui up
|
||||||
|
|||||||
@@ -301,6 +301,11 @@ removefile:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setSaveMode(bits: Int) {
|
||||||
|
fa.seek(49L)
|
||||||
|
fa.writeByte(bits)
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
// THESE ARE METHODS TO SUPPORT ON-LINE MODIFICATION //
|
// THESE ARE METHODS TO SUPPORT ON-LINE MODIFICATION //
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -64,7 +64,10 @@ Version 254 is a customised version of TEVD tailored to be used as a savegame fo
|
|||||||
Int8 0xFE
|
Int8 0xFE
|
||||||
Int8 Disk properties flag 1
|
Int8 Disk properties flag 1
|
||||||
0th bit: readonly
|
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)
|
Unit8[236] Rest of the long disk name (268 bytes total)
|
||||||
|
|
||||||
(Header size: 300 bytes)
|
(Header size: 300 bytes)
|
||||||
@@ -127,6 +130,9 @@ class VirtualDisk(
|
|||||||
var isReadOnly: Boolean
|
var isReadOnly: Boolean
|
||||||
set(value) { extraInfoBytes[0] = (extraInfoBytes[0] and 0xFE.toByte()) or value.toBit() }
|
set(value) { extraInfoBytes[0] = (extraInfoBytes[0] and 0xFE.toByte()) or value.toBit() }
|
||||||
get() = capacity == 0L || (extraInfoBytes.size > 0 && extraInfoBytes[0].and(1) == 1.toByte())
|
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)
|
fun getDiskNameString(charset: Charset) = diskName.toCanonicalString(charset)
|
||||||
val root: DiskEntry
|
val root: DiskEntry
|
||||||
get() = entries[0]!!
|
get() = entries[0]!!
|
||||||
|
|||||||
Reference in New Issue
Block a user