Search in sources :

Example 21 with ChunkImpl

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")));
}
Also used : BlockUri(org.terasology.engine.world.block.BlockUri) AssetManager(org.terasology.gestalt.assets.management.AssetManager) BlockFamilyDefinitionData(org.terasology.engine.world.block.loader.BlockFamilyDefinitionData) ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3i(org.joml.Vector3i) NullWorldAtlas(org.terasology.engine.world.block.tiles.NullWorldAtlas) ExtraBlockDataManager(org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) BlockManagerImpl(org.terasology.engine.world.block.internal.BlockManagerImpl) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 22 with ChunkImpl

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);
    }
}
Also used : ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3i(org.joml.Vector3i) Collection(java.util.Collection) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Example 23 with ChunkImpl

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());
    }
}
Also used : Vector3ic(org.joml.Vector3ic) ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3i(org.joml.Vector3i) Map(java.util.Map) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Aggregations

ChunkImpl (org.terasology.engine.world.chunks.internal.ChunkImpl)23 Chunk (org.terasology.engine.world.chunks.Chunk)19 Test (org.junit.jupiter.api.Test)17 Vector3i (org.joml.Vector3i)14 Vector3ic (org.joml.Vector3ic)14 BlockRegion (org.terasology.engine.world.block.BlockRegion)11 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)4 ChunkStore (org.terasology.engine.persistence.ChunkStore)4 ChunkProvider (org.terasology.engine.world.chunks.ChunkProvider)3 Map (java.util.Map)2 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)2 Event (org.terasology.engine.entitySystem.event.Event)2 StorageManager (org.terasology.engine.persistence.StorageManager)2 OnChunkLoaded (org.terasology.engine.world.chunks.event.OnChunkLoaded)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Collection (java.util.Collection)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Vector3f (org.joml.Vector3f)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 LocationComponent (org.terasology.engine.logic.location.LocationComponent)1