OSDN Git Service

* Mesh.getTriangle() now supports 32bit index buffers and no index buffers
authorShadowIsLord <ShadowIsLord@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Sun, 22 May 2011 01:19:40 +0000 (01:19 +0000)
committerShadowIsLord <ShadowIsLord@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Sun, 22 May 2011 01:19:40 +0000 (01:19 +0000)
 * Fix small logging issue in InputManager
 * Added stream-cache feature to streaming audio
 * Additional javadoc

git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@7515 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

engine/src/core/com/jme3/audio/ALObject.java
engine/src/core/com/jme3/audio/AudioBuffer.java
engine/src/core/com/jme3/audio/AudioData.java
engine/src/core/com/jme3/audio/AudioKey.java
engine/src/core/com/jme3/audio/AudioNode.java
engine/src/core/com/jme3/audio/AudioStream.java
engine/src/core/com/jme3/input/InputManager.java
engine/src/core/com/jme3/scene/Mesh.java
engine/src/core/com/jme3/scene/mesh/WrappedIndexBuffer.java

index 1076d23..a801fd6 100644 (file)
 
 package com.jme3.audio;
 
+/**
+ * Used for managing AL (Audio Library) objects.
+ * 
+ * @author Kirill Vainer
+ */
 public abstract class ALObject {
 
     protected int id = -1;
index 6971085..1b4d4ab 100644 (file)
@@ -38,10 +38,10 @@ import java.nio.ByteBuffer;
 /**
  * An <code>AudioBuffer</code> is an implementation of AudioData
  * where the audio is buffered (stored in memory). All parts of it
- * are accessable at any time. <br/>
+ * are accessible at any time. <br/>
  * AudioBuffers are useful for short sounds, like effects, etc.
  *
- * @author Kirill
+ * @author Kirill Vainer
  */
 public class AudioBuffer extends AudioData {
 
index 3349230..ab9675c 100644 (file)
@@ -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 {
 
index 616b5eb..73a435b 100644 (file)
@@ -42,13 +42,30 @@ import java.io.IOException;
 /**
  * <code>AudioKey</code> is extending AssetKey by holding stream flag.
  *
- * @author Kirill
+ * @author Kirill Vainer
  */
 public class AudioKey extends AssetKey<AudioData> {
 
     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
      *
      * @param name Name of the asset
@@ -70,15 +87,35 @@ public class AudioKey extends AssetKey<AudioData> {
 
     @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<AudioData> {
         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<AudioData> {
         super.read(im);
         InputCapsule ic = im.getCapsule(this);
         stream = ic.readBoolean("do_stream", false);
+        streamCache = ic.readBoolean("use_stream_cache", false);
     }
 
 }
index 72a0207..708e5c3 100644 (file)
@@ -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);
index 76fbd32..4c58b8a 100644 (file)
@@ -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");
     }
index cf43b88..850571a 100644 (file)
@@ -434,7 +434,7 @@ public class InputManager implements RawInputListener {
                 names.add(mapping);\r
                 mapping.triggers.add(hash);\r
             } else {\r
-                logger.log(Level.WARNING, "Attempted to add mapping '{0}' twice to trigger.", mappingName);\r
+                logger.log(Level.WARNING, "Attempted to add mapping \"{0}\" twice to trigger.", mappingName);\r
             }\r
         }\r
     }\r
index c10d0be..4e3330c 100644 (file)
@@ -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);
+            
         }
     }
     
index 464d988..e4c059c 100644 (file)
@@ -8,6 +8,13 @@ import java.nio.Buffer;
 import java.nio.IntBuffer;
 import java.nio.ShortBuffer;
 
+/**
+ * <code>WrappedIndexBuffer</code> 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;