recording and retrieving timestamps for save meta and world

This commit is contained in:
minjaesong
2021-09-11 22:24:13 +09:00
parent 4e0d1e0c9d
commit 784f5fd2ec
10 changed files with 57 additions and 31 deletions

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.serialise
import net.torvald.terrarum.App
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.gameactors.ActorID
import net.torvald.terrarum.modulebasegame.TerrarumIngame
@@ -15,8 +16,9 @@ import net.torvald.terrarum.weather.WeatherMixer
*/
object WriteMeta {
operator fun invoke(ingame: TerrarumIngame, currentPlayTime_t: Long): String {
operator fun invoke(ingame: TerrarumIngame, time_t: Long): String {
val world = ingame.world
val currentPlayTime_t = time_t - ingame.loadedTime_t
val meta = WorldMeta(
genver = Common.GENVER,
@@ -26,9 +28,9 @@ object WriteMeta {
weatseed0 = WeatherMixer.RNG.state0,
weatseed1 = WeatherMixer.RNG.state1,
playerid = ingame.actorGamer.referenceID,
creation_t = world.creationTime,
lastplay_t = world.lastPlayTime,
playtime_t = world.totalPlayTime + currentPlayTime_t,
creation_t = ingame.creationTime,
lastplay_t = App.getTIME_T(),
playtime_t = ingame.totalPlayTime + currentPlayTime_t,
loadorder = ModMgr.loadOrder.toTypedArray(),
worlds = ingame.gameworldIndices.toTypedArray()
)
@@ -36,9 +38,9 @@ object WriteMeta {
return Common.jsoner.toJson(meta)
}
fun encodeToByteArray64(ingame: TerrarumIngame, currentPlayTime_t: Long): ByteArray64 {
fun encodeToByteArray64(ingame: TerrarumIngame, time_t: Long): ByteArray64 {
val ba = ByteArray64()
this.invoke(ingame, currentPlayTime_t).toByteArray(Common.CHARSET).forEach { ba.add(it) }
this.invoke(ingame, time_t).toByteArray(Common.CHARSET).forEach { ba.add(it) }
return ba
}

View File

@@ -46,13 +46,12 @@ object WriteSavegame {
p.dispose()
val creation_t = ingame.world.creationTime
val creation_t = ingame.creationTime
val time_t = App.getTIME_T()
val currentPlayTime_t = time_t - ingame.loadedTime_t
// Write Meta //
val metaContent = EntryFile(WriteMeta.encodeToByteArray64(ingame, currentPlayTime_t))
val metaContent = EntryFile(WriteMeta.encodeToByteArray64(ingame, time_t))
val meta = DiskEntry(-1, 0, creation_t, time_t, metaContent)
addFile(disk, meta)
@@ -98,7 +97,7 @@ object WriteSavegame {
// Write World //
val worldNum = ingame.world.worldIndex
val worldMeta = EntryFile(WriteWorld.encodeToByteArray64(ingame))
val worldMeta = EntryFile(WriteWorld.encodeToByteArray64(ingame, time_t))
val world = DiskEntry(worldNum.toLong(), 0, creation_t, time_t, worldMeta)
addFile(disk, world)
@@ -182,6 +181,9 @@ object LoadSavegame {
newIngame.gameLoadInfoPayload = worldParam
newIngame.gameLoadMode = TerrarumIngame.GameLoadMode.LOAD_FROM
newIngame.savegameArchive = disk
newIngame.creationTime = meta.creation_t
newIngame.lastPlayTime = meta.lastplay_t
newIngame.totalPlayTime = meta.playtime_t
// load all the world blocklayer chunks
val worldnum = world.worldIndex.toLong()

View File

@@ -25,10 +25,14 @@ object WriteWorld {
actor != (CommonResourcePool.get("blockmarking_actor") as BlockMarkerActor)
}
private fun preWrite(ingame: TerrarumIngame): GameWorld {
private fun preWrite(ingame: TerrarumIngame, time_t: Long): GameWorld {
val world = ingame.world
val currentPlayTime_t = time_t - ingame.loadedTime_t
world.genver = Common.GENVER
world.comp = Common.COMP_GZIP
world.lastPlayTime = time_t
world.totalPlayTime += currentPlayTime_t
val actorIDbuf = ArrayList<ActorID>()
ingame.actorContainerActive.filter { actorAcceptable(it) }.forEach { actorIDbuf.add(it.referenceID) }
@@ -40,14 +44,14 @@ object WriteWorld {
return world
}
operator fun invoke(ingame: TerrarumIngame): String {
return Common.jsoner.toJson(preWrite(ingame))
operator fun invoke(ingame: TerrarumIngame, time_t: Long): String {
return Common.jsoner.toJson(preWrite(ingame, time_t))
}
fun encodeToByteArray64(ingame: TerrarumIngame): ByteArray64 {
fun encodeToByteArray64(ingame: TerrarumIngame, time_t: Long): ByteArray64 {
val baw = ByteArray64Writer(Common.CHARSET)
Common.jsoner.toJson(preWrite(ingame), baw)
Common.jsoner.toJson(preWrite(ingame, time_t), baw)
baw.flush(); baw.close()
return baw.toByteArray64()