mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-16 18:55:03 -04:00
moved machinePosition() to MachineHost
This commit is contained in:
parent
e940d5c745
commit
5065044b74
@ -55,4 +55,13 @@ public interface MachineHost extends EnvironmentHost {
|
|||||||
* @param node the node that was disconnected from the network.
|
* @param node the node that was disconnected from the network.
|
||||||
*/
|
*/
|
||||||
void onMachineDisconnect(Node node);
|
void onMachineDisconnect(Node node);
|
||||||
|
|
||||||
|
/** Helper method for printing the machine position in error messages and debug statements. */
|
||||||
|
default String machinePosition()
|
||||||
|
{
|
||||||
|
if (world() != null && world().provider != null)
|
||||||
|
return String.format("(%g, %g, %g, %d)", xPosition(), yPosition(), zPosition(), world().provider.dimensionId);
|
||||||
|
else
|
||||||
|
return String.format("(%g, %g, %g)", xPosition(), yPosition(), zPosition());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -780,7 +780,7 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach
|
|||||||
catch {
|
catch {
|
||||||
case t: Throwable =>
|
case t: Throwable =>
|
||||||
OpenComputers.log.error(
|
OpenComputers.log.error(
|
||||||
s"""Unexpected error loading a state of computer at ${machinePosition}. """ +
|
s"""Unexpected error loading a state of computer at ${host.machinePosition()}. """ +
|
||||||
s"""State: ${state.headOption.fold("no state")(_.toString)}. Unless you're upgrading/downgrading across a major version, please report this! Thank you.""", t)
|
s"""State: ${state.headOption.fold("no state")(_.toString)}. Unless you're upgrading/downgrading across a major version, please report this! Thank you.""", t)
|
||||||
close()
|
close()
|
||||||
}
|
}
|
||||||
@ -862,7 +862,7 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach
|
|||||||
catch {
|
catch {
|
||||||
case t: Throwable =>
|
case t: Throwable =>
|
||||||
OpenComputers.log.error(
|
OpenComputers.log.error(
|
||||||
s"""Unexpected error saving a state of computer at ${machinePosition}. """ +
|
s"""Unexpected error saving a state of computer at ${host.machinePosition()}. """ +
|
||||||
s"""State: ${state.headOption.fold("no state")(_.toString)}. Unless you're upgrading/downgrading across a major version, please report this! Thank you.""", t)
|
s"""State: ${state.headOption.fold("no state")(_.toString)}. Unless you're upgrading/downgrading across a major version, please report this! Thank you.""", t)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -1039,9 +1039,6 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach
|
|||||||
// Keep track of time spent executing the computer.
|
// Keep track of time spent executing the computer.
|
||||||
cpuTotal += System.nanoTime() - cpuStart
|
cpuTotal += System.nanoTime() - cpuStart
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Helper method for printing the machine position in error messages and debug statements. */
|
|
||||||
private def machinePosition = s"(${host.xPosition}, ${host.yPosition}, ${host.zPosition}, ${host.world().provider.dimensionId})"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object Machine extends MachineAPI {
|
object Machine extends MachineAPI {
|
||||||
|
@ -376,7 +376,7 @@ abstract class NativeLuaArchitecture(val machine: api.machine.Machine) extends A
|
|||||||
|
|
||||||
try lua.gc(LuaState.GcAction.COLLECT, 0) catch {
|
try lua.gc(LuaState.GcAction.COLLECT, 0) catch {
|
||||||
case t: Throwable =>
|
case t: Throwable =>
|
||||||
OpenComputers.log.warn(s"Error cleaning up loaded computer @ ${machinePosition}. This either means the server is badly overloaded or a user created an evil __gc method, accidentally or not.")
|
OpenComputers.log.warn(s"Error cleaning up loaded computer @ ${machine.host().machinePosition()}. This either means the server is badly overloaded or a user created an evil __gc method, accidentally or not.")
|
||||||
machine.crash("error in garbage collector, most likely __gc method timed out")
|
machine.crash("error in garbage collector, most likely __gc method timed out")
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
@ -414,22 +414,19 @@ abstract class NativeLuaArchitecture(val machine: api.machine.Machine) extends A
|
|||||||
|
|
||||||
try lua.gc(LuaState.GcAction.COLLECT, 0) catch {
|
try lua.gc(LuaState.GcAction.COLLECT, 0) catch {
|
||||||
case t: Throwable =>
|
case t: Throwable =>
|
||||||
OpenComputers.log.warn(s"Error cleaning up loaded computer @ ${machinePosition}. This either means the server is badly overloaded or a user created an evil __gc method, accidentally or not.")
|
OpenComputers.log.warn(s"Error cleaning up loaded computer @ ${machine.host().machinePosition()}. This either means the server is badly overloaded or a user created an evil __gc method, accidentally or not.")
|
||||||
machine.crash("error in garbage collector, most likely __gc method timed out")
|
machine.crash("error in garbage collector, most likely __gc method timed out")
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
case e: LuaRuntimeException =>
|
case e: LuaRuntimeException =>
|
||||||
OpenComputers.log.warn(s"Could not persist computer @ ${machinePosition}.\n${e.toString}" + (if (e.getLuaStackTrace.isEmpty) "" else "\tat " + e.getLuaStackTrace.mkString("\n\tat ")))
|
OpenComputers.log.warn(s"Could not persist computer @ ${machine.host().machinePosition()}.\n${e.toString}" + (if (e.getLuaStackTrace.isEmpty) "" else "\tat " + e.getLuaStackTrace.mkString("\n\tat ")))
|
||||||
nbt.removeTag("state")
|
nbt.removeTag("state")
|
||||||
case e: LuaGcMetamethodException =>
|
case e: LuaGcMetamethodException =>
|
||||||
OpenComputers.log.warn(s"Could not persist computer @ ${machinePosition}.\n${e.toString}")
|
OpenComputers.log.warn(s"Could not persist computer @ ${machine.host().machinePosition()}.\n${e.toString}")
|
||||||
nbt.removeTag("state")
|
nbt.removeTag("state")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Limit memory again.
|
// Limit memory again.
|
||||||
recomputeMemory(machine.host.internalComponents)
|
recomputeMemory(machine.host.internalComponents)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Helper method for printing the machine position in error messages and debug statements. */
|
|
||||||
private def machinePosition = s"(${machine.host.xPosition}, ${machine.host.yPosition}, ${machine.host.zPosition}, ${machine.host.world().provider.dimensionId})"
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user