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);
}
}
}
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;
}
}
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);
}
}
}
}
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);
}
}
}
}
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);
}
Aggregations