ソースを参照

Update application_states.adoc

mitm001 8 年 前
コミット
cd54839003
1 ファイル変更61 行追加17 行削除
  1. 61 17
      src/docs/asciidoc/jme3/advanced/application_states.adoc

+ 61 - 17
src/docs/asciidoc/jme3/advanced/application_states.adoc

@@ -187,6 +187,67 @@ public class MyAppState extends AbstractAppState {
 ----
 
 
+=== BaseAppState
+
+
+A new link:http://javadoc.jmonkeyengine.org/com/jme3/app/state/BaseAppState.html[BaseAppState] class was introduced as part of the link:https://hub.jmonkeyengine.org/t/jmonkeyengine-3-1-alpha-4-released/35478[updates] being made to the AppState interface. AbstractAppState is the most minimal of the minimal implementations of the AppState interface. You essentially still need to do everything yourself, including getting the funky enable/disable/initialized/terminate logic right. Now you just extend BaseAppState and you get onEnable() and onDisable() already worked out for you.
+
+Definition:
+
+[source,java]
+----
+public class MyBaseAppState extends BaseAppState {        
+    @Override    protected void initialize(Application app) {        
+        //It is technically safe to do all initialization and cleanup in the         
+        //onEnable()/onDisable() methods. Choosing to use initialize() and         
+        //cleanup() for this is a matter of performance specifics for the         
+        //implementor.        
+        //TODO: initialize your AppState, e.g. attach spatials to rootNode    
+    }
+
+    @Override    
+    protected void cleanup(Application app) {        
+        //TODO: clean up what you initialized in the initialize method,        
+        //e.g. remove all spatials from rootNode    
+    }
+    
+    //onEnable()/onDisable() can be used for managing things that should     
+    //only exist while the state is enabled. Prime examples would be scene     
+    //graph attachment or input listener attachment.    
+    @Override    
+    protected void onEnable() {        
+        //Called when the state is fully enabled, ie: is attached and         
+        //isEnabled() is true or when the setEnabled() status changes after the         
+        //state is attached.    
+    }
+    
+    @Override    
+    protected void onDisable() {        
+        //Called when the state was previously enabled but is now disabled         
+        //either because setEnabled(false) was called or the state is being         
+        //cleaned up.    
+    }        
+    
+    @Override    
+    public void update(float tpf) {        
+        //TODO: implement behavior during runtime    
+    }
+    
+}
+----
+
+Notable BaseAppState changes are as follows:
+
+*You no longer need to call super.initialize(stateManager, app) because it is now called by BaseAppState upon initialization for you.
+*  You no longer have to cast SimpleApplication to have access to AssetManager, AppStateManager, and you can even get a State directly. The getters getApplication(), getAssetManager(), getState(type) and their methods are available to you immediately. However, you still have to cast SimpleApplication to get rootNode.
+*  You no longer call super during cleanup, its done for you now.
+*  It is now safe to do all initialization and cleanup in the onEnable()/onDisable() methods. Choosing to use initialize() and cleanup() for this is a matter of performance specifics for the implementor.
+*  Cleanup and setEnabled now have logging built in.
+
+You use BaseAppState as you would AbstractAppState, other than mentioned above, and which one you use is entirely up to you. However, BaseAppState makes your life easier and is the recommended one to use now.
+
+
+
 == Pausing and Unpausing
 
 You define what an AppState does when Paused or Unpaused, in the `setEnabled()` and `update()` methods. Call `myState.setEnabled(false)` on all states that you want to pause. Call `myState.setEnabled(true)` on all states that you want to unpause.
@@ -264,23 +325,6 @@ public class MyAppState extends AbstractAppState {
 
 ----
 
-
-
-=== BaseAppState
-
-
-A new link:http://javadoc.jmonkeyengine.org/com/jme3/app/state/BaseAppState.html[BaseAppState] class was introduced as part of the link:https://hub.jmonkeyengine.org/t/jmonkeyengine-3-1-alpha-4-released/35478[updates] being made to the AppState interface. AbstractAppState is the most minimal of the minimal implementations of the AppState interface. You essentially still need to do everything yourself, including getting the funky enable/disable/initialized/terminate logic right. Now you just extend BaseAppState and you get onEnable() and onDisable() already worked out for you.
-
-Notable BaseAppState changes are as follows:
-
-*  You no longer need to call super.initialize(stateManager, app) because it is now called by BaseAppState upon initialization for you.
-*  You no longer have to cast SimpleApplication to have access to AssetManager, AppStateManager, and you can even get a State directly. The getters getApplication(), getAssetManager(), getState(type) and their methods are available to you immediately. However, you still have to cast SimpleApplication to get rootNode.
-*  You no longer call super during cleanup, its done for you now.
-*  It is now safe to do all initialization and cleanup in the onEnable()/onDisable() methods. Choosing to use initialize() and cleanup() for this is a matter of performance specifics for the implementor.
-*  Cleanup and setEnabled now have logging built in.
-
-You use BaseAppState as you would AbstractAppState, other than mentioned above, and which one you use is entirely up to you. However, BaseAppState makes your life easier and is the recommended one to use now.
-
 If you use the jme SDK you can add the following template to make adding BaseAppState to your project easier. 
 
 *  From the SDK select menu:Tools[Templates>JME Classes>New AppState].