Temporarily disable palette compression

This commit is contained in:
themode 2022-02-25 02:19:29 +01:00
parent c34ec0107e
commit b6ba957a7b

View File

@ -2,7 +2,6 @@ package net.minestom.server.instance.palette;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet; import it.unimi.dsi.fastutil.ints.IntSet;
import net.minestom.server.utils.MathUtils;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -115,25 +114,29 @@ final class AdaptivePalette implements Palette {
@Override @Override
public void write(@NotNull BinaryWriter writer) { public void write(@NotNull BinaryWriter writer) {
optimizedPalette().write(writer); final SpecializedPalette optimized = optimizedPalette();
this.palette = optimized;
optimized.write(writer);
} }
Palette optimizedPalette() { SpecializedPalette optimizedPalette() {
var currentPalette = this.palette; var currentPalette = this.palette;
if (currentPalette instanceof FlexiblePalette flexiblePalette) { if (currentPalette instanceof FlexiblePalette flexiblePalette) {
final int count = flexiblePalette.count(); final int count = flexiblePalette.count();
if (count == 0) { if (count == 0) {
return (this.palette = new FilledPalette(dimension, 0)); return new FilledPalette(dimension, 0);
} else { } else {
// Find all entries and compress the palette // Find all entries and compress the palette
IntSet entries = new IntOpenHashSet(flexiblePalette.paletteToValueList.size()); IntSet entries = new IntOpenHashSet(flexiblePalette.paletteToValueList.size());
currentPalette.getAll((x, y, z, value) -> entries.add(value)); currentPalette.getAll((x, y, z, value) -> entries.add(value));
final int bitsPerEntry = MathUtils.bitsToRepresent(entries.size()); if (entries.size() == 1) {
if (bitsPerEntry == 1) { return new FilledPalette(dimension, entries.iterator().nextInt());
return (this.palette = new FilledPalette(dimension, entries.iterator().nextInt()));
} else { } else {
flexiblePalette.resize(bitsPerEntry); // FIXME: client rendering
return flexiblePalette; //final int bitsPerEntry = MathUtils.bitsToRepresent(entries.size());
//flexiblePalette.resize(bitsPerEntry);
//assert flexiblePalette.bitsPerEntry() == bitsPerEntry;
//return flexiblePalette;
} }
} }
} }