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);
|
dfs = new DepthFirstSearch(this);
|
||||||
this.noiseGenerator = new SimplexOctaveGenerator(random, noiseOctaves);
|
this.noiseGenerator = new SimplexOctaveGenerator(random, noiseOctaves);
|
||||||
noiseGenerator.setScale(scale);
|
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.
|
* @return a value representing the island at the given point.
|
||||||
*/
|
*/
|
||||||
public double getWorldBlockValue(int worldX, int worldZ) {
|
public double getWorldBlockValue(int worldX, int worldZ) {
|
||||||
CoordinateIdentifier coords = new CoordinateIdentifier(worldX, worldZ);
|
CacheValue<Double> cacheVal = blockValueCache.retrieveCache(new CoordinateIdentifier(worldX, worldZ));
|
||||||
CacheValue<Double> cacheVal = blockValueCache.retrieveCache(coords);
|
if (cacheVal.isEmpty()) {
|
||||||
if (!cacheVal.isEmpty()) return cacheVal.getValue();
|
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 res = 0;
|
||||||
double shift = 1f - 2 * portionSea;
|
if (noise < 0) {
|
||||||
double rawNoise = noiseGenerator.noise(worldX, worldZ, noiseFrequency, noiseAmplitude, true);
|
res = - noise / maxNeg;
|
||||||
double noise = 0;
|
} else {
|
||||||
if (rawNoise < 0) {
|
res = noise / maxPos;
|
||||||
noise = ( - Math.pow(- rawNoise, exaggerationFactor) + shift);
|
}
|
||||||
} else {
|
cacheVal.setValue(res);
|
||||||
noise = Math.pow(rawNoise, islandValueExaggerationFactor) + shift;
|
|
||||||
}
|
}
|
||||||
double maxNeg = -1 + shift;
|
|
||||||
double maxPos = 1 + shift;
|
|
||||||
|
|
||||||
double res = 0;
|
return cacheVal.getValue();
|
||||||
if (noise < 0) {
|
|
||||||
res = - noise / maxNeg;
|
|
||||||
}
|
|
||||||
res = noise / maxPos;
|
|
||||||
cacheVal.setValue(res);
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -151,7 +152,7 @@ public class IslandWorldMapper implements CoordinateValidatable {
|
|||||||
if (!isIsland(firstBlockX, firstBlockZ)) return false;
|
if (!isIsland(firstBlockX, firstBlockZ)) return false;
|
||||||
if (!isIsland(secondBlockX, secondBlockZ)) return false;
|
if (!isIsland(secondBlockX, secondBlockZ)) return false;
|
||||||
dfs.setStartPosition(firstBlockX, firstBlockZ);
|
dfs.setStartPosition(firstBlockX, firstBlockZ);
|
||||||
dfs.setDirectionPosition(secondBlockX, secondBlockZ);
|
dfs.setEndPosition(secondBlockX, secondBlockZ);
|
||||||
boolean res = dfs.buildPathToEndNode();
|
boolean res = dfs.buildPathToEndNode();
|
||||||
dfs.deleteTree();
|
dfs.deleteTree();
|
||||||
return res;
|
return res;
|
||||||
|
Loading…
Reference in New Issue
Block a user