From 3a938b7dc9e29ed8ecfedb2cb6d28c211051087d Mon Sep 17 00:00:00 2001 From: "Sha..rd" Date: Sun, 22 May 2011 01:19:40 +0000 Subject: [PATCH] * Mesh.getTriangle() now supports 32bit index buffers and no index buffers * Fix small logging issue in InputManager * Added stream-cache feature to streaming audio * Additional javadoc git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7515 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- engine/src/core/com/jme3/audio/ALObject.java | 5 +++ .../src/core/com/jme3/audio/AudioBuffer.java | 4 +- engine/src/core/com/jme3/audio/AudioData.java | 2 +- engine/src/core/com/jme3/audio/AudioKey.java | 45 +++++++++++++++++-- engine/src/core/com/jme3/audio/AudioNode.java | 4 -- .../src/core/com/jme3/audio/AudioStream.java | 7 +-- .../src/core/com/jme3/input/InputManager.java | 2 +- engine/src/core/com/jme3/scene/Mesh.java | 32 +++++++------ .../jme3/scene/mesh/WrappedIndexBuffer.java | 7 +++ 9 files changed, 80 insertions(+), 28 deletions(-) diff --git a/engine/src/core/com/jme3/audio/ALObject.java b/engine/src/core/com/jme3/audio/ALObject.java index 1076d234e..a801fd6d9 100644 --- a/engine/src/core/com/jme3/audio/ALObject.java +++ b/engine/src/core/com/jme3/audio/ALObject.java @@ -32,6 +32,11 @@ package com.jme3.audio; +/** + * Used for managing AL (Audio Library) objects. + * + * @author Kirill Vainer + */ public abstract class ALObject { protected int id = -1; diff --git a/engine/src/core/com/jme3/audio/AudioBuffer.java b/engine/src/core/com/jme3/audio/AudioBuffer.java index 697108583..1b4d4abd9 100644 --- a/engine/src/core/com/jme3/audio/AudioBuffer.java +++ b/engine/src/core/com/jme3/audio/AudioBuffer.java @@ -38,10 +38,10 @@ import java.nio.ByteBuffer; /** * An AudioBuffer is an implementation of AudioData * where the audio is buffered (stored in memory). All parts of it - * are accessable at any time.
+ * are accessible at any time.
* AudioBuffers are useful for short sounds, like effects, etc. * - * @author Kirill + * @author Kirill Vainer */ public class AudioBuffer extends AudioData { diff --git a/engine/src/core/com/jme3/audio/AudioData.java b/engine/src/core/com/jme3/audio/AudioData.java index 33492305a..ab9675c5d 100644 --- a/engine/src/core/com/jme3/audio/AudioData.java +++ b/engine/src/core/com/jme3/audio/AudioData.java @@ -38,7 +38,7 @@ package com.jme3.audio; * are to be stored entirely in memory, while long audio files (music) is * streamed from the hard drive as it is played. * - * @author Kirill + * @author Kirill Vainer */ public abstract class AudioData extends ALObject { diff --git a/engine/src/core/com/jme3/audio/AudioKey.java b/engine/src/core/com/jme3/audio/AudioKey.java index 616b5eb68..73a435b0f 100644 --- a/engine/src/core/com/jme3/audio/AudioKey.java +++ b/engine/src/core/com/jme3/audio/AudioKey.java @@ -42,12 +42,29 @@ import java.io.IOException; /** * AudioKey is extending AssetKey by holding stream flag. * - * @author Kirill + * @author Kirill Vainer */ public class AudioKey extends AssetKey { private boolean stream; + private boolean streamCache; + /** + * Create a new AudioKey. + * + * @param name Name of the asset + * @param stream If true, the audio will be streamed from harddrive, + * otherwise it will be buffered entirely and then played. + * @param streamCache If stream is true, then this specifies if + * the stream cache is used. When enabled, the audio stream will + * be read entirely but not decoded, allowing features such as + * seeking, determining duration and looping. + */ + public AudioKey(String name, boolean stream, boolean streamCache){ + this(name, stream); + this.streamCache = streamCache; + } + /** * Create a new AudioKey * @@ -70,15 +87,35 @@ public class AudioKey extends AssetKey { @Override public String toString(){ - return name + (stream ? "/S" : ""); + return name + (stream ? + (streamCache ? + " (Stream/Cache)" : + " (Stream)") : + " (Buffer)"); } + /** + * @return True if the loaded audio should be a {@link AudioStream} or + * false if it should be a {@link AudioBuffer}. + */ public boolean isStream() { return stream; } + + /** + * Specifies if the stream cache is used. + * + * When enabled, the audio stream will + * be read entirely but not decoded, allowing features such as + * seeking, looping and determining duration. + */ + public boolean useStreamCache(){ + return streamCache; + } + @Override public boolean shouldCache(){ - return !stream; + return !stream && !streamCache; } @Override @@ -86,6 +123,7 @@ public class AudioKey extends AssetKey { super.write(ex); OutputCapsule oc = ex.getCapsule(this); oc.write(stream, "do_stream", false); + oc.write(streamCache, "use_stream_cache", false); } @Override @@ -93,6 +131,7 @@ public class AudioKey extends AssetKey { super.read(im); InputCapsule ic = im.getCapsule(this); stream = ic.readBoolean("do_stream", false); + streamCache = ic.readBoolean("use_stream_cache", false); } } diff --git a/engine/src/core/com/jme3/audio/AudioNode.java b/engine/src/core/com/jme3/audio/AudioNode.java index 72a02079b..708e5c388 100644 --- a/engine/src/core/com/jme3/audio/AudioNode.java +++ b/engine/src/core/com/jme3/audio/AudioNode.java @@ -428,10 +428,6 @@ public class AudioNode extends Node { * @see AudioNode#setDryFilter(com.jme3.audio.Filter) */ public void setReverbFilter(Filter reverbFilter) { - if (this.reverbFilter != null) { - throw new IllegalStateException("Filter already set"); - } - this.reverbFilter = reverbFilter; if (channel >= 0) renderer.updateSourceParam(this, AudioParam.ReverbFilter); diff --git a/engine/src/core/com/jme3/audio/AudioStream.java b/engine/src/core/com/jme3/audio/AudioStream.java index 76fbd327c..4c58b8a60 100644 --- a/engine/src/core/com/jme3/audio/AudioStream.java +++ b/engine/src/core/com/jme3/audio/AudioStream.java @@ -47,9 +47,9 @@ import java.io.InputStream; public class AudioStream extends AudioData implements Closeable{ protected InputStream in; - private float duration = -1f; - private boolean open = false; - private int[] ids; + protected float duration = -1f; + protected boolean open = false; + protected int[] ids; public AudioStream(){ } @@ -104,6 +104,7 @@ public class AudioStream extends AudioData implements Closeable{ throw new RuntimeException("Don't use getId() on streams"); } + @Override public void setId(int id){ throw new RuntimeException("Don't use setId() on streams"); } diff --git a/engine/src/core/com/jme3/input/InputManager.java b/engine/src/core/com/jme3/input/InputManager.java index cf43b8830..850571a58 100644 --- a/engine/src/core/com/jme3/input/InputManager.java +++ b/engine/src/core/com/jme3/input/InputManager.java @@ -434,7 +434,7 @@ public class InputManager implements RawInputListener { names.add(mapping); mapping.triggers.add(hash); } else { - logger.log(Level.WARNING, "Attempted to add mapping '{0}' twice to trigger.", mappingName); + logger.log(Level.WARNING, "Attempted to add mapping \"{0}\" twice to trigger.", mappingName); } } } diff --git a/engine/src/core/com/jme3/scene/Mesh.java b/engine/src/core/com/jme3/scene/Mesh.java index c10d0be1a..4e3330cae 100644 --- a/engine/src/core/com/jme3/scene/Mesh.java +++ b/engine/src/core/com/jme3/scene/Mesh.java @@ -51,6 +51,8 @@ import com.jme3.math.Triangle; import com.jme3.math.Vector2f; import com.jme3.math.Vector3f; import com.jme3.scene.VertexBuffer.*; +import com.jme3.scene.mesh.VirtualIndexBuffer; +import com.jme3.scene.mesh.WrappedIndexBuffer; import com.jme3.util.BufferUtils; import com.jme3.util.IntMap; import com.jme3.util.IntMap.Entry; @@ -455,25 +457,27 @@ public class Mesh implements Savable, Cloneable { public void getTriangle(int index, Vector3f v1, Vector3f v2, Vector3f v3){ VertexBuffer pb = getBuffer(Type.Position); - VertexBuffer ib = getBuffer(Type.Index); + IndexBuffer ib = getIndexBuffer(); + if (ib == null){ + ib = new VirtualIndexBuffer(vertCount, mode); + }else if (mode != Mode.Triangles){ + ib = new WrappedIndexBuffer(this); + } + if (pb.getFormat() == Format.Float){ FloatBuffer fpb = (FloatBuffer) pb.getData(); - if (ib.getFormat() == Format.UnsignedShort){ - // accepted format for buffers - ShortBuffer sib = (ShortBuffer) ib.getData(); - - // aquire triangle's vertex indices - int vertIndex = index * 3; - int vert1 = sib.get(vertIndex); - int vert2 = sib.get(vertIndex+1); - int vert3 = sib.get(vertIndex+2); + // aquire triangle's vertex indices + int vertIndex = index * 3; + int vert1 = ib.get(vertIndex); + int vert2 = ib.get(vertIndex+1); + int vert3 = ib.get(vertIndex+2); - BufferUtils.populateFromBuffer(v1, fpb, vert1); - BufferUtils.populateFromBuffer(v2, fpb, vert2); - BufferUtils.populateFromBuffer(v3, fpb, vert3); - } + BufferUtils.populateFromBuffer(v1, fpb, vert1); + BufferUtils.populateFromBuffer(v2, fpb, vert2); + BufferUtils.populateFromBuffer(v3, fpb, vert3); + } } diff --git a/engine/src/core/com/jme3/scene/mesh/WrappedIndexBuffer.java b/engine/src/core/com/jme3/scene/mesh/WrappedIndexBuffer.java index 464d988fa..e4c059cfe 100644 --- a/engine/src/core/com/jme3/scene/mesh/WrappedIndexBuffer.java +++ b/engine/src/core/com/jme3/scene/mesh/WrappedIndexBuffer.java @@ -8,6 +8,13 @@ import java.nio.Buffer; import java.nio.IntBuffer; import java.nio.ShortBuffer; +/** + * WrappedIndexBuffer converts from one representation of mesh + * data to another. For example it can be used to read TriangleStrip data + * as if it was in Triangle format. + * + * @author Kirill Vainer + */ public class WrappedIndexBuffer extends VirtualIndexBuffer { private final IndexBuffer ib;