Search in sources :

Example 6 with StorageManager

use of org.terasology.persistence.StorageManager in project Terasology by MovingBlocks.

the class StorageManagerTest method testChunkSurvivesStorageSaveAndRestore.

@Test
public void testChunkSurvivesStorageSaveAndRestore() throws Exception {
    Chunk chunk = new ChunkImpl(CHUNK_POS, blockManager, biomeManager);
    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(Matchers.any(Vector3i.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, biomeManager, storeChunkInZips);
    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.entitySystem.entity.internal.EngineEntityManager) ChunkImpl(org.terasology.world.chunks.internal.ChunkImpl) Vector3i(org.terasology.math.geom.Vector3i) StorageManager(org.terasology.persistence.StorageManager) Chunk(org.terasology.world.chunks.Chunk) ChunkProvider(org.terasology.world.chunks.ChunkProvider) ChunkStore(org.terasology.persistence.ChunkStore) Test(org.junit.Test)

Example 7 with StorageManager

use of org.terasology.persistence.StorageManager in project Terasology by MovingBlocks.

the class HeadlessEnvironment method close.

@Override
public void close() throws Exception {
    // it would be nice, if elements in the context implemented (Auto)Closeable
    // The StorageManager creates a thread pool (through TaskMaster)
    // which isn't closed automatically
    StorageManager storageManager = context.get(StorageManager.class);
    if (storageManager != null) {
        storageManager.finishSavingAndShutdown();
    }
    super.close();
}
Also used : ReadWriteStorageManager(org.terasology.persistence.internal.ReadWriteStorageManager) StorageManager(org.terasology.persistence.StorageManager)

Aggregations

StorageManager (org.terasology.persistence.StorageManager)7 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)5 Test (org.junit.Test)4 EntityRef (org.terasology.entitySystem.entity.EntityRef)4 IOException (java.io.IOException)2 EntityManager (org.terasology.entitySystem.entity.EntityManager)2 ChunkStore (org.terasology.persistence.ChunkStore)2 ReadWriteStorageManager (org.terasology.persistence.internal.ReadWriteStorageManager)2 Chunk (org.terasology.world.chunks.Chunk)2 ChunkProvider (org.terasology.world.chunks.ChunkProvider)2 ChunkImpl (org.terasology.world.chunks.internal.ChunkImpl)2 Path (java.nio.file.Path)1 ComponentSystemManager (org.terasology.engine.ComponentSystemManager)1 StateMainMenu (org.terasology.engine.modes.StateMainMenu)1 ModuleManager (org.terasology.engine.module.ModuleManager)1 RenderingSubsystemFactory (org.terasology.engine.subsystem.RenderingSubsystemFactory)1 EntityRefComponent (org.terasology.entitySystem.stubs.EntityRefComponent)1 StringComponent (org.terasology.entitySystem.stubs.StringComponent)1 LocationComponent (org.terasology.logic.location.LocationComponent)1 LocalPlayer (org.terasology.logic.players.LocalPlayer)1