- improve FakeApplication handling

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10111 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
nor..67 12 years ago
parent 220490bee7
commit d127a7389e
  1. 68
      sdk/jme3-core/src/com/jme3/gde/core/scene/FakeApplication.java
  2. 21
      sdk/jme3-core/src/com/jme3/gde/core/scene/SceneApplication.java

@ -41,6 +41,8 @@ import com.jme3.audio.Listener;
import com.jme3.gde.core.appstates.AppStateManagerNode;
import com.jme3.input.FlyByCamera;
import com.jme3.input.InputManager;
import com.jme3.light.Light;
import com.jme3.light.LightList;
import com.jme3.renderer.Camera;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.Renderer;
@ -58,6 +60,7 @@ import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
@ -360,6 +363,7 @@ public class FakeApplication extends SimpleApplication {
return states;
}
//TODO: make thread safe
@Override
public boolean attach(AppState state) {
boolean ret = super.attach(state);
@ -393,9 +397,22 @@ public class FakeApplication extends SimpleApplication {
*/
private ScheduledThreadPoolExecutor fakeAppThread = new ScheduledThreadPoolExecutor(1);
public void removeCurrentStates() {
for (Iterator<AppState> it = new ArrayList(appStateManager.getAddedStates()).iterator(); it.hasNext();) {
AppState appState = it.next();
try {
appStateManager.detach(appState);
} catch (Exception e) {
Exceptions.printStackTrace(e);
}
}
}
public void cleanupFakeApp() {
runQueuedFake();
appStateManager = new FakeAppStateManager(this);
if (guiNode != null) {
clearNode(guiNode);
}
if (rootNode != null) {
clearNode(rootNode);
}
@ -445,13 +462,6 @@ public class FakeApplication extends SimpleApplication {
NotifyDescriptor.WARNING_MESSAGE));
}
private void removeAllStates() {
for (Iterator<AppState> it = new ArrayList(appStateManager.getAddedStates()).iterator(); it.hasNext();) {
AppState appState = it.next();
appStateManager.detach(appState);
}
}
public boolean runQueuedFake() {
Future fut = fakeAppThread.submit(new Callable<Void>() {
public Void call() throws Exception {
@ -587,6 +597,30 @@ public class FakeApplication extends SimpleApplication {
return clazz;
}
private void removeAllStates() {
try {
try {
for (Iterator<AppState> it = new ArrayList(appStateManager.getAddedStates()).iterator(); it.hasNext();) {
AppState appState = it.next();
appStateManager.detach(appState);
}
} catch (Exception e) {
Exceptions.printStackTrace(e);
}
AppState state = appStateManager.getState(AppState.class);
while (state != null) {
try {
appStateManager.update(0);
} catch (Exception e) {
Exceptions.printStackTrace(e);
}
state = appStateManager.getState(AppState.class);
}
} catch (Exception e) {
Exceptions.printStackTrace(e);
}
}
private void clearNode(final Node externalNode) {
while (!externalNode.getChildren().isEmpty()) {
try {
@ -615,5 +649,23 @@ public class FakeApplication extends SimpleApplication {
externalNode.setUserData(string, null);
}
}
LightList llist = null;
try {
llist = externalNode.getLocalLightList();
for (Iterator<Light> it = llist.iterator(); it.hasNext();) {
Light light = it.next();
try {
externalNode.removeLight(light);
} catch (Exception e) {
Exceptions.printStackTrace(e);
} catch (Error e) {
Exceptions.printStackTrace(e);
}
}
} catch (Exception e) {
Exceptions.printStackTrace(e);
} catch (Error e) {
Exceptions.printStackTrace(e);
}
}
}

@ -35,6 +35,7 @@ import com.jme3.gde.core.assets.AssetData;
import com.jme3.gde.core.assets.AssetDataObject;
import com.jme3.gde.core.scene.controller.AbstractCameraController;
import com.jme3.gde.core.scene.processors.WireProcessor;
import com.jme3.gde.core.sceneexplorer.nodes.NodeUtility;
import com.jme3.gde.core.sceneviewer.SceneViewerTopComponent;
import com.jme3.gde.core.undoredo.SceneUndoRedoManager;
import com.jme3.input.FlyByCamera;
@ -381,11 +382,15 @@ public class SceneApplication extends Application implements LookupProvider {
return;
}
currentSceneRequest = request;
if (request.getDataObject() != null) {
setCurrentFileNode(request.getDataObject().getNodeDelegate());
if (request.getDataNode() != null) {
setCurrentFileNode(request.getDataNode());
} else {
setCurrentFileNode(null);
}
//TODO: handle this differently (no opened file)
if (request.getRootNode() == null && request.getJmeNode() == null) {
request.setJmeNode(NodeUtility.createNode(rootNode, false));
}
setHelpContext(request.getHelpCtx());
setWindowTitle(request.getWindowTitle());
if (request.getRequester() instanceof SceneApplication) {
@ -395,19 +400,17 @@ public class SceneApplication extends Application implements LookupProvider {
}
final AssetManager manager = request.getManager();
request.setFakeApp(fakeApp);
fakeApp.newAssetManager(manager);
enqueue(new Callable() {
public Object call() throws Exception {
if (manager != null) {
assetManager = manager;
fakeApp.newAssetManager(manager);
}
Spatial model = request.getRootNode();
if (model == null) {
StatusDisplayer.getDefault().setStatusText("could not load Spatial from request: " + getCurrentSceneRequest().getWindowTitle());
return null;
//TODO: use FakeApp internal root node, don't handle model vs clean scene here
if (model != null && model != rootNode) {
rootNode.attachChild(model);
}
//TODO: use FakeApp internal root node
rootNode.attachChild(model);
if (request.getToolNode() != null) {
toolsNode.attachChild(request.getToolNode());
}
@ -451,6 +454,8 @@ public class SceneApplication extends Application implements LookupProvider {
if (oldRequest.getRequester() instanceof SceneApplication) {
camController.disable();
}
//TODO: state list is not thread safe..
fakeApp.removeCurrentStates();
enqueue(new Callable() {
public Object call() throws Exception {
if (physicsState != null) {

Loading…
Cancel
Save