mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-18 03:36:47 -04:00
Merge remote-tracking branch 'origin/master-MC1.7.10' into master-MC1.12
This commit is contained in:
commit
4a09b855d8
@ -220,8 +220,8 @@ dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
embedded name: 'OC-LuaJ', version: '20220907.1', ext: 'jar'
|
embedded name: 'OC-LuaJ', version: '20220907.1', ext: 'jar'
|
||||||
embedded name: 'OC-JNLua', version: '20220904.0', ext: 'jar'
|
embedded name: 'OC-JNLua', version: '20220928.0', ext: 'jar'
|
||||||
embedded name: 'OC-JNLua-Natives', version: '20220904.0', ext: 'jar'
|
embedded name: 'OC-JNLua-Natives', version: '20220928.0', ext: 'jar'
|
||||||
|
|
||||||
testImplementation("org.mockito:mockito-all:1.10.19")
|
testImplementation("org.mockito:mockito-all:1.10.19")
|
||||||
|
|
||||||
|
@ -1506,10 +1506,21 @@ opencomputers {
|
|||||||
# to work.
|
# to work.
|
||||||
logFullNativeLibLoadErrors: false
|
logFullNativeLibLoadErrors: false
|
||||||
|
|
||||||
# Force loading one specific library, to avoid trying to load any
|
# Force the platform name for the native libraries, instead of relying
|
||||||
# others. Use this if you get warnings in the log or are told to do
|
# on auto-detecting it. Use this if your system is using an otherwise
|
||||||
# so for debugging purposes ;-)
|
# unsupported operating system or CPU architecture. If unsure, leave blank.
|
||||||
forceNativeLibWithName: ""
|
#
|
||||||
|
# Examples of platform strings include "solaris-x86_64" for 64-bit Solaris,
|
||||||
|
# or "windows-aarch64" for Windows on the aarch64 (64-bit arm) architecture.
|
||||||
|
forceNativeLibPlatform: ""
|
||||||
|
|
||||||
|
# Force the native library loader to check the specified directory for natives first,
|
||||||
|
# before trying to find libraries packaged with OpenComputers. Use this if you want to
|
||||||
|
# use custom native libraries, or are on an unsupported platform. If unsure, leave blank.
|
||||||
|
#
|
||||||
|
# This can be an absolute or relative path. If relative, the base directory will be the .minecraft
|
||||||
|
# directory of the running Minecraft instance.
|
||||||
|
forceNativeLibPathFirst: ""
|
||||||
|
|
||||||
# Used to suppress log spam for OpenGL errors on derpy drivers. I'm
|
# Used to suppress log spam for OpenGL errors on derpy drivers. I'm
|
||||||
# quite certain the code in the font render is valid, display list
|
# quite certain the code in the font render is valid, display list
|
||||||
|
@ -442,7 +442,8 @@ class Settings(val config: Config) {
|
|||||||
val limitMemory = !config.getBoolean("debug.disableMemoryLimit")
|
val limitMemory = !config.getBoolean("debug.disableMemoryLimit")
|
||||||
val forceCaseInsensitive = config.getBoolean("debug.forceCaseInsensitiveFS")
|
val forceCaseInsensitive = config.getBoolean("debug.forceCaseInsensitiveFS")
|
||||||
val logFullLibLoadErrors = config.getBoolean("debug.logFullNativeLibLoadErrors")
|
val logFullLibLoadErrors = config.getBoolean("debug.logFullNativeLibLoadErrors")
|
||||||
val forceNativeLib = config.getString("debug.forceNativeLibWithName")
|
val forceNativeLibPlatform = config.getString("debug.forceNativeLibPlatform")
|
||||||
|
val forceNativeLibPathFirst = config.getString("debug.forceNativeLibPathFirst")
|
||||||
val logOpenGLErrors = config.getBoolean("debug.logOpenGLErrors")
|
val logOpenGLErrors = config.getBoolean("debug.logOpenGLErrors")
|
||||||
val logHexFontErrors = config.getBoolean("debug.logHexFontErrors")
|
val logHexFontErrors = config.getBoolean("debug.logHexFontErrors")
|
||||||
val alwaysTryNative = config.getBoolean("debug.alwaysTryNative")
|
val alwaysTryNative = config.getBoolean("debug.alwaysTryNative")
|
||||||
|
@ -4,8 +4,8 @@ import java.io.File
|
|||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.nio.channels.Channels
|
import java.nio.channels.Channels
|
||||||
|
import java.nio.file.Paths
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
import com.google.common.base.Strings
|
import com.google.common.base.Strings
|
||||||
import com.google.common.io.PatternFilenameFilter
|
import com.google.common.io.PatternFilenameFilter
|
||||||
import li.cil.oc.OpenComputers
|
import li.cil.oc.OpenComputers
|
||||||
@ -130,15 +130,15 @@ abstract class LuaStateFactory {
|
|||||||
private var currentLib = ""
|
private var currentLib = ""
|
||||||
|
|
||||||
private val libraryName = {
|
private val libraryName = {
|
||||||
if (!Strings.isNullOrEmpty(Settings.get.forceNativeLib)) Settings.get.forceNativeLib
|
|
||||||
|
|
||||||
else {
|
|
||||||
val libExtension = {
|
val libExtension = {
|
||||||
if (SystemUtils.IS_OS_MAC) ".dylib"
|
if (SystemUtils.IS_OS_MAC) ".dylib"
|
||||||
else if (SystemUtils.IS_OS_WINDOWS) ".dll"
|
else if (SystemUtils.IS_OS_WINDOWS) ".dll"
|
||||||
else ".so"
|
else ".so"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val platformName = {
|
||||||
|
if (!Strings.isNullOrEmpty(Settings.get.forceNativeLibPlatform)) Settings.get.forceNativeLibPlatform
|
||||||
|
else {
|
||||||
val systemName = {
|
val systemName = {
|
||||||
if (SystemUtils.IS_OS_FREE_BSD) "freebsd"
|
if (SystemUtils.IS_OS_FREE_BSD) "freebsd"
|
||||||
else if (SystemUtils.IS_OS_NET_BSD) "netbsd"
|
else if (SystemUtils.IS_OS_NET_BSD) "netbsd"
|
||||||
@ -158,10 +158,13 @@ abstract class LuaStateFactory {
|
|||||||
else "unknown"
|
else "unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
"libjnlua" + version + "-" + systemName + "-" + archName + libExtension
|
systemName + "-" + archName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"libjnlua" + version + "-" + platformName + libExtension
|
||||||
|
}
|
||||||
|
|
||||||
protected def create(maxMemory: Option[Int] = None): jnlua.LuaState
|
protected def create(maxMemory: Option[Int] = None): jnlua.LuaState
|
||||||
|
|
||||||
protected def openLibs(state: jnlua.LuaState): Unit
|
protected def openLibs(state: jnlua.LuaState): Unit
|
||||||
@ -170,13 +173,12 @@ abstract class LuaStateFactory {
|
|||||||
|
|
||||||
def isAvailable = haveNativeLibrary
|
def isAvailable = haveNativeLibrary
|
||||||
|
|
||||||
val is64Bit = Architecture.IS_OS_X64
|
|
||||||
|
|
||||||
// Since we use native libraries we have to do some work. This includes
|
// Since we use native libraries we have to do some work. This includes
|
||||||
// figuring out what we're running on, so that we can load the proper shared
|
// figuring out what we're running on, so that we can load the proper shared
|
||||||
// libraries compiled for that system. It also means we have to unpack the
|
// libraries compiled for that system. It also means we have to unpack the
|
||||||
// shared libraries somewhere so that we can load them, because we cannot
|
// shared libraries somewhere so that we can load them, because we cannot
|
||||||
// load them directly from a JAR.
|
// load them directly from a JAR. Lastly, we need to handle library overrides in
|
||||||
|
// case the user wants to use custom libraries, or are not on a supported platform.
|
||||||
def init() {
|
def init() {
|
||||||
if (libraryName == null) {
|
if (libraryName == null) {
|
||||||
return
|
return
|
||||||
@ -194,9 +196,22 @@ abstract class LuaStateFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var tmpLibFile: File = null
|
||||||
|
if (!Strings.isNullOrEmpty(Settings.get.forceNativeLibPathFirst)) {
|
||||||
|
val libraryTest = new File(Settings.get.forceNativeLibPathFirst, libraryName);
|
||||||
|
if (libraryTest.canRead) {
|
||||||
|
tmpLibFile = libraryTest
|
||||||
|
currentLib = libraryTest.getAbsolutePath
|
||||||
|
OpenComputers.log.info(s"Found forced-path filesystem library $currentLib.")
|
||||||
|
}
|
||||||
|
else
|
||||||
|
OpenComputers.log.warn(s"forceNativeLibPathFirst is set, but $currentLib was not found there. Falling back to checking the built-in libraries.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentLib.isEmpty) {
|
||||||
val libraryUrl = classOf[Machine].getResource(s"/assets/${Settings.resourceDomain}/lib/$libraryName")
|
val libraryUrl = classOf[Machine].getResource(s"/assets/${Settings.resourceDomain}/lib/$libraryName")
|
||||||
if (libraryUrl == null) {
|
if (libraryUrl == null) {
|
||||||
OpenComputers.log.warn(s"Native library with name '$version/$libraryName' not found.")
|
OpenComputers.log.warn(s"Native library with name '$libraryName' not found.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,7 +223,7 @@ abstract class LuaStateFactory {
|
|||||||
else path + "/"
|
else path + "/"
|
||||||
}
|
}
|
||||||
else "./"
|
else "./"
|
||||||
val tmpLibFile = new File(tmpBasePath + tmpLibName)
|
tmpLibFile = new File(tmpBasePath + tmpLibName)
|
||||||
|
|
||||||
// Clean up old library files when not in tmp dir.
|
// Clean up old library files when not in tmp dir.
|
||||||
if (!Settings.get.nativeInTmpDir) {
|
if (!Settings.get.nativeInTmpDir) {
|
||||||
@ -296,6 +311,8 @@ abstract class LuaStateFactory {
|
|||||||
}
|
}
|
||||||
// Try to load the lib.
|
// Try to load the lib.
|
||||||
currentLib = tmpLibFile.getAbsolutePath
|
currentLib = tmpLibFile.getAbsolutePath
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LuaStateFactory.synchronized {
|
LuaStateFactory.synchronized {
|
||||||
System.load(currentLib)
|
System.load(currentLib)
|
||||||
|
@ -42,7 +42,7 @@ abstract class NativeLuaArchitecture(val machine: api.machine.Machine) extends A
|
|||||||
|
|
||||||
private[machine] var kernelMemory = 0
|
private[machine] var kernelMemory = 0
|
||||||
|
|
||||||
private[machine] val ramScale = if (factory.is64Bit) Settings.get.ramScaleFor64Bit else 1.0
|
private[machine] var ramScale: Double = 1.0
|
||||||
|
|
||||||
private val persistence = new PersistenceAPI(this)
|
private val persistence = new PersistenceAPI(this)
|
||||||
|
|
||||||
@ -150,16 +150,16 @@ abstract class NativeLuaArchitecture(val machine: api.machine.Machine) extends A
|
|||||||
override def isInitialized = kernelMemory > 0
|
override def isInitialized = kernelMemory > 0
|
||||||
|
|
||||||
override def recomputeMemory(components: java.lang.Iterable[ItemStack]) = {
|
override def recomputeMemory(components: java.lang.Iterable[ItemStack]) = {
|
||||||
val memory = math.ceil(memoryInBytes(components) * ramScale).toInt
|
val memoryBytes = memoryInBytes(components)
|
||||||
Option(lua) match {
|
Option(lua) match {
|
||||||
case Some(l) if Settings.get.limitMemory =>
|
case Some(l) if Settings.get.limitMemory =>
|
||||||
l.setTotalMemory(Int.MaxValue)
|
l.setTotalMemory(Int.MaxValue)
|
||||||
if (kernelMemory > 0) {
|
if (kernelMemory > 0) {
|
||||||
l.setTotalMemory(kernelMemory + memory)
|
l.setTotalMemory(kernelMemory + math.ceil(memoryBytes * ramScale).toInt)
|
||||||
}
|
}
|
||||||
case _ =>
|
case _ =>
|
||||||
}
|
}
|
||||||
memory > 0
|
memoryBytes > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
private def memoryInBytes(components: java.lang.Iterable[ItemStack]) = components.foldLeft(0.0)((acc, stack) => acc + (Option(api.Driver.driverFor(stack)) match {
|
private def memoryInBytes(components: java.lang.Iterable[ItemStack]) = components.foldLeft(0.0)((acc, stack) => acc + (Option(api.Driver.driverFor(stack)) match {
|
||||||
@ -314,6 +314,7 @@ abstract class NativeLuaArchitecture(val machine: api.machine.Machine) extends A
|
|||||||
return false
|
return false
|
||||||
case Some(value) => lua = value
|
case Some(value) => lua = value
|
||||||
}
|
}
|
||||||
|
ramScale = if (lua.getPointerWidth >= 8) Settings.get.ramScaleFor64Bit else 1.0
|
||||||
|
|
||||||
apis.foreach(_.initialize())
|
apis.foreach(_.initialize())
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user