OSDN Git Service

avoid vector creation in intersectsSphere, some corrections in stress tests for profi...
authorirrisor <irrisor@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Tue, 20 Sep 2005 09:47:22 +0000 (09:47 +0000)
committerirrisor <irrisor@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Tue, 20 Sep 2005 09:47:22 +0000 (09:47 +0000)
git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@2310 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

16 files changed:
.cvsignore
build.xml
src/com/jme/app/SimpleGame.java
src/com/jme/app/StandardGameState.java
src/com/jme/app/StandardGameStateDefaultCamera.java [new file with mode: 0755]
src/com/jme/bounding/BoundingSphere.java
src/com/jme/scene/BillboardNode.java
src/com/jme/scene/Spatial.java
src/com/jmex/effects/LensFlare.java
src/com/jmex/sound/openAL/objects/Sample3D.java
src/com/jmex/terrain/TerrainPage.java
src/jmetest/TestChooser.java
src/jmetest/TutorialGuide/HelloIntersection.java
src/jmetest/TutorialGuide/HelloLOD.java
src/jmetest/stress/graphbrowser/GraphBrowser.java
src/jmetest/stress/swarm/TestSwarm.java

index 539b6af..eecab2e 100755 (executable)
@@ -6,3 +6,4 @@ build.properties
 build-server.xml
 jme.jnlp
 properties.cfg
+ftp
index dae47bd..cbf7716 100755 (executable)
--- a/build.xml
+++ b/build.xml
@@ -90,6 +90,8 @@
                <delete dir="${doc}" />
                <delete>
                        <fileset dir="${src}" includes="**/*.class" />
+            <fileset dir="${release}" includes="jme*.jar"/>
+            <fileset dir="${webstart}" includes="*.jar"/>
                </delete>
        </target>
 
         <ftp server="ftp.jmonkeyengine.com" userid="${ftpuser}" password="${ftppassword}" remotedir="nightly" >
             <fileset dir="${webstart}" >
                 <include name="*.jar"/>
+                <include name="*.jnlp"/>
             </fileset>
             <fileset dir="${libs}" >
                 <include name="*.jar"/>
index 0eb4051..262a2ab 100755 (executable)
@@ -62,7 +62,7 @@ import com.jme.util.Timer;
  * of a main game loop. Interpolation is used between frames for varying framerates.
  *
  * @author Joshua Slack, (javadoc by cep21)
- * @version $Id: SimpleGame.java,v 1.37 2005-09-15 17:14:25 renanse Exp $
+ * @version $Id: SimpleGame.java,v 1.38 2005-09-20 09:47:17 irrisor Exp $
  */
 public abstract class SimpleGame extends BaseGame {
 
@@ -159,7 +159,7 @@ public abstract class SimpleGame extends BaseGame {
        simpleUpdate();
 
        /** Update controllers/render states/transforms/bounds for rootNode. */
-rootNode.updateGeometricState(tpf, true);
+    rootNode.updateGeometricState(tpf, true);
 
   }
 
index 1c23072..261a055 100755 (executable)
@@ -61,7 +61,7 @@ import com.jme.system.DisplaySystem;
  * 
  * @author Per Thulin
  */
-public class StandardGameState extends BasicGameState {
+public class StandardGameState extends StandardGameStateDefaultCamera {
        
        /** The camera of this game state. */
        protected Camera cam;
@@ -75,104 +75,17 @@ public class StandardGameState extends BasicGameState {
                super(name);
                
                initCamera();
-               initZBuffer();
-               
-           // Update geometric and rendering information for the rootNode.
-               rootNode.updateGeometricState(0.0f, true);
-           rootNode.updateRenderState();
-       }
-       
-       /**
-        * Creates a ZBuffer to display pixels closer to the camera above
-        * farther ones.
-        */
-       protected void initZBuffer() {
-               ZBufferState buf = DisplaySystem.getDisplaySystem().
-                       getRenderer().createZBufferState();
-               buf.setEnabled(true);
-               buf.setFunction(ZBufferState.CF_LEQUAL);                
-               rootNode.setRenderState(buf);
-       }
-       
-       /**
-        * Overwritten to appropriately call switchTo() or switchFrom().
-        * 
-        * @see GameState#setActive(boolean)
-        */
-       public void setActive(boolean active) {
-               if (active) onActivate();
-               else onDeactivate();
-               super.setActive(active);
-       }
-       
-       /**
-        * Calls stateUpdate(float), then updates the geometric state of the 
-        * rootNode.
-        * 
-        * @param tpf The elapsed time since last frame.
-        * @see GameState#update(float)
-        * @see StandardGameState#stateUpdate(float)
-        */
-       public final void update(float tpf) {   
-               stateUpdate(tpf);               
-               super.update(tpf);
-       }
-       
-       /**
-        * Calls stateRender(float), then renders the rootNode.
-        * 
-        * @param tpf The elapsed time since last frame.
-        * @see GameState#render(float)
-        * @see StandardGameState#stateRender(float)
-        */
-       public final void render(float tpf) {
-               stateRender(tpf);
-               super.render(tpf);
-       }
-       
-       /**
-        * This is where derived classes are supposed to put their game logic.
-        * Gets called between the input.update and 
-        * rootNode.updateGeometricState calls.
-        * 
-        * <p>
-        * Much like the structure of <code>SimpleGame</code>.
-        * </p>
-        * 
-        * @param tpf The time since the last frame.
-        */
-       protected void stateUpdate(float tpf) {         
-       }
-       
-       /**
-        * This is where derived classes are supposed to put their render logic.
-        * Gets called before the rootNode gets rendered.
-        * 
-        * <p>
-        * Much like the structure of <code>SimpleGame</code>.
-        * </p>
-        * 
-        * @param tpf The time since the last frame.
-        */
-       protected void stateRender(float tpf) {         
        }
-       
-       /**
+
+    /**
         * Points the renderers camera to the one contained by this state. Derived 
         * classes can put special actions they want to perform when activated here.
         */
        protected void onActivate() {
                DisplaySystem.getDisplaySystem().getRenderer().setCamera(cam);
        }
-       
-       /**
-        * Derived classes can put special actions they want to perform when 
-        * deactivated here.
-        */
-       protected void onDeactivate() {
-       }
-       
-       /**
+
+    /**
         * Gets the camera of this state.
         * 
         * @return The camera of this state.
diff --git a/src/com/jme/app/StandardGameStateDefaultCamera.java b/src/com/jme/app/StandardGameStateDefaultCamera.java
new file mode 100755 (executable)
index 0000000..81e6a99
--- /dev/null
@@ -0,0 +1,114 @@
+package com.jme.app;
+
+import com.jme.scene.state.ZBufferState;
+import com.jme.scene.Node;
+import com.jme.system.DisplaySystem;
+
+/**
+ * @author christian.schneider@uni-kassel.de
+ * @created 18.06.2005, 15:58:36
+ */
+public abstract class StandardGameStateDefaultCamera extends BasicGameState {
+    public StandardGameStateDefaultCamera( String name ) {
+        super( name );
+
+        initZBuffer();
+
+        // Update geometric and rendering information for the rootNode.
+        rootNode.updateGeometricState(0.0f, true);
+        rootNode.updateRenderState();
+    }
+
+    public Node getRootNode()
+    {
+        return rootNode;
+    }
+
+    /**
+        * Creates a ZBuffer to display pixels closer to the camera above
+        * farther ones.
+        */
+       protected void initZBuffer() {
+               ZBufferState buf = DisplaySystem.getDisplaySystem().
+                       getRenderer().createZBufferState();
+               buf.setEnabled(true);
+               buf.setFunction(ZBufferState.CF_LEQUAL);
+               rootNode.setRenderState(buf);
+       }
+
+    /**
+        * Overwritten to appropriately call switchTo() or switchFrom().
+        *
+        * @see GameState#setActive(boolean)
+        */
+       public void setActive(boolean active) {
+               if (active) onActivate();
+               else onDeactivate();
+               super.setActive(active);
+       }
+
+    /**
+        * Calls stateUpdate(float), then updates the geometric state of the
+        * rootNode.
+        *
+        * @param tpf The elapsed time since last frame.
+        * @see GameState#update(float)
+        * @see StandardGameState#stateUpdate(float)
+        */
+       public final void update(float tpf) {
+               stateUpdate(tpf);
+               super.update(tpf);
+       }
+
+    /**
+        * Calls stateRender(float), then renders the rootNode.
+        *
+        * @param tpf The elapsed time since last frame.
+        * @see GameState#render(float)
+        * @see StandardGameState#stateRender(float)
+        */
+       public final void render(float tpf) {
+               stateRender(tpf);
+               super.render(tpf);
+       }
+
+    /**
+        * This is where derived classes are supposed to put their game logic.
+        * Gets called between the input.update and
+        * rootNode.updateGeometricState calls.
+        *
+        * <p>
+        * Much like the structure of <code>SimpleGame</code>.
+        * </p>
+        *
+        * @param tpf The time since the last frame.
+        */
+       protected void stateUpdate(float tpf) {
+       }
+
+    /**
+        * This is where derived classes are supposed to put their render logic.
+        * Gets called before the rootNode gets rendered.
+        *
+        * <p>
+        * Much like the structure of <code>SimpleGame</code>.
+        * </p>
+        *
+        * @param tpf The time since the last frame.
+        */
+       protected void stateRender(float tpf) {
+       }
+
+    /**
+        * Points the renderers camera to the one contained by this state. Derived
+        * classes can put special actions they want to perform when activated here.
+        */
+       protected abstract void onActivate();
+
+    /**
+        * Derived classes can put special actions they want to perform when
+        * deactivated here.
+        */
+       protected void onDeactivate() {
+       }
+}
index c2d3b71..bfdedaf 100755 (executable)
@@ -54,7 +54,7 @@ import com.jme.util.geom.BufferUtils;
  * <code>computeFramePoint</code> in turn calls <code>containAABB</code>.
  * 
  * @author Mark Powell
- * @version $Id: BoundingSphere.java,v 1.29 2005-09-15 23:01:27 Mojomonkey Exp $
+ * @version $Id: BoundingSphere.java,v 1.30 2005-09-20 09:47:18 irrisor Exp $
  */
 public class BoundingSphere extends Sphere implements BoundingVolume {
 
@@ -88,8 +88,7 @@ public class BoundingSphere extends Sphere implements BoundingVolume {
      *            the center of the sphere.
      */
     public BoundingSphere(float radius, Vector3f center) {
-        super("bsphere", center, 10, 10, radius);
-        initCheckPlanes();
+        this("bsphere", radius, center);
     }
 
     /**
@@ -101,7 +100,7 @@ public class BoundingSphere extends Sphere implements BoundingVolume {
      *            the center of the sphere.
      */
     public BoundingSphere(String name, float radius, Vector3f center) {
-        super(name, center, 10, 10, radius);
+        super( name, center, 10, 10, radius );
         initCheckPlanes();
     }
 
@@ -304,6 +303,7 @@ public class BoundingSphere extends Sphere implements BoundingVolume {
      * @see #calcWelzl(com.jme.math.Vector3f[])
      */
     private void setSphere(Vector3f O, Vector3f A, Vector3f B) {
+        //todo: don't create vectors here!
         Vector3f a = A.subtract(O);
         Vector3f b = B.subtract(O);
         Vector3f acrossB = a.cross(b);
@@ -703,13 +703,16 @@ public class BoundingSphere extends Sphere implements BoundingVolume {
             return bv.intersectsSphere(this);
     }
 
+    private static Vector3f tmp_intersectsSphere = new Vector3f();
+
     /*
-     * (non-Javadoc)
-     * 
-     * @see com.jme.bounding.BoundingVolume#intersectsSphere(com.jme.bounding.BoundingSphere)
-     */
+    * (non-Javadoc)
+    *
+    * @see com.jme.bounding.BoundingVolume#intersectsSphere(com.jme.bounding.BoundingSphere)
+    */
     public boolean intersectsSphere(BoundingSphere bs) {
-        Vector3f diff = getCenter().subtract(bs.getCenter());
+        //note: as a field is used this is not thread safe!
+        Vector3f diff = tmp_intersectsSphere.set(getCenter()).subtractLocal(bs.getCenter());
         float rsum = getRadius() + bs.getRadius();
         return (diff.dot(diff) <= rsum * rsum);
     }
index 33ac7c8..c3721fc 100755 (executable)
@@ -51,7 +51,7 @@ import com.jme.renderer.Renderer;
  * 
  * @author Mark Powell
  * @author Joshua Slack
- * @version $Id: BillboardNode.java,v 1.20 2005-09-15 17:13:38 renanse Exp $
+ * @version $Id: BillboardNode.java,v 1.21 2005-09-20 09:47:18 irrisor Exp $
  */
 public class BillboardNode extends Node {
     private static final long serialVersionUID = 1L;
@@ -144,8 +144,8 @@ public class BillboardNode extends Node {
             break;
         }
 
-        for (int i = 0, cSize = children.size(); i < cSize; i++) {
-            Spatial child = (Spatial) children.get(i);
+        for (int i = 0, cSize = getChildren().size(); i < cSize; i++) {
+            Spatial child = (Spatial) getChildren().get(i);
             if (child != null) {
                 child.updateGeometricState(lastTime, false);
             }
index 8352ce2..98bf8eb 100755 (executable)
@@ -57,7 +57,7 @@ import com.jme.scene.state.TextureState;
  * 
  * @author Mark Powell
  * @author Joshua Slack
- * @version $Id: Spatial.java,v 1.70 2005-09-16 19:33:40 Mojomonkey Exp $
+ * @version $Id: Spatial.java,v 1.71 2005-09-20 09:47:18 irrisor Exp $
  */
 public abstract class Spatial implements Serializable {
        
@@ -603,12 +603,13 @@ public abstract class Spatial implements Serializable {
     }
 
     /**
+     * Called by {@link Node#attachChild(Spatial)} and {@link Node#detachChild(Spatial)} - don't call directly.
      * <code>setParent</code> sets the parent of this node.
      * 
      * @param parent
      *            the parent of this node.
      */
-    public void setParent(Node parent) {
+    protected void setParent(Node parent) {
         this.parent = parent;
     }
 
index cac8142..20d7479 100755 (executable)
@@ -65,7 +65,7 @@ import com.jme.system.JmeException;
  * Only FlareQuad objects are acceptable as children.
  * 
  * @author Joshua Slack
- * @version $Id: LensFlare.java,v 1.5 2005-09-16 21:36:16 renanse Exp $
+ * @version $Id: LensFlare.java,v 1.6 2005-09-20 09:47:19 irrisor Exp $
  */
 
 public class LensFlare extends Node {
@@ -255,7 +255,7 @@ public class LensFlare extends Node {
             }
         }
 
-        for (int x = children.size(); --x >= 0;) {
+        for (int x = getQuantity(); --x >= 0;) {
             FlareQuad fq = (FlareQuad) getChild(x);
             fq.setLocalScale(scale);
             fq.updatePosition(flarePoint, midPoint);
index b285de8..c50b119 100755 (executable)
@@ -71,8 +71,8 @@ public class Sample3D extends SoundSpatial{
         generateSource();
     }
     
-    public Sample3D(URL url){     
-        LoggingSystem.getLogger().log(Level.INFO,"Load file:"+url.getFile());
+    public Sample3D(URL url){
+        LoggingSystem.getLogger().log(Level.INFO,"Load file:"+url);
         buffer=SampleLoader.loadBuffer(url);
         generateSource();
     }
index 46fc900..8c9cdf1 100755 (executable)
@@ -58,7 +58,7 @@ import com.jme.util.LoggingSystem;
  * It is recommended that different combinations are tried.
  *
  * @author Mark Powell
- * @version $Id: TerrainPage.java,v 1.3 2005-09-16 19:33:42 Mojomonkey Exp $
+ * @version $Id: TerrainPage.java,v 1.4 2005-09-20 09:47:20 irrisor Exp $
  */
 public class TerrainPage extends Node {
 
@@ -591,7 +591,7 @@ public class TerrainPage extends Node {
     }
     
     public void fixNormals() {
-        Iterator it = children.iterator();
+        Iterator it = getChildren().iterator();
         while (it.hasNext()) {
             Object child = it.next();
             if (child instanceof TerrainPage) {
index 90ab83c..c66d1bc 100755 (executable)
@@ -369,6 +369,7 @@ public class TestChooser extends JDialog {
             TestChooser chooser = new TestChooser();
             final Vector classes = new Vector();
 
+            System.out.println( "Composing Test list..." );
             Sys.class.getName(); //to check loading lwjgl library
 
             //put some featured tests at the beginning
index beff803..33c1a88 100755 (executable)
@@ -51,7 +51,7 @@ import com.jme.scene.shape.Sphere;
 import com.jme.scene.state.MaterialState;
 import com.jme.scene.state.TextureState;
 import com.jme.util.TextureManager;
-import com.jmex.sound.fmod.SoundSystem;
+import com.jmex.sound.openAL.SoundSystem;
 
 
 /**
@@ -158,8 +158,8 @@ public class HelloIntersection extends SimpleGame {
                
                snode = SoundSystem.createSoundNode();
                /** Create program sound */
-               targetSound = SoundSystem.create3DSample("D:/eclipse/workspace/JMonkeyEngine/src/jmetest/data/sound/explosion.wav");
-               laserSound=SoundSystem.create3DSample("D:/eclipse/workspace/JMonkeyEngine/src/jmetest/data/sound/laser.ogg");
+               targetSound = SoundSystem.create3DSample( getClass().getResource( "/jmetest/data/sound/explosion.wav" ) );
+               laserSound = SoundSystem.create3DSample( getClass().getResource( "/jmetest/data/sound/laser.ogg" ) );
         SoundSystem.setSampleMaxAudibleDistance(targetSound, 1000);
         SoundSystem.setSampleMaxAudibleDistance(laserSound, 1000);
         // Then we bind the programid we received to our laser event id.
index cf932f4..33fe30c 100755 (executable)
@@ -45,12 +45,10 @@ import com.jme.input.KeyInput;
 import com.jme.input.action.KeyExitAction;
 import com.jme.math.Matrix3f;
 import com.jme.math.Vector3f;
-import com.jme.scene.CameraNode;
-import com.jme.scene.Controller;
-import com.jme.scene.Node;
-import com.jme.scene.TriMesh;
+import com.jme.scene.*;
 import com.jme.scene.lod.AreaClodMesh;
 import com.jme.scene.state.RenderState;
+import com.jme.util.LoggingSystem;
 import com.jmex.model.XMLparser.JmeBinaryReader;
 import com.jmex.model.XMLparser.Converters.FormatConverter;
 import com.jmex.model.XMLparser.Converters.ObjToJme;
@@ -156,22 +154,34 @@ public class HelloLOD extends SimpleGame {
         Node clodNode=new Node("Clod node");
         // For each mesh in maggie
         for (int i=0;i<meshParent.getQuantity();i++){
-            // Create an AreaClodMesh for that mesh.  Let it compute records automatically
-            AreaClodMesh acm=new AreaClodMesh("part"+i,(TriMesh) meshParent.getChild(i),null);
-            acm.setModelBound(new BoundingSphere());
-            acm.updateModelBound();
-
-            // Allow 1/2 of a triangle in every pixel on the screen in the bounds.
-            acm.setTrisPerPixel(.5f);
-
-            // Force a move of 2 units before updating the mesh geometry
-            acm.setDistanceTolerance(2);
-
-            // Give the clodMesh node the material state that the original had.
-            acm.setRenderState(meshParent.getChild(i).getRenderStateList()[RenderState.RS_MATERIAL]);
-
-            // Attach clod node.
-            clodNode.attachChild(acm);
+            final Spatial child = meshParent.getChild(i);
+            if ( child instanceof Node )
+            {
+                clodNode.attachChild( getClodNodeFromParent( (Node) child ) );
+            }
+            else if ( child instanceof TriMesh )
+            {
+                // Create an AreaClodMesh for that mesh.  Let it compute records automatically
+                AreaClodMesh acm=new AreaClodMesh("part"+i,(TriMesh) child,null);
+                acm.setModelBound(new BoundingSphere());
+                acm.updateModelBound();
+
+                // Allow 1/2 of a triangle in every pixel on the screen in the bounds.
+                acm.setTrisPerPixel(.5f);
+
+                // Force a move of 2 units before updating the mesh geometry
+                acm.setDistanceTolerance(2);
+
+                // Give the clodMesh node the material state that the original had.
+                acm.setRenderState(child.getRenderStateList()[RenderState.RS_MATERIAL]);
+
+                // Attach clod node.
+                clodNode.attachChild(acm);
+            }
+            else
+            {
+                LoggingSystem.getLogger().warning( "Unhandled Spatial type: " + child.getClass() );
+            }
         }
         return clodNode;
     }
index c6c05a0..a159fe2 100755 (executable)
@@ -13,8 +13,8 @@
  *   notice, this list of conditions and the following disclaimer in the
  *   documentation and/or other materials provided with the distribution.
  *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors 
- *   may be used to endorse or promote products derived from this software 
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *   may be used to endorse or promote products derived from this software
  *   without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@@ -42,9 +42,7 @@ import com.jme.input.KeyInput;
 import com.jme.light.AmbientLight;
 import com.jme.math.Vector3f;
 import com.jme.renderer.ColorRGBA;
-import com.jme.scene.Line;
-import com.jme.scene.Spatial;
-import com.jme.scene.Text;
+import com.jme.scene.*;
 import com.jme.scene.shape.Box;
 import com.jme.scene.state.LightState;
 import com.jme.scene.state.MaterialState;
@@ -85,6 +83,7 @@ public class GraphBrowser extends StressApp {
      * Command for toggling edges.
      */
     private static final String COMMAND_PATH_ONLY = "toggle_path_only";
+    private Box box;
 
     /**
      * Create a graphbrowser app that uses given {@link GraphAccessor} and {@link GraphLayouter}.
@@ -104,10 +103,11 @@ public class GraphBrowser extends StressApp {
         light.setEnabled( true );
         light.setDiffuse( new ColorRGBA( SCENE_LIGHT, SCENE_LIGHT, SCENE_LIGHT, 1 ) );
         lightState.attach( light );
+        box = new Box( "box", new Vector3f( -1, -1, -1 ), new Vector3f( 1, 1, 1 ) );
 
         for ( int i = accessor.getNodeCount() - 1; i >= 0; i-- ) {
             Object node = accessor.getNode( i );
-            Box nodeVis = new Box( String.valueOf( node ), new Vector3f( -1, -1, -1 ), new Vector3f( 1, 1, 1 ) );
+            Spatial nodeVis = new SharedMesh( String.valueOf( node ), box );
             nodeVis.getLocalTranslation().set( layouter.getCoordinates( node ) );
 
             MaterialState material = display.getRenderer().createMaterialState();
index 163984e..7d3850c 100755 (executable)
@@ -13,8 +13,8 @@
  *   notice, this list of conditions and the following disclaimer in the
  *   documentation and/or other materials provided with the distribution.
  *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors 
- *   may be used to endorse or promote products derived from this software 
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *   may be used to endorse or promote products derived from this software
  *   without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS