Search in sources :

Example 6 with Vector3ic

use of org.joml.Vector3ic in project Terasology by MovingBlocks.

the class AbstractFullWorldView method setValueAt.

@Override
public void setValueAt(Vector3ic pos, byte value) {
    setValueAt(getChunk(pos), Chunks.toRelative(pos, new Vector3i()), value);
    BlockRegion chunkRegion = new BlockRegion(pos).expand(1, 1, 1);
    for (Vector3ic affectedChunkPos : Chunks.toChunkRegion(chunkRegion, chunkRegion)) {
        Chunk dirtiedChunk = chunkProvider.getChunk(affectedChunkPos);
        if (dirtiedChunk != null) {
            dirtiedChunk.setDirty(true);
        }
    }
}
Also used : Vector3ic(org.joml.Vector3ic) Vector3i(org.joml.Vector3i) BlockRegion(org.terasology.engine.world.block.BlockRegion) Chunk(org.terasology.engine.world.chunks.Chunk)

Example 7 with Vector3ic

use of org.joml.Vector3ic in project Terasology by MovingBlocks.

the class StandardBatchPropagator method propagateSide.

private void propagateSide(Chunk chunk, Chunk adjChunk, Side side, Function<Vector3ic, Integer> indexProvider, BlockRegionc edgeRegion, int[] depths) {
    Vector3i adjPos = new Vector3i();
    for (Vector3ic pos : edgeRegion) {
        byte expectedValue = (byte) (rules.getValue(chunk, pos) - 1);
        if (expectedValue < 1) {
            continue;
        }
        pos.add(chunkEdgeDeltas.get(side), adjPos);
        int depthIndex = indexProvider.apply(pos);
        int depth = 0;
        Block lastBlock = chunk.getBlock(pos);
        byte adjValue = rules.getValue(adjChunk, adjPos);
        while (expectedValue > adjValue && adjValue != PropagatorWorldView.UNAVAILABLE && rules.canSpreadOutOf(lastBlock, side)) {
            lastBlock = adjChunk.getBlock(adjPos);
            if (rules.canSpreadInto(lastBlock, side.reverse())) {
                rules.setValue(adjChunk, adjPos, expectedValue);
                adjPos.add(side.direction());
                depth++;
                expectedValue--;
                adjValue = rules.getValue(adjChunk, adjPos);
            } else {
                break;
            }
        }
        depths[depthIndex] = depth;
    }
}
Also used : Vector3ic(org.joml.Vector3ic) Vector3i(org.joml.Vector3i) Block(org.terasology.engine.world.block.Block)

Example 8 with Vector3ic

use of org.joml.Vector3ic in project Terasology by MovingBlocks.

the class StandardBatchPropagator method reviewChange.

/**
 * Handles a single block being changed to a different type.
 *
 * @param blockChange The change that was made
 */
private void reviewChange(BlockChange blockChange) {
    Vector3ic blockChangePosition = blockChange.getPosition();
    byte newValue = rules.getFixedValue(blockChange.getTo(), blockChangePosition);
    byte existingValue = world.getValueAt(blockChangePosition);
    /* Handle if the block has an higher fixed value */
    if (newValue > existingValue) {
        increase(blockChangePosition, newValue);
    }
    /* Handle if the block has a lower fixed value */
    byte oldValue = rules.getFixedValue(blockChange.getFrom(), blockChangePosition);
    if (newValue < oldValue) {
        reduce(blockChangePosition, oldValue);
    }
    /* Process propagation out to other blocks */
    Vector3i adjPos = new Vector3i();
    for (Side side : Side.values()) {
        PropagationComparison comparison = rules.comparePropagation(blockChange.getTo(), blockChange.getFrom(), side);
        if (comparison.isRestricting() && existingValue > 0) {
            /* If the propagation of the new value is going to be lower/reduced */
            reduce(blockChangePosition, existingValue);
            side.getAdjacentPos(blockChangePosition, adjPos);
            byte adjValue = world.getValueAt(adjPos);
            if (adjValue == rules.propagateValue(existingValue, side, blockChange.getFrom(), scale)) {
                reduce(adjPos, adjValue);
            }
        } else if (comparison.isPermitting()) {
            /* If the propagation of the new value is going to be more allowing */
            if (existingValue > 0) {
                /* Spread this potentially higher value out */
                queueSpreadValue(blockChangePosition, existingValue);
            }
            /* Spread it out to the block on the side */
            side.getAdjacentPos(blockChangePosition, adjPos);
            byte adjValue = world.getValueAt(adjPos);
            if (adjValue != PropagatorWorldView.UNAVAILABLE) {
                queueSpreadValue(adjPos, adjValue);
            }
        }
    }
}
Also used : Side(org.terasology.engine.math.Side) Vector3ic(org.joml.Vector3ic) Vector3i(org.joml.Vector3i)

Example 9 with Vector3ic

use of org.joml.Vector3ic in project Terasology by MovingBlocks.

the class StandardBatchPropagator method processIncrease.

/**
 * Process all increasing propagation requests This is done from the strongest through to the weakest.
 */
private void processIncrease() {
    for (int depth = 0; depth < rules.getMaxValue() - 1; depth++) {
        byte value = (byte) (rules.getMaxValue() - depth);
        while (!increaseQueues[depth].isEmpty()) {
            Set<Vector3ic> toProcess = increaseQueues[depth];
            increaseQueues[depth] = Sets.newLinkedHashSetWithExpectedSize(toProcess.size());
            /* This step will add any new values to `increaseQueues` */
            for (Vector3ic pos : toProcess) {
                push(pos, value);
            }
        }
    }
}
Also used : Vector3ic(org.joml.Vector3ic)

Example 10 with Vector3ic

use of org.joml.Vector3ic in project Terasology by MovingBlocks.

the class StandardBatchPropagator method propagateBetween.

@Override
public void propagateBetween(Chunk chunk, Chunk adjChunk, Side side, boolean propagateExternal) {
    Function<Vector3ic, Integer> indexProvider = createIndexProvider(side);
    BlockRegion edgeRegion = new BlockRegion(0, 0, 0).setSize(Chunks.SIZE_X, Chunks.SIZE_Y, Chunks.SIZE_Z);
    edgeRegion.face(side, edgeRegion);
    int[] depth = new int[edgeRegion.volume()];
    propagateSide(chunk, adjChunk, side, indexProvider, edgeRegion, depth);
    propagateDepth(adjChunk, side, propagateExternal, indexProvider, edgeRegion, depth);
}
Also used : Vector3ic(org.joml.Vector3ic) BlockRegion(org.terasology.engine.world.block.BlockRegion)

Aggregations

Vector3ic (org.joml.Vector3ic)87 Vector3i (org.joml.Vector3i)52 Test (org.junit.jupiter.api.Test)35 BlockRegion (org.terasology.engine.world.block.BlockRegion)28 Chunk (org.terasology.engine.world.chunks.Chunk)28 ChunkImpl (org.terasology.engine.world.chunks.internal.ChunkImpl)16 Block (org.terasology.engine.world.block.Block)12 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)11 Map (java.util.Map)8 Lists (com.google.common.collect.Lists)5 List (java.util.List)5 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)5 LocationComponent (org.terasology.engine.logic.location.LocationComponent)5 BlockRegionComponent (org.terasology.engine.world.block.regions.BlockRegionComponent)5 Maps (com.google.common.collect.Maps)4 Sets (com.google.common.collect.Sets)4 ArrayList (java.util.ArrayList)4 Collections (java.util.Collections)4 Set (java.util.Set)4 Vector3f (org.joml.Vector3f)4