use of org.pepsoft.worldpainter.Tile in project WorldPainter by Captain-Chaos.
the class NibbleLayerPaint method remove.
@Override
public void remove(Dimension dimension, int centreX, int centreY, float dynamicLevel) {
if (brush.getRadius() == 0) {
// Special case: if the radius is 0, assume that the user wants to remove complete pixels instead of trying
// to apply the brush
removePixel(dimension, centreX, centreY);
return;
}
final int effectiveRadius = brush.getEffectiveRadius();
final int x1 = centreX - effectiveRadius, y1 = centreY - effectiveRadius, x2 = centreX + effectiveRadius, y2 = centreY + effectiveRadius;
final int tileX1 = x1 >> TILE_SIZE_BITS, tileY1 = y1 >> TILE_SIZE_BITS, tileX2 = x2 >> TILE_SIZE_BITS, tileY2 = y2 >> TILE_SIZE_BITS;
if ((tileX1 == tileX2) && (tileY1 == tileY2)) {
// The bounding box of the brush is entirely on one tile; optimize by painting directly to the tile
final Tile tile = dimension.getTileForEditing(tileX1, tileY1);
if (tile == null) {
return;
}
final int x1InTile = x1 & TILE_SIZE_MASK, y1InTile = y1 & TILE_SIZE_MASK, x2InTile = x2 & TILE_SIZE_MASK, y2InTile = y2 & TILE_SIZE_MASK;
final int tileXInWorld = tileX1 << TILE_SIZE_BITS, tileYInWorld = tileY1 << TILE_SIZE_BITS;
for (int y = y1InTile; y <= y2InTile; y++) {
for (int x = x1InTile; x <= x2InTile; x++) {
final int currentValue = tile.getLayerValue(layer, x, y);
final float strength = dynamicLevel * getFullStrength(centreX, centreY, tileXInWorld + x, tileYInWorld + y);
if (strength != 0f) {
int targetValue = 14 - (int) (strength * 14 + 0.5f);
if (targetValue < currentValue) {
tile.setLayerValue(layer, x, y, targetValue);
}
}
}
}
} else {
// The bounding box of the brush straddles more than one tile; paint to the dimension
for (int y = y1; y <= y2; y++) {
for (int x = x1; x <= x2; x++) {
final int currentValue = dimension.getLayerValueAt(layer, x, y);
final float strength = dynamicLevel * getFullStrength(centreX, centreY, x, y);
if (strength != 0f) {
int targetValue = 14 - (int) (strength * 14 + 0.f);
if (targetValue < currentValue) {
dimension.setLayerValueAt(layer, x, y, targetValue);
}
}
}
}
}
}
Aggregations