Created PaletteStorage#clean

This commit is contained in:
themode 2020-11-15 05:12:28 +01:00
parent f67328c7a7
commit 47a18fc305
4 changed files with 30 additions and 3 deletions

View File

@ -91,7 +91,7 @@ public final class BenchmarkManager {
}
/**
* Gets the memory used by the server in bytes.
* Gets the heap memory used by the server in bytes.
*
* @return the memory used by the server
*/

View File

@ -181,7 +181,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P
/**
* Called each tick.
*
* @param time the time of update in milliseconds
* @param time time of the update in milliseconds
*/
public abstract void update(long time);

View File

@ -112,6 +112,33 @@ public class PaletteStorage {
return sectionBlocks;
}
/**
* Loops through all the sections and blocks to find unused array (empty chunk section)
* <p>
* Useful after clearing one or multiple sections of a chunk. Can be unnecessarily expensive if the chunk
* is composed of almost-empty sections since the loop will not stop until a non-air block is discovered.
*/
public synchronized void clean() {
for (int i = 0; i < sectionBlocks.length; i++) {
long[] section = sectionBlocks[i];
if (section.length != 0) {
boolean canClear = true;
for (long blockGroup : section) {
if (blockGroup != 0) {
canClear = false;
break;
}
}
if (canClear) {
sectionBlocks[i] = new long[0];
}
}
}
}
public PaletteStorage copy() {
PaletteStorage paletteStorage = new PaletteStorage(bitsPerEntry, bitsIncrement);
paletteStorage.sectionBlocks = sectionBlocks.clone();

View File

@ -149,7 +149,7 @@ public final class PacketProcessor {
* @param reader the buffer containing the packet
*/
private void safeRead(@NotNull PlayerConnection connection, @NotNull Readable readable, @NotNull BinaryReader reader) {
final int readableBytes = reader.getBuffer().readableBytes();
final int readableBytes = reader.available();
// Check if there is anything to read
if (readableBytes == 0) {