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