mirror of
https://github.com/Minestom/Minestom.git
synced 2024-06-25 22:14:53 +02:00
Lighting reduce memory + Fix lighting not sending + Performance (#31)
* Reduce memory
* Clone
* Executor pool + cleanup
* Cleanup
* Don't batch, it's slower
* Parallel chunk loading for test
* Check below chunk 6. Sky light data doesn't appear to be saved above the highest point in the chunk height map.
* Fix weird locking
* ඞ
* Fix test
* Fix indentation
* Use short instead of int
* Use short instead of int
* Start removing borders
* Borders gone
* Cleanup
* Cleanup
* Remove borders fully - Still needs cleanup
* Cleanup 1
* Cleanup 2
* Cleanup 3
* Cleanup 4
* Cache
* Performance
* Performance
* Cleanup
* Cleanup
* Refactor
* Cleanup from self-review
(cherry picked from commit 12aa1e6b7b
)
81 lines
2.2 KiB
Java
81 lines
2.2 KiB
Java
package net.minestom.server.instance;
|
|
|
|
import net.minestom.server.instance.light.Light;
|
|
import net.minestom.server.instance.palette.Palette;
|
|
import net.minestom.server.network.NetworkBuffer;
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import static net.minestom.server.network.NetworkBuffer.SHORT;
|
|
|
|
public final class Section implements NetworkBuffer.Writer {
|
|
private final Palette blockPalette;
|
|
private final Palette biomePalette;
|
|
private final Light skyLight;
|
|
private final Light blockLight;
|
|
|
|
private Section(Palette blockPalette, Palette biomePalette) {
|
|
this.blockPalette = blockPalette;
|
|
this.biomePalette = biomePalette;
|
|
this.skyLight = Light.sky(blockPalette);
|
|
this.blockLight = Light.block(blockPalette);
|
|
}
|
|
|
|
private Section(Palette blockPalette, Palette biomePalette, Light skyLight, Light blockLight) {
|
|
this.blockPalette = blockPalette;
|
|
this.biomePalette = biomePalette;
|
|
this.skyLight = skyLight;
|
|
this.blockLight = blockLight;
|
|
}
|
|
|
|
public Section() {
|
|
this(Palette.blocks(), Palette.biomes());
|
|
}
|
|
|
|
public Palette blockPalette() {
|
|
return blockPalette;
|
|
}
|
|
|
|
public Palette biomePalette() {
|
|
return biomePalette;
|
|
}
|
|
|
|
public void clear() {
|
|
this.blockPalette.fill(0);
|
|
this.biomePalette.fill(0);
|
|
}
|
|
|
|
@Override
|
|
public @NotNull Section clone() {
|
|
final Light skyLight = Light.sky(blockPalette);
|
|
final Light blockLight = Light.block(blockPalette);
|
|
|
|
skyLight.set(this.skyLight.array());
|
|
blockLight.set(this.blockLight.array());
|
|
|
|
return new Section(this.blockPalette.clone(), this.biomePalette.clone(), skyLight, blockLight);
|
|
}
|
|
|
|
@Override
|
|
public void write(@NotNull NetworkBuffer writer) {
|
|
writer.write(SHORT, (short) blockPalette.count());
|
|
writer.write(blockPalette);
|
|
writer.write(biomePalette);
|
|
}
|
|
|
|
public void setSkyLight(byte[] copyArray) {
|
|
this.skyLight.set(copyArray);
|
|
}
|
|
|
|
public void setBlockLight(byte[] copyArray) {
|
|
this.blockLight.set(copyArray);
|
|
}
|
|
|
|
public Light skyLight() {
|
|
return skyLight;
|
|
}
|
|
|
|
public Light blockLight() {
|
|
return blockLight;
|
|
}
|
|
}
|