Search in sources :

Example 1 with WhiteNoise

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);
    });
}
Also used : BlockManager(org.terasology.world.block.BlockManager) Region(org.terasology.world.generation.Region) WorldRasterizer(org.terasology.world.generation.WorldRasterizer) Maps(com.google.common.collect.Maps) FloraFacet(org.terasology.core.world.generator.facets.FloraFacet) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) BaseVector3i(org.terasology.math.geom.BaseVector3i) Block(org.terasology.world.block.Block) CoreChunk(org.terasology.world.chunks.CoreChunk) Map(java.util.Map) CoreRegistry(org.terasology.registry.CoreRegistry) WhiteNoise(org.terasology.utilities.procedural.WhiteNoise) FloraFacet(org.terasology.core.world.generator.facets.FloraFacet) WhiteNoise(org.terasology.utilities.procedural.WhiteNoise) BaseVector3i(org.terasology.math.geom.BaseVector3i) Block(org.terasology.world.block.Block)

Example 2 with WhiteNoise

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);
    }
}
Also used : WhiteNoise(org.terasology.utilities.procedural.WhiteNoise) FastRandom(org.terasology.utilities.random.FastRandom) Test(org.junit.Test)

Example 3 with WhiteNoise

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);
}
Also used : WhiteNoise(org.terasology.utilities.procedural.WhiteNoise)

Example 4 with WhiteNoise

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);
}
Also used : WhiteNoise(org.terasology.utilities.procedural.WhiteNoise)

Aggregations

WhiteNoise (org.terasology.utilities.procedural.WhiteNoise)4 ImmutableList (com.google.common.collect.ImmutableList)1 Maps (com.google.common.collect.Maps)1 List (java.util.List)1 Map (java.util.Map)1 Test (org.junit.Test)1 FloraFacet (org.terasology.core.world.generator.facets.FloraFacet)1 BaseVector3i (org.terasology.math.geom.BaseVector3i)1 CoreRegistry (org.terasology.registry.CoreRegistry)1 FastRandom (org.terasology.utilities.random.FastRandom)1 Block (org.terasology.world.block.Block)1 BlockManager (org.terasology.world.block.BlockManager)1 CoreChunk (org.terasology.world.chunks.CoreChunk)1 Region (org.terasology.world.generation.Region)1 WorldRasterizer (org.terasology.world.generation.WorldRasterizer)1