mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-15 04:54:05 +09:00
wip 2
This commit is contained in:
@@ -2,6 +2,7 @@ package net.torvald.terrarum.serialise
|
||||
|
||||
import com.badlogic.gdx.utils.compression.Lzma
|
||||
import net.torvald.terrarum.AppLoader.printdbg
|
||||
import net.torvald.terrarum.gameitem.ItemID
|
||||
import net.torvald.terrarum.gameworld.BlockAddress
|
||||
import net.torvald.terrarum.gameworld.BlockLayer
|
||||
import net.torvald.terrarum.gameworld.FluidType
|
||||
@@ -151,6 +152,7 @@ internal object ReadLayerDataLzma {
|
||||
val wallDamages = HashMap<BlockAddress, Float>()
|
||||
val fluidTypes = HashMap<BlockAddress, FluidType>()
|
||||
val fluidFills = HashMap<BlockAddress, Float>()
|
||||
val tileNumToName = HashMap<Int, ItemID>()
|
||||
|
||||
// parse terrain damages
|
||||
for (c in payloadBytes["TdMG"]!!.indices step 10) {
|
||||
@@ -176,6 +178,8 @@ internal object ReadLayerDataLzma {
|
||||
|
||||
// TODO parse fluid(Types|Fills)
|
||||
|
||||
// TODO parse tileNumToName
|
||||
|
||||
|
||||
return ReadLayerDataZip.LayerData(
|
||||
BlockLayer(width, height, payloadBytes["WALL"]!!),
|
||||
@@ -183,7 +187,7 @@ internal object ReadLayerDataLzma {
|
||||
|
||||
spawnPoint.first, spawnPoint.second,
|
||||
|
||||
wallDamages, terrainDamages, fluidTypes, fluidFills
|
||||
wallDamages, terrainDamages, fluidTypes, fluidFills, tileNumToName
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.torvald.terrarum.serialise
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.AppLoader
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
@@ -9,10 +10,24 @@ import net.torvald.terrarum.gameitem.GameItem
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.*
|
||||
import net.torvald.terrarum.utils.JsonWriter.getJsonBuilder
|
||||
import net.torvald.util.SortedArrayList
|
||||
import java.io.File
|
||||
import java.nio.charset.Charset
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
internal class RNGPool() {
|
||||
private val RNG = HQRNG()
|
||||
private val used = SortedArrayList<Int>()
|
||||
fun next(): Int {
|
||||
var n = RNG.nextLong().ushr(32).toInt()
|
||||
while (used.contains(n)) {
|
||||
n = RNG.nextLong().ushr(32).toInt()
|
||||
}
|
||||
used.add(n)
|
||||
return n
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2018-10-03.
|
||||
*/
|
||||
@@ -20,6 +35,8 @@ object SavegameWriter {
|
||||
|
||||
// TODO create temporary files (worldinfo), create JSON files on RAM, pack those into TEVd as per Savegame container.txt
|
||||
|
||||
private val rngPool = RNGPool()
|
||||
|
||||
private val charset = Charset.forName("UTF-8")
|
||||
|
||||
private lateinit var playerName: String
|
||||
@@ -99,16 +116,16 @@ object SavegameWriter {
|
||||
// actors
|
||||
ingame.actorContainerActive.forEach {
|
||||
VDUtil.registerFile(disk, DiskEntry(
|
||||
it.referenceID!!, ROOT,
|
||||
it.referenceID!!.toString(16).toUpperCase().toByteArray(charset),
|
||||
rngPool.next(), ROOT,
|
||||
it.referenceID.toString(16).toUpperCase().toByteArray(charset),
|
||||
creationDate, creationDate,
|
||||
EntryFile(serialiseActor(it))
|
||||
))
|
||||
}
|
||||
ingame.actorContainerInactive.forEach {
|
||||
VDUtil.registerFile(disk, DiskEntry(
|
||||
it.referenceID!!, ROOT,
|
||||
it.referenceID!!.toString(16).toUpperCase().toByteArray(charset),
|
||||
rngPool.next(), ROOT,
|
||||
it.referenceID.toString(16).toUpperCase().toByteArray(charset),
|
||||
creationDate, creationDate,
|
||||
EntryFile(serialiseActor(it))
|
||||
))
|
||||
@@ -117,8 +134,8 @@ object SavegameWriter {
|
||||
// items
|
||||
ItemCodex.dynamicItemDescription.forEach { dynamicID, item ->
|
||||
VDUtil.registerFile(disk, DiskEntry(
|
||||
item.dynamicID, ROOT,
|
||||
dynamicID.toString(16).toUpperCase().toByteArray(charset),
|
||||
rngPool.next(), ROOT,
|
||||
dynamicID.toByteArray(charset),
|
||||
creationDate, creationDate,
|
||||
EntryFile(serialiseItem(item))
|
||||
))
|
||||
|
||||
@@ -52,8 +52,8 @@ object WriteWorldInfo {
|
||||
val infile = infileList[filenum - 1]
|
||||
|
||||
infile.forEach {
|
||||
outputStream.write("## from file: ${it.nameWithoutExtension()} ##############################\n".toByteArray())
|
||||
val readBytes = it.readBytes()
|
||||
outputStream.write("## from file: ${it.second.nameWithoutExtension()} ##############################\n".toByteArray())
|
||||
val readBytes = it.second.readBytes()
|
||||
outputStream.write(readBytes)
|
||||
outputStream.write("\n".toByteArray())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user