mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-17 22:31:52 +00:00
implement blockstate cache in Column
This commit is contained in:
+6
-1
@@ -13,6 +13,8 @@ import com.dfsek.terra.api.structure.feature.Locator;
|
|||||||
import com.dfsek.terra.api.util.Range;
|
import com.dfsek.terra.api.util.Range;
|
||||||
import com.dfsek.terra.api.world.chunk.generation.util.Column;
|
import com.dfsek.terra.api.world.chunk.generation.util.Column;
|
||||||
|
|
||||||
|
import net.jafama.FastMath;
|
||||||
|
|
||||||
|
|
||||||
public class PatternLocator implements Locator {
|
public class PatternLocator implements Locator {
|
||||||
private final Pattern pattern;
|
private final Pattern pattern;
|
||||||
@@ -25,6 +27,9 @@ public class PatternLocator implements Locator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BinaryColumn getSuitableCoordinates(Column<?> column) {
|
public BinaryColumn getSuitableCoordinates(Column<?> column) {
|
||||||
return new BinaryColumn(search, y -> pattern.matches(y, column));
|
int min = FastMath.max(column.getMinY(), search.getMin());
|
||||||
|
int max = FastMath.min(column.getMaxY(), search.getMax());
|
||||||
|
if(min >= max) return BinaryColumn.getNull();
|
||||||
|
return new BinaryColumn(min, max, y -> pattern.matches(y, column));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-2
@@ -13,6 +13,8 @@ import com.dfsek.terra.api.block.state.BlockState;
|
|||||||
import com.dfsek.terra.api.util.Range;
|
import com.dfsek.terra.api.util.Range;
|
||||||
import com.dfsek.terra.api.world.chunk.generation.util.Column;
|
import com.dfsek.terra.api.world.chunk.generation.util.Column;
|
||||||
|
|
||||||
|
import net.jafama.FastMath;
|
||||||
|
|
||||||
|
|
||||||
public class MatchPattern implements Pattern {
|
public class MatchPattern implements Pattern {
|
||||||
private final Range range;
|
private final Range range;
|
||||||
@@ -25,8 +27,10 @@ public class MatchPattern implements Pattern {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(int y, Column<?> column) {
|
public boolean matches(int y, Column<?> column) {
|
||||||
for(int i = range.getMin(); i < range.getMax(); i++) {
|
int min = FastMath.max(column.getMinY(), range.getMin() + y);
|
||||||
if(!matches.test(column.getBlock(y + i))) return false;
|
int max = FastMath.min(column.getMaxY(), range.getMax() + y);
|
||||||
|
for(int i = min; i < max; i++) {
|
||||||
|
if(!matches.test(column.getBlock(i))) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-1
@@ -27,6 +27,8 @@ public class Column<T extends WritableWorld> {
|
|||||||
private final int max;
|
private final int max;
|
||||||
private final T world;
|
private final T world;
|
||||||
|
|
||||||
|
private final BlockState[] cache;
|
||||||
|
|
||||||
public Column(int x, int z, T world) {
|
public Column(int x, int z, T world) {
|
||||||
this(x, z, world, world.getMinHeight(), world.getMaxHeight());
|
this(x, z, world, world.getMinHeight(), world.getMaxHeight());
|
||||||
}
|
}
|
||||||
@@ -37,6 +39,7 @@ public class Column<T extends WritableWorld> {
|
|||||||
this.world = world;
|
this.world = world;
|
||||||
this.max = max;
|
this.max = max;
|
||||||
this.min = min;
|
this.min = min;
|
||||||
|
this.cache = new BlockState[world.getMaxHeight() - world.getMinHeight()];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getX() {
|
public int getX() {
|
||||||
@@ -48,7 +51,13 @@ public class Column<T extends WritableWorld> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BlockState getBlock(int y) {
|
public BlockState getBlock(int y) {
|
||||||
return world.getBlockState(x, y, z);
|
int i = y - world.getMinHeight();
|
||||||
|
BlockState state = cache[i];
|
||||||
|
if(state == null) {
|
||||||
|
state = world.getBlockState(x, y, z);
|
||||||
|
cache[i] = state;
|
||||||
|
}
|
||||||
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T getWorld() {
|
public T getWorld() {
|
||||||
|
|||||||
Reference in New Issue
Block a user