Search in sources :

Example 1 with LightMerger

use of org.terasology.engine.world.propagation.light.LightMerger in project Terasology by MovingBlocks.

the class LocalChunkProvider method setRelevanceSystem.

// TODO: move loadingPipeline initialization into constructor.
public void setRelevanceSystem(RelevanceSystem relevanceSystem) {
    this.relevanceSystem = relevanceSystem;
    loadingPipeline = new ChunkProcessingPipeline(this::getChunk, relevanceSystem.createChunkTaskComporator());
    loadingPipeline.addStage(ChunkTaskProvider.create("Chunk generate internal lightning", (Consumer<Chunk>) InternalLightProcessor::generateInternalLighting)).addStage(ChunkTaskProvider.create("Chunk deflate", Chunk::deflate)).addStage(ChunkTaskProvider.createMulti("Light merging", chunks -> {
        Chunk[] localChunks = chunks.toArray(new Chunk[0]);
        return LightMerger.merge(localChunks);
    }, LightMerger::requiredChunks)).addStage(ChunkTaskProvider.create("Chunk ready", readyChunks::add));
}
Also used : LightMerger(org.terasology.engine.world.propagation.light.LightMerger) ChunkProcessingPipeline(org.terasology.engine.world.chunks.pipeline.ChunkProcessingPipeline) Chunk(org.terasology.engine.world.chunks.Chunk)

Example 2 with LightMerger

use of org.terasology.engine.world.propagation.light.LightMerger in project Terasology by MovingBlocks.

the class LocalChunkProvider method purgeWorld.

@Override
public void purgeWorld() {
    ChunkMonitor.fireChunkProviderDisposed(this);
    loadingPipeline.shutdown();
    unloadRequestTaskMaster.shutdown(new ChunkUnloadRequest(), true);
    getAllChunks().stream().filter(Chunk::isReady).forEach(chunk -> {
        worldEntity.send(new BeforeChunkUnload(chunk.getPosition(new Vector3i())));
        storageManager.deactivateChunk(chunk);
        chunk.dispose();
    });
    chunkCache.clear();
    storageManager.deleteWorld();
    worldEntity.send(new PurgeWorldEvent());
    loadingPipeline = new ChunkProcessingPipeline(this::getChunk, relevanceSystem.createChunkTaskComporator());
    loadingPipeline.addStage(ChunkTaskProvider.create("Chunk generate internal lightning", (Consumer<Chunk>) InternalLightProcessor::generateInternalLighting)).addStage(ChunkTaskProvider.create("Chunk deflate", Chunk::deflate)).addStage(ChunkTaskProvider.createMulti("Light merging", chunks -> {
        Chunk[] localChunks = chunks.toArray(new Chunk[0]);
        return LightMerger.merge(localChunks);
    }, LightMerger::requiredChunks)).addStage(ChunkTaskProvider.create("Chunk ready", readyChunks::add));
    unloadRequestTaskMaster = TaskMaster.createFIFOTaskMaster("Chunk-Unloader", 8);
    ChunkMonitor.fireChunkProviderInitialized(this);
    for (ChunkRelevanceRegion chunkRelevanceRegion : relevanceSystem.getRegions()) {
        for (Vector3ic pos : chunkRelevanceRegion.getCurrentRegion()) {
            createOrLoadChunk(pos);
        }
        chunkRelevanceRegion.setUpToDate();
    }
}
Also used : BeforeChunkUnload(org.terasology.engine.world.chunks.event.BeforeChunkUnload) LightMerger(org.terasology.engine.world.propagation.light.LightMerger) Vector3ic(org.joml.Vector3ic) ChunkRelevanceRegion(org.terasology.engine.world.chunks.internal.ChunkRelevanceRegion) Vector3i(org.joml.Vector3i) PurgeWorldEvent(org.terasology.engine.world.chunks.event.PurgeWorldEvent) ChunkProcessingPipeline(org.terasology.engine.world.chunks.pipeline.ChunkProcessingPipeline) Chunk(org.terasology.engine.world.chunks.Chunk)

Aggregations

Chunk (org.terasology.engine.world.chunks.Chunk)2 ChunkProcessingPipeline (org.terasology.engine.world.chunks.pipeline.ChunkProcessingPipeline)2 LightMerger (org.terasology.engine.world.propagation.light.LightMerger)2 Vector3i (org.joml.Vector3i)1 Vector3ic (org.joml.Vector3ic)1 BeforeChunkUnload (org.terasology.engine.world.chunks.event.BeforeChunkUnload)1 PurgeWorldEvent (org.terasology.engine.world.chunks.event.PurgeWorldEvent)1 ChunkRelevanceRegion (org.terasology.engine.world.chunks.internal.ChunkRelevanceRegion)1