1a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta/* 2a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * Copyright (c) 2009-2012 jMonkeyEngine 3a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * All rights reserved. 4a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * 5a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * Redistribution and use in source and binary forms, with or without 6a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * modification, are permitted provided that the following conditions are 7a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * met: 8a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * 9a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * * Redistributions of source code must retain the above copyright 10a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * notice, this list of conditions and the following disclaimer. 11a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * 12a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * * Redistributions in binary form must reproduce the above copyright 13a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * notice, this list of conditions and the following disclaimer in the 14a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * documentation and/or other materials provided with the distribution. 15a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * 16a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * * Neither the name of 'jMonkeyEngine' nor the names of its contributors 17a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * may be used to endorse or promote products derived from this software 18a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * without specific prior written permission. 19a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * 20a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta */ 32a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta 33a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartapackage jme3test.app; 34a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta 35a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport com.jme3.app.Application; 36a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport com.jme3.app.SimpleApplication; 37a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport com.jme3.app.state.AbstractAppState; 38a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport com.jme3.app.state.AppStateManager; 39a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport com.jme3.material.Material; 40a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport com.jme3.math.Vector3f; 41a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport com.jme3.renderer.RenderManager; 42a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport com.jme3.scene.Geometry; 43a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport com.jme3.scene.shape.Box; 44a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta 45a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta 46a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta/** 47a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * Tests the app state lifecycles. 48a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * 49a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * @author Paul Speed 50a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta */ 51a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartapublic class TestAppStateLifeCycle extends SimpleApplication { 52a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta 53a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta public static void main(String[] args){ 54a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta TestAppStateLifeCycle app = new TestAppStateLifeCycle(); 55a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta app.start(); 56a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta } 57a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta 58a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta @Override 59a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta public void simpleInitApp() { 60a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta Box b = new Box(Vector3f.ZERO, 1, 1, 1); 61a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta Geometry geom = new Geometry("Box", b); 62a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); 63a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg")); 64a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta geom.setMaterial(mat); 65a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta rootNode.attachChild(geom); 66a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta 67a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta System.out.println("Attaching test state."); 68a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta stateManager.attach(new TestState()); 69a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta } 70a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta 71a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta @Override 72a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta public void simpleUpdate(float tpf) { 73a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta 74a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta if(stateManager.getState(TestState.class) != null) { 75a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta System.out.println("Detaching test state."); 76a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta stateManager.detach(stateManager.getState(TestState.class)); 77a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta System.out.println("Done"); 78a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta } 79a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta } 80a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta 81a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta public class TestState extends AbstractAppState { 82a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta 83a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta @Override 84a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta public void initialize(AppStateManager stateManager, Application app) { 85a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta super.initialize(stateManager, app); 86a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta System.out.println("Initialized"); 87a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta } 88a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta 89a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta @Override 90a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta public void stateAttached(AppStateManager stateManager) { 91a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta super.stateAttached(stateManager); 92a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta System.out.println("Attached"); 93a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta } 94a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta 95a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta @Override 96a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta public void update(float tpf) { 97a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta super.update(tpf); 98a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta System.out.println("update"); 99a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta } 100a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta 101a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta @Override 102a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta public void render(RenderManager rm) { 103a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta super.render(rm); 104a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta System.out.println("render"); 105a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta } 106a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta 107a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta @Override 108a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta public void postRender() { 109a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta super.postRender(); 110a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta System.out.println("postRender"); 111a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta } 112a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta 113a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta @Override 114a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta public void stateDetached(AppStateManager stateManager) { 115a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta super.stateDetached(stateManager); 116a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta System.out.println("Detached"); 117a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta } 118a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta 119a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta @Override 120a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta public void cleanup() { 121a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta super.cleanup(); 122a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta System.out.println("Cleanup"); 123a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta } 124a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta 125a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta } 126a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta} 127