mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-13 07:09:51 +01:00
send individual section updates when less than half of the sections are updated.
This commit is contained in:
parent
d0163ae749
commit
7166525b8c
@ -8,7 +8,6 @@ import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.entity.pathfinding.PFColumnarSpace;
|
||||
import net.minestom.server.event.player.PlayerChunkLoadEvent;
|
||||
import net.minestom.server.event.player.PlayerChunkUnloadEvent;
|
||||
import net.minestom.server.instance.batch.BatchOption;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.instance.block.BlockManager;
|
||||
import net.minestom.server.instance.block.CustomBlock;
|
||||
@ -31,7 +30,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
// TODO light data & API
|
||||
|
||||
@ -547,23 +545,6 @@ public abstract class Chunk implements Viewable, DataContainer {
|
||||
PacketUtils.sendGroupedPacket(getViewers(), getFreshFullDataPacket());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a single section {@link ChunkDataPacket} to all chunk viewers.
|
||||
*
|
||||
* @param section The section to send.
|
||||
*/
|
||||
public synchronized void sendChunkSectionUpdate(int section) {
|
||||
Check.argCondition(!MathUtils.isBetween(section, 0, CHUNK_SECTION_COUNT),
|
||||
"The chunk section " + section + " does not exist");
|
||||
PacketUtils.sendGroupedPacket(
|
||||
//todo An option to filter out non-netty clients in sendGroupedPacket would be nice.
|
||||
getViewers()
|
||||
.stream()
|
||||
.filter(PlayerUtils::isNettyClient)
|
||||
.collect(Collectors.toUnmodifiableList()),
|
||||
createChunkSectionUpdatePacket(section));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a chunk section update packet to {@code player}.
|
||||
*
|
||||
@ -589,7 +570,6 @@ public abstract class Chunk implements Viewable, DataContainer {
|
||||
@NotNull
|
||||
protected ChunkDataPacket createChunkSectionUpdatePacket(int section) {
|
||||
ChunkDataPacket chunkDataPacket = getFreshPartialDataPacket();
|
||||
chunkDataPacket.fullChunk = false;
|
||||
int[] sections = new int[CHUNK_SECTION_COUNT];
|
||||
sections[section] = 1;
|
||||
chunkDataPacket.sections = sections;
|
||||
|
@ -10,10 +10,13 @@ import net.minestom.server.data.Data;
|
||||
import net.minestom.server.instance.Chunk;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.instance.InstanceContainer;
|
||||
import net.minestom.server.network.packet.server.play.ChunkDataPacket;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import net.minestom.server.utils.block.CustomBlockUtils;
|
||||
import net.minestom.server.utils.callback.OptionalCallback;
|
||||
import net.minestom.server.utils.chunk.ChunkCallback;
|
||||
import net.minestom.server.utils.chunk.ChunkUtils;
|
||||
import net.minestom.server.utils.player.PlayerUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
@ -35,7 +38,6 @@ import java.util.function.IntConsumer;
|
||||
* @see Batch
|
||||
*/
|
||||
public class ChunkBatch implements Batch<ChunkCallback> {
|
||||
private static final int CHUNK_SECTION_THRESHOLD = Chunk.CHUNK_SECTION_COUNT / 2;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ChunkBatch.class);
|
||||
|
||||
|
||||
@ -252,15 +254,14 @@ public class ChunkBatch implements Batch<ChunkCallback> {
|
||||
/**
|
||||
* Updates the given chunk for all of its viewers, and executes the callback.
|
||||
*/
|
||||
private void updateChunk(@NotNull Instance instance, Chunk chunk, IntSet sections, @Nullable ChunkCallback callback, boolean safeCallback) {
|
||||
private void updateChunk(@NotNull Instance instance, Chunk chunk, IntSet updatedSections, @Nullable ChunkCallback callback, boolean safeCallback) {
|
||||
// Refresh chunk for viewers
|
||||
if (sections.size() <= CHUNK_SECTION_THRESHOLD) {
|
||||
// Update only a few sections of the chunk
|
||||
sections.forEach((IntConsumer) chunk::sendChunkSectionUpdate);
|
||||
} else {
|
||||
// Update the entire chunk
|
||||
chunk.sendChunk();
|
||||
}
|
||||
ChunkDataPacket chunkDataPacket = chunk.getFreshPartialDataPacket();
|
||||
int[] sections = new int[Chunk.CHUNK_SECTION_COUNT];
|
||||
for (int section : updatedSections)
|
||||
sections[section] = 1;
|
||||
chunkDataPacket.sections = sections;
|
||||
PacketUtils.sendGroupedPacket(chunk.getViewers(), chunkDataPacket, PlayerUtils::isNettyClient);
|
||||
|
||||
if (instance instanceof InstanceContainer) {
|
||||
// FIXME: put method in Instance instead
|
||||
|
Loading…
Reference in New Issue
Block a user