mirror of https://github.com/Minestom/Minestom.git
reduce memory of loaded lighting
This commit is contained in:
parent
6b8a4e4cc9
commit
667b9016ca
|
@ -5,6 +5,10 @@ import net.minestom.server.instance.palette.Palette;
|
|||
import net.minestom.server.network.NetworkBuffer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static net.minestom.server.instance.light.LightCompute.contentFullyLit;
|
||||
import static net.minestom.server.instance.light.LightCompute.emptyContent;
|
||||
import static net.minestom.server.network.NetworkBuffer.SHORT;
|
||||
|
||||
public final class Section implements NetworkBuffer.Writer {
|
||||
|
@ -49,8 +53,8 @@ public final class Section implements NetworkBuffer.Writer {
|
|||
final Light skyLight = Light.sky(blockPalette);
|
||||
final Light blockLight = Light.block(blockPalette);
|
||||
|
||||
skyLight.set(this.skyLight.array());
|
||||
blockLight.set(this.blockLight.array());
|
||||
setBlockLight(this.skyLight.array());
|
||||
setSkyLight(this.blockLight.array());
|
||||
|
||||
return new Section(this.blockPalette.clone(), this.biomePalette.clone(), skyLight, blockLight);
|
||||
}
|
||||
|
@ -63,11 +67,17 @@ public final class Section implements NetworkBuffer.Writer {
|
|||
}
|
||||
|
||||
public void setSkyLight(byte[] copyArray) {
|
||||
this.skyLight.set(copyArray);
|
||||
if (copyArray == null || copyArray.length == 0) this.skyLight.set(emptyContent);
|
||||
else if (Arrays.equals(copyArray, emptyContent)) this.skyLight.set(emptyContent);
|
||||
else if (Arrays.equals(copyArray, contentFullyLit)) this.skyLight.set(contentFullyLit);
|
||||
else this.skyLight.set(copyArray);
|
||||
}
|
||||
|
||||
public void setBlockLight(byte[] copyArray) {
|
||||
this.blockLight.set(copyArray);
|
||||
if (copyArray == null || copyArray.length == 0) this.blockLight.set(emptyContent);
|
||||
else if (Arrays.equals(copyArray, emptyContent)) this.blockLight.set(emptyContent);
|
||||
else if (Arrays.equals(copyArray, contentFullyLit)) this.blockLight.set(contentFullyLit);
|
||||
else this.blockLight.set(copyArray);
|
||||
}
|
||||
|
||||
public Light skyLight() {
|
||||
|
|
|
@ -195,14 +195,12 @@ final class BlockLight implements Light {
|
|||
}
|
||||
|
||||
@Override
|
||||
@ApiStatus.Internal
|
||||
public void set(byte[] copyArray) {
|
||||
if (copyArray.length == 0) {
|
||||
this.content = emptyContent;
|
||||
this.contentPropagation = emptyContent;
|
||||
} else {
|
||||
this.content = copyArray.clone();
|
||||
this.contentPropagation = this.content;
|
||||
}
|
||||
this.content = copyArray.clone();
|
||||
this.contentPropagation = this.content;
|
||||
this.isValidBorders = true;
|
||||
this.needsSend = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,6 +7,7 @@ import net.minestom.server.instance.palette.Palette;
|
|||
import net.minestom.server.utils.Direction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import static net.minestom.server.instance.light.BlockLight.buildInternalQueue;
|
||||
|
@ -17,6 +18,11 @@ public final class LightCompute {
|
|||
static final int SECTION_SIZE = 16;
|
||||
|
||||
public static final byte[] emptyContent = new byte[LIGHT_LENGTH];
|
||||
public static final byte[] contentFullyLit = new byte[LIGHT_LENGTH];
|
||||
|
||||
static {
|
||||
Arrays.fill(contentFullyLit, (byte) -1);
|
||||
}
|
||||
|
||||
static @NotNull Result compute(Palette blockPalette) {
|
||||
return LightCompute.compute(blockPalette, buildInternalQueue(blockPalette));
|
||||
|
|
|
@ -10,8 +10,8 @@ import net.minestom.server.instance.Section;
|
|||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.instance.block.BlockFace;
|
||||
import net.minestom.server.instance.palette.Palette;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -29,13 +29,7 @@ final class SkyLight implements Light {
|
|||
|
||||
private Set<Point> toUpdateSet = new HashSet<>();
|
||||
private final Section[] neighborSections = new Section[BlockFace.values().length];
|
||||
|
||||
private boolean fullyLit = false;
|
||||
private static final byte[] contentFullyLit = new byte[LIGHT_LENGTH];
|
||||
|
||||
static {
|
||||
Arrays.fill(contentFullyLit, (byte) -1);
|
||||
}
|
||||
|
||||
SkyLight(Palette blockPalette) {
|
||||
this.blockPalette = blockPalette;
|
||||
|
@ -220,14 +214,12 @@ final class SkyLight implements Light {
|
|||
}
|
||||
|
||||
@Override
|
||||
@ApiStatus.Internal
|
||||
public void set(byte[] copyArray) {
|
||||
if (copyArray.length == 0) {
|
||||
this.content = emptyContent;
|
||||
this.contentPropagation = emptyContent;
|
||||
} else {
|
||||
this.content = copyArray.clone();
|
||||
this.contentPropagation = this.content;
|
||||
}
|
||||
this.content = copyArray.clone();
|
||||
this.contentPropagation = this.content;
|
||||
this.isValidBorders = true;
|
||||
this.needsSend = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue