private void cleanup() { logger.info("Shutting down Terasology..."); changeStatus(StandardGameStatus.SHUTTING_DOWN); if (currentState != null) { currentState.dispose(); currentState = null; } Iterator<EngineSubsystem> preshutdownIter = allSubsystems.descendingIterator(); while (preshutdownIter.hasNext()) { EngineSubsystem subsystem = preshutdownIter.next(); try { subsystem.preShutdown(); } catch (RuntimeException e) { logger.error("Error preparing to shutdown {} subsystem", subsystem.getName(), e); } } Iterator<EngineSubsystem> shutdownIter = allSubsystems.descendingIterator(); while (shutdownIter.hasNext()) { EngineSubsystem subsystem = shutdownIter.next(); try { subsystem.shutdown(); } catch (RuntimeException e) { logger.error("Error shutting down {} subsystem", subsystem.getName(), e); } } }
private void switchState(GameState newState) { if (currentState != null) { currentState.dispose(); } currentState = newState; LoggingContext.setGameState(newState); newState.init(this); for (StateChangeSubscriber subscriber : stateChangeSubscribers) { subscriber.onStateChange(); } // drain input queues InputSystem inputSystem = rootContext.get(InputSystem.class); inputSystem.getMouseDevice().getInputQueue(); inputSystem.getKeyboard().getInputQueue(); }
private void cleanup() { logger.info("Shutting down Terasology..."); try { Iterator<EngineSubsystem> iter = subsystems.descendingIterator(); while (iter.hasNext()) { EngineSubsystem subsystem = iter.next(); subsystem.shutdown(config); } config.save(); if (currentState != null) { currentState.dispose(); currentState = null; } } finally { // Even if a graceful shutdown of the subsystems fails, // the thread pool has to be shut down stopThreads(); } }