Increased max cache size and fixed caching on method.
This commit is contained in:
parent
2d9163f5c2
commit
2e67cb90ca
@ -29,7 +29,7 @@ public class IslandWorldMapper implements CoordinateValidatable {
|
||||
dfs = new DepthFirstSearch(this);
|
||||
this.noiseGenerator = new SimplexOctaveGenerator(random, noiseOctaves);
|
||||
noiseGenerator.setScale(scale);
|
||||
blockValueCache = new Cache<>(1024);
|
||||
blockValueCache = new Cache<>(4096);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -113,29 +113,30 @@ public class IslandWorldMapper implements CoordinateValidatable {
|
||||
* @return a value representing the island at the given point.
|
||||
*/
|
||||
public double getWorldBlockValue(int worldX, int worldZ) {
|
||||
CoordinateIdentifier coords = new CoordinateIdentifier(worldX, worldZ);
|
||||
CacheValue<Double> cacheVal = blockValueCache.retrieveCache(coords);
|
||||
if (!cacheVal.isEmpty()) return cacheVal.getValue();
|
||||
CacheValue<Double> cacheVal = blockValueCache.retrieveCache(new CoordinateIdentifier(worldX, worldZ));
|
||||
if (cacheVal.isEmpty()) {
|
||||
double portionSea = 1f - (this.islandBlockGenerationPercent / 100f);
|
||||
double shift = 1f - 2 * portionSea;
|
||||
double rawNoise = noiseGenerator.noise(worldX, worldZ, noiseFrequency, noiseAmplitude, true);
|
||||
double noise = 0;
|
||||
if (rawNoise < 0) {
|
||||
noise = ( - Math.pow(- rawNoise, exaggerationFactor) + shift);
|
||||
} else {
|
||||
noise = Math.pow(rawNoise, islandValueExaggerationFactor) + shift;
|
||||
}
|
||||
double maxNeg = -1 + shift;
|
||||
double maxPos = 1 + shift;
|
||||
|
||||
double portionSea = 1f - (this.islandBlockGenerationPercent / 100f);
|
||||
double shift = 1f - 2 * portionSea;
|
||||
double rawNoise = noiseGenerator.noise(worldX, worldZ, noiseFrequency, noiseAmplitude, true);
|
||||
double noise = 0;
|
||||
if (rawNoise < 0) {
|
||||
noise = ( - Math.pow(- rawNoise, exaggerationFactor) + shift);
|
||||
} else {
|
||||
noise = Math.pow(rawNoise, islandValueExaggerationFactor) + shift;
|
||||
double res = 0;
|
||||
if (noise < 0) {
|
||||
res = - noise / maxNeg;
|
||||
} else {
|
||||
res = noise / maxPos;
|
||||
}
|
||||
cacheVal.setValue(res);
|
||||
}
|
||||
double maxNeg = -1 + shift;
|
||||
double maxPos = 1 + shift;
|
||||
|
||||
double res = 0;
|
||||
if (noise < 0) {
|
||||
res = - noise / maxNeg;
|
||||
}
|
||||
res = noise / maxPos;
|
||||
cacheVal.setValue(res);
|
||||
return res;
|
||||
return cacheVal.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -151,7 +152,7 @@ public class IslandWorldMapper implements CoordinateValidatable {
|
||||
if (!isIsland(firstBlockX, firstBlockZ)) return false;
|
||||
if (!isIsland(secondBlockX, secondBlockZ)) return false;
|
||||
dfs.setStartPosition(firstBlockX, firstBlockZ);
|
||||
dfs.setDirectionPosition(secondBlockX, secondBlockZ);
|
||||
dfs.setEndPosition(secondBlockX, secondBlockZ);
|
||||
boolean res = dfs.buildPathToEndNode();
|
||||
dfs.deleteTree();
|
||||
return res;
|
||||
|
Loading…
Reference in New Issue
Block a user