Search in sources :

Example 1 with SingleChunkView

use of org.terasology.engine.world.propagation.SingleChunkView 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();
}
Also used : StandardBatchPropagator(org.terasology.engine.world.propagation.StandardBatchPropagator) StandardBatchPropagator(org.terasology.engine.world.propagation.StandardBatchPropagator) BatchPropagator(org.terasology.engine.world.propagation.BatchPropagator) Vector3i(org.joml.Vector3i) Block(org.terasology.engine.world.block.Block) PropagationRules(org.terasology.engine.world.propagation.PropagationRules) SingleChunkView(org.terasology.engine.world.propagation.SingleChunkView)

Example 2 with SingleChunkView

use of org.terasology.engine.world.propagation.SingleChunkView 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();
}
Also used : StandardBatchPropagator(org.terasology.engine.world.propagation.StandardBatchPropagator) StandardBatchPropagator(org.terasology.engine.world.propagation.StandardBatchPropagator) BatchPropagator(org.terasology.engine.world.propagation.BatchPropagator) Vector3i(org.joml.Vector3i) Block(org.terasology.engine.world.block.Block) SingleChunkView(org.terasology.engine.world.propagation.SingleChunkView)

Aggregations

Vector3i (org.joml.Vector3i)2 Block (org.terasology.engine.world.block.Block)2 BatchPropagator (org.terasology.engine.world.propagation.BatchPropagator)2 SingleChunkView (org.terasology.engine.world.propagation.SingleChunkView)2 StandardBatchPropagator (org.terasology.engine.world.propagation.StandardBatchPropagator)2 PropagationRules (org.terasology.engine.world.propagation.PropagationRules)1