Search in sources :

Example 1 with ScratchCell

use of io.xol.chunkstories.world.cell.ScratchCell in project chunkstories by Hugobros3.

the class HeightmapArrayTexture method loadTopVoxels.

private void loadTopVoxels(HeightmapImplementation sum, ByteBuffer bb, int lod) {
    bb.clear();
    int[] data = sum.getVoxelData();
    ScratchCell cell = new ScratchCell(world);
    cell.sunlight = 15;
    for (int i = 0; i < size[lod] * size[lod]; i++) {
        int j = HeightmapImplementation.mainMimpmapOffsets[lod] + i;
        int raw_data = data[j];
        Voxel v = world.getContentTranslator().getVoxelForId(VoxelFormat.id(raw_data));
        cell.voxel = v;
        if (v.getDefinition().isLiquid())
            bb.putInt(512);
        else
            bb.putInt(((VoxelTextureAtlased) v.getVoxelTexture(VoxelSide.TOP, cell)).positionInColorIndex);
    }
    bb.flip();
}
Also used : VoxelTextureAtlased(io.xol.chunkstories.voxel.VoxelTextureAtlased) Voxel(io.xol.chunkstories.api.voxel.Voxel) ScratchCell(io.xol.chunkstories.world.cell.ScratchCell)

Example 2 with ScratchCell

use of io.xol.chunkstories.world.cell.ScratchCell in project chunkstories by Hugobros3.

the class ChunkLightBaker method propagateLightning.

// Now entering lightning code part, brace yourselves
private int propagateLightning(IntDeque blockSources, IntDeque sunSources, boolean adjacent) {
    int modifiedBlocks = 0;
    CubicChunk leftChunk, rightChunk, topChunk, bottomChunk, frontChunk, backChunk;
    topChunk = world.getChunk(chunkX, chunkY + 1, chunkZ);
    bottomChunk = world.getChunk(chunkX, chunkY - 1, chunkZ);
    frontChunk = world.getChunk(chunkX, chunkY, chunkZ + 1);
    backChunk = world.getChunk(chunkX, chunkY, chunkZ - 1);
    leftChunk = world.getChunk(chunkX - 1, chunkY, chunkZ);
    rightChunk = world.getChunk(chunkX + 1, chunkY, chunkZ);
    // Don't spam the requeue requests
    boolean checkTopBleeding = adjacent && (topChunk != null);
    boolean checkBottomBleeding = adjacent && (bottomChunk != null);
    boolean checkFrontBleeding = adjacent && (frontChunk != null);
    boolean checkBackBleeding = adjacent && (backChunk != null);
    boolean checkLeftBleeding = adjacent && (leftChunk != null);
    boolean checkRightBleeding = adjacent && (rightChunk != null);
    boolean requestTop = false;
    boolean requestBot = false;
    boolean requestFront = false;
    boolean requestBack = false;
    boolean requestLeft = false;
    boolean requestRight = false;
    ScratchCell cell = new ScratchCell(world);
    ScratchCell adj = new ScratchCell(world);
    while (blockSources.size() > 0) {
        int z = blockSources.removeLast();
        int y = blockSources.removeLast();
        int x = blockSources.removeLast();
        peek(x, y, z, cell);
        int cellLightLevel = cell.blocklight;
        if (cell.voxel.getDefinition().isOpaque())
            cellLightLevel = cell.voxel.getEmittedLightLevel(cell);
        if (cellLightLevel > 1) {
            if (x < 31) {
                peek(x + 1, y, z, adj);
                int fadedLightLevel = cellLightLevel - (adj.voxel.getLightLevelModifier(adj, cell, VoxelSide.LEFT) + 1);
                if (adj.blocklight < fadedLightLevel) {
                    adj.blocklight = fadedLightLevel;
                    poke(adj);
                    modifiedBlocks++;
                    blockSources.addLast(x + 1);
                    blockSources.addLast(y);
                    blockSources.addLast(z);
                }
            } else if (checkRightBleeding) {
                peek(32, y, z, adj);
                int fadedLightLevel = cellLightLevel - (adj.voxel.getLightLevelModifier(adj, cell, VoxelSide.LEFT) + 1);
                if (adj.blocklight < fadedLightLevel) {
                    requestRight = true;
                    checkRightBleeding = false;
                }
            }
            if (x > 0) {
                peek(x - 1, y, z, adj);
                int fadedLightLevel = cellLightLevel - (adj.voxel.getLightLevelModifier(adj, cell, VoxelSide.RIGHT) + 1);
                if (adj.blocklight < fadedLightLevel) {
                    adj.blocklight = fadedLightLevel;
                    poke(adj);
                    modifiedBlocks++;
                    blockSources.addLast(x - 1);
                    blockSources.addLast(y);
                    blockSources.addLast(z);
                }
            } else if (checkLeftBleeding) {
                peek(-1, y, z, adj);
                int fadedLightLevel = cellLightLevel - (adj.voxel.getLightLevelModifier(adj, cell, VoxelSide.RIGHT) + 1);
                if (adj.blocklight < fadedLightLevel) {
                    requestLeft = true;
                    checkLeftBleeding = false;
                }
            }
            if (z < 31) {
                peek(x, y, z + 1, adj);
                int fadedLightLevel = cellLightLevel - (adj.voxel.getLightLevelModifier(adj, cell, VoxelSide.BACK) + 1);
                if (adj.blocklight < fadedLightLevel) {
                    adj.blocklight = fadedLightLevel;
                    poke(adj);
                    modifiedBlocks++;
                    blockSources.addLast(x);
                    blockSources.addLast(y);
                    blockSources.addLast(z + 1);
                }
            } else if (checkFrontBleeding) {
                peek(x, y, 32, adj);
                int fadedLightLevel = cellLightLevel - (adj.voxel.getLightLevelModifier(adj, cell, VoxelSide.BACK) + 1);
                if (adj.blocklight < fadedLightLevel) {
                    requestFront = true;
                    checkFrontBleeding = false;
                }
            }
            if (z > 0) {
                peek(x, y, z - 1, adj);
                int fadedLightLevel = cellLightLevel - (adj.voxel.getLightLevelModifier(adj, cell, VoxelSide.FRONT) + 1);
                if (adj.blocklight < fadedLightLevel) {
                    adj.blocklight = fadedLightLevel;
                    poke(adj);
                    modifiedBlocks++;
                    blockSources.addLast(x);
                    blockSources.addLast(y);
                    blockSources.addLast(z - 1);
                }
            } else if (checkBackBleeding) {
                peek(x, y, -1, adj);
                int fadedLightLevel = cellLightLevel - (adj.voxel.getLightLevelModifier(adj, cell, VoxelSide.FRONT) + 1);
                if (adj.blocklight < fadedLightLevel) {
                    requestBack = true;
                    checkBackBleeding = false;
                }
            }
            if (y < 31) {
                peek(x, y + 1, z, adj);
                int fadedLightLevel = cellLightLevel - (adj.voxel.getLightLevelModifier(adj, cell, VoxelSide.BOTTOM) + 1);
                if (adj.blocklight < fadedLightLevel) {
                    adj.blocklight = fadedLightLevel;
                    poke(adj);
                    modifiedBlocks++;
                    blockSources.addLast(x);
                    blockSources.addLast(y + 1);
                    blockSources.addLast(z);
                }
            } else if (checkTopBleeding) {
                peek(x, 32, z, adj);
                int fadedLightLevel = cellLightLevel - (adj.voxel.getLightLevelModifier(adj, cell, VoxelSide.BOTTOM) + 1);
                if (adj.blocklight < fadedLightLevel) {
                    requestTop = true;
                    checkTopBleeding = false;
                }
            }
            if (y > 0) {
                peek(x, y - 1, z, adj);
                int fadedLightLevel = cellLightLevel - (adj.voxel.getLightLevelModifier(adj, cell, VoxelSide.TOP) + 1);
                if (adj.blocklight < fadedLightLevel) {
                    adj.blocklight = fadedLightLevel;
                    poke(adj);
                    modifiedBlocks++;
                    blockSources.addLast(x);
                    blockSources.addLast(y - 1);
                    blockSources.addLast(z);
                }
            } else if (checkBottomBleeding) {
                peek(x, -1, z, adj);
                int fadedLightLevel = cellLightLevel - (adj.voxel.getLightLevelModifier(adj, cell, VoxelSide.TOP) + 1);
                if (adj.blocklight < fadedLightLevel) {
                    requestBot = true;
                    checkBottomBleeding = false;
                }
            }
        }
    }
    while (sunSources.size() > 0) {
        int z = sunSources.removeLast();
        int y = sunSources.removeLast();
        int x = sunSources.removeLast();
        peek(x, y, z, cell);
        int cellLightLevel = cell.sunlight;
        if (cell.voxel.getDefinition().isOpaque())
            cellLightLevel = cell.voxel.getEmittedLightLevel(cell);
        if (cellLightLevel > 1) {
            if (x < 31) {
                peek(x + 1, y, z, adj);
                int fadedLightLevel = cellLightLevel - (adj.voxel.getLightLevelModifier(adj, cell, VoxelSide.LEFT) + 1);
                if (adj.sunlight < fadedLightLevel) {
                    adj.sunlight = fadedLightLevel;
                    poke(adj);
                    modifiedBlocks++;
                    sunSources.addLast(x + 1);
                    sunSources.addLast(y);
                    sunSources.addLast(z);
                }
            } else if (checkRightBleeding) {
                peek(32, y, z, adj);
                int fadedLightLevel = cellLightLevel - (adj.voxel.getLightLevelModifier(adj, cell, VoxelSide.LEFT) + 1);
                if (adj.sunlight < fadedLightLevel) {
                    requestRight = true;
                    checkRightBleeding = false;
                }
            }
            if (x > 0) {
                peek(x - 1, y, z, adj);
                int fadedLightLevel = cellLightLevel - (adj.voxel.getLightLevelModifier(adj, cell, VoxelSide.RIGHT) + 1);
                if (adj.sunlight < fadedLightLevel) {
                    adj.sunlight = fadedLightLevel;
                    poke(adj);
                    modifiedBlocks++;
                    sunSources.addLast(x - 1);
                    sunSources.addLast(y);
                    sunSources.addLast(z);
                }
            } else if (checkLeftBleeding) {
                peek(-1, y, z, adj);
                int fadedLightLevel = cellLightLevel - (adj.voxel.getLightLevelModifier(adj, cell, VoxelSide.RIGHT) + 1);
                if (adj.sunlight < fadedLightLevel) {
                    requestLeft = true;
                    checkLeftBleeding = false;
                }
            }
            if (z < 31) {
                peek(x, y, z + 1, adj);
                int fadedLightLevel = cellLightLevel - (adj.voxel.getLightLevelModifier(adj, cell, VoxelSide.BACK) + 1);
                if (adj.sunlight < fadedLightLevel) {
                    adj.sunlight = fadedLightLevel;
                    poke(adj);
                    modifiedBlocks++;
                    sunSources.addLast(x);
                    sunSources.addLast(y);
                    sunSources.addLast(z + 1);
                }
            } else if (checkFrontBleeding) {
                peek(x, y, 32, adj);
                int fadedLightLevel = cellLightLevel - (adj.voxel.getLightLevelModifier(adj, cell, VoxelSide.BACK) + 1);
                if (adj.sunlight < fadedLightLevel) {
                    requestFront = true;
                    checkFrontBleeding = false;
                }
            }
            if (z > 0) {
                peek(x, y, z - 1, adj);
                int fadedLightLevel = cellLightLevel - (adj.voxel.getLightLevelModifier(adj, cell, VoxelSide.FRONT) + 1);
                if (adj.sunlight < fadedLightLevel) {
                    adj.sunlight = fadedLightLevel;
                    poke(adj);
                    modifiedBlocks++;
                    sunSources.addLast(x);
                    sunSources.addLast(y);
                    sunSources.addLast(z - 1);
                }
            } else if (checkBackBleeding) {
                peek(x, y, -1, adj);
                int fadedLightLevel = cellLightLevel - (adj.voxel.getLightLevelModifier(adj, cell, VoxelSide.FRONT) + 1);
                if (adj.sunlight < fadedLightLevel) {
                    requestBack = true;
                    checkBackBleeding = false;
                }
            }
            if (y < 31) {
                peek(x, y + 1, z, adj);
                int fadedLightLevel = cellLightLevel - (adj.voxel.getLightLevelModifier(adj, cell, VoxelSide.BOTTOM) + 1);
                if (adj.sunlight < fadedLightLevel) {
                    adj.sunlight = fadedLightLevel;
                    poke(adj);
                    modifiedBlocks++;
                    sunSources.addLast(x);
                    sunSources.addLast(y + 1);
                    sunSources.addLast(z);
                }
            } else if (checkTopBleeding) {
                peek(x, 32, z, adj);
                int fadedLightLevel = cellLightLevel - (adj.voxel.getLightLevelModifier(adj, cell, VoxelSide.BOTTOM) + 1);
                if (adj.sunlight < fadedLightLevel) {
                    requestTop = true;
                    checkTopBleeding = false;
                }
            }
            // fade when traveling backwards so we do not decrement fadedLightLevel !
            if (y > 0) {
                peek(x, y - 1, z, adj);
                int fadedLightLevel = cellLightLevel - (adj.voxel.getLightLevelModifier(adj, cell, VoxelSide.TOP));
                if (adj.sunlight < fadedLightLevel) {
                    adj.sunlight = fadedLightLevel;
                    poke(adj);
                    modifiedBlocks++;
                    sunSources.addLast(x);
                    sunSources.addLast(y - 1);
                    sunSources.addLast(z);
                }
            } else if (checkBottomBleeding) {
                peek(x, -1, z, adj);
                int fadedLightLevel = cellLightLevel - (adj.voxel.getLightLevelModifier(adj, cell, VoxelSide.TOP));
                if (adj.sunlight < fadedLightLevel) {
                    requestBot = true;
                    checkBottomBleeding = false;
                }
            }
        }
    }
    if (requestTop)
        topChunk.lightBaker().requestLightningUpdate();
    if (requestBot)
        bottomChunk.lightBaker().requestLightningUpdate();
    if (requestLeft)
        leftChunk.lightBaker().requestLightningUpdate();
    if (requestRight)
        rightChunk.lightBaker().requestLightningUpdate();
    if (requestBack)
        backChunk.lightBaker().requestLightningUpdate();
    if (requestFront)
        frontChunk.lightBaker().requestLightningUpdate();
    return modifiedBlocks;
}
Also used : ScratchCell(io.xol.chunkstories.world.cell.ScratchCell)

Example 3 with ScratchCell

use of io.xol.chunkstories.world.cell.ScratchCell in project chunkstories by Hugobros3.

the class ChunkLightBaker method propagateLightningBeyondChunk.

// TODO use getLightLevelModifier
private int propagateLightningBeyondChunk(IntDeque blockSources, IntDeque sunSources) {
    int modifiedBlocks = 0;
    int bounds = 64;
    ScratchCell cell = new ScratchCell(world);
    ScratchCell sideCell = new ScratchCell(world);
    while (blockSources.size() > 0) {
        int z = blockSources.removeLast();
        int y = blockSources.removeLast();
        int x = blockSources.removeLast();
        peek(x, y, z, cell);
        int ll = cell.getBlocklight();
        if (cell.getVoxel().getDefinition().isOpaque())
            ll = cell.getVoxel().getEmittedLightLevel(cell);
        if (ll > 1) {
            // X-propagation
            if (x < bounds) {
                int adj = this.peekRawFast(x + 1, y, z);
                if (!world.getContentTranslator().getVoxelForId((adj & 0xFFFF)).getDefinition().isOpaque() && ((adj & blocklightMask) >> blockBitshift) < ll - 1) {
                    this.pokeRawFast(x + 1, y, z, adj & blockAntiMask | (ll - 1) << blockBitshift);
                    modifiedBlocks++;
                    blockSources.addLast(x + 1);
                    blockSources.addLast(y);
                    blockSources.addLast(z);
                }
            }
            if (x > -bounds) {
                int adj = this.peekRawFast(x - 1, y, z);
                if (!world.getContentTranslator().getVoxelForId((adj & 0xFFFF)).getDefinition().isOpaque() && ((adj & blocklightMask) >> blockBitshift) < ll - 1) {
                    this.pokeRawFast(x - 1, y, z, adj & blockAntiMask | (ll - 1) << blockBitshift);
                    modifiedBlocks++;
                    blockSources.addLast(x - 1);
                    blockSources.addLast(y);
                    blockSources.addLast(z);
                }
            }
            // Z-propagation
            if (z < bounds) {
                int adj = this.peekRawFast(x, y, z + 1);
                if (!world.getContentTranslator().getVoxelForId((adj & 0xFFFF)).getDefinition().isOpaque() && ((adj & blocklightMask) >> blockBitshift) < ll - 1) {
                    this.pokeRawFast(x, y, z + 1, adj & blockAntiMask | (ll - 1) << blockBitshift);
                    modifiedBlocks++;
                    blockSources.addLast(x);
                    blockSources.addLast(y);
                    blockSources.addLast(z + 1);
                }
            }
            if (z > -bounds) {
                int adj = this.peekRawFast(x, y, z - 1);
                if (!world.getContentTranslator().getVoxelForId((adj & 0xFFFF)).getDefinition().isOpaque() && ((adj & blocklightMask) >> blockBitshift) < ll - 1) {
                    this.pokeRawFast(x, y, z - 1, adj & blockAntiMask | (ll - 1) << blockBitshift);
                    modifiedBlocks++;
                    blockSources.addLast(x);
                    blockSources.addLast(y);
                    blockSources.addLast(z - 1);
                }
            }
            // Y-propagation
            if (// y = 254+1
            y < bounds) {
                int adj = this.peekRawFast(x, y + 1, z);
                if (!world.getContentTranslator().getVoxelForId((adj & 0xFFFF)).getDefinition().isOpaque() && ((adj & blocklightMask) >> blockBitshift) < ll - 1) {
                    this.pokeRawFast(x, y + 1, z, adj & blockAntiMask | (ll - 1) << blockBitshift);
                    modifiedBlocks++;
                    blockSources.addLast(x);
                    blockSources.addLast(y + 1);
                    blockSources.addLast(z);
                }
            }
            if (y > -bounds) {
                int adj = this.peekRawFast(x, y - 1, z);
                if (!world.getContentTranslator().getVoxelForId((adj & 0xFFFF)).getDefinition().isOpaque() && ((adj & blocklightMask) >> blockBitshift) < ll - 1) {
                    this.pokeRawFast(x, y - 1, z, adj & blockAntiMask | (ll - 1) << blockBitshift);
                    modifiedBlocks++;
                    blockSources.addLast(x);
                    blockSources.addLast(y - 1);
                    blockSources.addLast(z);
                }
            }
        }
    }
    // Sunlight propagation
    while (sunSources.size() > 0) {
        int z = sunSources.removeLast();
        int y = sunSources.removeLast();
        int x = sunSources.removeLast();
        peek(x, y, z, cell);
        int ll = cell.sunlight;
        if (cell.getVoxel().getDefinition().isOpaque())
            ll = 0;
        if (ll > 1) {
            // X-propagation
            if (x < bounds) {
                peek(x + 1, y, z, sideCell);
                int llRight = ll - sideCell.voxel.getLightLevelModifier(sideCell, cell, VoxelSide.LEFT);
                if (!sideCell.getVoxel().getDefinition().isOpaque() && sideCell.sunlight < llRight - 1) {
                    sideCell.sunlight = llRight - 1;
                    poke(sideCell);
                    modifiedBlocks++;
                    sunSources.addLast(x + 1);
                    sunSources.addLast(y);
                    sunSources.addLast(z);
                }
            }
            if (x > -bounds) {
                peek(x - 1, y, z, sideCell);
                int llLeft = ll - sideCell.voxel.getLightLevelModifier(sideCell, cell, VoxelSide.RIGHT);
                if (!sideCell.voxel.getDefinition().isOpaque() && sideCell.sunlight < llLeft - 1) {
                    sideCell.sunlight = llLeft - 1;
                    poke(sideCell);
                    modifiedBlocks++;
                    sunSources.addLast(x - 1);
                    sunSources.addLast(y);
                    sunSources.addLast(z);
                }
            }
            // Z-propagation
            if (z < bounds) {
                peek(x, y, z + 1, sideCell);
                int llFront = ll - sideCell.voxel.getLightLevelModifier(sideCell, cell, VoxelSide.BACK);
                if (!sideCell.voxel.getDefinition().isOpaque() && sideCell.sunlight < llFront - 1) {
                    sideCell.sunlight = llFront - 1;
                    poke(sideCell);
                    modifiedBlocks++;
                    sunSources.addLast(x);
                    sunSources.addLast(y);
                    sunSources.addLast(z + 1);
                }
            }
            if (z > -bounds) {
                peek(x, y, z - 1, sideCell);
                int llBack = ll - sideCell.voxel.getLightLevelModifier(sideCell, cell, VoxelSide.FRONT);
                if (!sideCell.voxel.getDefinition().isOpaque() && sideCell.sunlight < llBack - 1) {
                    sideCell.sunlight = llBack - 1;
                    poke(sideCell);
                    modifiedBlocks++;
                    sunSources.addLast(x);
                    sunSources.addLast(y);
                    sunSources.addLast(z - 1);
                }
            }
            // Y-propagation
            if (y < bounds) {
                peek(x, y + 1, z, sideCell);
                int llTop = ll - sideCell.voxel.getLightLevelModifier(sideCell, cell, VoxelSide.BOTTOM);
                if (!sideCell.voxel.getDefinition().isOpaque() && sideCell.sunlight < llTop - 1) {
                    sideCell.sunlight = llTop - 1;
                    poke(sideCell);
                    modifiedBlocks++;
                    sunSources.addLast(x);
                    sunSources.addLast(y + 1);
                    sunSources.addLast(z);
                }
            }
            if (y > -bounds) {
                peek(x, y - 1, z, sideCell);
                int llBottom = ll - sideCell.voxel.getLightLevelModifier(sideCell, cell, VoxelSide.TOP);
                if (!sideCell.voxel.getDefinition().isOpaque() && sideCell.sunlight < llBottom) {
                    sideCell.sunlight = llBottom;
                    poke(sideCell);
                    modifiedBlocks++;
                    sunSources.addLast(x);
                    sunSources.addLast(y - 1);
                    sunSources.addLast(z);
                }
            }
        }
    }
    return modifiedBlocks;
}
Also used : ScratchCell(io.xol.chunkstories.world.cell.ScratchCell)

Example 4 with ScratchCell

use of io.xol.chunkstories.world.cell.ScratchCell in project chunkstories by Hugobros3.

the class ChunkLightBaker method addAdjacentChunksLightSources.

private int addAdjacentChunksLightSources(IntDeque blockSources, IntDeque sunSources) {
    ScratchCell cell = new ScratchCell(world);
    ScratchCell adj = new ScratchCell(world);
    CubicChunk leftChunk, rightChunk, topChunk, bottomChunk, frontChunk, backChunk;
    topChunk = world.getChunk(chunkX, chunkY + 1, chunkZ);
    bottomChunk = world.getChunk(chunkX, chunkY - 1, chunkZ);
    frontChunk = world.getChunk(chunkX, chunkY, chunkZ + 1);
    backChunk = world.getChunk(chunkX, chunkY, chunkZ - 1);
    leftChunk = world.getChunk(chunkX - 1, chunkY, chunkZ);
    rightChunk = world.getChunk(chunkX + 1, chunkY, chunkZ);
    int mods = 0;
    if (world != null) {
        if (rightChunk != null) {
            for (int z = 0; z < 32; z++) for (int y = 0; y < 32; y++) {
                peek(32, y, z, adj);
                peek(31, y, z, cell);
                int modifier = cell.voxel.getLightLevelModifier(cell, adj, VoxelSide.RIGHT) + 1;
                if (adj.blocklight - modifier > cell.blocklight) {
                    cell.blocklight = adj.blocklight - modifier;
                    poke(cell);
                    mods++;
                    blockSources.addLast(cell.x & 0x1f);
                    blockSources.addLast(cell.y & 0x1f);
                    blockSources.addLast(cell.z & 0x1f);
                }
                if (adj.sunlight - modifier > cell.sunlight) {
                    cell.sunlight = adj.sunlight - modifier;
                    mods++;
                    poke(cell);
                    sunSources.addLast(cell.x & 0x1f);
                    sunSources.addLast(cell.y & 0x1f);
                    sunSources.addLast(cell.z & 0x1f);
                }
            }
        }
        if (leftChunk != null) {
            for (int z = 0; z < 32; z++) for (int y = 0; y < 32; y++) {
                peek(-1, y, z, adj);
                peek(0, y, z, cell);
                int modifier = cell.voxel.getLightLevelModifier(cell, adj, VoxelSide.LEFT) + 1;
                if (adj.blocklight - modifier > cell.blocklight) {
                    cell.blocklight = adj.blocklight - modifier;
                    poke(cell);
                    mods++;
                    blockSources.addLast(cell.x & 0x1f);
                    blockSources.addLast(cell.y & 0x1f);
                    blockSources.addLast(cell.z & 0x1f);
                }
                if (adj.sunlight - modifier > cell.sunlight) {
                    cell.sunlight = adj.sunlight - modifier;
                    mods++;
                    poke(cell);
                    sunSources.addLast(cell.x & 0x1f);
                    sunSources.addLast(cell.y & 0x1f);
                    sunSources.addLast(cell.z & 0x1f);
                }
            }
        }
        if (topChunk != null && !topChunk.isAirChunk()) {
            for (int z = 0; z < 32; z++) for (int x = 0; x < 32; x++) {
                peek(x, 32, z, adj);
                peek(x, 31, z, cell);
                int modifier = cell.voxel.getLightLevelModifier(cell, adj, VoxelSide.TOP) + 1;
                if (adj.blocklight - modifier > cell.blocklight) {
                    cell.blocklight = adj.blocklight - modifier;
                    poke(cell);
                    mods++;
                    blockSources.addLast(cell.x & 0x1f);
                    blockSources.addLast(cell.y & 0x1f);
                    blockSources.addLast(cell.z & 0x1f);
                }
                // sunlight doesn't dim travelling downwards
                modifier -= 1;
                if (adj.sunlight - modifier > cell.sunlight) {
                    cell.sunlight = adj.sunlight - modifier;
                    mods++;
                    poke(cell);
                    sunSources.addLast(cell.x & 0x1f);
                    sunSources.addLast(cell.y & 0x1f);
                    sunSources.addLast(cell.z & 0x1f);
                }
            }
        } else {
            for (int x = 0; x < 32; x++) for (int z = 0; z < 32; z++) {
                peek(x, 32, z, adj);
                peek(x, 31, z, cell);
                int modifier = cell.voxel.getLightLevelModifier(cell, adj, VoxelSide.TOP);
                if (adj.sunlight - modifier > cell.sunlight) {
                    cell.sunlight = adj.sunlight - modifier;
                    poke(cell);
                    mods++;
                    sunSources.addLast(cell.x & 0x1f);
                    sunSources.addLast(cell.y & 0x1f);
                    sunSources.addLast(cell.z & 0x1f);
                }
            }
        }
        if (bottomChunk != null) {
            for (int z = 0; z < 32; z++) for (int x = 0; x < 32; x++) {
                peek(x, -1, z, adj);
                peek(x, 0, z, cell);
                int modifier = cell.voxel.getLightLevelModifier(cell, adj, VoxelSide.BOTTOM) + 1;
                if (adj.blocklight - modifier > cell.blocklight) {
                    cell.blocklight = adj.blocklight - modifier;
                    poke(cell);
                    mods++;
                    blockSources.addLast(cell.x & 0x1f);
                    blockSources.addLast(cell.y & 0x1f);
                    blockSources.addLast(cell.z & 0x1f);
                }
                if (adj.sunlight - modifier > cell.sunlight) {
                    cell.sunlight = adj.sunlight - modifier;
                    mods++;
                    poke(cell);
                    sunSources.addLast(cell.x & 0x1f);
                    sunSources.addLast(cell.y & 0x1f);
                    sunSources.addLast(cell.z & 0x1f);
                }
            }
        }
        // cc = world.getChunk(chunkX, chunkY, chunkZ + 1);
        if (frontChunk != null) {
            for (int y = 0; y < 32; y++) for (int x = 0; x < 32; x++) {
                peek(x, y, 32, adj);
                peek(x, y, 31, cell);
                int modifier = cell.voxel.getLightLevelModifier(cell, adj, VoxelSide.FRONT) + 1;
                if (adj.blocklight - modifier > cell.blocklight) {
                    cell.blocklight = adj.blocklight - modifier;
                    poke(cell);
                    mods++;
                    blockSources.addLast(cell.x & 0x1f);
                    blockSources.addLast(cell.y & 0x1f);
                    blockSources.addLast(cell.z & 0x1f);
                }
                if (adj.sunlight - modifier > cell.sunlight) {
                    cell.sunlight = adj.sunlight - modifier;
                    mods++;
                    poke(cell);
                    sunSources.addLast(cell.x & 0x1f);
                    sunSources.addLast(cell.y & 0x1f);
                    sunSources.addLast(cell.z & 0x1f);
                }
            }
        }
        // cc = world.getChunk(chunkX, chunkY, chunkZ - 1);
        if (backChunk != null) {
            for (int y = 0; y < 32; y++) for (int x = 0; x < 32; x++) {
                peek(x, y, -1, adj);
                peek(x, y, 0, cell);
                int modifier = cell.voxel.getLightLevelModifier(cell, adj, VoxelSide.BACK) + 1;
                if (adj.blocklight - modifier > cell.blocklight) {
                    cell.blocklight = adj.blocklight - modifier;
                    poke(cell);
                    mods++;
                    blockSources.addLast(cell.x & 0x1f);
                    blockSources.addLast(cell.y & 0x1f);
                    blockSources.addLast(cell.z & 0x1f);
                }
                if (adj.sunlight - modifier > cell.sunlight) {
                    cell.sunlight = adj.sunlight - modifier;
                    mods++;
                    poke(cell);
                    sunSources.addLast(cell.x & 0x1f);
                    sunSources.addLast(cell.y & 0x1f);
                    sunSources.addLast(cell.z & 0x1f);
                }
            }
        }
    }
    return mods;
}
Also used : ScratchCell(io.xol.chunkstories.world.cell.ScratchCell)

Aggregations

ScratchCell (io.xol.chunkstories.world.cell.ScratchCell)4 Voxel (io.xol.chunkstories.api.voxel.Voxel)1 VoxelTextureAtlased (io.xol.chunkstories.voxel.VoxelTextureAtlased)1