Search in sources :

Example 1 with QueueLinearFloodFiller

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

the class Flood method tick.

@Override
protected void tick(int centreX, int centreY, boolean inverse, boolean first, float dynamicLevel) {
    Dimension dimension = getDimension();
    int terrainHeight = dimension.getIntHeightAt(centreX, centreY);
    if (terrainHeight == -1) {
        // Not on a tile
        return;
    }
    int waterLevel = dimension.getWaterLevelAt(centreX, centreY);
    boolean fluidPresent = waterLevel > terrainHeight;
    if (inverse && (!fluidPresent)) {
        // No point lowering the water level if there is no water...
        return;
    }
    int height = Math.max(terrainHeight, waterLevel);
    int floodToHeight;
    if (fluidPresent && (floodWithLava != dimension.getBitLayerValueAt(FloodWithLava.INSTANCE, centreX, centreY))) {
        // There is fluid present of a different type; don't change the
        // height, just change the type
        floodToHeight = height;
        inverse = false;
    } else {
        if (inverse ? (height <= 0) : (height >= (dimension.getMaxHeight() - 1))) {
            // Already at the lowest or highest possible point
            return;
        }
        floodToHeight = inverse ? height : (height + 1);
    }
    synchronized (dimension) {
        dimension.setEventsInhibited(true);
    }
    try {
        synchronized (dimension) {
            dimension.rememberChanges();
        }
        QueueLinearFloodFiller flooder = new QueueLinearFloodFiller(dimension, floodToHeight, floodWithLava, inverse);
        if (!flooder.floodFill(centreX, centreY, SwingUtilities.getWindowAncestor(getView()))) {
            // Cancelled by user
            synchronized (dimension) {
                if (dimension.undoChanges()) {
                    dimension.clearRedo();
                    dimension.armSavePoint();
                }
            }
        }
    } finally {
        synchronized (dimension) {
            dimension.setEventsInhibited(false);
        }
    }
}
Also used : QueueLinearFloodFiller(org.pepsoft.worldpainter.QueueLinearFloodFiller) Dimension(org.pepsoft.worldpainter.Dimension)

Aggregations

Dimension (org.pepsoft.worldpainter.Dimension)1 QueueLinearFloodFiller (org.pepsoft.worldpainter.QueueLinearFloodFiller)1