Search in sources :

Example 1 with PropagationRules

use of org.terasology.world.propagation.PropagationRules in project Terasology by MovingBlocks.

the class LightMerger method merge.

private void merge(Chunk chunk) {
    Chunk[] localChunks = assembleLocalChunks(chunk);
    localChunks[CENTER_INDEX] = chunk;
    List<BatchPropagator> propagators = Lists.newArrayList();
    propagators.add(new StandardBatchPropagator(new LightPropagationRules(), new LocalChunkView(localChunks, lightRules)));
    PropagatorWorldView regenWorldView = new LocalChunkView(localChunks, sunlightRegenRules);
    PropagationRules sunlightRules = new SunlightPropagationRules(regenWorldView);
    PropagatorWorldView sunlightWorldView = new LocalChunkView(localChunks, sunlightRules);
    BatchPropagator sunlightPropagator = new StandardBatchPropagator(sunlightRules, sunlightWorldView);
    propagators.add(new SunlightRegenBatchPropagator(sunlightRegenRules, regenWorldView, sunlightPropagator, sunlightWorldView));
    propagators.add(sunlightPropagator);
    for (BatchPropagator propagator : propagators) {
        // Propagate Inwards
        for (Side side : Side.values()) {
            Vector3i adjChunkPos = side.getAdjacentPos(chunk.getPosition());
            LitChunk adjChunk = chunkProvider.getChunkUnready(adjChunkPos);
            if (adjChunk != null) {
                propagator.propagateBetween(adjChunk, chunk, side.reverse(), false);
            }
        }
        // Propagate Outwards
        for (Side side : Side.values()) {
            Vector3i adjChunkPos = side.getAdjacentPos(chunk.getPosition());
            LitChunk adjChunk = chunkProvider.getChunk(adjChunkPos);
            if (adjChunk != null) {
                propagator.propagateBetween(chunk, adjChunk, side, true);
            }
        }
    }
    for (BatchPropagator propagator : propagators) {
        propagator.process();
    }
    chunk.deflateSunlight();
}
Also used : StandardBatchPropagator(org.terasology.world.propagation.StandardBatchPropagator) StandardBatchPropagator(org.terasology.world.propagation.StandardBatchPropagator) SunlightRegenBatchPropagator(org.terasology.world.propagation.SunlightRegenBatchPropagator) BatchPropagator(org.terasology.world.propagation.BatchPropagator) SunlightRegenBatchPropagator(org.terasology.world.propagation.SunlightRegenBatchPropagator) LitChunk(org.terasology.world.chunks.LitChunk) Chunk(org.terasology.world.chunks.Chunk) LitChunk(org.terasology.world.chunks.LitChunk) Side(org.terasology.math.Side) PropagatorWorldView(org.terasology.world.propagation.PropagatorWorldView) Vector3i(org.terasology.math.geom.Vector3i) LocalChunkView(org.terasology.world.propagation.LocalChunkView) PropagationRules(org.terasology.world.propagation.PropagationRules)

Example 2 with PropagationRules

use of org.terasology.world.propagation.PropagationRules in project Terasology by MovingBlocks.

the class InternalLightProcessor method populateSunlight.

private static void populateSunlight(LitChunk chunk) {
    PropagationRules sunlightRules = new SunlightPropagationRules(chunk);
    BatchPropagator lightPropagator = new StandardBatchPropagator(sunlightRules, new SingleChunkView(sunlightRules, chunk));
    for (int x = 0; x < ChunkConstants.SIZE_X; x++) {
        for (int z = 0; z < ChunkConstants.SIZE_Z; z++) {
            for (int y = 0; y < ChunkConstants.MAX_SUNLIGHT; ++y) {
                Vector3i pos = new Vector3i(x, y, z);
                Block block = chunk.getBlock(x, y, z);
                byte light = sunlightRules.getFixedValue(block, pos);
                if (light > 0) {
                    chunk.setSunlight(x, y, z, light);
                    lightPropagator.propagateFrom(pos, light);
                }
            }
        }
    }
    lightPropagator.process();
}
Also used : StandardBatchPropagator(org.terasology.world.propagation.StandardBatchPropagator) StandardBatchPropagator(org.terasology.world.propagation.StandardBatchPropagator) BatchPropagator(org.terasology.world.propagation.BatchPropagator) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) PropagationRules(org.terasology.world.propagation.PropagationRules) SingleChunkView(org.terasology.world.propagation.SingleChunkView)

Aggregations

Vector3i (org.terasology.math.geom.Vector3i)2 BatchPropagator (org.terasology.world.propagation.BatchPropagator)2 PropagationRules (org.terasology.world.propagation.PropagationRules)2 StandardBatchPropagator (org.terasology.world.propagation.StandardBatchPropagator)2 Side (org.terasology.math.Side)1 Block (org.terasology.world.block.Block)1 Chunk (org.terasology.world.chunks.Chunk)1 LitChunk (org.terasology.world.chunks.LitChunk)1 LocalChunkView (org.terasology.world.propagation.LocalChunkView)1 PropagatorWorldView (org.terasology.world.propagation.PropagatorWorldView)1 SingleChunkView (org.terasology.world.propagation.SingleChunkView)1 SunlightRegenBatchPropagator (org.terasology.world.propagation.SunlightRegenBatchPropagator)1