- Improvements to FakeApp lifecycle and cleanup
- Use main rootNode for FakeApp
- Improve "Run AppState" integration slightly

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10099 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
nor..67 12 years ago
parent 75852531af
commit 92a96b64d7
  1. 19
      sdk/jme3-core/src/com/jme3/gde/core/appstates/AppStateExplorerTopComponent.java
  2. 3
      sdk/jme3-core/src/com/jme3/gde/core/appstates/RunAppStateAction.java
  3. 26
      sdk/jme3-core/src/com/jme3/gde/core/scene/FakeApplication.java
  4. 50
      sdk/jme3-core/src/com/jme3/gde/core/scene/SceneApplication.java

@ -31,14 +31,14 @@
*/ */
package com.jme3.gde.core.appstates; package com.jme3.gde.core.appstates;
import com.jme3.asset.AssetManager;
import com.jme3.gde.core.assets.ProjectAssetManager; import com.jme3.gde.core.assets.ProjectAssetManager;
import com.jme3.gde.core.scene.FakeApplication;
import com.jme3.gde.core.scene.PreviewRequest; import com.jme3.gde.core.scene.PreviewRequest;
import com.jme3.gde.core.scene.SceneApplication; import com.jme3.gde.core.scene.SceneApplication;
import com.jme3.gde.core.scene.SceneListener; import com.jme3.gde.core.scene.SceneListener;
import com.jme3.gde.core.scene.SceneRequest; import com.jme3.gde.core.scene.SceneRequest;
import com.jme3.renderer.Camera;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import java.util.Iterator;
import javax.swing.ActionMap; import javax.swing.ActionMap;
import org.netbeans.api.settings.ConvertAsProperties; import org.netbeans.api.settings.ConvertAsProperties;
import org.openide.awt.ActionID; import org.openide.awt.ActionID;
@ -85,7 +85,8 @@ public final class AppStateExplorerTopComponent extends TopComponent implements
return; return;
} }
mgr = request.getManager(); mgr = request.getManager();
final AppStateManagerNode nod = new AppStateManagerNode(request.getFakeApp().getStateManager()); FakeApplication app = request.getFakeApp();
final AppStateManagerNode nod = new AppStateManagerNode(app.getStateManager());
jButton1.setEnabled(true); jButton1.setEnabled(true);
explorerManager.setRootContext(nod); explorerManager.setRootContext(nod);
setActivatedNodes(new Node[]{nod}); setActivatedNodes(new Node[]{nod});
@ -93,7 +94,6 @@ public final class AppStateExplorerTopComponent extends TopComponent implements
public void sceneClosed(SceneRequest request) { public void sceneClosed(SceneRequest request) {
currentRequest = null; currentRequest = null;
SceneApplication.getApplication().setFakeApp(null);
mgr = null; mgr = null;
jButton1.setEnabled(false); jButton1.setEnabled(false);
explorerManager.setRootContext(Node.EMPTY); explorerManager.setRootContext(Node.EMPTY);
@ -121,6 +121,17 @@ public final class AppStateExplorerTopComponent extends TopComponent implements
SceneApplication.getApplication().addSceneListener(listener); SceneApplication.getApplication().addSceneListener(listener);
} }
public static void openExplorer() {
for (Iterator<TopComponent> it = TopComponent.getRegistry().getOpened().iterator(); it.hasNext();) {
TopComponent topComponent = it.next();
if (topComponent instanceof AppStateExplorerTopComponent) {
AppStateExplorerTopComponent explorer = (AppStateExplorerTopComponent) topComponent;
explorer.requestVisible();
return;
}
}
}
/** /**
* This method is called from within the constructor to initialize the form. * This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always * WARNING: Do NOT modify this code. The content of this method is always

@ -126,6 +126,7 @@ public class RunAppStateAction implements ContextAwareAction {
try { try {
AppState state = (AppState) app.getClassByName(className).newInstance(); AppState state = (AppState) app.getClassByName(className).newInstance();
app.getStateManager().attach(state); app.getStateManager().attach(state);
AppStateExplorerTopComponent.openExplorer();
} catch (InstantiationException ex) { } catch (InstantiationException ex) {
DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message("Error creating AppState, make sure it has an empty constructor!\n" + ex.getMessage())); DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message("Error creating AppState, make sure it has an empty constructor!\n" + ex.getMessage()));
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);
@ -142,7 +143,7 @@ public class RunAppStateAction implements ContextAwareAction {
} }
} }
public void checkData(Lookup actionContext, final String name) { private void checkData(Lookup actionContext, final String name) {
source = null; source = null;
className = null; className = null;
try { try {

@ -46,6 +46,7 @@ import com.jme3.renderer.RenderManager;
import com.jme3.renderer.Renderer; import com.jme3.renderer.Renderer;
import com.jme3.renderer.ViewPort; import com.jme3.renderer.ViewPort;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import com.jme3.scene.UserData;
import com.jme3.scene.control.Control; import com.jme3.scene.control.Control;
import com.jme3.system.AppSettings; import com.jme3.system.AppSettings;
import com.jme3.system.JmeContext; import com.jme3.system.JmeContext;
@ -56,6 +57,7 @@ import java.io.ByteArrayOutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
@ -392,14 +394,27 @@ public class FakeApplication extends SimpleApplication {
*/ */
private ScheduledThreadPoolExecutor fakeAppThread = new ScheduledThreadPoolExecutor(1); private ScheduledThreadPoolExecutor fakeAppThread = new ScheduledThreadPoolExecutor(1);
public void setRootNode(Node rootNode) { public void cleanupFakeApp() {
this.rootNode = rootNode; if (rootNode == null) {
return;
}
clearNode(rootNode);
appStateManager = new FakeAppStateManager(this);
}
public void startFakeApp(){
fakeAppThread = new ScheduledThreadPoolExecutor(1);
} }
public void stopFakeApp() { public void stopFakeApp() {
cleanupFakeApp();
fakeAppThread.shutdown(); fakeAppThread.shutdown();
} }
public void newAssetManager(AssetManager manager){
this.assetManager = manager;
}
private void defaultFakeError() { private void defaultFakeError() {
defaultFakeError(false); defaultFakeError(false);
} }
@ -594,5 +609,12 @@ public class FakeApplication extends SimpleApplication {
} }
control = externalNode.getControl(Control.class); control = externalNode.getControl(Control.class);
} }
Collection<String> keys = externalNode.getUserDataKeys();
if (keys != null) {
for (Iterator<String> it = keys.iterator(); it.hasNext();) {
String string = it.next();
externalNode.setUserData(string, null);
}
}
} }
} }

@ -26,6 +26,7 @@ package com.jme3.gde.core.scene;
import com.jme3.app.Application; import com.jme3.app.Application;
import com.jme3.app.StatsView; import com.jme3.app.StatsView;
import com.jme3.asset.AssetManager;
import com.jme3.bullet.BulletAppState; import com.jme3.bullet.BulletAppState;
import com.jme3.font.BitmapFont; import com.jme3.font.BitmapFont;
import com.jme3.font.BitmapText; import com.jme3.font.BitmapText;
@ -91,7 +92,13 @@ public class SceneApplication extends Application implements LookupProvider {
} }
return application; return application;
} }
protected Node rootNode = new Node("Root Node"); protected Node rootNode = new Node("Root Node") {
@Override
public boolean removeFromParent() {
DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message("Trying to remove main RootNode!"));
return false;
}
};
protected Node guiNode = new Node("Gui Node"); protected Node guiNode = new Node("Gui Node");
private Node statsGuiNode = new Node("Stats Gui Node"); private Node statsGuiNode = new Node("Stats Gui Node");
protected Node toolsNode = new Node("Tools Node"); protected Node toolsNode = new Node("Tools Node");
@ -141,6 +148,7 @@ public class SceneApplication extends Application implements LookupProvider {
createCanvas(); createCanvas();
startCanvas(true); startCanvas(true);
} }
fakeApp = new FakeApplication(rootNode, guiNode, assetManager, cam);
nodeSync = new NodeSyncAppState(); nodeSync = new NodeSyncAppState();
stateManager.attach(nodeSync); stateManager.attach(nodeSync);
progressHandle.progress("initialize Base Application", 1); progressHandle.progress("initialize Base Application", 1);
@ -205,6 +213,7 @@ public class SceneApplication extends Application implements LookupProvider {
@Override @Override
public void initialize() { public void initialize() {
thread = Thread.currentThread(); thread = Thread.currentThread();
fakeApp.startFakeApp();
try { try {
super.initialize(); super.initialize();
{ {
@ -261,6 +270,12 @@ public class SceneApplication extends Application implements LookupProvider {
} }
} }
@Override
public void destroy() {
fakeApp.stopFakeApp();
super.destroy();
}
@Override @Override
public void update() { public void update() {
if (speed == 0) { if (speed == 0) {
@ -310,6 +325,8 @@ public class SceneApplication extends Application implements LookupProvider {
} }
} }
//TODO: Lookup for Application //TODO: Lookup for Application
public Lookup createAdditionalLookup(Lookup baseContext) { public Lookup createAdditionalLookup(Lookup baseContext) {
return Lookups.fixed(getApplication()); return Lookups.fixed(getApplication());
@ -378,26 +395,20 @@ public class SceneApplication extends Application implements LookupProvider {
} else { } else {
camController.disable(); camController.disable();
} }
//TODO: reuse fakeapp final AssetManager manager = request.getManager();
fakeApp = new FakeApplication(rootNode, guiNode, request.getManager(), cam);
request.setFakeApp(fakeApp); request.setFakeApp(fakeApp);
enqueue(new Callable() { enqueue(new Callable() {
public Object call() throws Exception { public Object call() throws Exception {
if (request.getManager() != null) { if (manager != null) {
assetManager = request.getManager(); assetManager = manager;
fakeApp.newAssetManager(manager);
} }
Spatial model = request.getRootNode(); Spatial model = request.getRootNode();
if (model == null) { if (model == null) {
StatusDisplayer.getDefault().setStatusText("could not load Spatial from request: " + getCurrentSceneRequest().getWindowTitle()); StatusDisplayer.getDefault().setStatusText("could not load Spatial from request: " + getCurrentSceneRequest().getWindowTitle());
return null; return null;
} }
//TODO: bit dangerous, setting rootNode late //TODO: use FakeApp internal root node
// still it should only be accessed from the
// update loop and be set until then.
if (model instanceof Node) {
fakeApp.setRootNode((Node) model);
}
rootNode.attachChild(model); rootNode.attachChild(model);
if (request.getToolNode() != null) { if (request.getToolNode() != null) {
toolsNode.attachChild(request.getToolNode()); toolsNode.attachChild(request.getToolNode());
@ -442,10 +453,6 @@ public class SceneApplication extends Application implements LookupProvider {
if (oldRequest.getRequester() instanceof SceneApplication) { if (oldRequest.getRequester() instanceof SceneApplication) {
camController.disable(); camController.disable();
} }
if (fakeApp != null) {
fakeApp.stopFakeApp();
}
fakeApp = null;
enqueue(new Callable() { enqueue(new Callable() {
public Object call() throws Exception { public Object call() throws Exception {
if (physicsState != null) { if (physicsState != null) {
@ -453,6 +460,10 @@ public class SceneApplication extends Application implements LookupProvider {
getStateManager().detach(physicsState); getStateManager().detach(physicsState);
physicsState = null; physicsState = null;
} }
//TODO: possibly dangerous (new var is created in EDT
if (fakeApp != null) {
fakeApp.cleanupFakeApp();
}
toolsNode.detachAllChildren(); toolsNode.detachAllChildren();
rootNode.detachAllChildren(); rootNode.detachAllChildren();
// resetCam(); // resetCam();
@ -645,11 +656,4 @@ public class SceneApplication extends Application implements LookupProvider {
return java.awt.EventQueue.isDispatchThread(); return java.awt.EventQueue.isDispatchThread();
} }
public FakeApplication getFakeApp() {
return fakeApp;
}
public void setFakeApp(FakeApplication fakeApp) {
this.fakeApp = fakeApp;
}
} }

Loading…
Cancel
Save