Fix //vis

This commit is contained in:
Jesse Boyd
2019-11-17 17:22:21 +00:00
parent c3f86fd6da
commit 69c225c00f
12 changed files with 77 additions and 54 deletions

View File

@ -63,7 +63,8 @@ public class ChunkPacket implements Function<byte[], byte[]>, Supplier<byte[]> {
synchronized (this) {
if (sectionBytes == null) {
IBlocks tmpChunk = getChunk();
sectionBytes = tmpChunk.toByteArray(FaweCache.IMP.BYTE_BUFFER_8192.get(), tmpChunk.getBitMask());
byte[] buf = FaweCache.IMP.BYTE_BUFFER_8192.get();
sectionBytes = tmpChunk.toByteArray(buf, tmpChunk.getBitMask(), this.full);
}
tmp = sectionBytes;
}

View File

@ -10,21 +10,20 @@ import com.boydti.fawe.beta.implementation.packet.ChunkPacket;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeType;
import java.util.Collection;
import java.util.function.Supplier;
import java.util.stream.Stream;
public class ChunkSendProcessor implements IBatchProcessor {
private final Supplier<Stream<Player>> players;
private final Supplier<Collection<Player>> players;
private final World world;
private final boolean full;
public ChunkSendProcessor(World world, Supplier<Stream<Player>> players) {
public ChunkSendProcessor(World world, Supplier<Collection<Player>> players) {
this(world, players, false);
}
public ChunkSendProcessor(World world, Supplier<Stream<Player>> players, boolean full) {
public ChunkSendProcessor(World world, Supplier<Collection<Player>> players, boolean full) {
this.players = players;
this.world = world;
this.full = full;
@ -34,7 +33,7 @@ public class ChunkSendProcessor implements IBatchProcessor {
return world;
}
public Supplier<Stream<Player>> getPlayers() {
public Supplier<Collection<Player>> getPlayers() {
return players;
}
@ -53,12 +52,15 @@ public class ChunkSendProcessor implements IBatchProcessor {
}
}
ChunkPacket packet = new ChunkPacket(chunkX, chunkZ, () -> blocks, full);
Stream<Player> stream = this.players.get();
Collection<Player> stream = this.players.get();
if (stream == null) {
world.sendFakeChunk(null, packet);
} else {
stream.filter(player -> player.getWorld().equals(world))
.forEach(player -> world.sendFakeChunk(player, packet));
for (Player player : stream) {
if (player.getWorld().equals(world)) {
world.sendFakeChunk(player, packet);
}
}
}
return set;
}

View File

@ -7,6 +7,7 @@ import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.IChunkGet;
import com.boydti.fawe.beta.IChunkSet;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.beta.implementation.IChunkExtent;
import com.boydti.fawe.beta.implementation.packet.ChunkPacket;
import com.boydti.fawe.util.MathMan;
import com.sk89q.worldedit.entity.Player;
@ -14,19 +15,25 @@ import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.world.World;
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.function.Supplier;
import java.util.stream.Stream;
public class PersistentChunkSendProcessor extends ChunkSendProcessor {
private final Long2ObjectLinkedOpenHashMap<Character> current;
private final IQueueExtent queue;
@Nullable
private Long2ObjectLinkedOpenHashMap<Character> previous;
private IChunkExtent queue;
public PersistentChunkSendProcessor(IQueueExtent queue, World world, PersistentChunkSendProcessor previous, Supplier<Stream<Player>> players) {
public PersistentChunkSendProcessor(World world, PersistentChunkSendProcessor previous, Supplier<Collection<Player>> players) {
super(world, players);
this.current = new Long2ObjectLinkedOpenHashMap<>();
this.previous = previous.current;
this.previous = previous != null ? previous.current : null;
}
public void init(IChunkExtent queue) {
this.queue = queue;
}
@ -35,10 +42,15 @@ public class PersistentChunkSendProcessor extends ChunkSendProcessor {
int chunkX = chunk.getX();
int chunkZ = chunk.getZ();
long pair = MathMan.pairInt(chunkX, chunkZ);
Character bitMask = (char) (set.hasBiomes() ? Character.MAX_VALUE : set.getBitMask());
current.put(pair, bitMask);
Character lastValue = previous.remove(pair);
return new CombinedBlocks(get, set, lastValue == null ? 0 : lastValue);
char bitMask = (char) (set.hasBiomes() ? Character.MAX_VALUE : set.getBitMask());
synchronized (this) {
current.put(pair, (Character) bitMask);
if (previous != null) {
Character lastValue = previous.remove(pair);
if (lastValue != null) bitMask |= lastValue;
}
}
return new CombinedBlocks(get, set, bitMask);
}
public void flush() {
@ -47,13 +59,15 @@ public class PersistentChunkSendProcessor extends ChunkSendProcessor {
}
public void clear() {
if (queue == null) throw new IllegalStateException("Queue is not provided");
clear(current);
current.clear();
queue = null;
}
public void clear(Long2ObjectLinkedOpenHashMap<Character> current) {
if (current != null && !current.isEmpty()) {
Stream<Player> players = getPlayers().get();
Collection<Player> players = getPlayers().get();
for (Long2ObjectMap.Entry<Character> entry : current.long2ObjectEntrySet()) {
long pair = entry.getLongKey();
int chunkX = MathMan.unpairIntX(pair);