Search in sources :

Example 31 with Dimension

use of org.pepsoft.worldpainter.Dimension in project WorldPainter by Captain-Chaos.

the class Pencil method tick.

@Override
protected void tick(int centreX, int centreY, boolean undo, boolean first, float dynamicLevel) {
    Dimension dimension = getDimension();
    dimension.setEventsInhibited(true);
    try {
        painter.setUndo(undo);
        if (first) {
            // Either a single click, or the start of a drag
            lockedX = centreX;
            lockedY = centreY;
            lockedAxis = null;
            if (isShiftDown()) {
                // Shift was pressed: draw a line from the last location
                if ((previousX != Integer.MIN_VALUE) && (previousY != Integer.MIN_VALUE)) {
                    if (isCtrlDown()) {
                        // Ctrl was also pressed: snap the line to 45 degree
                        // angles
                        int[] snappedCoords = snapCoords(previousX, previousY, centreX, centreY, getAxis(previousX, previousY, centreX, centreY));
                        centreX = snappedCoords[0];
                        centreY = snappedCoords[1];
                    }
                    painter.drawLine(dimension, previousX, previousY, centreX, centreY);
                }
                inhibitDrag = true;
            } else {
                // Shift was not pressed: just draw a single dot
                painter.drawPoint(dimension, centreX, centreY);
                inhibitDrag = false;
            }
            previousX = centreX;
            previousY = centreY;
        } else if (!inhibitDrag) {
            // Continuation of a drag
            if (isCtrlDown()) {
                // relative to the point where the drag was started
                if (lockedAxis == null) {
                    lockedAxis = getAxis(lockedX, lockedY, centreX, centreY);
                }
                int[] snappedCoords = snapCoords(lockedX, lockedY, centreX, centreY, lockedAxis);
                centreX = snappedCoords[0];
                centreY = snappedCoords[1];
            }
            if ((centreX != previousX) || (centreY != previousY)) {
                if ((Math.abs(centreX - previousX) <= 1) && (Math.abs(centreY - previousY) <= 1)) {
                    painter.drawPoint(dimension, centreX, centreY);
                } else {
                    painter.drawLine(dimension, previousX, previousY, centreX, centreY);
                }
                previousX = centreX;
                previousY = centreY;
            }
        }
    } finally {
        dimension.setEventsInhibited(false);
    }
}
Also used : Dimension(org.pepsoft.worldpainter.Dimension)

Example 32 with Dimension

use of org.pepsoft.worldpainter.Dimension in project WorldPainter by Captain-Chaos.

the class RaisePyramid method tick.

@Override
protected void tick(int centreX, int centreY, boolean inverse, boolean first, float dynamicLevel) {
    Dimension dimension = getDimension();
    float height = dimension.getHeightAt(centreX, centreY);
    dimension.setEventsInhibited(true);
    try {
        if (height < (dimension.getMaxHeight() - 1.5f)) {
            dimension.setHeightAt(centreX, centreY, height + 1);
        }
        dimension.setTerrainAt(centreX, centreY, Terrain.SANDSTONE);
        int maxR = dimension.getMaxHeight();
        for (int r = 1; r < maxR; r++) {
            if (!raiseRing(dimension, centreX, centreY, r, height--)) {
                break;
            }
        }
    } finally {
        dimension.setEventsInhibited(false);
    }
}
Also used : Dimension(org.pepsoft.worldpainter.Dimension)

Example 33 with Dimension

use of org.pepsoft.worldpainter.Dimension in project WorldPainter by Captain-Chaos.

the class RaiseMountain method tick.

@Override
protected void tick(int centreX, int centreY, boolean inverse, boolean first, float dynamicLevel) {
    Dimension dimension = getDimension();
    float adjustment = (float) Math.pow(getLevel() * dynamicLevel * 2, 2.0);
    float peakHeight = dimension.getHeightAt(centreX + peakDX, centreY + peakDY) + (inverse ? -adjustment : adjustment);
    if (peakHeight < 0.0f) {
        peakHeight = 0.0f;
    } else if (peakHeight > (dimension.getMaxHeight() - 1)) {
        peakHeight = dimension.getMaxHeight() - 1;
    }
    dimension.setEventsInhibited(true);
    try {
        int maxZ = dimension.getMaxHeight() - 1;
        int radius = getEffectiveRadius();
        long seed = dimension.getSeed();
        boolean applyTheme = options.isApplyTheme();
        for (int x = centreX - radius; x <= centreX + radius; x++) {
            for (int y = centreY - radius; y <= centreY + radius; y++) {
                float currentHeight = dimension.getHeightAt(x, y);
                float targetHeight = getTargetHeight(seed, maxZ, centreX, centreY, x, y, peakHeight, inverse);
                if (inverse ? (targetHeight < currentHeight) : (targetHeight > currentHeight)) {
                    // float strength = calcStrength(centerX, centerY, x, y);
                    // float newHeight = strength * targetHeight  + (1f - strength) * currentHeight;
                    dimension.setHeightAt(x, y, targetHeight);
                    if (applyTheme) {
                        dimension.applyTheme(x, y);
                    }
                }
            }
        }
    } finally {
        dimension.setEventsInhibited(false);
    }
}
Also used : Dimension(org.pepsoft.worldpainter.Dimension)

Example 34 with Dimension

use of org.pepsoft.worldpainter.Dimension in project WorldPainter by Captain-Chaos.

the class RaiseRotatedPyramid method tick.

protected void tick(int centreX, int centreY, boolean inverse, boolean first, float dynamicLevel) {
    Dimension dimension = getDimension();
    float height = dimension.getHeightAt(centreX, centreY);
    dimension.setEventsInhibited(true);
    try {
        if (height < (dimension.getMaxHeight() - 1.5f)) {
            dimension.setHeightAt(centreX, centreY, height + 1);
        }
        dimension.setTerrainAt(centreX, centreY, Terrain.SANDSTONE);
        int maxR = dimension.getMaxHeight();
        for (int r = 1; r < maxR; r++) {
            if (!raiseRing(dimension, centreX, centreY, r, height--)) {
                break;
            }
        }
    } finally {
        dimension.setEventsInhibited(false);
    }
}
Also used : Dimension(org.pepsoft.worldpainter.Dimension)

Example 35 with Dimension

use of org.pepsoft.worldpainter.Dimension in project WorldPainter by Captain-Chaos.

the class Smooth method tick.

@Override
protected void tick(int centreX, int centreY, boolean inverse, boolean first, float dynamicLevel) {
    int radius = getEffectiveRadius(), diameter = radius * 2 + 1;
    if ((totals == null) || (totals.length < (diameter + 10))) {
        totals = new float[diameter + 10][diameter + 10];
        currentHeights = new float[diameter + 10][diameter + 10];
        sampleCounts = new int[diameter + 10][diameter + 10];
    } else {
        for (int i = 0; i < diameter + 10; i++) {
            Arrays.fill(totals[i], 0.0f);
            Arrays.fill(currentHeights[i], 0.0f);
            Arrays.fill(sampleCounts[i], 0);
        }
    }
    boolean applyTheme = options.isApplyTheme();
    Dimension dimension = getDimension();
    dimension.setEventsInhibited(true);
    try {
        for (int x = 0; x < diameter + 10; x++) {
            for (int y = 0; y < diameter + 10; y++) {
                float currentHeight = dimension.getHeightAt(centreX - radius + x - 5, centreY - radius + y - 5);
                if (currentHeight != Float.MIN_VALUE) {
                    currentHeights[x][y] = currentHeight;
                    int dxFrom = Math.max(x - 5, 0);
                    int dxTo = Math.min(x + 5, diameter + 9);
                    int dyFrom = Math.max(y - 5, 0);
                    int dyTo = Math.min(y + 5, diameter + 9);
                    for (int dx = dxFrom; dx <= dxTo; dx++) {
                        for (int dy = dyFrom; dy <= dyTo; dy++) {
                            totals[dx][dy] += currentHeight;
                            sampleCounts[dx][dy]++;
                        }
                    }
                }
            }
            if (x >= 10) {
                for (int y = 5; y < diameter + 5; y++) {
                    float strength = dynamicLevel * getStrength(centreX, centreY, centreX + x - radius - 10, centreY + y - radius - 5);
                    if (strength > 0.0f) {
                        float newHeight = strength * (totals[x - 5][y] / sampleCounts[x - 5][y]) + (1 - strength) * currentHeights[x - 5][y];
                        dimension.setHeightAt(x + centreX - radius - 10, y + centreY - radius - 5, newHeight);
                        if (applyTheme) {
                            dimension.applyTheme(x + centreX - radius - 10, y + centreY - radius - 5);
                        }
                    }
                }
            }
        }
    } finally {
        dimension.setEventsInhibited(false);
    }
}
Also used : Dimension(org.pepsoft.worldpainter.Dimension)

Aggregations

Dimension (org.pepsoft.worldpainter.Dimension)39 File (java.io.File)9 Tile (org.pepsoft.worldpainter.Tile)7 World2 (org.pepsoft.worldpainter.World2)6 EventVO (org.pepsoft.worldpainter.vo.EventVO)6 FileOutputStream (java.io.FileOutputStream)5 ProgressReceiver (org.pepsoft.util.ProgressReceiver)5 java.awt (java.awt)4 FileInputStream (java.io.FileInputStream)4 ObjectInputStream (java.io.ObjectInputStream)4 GZIPInputStream (java.util.zip.GZIPInputStream)4 SubProgressReceiver (org.pepsoft.util.SubProgressReceiver)4 ObjectOutputStream (java.io.ObjectOutputStream)3 java.util (java.util)3 List (java.util.List)3 Map (java.util.Map)3 GZIPOutputStream (java.util.zip.GZIPOutputStream)3 FileInUseException (org.pepsoft.worldpainter.util.FileInUseException)3 java.awt.event (java.awt.event)2 PropertyVetoException (java.beans.PropertyVetoException)2