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