From a5be89598fa778eeeeb87e0b2f6c526d392c58fb Mon Sep 17 00:00:00 2001 From: "sha..rd" Date: Sat, 24 Sep 2011 00:50:13 +0000 Subject: [PATCH] * Always close InputStream in WAVLoader * Fix use of deprecated classes/methods in android tests * Fix bugs with joysticks often generating events for both the negative and positive side of axis * Camera.clone() properly clones the gui bounding * Camera.setParallelProjection() updates the camera's projection matrix instead of keeping old values * LwjglOffscreenBuffer obeys by framerate setting and sets renderable property as needed git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8283 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../android/jme3test/android/TestAmbient.java | 4 +-- .../android/TestSkyLoadingLagoon.java | 3 +- .../android/TestSkyLoadingPrimitives.java | 3 +- engine/src/core/com/jme3/animation/Bone.java | 3 ++ .../src/core/com/jme3/animation/Skeleton.java | 1 - .../com/jme3/audio/plugins/WAVLoader.java | 31 ++++++++++++++----- .../src/core/com/jme3/input/InputManager.java | 4 +++ engine/src/core/com/jme3/renderer/Camera.java | 2 ++ .../jme3/renderer/lwjgl/LwjglRenderer.java | 4 ++- .../system/lwjgl/LwjglOffscreenBuffer.java | 31 ++++++++----------- .../test/jme3test/niftygui/TestNiftyGui.java | 6 ++-- 11 files changed, 54 insertions(+), 38 deletions(-) diff --git a/engine/src/android/jme3test/android/TestAmbient.java b/engine/src/android/jme3test/android/TestAmbient.java index 0b8f0ea98..d062efec1 100644 --- a/engine/src/android/jme3test/android/TestAmbient.java +++ b/engine/src/android/jme3test/android/TestAmbient.java @@ -83,10 +83,10 @@ public class TestAmbient extends SimpleApplication { audioRenderer.playSource(beep); */ - waves = new AudioNode(audioRenderer, assetManager, "Sound/Environment/Ocean Waves.ogg", true); + waves = new AudioNode(assetManager, "Sound/Environment/Ocean Waves.ogg", true); waves.setPositional(true); - nature = new AudioNode(audioRenderer, assetManager, "Sound/Environment/Nature.ogg", true); + nature = new AudioNode(assetManager, "Sound/Environment/Nature.ogg", true); waves.setLocalTranslation(new Vector3f(4, -1, 30)); waves.setMaxDistance(5); diff --git a/engine/src/android/jme3test/android/TestSkyLoadingLagoon.java b/engine/src/android/jme3test/android/TestSkyLoadingLagoon.java index 506d0fa02..507c6614d 100644 --- a/engine/src/android/jme3test/android/TestSkyLoadingLagoon.java +++ b/engine/src/android/jme3test/android/TestSkyLoadingLagoon.java @@ -36,7 +36,6 @@ import com.jme3.app.SimpleApplication; import com.jme3.scene.Spatial; import com.jme3.texture.Texture; import com.jme3.util.SkyFactory; -import com.jme3.util.android.AndroidSkyFactory; public class TestSkyLoadingLagoon extends SimpleApplication { @@ -64,7 +63,7 @@ public class TestSkyLoadingLagoon extends SimpleApplication { Texture down = assetManager.loadTexture("Textures/Sky/Primitives/primitives_negative_y.png"); */ - Spatial sky = AndroidSkyFactory.createSky(assetManager, west, east, north, south, up, down); + Spatial sky = SkyFactory.createSky(assetManager, west, east, north, south, up, down); rootNode.attachChild(sky); } diff --git a/engine/src/android/jme3test/android/TestSkyLoadingPrimitives.java b/engine/src/android/jme3test/android/TestSkyLoadingPrimitives.java index 78add3c1d..282e237bf 100644 --- a/engine/src/android/jme3test/android/TestSkyLoadingPrimitives.java +++ b/engine/src/android/jme3test/android/TestSkyLoadingPrimitives.java @@ -36,7 +36,6 @@ import com.jme3.app.SimpleApplication; import com.jme3.scene.Spatial; import com.jme3.texture.Texture; import com.jme3.util.SkyFactory; -import com.jme3.util.android.AndroidSkyFactory; public class TestSkyLoadingPrimitives extends SimpleApplication { @@ -62,7 +61,7 @@ public class TestSkyLoadingPrimitives extends SimpleApplication { Texture up = assetManager.loadTexture("Textures/Sky/Primitives/primitives_positive_y.png"); Texture down = assetManager.loadTexture("Textures/Sky/Primitives/primitives_negative_y.png"); - Spatial sky = AndroidSkyFactory.createSky(assetManager, west, east, north, south, up, down); + Spatial sky = SkyFactory.createSky(assetManager, west, east, north, south, up, down); rootNode.attachChild(sky); } diff --git a/engine/src/core/com/jme3/animation/Bone.java b/engine/src/core/com/jme3/animation/Bone.java index 889cde433..c1b2a0c5c 100644 --- a/engine/src/core/com/jme3/animation/Bone.java +++ b/engine/src/core/com/jme3/animation/Bone.java @@ -102,6 +102,9 @@ public final class Bone implements Savable { * @param name Name to give to this bone */ public Bone(String name) { + if (name == null) + throw new IllegalArgumentException("Name cannot be null"); + this.name = name; initialPos = new Vector3f(); diff --git a/engine/src/core/com/jme3/animation/Skeleton.java b/engine/src/core/com/jme3/animation/Skeleton.java index e29ee90d6..672359117 100644 --- a/engine/src/core/com/jme3/animation/Skeleton.java +++ b/engine/src/core/com/jme3/animation/Skeleton.java @@ -210,7 +210,6 @@ public final class Skeleton implements Savable { return boneList[i]; } } - return null; } diff --git a/engine/src/core/com/jme3/audio/plugins/WAVLoader.java b/engine/src/core/com/jme3/audio/plugins/WAVLoader.java index ca237863d..5b7d76dc8 100644 --- a/engine/src/core/com/jme3/audio/plugins/WAVLoader.java +++ b/engine/src/core/com/jme3/audio/plugins/WAVLoader.java @@ -41,6 +41,7 @@ import com.jme3.audio.AudioKey; import com.jme3.util.BufferUtils; import com.jme3.util.LittleEndien; import java.io.IOException; +import java.io.InputStream; import java.nio.ByteBuffer; import java.util.logging.Level; import java.util.logging.Logger; @@ -52,7 +53,7 @@ public class WAVLoader implements AssetLoader { // all these are in big endian private static final int i_RIFF = 0x46464952; private static final int i_WAVE = 0x45564157; - private static final int i_fmt = 0x20746D66 ; + private static final int i_fmt = 0x20746D66; private static final int i_data = 0x61746164; private boolean readStream = false; @@ -104,7 +105,6 @@ public class WAVLoader implements AssetLoader { if (remaining > 0){ in.skipBytes(remaining); } - } private void readDataChunkForBuffer(int len) throws IOException { @@ -123,9 +123,9 @@ public class WAVLoader implements AssetLoader { audioStream.updateData(in, duration); } - public Object load(AssetInfo info) throws IOException { - this.in = new LittleEndien(info.openStream()); - + private AudioData load(InputStream inputStream, boolean stream) throws IOException{ + this.in = new LittleEndien(inputStream); + int sig = in.readInt(); if (sig != i_RIFF) throw new IOException("File is not a WAVE file"); @@ -135,8 +135,7 @@ public class WAVLoader implements AssetLoader { if (in.readInt() != i_WAVE) throw new IOException("WAVE File does not contain audio"); - readStream = ((AudioKey)info.getKey()).isStream(); - + readStream = stream; if (readStream){ audioStream = new AudioStream(); audioData = audioStream; @@ -168,9 +167,25 @@ public class WAVLoader implements AssetLoader { if (skipped <= 0) { return null; } - break; } } } + + public Object load(AssetInfo info) throws IOException { + AudioData data; + InputStream inputStream = null; + try { + inputStream = info.openStream(); + data = load(inputStream, ((AudioKey)info.getKey()).isStream()); + if (data instanceof AudioStream){ + inputStream = null; + } + return data; + } finally { + if (inputStream != null){ + inputStream.close(); + } + } + } } diff --git a/engine/src/core/com/jme3/input/InputManager.java b/engine/src/core/com/jme3/input/InputManager.java index 4f3fea86d..46be9f9f4 100644 --- a/engine/src/core/com/jme3/input/InputManager.java +++ b/engine/src/core/com/jme3/input/InputManager.java @@ -337,12 +337,16 @@ public class InputManager implements RawInputListener { } else if (value < 0) { int hash = JoyAxisTrigger.joyAxisHash(joyId, axis, true); + int otherHash = JoyAxisTrigger.joyAxisHash(joyId, axis, false); invokeAnalogsAndActions(hash, -value, true); axisValues.put(hash, -value); + axisValues.remove(otherHash); } else { int hash = JoyAxisTrigger.joyAxisHash(joyId, axis, false); + int otherHash = JoyAxisTrigger.joyAxisHash(joyId, axis, true); invokeAnalogsAndActions(hash, value, true); axisValues.put(hash, value); + axisValues.remove(otherHash); } } diff --git a/engine/src/core/com/jme3/renderer/Camera.java b/engine/src/core/com/jme3/renderer/Camera.java index 5c787c7c6..5a4c56cfc 100644 --- a/engine/src/core/com/jme3/renderer/Camera.java +++ b/engine/src/core/com/jme3/renderer/Camera.java @@ -286,6 +286,7 @@ public class Camera implements Savable, Cloneable { cam.viewMatrix = viewMatrix.clone(); cam.projectionMatrix = projectionMatrix.clone(); cam.viewProjectionMatrix = viewProjectionMatrix.clone(); + cam.guiBounding = (BoundingBox) guiBounding.clone(); cam.update(); @@ -1227,6 +1228,7 @@ public class Camera implements Savable, Cloneable { */ public void setParallelProjection(final boolean value) { this.parallelProjection = value; + onFrustumChange(); } /** diff --git a/engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglRenderer.java b/engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglRenderer.java index 6e1d65125..ef2acbfd6 100644 --- a/engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglRenderer.java +++ b/engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglRenderer.java @@ -1530,7 +1530,9 @@ public class LwjglRenderer implements Renderer { public void setFrameBuffer(FrameBuffer fb) { if (lastFb == fb) { - return; + if (fb == null || !fb.isUpdateNeeded()){ + return; + } } // generate mipmaps for last FB if needed diff --git a/engine/src/lwjgl-ogl/com/jme3/system/lwjgl/LwjglOffscreenBuffer.java b/engine/src/lwjgl-ogl/com/jme3/system/lwjgl/LwjglOffscreenBuffer.java index 14228ce69..4bec7992b 100644 --- a/engine/src/lwjgl-ogl/com/jme3/system/lwjgl/LwjglOffscreenBuffer.java +++ b/engine/src/lwjgl-ogl/com/jme3/system/lwjgl/LwjglOffscreenBuffer.java @@ -43,6 +43,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.lwjgl.LWJGLException; import org.lwjgl.Sys; +import org.lwjgl.opengl.Display; import org.lwjgl.opengl.OpenGLException; import org.lwjgl.opengl.Pbuffer; import org.lwjgl.opengl.PixelFormat; @@ -64,10 +65,11 @@ public class LwjglOffscreenBuffer extends LwjglContext implements Runnable { } pixelFormat = new PixelFormat(settings.getBitsPerPixel(), - 0, - settings.getDepthBits(), - settings.getStencilBits(), - settings.getSamples()); + 0, + settings.getDepthBits(), + settings.getStencilBits(), + settings.getSamples()); + width = settings.getWidth(); height = settings.getHeight(); try{ @@ -77,21 +79,7 @@ public class LwjglOffscreenBuffer extends LwjglContext implements Runnable { } }); - //String rendererStr = settings.getString("Renderer"); -// if (rendererStr.startsWith("LWJGL-OpenGL3")){ -// ContextAttribs attribs; -// if (rendererStr.equals("LWJGL-OpenGL3.1")){ -// attribs = new ContextAttribs(3, 1); -// }else{ -// attribs = new ContextAttribs(3, 0); -// } -// attribs.withForwardCompatible(true); -// attribs.withDebug(false); -// Display.create(pf, attribs); -// }else{ pbuffer = new Pbuffer(width, height, pixelFormat, null, null, createContextAttribs()); -// } - pbuffer.makeCurrent(); renderable.set(true); @@ -141,9 +129,16 @@ public class LwjglOffscreenBuffer extends LwjglContext implements Runnable { assert checkGLError(); renderer.onFrame(); + + int frameRate = settings.getFrameRate(); + if (frameRate >= 1){ + Display.sync(frameRate); + } } protected void deinitInThread(){ + renderable.set(false); + listener.destroy(); renderer.cleanup(); pbuffer.destroy(); diff --git a/engine/src/test/jme3test/niftygui/TestNiftyGui.java b/engine/src/test/jme3test/niftygui/TestNiftyGui.java index f024a8cae..fe7db742f 100644 --- a/engine/src/test/jme3test/niftygui/TestNiftyGui.java +++ b/engine/src/test/jme3test/niftygui/TestNiftyGui.java @@ -66,9 +66,6 @@ public class TestNiftyGui extends SimpleApplication implements ScreenController audioRenderer, guiViewPort); nifty = niftyDisplay.getNifty(); - - URL url = Thread.currentThread().getContextClassLoader().getResource("jme3test/niftygui/hellojme.xml"); - nifty.fromXml("Interface/Nifty/HelloJme.xml", "start", this); // attach the nifty display to the gui view port as a processor @@ -76,7 +73,8 @@ public class TestNiftyGui extends SimpleApplication implements ScreenController // disable the fly cam // flyCam.setEnabled(false); - flyCam.setDragToRotate(true); +// flyCam.setDragToRotate(true); + inputManager.setCursorVisible(true); } public void bind(Nifty nifty, Screen screen) {