-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert to latest chunk format on send.
This fixes some of the major lag that has been occurring since 1.13. Legacy chunk conversion on the client has been so slow that some people can't even join.
- Loading branch information
1 parent
0ae6d9b
commit 1acd6a5
Showing
10 changed files
with
391 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package cn.nukkit.level.util; | ||
|
||
public interface BitArray { | ||
|
||
void set(int index, int value); | ||
|
||
int get(int index); | ||
|
||
int size(); | ||
|
||
int[] getWords(); | ||
|
||
BitArrayVersion getVersion(); | ||
|
||
BitArray copy(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package cn.nukkit.level.util; | ||
|
||
public enum BitArrayVersion { | ||
V16(16, 2, null), | ||
V8(8, 4, V16), | ||
V6(6, 5, V8), // 2 bit padding | ||
V5(5, 6, V6), // 2 bit padding | ||
V4(4, 8, V5), | ||
V3(3, 10, V4), // 2 bit padding | ||
V2(2, 16, V3), | ||
V1(1, 32, V2); | ||
|
||
final byte bits; | ||
final byte entriesPerWord; | ||
final int maxEntryValue; | ||
final BitArrayVersion next; | ||
|
||
BitArrayVersion(int bits, int entriesPerWord, BitArrayVersion next) { | ||
this.bits = (byte) bits; | ||
this.entriesPerWord = (byte) entriesPerWord; | ||
this.maxEntryValue = (1 << this.bits) - 1; | ||
this.next = next; | ||
} | ||
|
||
public static BitArrayVersion get(int version, boolean read) { | ||
for (BitArrayVersion ver : values()) { | ||
if ((!read && ver.entriesPerWord <= version) || (read && ver.bits == version)) { | ||
return ver; | ||
} | ||
} | ||
throw new IllegalArgumentException("Invalid palette version: " + version); | ||
} | ||
|
||
public BitArray createPalette(int size) { | ||
return this.createPalette(size, new int[this.getWordsForSize(size)]); | ||
} | ||
|
||
public byte getId() { | ||
return bits; | ||
} | ||
|
||
public int getWordsForSize(int size) { | ||
return (size / entriesPerWord) + (size % entriesPerWord == 0 ? 0 : 1); | ||
} | ||
|
||
public int getMaxEntryValue() { | ||
return maxEntryValue; | ||
} | ||
|
||
public BitArrayVersion next() { | ||
return next; | ||
} | ||
|
||
public BitArray createPalette(int size, int[] words) { | ||
if (this == V3 || this == V5 || this == V6) { | ||
// Padded palettes aren't able to use bitwise operations due to their padding. | ||
return new PaddedBitArray(this, size, words); | ||
} else { | ||
return new Pow2BitArray(this, size, words); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package cn.nukkit.level.util; | ||
|
||
import cn.nukkit.math.MathHelper; | ||
import com.google.common.base.Preconditions; | ||
|
||
import java.util.Arrays; | ||
|
||
public class PaddedBitArray implements BitArray { | ||
|
||
/** | ||
* Array used to store data | ||
*/ | ||
private final int[] words; | ||
|
||
/** | ||
* Palette version information | ||
*/ | ||
private final BitArrayVersion version; | ||
|
||
/** | ||
* Number of entries in this palette (<b>not</b> the length of the words array that internally backs this palette) | ||
*/ | ||
private final int size; | ||
|
||
PaddedBitArray(BitArrayVersion version, int size, int[] words) { | ||
this.size = size; | ||
this.version = version; | ||
this.words = words; | ||
int expectedWordsLength = MathHelper.ceil((float) size / version.entriesPerWord); | ||
if (words.length != expectedWordsLength) { | ||
throw new IllegalArgumentException("Invalid length given for storage, got: " + words.length + | ||
" but expected: " + expectedWordsLength); | ||
} | ||
} | ||
|
||
@Override | ||
public void set(int index, int value) { | ||
Preconditions.checkElementIndex(index, this.size); | ||
Preconditions.checkArgument(value >= 0 && value <= this.version.maxEntryValue, | ||
"Max value: %s. Received value", this.version.maxEntryValue, value); | ||
int arrayIndex = index / this.version.entriesPerWord; | ||
int offset = (index % this.version.entriesPerWord) * this.version.bits; | ||
|
||
this.words[arrayIndex] = this.words[arrayIndex] & ~(this.version.maxEntryValue << offset) | (value & this.version.maxEntryValue) << offset; | ||
} | ||
|
||
@Override | ||
public int get(int index) { | ||
Preconditions.checkElementIndex(index, this.size); | ||
int arrayIndex = index / this.version.entriesPerWord; | ||
int offset = (index % this.version.entriesPerWord) * this.version.bits; | ||
|
||
return (this.words[arrayIndex] >>> offset) & this.version.maxEntryValue; | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return this.size; | ||
} | ||
|
||
@Override | ||
public int[] getWords() { | ||
return this.words; | ||
} | ||
|
||
@Override | ||
public BitArrayVersion getVersion() { | ||
return this.version; | ||
} | ||
|
||
@Override | ||
public BitArray copy() { | ||
return new PaddedBitArray(this.version, this.size, Arrays.copyOf(this.words, this.words.length)); | ||
} | ||
} |
Oops, something went wrong.
1acd6a5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my map have problem when using this version :(
1acd6a5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm aware of the problem and working on a fix. Go back to the last build for now. It's only visual so it won't effect the chunks server side.