diff --git a/src/main/resources/assets/opencomputers/lib/native.32.dll b/src/main/resources/assets/opencomputers/lib/native.32.dll index d311f63a6..3628e438f 100644 Binary files a/src/main/resources/assets/opencomputers/lib/native.32.dll and b/src/main/resources/assets/opencomputers/lib/native.32.dll differ diff --git a/src/main/resources/assets/opencomputers/lib/native.64.dll b/src/main/resources/assets/opencomputers/lib/native.64.dll index 2acc4e534..892438624 100644 Binary files a/src/main/resources/assets/opencomputers/lib/native.64.dll and b/src/main/resources/assets/opencomputers/lib/native.64.dll differ diff --git a/src/main/resources/assets/opencomputers/lua/kernel.lua b/src/main/resources/assets/opencomputers/lua/kernel.lua index 300cba059..084da241b 100644 --- a/src/main/resources/assets/opencomputers/lua/kernel.lua +++ b/src/main/resources/assets/opencomputers/lua/kernel.lua @@ -276,7 +276,7 @@ wrappedUserdataMeta = { -- We need custom persist logic here to avoid ERIS trying to save the -- userdata referenced in this table directly. It will be repopulated -- in the load methods of the persisted userdata wrappers (see below). - [persistKey or "LuaJ"] = function() + [persistKey and persistKey() or "LuaJ"] = function() return function() -- When using special persistence we have to manually reassign the -- metatable of the persisted value. @@ -343,7 +343,7 @@ local userdataWrapper = { -- of the actual class when saving, so we can create a new instance via -- reflection when loading again (and then immediately wrap it again). -- Collect wrapped callback methods. - [persistKey or "LuaJ"] = function(self) + [persistKey and persistKey() or "LuaJ"] = function(self) local className, nbt = userdata.save(wrappedUserdata[self]) -- The returned closure is what actually gets persisted, including the -- upvalues, that being the classname and a byte array representing the diff --git a/src/main/scala/li/cil/oc/server/component/machine/ArchitectureAPI.scala b/src/main/scala/li/cil/oc/server/component/machine/ArchitectureAPI.scala index 30c8b1d10..5bbd0f440 100644 --- a/src/main/scala/li/cil/oc/server/component/machine/ArchitectureAPI.scala +++ b/src/main/scala/li/cil/oc/server/component/machine/ArchitectureAPI.scala @@ -1,6 +1,7 @@ package li.cil.oc.server.component.machine import li.cil.oc.api +import net.minecraft.nbt.NBTTagCompound abstract class ArchitectureAPI(val machine: api.machine.Machine) { protected def node = machine.node @@ -8,4 +9,8 @@ abstract class ArchitectureAPI(val machine: api.machine.Machine) { protected def components = machine.components def initialize() + + def load(nbt: NBTTagCompound) {} + + def save(nbt: NBTTagCompound) {} } diff --git a/src/main/scala/li/cil/oc/server/component/machine/LuaJLuaArchitecture.scala b/src/main/scala/li/cil/oc/server/component/machine/LuaJLuaArchitecture.scala index 91d3e1abd..6eec110f5 100644 --- a/src/main/scala/li/cil/oc/server/component/machine/LuaJLuaArchitecture.scala +++ b/src/main/scala/li/cil/oc/server/component/machine/LuaJLuaArchitecture.scala @@ -181,7 +181,7 @@ class LuaJLuaArchitecture(val machine: api.machine.Machine) extends Architecture } catch { case e: LuaError => - OpenComputers.log.log(Level.WARNING, "Kernel crashed. This is a bug!" + e) + OpenComputers.log.log(Level.WARNING, "Kernel crashed. This is a bug!", e) new ExecutionResult.Error("kernel panic: this is a bug, check your log file and report it") case e: Throwable => OpenComputers.log.log(Level.WARNING, "Unexpected error in kernel. This is a bug!", e) diff --git a/src/main/scala/li/cil/oc/server/component/machine/NativeLuaArchitecture.scala b/src/main/scala/li/cil/oc/server/component/machine/NativeLuaArchitecture.scala index 65e97e36e..c931e1875 100644 --- a/src/main/scala/li/cil/oc/server/component/machine/NativeLuaArchitecture.scala +++ b/src/main/scala/li/cil/oc/server/component/machine/NativeLuaArchitecture.scala @@ -355,6 +355,10 @@ class NativeLuaArchitecture(val machine: api.machine.Machine) extends Architectu } kernelMemory = (nbt.getInteger("kernelMemory") * ramScale).toInt + + for (api <- apis) { + api.load(nbt) + } } catch { case e: LuaRuntimeException => OpenComputers.log.warning("Could not unpersist computer.\n" + e.toString + (if (e.getLuaStackTrace.isEmpty) "" else "\tat " + e.getLuaStackTrace.mkString("\n\tat "))) @@ -397,6 +401,10 @@ class NativeLuaArchitecture(val machine: api.machine.Machine) extends Architectu } nbt.setInteger("kernelMemory", math.ceil(kernelMemory / ramScale).toInt) + + for (api <- apis) { + api.save(nbt) + } } catch { case e: LuaRuntimeException => OpenComputers.log.warning("Could not persist computer.\n" + e.toString + (if (e.getLuaStackTrace.isEmpty) "" else "\tat " + e.getLuaStackTrace.mkString("\n\tat "))) diff --git a/src/main/scala/li/cil/oc/server/component/machine/luac/PersistenceAPI.scala b/src/main/scala/li/cil/oc/server/component/machine/luac/PersistenceAPI.scala index 3882ab79e..372acb50c 100644 --- a/src/main/scala/li/cil/oc/server/component/machine/luac/PersistenceAPI.scala +++ b/src/main/scala/li/cil/oc/server/component/machine/luac/PersistenceAPI.scala @@ -5,13 +5,20 @@ import java.util.UUID import com.naef.jnlua.LuaState import li.cil.oc.Settings import li.cil.oc.server.component.machine.NativeLuaArchitecture +import li.cil.oc.util.ExtendedLuaState._ +import net.minecraft.nbt.NBTTagCompound import scala.collection.mutable class PersistenceAPI(owner: NativeLuaArchitecture) extends NativeLuaAPI(owner) { + private var persistKey = "__persist" + UUID.randomUUID().toString.replaceAll("-", "") + override def initialize() { // Will be replaced by old value in load. - lua.pushString("__persist" + UUID.randomUUID().toString.replaceAll("-", "")) + lua.pushScalaFunction(lua => { + lua.pushString(persistKey) + 1 + }) lua.setGlobal("persistKey") if (Settings.get.allowPersistence) { @@ -84,20 +91,30 @@ class PersistenceAPI(owner: NativeLuaArchitecture) extends NativeLuaAPI(owner) { } } + override def load(nbt: NBTTagCompound) { + super.load(nbt) + if (nbt.hasKey("persistKey")) { + persistKey = nbt.getString("persistKey") + } + } + + override def save(nbt: NBTTagCompound) { + super.save(nbt) + nbt.setString("persistKey", persistKey) + } + def configure() { lua.getGlobal("eris") lua.getField(-1, "settings") lua.pushString("spkey") - lua.getGlobal("persistKey") + lua.pushString(persistKey) lua.call(2, 0) - if (Settings.get.debugPersistence) { - lua.getField(-1, "settings") - lua.pushString("path") - lua.pushBoolean(true) - lua.call(2, 0) - } + lua.getField(-1, "settings") + lua.pushString("path") + lua.pushBoolean(Settings.get.debugPersistence) + lua.call(2, 0) lua.pop(1) } diff --git a/src/main/scala/li/cil/oc/util/Audio.scala b/src/main/scala/li/cil/oc/util/Audio.scala index 53677c205..5d5089135 100644 --- a/src/main/scala/li/cil/oc/util/Audio.scala +++ b/src/main/scala/li/cil/oc/util/Audio.scala @@ -8,7 +8,7 @@ import cpw.mods.fml.common.{ITickHandler, TickType} import cpw.mods.fml.relauncher.Side import net.minecraft.client.Minecraft import org.lwjgl.BufferUtils -import org.lwjgl.openal.{AL10, Util} +import org.lwjgl.openal.{AL, AL10, Util} import scala.collection.mutable @@ -29,7 +29,7 @@ object Audio extends ITickHandler { def play(x: Float, y: Float, z: Float, frequencyInHz: Int, durationInMilliseconds: Int) { val distanceBasedGain = math.max(0, 1 - Minecraft.getMinecraft.thePlayer.getDistance(x, y, z) / 12).toFloat val gain = distanceBasedGain * volume - if (gain > 0) { + if (gain > 0 && AL.isCreated) { val sampleCount = durationInMilliseconds * sampleRate / 1000 val data = BufferUtils.createByteBuffer(sampleCount) val step = frequencyInHz / sampleRate.toFloat @@ -57,7 +57,9 @@ object Audio extends ITickHandler { sources.synchronized(sources --= sources.filter(_.checkFinished)) // Clear error stack. - AL10.alGetError() + if (AL.isCreated) { + AL10.alGetError() + } } private class Source(val x: Float, y: Float, z: Float, val data: ByteBuffer, val gain: Float) {