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());
}
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();
}
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;
}
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());
}
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));
}
Aggregations