diff --git a/engine/src/desktop-fx/com/jme3/post/filters/BloomFilter.java b/engine/src/desktop-fx/com/jme3/post/filters/BloomFilter.java index aeccd77ac..17986f285 100644 --- a/engine/src/desktop-fx/com/jme3/post/filters/BloomFilter.java +++ b/engine/src/desktop-fx/com/jme3/post/filters/BloomFilter.java @@ -111,8 +111,8 @@ public class BloomFilter extends Filter { @Override protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) { - screenWidth = (int) (w / downSamplingFactor); - screenHeight = (int) (h / downSamplingFactor); + screenWidth = (int) Math.max(1, (w / downSamplingFactor)); + screenHeight = (int) Math.max(1, (h / downSamplingFactor)); // System.out.println(screenWidth + " " + screenHeight); if (glowMode != GlowMode.Scene) { preGlowPass = new Pass(); diff --git a/engine/src/desktop/com/jme3/system/JmeSystem.java b/engine/src/desktop/com/jme3/system/JmeSystem.java index e6a997dfc..fd33a9f26 100644 --- a/engine/src/desktop/com/jme3/system/JmeSystem.java +++ b/engine/src/desktop/com/jme3/system/JmeSystem.java @@ -37,6 +37,7 @@ import com.jme3.asset.AssetManager; import com.jme3.asset.AssetNotFoundException; import com.jme3.asset.DesktopAssetManager; import com.jme3.audio.AudioRenderer; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URL; @@ -47,10 +48,37 @@ import java.util.logging.Logger; import javax.swing.SwingUtilities; public class JmeSystem { - + private static final Logger logger = Logger.getLogger(JmeSystem.class.getName()); private static boolean initialized = false; private static boolean lowPermissions = false; + private static File storageFolder = null; + + public static synchronized File getStorageFolder(){ + if (lowPermissions){ + throw new UnsupportedOperationException("File system access restricted"); + } + if (storageFolder == null){ + // Initialize storage folder + storageFolder = new File(System.getProperty("user.home"), ".jme3"); + if (!storageFolder.exists()){ + storageFolder.mkdir(); + } + } + return storageFolder; + } + + public static String getFullName() { + return JmeVersion.FULL_NAME; + } + + public static InputStream getResourceAsStream(String name) { + return JmeSystem.class.getResourceAsStream(name); + } + + public static URL getResource(String name) { + return JmeSystem.class.getResource(name); + } public static boolean trackDirectMemory() { return false; @@ -77,7 +105,6 @@ public class JmeSystem { throw new IllegalStateException("Cannot run from EDT"); } - final AppSettings settings = new AppSettings(false); settings.copyFrom(sourceSettings); String iconPath = sourceSettings.getSettingsDialogImage(); @@ -317,7 +344,6 @@ public class JmeSystem { } logger.log(Level.INFO, "Running on {0}", getFullName()); - if (!lowPermissions) { try { Natives.extractNativeLibs(getPlatform(), settings); @@ -326,16 +352,4 @@ public class JmeSystem { } } } - - public static String getFullName() { - return "jMonkeyEngine 3.0.0 Beta"; - } - - public static InputStream getResourceAsStream(String name) { - return JmeSystem.class.getResourceAsStream(name); - } - - public static URL getResource(String name) { - return JmeSystem.class.getResource(name); - } } diff --git a/engine/src/desktop/com/jme3/system/Natives.java b/engine/src/desktop/com/jme3/system/Natives.java index 857975001..e189a9244 100644 --- a/engine/src/desktop/com/jme3/system/Natives.java +++ b/engine/src/desktop/com/jme3/system/Natives.java @@ -51,12 +51,52 @@ public class Natives { private static final Logger logger = Logger.getLogger(Natives.class.getName()); private static final byte[] buf = new byte[1024]; - private static File workingDir = new File("").getAbsoluteFile(); + private static File extractionDirOverride = null; + private static File extractionDir = null; public static void setExtractionDir(String name) { - workingDir = new File(name).getAbsoluteFile(); + extractionDirOverride = new File(name).getAbsoluteFile(); + } + + public static File getExtractionDir(){ + if (extractionDirOverride != null){ + return extractionDirOverride; + } + if (extractionDir == null){ + extractionDir = new File(JmeSystem.getStorageFolder(), + "natives_" + Integer.toHexString(computeNativesHash()) ); + if (!extractionDir.exists()){ + extractionDir.mkdir(); + } + } + return extractionDir; } + private static int computeNativesHash(){ + try { + String classpath = System.getProperty("java.class.path"); + URL url = Natives.class.getResource(""); + if (url != null) { + StringBuilder sb = new StringBuilder(url.toString()); + if (sb.indexOf("jar:") == 0) { + sb.delete(0, 4); + sb.delete(sb.indexOf("!"), sb.length()); + sb.delete(sb.lastIndexOf("/") + 1, sb.length()); + } + try { + url = new URL(sb.toString()); + } catch (MalformedURLException ex) { + throw new UnsupportedOperationException(ex); + } + } + URLConnection conn = url.openConnection(); + int hash = classpath.hashCode() ^ (int)conn.getLastModified(); + return hash; + } catch (IOException ex) { + throw new UnsupportedOperationException(ex); + } + } + protected static void extractNativeLib(String sysName, String name) throws IOException { extractNativeLib(sysName, name, false, true); } @@ -81,7 +121,7 @@ public class Natives { URLConnection conn = url.openConnection(); InputStream in = conn.getInputStream(); - File targetFile = new File(workingDir, fullname); + File targetFile = new File(getExtractionDir(), fullname); try { if (targetFile.exists()){ @@ -123,24 +163,6 @@ public class Natives { logger.log(Level.FINE, "Copied {0} to {1}", new Object[]{fullname, targetFile}); } - private static String getExtractionDir() { - URL temp = Natives.class.getResource(""); - if (temp != null) { - StringBuilder sb = new StringBuilder(temp.toString()); - if (sb.indexOf("jar:") == 0) { - sb.delete(0, 4); - sb.delete(sb.indexOf("!"), sb.length()); - sb.delete(sb.lastIndexOf("/") + 1, sb.length()); - } - try { - return new URL(sb.toString()).toString(); - } catch (MalformedURLException ex) { - return null; - } - } - return null; - } - protected static boolean isUsingNativeBullet(){ try { Class clazz = Class.forName("com.jme3.bullet.util.NativeMeshUtil"); @@ -171,14 +193,11 @@ public class Natives { needJInput = settings.useJoysticks(); if (needLWJGL) { - logger.log(Level.INFO, "Extraction Directory #1: {0}", getExtractionDir()); - logger.log(Level.INFO, "Extraction Directory #2: {0}", workingDir.toString()); - logger.log(Level.INFO, "Extraction Directory #3: {0}", System.getProperty("user.dir")); + logger.log(Level.INFO, "Extraction Directory: {0}", getExtractionDir().toString()); + // LWJGL supports this feature where // it can load libraries from this path. - // This is a fallback method in case the OS doesn't load - // native libraries from the working directory (e.g Linux). - System.setProperty("org.lwjgl.librarypath", workingDir.toString()); + System.setProperty("org.lwjgl.librarypath", getExtractionDir().toString()); } switch (platform) {