Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,33 @@ public final class RegionImage {
private final RegionCoordinate region;
private final Path directory;
private final int maxZoom;
private int @Nullable [][] pixels = null;
private volatile int @Nullable [][] pixels = null;

public RegionImage(final RegionCoordinate region, final Path directory, final int maxZoom) {
this.region = region;
this.directory = directory;
this.maxZoom = maxZoom;
}

public synchronized void setPixel(final int x, final int z, final int color) {
if (this.pixels == null) {
this.pixels = new int[SIZE][SIZE];
for (final int[] arr : this.pixels) {
// Callers write distinct pixels, so only the allocation needs the lock.
public void setPixel(final int x, final int z, final int color) {
int @Nullable [][] pixels = this.pixels;
if (pixels == null) {
pixels = this.allocatePixels();
}
pixels[x & (SIZE - 1)][z & (SIZE - 1)] = color;
}

private synchronized int[][] allocatePixels() {
int @Nullable [][] pixels = this.pixels;
if (pixels == null) {
pixels = new int[SIZE][SIZE];
for (final int[] arr : pixels) {
Arrays.fill(arr, Integer.MIN_VALUE);
}
this.pixels = pixels;
}
this.pixels[x & (SIZE - 1)][z & (SIZE - 1)] = color;
return pixels;
}

/**
Expand Down
Loading