mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-08 16:56:07 +00:00
implement BiomePipeline
This commit is contained in:
25
common/src/main/java/com/dfsek/terra/biome/BiomeCache.java
Normal file
25
common/src/main/java/com/dfsek/terra/biome/BiomeCache.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.dfsek.terra.biome;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Vector2;
|
||||
import com.dfsek.terra.biome.pipeline.BiomeHolder;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BiomeCache {
|
||||
LoadingCache<Vector2, BiomeHolder> cache;
|
||||
|
||||
public BiomeCache() {
|
||||
cache = CacheBuilder.newBuilder()
|
||||
.maximumSize(1024)
|
||||
.build(
|
||||
new CacheLoader<Vector2, BiomeHolder>() {
|
||||
@Override
|
||||
public BiomeHolder load(@NotNull Vector2 key) throws Exception {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.dfsek.terra.biome.pipeline;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Vector2;
|
||||
import com.dfsek.terra.api.util.GlueList;
|
||||
import com.dfsek.terra.biome.pipeline.source.BiomeSource;
|
||||
import com.dfsek.terra.biome.pipeline.stages.Stage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BiomePipeline {
|
||||
private final BiomeSource source;
|
||||
private final List<Stage> stages;
|
||||
private final int size;
|
||||
private final int init;
|
||||
|
||||
private BiomePipeline(BiomeSource source, List<Stage> stages, int size, int init) {
|
||||
this.source = source;
|
||||
this.stages = stages;
|
||||
this.size = size;
|
||||
this.init = init;
|
||||
}
|
||||
|
||||
public BiomeHolder getBiomes(int x, int z) {
|
||||
BiomeHolder holder = new TerraBiomeHolder(25, new Vector2(x * (init - 1), z * (init - 1)));
|
||||
holder.fill(source);
|
||||
for(Stage stage : stages) holder = stage.apply(holder);
|
||||
return holder;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public static final class BiomePipelineBuilder {
|
||||
private final int init;
|
||||
List<Stage> stages = new GlueList<>();
|
||||
private int expand;
|
||||
|
||||
public BiomePipelineBuilder(int init) {
|
||||
this.init = init;
|
||||
expand = init;
|
||||
}
|
||||
|
||||
public BiomePipeline build(BiomeSource source) {
|
||||
return new BiomePipeline(source, stages, expand, init);
|
||||
}
|
||||
|
||||
public BiomePipelineBuilder addStage(Stage stage) {
|
||||
stages.add(stage);
|
||||
if(stage.isExpansion()) expand = expand * 2 - 1;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.dfsek.terra.biome.pipeline;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Vector2;
|
||||
|
||||
public class Position {
|
||||
private final int x;
|
||||
private final int y;
|
||||
|
||||
public Position(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public Vector2 getAsVector() {
|
||||
return new Vector2(x, y);
|
||||
}
|
||||
|
||||
public Position newFromAdd(Position other) {
|
||||
return new Position(x + other.getX(), y + other.getY());
|
||||
}
|
||||
|
||||
public Position newMultiply(int m) {
|
||||
return new Position(x * m, y * m);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.dfsek.terra.biome.pipeline.stages;
|
||||
|
||||
import com.dfsek.terra.biome.pipeline.BiomeHolder;
|
||||
import com.dfsek.terra.biome.pipeline.expand.BiomeExpander;
|
||||
|
||||
public class ExpanderStage implements Stage {
|
||||
private final BiomeExpander expander;
|
||||
|
||||
public ExpanderStage(BiomeExpander expander) {
|
||||
this.expander = expander;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExpansion() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeHolder apply(BiomeHolder in) {
|
||||
return in.expand(expander);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.dfsek.terra.biome.pipeline.stages;
|
||||
|
||||
import com.dfsek.terra.biome.pipeline.BiomeHolder;
|
||||
import com.dfsek.terra.biome.pipeline.mutator.BiomeMutator;
|
||||
|
||||
public class MutatorStage implements Stage {
|
||||
private final BiomeMutator mutator;
|
||||
|
||||
public MutatorStage(BiomeMutator mutator) {
|
||||
this.mutator = mutator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExpansion() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeHolder apply(BiomeHolder in) {
|
||||
in.mutate(mutator);
|
||||
return in;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.dfsek.terra.biome.pipeline.stages;
|
||||
|
||||
import com.dfsek.terra.biome.pipeline.BiomeHolder;
|
||||
|
||||
public interface Stage {
|
||||
boolean isExpansion();
|
||||
|
||||
BiomeHolder apply(BiomeHolder in);
|
||||
}
|
||||
Reference in New Issue
Block a user