/** * 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); } } }
private void initStateManager(){ stateManager = new AppStateManager(this); // Always register a ResetStatsState to make sure // that the stats are cleared every frame stateManager.attach(new ResetStatsState()); }
@Override public void simpleUpdate(float tpf) { if (frame % 4 == 0) { System.out.println(++count); bulletAppState = new BulletAppState(); bulletAppState.setThreadingType(ThreadingType.PARALLEL); stateManager.attach(bulletAppState); } else if (frame % 4 == 2) { stateManager.detach(bulletAppState); } frame++; if (count == 70) { System.exit(0); } } }
@Override public void update() { if (prof!=null) prof.appStep(AppStep.BeginFrame); super.update(); // makes sure to execute AppTasks if (speed == 0 || paused) { return; } float tpf = timer.getTimePerFrame() * speed; // update states if (prof!=null) prof.appStep(AppStep.StateManagerUpdate); stateManager.update(tpf); // simple update and root node simpleUpdate(tpf); if (prof!=null) prof.appStep(AppStep.SpatialUpdate); rootNode.updateLogicalState(tpf); guiNode.updateLogicalState(tpf); rootNode.updateGeometricState(); guiNode.updateGeometricState(); // render states if (prof!=null) prof.appStep(AppStep.StateManagerRender); stateManager.render(renderManager); if (prof!=null) prof.appStep(AppStep.RenderFrame); renderManager.render(tpf, context.isRenderable()); simpleRender(renderManager); stateManager.postRender(); if (prof!=null) prof.appStep(AppStep.EndFrame); }
/** * Returns the first state that is an instance of subclass of the specified class. * @param <T> * @param stateClass * @return First attached state that is an instance of stateClass */ public <T extends AppState> T getState(Class<T> stateClass){ return getState(stateClass, false); }
/** * Starts the game, opens up the start menu / level */ private void startGame() { if (params.containsKey("level")) { GameState gameState = new GameState(params.get("level")); stateManager.attach(gameState); } else { // Enable the start menu stateManager.getState(MainMenuState.class).setEnabled(true); } }
/** * Transition this state from terminating to detached. Should be invoked * only by a subclass or by the AppStateManager. Invoked once for each time * {@link #initialize(com.jme3.app.state.AppStateManager, com.jme3.app.Application)} * is invoked. */ public void cleanup() { if (debugAppState != null) { stateManager.detach(debugAppState); debugAppState = null; } stopPhysics(); }
@Override public void update() { simpleApplicationUpdate(); //System.out.println("tpf = " + timer.getTimePerFrame() * speed + " (" + timer.getTimePerFrame() + ", " + speed + ")"); //System.out.println("fps = " + timer.getFrameRate() / speed); if (speed == 0) { timer.update(); final float tpf = timer.getTimePerFrame(); if (inputEnabled) { inputManager.update(tpf); } guiNode.updateLogicalState(tpf); guiNode.updateGeometricState(); // render states stateManager.render(renderManager); renderManager.render(tpf, context.isRenderable()); simpleRender(renderManager); stateManager.postRender(); } }
private void initStateManager(){ stateManager = new AppStateManager(this); }
public void viewInfoMenuClick(int index, Object value, boolean isToggled) { switch (index) { case 0: TimeAppState timeAppState = app.getStateManager().getState(TimeAppState.class); if (timeAppState == null) { timeAppState = new TimeAppState(screen); app.getStateManager().attach(timeAppState); } else { app.getStateManager().detach(timeAppState); } break; } }
/** * Update this state prior to rendering. Should be invoked only by a * subclass or by the AppStateManager. Invoked once per frame, provided the * state is attached and enabled. * * @param tpf the time interval between frames (in seconds, ≥0) */ public void update(float tpf) { if (debugEnabled && debugAppState == null && pSpace != null) { debugAppState = new BulletDebugAppState(pSpace); stateManager.attach(debugAppState); } else if (!debugEnabled && debugAppState != null) { stateManager.detach(debugAppState); debugAppState = null; } if (!active) { return; } pSpace.distributeEvents(); this.tpf = tpf; }
stateManager.update(tpf); stateManager.render(renderManager); stateManager.postRender();
@Override public void initialize(AppStateManager stateManager, Application app) { super.initialize(stateManager, app); this.app = (SimpleApplication) app; phatScreenshotAppState = this.app.getStateManager().getState(PHATScreenshotAppState.class); if (phatScreenshotAppState == null) { phatScreenshotAppState = new PHATScreenshotAppState(); this.app.getStateManager().attach(phatScreenshotAppState); } phatScreenshotAppState.takeScreenshot(); }
private void initStateManager(){ stateManager = new AppStateManager(this); // Always register a ResetStatsState to make sure // that the stats are cleared every frame stateManager.attach(new ResetStatsState()); }
/** * Transition this state from terminating to detached. Should be invoked * only by a subclass or by the AppStateManager. Invoked once for each time * {@link #initialize(com.jme3.app.state.AppStateManager, com.jme3.app.Application)} * is invoked. */ public void cleanup() { if (debugAppState != null) { stateManager.detach(debugAppState); debugAppState = null; } stopPhysics(); }
/** * Create a new VR application and attach the given {@link AppState app states}.<br> * The application scene is made of a {@link #getRootNode() root node} that holds the scene spatials * and a {@link #getGuiNode() GUI node} that is the root of the Graphical user interface. * @param initialStates the {@link AppState app states} to attach to the application. */ public VRApplication(AppState... initialStates) { this(); if (initialStates != null) { for (AppState a : initialStates) { if (a != null) { stateManager.attach(a); } } } }