use of org.terasology.utilities.procedural.WhiteNoise in project Terasology by MovingBlocks.
the class FloraRasterizer method generateChunk.
@Override
public void generateChunk(CoreChunk chunk, Region chunkRegion) {
FloraFacet facet = chunkRegion.getFacet(FloraFacet.class);
WhiteNoise noise = new WhiteNoise(chunk.getPosition().hashCode());
Map<BaseVector3i, FloraType> entries = facet.getRelativeEntries();
// check if some other rasterizer has already placed something here
entries.keySet().stream().filter(pos -> chunk.getBlock(pos).equals(air)).forEach(pos -> {
FloraType type = entries.get(pos);
List<Block> list = flora.get(type);
int blockIdx = Math.abs(noise.intNoise(pos.x(), pos.y(), pos.z())) % list.size();
Block block = list.get(blockIdx);
chunk.setBlock(pos, block);
});
}
use of org.terasology.utilities.procedural.WhiteNoise in project Terasology by MovingBlocks.
the class WhiteNoiseTest method testDistribution.
@Test
public void testDistribution() {
FastRandom rng = new FastRandom(0xBEEF);
WhiteNoise noiseGen = new WhiteNoise(0xDEADC0DE);
int count = 100000;
int bucketCount = 20;
int[] buckets = new int[bucketCount];
for (int i = 0; i < count; i++) {
float posX = rng.nextFloat() * 100f;
float posY = rng.nextFloat() * 100f;
float posZ = rng.nextFloat() * 100f;
float noise = 0.5f + 0.5f * noiseGen.noise(posX, posY, posZ);
int idx = (int) (noise * bucketCount);
if (idx == bucketCount) {
idx = bucketCount - 1;
}
buckets[idx]++;
}
float avg = count / bucketCount;
for (int i = 0; i < bucketCount; i++) {
float val = Math.abs((buckets[i] - avg) / avg);
// less than 5% deviation from the expected average
Assert.assertTrue(val < 0.05);
}
}
use of org.terasology.utilities.procedural.WhiteNoise in project Terasology by MovingBlocks.
the class DefaultFloraProvider method setSeed.
@Override
public void setSeed(long seed) {
super.setSeed(seed);
densityNoiseGen = new WhiteNoise(seed);
}
use of org.terasology.utilities.procedural.WhiteNoise in project Terasology by MovingBlocks.
the class DefaultTreeProvider method setSeed.
@Override
public void setSeed(long seed) {
super.setSeed(seed);
densityNoiseGen = new WhiteNoise(seed);
}
Aggregations