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 initSubsystems() { changeStatus(TerasologyEngineStatus.INITIALIZING_SUBSYSTEMS); for (EngineSubsystem subsystem : getSubsystems()) { changeStatus(() -> "Initialising " + subsystem.getName() + " subsystem"); subsystem.initialise(this, rootContext); } }
/** Gives a chance to subsystems to do something BEFORE managers and Time are initialized. */ private void preInitSubsystems() { changeStatus(TerasologyEngineStatus.PREPARING_SUBSYSTEMS); for (EngineSubsystem subsystem : getSubsystems()) { changeStatus(() -> "Pre-initialising " + subsystem.getName() + " subsystem"); subsystem.preInitialise(rootContext); } }
/** * The main loop runs until the EngineState is set back to INITIALIZED by shutdown() or until the * OS requests the application's window to be closed. Engine cleanup and disposal occur * afterwards. */ private void mainLoop() { PerformanceMonitor.startActivity("Other"); // MAIN GAME LOOP while (!shutdownRequested) { assetTypeManager.reloadChangedOnDisk(); processPendingState(); if (currentState == null) { shutdown(); break; } Iterator<Float> updateCycles = timeSubsystem.getEngineTime().tick(); for (EngineSubsystem subsystem : allSubsystems) { try (Activity ignored = PerformanceMonitor.startActivity(subsystem.getName() + " PreUpdate")) { subsystem.preUpdate(currentState, timeSubsystem.getEngineTime().getRealDelta()); } } while (updateCycles.hasNext()) { float updateDelta = updateCycles.next(); // gameTime gets updated here! try (Activity ignored = PerformanceMonitor.startActivity("Main Update")) { currentState.update(updateDelta); } } // Waiting processes are set by modules via GameThread.a/synch() methods. GameThread.processWaitingProcesses(); for (EngineSubsystem subsystem : getSubsystems()) { try (Activity ignored = PerformanceMonitor.startActivity(subsystem.getName() + " Subsystem postUpdate")) { subsystem.postUpdate(currentState, timeSubsystem.getEngineTime().getRealDelta()); } } assetTypeManager.disposedUnusedAssets(); PerformanceMonitor.rollCycle(); PerformanceMonitor.startActivity("Other"); } PerformanceMonitor.endActivity(); }