Search in sources :

Example 1 with PerlinNoise

use of org.pepsoft.util.PerlinNoise in project WorldPainter by Captain-Chaos.

the class SimpleTheme method setSeed.

@Override
public final void setSeed(long seed) {
    this.seed = seed;
    perlinNoise = new PerlinNoise(seed);
}
Also used : PerlinNoise(org.pepsoft.util.PerlinNoise)

Example 2 with PerlinNoise

use of org.pepsoft.util.PerlinNoise in project WorldPainter by Captain-Chaos.

the class ResourcesExporter method setSettings.

@Override
public void setSettings(ExporterSettings settings) {
    super.setSettings(settings);
    ResourcesExporterSettings resourcesSettings = (ResourcesExporterSettings) getSettings();
    if (resourcesSettings != null) {
        noiseGenerators = new PerlinNoise[256];
        seedOffsets = new long[256];
        minLevels = new int[256];
        maxLevels = new int[256];
        chances = new float[256][16];
        activeOreCount = 0;
        for (int blockType : resourcesSettings.getBlockTypes()) {
            if (resourcesSettings.getChance(blockType) == 0) {
                continue;
            }
            activeOreCount++;
            noiseGenerators[blockType] = new PerlinNoise(0);
            seedOffsets[blockType] = resourcesSettings.getSeedOffset(blockType);
            minLevels[blockType] = resourcesSettings.getMinLevel(blockType);
            maxLevels[blockType] = resourcesSettings.getMaxLevel(blockType);
            chances[blockType] = new float[16];
            for (int i = 0; i < 16; i++) {
                chances[blockType][i] = PerlinNoise.getLevelForPromillage(Math.min(resourcesSettings.getChance(blockType) * i / 8f, 1000f));
            }
        }
    }
}
Also used : PerlinNoise(org.pepsoft.util.PerlinNoise)

Example 3 with PerlinNoise

use of org.pepsoft.util.PerlinNoise in project WorldPainter by Captain-Chaos.

the class HeightMapImporter method importToDimension.

public void importToDimension(Dimension dimension, boolean createTiles, ProgressReceiver progressReceiver) throws ProgressReceiver.OperationCancelled {
    // Sanity checks
    if (dimension.getMaxHeight() != maxHeight) {
        throw new IllegalArgumentException(String.format("Dimension has different maxHeight (%d) than configured (%d)", dimension.getMaxHeight(), maxHeight));
    }
    Rectangle extent = heightMap.getExtent();
    if (dimension.getWorld() != null) {
        dimension.getWorld().addHistoryEntry(HistoryEntry.WORLD_HEIGHT_MAP_IMPORTED_TO_DIMENSION, dimension.getName(), imageFile);
    }
    final boolean useVoidBelow = voidBelowLevel > 0;
    final int x1 = extent.x;
    final int x2 = extent.x + extent.width - 1;
    final int y1 = extent.y;
    final int y2 = extent.y + extent.height - 1;
    final int tileX1 = x1 >> TILE_SIZE_BITS;
    final int tileY1 = y1 >> TILE_SIZE_BITS;
    final int tileX2 = x2 >> TILE_SIZE_BITS;
    final int tileY2 = y2 >> TILE_SIZE_BITS;
    final int widthInTiles = tileX2 - tileX1 + 1;
    final int heightInTiles = tileY2 - tileY1 + 1;
    final int totalTileCount = widthInTiles * heightInTiles;
    final int floor = Math.max(worldWaterLevel - 20, 0);
    final int variation = Math.min(15, (worldWaterLevel - floor) / 2);
    final PerlinNoise noiseGenerator = new PerlinNoise(0);
    noiseGenerator.setSeed(dimension.getSeed());
    int tileCount = 0;
    calculateFlags();
    for (int tileX = tileX1; tileX <= tileX2; tileX++) {
        for (int tileY = tileY1; tileY <= tileY2; tileY++) {
            boolean tileIsNew;
            Tile tile = dimension.getTileForEditing(tileX, tileY);
            if (tile == null) {
                if (createTiles) {
                    tile = tileFactory.createTile(tileX, tileY);
                    tileIsNew = true;
                } else {
                    tileCount++;
                    if (progressReceiver != null) {
                        progressReceiver.setProgress((float) tileCount / totalTileCount);
                    }
                    continue;
                }
            } else {
                tileIsNew = false;
                tile.inhibitEvents();
            }
            final int xOffset = tileX << TILE_SIZE_BITS;
            final int yOffset = tileY << TILE_SIZE_BITS;
            for (int x = 0; x < TILE_SIZE; x++) {
                for (int y = 0; y < TILE_SIZE; y++) {
                    final int imageX = xOffset + x;
                    final int imageY = yOffset + y;
                    if ((imageX >= x1) && (imageX <= x2) && (imageY >= y1) && (imageY <= y2)) {
                        final float imageLevel = heightMap.getHeight(imageX, imageY);
                        final float height = calculateHeight(imageLevel);
                        if (onlyRaise && (!tileIsNew)) {
                            if (height > tile.getHeight(x, y)) {
                                tile.setHeight(x, y, height);
                                tileFactory.applyTheme(tile, x, y);
                            }
                        } else {
                            tile.setHeight(x, y, height);
                            tile.setWaterLevel(x, y, worldWaterLevel);
                            if (useVoidBelow && (imageLevel < voidBelowLevel)) {
                                tile.setBitLayerValue(org.pepsoft.worldpainter.layers.Void.INSTANCE, x, y, true);
                            }
                            tileFactory.applyTheme(tile, x, y);
                        }
                    } else if (tileIsNew) {
                        tile.setHeight(x, y, floor + (noiseGenerator.getPerlinNoise(imageX / MEDIUM_BLOBS, imageY / MEDIUM_BLOBS) + 0.5f) * variation);
                        tile.setTerrain(x, y, Terrain.BEACHES);
                        tile.setWaterLevel(x, y, worldWaterLevel);
                        if (useVoidBelow) {
                            tile.setBitLayerValue(org.pepsoft.worldpainter.layers.Void.INSTANCE, x, y, true);
                        }
                    }
                }
            }
            if (tileIsNew) {
                dimension.addTile(tile);
            } else {
                tile.releaseEvents();
            }
            tileCount++;
            if (progressReceiver != null) {
                progressReceiver.setProgress((float) tileCount / totalTileCount);
            }
        }
    }
}
Also used : PerlinNoise(org.pepsoft.util.PerlinNoise)

Example 4 with PerlinNoise

use of org.pepsoft.util.PerlinNoise in project WorldPainter by Captain-Chaos.

the class Dimension method init.

private void init() {
    listeners = new ArrayList<>();
    dirtyTiles = new HashSet<>();
    addedTiles = new HashSet<>();
    removedTiles = new HashSet<>();
    propertyChangeSupport = new PropertyChangeSupport(this);
    garden = new WPGarden();
    topLayerDepthNoise = new PerlinNoise(seed + TOP_LAYER_DEPTH_SEED_OFFSET);
    for (Tile tile : tiles.values()) {
        tile.addListener(this);
        Set<Seed> seeds = tile.getSeeds();
        if (seeds != null) {
            for (Seed gardenSeed : seeds) {
                gardenSeed.garden = garden;
            }
        }
    }
    // Legacy support
    if (wpVersion < 1) {
        if (borderSize == 0) {
            borderSize = 2;
        }
        if (overlayScale == 0.0f) {
            overlayScale = 1.0f;
        }
        if (overlayTransparency == 0.0f) {
            overlayTransparency = 0.5f;
        }
        if (gridSize == 0) {
            gridSize = 128;
        }
        if (!biomesConverted) {
            // Convert the nibble sized biomes data from a legacy map (by
            // deleting it so that it will be recalculated
            tiles.values().forEach(org.pepsoft.worldpainter.Tile::convertBiomeData);
            biomesConverted = true;
        }
        if (maxHeight == 0) {
            maxHeight = 128;
        }
        if (subsurfaceMaterial == Terrain.RESOURCES) {
            subsurfaceMaterial = Terrain.STONE;
            // Load legacy settings
            ResourcesExporterSettings settings = new ResourcesExporterSettings(maxHeight);
            settings.setChance(BLK_GOLD_ORE, 1);
            settings.setChance(BLK_IRON_ORE, 5);
            settings.setChance(BLK_COAL, 9);
            settings.setChance(BLK_LAPIS_LAZULI_ORE, 1);
            settings.setChance(BLK_DIAMOND_ORE, 1);
            settings.setChance(BLK_REDSTONE_ORE, 6);
            settings.setChance(BLK_WATER, 1);
            settings.setChance(BLK_LAVA, 1);
            settings.setChance(BLK_DIRT, 9);
            settings.setChance(BLK_GRAVEL, 9);
            settings.setMaxLevel(BLK_GOLD_ORE, Terrain.GOLD_LEVEL);
            settings.setMaxLevel(BLK_IRON_ORE, Terrain.IRON_LEVEL);
            settings.setMaxLevel(BLK_COAL, Terrain.COAL_LEVEL);
            settings.setMaxLevel(BLK_LAPIS_LAZULI_ORE, Terrain.LAPIS_LAZULI_LEVEL);
            settings.setMaxLevel(BLK_DIAMOND_ORE, Terrain.DIAMOND_LEVEL);
            settings.setMaxLevel(BLK_REDSTONE_ORE, Terrain.REDSTONE_LEVEL);
            settings.setMaxLevel(BLK_WATER, Terrain.WATER_LEVEL);
            settings.setMaxLevel(BLK_LAVA, Terrain.LAVA_LEVEL);
            settings.setMaxLevel(BLK_DIRT, Terrain.DIRT_LEVEL);
            settings.setMaxLevel(BLK_GRAVEL, Terrain.GRAVEL_LEVEL);
            layerSettings.put(Resources.INSTANCE, settings);
        }
        if (contourSeparation == 0) {
            contourSeparation = 10;
        }
        if (topLayerMinDepth == 0) {
            topLayerMinDepth = 3;
            topLayerVariation = 4;
        }
        if (lastViewPosition == null) {
            lastViewPosition = new Point();
        }
        if ((customLayers == null) || customLayers.isEmpty()) {
            // The customLayers.isEmpty() is to fix a bug which escaped in a beta
            customLayers = new ArrayList<>();
            customLayers.addAll(getAllLayers(false).stream().filter(layer -> layer instanceof CustomLayer).map(layer -> (CustomLayer) layer).collect(Collectors.toList()));
        }
    }
    if (wpVersion < 2) {
        if (overlay != null) {
            fixOverlayCoords = true;
        }
    }
    if (wpVersion < 3) {
        ceilingHeight = maxHeight;
    }
    wpVersion = CURRENT_WP_VERSION;
    // Make sure that any custom layers which somehow ended up in the world
    // are on the custom layer list so they will be added to a palette in
    // the GUI. TODO: fix this properly
    // Make sure customLayers isn't some weird read-only list
    getAllLayers(false).stream().filter(layer -> (layer instanceof CustomLayer) && (!customLayers.contains(layer))).forEach(layer -> {
        if ((!(customLayers instanceof ArrayList)) && (!(customLayers instanceof LinkedList))) {
            // Make sure customLayers isn't some weird read-only list
            customLayers = new ArrayList<>(customLayers);
        }
        customLayers.add((CustomLayer) layer);
    });
}
Also used : java.util(java.util) CustomBiome(org.pepsoft.worldpainter.biomeschemes.CustomBiome) ExporterSettings(org.pepsoft.worldpainter.layers.exporters.ExporterSettings) ObjectInputStream(java.io.ObjectInputStream) org.pepsoft.worldpainter.layers(org.pepsoft.worldpainter.layers) UndoManager(org.pepsoft.util.undo.UndoManager) ResourcesExporterSettings(org.pepsoft.worldpainter.layers.exporters.ResourcesExporter.ResourcesExporterSettings) Point3i(javax.vecmath.Point3i) AttributeKey(org.pepsoft.util.AttributeKey) ImageIO(javax.imageio.ImageIO) SelectionChunk(org.pepsoft.worldpainter.selection.SelectionChunk) MathUtils(org.pepsoft.util.MathUtils) Garden(org.pepsoft.worldpainter.gardenofeden.Garden) Constants(org.pepsoft.worldpainter.Constants) PerlinNoise(org.pepsoft.util.PerlinNoise) ImageReader(javax.imageio.ImageReader) Seed(org.pepsoft.worldpainter.gardenofeden.Seed) DefaultFilter(org.pepsoft.worldpainter.panels.DefaultFilter) IOException(java.io.IOException) FileImageInputStream(javax.imageio.stream.FileImageInputStream) Collectors(java.util.stream.Collectors) File(java.io.File) ImageInputStream(javax.imageio.stream.ImageInputStream) Serializable(java.io.Serializable) java.awt(java.awt) List(java.util.List) Brush(org.pepsoft.worldpainter.brushes.Brush) PropertyChangeListener(java.beans.PropertyChangeListener) Constants(org.pepsoft.minecraft.Constants) ProgressReceiver(org.pepsoft.util.ProgressReceiver) SelectionBlock(org.pepsoft.worldpainter.selection.SelectionBlock) OperationCancelled(org.pepsoft.util.ProgressReceiver.OperationCancelled) PropertyChangeSupport(java.beans.PropertyChangeSupport) Filter(org.pepsoft.worldpainter.operations.Filter) javax.swing(javax.swing) Minecraft1_7Biomes(org.pepsoft.worldpainter.biomeschemes.Minecraft1_7Biomes) PropertyChangeSupport(java.beans.PropertyChangeSupport) PerlinNoise(org.pepsoft.util.PerlinNoise) ResourcesExporterSettings(org.pepsoft.worldpainter.layers.exporters.ResourcesExporter.ResourcesExporterSettings) Seed(org.pepsoft.worldpainter.gardenofeden.Seed)

Example 5 with PerlinNoise

use of org.pepsoft.util.PerlinNoise in project WorldPainter by Captain-Chaos.

the class MixedMaterial method init.

private void init() {
    switch(mode) {
        case SIMPLE:
            if (rows.length != 1) {
                throw new IllegalArgumentException("Only one row allowed for SIMPLE mode");
            }
            simpleMaterial = rows[0].material;
            break;
        case NOISE:
            if (rows.length < 2) {
                throw new IllegalArgumentException("Multiple rows required for NOISE mode");
            }
            materials = new Material[1000];
            int index = 0;
            for (Row row : rows) {
                for (int i = 0; i < row.occurrence; i++) {
                    materials[index++] = row.material;
                }
            }
            random = new Random();
            break;
        case BLOBS:
            if (rows.length < 2) {
                throw new IllegalArgumentException("Multiple rows required for BLOBS mode");
            }
            sortedRows = Arrays.copyOf(rows, rows.length);
            Arrays.sort(sortedRows, (r1, r2) -> r1.occurrence - r2.occurrence);
            noiseGenerators = new PerlinNoise[rows.length - 1];
            int cumulativePermillage = 0;
            for (int i = 0; i < noiseGenerators.length; i++) {
                noiseGenerators[i] = new PerlinNoise(0);
                cumulativePermillage += sortedRows[i].occurrence * (1000 - cumulativePermillage) / 1000;
                sortedRows[i].chance = PerlinNoise.getLevelForPromillage(cumulativePermillage);
            }
            break;
        case LAYERED:
            if (rows.length < 2) {
                throw new IllegalArgumentException("Multiple rows required for LAYERED mode");
            }
            if ((!repeat) && ((layerXSlope != 0) || (layerYSlope != 0))) {
                throw new IllegalArgumentException("Angle may not be non-zero if repeat is false");
            }
            List<Material> tmpMaterials = new ArrayList<>(org.pepsoft.minecraft.Constants.DEFAULT_MAX_HEIGHT_2);
            for (int i = rows.length - 1; i >= 0; i--) {
                for (int j = 0; j < rows[i].occurrence; j++) {
                    tmpMaterials.add(rows[i].material);
                }
            }
            materials = tmpMaterials.toArray(new Material[tmpMaterials.size()]);
            if (variation != null) {
                layerNoiseheightMap = new NoiseHeightMap(variation, NOISE_SEED_OFFSET);
                layerNoiseOffset = variation.getRange();
            } else {
                layerNoiseheightMap = null;
                layerNoiseOffset = 0;
            }
            break;
    }
}
Also used : NoiseHeightMap(org.pepsoft.worldpainter.heightMaps.NoiseHeightMap) PerlinNoise(org.pepsoft.util.PerlinNoise) Material(org.pepsoft.minecraft.Material)

Aggregations

PerlinNoise (org.pepsoft.util.PerlinNoise)9 java.awt (java.awt)1 BufferedImage (java.awt.image.BufferedImage)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 PropertyChangeSupport (java.beans.PropertyChangeSupport)1 File (java.io.File)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 Serializable (java.io.Serializable)1 java.util (java.util)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ImageIO (javax.imageio.ImageIO)1 ImageReader (javax.imageio.ImageReader)1 FileImageInputStream (javax.imageio.stream.FileImageInputStream)1 ImageInputStream (javax.imageio.stream.ImageInputStream)1 javax.swing (javax.swing)1 Point3i (javax.vecmath.Point3i)1 ChunkFactory (org.pepsoft.minecraft.ChunkFactory)1 Constants (org.pepsoft.minecraft.Constants)1