Increased max cache size and fixed caching on method.

This commit is contained in:
Harrison Deng 2020-04-24 15:10:03 -05:00
parent 2d9163f5c2
commit 2e67cb90ca

View File

@ -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,10 +113,8 @@ 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 portionSea = 1f - (this.islandBlockGenerationPercent / 100f);
double shift = 1f - 2 * portionSea; double shift = 1f - 2 * portionSea;
double rawNoise = noiseGenerator.noise(worldX, worldZ, noiseFrequency, noiseAmplitude, true); double rawNoise = noiseGenerator.noise(worldX, worldZ, noiseFrequency, noiseAmplitude, true);
@ -132,10 +130,13 @@ public class IslandWorldMapper implements CoordinateValidatable {
double res = 0; double res = 0;
if (noise < 0) { if (noise < 0) {
res = - noise / maxNeg; res = - noise / maxNeg;
} } else {
res = noise / maxPos; res = noise / maxPos;
}
cacheVal.setValue(res); 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(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;