Examples of FastRandom


Examples of org.terasology.utilities.random.FastRandom

public class NoiseTable {

    private final int[] noisePermutations;

    public NoiseTable(long seed) {
        FastRandom rand = new FastRandom(seed);

        noisePermutations = new int[512];
        int[] noiseTable = new int[256];

        // Init. the noise table
        for (int i = 0; i < 256; i++) {
            noiseTable[i] = i;
        }

        // Shuffle the array
        for (int i = 0; i < 256; i++) {
            int j = rand.nextInt(256);

            int swap = noiseTable[i];
            noiseTable[i] = noiseTable[j];
            noiseTable[j] = swap;
        }
View Full Code Here

Examples of org.terasology.utilities.random.FastRandom

    @ReceiveEvent(components = {InventoryComponent.class, DropBlockInventoryComponent.class, LocationComponent.class})
    public void dropContentsOfInventory(DoDestroyEvent event, EntityRef entity) {
        Vector3f position = entity.getComponent(LocationComponent.class).getWorldPosition();

        FastRandom random = new FastRandom();
        int slotCount = InventoryUtils.getSlotCount(entity);
        for (int i = 0; i < slotCount; i++) {
            EntityRef itemInSlot = InventoryUtils.getItemAt(entity, i);
            if (itemInSlot.exists()) {
                EntityRef pickup = pickupBuilder.createPickupFor(itemInSlot, position, 60, true);
                pickup.send(new ImpulseEvent(random.nextVector3f(30.0f)));
            }
        }
    }
View Full Code Here

Examples of org.terasology.utilities.random.FastRandom

            float facetValue = facet.get(pos);
            CoreBiome biome = biomeFacet.get(pos.x, pos.z);
            if (facetValue > 0) {
                for (TreeGenerator generator : treeGeneratorLookup.get(biome)) {
                    if (generator.getGenerationProbability() > (facetValue / 256f)) {
                        generator.generate(chunk, new FastRandom((long) facetValue), pos.x, pos.y, pos.z);
                        break;
                    }
                }
            }
        }
View Full Code Here

Examples of org.terasology.utilities.random.FastRandom

     * Initialize permutations with a given seed
     *
     * @param seed a seed value used for permutation shuffling
     */
    public SimplexNoise(long seed) {
        FastRandom rand = new FastRandom(seed);

        short[] p = new short[256];

        // Initialize with all values [0..255]
        for (short i = 0; i < 256; i++) {
            p[i] = i;
        }

        // Shuffle the array
        for (int i = 0; i < 256; i++) {
            int j = rand.nextInt(256);

            short swap = p[i];
            p[i] = p[j];
            p[j] = swap;
        }
View Full Code Here

Examples of org.terasology.utilities.random.FastRandom

     * Init. a new generator with a given seed value.
     *
     * @param seed The seed value
     */
    public PerlinNoise(long seed) {
        FastRandom rand = new FastRandom(seed);

        noisePermutations = new int[512];
        int[] noiseTable = new int[256];

        // Init. the noise table
        for (int i = 0; i < 256; i++) {
            noiseTable[i] = i;
        }

        // Shuffle the array
        for (int i = 0; i < 256; i++) {
            int j = rand.nextInt(256);

            int swap = noiseTable[i];
            noiseTable[i] = noiseTable[j];
            noiseTable[j] = swap;
        }
View Full Code Here

Examples of org.terasology.utilities.random.FastRandom

    @Test
    public void speedTest() {
        int seed = "asdf".hashCode();
        int warmUp = 10000;
        int count = 1000000;
        FastRandom pfr = new FastRandom(seed);
        FastRandom sfr = new FastRandom(seed);

        PerlinNoise pn = new PerlinNoise(seed);
        SimplexNoise sn = new SimplexNoise(seed);

        for (int i = 0; i < warmUp; i++) {
            float posX = pfr.nextFloat() * 1000f;
            float posY = pfr.nextFloat() * 1000f;
            float posZ = pfr.nextFloat() * 1000f;

            pn.noise(posX, posY, posZ);
        }

        for (int i = 0; i < warmUp; i++) {
            float posX = sfr.nextFloat() * 1000f;
            float posY = sfr.nextFloat() * 1000f;
            float posZ = sfr.nextFloat() * 1000f;

            sn.noise(posX, posY, posZ);
        }

        long start = System.nanoTime();

        for (int i = 0; i < count; i++) {
            float posX = pfr.nextFloat() * 1000f;
            float posY = pfr.nextFloat() * 1000f;
            float posZ = pfr.nextFloat() * 1000f;

            pn.noise(posX, posY, posZ);
        }

        logger.info("Perlin Noise : " + (System.nanoTime() - start) / 1000000 + "ms.");

        start = System.nanoTime();

        for (int i = 0; i < count; i++) {
            float posX = sfr.nextFloat() * 1000f;
            float posY = sfr.nextFloat() * 1000f;
            float posZ = sfr.nextFloat() * 1000f;

            sn.noise(posX, posY, posZ);
        }

        logger.info("Simplex Noise : " + (System.nanoTime() - start) / 1000000 + "ms.");
View Full Code Here

Examples of org.terasology.utilities.random.FastRandom

        logger.info("java.util.Random: {}ms.", (System.nanoTime() - start) / 1000000);
        logger.trace("Use the result so that JVM doesn't skip the computation - here it is: {}", sum);

        // -------------------------------------------------------

        FastRandom fr = new FastRandom(seed);

        // warmup
        sum = 0;
        for (int j = 0; j < warmUpCount; j++) {
            sum += fr.nextInt();
        }
        sum = 0;
        start = System.nanoTime();
        for (int j = 0; j < count; j++) {
            sum += fr.nextInt();
        }

        logger.info("FastRandom: {}ms.", (System.nanoTime() - start) / 1000000);
        logger.trace("Use the result so that JVM doesn't skip the computation - here it is: {}", sum);
View Full Code Here

Examples of org.terasology.utilities.random.FastRandom

    @Override
    public void initialise() {
        blockItemFactory = new BlockItemFactory(entityManager);
        pickupBuilder = new PickupBuilder(entityManager);
        random = new FastRandom();
    }
View Full Code Here

Examples of org.terasology.utilities.random.FastRandom

        super("Iterate entities by multiple components", 10000, new int[]{10000});
    }

    @Override
    public void setup() {
        FastRandom rand = new FastRandom(0L);
        rawEntityData = Lists.newArrayList();
        for (int i = 0; i < 1000; ++i) {
            List<Component> entityData = Lists.newArrayList();
            if (rand.nextFloat() < 0.75f) {
                entityData.add(new LocationComponent());
            }
            if (rand.nextFloat() < 0.5f) {
                entityData.add(new MeshComponent());
            }
            if (rand.nextFloat() < 0.5f) {
                entityData.add(new InventoryComponent());
            }
            if (rand.nextFloat() < 0.25f) {
                entityData.add(new BlockComponent());
            }
            rawEntityData.add(entityData);
        }
View Full Code Here

Examples of org.terasology.utilities.random.FastRandom

        super("Create Entities", 10000, new int[]{10000});
    }

    @Override
    public void setup() {
        FastRandom rand = new FastRandom(0L);
        rawEntityData = Lists.newArrayList();
        for (int i = 0; i < 1000; ++i) {
            List<Component> entityData = Lists.newArrayList();
            if (rand.nextFloat() < 0.75f) {
                entityData.add(new LocationComponent());
            }
            if (rand.nextFloat() < 0.5f) {
                entityData.add(new MeshComponent());
            }
            if (rand.nextFloat() < 0.5f) {
                entityData.add(new InventoryComponent());
            }
            if (rand.nextFloat() < 0.25f) {
                entityData.add(new BlockComponent());
            }
            rawEntityData.add(entityData);
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.