use of org.terasology.gestalt.assets.management.AssetTypeManager in project Terasology by MovingBlocks.
the class StateIngame method dispose.
@Override
public void dispose(boolean shuttingDown) {
ChunkProvider chunkProvider = context.get(ChunkProvider.class);
chunkProvider.dispose();
AssetTypeManager assetTypeManager = context.get(ModuleAwareAssetTypeManager.class);
// dispose all module assets
assetTypeManager.getAssetTypes().forEach(assetType -> {
for (ResourceUrn urn : assetType.getLoadedAssetUrns()) {
if (!urn.getModuleName().equals(TerasologyConstants.ENGINE_MODULE)) {
assetType.getAsset(urn).ifPresent(Asset::dispose);
}
}
});
// dispose engine assets that should not be kept when switching game states
assetTypeManager.getAssetType(BlockFamilyDefinition.class).ifPresent(AssetType::disposeAll);
assetTypeManager.getAssetType(Prefab.class).ifPresent(AssetType::disposeAll);
boolean save = networkSystem.getMode().isAuthority();
if (save && storageManager != null) {
storageManager.waitForCompletionOfPreviousSaveAndStartSaving();
}
networkSystem.shutdown();
// TODO: Shutdown background threads
eventSystem.process();
GameThread.processWaitingProcesses();
if (nuiManager != null) {
nuiManager.clear();
}
context.get(AudioManager.class).stopAllSounds();
if (worldRenderer != null) {
worldRenderer.dispose();
worldRenderer = null;
}
componentSystemManager.shutdown();
context.get(PhysicsEngine.class).dispose();
entityManager.clear();
if (storageManager != null) {
storageManager.finishSavingAndShutdown();
}
ModuleEnvironment oldEnvironment = context.get(ModuleManager.class).getEnvironment();
context.get(ModuleManager.class).loadEnvironment(Collections.<Module>emptySet(), true);
if (!shuttingDown) {
context.get(EnvironmentSwitchHandler.class).handleSwitchToEmptyEnvironment(context);
}
if (oldEnvironment != null) {
oldEnvironment.close();
}
console.dispose();
GameThread.clearWaitingProcesses();
if (nuiManager != null) {
/*
* Clear the binding as otherwise the complete ingame state would be
* referenced.
*/
nuiManager.getHUD().clearVisibleBinding();
}
}
Aggregations