diff --git a/src/main/scala/li/cil/oc/common/SaveHandler.scala b/src/main/scala/li/cil/oc/common/SaveHandler.scala index 629a4dfd5..33211e646 100644 --- a/src/main/scala/li/cil/oc/common/SaveHandler.scala +++ b/src/main/scala/li/cil/oc/common/SaveHandler.scala @@ -9,8 +9,8 @@ import cpw.mods.fml.common.eventhandler.EventPriority import cpw.mods.fml.common.eventhandler.SubscribeEvent import li.cil.oc.OpenComputers import li.cil.oc.Settings -import li.cil.oc.api.network.EnvironmentHost import li.cil.oc.api.machine.MachineHost +import li.cil.oc.api.network.EnvironmentHost import li.cil.oc.util.BlockPosition import net.minecraft.nbt.CompressedStreamTools import net.minecraft.nbt.NBTTagCompound @@ -32,6 +32,16 @@ object SaveHandler { private val TimeToHoldOntoOldSaves = 60 * 1000 + // THIS IS A MASSIVE HACK OF THE UGLIEST KINDS. + // But it works, and the alternative would be to change the Persistable + // interface to pass along this state to *everything that gets saved ever*, + // which in 99% of the cases it doesn't need to know. So yes, this is fugly, + // but the "clean" solution would be no less fugly. + // Why is this even required? To avoid flushing file systems to disk and + // avoid persisting machine states when sending description packets to clients, + // which takes a lot of time and is completely unnecessary in those cases. + var savingForClients = false + val saveData = mutable.Map.empty[Int, mutable.Map[ChunkCoordIntPair, mutable.Map[String, Array[Byte]]]] def savePath = new io.File(DimensionManager.getCurrentSaveRootDirectory, Settings.savePath) diff --git a/src/main/scala/li/cil/oc/common/tileentity/traits/TileEntity.scala b/src/main/scala/li/cil/oc/common/tileentity/traits/TileEntity.scala index 7721b8245..7c7d11c03 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/traits/TileEntity.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/traits/TileEntity.scala @@ -5,7 +5,7 @@ import cpw.mods.fml.relauncher.SideOnly import li.cil.oc.OpenComputers import li.cil.oc.Settings import li.cil.oc.client.Sound -import li.cil.oc.server.fs.FileSystem +import li.cil.oc.common.SaveHandler import li.cil.oc.util.BlockPosition import li.cil.oc.util.SideTracker import net.minecraft.nbt.NBTTagCompound @@ -90,14 +90,15 @@ trait TileEntity extends net.minecraft.tileentity.TileEntity { override def getDescriptionPacket = { val nbt = new NBTTagCompound() - FileSystem.savingForClients = true + // See comment on savingForClients variable. + SaveHandler.savingForClients = true try { try writeToNBTForClient(nbt) catch { case e: Throwable => OpenComputers.log.warn("There was a problem writing a TileEntity description packet. Please report this if you see it!", e) } if (nbt.hasNoTags) null else new S35PacketUpdateTileEntity(x, y, z, -1, nbt) } finally { - FileSystem.savingForClients = false + SaveHandler.savingForClients = false } } diff --git a/src/main/scala/li/cil/oc/server/component/FileSystem.scala b/src/main/scala/li/cil/oc/server/component/FileSystem.scala index 0a90e6859..2871a5743 100644 --- a/src/main/scala/li/cil/oc/server/component/FileSystem.scala +++ b/src/main/scala/li/cil/oc/server/component/FileSystem.scala @@ -14,7 +14,7 @@ import li.cil.oc.api.machine.Context import li.cil.oc.api.network.EnvironmentHost import li.cil.oc.api.network._ import li.cil.oc.api.prefab -import li.cil.oc.server.fs.FileSystem +import li.cil.oc.common.SaveHandler import li.cil.oc.server.{PacketSender => ServerPacketSender} import li.cil.oc.util.ExtendedNBT._ import net.minecraft.nbt.NBTTagCompound @@ -287,7 +287,7 @@ class FileSystem(val fileSystem: IFileSystem, var label: Label, val host: Option label.save(nbt) } - if (!FileSystem.savingForClients) { + if (!SaveHandler.savingForClients) { val ownersNbt = new NBTTagList() for ((address, handles) <- owners) { val ownerNbt = new NBTTagCompound() diff --git a/src/main/scala/li/cil/oc/server/fs/FileSystem.scala b/src/main/scala/li/cil/oc/server/fs/FileSystem.scala index fce6ffb89..e826939d7 100755 --- a/src/main/scala/li/cil/oc/server/fs/FileSystem.scala +++ b/src/main/scala/li/cil/oc/server/fs/FileSystem.scala @@ -22,8 +22,6 @@ import net.minecraftforge.common.DimensionManager import scala.util.Try object FileSystem extends api.detail.FileSystemAPI { - var savingForClients = false - lazy val isCaseInsensitive = Settings.get.forceCaseInsensitive || (try { val uuid = UUID.randomUUID().toString val lowerCase = new io.File(DimensionManager.getCurrentSaveRootDirectory, uuid + "oc_rox") diff --git a/src/main/scala/li/cil/oc/server/machine/Machine.scala b/src/main/scala/li/cil/oc/server/machine/Machine.scala index 6869309a6..0a8223196 100644 --- a/src/main/scala/li/cil/oc/server/machine/Machine.scala +++ b/src/main/scala/li/cil/oc/server/machine/Machine.scala @@ -730,7 +730,7 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach override def save(nbt: NBTTagCompound): Unit = Machine.this.synchronized(state.synchronized { assert(!isExecuting) // Lock on 'this' should guarantee this. - if (FileSystem.savingForClients) { + if (SaveHandler.savingForClients) { return }