mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-03 22:36:10 +00:00
fix #264 with artifacting
This commit is contained in:
@@ -12,69 +12,77 @@ import com.dfsek.terra.addons.biome.pipeline.api.delegate.BiomeDelegate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.stage.type.BiomeExpander;
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.stage.type.BiomeMutator;
|
||||
import com.dfsek.terra.addons.biome.pipeline.source.BiomeSource;
|
||||
import com.dfsek.terra.api.util.vector.Vector2;
|
||||
|
||||
|
||||
public class BiomeHolderImpl implements BiomeHolder {
|
||||
private final Vector2.Mutable origin;
|
||||
private final int width;
|
||||
private final int offset;
|
||||
private final double totalWidth;
|
||||
private final int originalWidth;
|
||||
private BiomeDelegate[][] biomes;
|
||||
|
||||
public BiomeHolderImpl(int width, Vector2.Mutable origin) {
|
||||
public BiomeHolderImpl(int width, double totalWidth) {
|
||||
this.totalWidth = totalWidth;
|
||||
this.originalWidth = width;
|
||||
width += 4;
|
||||
this.width = width;
|
||||
biomes = new BiomeDelegate[width][width];
|
||||
this.origin = origin;
|
||||
this.offset = 2;
|
||||
}
|
||||
|
||||
private BiomeHolderImpl(BiomeDelegate[][] biomes, Vector2.Mutable origin, int width, int offset) {
|
||||
private BiomeHolderImpl(BiomeDelegate[][] biomes, int width, int offset, double totalWidth, int originalWidth) {
|
||||
this.biomes = biomes;
|
||||
this.origin = origin;
|
||||
this.width = width;
|
||||
this.offset = 2 * offset;
|
||||
this.totalWidth = totalWidth;
|
||||
this.originalWidth = originalWidth;
|
||||
}
|
||||
|
||||
private double normalise(double in) {
|
||||
return totalWidth * ((in - offset) / originalWidth);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeHolder expand(BiomeExpander expander, long seed) {
|
||||
public BiomeHolder expand(BiomeExpander expander, int x, int z, long seed) {
|
||||
BiomeDelegate[][] old = biomes;
|
||||
int newWidth = width * 2 - 1;
|
||||
|
||||
biomes = new BiomeDelegate[newWidth][newWidth];
|
||||
|
||||
for(int x = 0; x < width; x++) {
|
||||
for(int z = 0; z < width; z++) {
|
||||
biomes[x * 2][z * 2] = old[x][z];
|
||||
if(z != width - 1)
|
||||
biomes[x * 2][z * 2 + 1] = expander.getBetween(x + origin.getX(), z + 1 + origin.getZ(), seed, old[x][z],
|
||||
old[x][z + 1]);
|
||||
if(x != width - 1)
|
||||
biomes[x * 2 + 1][z * 2] = expander.getBetween(x + 1 + origin.getX(), z + origin.getZ(), seed, old[x][z],
|
||||
old[x + 1][z]);
|
||||
if(x != width - 1 && z != width - 1)
|
||||
biomes[x * 2 + 1][z * 2 + 1] = expander.getBetween(x + 1 + origin.getX(), z + 1 + origin.getZ(), seed, old[x][z],
|
||||
old[x + 1][z + 1], old[x][z + 1], old[x + 1][z]);
|
||||
|
||||
for(int xi = 0; xi < width; xi++) {
|
||||
for(int zi = 0; zi < width; zi++) {
|
||||
biomes[xi * 2][zi * 2] = old[xi][zi];
|
||||
if(zi != width - 1)
|
||||
biomes[xi * 2][zi * 2 + 1] = expander.getBetween(normalise(xi) + x, normalise(zi + 1) + z, seed, old[xi][zi],
|
||||
old[xi][zi + 1]);
|
||||
if(xi != width - 1)
|
||||
biomes[xi * 2 + 1][zi * 2] = expander.getBetween(normalise(xi + 1) + x, normalise(zi) + z, seed, old[xi][zi],
|
||||
old[xi + 1][zi]);
|
||||
if(xi != width - 1 && zi != width - 1)
|
||||
biomes[xi * 2 + 1][zi * 2 + 1] = expander.getBetween(normalise(xi + 1) + x, normalise(zi + 1) + z, seed,
|
||||
old[xi][zi],
|
||||
old[xi + 1][zi + 1], old[xi][zi + 1], old[xi + 1][zi]);
|
||||
}
|
||||
}
|
||||
return new BiomeHolderImpl(biomes, origin.setX(origin.getX() * 2 - 1).setZ(origin.getZ() * 2 - 1), newWidth, offset);
|
||||
return new BiomeHolderImpl(biomes, newWidth, offset, totalWidth, originalWidth * 2 - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mutate(BiomeMutator mutator, long seed) {
|
||||
for(int x = 0; x < width; x++) {
|
||||
for(int z = 0; z < width; z++) {
|
||||
BiomeMutator.ViewPoint viewPoint = new BiomeMutator.ViewPoint(this, x, z);
|
||||
biomes[x][z] = mutator.mutate(viewPoint, x + origin.getX(), z + origin.getZ(), seed);
|
||||
public void mutate(BiomeMutator mutator, int x, int z, long seed) {
|
||||
for(int xi = 0; xi < width; xi++) {
|
||||
for(int zi = 0; zi < width; zi++) {
|
||||
BiomeMutator.ViewPoint viewPoint = new BiomeMutator.ViewPoint(this, xi, zi);
|
||||
biomes[xi][zi] = mutator.mutate(viewPoint, normalise(xi) + x, normalise(zi) + z, seed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fill(BiomeSource source, long seed) {
|
||||
for(int x = 0; x < width; x++) {
|
||||
for(int z = 0; z < width; z++) {
|
||||
biomes[x][z] = source.getBiome(origin.getX() + x, origin.getZ() + z, seed);
|
||||
public void fill(BiomeSource source, int x, int z, long seed) {
|
||||
for(int xi = 0; xi < width; xi++) {
|
||||
for(int zi = 0; zi < width; zi++) {
|
||||
biomes[xi][zi] = source.getBiome(normalise(xi) + x, normalise(zi) + z, seed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import java.util.List;
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.BiomeHolder;
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.stage.Stage;
|
||||
import com.dfsek.terra.addons.biome.pipeline.source.BiomeSource;
|
||||
import com.dfsek.terra.api.util.vector.Vector2;
|
||||
|
||||
|
||||
public class BiomePipeline {
|
||||
@@ -22,12 +21,14 @@ public class BiomePipeline {
|
||||
private final List<Stage> stages;
|
||||
private final int size;
|
||||
private final int init;
|
||||
private final int resolution;
|
||||
|
||||
private BiomePipeline(BiomeSource source, List<Stage> stages, int size, int init) {
|
||||
private BiomePipeline(BiomeSource source, List<Stage> stages, int size, int init, int resolution) {
|
||||
this.source = source;
|
||||
this.stages = stages;
|
||||
this.size = size;
|
||||
this.init = init;
|
||||
this.resolution = resolution;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,9 +40,13 @@ public class BiomePipeline {
|
||||
* @return BiomeHolder containing biomes.
|
||||
*/
|
||||
public BiomeHolder getBiomes(int x, int z, long seed) {
|
||||
BiomeHolder holder = new BiomeHolderImpl(init, Vector2.of(x * (init - 1), z * (init - 1)).mutable());
|
||||
holder.fill(source, seed);
|
||||
for(Stage stage : stages) holder = stage.apply(holder, seed);
|
||||
x *= size;
|
||||
z *= size;
|
||||
BiomeHolder holder = new BiomeHolderImpl(init, size);
|
||||
holder.fill(source, x, z, seed);
|
||||
for(Stage stage : stages) {
|
||||
holder = stage.apply(holder, x, z, seed);
|
||||
}
|
||||
return holder;
|
||||
}
|
||||
|
||||
@@ -61,10 +66,12 @@ public class BiomePipeline {
|
||||
private final int init;
|
||||
private final List<Stage> stages = new ArrayList<>();
|
||||
private int expand;
|
||||
private final int resolution;
|
||||
|
||||
public BiomePipelineBuilder(int init) {
|
||||
public BiomePipelineBuilder(int init, int resolution) {
|
||||
this.init = init;
|
||||
expand = init;
|
||||
this.resolution = resolution;
|
||||
}
|
||||
|
||||
public BiomePipeline build(BiomeSource source) {
|
||||
@@ -72,7 +79,7 @@ public class BiomePipeline {
|
||||
if(stage.isExpansion()) expand = expand * 2 - 1;
|
||||
}
|
||||
|
||||
return new BiomePipeline(source, stages, expand, init);
|
||||
return new BiomePipeline(source, stages, expand, init, resolution);
|
||||
}
|
||||
|
||||
public BiomePipelineBuilder addStage(Stage stage) {
|
||||
|
||||
@@ -14,11 +14,11 @@ import com.dfsek.terra.addons.biome.pipeline.source.BiomeSource;
|
||||
|
||||
|
||||
public interface BiomeHolder {
|
||||
BiomeHolder expand(BiomeExpander expander, long seed);
|
||||
BiomeHolder expand(BiomeExpander expander, int x, int z, long seed);
|
||||
|
||||
void mutate(BiomeMutator mutator, long seed);
|
||||
void mutate(BiomeMutator mutator, int x, int z, long seed);
|
||||
|
||||
void fill(BiomeSource source, long seed);
|
||||
void fill(BiomeSource source, int x, int z, long seed);
|
||||
|
||||
BiomeDelegate getBiome(int x, int z);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import com.dfsek.terra.addons.biome.pipeline.api.delegate.BiomeDelegate;
|
||||
|
||||
|
||||
public interface Stage {
|
||||
BiomeHolder apply(BiomeHolder in, long seed);
|
||||
BiomeHolder apply(BiomeHolder in, int x, int z, long seed);
|
||||
|
||||
boolean isExpansion();
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public class BiomePipelineTemplate extends BiomeProviderTemplate {
|
||||
|
||||
@Override
|
||||
public BiomeProvider get() {
|
||||
BiomePipeline.BiomePipelineBuilder biomePipelineBuilder = new BiomePipeline.BiomePipelineBuilder(initialSize);
|
||||
BiomePipeline.BiomePipelineBuilder biomePipelineBuilder = new BiomePipeline.BiomePipelineBuilder(initialSize, resolution);
|
||||
stages.forEach(biomePipelineBuilder::addStage);
|
||||
BiomePipeline pipeline = biomePipelineBuilder.build(source);
|
||||
return new BiomePipelineProvider(pipeline, resolution, blend, blendAmp);
|
||||
|
||||
@@ -21,8 +21,8 @@ public class ExpanderStage implements Stage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeHolder apply(BiomeHolder in, long seed) {
|
||||
return in.expand(expander, seed);
|
||||
public BiomeHolder apply(BiomeHolder in, int x, int z, long seed) {
|
||||
return in.expand(expander, x, z, seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,8 +21,8 @@ public class MutatorStage implements Stage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeHolder apply(BiomeHolder in, long seed) {
|
||||
in.mutate(mutator, seed);
|
||||
public BiomeHolder apply(BiomeHolder in, int x, int z, long seed) {
|
||||
in.mutate(mutator, x, z, seed);
|
||||
return in;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user