DFS's should now run locally on each thread.

This commit is contained in:
Harrison Deng 2020-04-26 16:47:22 -05:00
parent faa2cfd79f
commit e8340bfc91

View File

@ -21,10 +21,6 @@ public class BiomePerIslandGenerator implements IslandBiomeGenerator {
private volatile IslandWorldMapper worldIslandMap;
private volatile BiomeSelector biomeSelector;
private volatile World world;
private final DepthFirstSearch freshCachePropagator;
private final DepthFirstSearch existenceChecker;
private final FreshCachePropagationInfo freshCachePropInfo;
private final PreviousGenerationInfo existenceInfo;
private volatile Point2 currChunkCoords;
private volatile Biome[][] localChunkCache;
@ -32,12 +28,8 @@ public class BiomePerIslandGenerator implements IslandBiomeGenerator {
public BiomePerIslandGenerator() {
this.temperatureMapGenerator = new TemperatureMapGenerator();
chunkBiomesCache = new Cache<>(4096);
chunkBiomesCache = new Cache<>(8192);
chunkGenStatusCache = new Cache<>(4096);
freshCachePropInfo = new FreshCachePropagationInfo();
freshCachePropagator = new DepthFirstSearch(freshCachePropInfo);
existenceInfo = new PreviousGenerationInfo();
existenceChecker = new DepthFirstSearch(existenceInfo);
localChunkCache = new Biome[16][16];
}
@ -72,16 +64,19 @@ public class BiomePerIslandGenerator implements IslandBiomeGenerator {
if (!worldIslandMap.isIsland(worldX, worldZ)) {
return biomeSelector.getOceanBiome(temperature);
}
freshCachePropInfo.clear();
existenceChecker.setStartPosition(worldX, worldZ);
if (!existenceChecker.findTarget(existenceInfo)) {
if (freshCachePropInfo.main == null) freshCachePropInfo.main = biomeSelector.getLandBiome(temperature);
if (freshCachePropInfo.shore == null) freshCachePropInfo.shore = biomeSelector.getShoreBiome(freshCachePropInfo.main, temperature);
if (freshCachePropInfo.shallow == null) freshCachePropInfo.shallow = biomeSelector.getOceanBiome(temperature);
IslandBiomeInfo biomeInfo = new IslandBiomeInfo();
DepthFirstSearch prevBiomeFinder = new DepthFirstSearch(biomeInfo);
prevBiomeFinder.setStartPosition(worldX, worldZ);
if (!prevBiomeFinder.findTarget(biomeInfo)) {
if (biomeInfo.main == null) biomeInfo.main = biomeSelector.getLandBiome(temperature);
if (biomeInfo.shore == null) biomeInfo.shore = biomeSelector.getShoreBiome(biomeInfo.main, temperature);
if (biomeInfo.shallow == null) biomeInfo.shallow = biomeSelector.getOceanBiome(temperature);
}
freshCachePropagator.setStartPosition(worldX, worldZ);
freshCachePropagator.findTarget(freshCachePropInfo);
FreshCachePropagationInfo propInfo = new FreshCachePropagationInfo(biomeInfo.main, biomeInfo.shore, biomeInfo.shallow);
DepthFirstSearch prop = new DepthFirstSearch(propInfo);
prop.setStartPosition(worldX, worldZ);
prop.findTarget(propInfo);
return getBiome(worldX, worldZ);
}
@ -130,9 +125,7 @@ public class BiomePerIslandGenerator implements IslandBiomeGenerator {
}
private class FreshCachePropagationInfo implements CoordinateTargetValidatable, CoordinateValidatable {
public Biome shore;
public Biome main;
public Biome shallow;
public final Biome main, shore, shallow;
@Override
public boolean isCoordinateTarget(int x, int y) {
@ -154,37 +147,47 @@ public class BiomePerIslandGenerator implements IslandBiomeGenerator {
return chunkCoords.fastEquals(currChunkCoords) && worldIslandMap.isIsland(x, y);
}
public boolean allBiomesAcquired() {
return shore != null && main != null && shallow != null;
}
public void clear() {
main = null;
shore = null;
shallow = null;
public FreshCachePropagationInfo(Biome main, Biome shore, Biome shallow) {
this.main = main;
this.shore = shore;
this.shallow = shallow;
}
}
private class PreviousGenerationInfo implements CoordinateTargetValidatable, CoordinateValidatable {
private class IslandBiomeInfo implements CoordinateTargetValidatable, CoordinateValidatable {
private boolean isLand, isShore, isShallow;
public Biome main, shore, shallow;
@Override
public boolean validate(int x, int y) {
isShore = false;
isShallow = false;
isLand = false;
return worldIslandMap.isIsland(x, y);
}
@Override
public boolean isCoordinateTarget(int x, int y) {
if (freshCachePropInfo.main == null && worldIslandMap.isLand(x, y) && !worldIslandMap.isShore(x, y)) {
freshCachePropInfo.main = getBiome(x, y);
if ((isLand = worldIslandMap.isLand(x, y))) {
isShore = worldIslandMap.isShore(x, y);
} else {
isShallow = worldIslandMap.isShallowPortion(x, y);
}
if (freshCachePropInfo.shore == null && worldIslandMap.isShore(x, y)) {
freshCachePropInfo.shore = getBiome(x, y);
if (main == null && isLand && !isShore) {
main = getBiome(x, y);
} else
if (shore == null && isShore) {
shore = getBiome(x, y);
} else
if (shallow == null && isShallow) {
shallow = getBiome(x, y);
}
if (freshCachePropInfo.shallow == null && worldIslandMap.isShallowPortion(x, y)) {
freshCachePropInfo.shallow = getBiome(x, y);
}
return freshCachePropInfo.allBiomesAcquired();
return allBiomesAcquired();
}
public boolean allBiomesAcquired() {
return shore != null && main != null && shallow != null;
}
}
}