some cleanup in save handler

This commit is contained in:
Florian Nücke 2014-03-16 08:00:46 +01:00
parent 067664dd3e
commit b3a737c57c

View File

@ -3,29 +3,24 @@ package li.cil.oc.common
import java.io
import java.util.logging.Level
import li.cil.oc.{OpenComputers, Settings}
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.world.ChunkCoordIntPair
import net.minecraftforge.common.DimensionManager
import net.minecraftforge.event.ForgeSubscribe
import net.minecraftforge.event.world.WorldEvent
import scala.collection.mutable
// TODO Save all data to an NBT compound and save it as a single file, to improve file I/O performance.
object SaveHandler {
val saveData = mutable.Map.empty[ChunkCoordIntPair, mutable.Map[String, Array[Byte]]]
var cachedNbt = new NBTTagCompound()
def savePath = new io.File(DimensionManager.getCurrentSaveRootDirectory, Settings.savePath + "state")
def scheduleSave(chunk: ChunkCoordIntPair, name: String, data: Array[Byte]) = saveData.synchronized {
if (chunk == null) OpenComputers.log.warning("Cannot save machines with non tile entity owners.")
if (chunk == null) throw new IllegalArgumentException("chunk is null")
else saveData.getOrElseUpdate(chunk, mutable.Map.empty[String, Array[Byte]]) += name -> data
}
def load(chunk: ChunkCoordIntPair, name: String): Array[Byte] = {
if (chunk == null) null
else {
if (chunk == null) throw new IllegalArgumentException("chunk is null")
val path = savePath
val chunkPath = new io.File(path, s"${chunk.chunkXPos}.${chunk.chunkZPos}")
val file = new io.File(chunkPath, name)
@ -50,7 +45,6 @@ object SaveHandler {
Array.empty[Byte]
}
}
}
// Used by the native lua state to store kernel and stack data in auxiliary
// files instead of directly in the tile entity data, avoiding potential