Search in sources :

Example 66 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class StandardBatchPropagator method processReduction.

private void processReduction() {
    int depth = 0;
    while (depth < rules.getMaxValue()) {
        byte oldValue = (byte) (rules.getMaxValue() - depth);
        Set<Vector3i> toProcess = reduceQueues[depth];
        if (!toProcess.isEmpty()) {
            reduceQueues[depth] = Sets.newLinkedHashSetWithExpectedSize(toProcess.size());
            for (Vector3i pos : toProcess) {
                purge(pos, oldValue);
            }
            if (toProcess.isEmpty()) {
                depth++;
            }
        } else {
            depth++;
        }
    }
}
Also used : Vector3i(org.terasology.math.geom.Vector3i)

Example 67 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class StandardBatchPropagator method propagateDepth.

private void propagateDepth(LitChunk adjChunk, Side side, boolean propagateExternal, IndexProvider indexProvider, Region3i edgeRegion, int[] depths) {
    Vector3i adjPos = new Vector3i();
    int[] adjDepth = new int[depths.length];
    int dimA = (side == Side.LEFT || side == Side.RIGHT) ? ChunkConstants.SIZE_Y : ChunkConstants.SIZE_X;
    int dimB = (side == Side.FRONT || side == Side.BACK) ? ChunkConstants.SIZE_Y : ChunkConstants.SIZE_Z;
    ChunkMath.populateMinAdjacent2D(depths, adjDepth, dimA, dimB, !propagateExternal);
    if (propagateExternal) {
        for (int y = 0; y < dimB; ++y) {
            adjDepth[y * dimA] = 0;
            adjDepth[dimA - 1 + y * dimA] = 0;
        }
        for (int x = 0; x < dimA; ++x) {
            adjDepth[x] = 0;
            adjDepth[x + dimA * (dimB - 1)] = 0;
        }
    }
    for (Vector3i pos : edgeRegion) {
        int depthIndex = indexProvider.getIndexFor(pos);
        int adjacentDepth = adjDepth[depthIndex];
        for (int i = adjacentDepth; i < depths[depthIndex]; ++i) {
            adjPos.set(side.getVector3i());
            adjPos.mul(i + 1);
            adjPos.add(pos);
            adjPos.add(chunkEdgeDeltas.get(side));
            byte value = rules.getValue(adjChunk, adjPos);
            if (value > 1) {
                queueSpreadValue(adjChunk.chunkToWorldPosition(adjPos), value);
            }
        }
    }
}
Also used : Vector3i(org.terasology.math.geom.Vector3i)

Example 68 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class StandardBatchPropagator method push.

private void push(Vector3i pos, byte value) {
    Block block = world.getBlockAt(pos);
    for (Side side : Side.values()) {
        byte spreadValue = rules.propagateValue(value, side, block);
        Vector3i adjPos = side.getAdjacentPos(pos);
        if (rules.canSpreadOutOf(block, side)) {
            byte adjValue = world.getValueAt(adjPos);
            if (adjValue < spreadValue && adjValue != PropagatorWorldView.UNAVAILABLE) {
                Block adjBlock = world.getBlockAt(adjPos);
                if (rules.canSpreadInto(adjBlock, side.reverse())) {
                    increase(adjPos, spreadValue);
                }
            }
        }
    }
}
Also used : Side(org.terasology.math.Side) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block)

Example 69 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class StandardBatchPropagator method processIncrease.

private void processIncrease() {
    int depth = 0;
    while (depth < rules.getMaxValue() - 1) {
        byte value = (byte) (rules.getMaxValue() - depth);
        Set<Vector3i> toProcess = increaseQueues[depth];
        if (!toProcess.isEmpty()) {
            increaseQueues[depth] = Sets.newLinkedHashSetWithExpectedSize(toProcess.size());
            for (Vector3i pos : toProcess) {
                push(pos, value);
            }
            if (increaseQueues[depth].isEmpty()) {
                depth++;
            }
        } else {
            depth++;
        }
    }
}
Also used : Vector3i(org.terasology.math.geom.Vector3i)

Example 70 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class StandardBatchPropagator method purge.

private void purge(Vector3i pos, byte oldValue) {
    Block block = world.getBlockAt(pos);
    increaseQueues[rules.getMaxValue() - oldValue].remove(pos);
    byte fixedValue = rules.getFixedValue(block, pos);
    if (fixedValue > 0) {
        increase(pos, fixedValue);
    } else {
        world.setValueAt(pos, NO_VALUE);
    }
    for (Side side : Side.values()) {
        byte expectedValue = rules.propagateValue(oldValue, side, block);
        Vector3i adjPos = side.getAdjacentPos(pos);
        if (rules.canSpreadOutOf(block, side)) {
            byte adjValue = world.getValueAt(adjPos);
            if (adjValue == expectedValue) {
                Block adjBlock = world.getBlockAt(adjPos);
                if (rules.canSpreadInto(adjBlock, side.reverse())) {
                    reduce(adjPos, expectedValue);
                }
            } else if (adjValue > 0) {
                queueSpreadValue(adjPos, adjValue);
            }
        }
    }
}
Also used : Side(org.terasology.math.Side) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block)

Aggregations

Vector3i (org.terasology.math.geom.Vector3i)246 Test (org.junit.Test)91 EntityRef (org.terasology.entitySystem.entity.EntityRef)34 Block (org.terasology.world.block.Block)32 Chunk (org.terasology.world.chunks.Chunk)30 Vector3f (org.terasology.math.geom.Vector3f)21 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)17 ChunkImpl (org.terasology.world.chunks.internal.ChunkImpl)17 Region3i (org.terasology.math.Region3i)15 BaseVector3i (org.terasology.math.geom.BaseVector3i)15 LocationComponent (org.terasology.logic.location.LocationComponent)14 BlockComponent (org.terasology.world.block.BlockComponent)10 Side (org.terasology.math.Side)9 ChunkViewCoreImpl (org.terasology.world.internal.ChunkViewCoreImpl)8 Before (org.junit.Before)7 Biome (org.terasology.world.biomes.Biome)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 CoreChunk (org.terasology.world.chunks.CoreChunk)6 RenderableChunk (org.terasology.world.chunks.RenderableChunk)6