geforkt von Mirrors/FastAsyncWorldEdit
Extract common code when resizing arrays (#2257)
Dieser Commit ist enthalten in:
Ursprung
82418155f6
Commit
4fa927f996
@ -410,68 +410,48 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet {
|
|||||||
if (layer < minSectionPosition) {
|
if (layer < minSectionPosition) {
|
||||||
int diff = minSectionPosition - layer;
|
int diff = minSectionPosition - layer;
|
||||||
sectionCount += diff;
|
sectionCount += diff;
|
||||||
char[][] tmpBlocks = new char[sectionCount][];
|
|
||||||
Section[] tmpSections = new Section[sectionCount];
|
|
||||||
Object[] tmpSectionLocks = new Object[sectionCount];
|
|
||||||
System.arraycopy(blocks, 0, tmpBlocks, diff, blocks.length);
|
|
||||||
System.arraycopy(sections, 0, tmpSections, diff, sections.length);
|
|
||||||
System.arraycopy(sectionLocks, 0, tmpSectionLocks, diff, sections.length);
|
|
||||||
for (int i = 0; i < diff; i++) {
|
|
||||||
tmpSections[i] = EMPTY;
|
|
||||||
tmpSectionLocks[i] = new Object();
|
|
||||||
}
|
|
||||||
blocks = tmpBlocks;
|
|
||||||
sections = tmpSections;
|
|
||||||
sectionLocks = tmpSectionLocks;
|
|
||||||
minSectionPosition = layer;
|
minSectionPosition = layer;
|
||||||
if (biomes != null) {
|
resizeSectionsArrays(diff, false); // prepend new layer(s)
|
||||||
BiomeType[][] tmpBiomes = new BiomeType[sectionCount][64];
|
|
||||||
System.arraycopy(biomes, 0, tmpBiomes, diff, biomes.length);
|
|
||||||
biomes = tmpBiomes;
|
|
||||||
}
|
|
||||||
if (light != null) {
|
|
||||||
char[][] tmplight = new char[sectionCount][];
|
|
||||||
System.arraycopy(light, 0, tmplight, diff, light.length);
|
|
||||||
light = tmplight;
|
|
||||||
}
|
|
||||||
if (skyLight != null) {
|
|
||||||
char[][] tmplight = new char[sectionCount][];
|
|
||||||
System.arraycopy(skyLight, 0, tmplight, diff, skyLight.length);
|
|
||||||
skyLight = tmplight;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
int diff = layer - maxSectionPosition;
|
int diff = layer - maxSectionPosition;
|
||||||
sectionCount += diff;
|
sectionCount += diff;
|
||||||
|
maxSectionPosition = layer;
|
||||||
|
resizeSectionsArrays(diff, true); // append new layer(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resizeSectionsArrays(int diff, boolean appendNew) {
|
||||||
char[][] tmpBlocks = new char[sectionCount][];
|
char[][] tmpBlocks = new char[sectionCount][];
|
||||||
Section[] tmpSections = new Section[sectionCount];
|
Section[] tmpSections = new Section[sectionCount];
|
||||||
Object[] tmpSectionLocks = new Object[sectionCount];
|
Object[] tmpSectionLocks = new Object[sectionCount];
|
||||||
System.arraycopy(blocks, 0, tmpBlocks, 0, blocks.length);
|
int destPos = appendNew ? 0 : diff;
|
||||||
System.arraycopy(sections, 0, tmpSections, 0, sections.length);
|
System.arraycopy(blocks, 0, tmpBlocks, destPos, blocks.length);
|
||||||
System.arraycopy(sectionLocks, 0, tmpSectionLocks, 0, sections.length);
|
System.arraycopy(sections, 0, tmpSections, destPos, sections.length);
|
||||||
for (int i = sectionCount - diff; i < sectionCount; i++) {
|
System.arraycopy(sectionLocks, 0, tmpSectionLocks, destPos, sections.length);
|
||||||
|
int toFillFrom = appendNew ? sectionCount - diff : 0;
|
||||||
|
int toFillTo = appendNew ? sectionCount : diff;
|
||||||
|
for (int i = toFillFrom; i < toFillTo; i++) {
|
||||||
tmpSections[i] = EMPTY;
|
tmpSections[i] = EMPTY;
|
||||||
tmpSectionLocks[i] = new Object();
|
tmpSectionLocks[i] = new Object();
|
||||||
}
|
}
|
||||||
blocks = tmpBlocks;
|
blocks = tmpBlocks;
|
||||||
sections = tmpSections;
|
sections = tmpSections;
|
||||||
sectionLocks = tmpSectionLocks;
|
sectionLocks = tmpSectionLocks;
|
||||||
maxSectionPosition = layer;
|
|
||||||
if (biomes != null) {
|
if (biomes != null) {
|
||||||
BiomeType[][] tmpBiomes = new BiomeType[sectionCount][64];
|
BiomeType[][] tmpBiomes = new BiomeType[sectionCount][64];
|
||||||
System.arraycopy(biomes, 0, tmpBiomes, 0, biomes.length);
|
System.arraycopy(biomes, 0, tmpBiomes, destPos, biomes.length);
|
||||||
biomes = tmpBiomes;
|
biomes = tmpBiomes;
|
||||||
}
|
}
|
||||||
if (light != null) {
|
if (light != null) {
|
||||||
char[][] tmplight = new char[sectionCount][];
|
char[][] tmplight = new char[sectionCount][];
|
||||||
System.arraycopy(light, 0, tmplight, 0, light.length);
|
System.arraycopy(light, 0, tmplight, destPos, light.length);
|
||||||
light = tmplight;
|
light = tmplight;
|
||||||
}
|
}
|
||||||
if (skyLight != null) {
|
if (skyLight != null) {
|
||||||
char[][] tmplight = new char[sectionCount][];
|
char[][] tmplight = new char[sectionCount][];
|
||||||
System.arraycopy(skyLight, 0, tmplight, 0, skyLight.length);
|
System.arraycopy(skyLight, 0, tmplight, destPos, skyLight.length);
|
||||||
skyLight = tmplight;
|
skyLight = tmplight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -489,48 +489,36 @@ public class ThreadUnsafeCharBlocks implements IChunkSet, IBlocks {
|
|||||||
if (layer < minSectionPosition) {
|
if (layer < minSectionPosition) {
|
||||||
int diff = minSectionPosition - layer;
|
int diff = minSectionPosition - layer;
|
||||||
sectionCount += diff;
|
sectionCount += diff;
|
||||||
char[][] tmpBlocks = new char[sectionCount][];
|
|
||||||
System.arraycopy(blocks, 0, tmpBlocks, diff, blocks.length);
|
|
||||||
blocks = tmpBlocks;
|
|
||||||
minSectionPosition = layer;
|
minSectionPosition = layer;
|
||||||
if (biomes != null) {
|
resizeSectionsArrays(layer, diff, false); // prepend new layer(s)
|
||||||
BiomeType[][] tmpBiomes = new BiomeType[sectionCount][64];
|
|
||||||
System.arraycopy(biomes, 0, tmpBiomes, diff, biomes.length);
|
|
||||||
biomes = tmpBiomes;
|
|
||||||
}
|
|
||||||
if (light != null) {
|
|
||||||
char[][] tmplight = new char[sectionCount][];
|
|
||||||
System.arraycopy(light, 0, tmplight, diff, light.length);
|
|
||||||
light = tmplight;
|
|
||||||
}
|
|
||||||
if (skyLight != null) {
|
|
||||||
char[][] tmplight = new char[sectionCount][];
|
|
||||||
System.arraycopy(skyLight, 0, tmplight, diff, skyLight.length);
|
|
||||||
skyLight = tmplight;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
int diff = layer - maxSectionPosition;
|
int diff = layer - maxSectionPosition;
|
||||||
sectionCount += diff;
|
sectionCount += diff;
|
||||||
char[][] tmpBlocks = new char[sectionCount][];
|
|
||||||
System.arraycopy(blocks, 0, tmpBlocks, 0, blocks.length);
|
|
||||||
blocks = tmpBlocks;
|
|
||||||
maxSectionPosition = layer;
|
maxSectionPosition = layer;
|
||||||
|
resizeSectionsArrays(layer, diff, true); // append new layer(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resizeSectionsArrays(int layer, int diff, boolean appendNew) {
|
||||||
|
char[][] tmpBlocks = new char[sectionCount][];
|
||||||
|
int destPos = appendNew ? 0 : diff;
|
||||||
|
System.arraycopy(blocks, 0, tmpBlocks, destPos, blocks.length);
|
||||||
|
blocks = tmpBlocks;
|
||||||
if (biomes != null) {
|
if (biomes != null) {
|
||||||
BiomeType[][] tmpBiomes = new BiomeType[sectionCount][64];
|
BiomeType[][] tmpBiomes = new BiomeType[sectionCount][64];
|
||||||
System.arraycopy(biomes, 0, tmpBiomes, 0, biomes.length);
|
System.arraycopy(biomes, 0, tmpBiomes, destPos, biomes.length);
|
||||||
biomes = tmpBiomes;
|
biomes = tmpBiomes;
|
||||||
}
|
}
|
||||||
if (light != null) {
|
if (light != null) {
|
||||||
char[][] tmplight = new char[sectionCount][];
|
char[][] tmplight = new char[sectionCount][];
|
||||||
System.arraycopy(light, 0, tmplight, 0, light.length);
|
System.arraycopy(light, 0, tmplight, destPos, light.length);
|
||||||
light = tmplight;
|
light = tmplight;
|
||||||
}
|
}
|
||||||
if (skyLight != null) {
|
if (skyLight != null) {
|
||||||
char[][] tmplight = new char[sectionCount][];
|
char[][] tmplight = new char[sectionCount][];
|
||||||
System.arraycopy(skyLight, 0, tmplight, 0, skyLight.length);
|
System.arraycopy(skyLight, 0, tmplight, destPos, skyLight.length);
|
||||||
skyLight = tmplight;
|
skyLight = tmplight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren