Search in sources :

Example 1 with StorageManager

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

use of org.terasology.engine.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 : StorageManager(org.terasology.engine.persistence.StorageManager) ReadWriteStorageManager(org.terasology.engine.persistence.internal.ReadWriteStorageManager)

Example 3 with StorageManager

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

the class LoadEntities method step.

@Override
public boolean step() {
    EntityManager em = context.get(EntityManager.class);
    boolean entityCreated = false;
    for (EntityRef entity : em.getAllEntities()) {
        entityCreated = true;
        logger.error("Entity created before load: {}", entity.toFullDescription());
    }
    if (entityCreated) {
        throw new IllegalStateException("Entity creation detected during component system initialisation, game load aborting");
    }
    StorageManager storageManager = context.get(StorageManager.class);
    try {
        storageManager.loadGlobalStore();
    } catch (IOException e) {
        logger.error("Failed to load global data.", e);
    }
    return true;
}
Also used : EntityManager(org.terasology.engine.entitySystem.entity.EntityManager) StorageManager(org.terasology.engine.persistence.StorageManager) IOException(java.io.IOException) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Example 4 with StorageManager

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

the class StorageManagerTest method testGlobalEntitiesStoredAndRestored.

@Test
public void testGlobalEntitiesStoredAndRestored() throws Exception {
    EntityRef entity = entityManager.create(new StringComponent("Test"));
    long entityId = entity.getId();
    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();
    List<EntityRef> entities = Lists.newArrayList(newEntityManager.getEntitiesWith(StringComponent.class));
    assertEquals(1, entities.size());
    assertEquals(entityId, entities.get(0).getId());
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) StringComponent(org.terasology.unittest.stubs.StringComponent) StorageManager(org.terasology.engine.persistence.StorageManager) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 5 with StorageManager

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

Aggregations

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