mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-10 05:39:11 +01:00
Use a bitset for light mask (thanks @Kebab11noel)
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
d53ef36586
commit
872a49d371
@ -177,8 +177,6 @@ public class DynamicChunk extends Chunk {
|
||||
}
|
||||
|
||||
private synchronized @NotNull UpdateLightPacket createLightPacket() {
|
||||
long skyMask = 0;
|
||||
long blockMask = 0;
|
||||
List<byte[]> skyLights = new ArrayList<>();
|
||||
List<byte[]> blockLights = new ArrayList<>();
|
||||
|
||||
@ -199,18 +197,13 @@ public class DynamicChunk extends Chunk {
|
||||
|
||||
if (!ArrayUtils.empty(skyLight)) {
|
||||
skyLights.add(skyLight);
|
||||
skyMask |= 1L << index;
|
||||
updateLightPacket.skyLightMask.set(index);
|
||||
}
|
||||
if (!ArrayUtils.empty(blockLight)) {
|
||||
blockLights.add(blockLight);
|
||||
blockMask |= 1L << index;
|
||||
updateLightPacket.blockLightMask.set(index);
|
||||
}
|
||||
}
|
||||
|
||||
updateLightPacket.skyLightMask = new long[]{skyMask};
|
||||
updateLightPacket.blockLightMask = new long[]{blockMask};
|
||||
updateLightPacket.emptySkyLightMask = new long[0];
|
||||
updateLightPacket.emptyBlockLightMask = new long[0];
|
||||
return updateLightPacket;
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.List;
|
||||
|
||||
public class UpdateLightPacket implements ServerPacket {
|
||||
@ -16,11 +17,11 @@ public class UpdateLightPacket implements ServerPacket {
|
||||
//todo make changeable
|
||||
public boolean trustEdges = true;
|
||||
|
||||
public long[] skyLightMask = new long[0];
|
||||
public long[] blockLightMask = new long[0];
|
||||
public BitSet skyLightMask = new BitSet();
|
||||
public BitSet blockLightMask = new BitSet();
|
||||
|
||||
public long[] emptySkyLightMask = new long[0];
|
||||
public long[] emptyBlockLightMask = new long[0];
|
||||
public BitSet emptySkyLightMask = new BitSet();
|
||||
public BitSet emptyBlockLightMask = new BitSet();
|
||||
|
||||
public List<byte[]> skyLight = new ArrayList<>();
|
||||
public List<byte[]> blockLight = new ArrayList<>();
|
||||
@ -38,11 +39,11 @@ public class UpdateLightPacket implements ServerPacket {
|
||||
|
||||
writer.writeBoolean(trustEdges);
|
||||
|
||||
writer.writeLongArray(skyLightMask);
|
||||
writer.writeLongArray(blockLightMask);
|
||||
writer.writeLongArray(skyLightMask.toLongArray());
|
||||
writer.writeLongArray(blockLightMask.toLongArray());
|
||||
|
||||
writer.writeLongArray(emptySkyLightMask);
|
||||
writer.writeLongArray(emptyBlockLightMask);
|
||||
writer.writeLongArray(emptySkyLightMask.toLongArray());
|
||||
writer.writeLongArray(emptyBlockLightMask.toLongArray());
|
||||
|
||||
writer.writeVarInt(skyLight.size());
|
||||
for (byte[] bytes : skyLight) {
|
||||
@ -64,11 +65,11 @@ public class UpdateLightPacket implements ServerPacket {
|
||||
|
||||
trustEdges = reader.readBoolean();
|
||||
|
||||
skyLightMask = reader.readLongArray();
|
||||
blockLightMask = reader.readLongArray();
|
||||
skyLightMask = BitSet.valueOf(reader.readLongArray());
|
||||
blockLightMask = BitSet.valueOf(reader.readLongArray());
|
||||
|
||||
emptySkyLightMask = reader.readLongArray();
|
||||
emptyBlockLightMask = reader.readLongArray();
|
||||
emptySkyLightMask = BitSet.valueOf(reader.readLongArray());
|
||||
emptyBlockLightMask = BitSet.valueOf(reader.readLongArray());
|
||||
|
||||
// sky light
|
||||
skyLight.clear();
|
||||
|
Loading…
Reference in New Issue
Block a user