Added caching solution to temperature map generator.
This commit is contained in:
parent
6c8389d60e
commit
60ab555c57
@ -4,18 +4,29 @@ import java.util.Random;
|
||||
|
||||
import org.bukkit.util.noise.SimplexOctaveGenerator;
|
||||
|
||||
import ca.recrown.islandsurvivalcraft.caching.Cache;
|
||||
import ca.recrown.islandsurvivalcraft.caching.CacheValue;
|
||||
import ca.recrown.islandsurvivalcraft.caching.CoordinateIdentifier;
|
||||
|
||||
class TemperatureMapGenerator {
|
||||
private final Cache<Float> temperatureCache;
|
||||
private final double frequency = 0.5D;
|
||||
private final double amplitude = 0.5D;
|
||||
|
||||
private SimplexOctaveGenerator noiseGenerator;
|
||||
|
||||
public TemperatureMapGenerator() {
|
||||
temperatureCache = new Cache<>(1024);
|
||||
}
|
||||
|
||||
public void setSeed(long seed) {
|
||||
noiseGenerator = new SimplexOctaveGenerator(new Random(seed), 4);
|
||||
noiseGenerator.setScale(0.0008D);
|
||||
noiseGenerator = new SimplexOctaveGenerator(new Random(seed), 2);
|
||||
noiseGenerator.setScale(0.005D);
|
||||
}
|
||||
|
||||
public float getTemperature(int worldX, int worldZ) {
|
||||
return (float) noiseGenerator.noise(worldX, worldZ, frequency, amplitude, true);
|
||||
CacheValue<Float> val = temperatureCache.retrieveCache(new CoordinateIdentifier(worldX/4, worldZ/4));
|
||||
if (val.isEmpty()) val.setValue((float) noiseGenerator.noise(worldX/4, worldZ/4, frequency, amplitude, true));
|
||||
return val.getValue();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user