- load library in Natives.java on demand

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7417 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
nor..67 14 years ago
parent e04b1b464a
commit ea6e817f7f
  1. 2
      engine/src/bullet/com/jme3/bullet/PhysicsSpace.java
  2. 38
      engine/src/desktop/com/jme3/system/Natives.java

@ -142,7 +142,6 @@ public class PhysicsSpace {
this.worldMax.set(worldMax); this.worldMax.set(worldMax);
this.broadphaseType = broadphaseType; this.broadphaseType = broadphaseType;
create(); create();
System.loadLibrary("bulletjme");
initNativePhysics(); initNativePhysics();
} }
@ -151,7 +150,6 @@ public class PhysicsSpace {
*/ */
public void create() { public void create() {
//TODO: boroadphase! //TODO: boroadphase!
System.loadLibrary("bulletjme");
initNativePhysics(); initNativePhysics();
physicsSpaceId = createPhysicsSpace(worldMin.x, worldMin.y, worldMin.z, worldMax.x, worldMax.y, worldMax.z, 3, false); physicsSpaceId = createPhysicsSpace(worldMin.x, worldMin.y, worldMin.z, worldMax.x, worldMax.y, worldMax.z, 3, false);
pQueueTL.set(pQueue); pQueueTL.set(pQueue);

@ -58,15 +58,20 @@ public class Natives {
} }
protected static void extractNativeLib(String sysName, String name) throws IOException { protected static void extractNativeLib(String sysName, String name) throws IOException {
extractNativeLib(sysName, name, false);
}
protected static void extractNativeLib(String sysName, String name, boolean load) throws IOException {
String fullname = System.mapLibraryName(name); String fullname = System.mapLibraryName(name);
String path = "native/" + sysName + "/" + fullname; String path = "native/" + sysName + "/" + fullname;
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(path); InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
//InputStream in = Natives.class.getResourceAsStream(); //InputStream in = Natives.class.getResourceAsStream();
if (in == null) { if (in == null) {
if(name!="bulletjme") if (name != "bulletjme") {
logger.log(Level.WARNING, "Cannot locate native library: {0}/{1}", logger.log(Level.WARNING, "Cannot locate native library: {0}/{1}",
new String[]{sysName, fullname}); new String[]{sysName, fullname});
}
return; return;
} }
File targetFile = new File(workingDir, fullname); File targetFile = new File(workingDir, fullname);
@ -80,12 +85,17 @@ public class Natives {
out.close(); out.close();
} catch (FileNotFoundException ex) { } catch (FileNotFoundException ex) {
if (ex.getMessage().contains("used by another process")) { if (ex.getMessage().contains("used by another process")) {
if (load) {
System.load(targetFile.getAbsolutePath());
}
return; return;
} }
throw ex; throw ex;
} }
if (load) {
System.load(targetFile.getAbsolutePath());
}
logger.log(Level.FINE, "Copied {0} to {1}", new Object[]{fullname, targetFile}); logger.log(Level.FINE, "Copied {0} to {1}", new Object[]{fullname, targetFile});
} }
@ -150,8 +160,8 @@ public class Natives {
extractNativeLib("windows", "jinput-dx8_64"); extractNativeLib("windows", "jinput-dx8_64");
extractNativeLib("windows", "jinput-raw_64"); extractNativeLib("windows", "jinput-raw_64");
} }
if(needNativeBullet){ if (needNativeBullet) {
extractNativeLib("windows", "bulletjme"); extractNativeLib("windows", "bulletjme", true);
} }
break; break;
case Windows32: case Windows32:
@ -165,8 +175,8 @@ public class Natives {
extractNativeLib("windows", "jinput-dx8"); extractNativeLib("windows", "jinput-dx8");
extractNativeLib("windows", "jinput-raw"); extractNativeLib("windows", "jinput-raw");
} }
if(needNativeBullet){ if (needNativeBullet) {
extractNativeLib("windows", "bulletjme"); extractNativeLib("windows", "bulletjme", true);
} }
break; break;
case Linux64: case Linux64:
@ -179,8 +189,8 @@ public class Natives {
if (needOAL) { if (needOAL) {
extractNativeLib("linux", "openal64"); extractNativeLib("linux", "openal64");
} }
if(needNativeBullet){ if (needNativeBullet) {
extractNativeLib("linux", "bulletjme"); extractNativeLib("linux", "bulletjme", true);
} }
break; break;
case Linux32: case Linux32:
@ -193,8 +203,8 @@ public class Natives {
if (needOAL) { if (needOAL) {
extractNativeLib("linux", "openal"); extractNativeLib("linux", "openal");
} }
if(needNativeBullet){ if (needNativeBullet) {
extractNativeLib("linux", "bulletjme32"); extractNativeLib("linux", "bulletjme", true);
} }
break; break;
case MacOSX_PPC32: case MacOSX_PPC32:
@ -209,8 +219,8 @@ public class Natives {
if (needJInput) { if (needJInput) {
extractNativeLib("macosx", "jinput-osx"); extractNativeLib("macosx", "jinput-osx");
} }
if(needNativeBullet){ if (needNativeBullet) {
extractNativeLib("macosx", "bulletjme"); extractNativeLib("macosx", "bulletjme", true);
} }
break; break;
} }

Loading…
Cancel
Save