Search in sources :

Example 1 with PropagatorWorldView

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

the class LightMerger method merge.

/**
 * Merge light for chunk.
 *
 * @param localChunks nearest chunks with target chunk
 * @throws IllegalArgumentException if {@code localChunks.length != LOCAL_CHUNKS_ARRAY_LENGTH} or {@code
 *         chunk} not in center of {@code localChunks}
 */
public static Chunk merge(Chunk[] localChunks) {
    Preconditions.checkArgument(localChunks.length == LOCAL_CHUNKS_ARRAY_LENGTH, "Length of parameter [localChunks] must be equals [" + LOCAL_CHUNKS_ARRAY_LENGTH + "]");
    Preconditions.checkArgument(Arrays.stream(localChunks).noneMatch(Objects::isNull), "Parameter [localChunks] " + "must not contains nulls");
    Arrays.sort(localChunks, Comparator.<Chunk>comparingInt(c -> c.getPosition().x()).thenComparingInt(c -> c.getPosition().y()).thenComparing(c -> c.getPosition().z()));
    Chunk chunk = localChunks[CENTER_INDEX];
    List<BatchPropagator> propagators = Lists.newArrayList();
    propagators.add(new StandardBatchPropagator(new LightPropagationRules(), new LocalChunkView(localChunks, LIGHT_RULES)));
    PropagatorWorldView regenWorldView = new LocalChunkView(localChunks, SUNLIGHT_REGEN_RULES);
    PropagationRules sunlightRules = new SunlightPropagationRules(regenWorldView);
    PropagatorWorldView sunlightWorldView = new LocalChunkView(localChunks, sunlightRules);
    BatchPropagator sunlightPropagator = new StandardBatchPropagator(sunlightRules, sunlightWorldView);
    propagators.add(new SunlightRegenBatchPropagator(SUNLIGHT_REGEN_RULES, regenWorldView, sunlightPropagator, sunlightWorldView));
    propagators.add(sunlightPropagator);
    for (BatchPropagator propagator : propagators) {
        // Propagate Inwards
        for (Side side : Side.allSides()) {
            Chunk adjChunk = localChunks[indexOf(side)];
            if (adjChunk != null) {
                propagator.propagateBetween(adjChunk, chunk, side.reverse(), false);
            }
        }
        // Propagate Outwards
        for (Side side : Side.allSides()) {
            Chunk adjChunk = localChunks[indexOf(side)];
            if (adjChunk != null) {
                propagator.propagateBetween(chunk, adjChunk, side, true);
            }
        }
    }
    for (BatchPropagator propagator : propagators) {
        propagator.process();
    }
    chunk.deflateSunlight();
    return chunk;
}
Also used : Arrays(java.util.Arrays) PropagationRules(org.terasology.engine.world.propagation.PropagationRules) Objects(java.util.Objects) LocalChunkView(org.terasology.engine.world.propagation.LocalChunkView) List(java.util.List) Lists(com.google.common.collect.Lists) Vector3ic(org.joml.Vector3ic) StandardBatchPropagator(org.terasology.engine.world.propagation.StandardBatchPropagator) Vector3i(org.joml.Vector3i) Chunk(org.terasology.engine.world.chunks.Chunk) Preconditions(com.google.common.base.Preconditions) BatchPropagator(org.terasology.engine.world.propagation.BatchPropagator) Side(org.terasology.engine.math.Side) Comparator(java.util.Comparator) PropagatorWorldView(org.terasology.engine.world.propagation.PropagatorWorldView) SunlightRegenBatchPropagator(org.terasology.engine.world.propagation.SunlightRegenBatchPropagator) Side(org.terasology.engine.math.Side) StandardBatchPropagator(org.terasology.engine.world.propagation.StandardBatchPropagator) StandardBatchPropagator(org.terasology.engine.world.propagation.StandardBatchPropagator) BatchPropagator(org.terasology.engine.world.propagation.BatchPropagator) SunlightRegenBatchPropagator(org.terasology.engine.world.propagation.SunlightRegenBatchPropagator) SunlightRegenBatchPropagator(org.terasology.engine.world.propagation.SunlightRegenBatchPropagator) PropagatorWorldView(org.terasology.engine.world.propagation.PropagatorWorldView) LocalChunkView(org.terasology.engine.world.propagation.LocalChunkView) PropagationRules(org.terasology.engine.world.propagation.PropagationRules) Chunk(org.terasology.engine.world.chunks.Chunk)

Aggregations

Preconditions (com.google.common.base.Preconditions)1 Lists (com.google.common.collect.Lists)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Objects (java.util.Objects)1 Vector3i (org.joml.Vector3i)1 Vector3ic (org.joml.Vector3ic)1 Side (org.terasology.engine.math.Side)1 Chunk (org.terasology.engine.world.chunks.Chunk)1 BatchPropagator (org.terasology.engine.world.propagation.BatchPropagator)1 LocalChunkView (org.terasology.engine.world.propagation.LocalChunkView)1 PropagationRules (org.terasology.engine.world.propagation.PropagationRules)1 PropagatorWorldView (org.terasology.engine.world.propagation.PropagatorWorldView)1 StandardBatchPropagator (org.terasology.engine.world.propagation.StandardBatchPropagator)1 SunlightRegenBatchPropagator (org.terasology.engine.world.propagation.SunlightRegenBatchPropagator)1