mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 11:15:12 -04:00
Fixed another userdata related persistence issue (discrepancy in callback name after load leading to userdata failing to be saved again).
This commit is contained in:
parent
ac25db2c0d
commit
0c96d38afb
Binary file not shown.
Binary file not shown.
@ -276,7 +276,7 @@ wrappedUserdataMeta = {
|
|||||||
-- We need custom persist logic here to avoid ERIS trying to save the
|
-- We need custom persist logic here to avoid ERIS trying to save the
|
||||||
-- userdata referenced in this table directly. It will be repopulated
|
-- userdata referenced in this table directly. It will be repopulated
|
||||||
-- in the load methods of the persisted userdata wrappers (see below).
|
-- in the load methods of the persisted userdata wrappers (see below).
|
||||||
[persistKey or "LuaJ"] = function()
|
[persistKey and persistKey() or "LuaJ"] = function()
|
||||||
return function()
|
return function()
|
||||||
-- When using special persistence we have to manually reassign the
|
-- When using special persistence we have to manually reassign the
|
||||||
-- metatable of the persisted value.
|
-- 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
|
-- of the actual class when saving, so we can create a new instance via
|
||||||
-- reflection when loading again (and then immediately wrap it again).
|
-- reflection when loading again (and then immediately wrap it again).
|
||||||
-- Collect wrapped callback methods.
|
-- Collect wrapped callback methods.
|
||||||
[persistKey or "LuaJ"] = function(self)
|
[persistKey and persistKey() or "LuaJ"] = function(self)
|
||||||
local className, nbt = userdata.save(wrappedUserdata[self])
|
local className, nbt = userdata.save(wrappedUserdata[self])
|
||||||
-- The returned closure is what actually gets persisted, including the
|
-- The returned closure is what actually gets persisted, including the
|
||||||
-- upvalues, that being the classname and a byte array representing the
|
-- upvalues, that being the classname and a byte array representing the
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package li.cil.oc.server.component.machine
|
package li.cil.oc.server.component.machine
|
||||||
|
|
||||||
import li.cil.oc.api
|
import li.cil.oc.api
|
||||||
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
|
|
||||||
abstract class ArchitectureAPI(val machine: api.machine.Machine) {
|
abstract class ArchitectureAPI(val machine: api.machine.Machine) {
|
||||||
protected def node = machine.node
|
protected def node = machine.node
|
||||||
@ -8,4 +9,8 @@ abstract class ArchitectureAPI(val machine: api.machine.Machine) {
|
|||||||
protected def components = machine.components
|
protected def components = machine.components
|
||||||
|
|
||||||
def initialize()
|
def initialize()
|
||||||
|
|
||||||
|
def load(nbt: NBTTagCompound) {}
|
||||||
|
|
||||||
|
def save(nbt: NBTTagCompound) {}
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ class LuaJLuaArchitecture(val machine: api.machine.Machine) extends Architecture
|
|||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
case e: LuaError =>
|
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")
|
new ExecutionResult.Error("kernel panic: this is a bug, check your log file and report it")
|
||||||
case e: Throwable =>
|
case e: Throwable =>
|
||||||
OpenComputers.log.log(Level.WARNING, "Unexpected error in kernel. This is a bug!", e)
|
OpenComputers.log.log(Level.WARNING, "Unexpected error in kernel. This is a bug!", e)
|
||||||
|
@ -355,6 +355,10 @@ class NativeLuaArchitecture(val machine: api.machine.Machine) extends Architectu
|
|||||||
}
|
}
|
||||||
|
|
||||||
kernelMemory = (nbt.getInteger("kernelMemory") * ramScale).toInt
|
kernelMemory = (nbt.getInteger("kernelMemory") * ramScale).toInt
|
||||||
|
|
||||||
|
for (api <- apis) {
|
||||||
|
api.load(nbt)
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
case e: LuaRuntimeException =>
|
case e: LuaRuntimeException =>
|
||||||
OpenComputers.log.warning("Could not unpersist computer.\n" + e.toString + (if (e.getLuaStackTrace.isEmpty) "" else "\tat " + e.getLuaStackTrace.mkString("\n\tat ")))
|
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)
|
nbt.setInteger("kernelMemory", math.ceil(kernelMemory / ramScale).toInt)
|
||||||
|
|
||||||
|
for (api <- apis) {
|
||||||
|
api.save(nbt)
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
case e: LuaRuntimeException =>
|
case e: LuaRuntimeException =>
|
||||||
OpenComputers.log.warning("Could not persist computer.\n" + e.toString + (if (e.getLuaStackTrace.isEmpty) "" else "\tat " + e.getLuaStackTrace.mkString("\n\tat ")))
|
OpenComputers.log.warning("Could not persist computer.\n" + e.toString + (if (e.getLuaStackTrace.isEmpty) "" else "\tat " + e.getLuaStackTrace.mkString("\n\tat ")))
|
||||||
|
@ -5,13 +5,20 @@ import java.util.UUID
|
|||||||
import com.naef.jnlua.LuaState
|
import com.naef.jnlua.LuaState
|
||||||
import li.cil.oc.Settings
|
import li.cil.oc.Settings
|
||||||
import li.cil.oc.server.component.machine.NativeLuaArchitecture
|
import li.cil.oc.server.component.machine.NativeLuaArchitecture
|
||||||
|
import li.cil.oc.util.ExtendedLuaState._
|
||||||
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
|
|
||||||
import scala.collection.mutable
|
import scala.collection.mutable
|
||||||
|
|
||||||
class PersistenceAPI(owner: NativeLuaArchitecture) extends NativeLuaAPI(owner) {
|
class PersistenceAPI(owner: NativeLuaArchitecture) extends NativeLuaAPI(owner) {
|
||||||
|
private var persistKey = "__persist" + UUID.randomUUID().toString.replaceAll("-", "")
|
||||||
|
|
||||||
override def initialize() {
|
override def initialize() {
|
||||||
// Will be replaced by old value in load.
|
// 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")
|
lua.setGlobal("persistKey")
|
||||||
|
|
||||||
if (Settings.get.allowPersistence) {
|
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() {
|
def configure() {
|
||||||
lua.getGlobal("eris")
|
lua.getGlobal("eris")
|
||||||
|
|
||||||
lua.getField(-1, "settings")
|
lua.getField(-1, "settings")
|
||||||
lua.pushString("spkey")
|
lua.pushString("spkey")
|
||||||
lua.getGlobal("persistKey")
|
lua.pushString(persistKey)
|
||||||
lua.call(2, 0)
|
lua.call(2, 0)
|
||||||
|
|
||||||
if (Settings.get.debugPersistence) {
|
|
||||||
lua.getField(-1, "settings")
|
lua.getField(-1, "settings")
|
||||||
lua.pushString("path")
|
lua.pushString("path")
|
||||||
lua.pushBoolean(true)
|
lua.pushBoolean(Settings.get.debugPersistence)
|
||||||
lua.call(2, 0)
|
lua.call(2, 0)
|
||||||
}
|
|
||||||
|
|
||||||
lua.pop(1)
|
lua.pop(1)
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import cpw.mods.fml.common.{ITickHandler, TickType}
|
|||||||
import cpw.mods.fml.relauncher.Side
|
import cpw.mods.fml.relauncher.Side
|
||||||
import net.minecraft.client.Minecraft
|
import net.minecraft.client.Minecraft
|
||||||
import org.lwjgl.BufferUtils
|
import org.lwjgl.BufferUtils
|
||||||
import org.lwjgl.openal.{AL10, Util}
|
import org.lwjgl.openal.{AL, AL10, Util}
|
||||||
|
|
||||||
import scala.collection.mutable
|
import scala.collection.mutable
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ object Audio extends ITickHandler {
|
|||||||
def play(x: Float, y: Float, z: Float, frequencyInHz: Int, durationInMilliseconds: Int) {
|
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 distanceBasedGain = math.max(0, 1 - Minecraft.getMinecraft.thePlayer.getDistance(x, y, z) / 12).toFloat
|
||||||
val gain = distanceBasedGain * volume
|
val gain = distanceBasedGain * volume
|
||||||
if (gain > 0) {
|
if (gain > 0 && AL.isCreated) {
|
||||||
val sampleCount = durationInMilliseconds * sampleRate / 1000
|
val sampleCount = durationInMilliseconds * sampleRate / 1000
|
||||||
val data = BufferUtils.createByteBuffer(sampleCount)
|
val data = BufferUtils.createByteBuffer(sampleCount)
|
||||||
val step = frequencyInHz / sampleRate.toFloat
|
val step = frequencyInHz / sampleRate.toFloat
|
||||||
@ -57,8 +57,10 @@ object Audio extends ITickHandler {
|
|||||||
sources.synchronized(sources --= sources.filter(_.checkFinished))
|
sources.synchronized(sources --= sources.filter(_.checkFinished))
|
||||||
|
|
||||||
// Clear error stack.
|
// Clear error stack.
|
||||||
|
if (AL.isCreated) {
|
||||||
AL10.alGetError()
|
AL10.alGetError()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class Source(val x: Float, y: Float, z: Float, val data: ByteBuffer, val gain: Float) {
|
private class Source(val x: Float, y: Float, z: Float, val data: ByteBuffer, val gain: Float) {
|
||||||
// Clear error stack.
|
// Clear error stack.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user