diff options
Diffstat (limited to 'engine/src/test/jme3test/app')
-rw-r--r-- | engine/src/test/jme3test/app/TestApplication.java | 75 | ||||
-rw-r--r-- | engine/src/test/jme3test/app/TestBareBonesApp.java | 90 | ||||
-rw-r--r-- | engine/src/test/jme3test/app/TestChangeAppIcon.java | 75 | ||||
-rw-r--r-- | engine/src/test/jme3test/app/TestContextRestart.java | 59 | ||||
-rw-r--r-- | engine/src/test/jme3test/app/TestIDList.java | 164 | ||||
-rw-r--r-- | engine/src/test/jme3test/app/TestReleaseDirectMemory.java | 70 | ||||
-rw-r--r-- | engine/src/test/jme3test/app/TestTempVars.java | 114 | ||||
-rw-r--r-- | engine/src/test/jme3test/app/state/RootNodeState.java | 54 | ||||
-rw-r--r-- | engine/src/test/jme3test/app/state/TestAppStates.java | 100 |
9 files changed, 801 insertions, 0 deletions
diff --git a/engine/src/test/jme3test/app/TestApplication.java b/engine/src/test/jme3test/app/TestApplication.java new file mode 100644 index 0000000..ae07f8a --- /dev/null +++ b/engine/src/test/jme3test/app/TestApplication.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2009-2010 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * 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 + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package jme3test.app; + +import com.jme3.app.Application; +import com.jme3.system.AppSettings; +import com.jme3.system.JmeContext.Type; + +/** + * Test Application functionality, such as create, restart, destroy, etc. + * @author Kirill + */ +public class TestApplication { + + public static void main(String[] args) throws InterruptedException{ + System.out.println("Creating application.."); + Application app = new Application(); + System.out.println("Starting application in LWJGL mode.."); + app.start(); + System.out.println("Waiting 5 seconds"); + Thread.sleep(5000); + System.out.println("Closing application.."); + app.stop(); + + Thread.sleep(2000); + System.out.println("Starting in fullscreen mode"); + app = new Application(); + AppSettings settings = new AppSettings(true); + settings.setFullscreen(true); + settings.setResolution(-1,-1); // current width/height + app.setSettings(settings); + app.start(); + Thread.sleep(5000); + app.stop(); + + Thread.sleep(2000); + System.out.println("Creating offscreen buffer application"); + app = new Application(); + app.start(Type.OffscreenSurface); + Thread.sleep(3000); + System.out.println("Destroying offscreen buffer"); + app.stop(); + } + +} diff --git a/engine/src/test/jme3test/app/TestBareBonesApp.java b/engine/src/test/jme3test/app/TestBareBonesApp.java new file mode 100644 index 0000000..ee46388 --- /dev/null +++ b/engine/src/test/jme3test/app/TestBareBonesApp.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2009-2010 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * 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 + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package jme3test.app; + +import com.jme3.app.Application; +import com.jme3.math.Vector3f; +import com.jme3.scene.Geometry; +import com.jme3.scene.shape.Box; + +/** + * Test a bare-bones application, without SimpleApplication. + */ +public class TestBareBonesApp extends Application { + + private Geometry boxGeom; + + public static void main(String[] args){ + TestBareBonesApp app = new TestBareBonesApp(); + app.start(); + } + + @Override + public void initialize(){ + super.initialize(); + + System.out.println("Initialize"); + + // create a box + boxGeom = new Geometry("Box", new Box(Vector3f.ZERO, 2, 2, 2)); + + // load some default material + boxGeom.setMaterial(assetManager.loadMaterial("Interface/Logo/Logo.j3m")); + + // attach box to display in primary viewport + viewPort.attachScene(boxGeom); + } + + @Override + public void update(){ + super.update(); + + // do some animation + float tpf = timer.getTimePerFrame(); + boxGeom.rotate(tpf * 2, tpf * 4, tpf * 3); + + // dont forget to update the scenes + boxGeom.updateLogicalState(tpf); + boxGeom.updateGeometricState(); + + // render the viewports + renderManager.render(tpf, context.isRenderable()); + } + + @Override + public void destroy(){ + super.destroy(); + + System.out.println("Destroy"); + } +} diff --git a/engine/src/test/jme3test/app/TestChangeAppIcon.java b/engine/src/test/jme3test/app/TestChangeAppIcon.java new file mode 100644 index 0000000..004bd32 --- /dev/null +++ b/engine/src/test/jme3test/app/TestChangeAppIcon.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2009-2010 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * 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 + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package jme3test.app; + +import com.jme3.app.SimpleApplication; +import com.jme3.font.BitmapText; +import com.jme3.system.AppSettings; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.util.logging.Logger; +import javax.imageio.ImageIO; + +public class TestChangeAppIcon extends SimpleApplication { + + private static final Logger log=Logger.getLogger(TestChangeAppIcon.class.getName()); + + public static void main(String[] args) { + TestChangeAppIcon app = new TestChangeAppIcon(); + AppSettings settings = new AppSettings(true); + + try { + Class<TestChangeAppIcon> clazz = TestChangeAppIcon.class; + + settings.setIcons(new BufferedImage[]{ + ImageIO.read(clazz.getResourceAsStream("/Interface/icons/SmartMonkey256.png")), + ImageIO.read(clazz.getResourceAsStream("/Interface/icons/SmartMonkey128.png")), + ImageIO.read(clazz.getResourceAsStream("/Interface/icons/SmartMonkey32.png")), + ImageIO.read(clazz.getResourceAsStream("/Interface/icons/SmartMonkey16.png")), + }); + } catch (IOException e) { + log.log(java.util.logging.Level.WARNING, "Unable to load program icons", e); + } + app.setSettings(settings); + app.start(); + } + + @Override + public void simpleInitApp() { + // Write text on the screen (HUD) + guiNode.detachAllChildren(); + BitmapText helloText = new BitmapText(guiFont); + helloText.setText("The icon of the app should be a smart monkey!"); + helloText.setLocalTranslation(300, helloText.getLineHeight(), 0); + guiNode.attachChild(helloText); + } +} diff --git a/engine/src/test/jme3test/app/TestContextRestart.java b/engine/src/test/jme3test/app/TestContextRestart.java new file mode 100644 index 0000000..b83f336 --- /dev/null +++ b/engine/src/test/jme3test/app/TestContextRestart.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2009-2010 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * 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 + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package jme3test.app; + +import com.jme3.app.Application; +import com.jme3.system.AppSettings; + +public class TestContextRestart { + + public static void main(String[] args) throws InterruptedException{ + AppSettings settings = new AppSettings(true); + + final Application app = new Application(); + app.setSettings(settings); + app.start(); + + Thread.sleep(3000); + + settings.setFullscreen(true); + settings.setResolution(-1, -1); + app.setSettings(settings); + app.restart(); + + Thread.sleep(3000); + + app.stop(); + } + +} diff --git a/engine/src/test/jme3test/app/TestIDList.java b/engine/src/test/jme3test/app/TestIDList.java new file mode 100644 index 0000000..4e33eaa --- /dev/null +++ b/engine/src/test/jme3test/app/TestIDList.java @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2009-2010 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * 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 + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package jme3test.app; + +import com.jme3.renderer.IDList; +import java.util.*; + +public class TestIDList { + + static class StateCol { + + static Random rand = new Random(); + + Map<Integer, Object> objs = new HashMap<Integer, Object>(); + + public StateCol(){ + // populate with free ids + List<Integer> freeIds = new ArrayList(); + for (int i = 0; i < 16; i++){ + freeIds.add(i); + } + + // create random + int numStates = rand.nextInt(6) + 1; + for (int i = 0; i < numStates; i++){ + // remove a random id from free id list + int idx = rand.nextInt(freeIds.size()); + int id = freeIds.remove(idx); + + objs.put(id, new Object()); + } + } + + public void print(){ + System.out.println("-----------------"); + + Set<Integer> keys = objs.keySet(); + Integer[] keysArr = keys.toArray(new Integer[0]); + Arrays.sort(keysArr); + for (int i = 0; i < keysArr.length; i++){ + System.out.println(keysArr[i]+" => "+objs.get(keysArr[i]).hashCode()); + } + } + + } + + static IDList list = new IDList(); + static int boundSlot = 0; + + static Object[] slots = new Object[16]; + static boolean[] enabledSlots = new boolean[16]; + + static void enable(int slot){ + System.out.println("Enabled SLOT["+slot+"]"); + if (enabledSlots[slot] == true){ + System.err.println("FAIL! Extra state change"); + } + enabledSlots[slot] = true; + } + + static void disable(int slot){ + System.out.println("Disabled SLOT["+slot+"]"); + if (enabledSlots[slot] == false){ + System.err.println("FAIL! Extra state change"); + } + enabledSlots[slot] = false; + } + + static void setSlot(int slot, Object val){ + if (!list.moveToNew(slot)){ + enable(slot); + } + if (slots[slot] != val){ + System.out.println("SLOT["+slot+"] = "+val.hashCode()); + slots[slot] = val; + } + } + + static void checkSlots(StateCol state){ + for (int i = 0; i < 16; i++){ + if (slots[i] != null && enabledSlots[i] == false){ + System.err.println("FAIL! SLOT["+i+"] assigned, but disabled"); + } + if (slots[i] == null && enabledSlots[i] == true){ + System.err.println("FAIL! SLOT["+i+"] enabled, but not assigned"); + } + + Object val = state.objs.get(i); + if (val != null){ + if (slots[i] != val) + System.err.println("FAIL! SLOT["+i+"] does not contain correct value"); + if (!enabledSlots[i]) + System.err.println("FAIL! SLOT["+i+"] is not enabled"); + }else{ + if (slots[i] != null) + System.err.println("FAIL! SLOT["+i+"] is not set"); + if (enabledSlots[i]) + System.err.println("FAIL! SLOT["+i+"] is enabled"); + } + } + } + + static void clearSlots(){ + for (int i = 0; i < list.oldLen; i++){ + int slot = list.oldList[i]; + disable(slot); + slots[slot] = null; + } + list.copyNewToOld(); +// context.attribIndexList.print(); + } + + static void setState(StateCol state){ + state.print(); + for (Map.Entry<Integer, Object> entry : state.objs.entrySet()){ + setSlot(entry.getKey(), entry.getValue()); + } + clearSlots(); + checkSlots(state); + } + + public static void main(String[] args){ + StateCol[] states = new StateCol[20]; + for (int i = 0; i < states.length; i++) + states[i] = new StateCol(); + + // shuffle would be useful here.. + + for (int i = 0; i < states.length; i++){ + setState(states[i]); + } + } + +} diff --git a/engine/src/test/jme3test/app/TestReleaseDirectMemory.java b/engine/src/test/jme3test/app/TestReleaseDirectMemory.java new file mode 100644 index 0000000..84a58ae --- /dev/null +++ b/engine/src/test/jme3test/app/TestReleaseDirectMemory.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2009-2010 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * 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 + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package jme3test.app; + +import com.jme3.app.SimpleApplication; +import com.jme3.material.Material; +import com.jme3.math.Vector3f; +import com.jme3.scene.Geometry; +import com.jme3.scene.shape.Box; +import com.jme3.util.BufferUtils; +import java.nio.ByteBuffer; +import java.nio.FloatBuffer; + +public class TestReleaseDirectMemory extends SimpleApplication { + + public static void main(String[] args){ + TestReleaseDirectMemory app = new TestReleaseDirectMemory(); + app.start(); + } + + @Override + public void simpleInitApp() { + Box b = new Box(Vector3f.ZERO, 1, 1, 1); + Geometry geom = new Geometry("Box", b); + Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); + mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg")); + geom.setMaterial(mat); + rootNode.attachChild(geom); + } + + @Override + public void simpleUpdate(float tpf) { + ByteBuffer buf = BufferUtils.createByteBuffer(500000); + BufferUtils.destroyDirectBuffer(buf); + + FloatBuffer buf2 = BufferUtils.createFloatBuffer(500000); + BufferUtils.destroyDirectBuffer(buf2); + } + +} diff --git a/engine/src/test/jme3test/app/TestTempVars.java b/engine/src/test/jme3test/app/TestTempVars.java new file mode 100644 index 0000000..7102888 --- /dev/null +++ b/engine/src/test/jme3test/app/TestTempVars.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2009-2010 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * 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 + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package jme3test.app; + +import com.jme3.math.Vector3f; +import com.jme3.util.TempVars; + +public class TestTempVars { + + private static final int ITERATIONS = 10000000; + private static final int NANOS_TO_MS = 1000000; + + private static final Vector3f sumCompute = new Vector3f(); + + public static void main(String[] args) { + long milliseconds, nanos; + + for (int i = 0; i < 4; i++){ + System.gc(); + } + +// sumCompute.set(0, 0, 0); +// long nanos = System.nanoTime(); +// for (int i = 0; i < ITERATIONS; i++) { +// recursiveMethod(0); +// } +// long milliseconds = (System.nanoTime() - nanos) / NANOS_TO_MS; +// System.out.println("100 million TempVars calls with 5 recursions: " + milliseconds + " ms"); +// System.out.println(sumCompute); + + sumCompute.set(0, 0, 0); + nanos = System.nanoTime(); + for (int i = 0; i < ITERATIONS; i++) { + methodThatUsesTempVars(); + } + milliseconds = (System.nanoTime() - nanos) / NANOS_TO_MS; + System.out.println("100 million TempVars calls: " + milliseconds + " ms"); + System.out.println(sumCompute); + + sumCompute.set(0, 0, 0); + nanos = System.nanoTime(); + for (int i = 0; i < ITERATIONS; i++) { + methodThatUsesAllocation(); + } + milliseconds = (System.nanoTime() - nanos) / NANOS_TO_MS; + System.out.println("100 million allocation calls: " + milliseconds + " ms"); + System.out.println(sumCompute); + + nanos = System.nanoTime(); + for (int i = 0; i < 10; i++){ + System.gc(); + } + milliseconds = (System.nanoTime() - nanos) / NANOS_TO_MS; + System.out.println("cleanup time after allocation calls: " + milliseconds + " ms"); + } + + public static void methodThatUsesAllocation(){ + Vector3f vector = new Vector3f(); + vector.set(0.1f, 0.2f, 0.3f); + sumCompute.addLocal(vector); + } + + public static void recursiveMethod(int recurse) { + TempVars vars = TempVars.get(); + { + vars.vect1.set(0.1f, 0.2f, 0.3f); + + if (recurse < 4) { + recursiveMethod(recurse + 1); + } + + sumCompute.addLocal(vars.vect1); + } + vars.release(); + } + + public static void methodThatUsesTempVars() { + TempVars vars = TempVars.get(); + { + vars.vect1.set(0.1f, 0.2f, 0.3f); + sumCompute.addLocal(vars.vect1); + } + vars.release(); + } +} diff --git a/engine/src/test/jme3test/app/state/RootNodeState.java b/engine/src/test/jme3test/app/state/RootNodeState.java new file mode 100644 index 0000000..fddb63a --- /dev/null +++ b/engine/src/test/jme3test/app/state/RootNodeState.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2009-2010 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * 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 + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package jme3test.app.state; + +import com.jme3.app.state.AbstractAppState; +import com.jme3.scene.Node; + +public class RootNodeState extends AbstractAppState { + + private Node rootNode = new Node("Root Node"); + + public Node getRootNode(){ + return rootNode; + } + + @Override + public void update(float tpf) { + super.update(tpf); + + rootNode.updateLogicalState(tpf); + rootNode.updateGeometricState(); + } + +} diff --git a/engine/src/test/jme3test/app/state/TestAppStates.java b/engine/src/test/jme3test/app/state/TestAppStates.java new file mode 100644 index 0000000..721bc04 --- /dev/null +++ b/engine/src/test/jme3test/app/state/TestAppStates.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2009-2010 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * 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 + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package jme3test.app.state; + +import com.jme3.app.Application; +import com.jme3.niftygui.NiftyJmeDisplay; +import com.jme3.scene.Spatial; +import com.jme3.system.AppSettings; +import com.jme3.system.JmeContext; + +public class TestAppStates extends Application { + + public static void main(String[] args){ + TestAppStates app = new TestAppStates(); + app.start(); + } + + @Override + public void start(JmeContext.Type contextType){ + AppSettings settings = new AppSettings(true); + settings.setResolution(1024, 768); + setSettings(settings); + + super.start(contextType); + } + + @Override + public void initialize(){ + super.initialize(); + + System.out.println("Initialize"); + + RootNodeState state = new RootNodeState(); + viewPort.attachScene(state.getRootNode()); + stateManager.attach(state); + + Spatial model = assetManager.loadModel("Models/Teapot/Teapot.obj"); + model.scale(3); + model.setMaterial(assetManager.loadMaterial("Interface/Logo/Logo.j3m")); + state.getRootNode().attachChild(model); + + NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager, + inputManager, + audioRenderer, + guiViewPort); + niftyDisplay.getNifty().fromXml("Interface/Nifty/HelloJme.xml", "start"); + guiViewPort.addProcessor(niftyDisplay); + } + + @Override + public void update(){ + super.update(); + + // do some animation + float tpf = timer.getTimePerFrame(); + + stateManager.update(tpf); + stateManager.render(renderManager); + + // render the viewports + renderManager.render(tpf, context.isRenderable()); + } + + @Override + public void destroy(){ + super.destroy(); + + System.out.println("Destroy"); + } +} |