1 /* 2 * Copyright (c) 2009-2010 jMonkeyEngine 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * * Neither the name of 'jMonkeyEngine' nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 package com.jme3.app.state; 34 35 import com.jme3.app.Application; 36 import com.jme3.renderer.RenderManager; 37 38 /** 39 * AppState represents a continously executing code inside the main loop. 40 * An <code>AppState</code> can track when it is attached to the 41 * {@link AppStateManager} or when it is detached. <br/><code>AppState</code>s 42 * are initialized in the render thread, upon a call to {@link AppState#initialize(com.jme3.app.state.AppStateManager, com.jme3.app.Application) } 43 * and are de-initialized upon a call to {@link AppState#cleanup()}. 44 * Implementations should return the correct value with a call to 45 * {@link AppState#isInitialized() } as specified above.<br/> 46 * 47 * 48 * @author Kirill Vainer 49 */ 50 public interface AppState { 51 52 /** 53 * Called to initialize the AppState. 54 * 55 * @param stateManager The state manager 56 * @param app 57 */ initialize(AppStateManager stateManager, Application app)58 public void initialize(AppStateManager stateManager, Application app); 59 60 /** 61 * @return True if <code>initialize()</code> was called on the state, 62 * false otherwise. 63 */ isInitialized()64 public boolean isInitialized(); 65 66 /** 67 * Enable or disable the functionality of the <code>AppState</code>. 68 * The effect of this call depends on implementation. An 69 * <code>AppState</code> starts as being enabled by default. 70 * 71 * @param active activate the AppState or not. 72 */ setEnabled(boolean active)73 public void setEnabled(boolean active); 74 75 /** 76 * @return True if the <code>AppState</code> is enabled, false otherwise. 77 * 78 * @see AppState#setEnabled(boolean) 79 */ isEnabled()80 public boolean isEnabled(); 81 /** 82 * Called when the state was attached. 83 * 84 * @param stateManager State manager to which the state was attached to. 85 */ stateAttached(AppStateManager stateManager)86 public void stateAttached(AppStateManager stateManager); 87 88 /** 89 * Called when the state was detached. 90 * 91 * @param stateManager The state manager from which the state was detached from. 92 */ stateDetached(AppStateManager stateManager)93 public void stateDetached(AppStateManager stateManager); 94 95 /** 96 * Called to update the state. 97 * 98 * @param tpf Time per frame. 99 */ update(float tpf)100 public void update(float tpf); 101 102 /** 103 * Render the state. 104 * 105 * @param rm RenderManager 106 */ render(RenderManager rm)107 public void render(RenderManager rm); 108 109 /** 110 * Called after all rendering commands are flushed. 111 */ postRender()112 public void postRender(); 113 114 /** 115 * Cleanup the game state. 116 */ cleanup()117 public void cleanup(); 118 119 } 120