Search in sources :

Example 1 with ChunkStore

use of org.terasology.engine.persistence.ChunkStore 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 ChunkStore

use of org.terasology.engine.persistence.ChunkStore in project Terasology by MovingBlocks.

the class AbstractStorageManager method loadChunkStore.

@Override
public ChunkStore loadChunkStore(Vector3ic chunkPos) {
    byte[] chunkData = loadCompressedChunk(chunkPos);
    ChunkStore store = null;
    if (chunkData != null) {
        ByteArrayInputStream bais = new ByteArrayInputStream(chunkData);
        try (GZIPInputStream gzipIn = new GZIPInputStream(bais)) {
            EntityData.ChunkStore storeData = EntityData.ChunkStore.parseFrom(gzipIn);
            store = new ChunkStoreInternal(storeData, entityManager, blockManager, extraDataManager);
        } catch (IOException e) {
            logger.error("Failed to read existing saved chunk {}", chunkPos);
        }
    }
    return store;
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) EntityData(org.terasology.protobuf.EntityData) IOException(java.io.IOException) ChunkStore(org.terasology.engine.persistence.ChunkStore)

Example 3 with ChunkStore

use of org.terasology.engine.persistence.ChunkStore in project Terasology by MovingBlocks.

the class LocalChunkProvider method createOrLoadChunk.

protected ListenableFuture<Chunk> createOrLoadChunk(Vector3ic chunkPos) {
    Vector3i pos = new Vector3i(chunkPos);
    return loadingPipeline.invokeGeneratorTask(pos, () -> {
        ChunkStore chunkStore = storageManager.loadChunkStore(pos);
        Chunk chunk;
        EntityBufferImpl buffer = new EntityBufferImpl();
        if (chunkStore == null) {
            chunk = new ChunkImpl(pos, blockManager, extraDataManager);
            generator.createChunk(chunk, buffer);
            generateQueuedEntities.put(chunk.getPosition(new Vector3i()), buffer.getAll());
        } else {
            chunk = chunkStore.getChunk();
        }
        return chunk;
    });
}
Also used : ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3i(org.joml.Vector3i) EntityBufferImpl(org.terasology.engine.world.generation.impl.EntityBufferImpl) Chunk(org.terasology.engine.world.chunks.Chunk) ChunkStore(org.terasology.engine.persistence.ChunkStore)

Example 4 with ChunkStore

use of org.terasology.engine.persistence.ChunkStore 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 5 with ChunkStore

use of org.terasology.engine.persistence.ChunkStore 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)

Aggregations

ChunkStore (org.terasology.engine.persistence.ChunkStore)6 Chunk (org.terasology.engine.world.chunks.Chunk)4 ChunkImpl (org.terasology.engine.world.chunks.internal.ChunkImpl)4 Test (org.junit.jupiter.api.Test)3 ChunkProvider (org.terasology.engine.world.chunks.ChunkProvider)3 Vector3i (org.joml.Vector3i)2 Vector3ic (org.joml.Vector3ic)2 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)2 StorageManager (org.terasology.engine.persistence.StorageManager)2 TIntList (gnu.trove.list.TIntList)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 Vector3f (org.joml.Vector3f)1 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)1 LocationComponent (org.terasology.engine.logic.location.LocationComponent)1 OnActivatedBlocks (org.terasology.engine.world.block.OnActivatedBlocks)1 OnAddedBlocks (org.terasology.engine.world.block.OnAddedBlocks)1 OnChunkGenerated (org.terasology.engine.world.chunks.event.OnChunkGenerated)1 OnChunkLoaded (org.terasology.engine.world.chunks.event.OnChunkLoaded)1