Search in sources :

Example 1 with ChunkProvider

use of org.terasology.engine.world.chunks.ChunkProvider in project Terasology by MovingBlocks.

the class StorageManagerTest method testEntitySurvivesStorageInChunkStore.

@Test
public void testEntitySurvivesStorageInChunkStore() throws Exception {
    Chunk chunk = new ChunkImpl(CHUNK_POS, blockManager, extraDataManager);
    chunk.setBlock(0, 0, 0, testBlock);
    chunk.markReady();
    ChunkProvider chunkProvider = mock(ChunkProvider.class);
    when(chunkProvider.getAllChunks()).thenReturn(Arrays.asList(chunk));
    CoreRegistry.put(ChunkProvider.class, chunkProvider);
    EntityRef entity = entityManager.create();
    long id = entity.getId();
    LocationComponent locationComponent = new LocationComponent();
    AABBfc aabb = chunk.getAABB();
    Vector3f positionInChunk = new Vector3f(aabb.minX(), aabb.minY(), aabb.minZ());
    positionInChunk.x += 1;
    positionInChunk.y += 1;
    positionInChunk.z += 1;
    locationComponent.setWorldPosition(positionInChunk);
    entity.addComponent(locationComponent);
    esm.waitForCompletionOfPreviousSaveAndStartSaving();
    esm.finishSavingAndShutdown();
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    EngineEntityManager newEntityManager = context.get(EngineEntityManager.class);
    StorageManager newSM = new ReadWriteStorageManager(savePath, moduleEnvironment, newEntityManager, blockManager, extraDataManager, false, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus);
    newSM.loadGlobalStore();
    ChunkStore restored = newSM.loadChunkStore(CHUNK_POS);
    restored.restoreEntities();
    EntityRef ref = newEntityManager.getEntity(id);
    assertTrue(ref.exists());
    assertTrue(ref.isActive());
}
Also used : AABBfc(org.terasology.joml.geom.AABBfc) EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3f(org.joml.Vector3f) StorageManager(org.terasology.engine.persistence.StorageManager) Chunk(org.terasology.engine.world.chunks.Chunk) ChunkProvider(org.terasology.engine.world.chunks.ChunkProvider) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ChunkStore(org.terasology.engine.persistence.ChunkStore) Test(org.junit.jupiter.api.Test)

Example 2 with ChunkProvider

use of org.terasology.engine.world.chunks.ChunkProvider in project Terasology by MovingBlocks.

the class ReadWriteStorageManager method createSaveTransaction.

private SaveTransaction createSaveTransaction() {
    SaveTransactionBuilder saveTransactionBuilder = new SaveTransactionBuilder(privateEntityManager, entitySetDeltaRecorder, isStoreChunksInZips(), getStoragePathProvider(), worldDirectoryWriteLock, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus);
    ChunkProvider chunkProvider = CoreRegistry.get(ChunkProvider.class);
    NetworkSystem networkSystem = CoreRegistry.get(NetworkSystem.class);
    addChunksToSaveTransaction(saveTransactionBuilder, chunkProvider);
    addPlayersToSaveTransaction(saveTransactionBuilder, networkSystem);
    addGlobalStoreBuilderToSaveTransaction(saveTransactionBuilder);
    addGameManifestToSaveTransaction(saveTransactionBuilder);
    return saveTransactionBuilder.build();
}
Also used : NetworkSystem(org.terasology.engine.network.NetworkSystem) ChunkProvider(org.terasology.engine.world.chunks.ChunkProvider)

Example 3 with ChunkProvider

use of org.terasology.engine.world.chunks.ChunkProvider in project Terasology by MovingBlocks.

the class StorageManagerTest method testChunkSurvivesStorageSaveAndRestore.

@Test
public void testChunkSurvivesStorageSaveAndRestore() throws Exception {
    Chunk chunk = new ChunkImpl(CHUNK_POS, blockManager, extraDataManager);
    chunk.setBlock(0, 0, 0, testBlock);
    chunk.setBlock(0, 4, 2, testBlock2);
    chunk.markReady();
    ChunkProvider chunkProvider = mock(ChunkProvider.class);
    when(chunkProvider.getAllChunks()).thenReturn(Arrays.asList(chunk));
    when(chunkProvider.getChunk(ArgumentMatchers.any(Vector3ic.class))).thenReturn(chunk);
    CoreRegistry.put(ChunkProvider.class, chunkProvider);
    boolean storeChunkInZips = true;
    esm.setStoreChunksInZips(storeChunkInZips);
    esm.waitForCompletionOfPreviousSaveAndStartSaving();
    esm.finishSavingAndShutdown();
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    EngineEntityManager newEntityManager = context.get(EngineEntityManager.class);
    StorageManager newSM = new ReadWriteStorageManager(savePath, moduleEnvironment, newEntityManager, blockManager, extraDataManager, storeChunkInZips, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus);
    newSM.loadGlobalStore();
    ChunkStore restored = newSM.loadChunkStore(CHUNK_POS);
    assertNotNull(restored);
    assertEquals(CHUNK_POS, restored.getChunkPosition());
    assertNotNull(restored.getChunk());
    assertEquals(testBlock, restored.getChunk().getBlock(0, 0, 0));
    assertEquals(testBlock2, restored.getChunk().getBlock(0, 4, 2));
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3ic(org.joml.Vector3ic) StorageManager(org.terasology.engine.persistence.StorageManager) Chunk(org.terasology.engine.world.chunks.Chunk) ChunkProvider(org.terasology.engine.world.chunks.ChunkProvider) ChunkStore(org.terasology.engine.persistence.ChunkStore) Test(org.junit.jupiter.api.Test)

Example 4 with ChunkProvider

use of org.terasology.engine.world.chunks.ChunkProvider in project Terasology by MovingBlocks.

the class StorageManagerTest method testStoreAndRestoreChunkStore.

@Test
public void testStoreAndRestoreChunkStore() {
    Chunk chunk = new ChunkImpl(CHUNK_POS, blockManager, extraDataManager);
    chunk.setBlock(0, 0, 0, testBlock);
    chunk.markReady();
    ChunkProvider chunkProvider = mock(ChunkProvider.class);
    when(chunkProvider.getAllChunks()).thenReturn(Arrays.asList(chunk));
    CoreRegistry.put(ChunkProvider.class, chunkProvider);
    esm.waitForCompletionOfPreviousSaveAndStartSaving();
    esm.finishSavingAndShutdown();
    ChunkStore restored = esm.loadChunkStore(CHUNK_POS);
    assertNotNull(restored);
    assertEquals(CHUNK_POS, restored.getChunkPosition());
    assertNotNull(restored.getChunk());
    assertEquals(testBlock, restored.getChunk().getBlock(0, 0, 0));
}
Also used : ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Chunk(org.terasology.engine.world.chunks.Chunk) ChunkProvider(org.terasology.engine.world.chunks.ChunkProvider) ChunkStore(org.terasology.engine.persistence.ChunkStore) Test(org.junit.jupiter.api.Test)

Example 5 with ChunkProvider

use of org.terasology.engine.world.chunks.ChunkProvider 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

ChunkProvider (org.terasology.engine.world.chunks.ChunkProvider)6 Test (org.junit.jupiter.api.Test)3 ChunkStore (org.terasology.engine.persistence.ChunkStore)3 Chunk (org.terasology.engine.world.chunks.Chunk)3 ChunkImpl (org.terasology.engine.world.chunks.internal.ChunkImpl)3 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)2 StorageManager (org.terasology.engine.persistence.StorageManager)2 Vector3f (org.joml.Vector3f)1 Vector3ic (org.joml.Vector3ic)1 AudioManager (org.terasology.engine.audio.AudioManager)1 EnvironmentSwitchHandler (org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)1 ModuleManager (org.terasology.engine.core.module.ModuleManager)1 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)1 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)1 LocationComponent (org.terasology.engine.logic.location.LocationComponent)1 NetworkSystem (org.terasology.engine.network.NetworkSystem)1 PhysicsEngine (org.terasology.engine.physics.engine.PhysicsEngine)1 BlockFamilyDefinition (org.terasology.engine.world.block.loader.BlockFamilyDefinition)1 Asset (org.terasology.gestalt.assets.Asset)1 AssetType (org.terasology.gestalt.assets.AssetType)1