fix #264 with artifacting

This commit is contained in:
dfsek
2022-07-16 03:34:59 -07:00
parent a175601424
commit 145eed893a
7 changed files with 60 additions and 45 deletions

View File

@@ -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.BiomeExpander;
import com.dfsek.terra.addons.biome.pipeline.api.stage.type.BiomeMutator; import com.dfsek.terra.addons.biome.pipeline.api.stage.type.BiomeMutator;
import com.dfsek.terra.addons.biome.pipeline.source.BiomeSource; import com.dfsek.terra.addons.biome.pipeline.source.BiomeSource;
import com.dfsek.terra.api.util.vector.Vector2;
public class BiomeHolderImpl implements BiomeHolder { public class BiomeHolderImpl implements BiomeHolder {
private final Vector2.Mutable origin;
private final int width; private final int width;
private final int offset; private final int offset;
private final double totalWidth;
private final int originalWidth;
private BiomeDelegate[][] biomes; private BiomeDelegate[][] biomes;
public BiomeHolderImpl(int width, Vector2.Mutable origin) { public BiomeHolderImpl(int width, double totalWidth) {
this.totalWidth = totalWidth;
this.originalWidth = width;
width += 4; width += 4;
this.width = width; this.width = width;
biomes = new BiomeDelegate[width][width]; biomes = new BiomeDelegate[width][width];
this.origin = origin;
this.offset = 2; 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.biomes = biomes;
this.origin = origin;
this.width = width; this.width = width;
this.offset = 2 * offset; this.offset = 2 * offset;
this.totalWidth = totalWidth;
this.originalWidth = originalWidth;
}
private double normalise(double in) {
return totalWidth * ((in - offset) / originalWidth);
} }
@Override @Override
public BiomeHolder expand(BiomeExpander expander, long seed) { public BiomeHolder expand(BiomeExpander expander, int x, int z, long seed) {
BiomeDelegate[][] old = biomes; BiomeDelegate[][] old = biomes;
int newWidth = width * 2 - 1; int newWidth = width * 2 - 1;
biomes = new BiomeDelegate[newWidth][newWidth]; biomes = new BiomeDelegate[newWidth][newWidth];
for(int x = 0; x < width; x++) {
for(int z = 0; z < width; z++) { for(int xi = 0; xi < width; xi++) {
biomes[x * 2][z * 2] = old[x][z]; for(int zi = 0; zi < width; zi++) {
if(z != width - 1) biomes[xi * 2][zi * 2] = old[xi][zi];
biomes[x * 2][z * 2 + 1] = expander.getBetween(x + origin.getX(), z + 1 + origin.getZ(), seed, old[x][z], if(zi != width - 1)
old[x][z + 1]); biomes[xi * 2][zi * 2 + 1] = expander.getBetween(normalise(xi) + x, normalise(zi + 1) + z, seed, old[xi][zi],
if(x != width - 1) old[xi][zi + 1]);
biomes[x * 2 + 1][z * 2] = expander.getBetween(x + 1 + origin.getX(), z + origin.getZ(), seed, old[x][z], if(xi != width - 1)
old[x + 1][z]); biomes[xi * 2 + 1][zi * 2] = expander.getBetween(normalise(xi + 1) + x, normalise(zi) + z, seed, old[xi][zi],
if(x != width - 1 && z != width - 1) old[xi + 1][zi]);
biomes[x * 2 + 1][z * 2 + 1] = expander.getBetween(x + 1 + origin.getX(), z + 1 + origin.getZ(), seed, old[x][z], if(xi != width - 1 && zi != width - 1)
old[x + 1][z + 1], old[x][z + 1], old[x + 1][z]); 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 @Override
public void mutate(BiomeMutator mutator, long seed) { public void mutate(BiomeMutator mutator, int x, int z, long seed) {
for(int x = 0; x < width; x++) { for(int xi = 0; xi < width; xi++) {
for(int z = 0; z < width; z++) { for(int zi = 0; zi < width; zi++) {
BiomeMutator.ViewPoint viewPoint = new BiomeMutator.ViewPoint(this, x, z); BiomeMutator.ViewPoint viewPoint = new BiomeMutator.ViewPoint(this, xi, zi);
biomes[x][z] = mutator.mutate(viewPoint, x + origin.getX(), z + origin.getZ(), seed); biomes[xi][zi] = mutator.mutate(viewPoint, normalise(xi) + x, normalise(zi) + z, seed);
} }
} }
} }
@Override @Override
public void fill(BiomeSource source, long seed) { public void fill(BiomeSource source, int x, int z, long seed) {
for(int x = 0; x < width; x++) { for(int xi = 0; xi < width; xi++) {
for(int z = 0; z < width; z++) { for(int zi = 0; zi < width; zi++) {
biomes[x][z] = source.getBiome(origin.getX() + x, origin.getZ() + z, seed); biomes[xi][zi] = source.getBiome(normalise(xi) + x, normalise(zi) + z, seed);
} }
} }
} }

View File

@@ -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.BiomeHolder;
import com.dfsek.terra.addons.biome.pipeline.api.stage.Stage; import com.dfsek.terra.addons.biome.pipeline.api.stage.Stage;
import com.dfsek.terra.addons.biome.pipeline.source.BiomeSource; import com.dfsek.terra.addons.biome.pipeline.source.BiomeSource;
import com.dfsek.terra.api.util.vector.Vector2;
public class BiomePipeline { public class BiomePipeline {
@@ -22,12 +21,14 @@ public class BiomePipeline {
private final List<Stage> stages; private final List<Stage> stages;
private final int size; private final int size;
private final int init; 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.source = source;
this.stages = stages; this.stages = stages;
this.size = size; this.size = size;
this.init = init; this.init = init;
this.resolution = resolution;
} }
/** /**
@@ -39,9 +40,13 @@ public class BiomePipeline {
* @return BiomeHolder containing biomes. * @return BiomeHolder containing biomes.
*/ */
public BiomeHolder getBiomes(int x, int z, long seed) { public BiomeHolder getBiomes(int x, int z, long seed) {
BiomeHolder holder = new BiomeHolderImpl(init, Vector2.of(x * (init - 1), z * (init - 1)).mutable()); x *= size;
holder.fill(source, seed); z *= size;
for(Stage stage : stages) holder = stage.apply(holder, seed); 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; return holder;
} }
@@ -61,10 +66,12 @@ public class BiomePipeline {
private final int init; private final int init;
private final List<Stage> stages = new ArrayList<>(); private final List<Stage> stages = new ArrayList<>();
private int expand; private int expand;
private final int resolution;
public BiomePipelineBuilder(int init) { public BiomePipelineBuilder(int init, int resolution) {
this.init = init; this.init = init;
expand = init; expand = init;
this.resolution = resolution;
} }
public BiomePipeline build(BiomeSource source) { public BiomePipeline build(BiomeSource source) {
@@ -72,7 +79,7 @@ public class BiomePipeline {
if(stage.isExpansion()) expand = expand * 2 - 1; 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) { public BiomePipelineBuilder addStage(Stage stage) {

View File

@@ -14,11 +14,11 @@ import com.dfsek.terra.addons.biome.pipeline.source.BiomeSource;
public interface BiomeHolder { 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); BiomeDelegate getBiome(int x, int z);

View File

@@ -12,7 +12,7 @@ import com.dfsek.terra.addons.biome.pipeline.api.delegate.BiomeDelegate;
public interface Stage { public interface Stage {
BiomeHolder apply(BiomeHolder in, long seed); BiomeHolder apply(BiomeHolder in, int x, int z, long seed);
boolean isExpansion(); boolean isExpansion();

View File

@@ -46,7 +46,7 @@ public class BiomePipelineTemplate extends BiomeProviderTemplate {
@Override @Override
public BiomeProvider get() { public BiomeProvider get() {
BiomePipeline.BiomePipelineBuilder biomePipelineBuilder = new BiomePipeline.BiomePipelineBuilder(initialSize); BiomePipeline.BiomePipelineBuilder biomePipelineBuilder = new BiomePipeline.BiomePipelineBuilder(initialSize, resolution);
stages.forEach(biomePipelineBuilder::addStage); stages.forEach(biomePipelineBuilder::addStage);
BiomePipeline pipeline = biomePipelineBuilder.build(source); BiomePipeline pipeline = biomePipelineBuilder.build(source);
return new BiomePipelineProvider(pipeline, resolution, blend, blendAmp); return new BiomePipelineProvider(pipeline, resolution, blend, blendAmp);

View File

@@ -21,8 +21,8 @@ public class ExpanderStage implements Stage {
} }
@Override @Override
public BiomeHolder apply(BiomeHolder in, long seed) { public BiomeHolder apply(BiomeHolder in, int x, int z, long seed) {
return in.expand(expander, seed); return in.expand(expander, x, z, seed);
} }
@Override @Override

View File

@@ -21,8 +21,8 @@ public class MutatorStage implements Stage {
} }
@Override @Override
public BiomeHolder apply(BiomeHolder in, long seed) { public BiomeHolder apply(BiomeHolder in, int x, int z, long seed) {
in.mutate(mutator, seed); in.mutate(mutator, x, z, seed);
return in; return in;
} }