Ver código fonte

Added some methods for bulk-attaching a bunch
of app states at once. This is useful when
attaching several app states from a different
thread because there is a guarantee that they
all get initialized together before any of their
update() methods are called.


git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10504 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

PSp..om 12 anos atrás
pai
commit
a62a2d0299

+ 26 - 0
engine/src/core/com/jme3/app/state/AppStateManager.java

@@ -139,6 +139,32 @@ public class AppStateManager {
         }
     }
 
+    /**
+     * Attaches many state to the AppStateManager in a way that is guaranteed
+     * that they will all get initialized before any of their updates are run.
+     * The same state cannot be attached twice and will be ignored.
+     *
+     * @param states The states to attach
+     */
+    public void attachAll(AppState... states){
+        attachAll(Arrays.asList(states));
+    }
+
+    /**
+     * Attaches many state to the AppStateManager in a way that is guaranteed
+     * that they will all get initialized before any of their updates are run.
+     * The same state cannot be attached twice and will be ignored.
+     *
+     * @param states The states to attach
+     */
+    public void attachAll(Iterable<AppState> states){
+        synchronized (this.states){
+            for( AppState state : states ) {
+                attach(state);
+            }
+        }
+    }
+
     /**
      * Detaches the state from the AppStateManager. 
      *