use of org.terasology.engine.world.propagation.StandardBatchPropagator 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;
}
use of org.terasology.engine.world.propagation.StandardBatchPropagator in project Terasology by MovingBlocks.
the class InternalLightProcessor method populateSunlight.
/**
* Propagate the initial sunlight values out
*
* @param chunk The chunk to set in
*/
private static void populateSunlight(Chunk chunk, int scale) {
PropagationRules sunlightRules = new SunlightPropagationRules(chunk);
BatchPropagator lightPropagator = new StandardBatchPropagator(sunlightRules, new SingleChunkView(sunlightRules, chunk), scale);
Vector3i pos = new Vector3i();
for (int x = 0; x < Chunks.SIZE_X; x++) {
for (int z = 0; z < Chunks.SIZE_Z; z++) {
/* Start at the bottom of the chunk and then move up until the max sunlight level */
for (int y = 0; y < Chunks.SIZE_Y; y++) {
pos.set(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();
}
use of org.terasology.engine.world.propagation.StandardBatchPropagator in project Terasology by MovingBlocks.
the class InternalLightProcessor method populateLight.
/**
* Propagate out light from the initial luminous blocks
*
* @param chunk The chunk to populate through
*/
private static void populateLight(Chunk chunk, int scale) {
BatchPropagator lightPropagator = new StandardBatchPropagator(LIGHT_RULES, new SingleChunkView(LIGHT_RULES, chunk), scale);
Vector3i pos = new Vector3i();
for (int x = 0; x < Chunks.SIZE_X; x++) {
for (int z = 0; z < Chunks.SIZE_Z; z++) {
for (int y = 0; y < Chunks.SIZE_Y; y++) {
Block block = chunk.getBlock(x, y, z);
if (block.getLuminance() > 0) {
chunk.setLight(x, y, z, block.getLuminance());
lightPropagator.propagateFrom(pos.set(x, y, z), block.getLuminance());
}
}
}
}
lightPropagator.process();
}
Aggregations