Search in sources :

Example 1 with Asset

use of org.terasology.gestalt.assets.Asset in project Terasology by MovingBlocks.

the class AssetTypeHandlerFactoryTest method testCreate.

@Test
public void testCreate() {
    TypeHandlerFactory factory = new AssetTypeHandlerFactory();
    List<TypeInfo<? extends Asset>> typesToTest = Lists.newArrayList(TypeInfo.of(Texture.class), TypeInfo.of(UIElement.class), TypeInfo.of(StaticSound.class), TypeInfo.of(StreamingSound.class));
    for (TypeInfo<? extends Asset> typeInfo : typesToTest) {
        Optional<? extends TypeHandler<? extends Asset>> typeHandler = factory.create(typeInfo, null);
        assertTrue(typeHandler.isPresent());
        assertTrue(typeHandler.get() instanceof AssetTypeHandler);
    }
}
Also used : UIElement(org.terasology.nui.asset.UIElement) StaticSound(org.terasology.engine.audio.StaticSound) AssetTypeHandler(org.terasology.engine.persistence.typeHandling.extensionTypes.AssetTypeHandler) Asset(org.terasology.gestalt.assets.Asset) TypeHandlerFactory(org.terasology.persistence.typeHandling.TypeHandlerFactory) StreamingSound(org.terasology.engine.audio.StreamingSound) TypeInfo(org.terasology.reflection.TypeInfo) Texture(org.terasology.engine.rendering.assets.texture.Texture) Test(org.junit.jupiter.api.Test)

Example 2 with Asset

use of org.terasology.gestalt.assets.Asset 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();
    }
}
Also used : PhysicsEngine(org.terasology.engine.physics.engine.PhysicsEngine) ModuleManager(org.terasology.engine.core.module.ModuleManager) AudioManager(org.terasology.engine.audio.AudioManager) AssetType(org.terasology.gestalt.assets.AssetType) ModuleAwareAssetTypeManager(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager) AssetTypeManager(org.terasology.gestalt.assets.management.AssetTypeManager) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) Asset(org.terasology.gestalt.assets.Asset) ChunkProvider(org.terasology.engine.world.chunks.ChunkProvider) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) BlockFamilyDefinition(org.terasology.engine.world.block.loader.BlockFamilyDefinition) Prefab(org.terasology.engine.entitySystem.prefab.Prefab) EnvironmentSwitchHandler(org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)

Aggregations

Asset (org.terasology.gestalt.assets.Asset)2 Test (org.junit.jupiter.api.Test)1 AudioManager (org.terasology.engine.audio.AudioManager)1 StaticSound (org.terasology.engine.audio.StaticSound)1 StreamingSound (org.terasology.engine.audio.StreamingSound)1 EnvironmentSwitchHandler (org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)1 ModuleManager (org.terasology.engine.core.module.ModuleManager)1 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)1 AssetTypeHandler (org.terasology.engine.persistence.typeHandling.extensionTypes.AssetTypeHandler)1 PhysicsEngine (org.terasology.engine.physics.engine.PhysicsEngine)1 Texture (org.terasology.engine.rendering.assets.texture.Texture)1 BlockFamilyDefinition (org.terasology.engine.world.block.loader.BlockFamilyDefinition)1 ChunkProvider (org.terasology.engine.world.chunks.ChunkProvider)1 AssetType (org.terasology.gestalt.assets.AssetType)1 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)1 AssetTypeManager (org.terasology.gestalt.assets.management.AssetTypeManager)1 ModuleAwareAssetTypeManager (org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager)1 ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)1 UIElement (org.terasology.nui.asset.UIElement)1 TypeHandlerFactory (org.terasology.persistence.typeHandling.TypeHandlerFactory)1