Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-09 13:00:05 +01:00
Don't synchronise across the entire edit for a single ChunkSection load (speed boost)
Dieser Commit ist enthalten in:
Ursprung
606cfa5cbc
Commit
42346b429b
@ -825,7 +825,7 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks {
|
|||||||
return super.trim(true);
|
return super.trim(true);
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
if (!hasSection(i) || super.sections[i] == CharBlocks.EMPTY) {
|
if (!hasSection(i) || !super.sections[i].isFull()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ChunkSection existing = getSections(true)[i];
|
ChunkSection existing = getSections(true)[i];
|
||||||
|
@ -827,7 +827,7 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
|
|||||||
return super.trim(true);
|
return super.trim(true);
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
if (!hasSection(i) || super.sections[i] == CharBlocks.EMPTY) {
|
if (!hasSection(i) || !super.sections[i].isFull()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ChunkSection existing = getSections(true)[i];
|
ChunkSection existing = getSections(true)[i];
|
||||||
|
@ -830,7 +830,7 @@ public class BukkitGetBlocks_1_16_2 extends CharGetBlocks {
|
|||||||
return super.trim(true);
|
return super.trim(true);
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
if (!hasSection(i) || super.sections[i] == CharBlocks.EMPTY) {
|
if (!hasSection(i) || !super.sections[i].isFull()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ChunkSection existing = getSections(true)[i];
|
ChunkSection existing = getSections(true)[i];
|
||||||
|
@ -830,7 +830,7 @@ public class BukkitGetBlocks_1_16_4 extends CharGetBlocks {
|
|||||||
return super.trim(true);
|
return super.trim(true);
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
if (!hasSection(i) || super.sections[i] == CharBlocks.EMPTY) {
|
if (!hasSection(i) || !super.sections[i].isFull()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ChunkSection existing = getSections(true)[i];
|
ChunkSection existing = getSections(true)[i];
|
||||||
|
@ -9,17 +9,24 @@ import org.jetbrains.annotations.Range;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public abstract class CharBlocks implements IBlocks {
|
public abstract class CharBlocks implements IBlocks {
|
||||||
|
|
||||||
public static final Logger logger = LoggerFactory.getLogger(CharBlocks.class);
|
public static final Logger logger = LoggerFactory.getLogger(CharBlocks.class);
|
||||||
|
|
||||||
public static final Section FULL = new Section() {
|
protected final Section FULL = new Section() {
|
||||||
@Override
|
@Override
|
||||||
public final char[] get(CharBlocks blocks, int layer) {
|
public final char[] get(CharBlocks blocks, int layer) {
|
||||||
return blocks.blocks[layer];
|
return blocks.blocks[layer];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final boolean isFull() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
public static final Section EMPTY = new Section() {
|
protected final Section EMPTY = new Section() {
|
||||||
@Override
|
@Override
|
||||||
public final synchronized char[] get(CharBlocks blocks, int layer) {
|
public final synchronized char[] get(CharBlocks blocks, int layer) {
|
||||||
char[] arr = blocks.blocks[layer];
|
char[] arr = blocks.blocks[layer];
|
||||||
@ -39,15 +46,22 @@ public abstract class CharBlocks implements IBlocks {
|
|||||||
}
|
}
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final boolean isFull() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
public final char[][] blocks;
|
public final char[][] blocks;
|
||||||
public final Section[] sections;
|
public final Section[] sections;
|
||||||
|
private final Object[] loadLock = new Object[16];
|
||||||
|
|
||||||
public CharBlocks() {
|
public CharBlocks() {
|
||||||
blocks = new char[16][];
|
blocks = new char[16][];
|
||||||
sections = new Section[16];
|
sections = new Section[16];
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
sections[i] = EMPTY;
|
sections[i] = EMPTY;
|
||||||
|
loadLock[i] = new Object();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +69,7 @@ public abstract class CharBlocks implements IBlocks {
|
|||||||
public boolean trim(boolean aggressive) {
|
public boolean trim(boolean aggressive) {
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
if (sections[i] == EMPTY && blocks[i] != null) {
|
if (!sections[i].isFull() && blocks[i] != null) {
|
||||||
blocks[i] = null;
|
blocks[i] = null;
|
||||||
} else {
|
} else {
|
||||||
result = false;
|
result = false;
|
||||||
@ -67,7 +81,7 @@ public abstract class CharBlocks implements IBlocks {
|
|||||||
@Override
|
@Override
|
||||||
public boolean trim(boolean aggressive, int layer) {
|
public boolean trim(boolean aggressive, int layer) {
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
if (sections[layer] == EMPTY && blocks[layer] != null) {
|
if (!sections[layer].isFull() && blocks[layer] != null) {
|
||||||
blocks[layer] = null;
|
blocks[layer] = null;
|
||||||
} else {
|
} else {
|
||||||
result = false;
|
result = false;
|
||||||
@ -99,13 +113,19 @@ public abstract class CharBlocks implements IBlocks {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasSection(@Range(from = 0, to = 15) int layer) {
|
public boolean hasSection(@Range(from = 0, to = 15) int layer) {
|
||||||
return sections[layer] == FULL;
|
return sections[layer].isFull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public char[] load(@Range(from = 0, to = 15) int layer) {
|
public char[] load(@Range(from = 0, to = 15) int layer) {
|
||||||
|
Section section = sections[layer];
|
||||||
|
if (section.isFull()) {
|
||||||
|
return section.get(this, layer);
|
||||||
|
}
|
||||||
|
synchronized (loadLock[layer]) {
|
||||||
return sections[layer].get(this, layer);
|
return sections[layer].get(this, layer);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState getBlock(int x, int y, int z) {
|
public BlockState getBlock(int x, int y, int z) {
|
||||||
@ -149,6 +169,8 @@ public abstract class CharBlocks implements IBlocks {
|
|||||||
|
|
||||||
public abstract char[] get(CharBlocks blocks, @Range(from = 0, to = 15) int layer);
|
public abstract char[] get(CharBlocks blocks, @Range(from = 0, to = 15) int layer);
|
||||||
|
|
||||||
|
public abstract boolean isFull();
|
||||||
|
|
||||||
public final char get(CharBlocks blocks, @Range(from = 0, to = 15) int layer, int index) {
|
public final char get(CharBlocks blocks, @Range(from = 0, to = 15) int layer, int index) {
|
||||||
return get(blocks, layer)[index];
|
return get(blocks, layer)[index];
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren