use of org.terasology.engine.world.chunks.internal.ChunkImpl in project Terasology by MovingBlocks.
the class ChunkTest method setup.
@BeforeEach
public void setup() throws Exception {
super.setup();
AssetManager assetManager = CoreRegistry.get(AssetManager.class);
blockManager = new BlockManagerImpl(new NullWorldAtlas(), assetManager);
CoreRegistry.put(BlockManager.class, blockManager);
ExtraBlockDataManager extraDataManager = new ExtraBlockDataManager();
chunk = new ChunkImpl(new Vector3i(0, 0, 0), blockManager, extraDataManager);
BlockFamilyDefinitionData solidData = new BlockFamilyDefinitionData();
solidData.getBaseSection().setDisplayName("Stone");
solidData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
solidData.getBaseSection().setTranslucent(false);
solidData.setBlockFamily(SymmetricFamily.class);
assetManager.loadAsset(new ResourceUrn("engine:stone"), solidData, BlockFamilyDefinition.class);
solid = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:stone")));
}
use of org.terasology.engine.world.chunks.internal.ChunkImpl in project Terasology by MovingBlocks.
the class SaveTransaction method prepareCompressedChunkBuilders.
/**
* @param unsavedEntities currently loaded persistent entities without owner that have not been saved yet.
* This method removes entities it saves.
*/
private void prepareCompressedChunkBuilders(Set<EntityRef> unsavedEntities) {
Map<Vector3i, Collection<EntityRef>> chunkPosToEntitiesMap = createChunkPosToUnsavedOwnerLessEntitiesMap();
allChunks = Maps.newHashMap();
allChunks.putAll(unloadedChunks);
for (Map.Entry<Vector3i, ChunkImpl> chunkEntry : loadedChunks.entrySet()) {
Collection<EntityRef> entitiesToStore = chunkPosToEntitiesMap.get(chunkEntry.getKey());
if (entitiesToStore == null) {
entitiesToStore = Collections.emptySet();
}
ChunkImpl chunk = chunkEntry.getValue();
unsavedEntities.removeAll(entitiesToStore);
CompressedChunkBuilder compressedChunkBuilder = new CompressedChunkBuilder(privateEntityManager, chunk, entitiesToStore, false);
unsavedEntities.removeAll(compressedChunkBuilder.getStoredEntities());
allChunks.put(chunkEntry.getKey(), compressedChunkBuilder);
}
}
use of org.terasology.engine.world.chunks.internal.ChunkImpl in project Terasology by MovingBlocks.
the class ReadWriteStorageManager method addChunksToSaveTransaction.
private void addChunksToSaveTransaction(SaveTransactionBuilder saveTransactionBuilder, ChunkProvider chunkProvider) {
unloadedAndSavingChunkMap.clear();
/*
* New entries might be added concurrently. By using putAll + clear to transfer entries we might loose new
* ones added in between putAll and clear. By iterating we can make sure that all entries removed
* from unloadedAndUnsavedChunkMap get added to unloadedAndSavingChunkMap.
*/
Iterator<Map.Entry<Vector3ic, CompressedChunkBuilder>> unsavedEntryIterator = unloadedAndUnsavedChunkMap.entrySet().iterator();
while (unsavedEntryIterator.hasNext()) {
Map.Entry<Vector3ic, CompressedChunkBuilder> entry = unsavedEntryIterator.next();
unloadedAndSavingChunkMap.put(entry.getKey(), entry.getValue());
unsavedEntryIterator.remove();
}
chunkProvider.getAllChunks().stream().filter(Chunk::isReady).forEach(chunk -> {
// If there is a newer undisposed version of the chunk,we don't need to save the disposed version:
unloadedAndSavingChunkMap.remove(chunk.getPosition(new Vector3i()));
// this storage manager can only work with ChunkImpls
ChunkImpl chunkImpl = (ChunkImpl) chunk;
saveTransactionBuilder.addLoadedChunk(chunk.getPosition(), chunkImpl);
});
for (Map.Entry<Vector3ic, CompressedChunkBuilder> entry : unloadedAndSavingChunkMap.entrySet()) {
saveTransactionBuilder.addUnloadedChunk(entry.getKey(), entry.getValue());
}
}
Aggregations