mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-22 17:27:38 +00:00
Fix //vis
This commit is contained in:
parent
c3f86fd6da
commit
69c225c00f
@ -80,7 +80,7 @@ public class MapChunkUtil_1_14 {
|
||||
try {
|
||||
PacketPlayOutMapChunk nmsPacket;
|
||||
int bitMask = packet.getChunk().getBitMask();
|
||||
if (bitMask == 0) {
|
||||
if (bitMask == 0) { // TODO remove once sending tiles/entities is fixed
|
||||
nmsPacket = Fawe.get().getQueueHandler().sync((Callable<PacketPlayOutMapChunk>) () -> {
|
||||
Chunk nmsChunk = world.getChunkAt(packet.getChunkX(), packet.getChunkZ());
|
||||
PacketPlayOutMapChunk nmsPacket1 = new PacketPlayOutMapChunk(nmsChunk, 65535);
|
||||
|
@ -28,7 +28,7 @@ public class CombinedBlocks implements IBlocks {
|
||||
public CombinedBlocks(IBlocks secondary, IBlocks primary, int addMask) {
|
||||
this.secondary = secondary;
|
||||
this.primary = primary;
|
||||
this.addMask = addMask;
|
||||
this.addMask = addMask == 0 ? 0 : addMask & secondary.getBitMask();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -8,8 +8,10 @@ import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||
import com.sk89q.worldedit.world.block.BlockID;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.registry.BlockRegistry;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -45,11 +47,11 @@ public interface IBlocks extends Trimable {
|
||||
|
||||
IBlocks reset();
|
||||
|
||||
default byte[] toByteArray(int bitMask) {
|
||||
return toByteArray(null, bitMask);
|
||||
default byte[] toByteArray(boolean full) {
|
||||
return toByteArray(null, getBitMask(), full);
|
||||
}
|
||||
|
||||
default byte[] toByteArray(byte[] buffer, int bitMask) {
|
||||
default byte[] toByteArray(byte[] buffer, int bitMask, boolean full) {
|
||||
if (buffer == null) {
|
||||
buffer = new byte[1024];
|
||||
}
|
||||
@ -58,11 +60,11 @@ public interface IBlocks extends Trimable {
|
||||
FastByteArrayOutputStream sectionByteArray = new FastByteArrayOutputStream(buffer);
|
||||
FaweOutputStream sectionWriter = new FaweOutputStream(sectionByteArray);
|
||||
|
||||
System.out.println("Bitmask " + getBitMask());
|
||||
|
||||
try {
|
||||
for (int layer = 0; layer < FaweCache.IMP.CHUNK_LAYERS; layer++) {
|
||||
if (!this.hasSection(layer)) continue;
|
||||
if (!this.hasSection(layer) || (bitMask & (1 << layer)) == 0) continue;
|
||||
|
||||
System.out.println("Write section " + layer);
|
||||
|
||||
char[] ids = this.load(layer);
|
||||
|
||||
@ -83,7 +85,7 @@ public interface IBlocks extends Trimable {
|
||||
|
||||
sectionWriter.writeShort(nonEmpty); // non empty
|
||||
|
||||
// if (false) {
|
||||
// if (false) { // short palette
|
||||
// sectionWriter.writeByte(14); // globalPaletteBitsPerBlock
|
||||
// BitArray4096 bits = new BitArray4096(14); // globalPaletteBitsPerBlock
|
||||
// bits.setAt(0, 0);
|
||||
@ -123,22 +125,7 @@ public interface IBlocks extends Trimable {
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
// if (writeBiomes) {
|
||||
// for (int x = 0; x < 16; x++) {
|
||||
// for (int z = 0; z < 16; z++) {
|
||||
// BiomeType biome = this.getBiomeType(x, z);
|
||||
// if (biome == null) {
|
||||
// if (writeBiomes) {
|
||||
// break;
|
||||
// } else {
|
||||
// biome = BiomeTypes.FOREST;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
if (bitMask == Character.MAX_VALUE) {
|
||||
if (full) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
BiomeType biome = getBiomeType(x, z);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -1187,8 +1187,6 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
char combined = block.getDefaultState().getOrdinalChar();
|
||||
mainArr[index] = combined;
|
||||
floorArr[index] = combined;
|
||||
} else {
|
||||
System.out.println("Block is null: " + color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -193,7 +193,6 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
|
||||
public void close() throws IOException {
|
||||
super.close();
|
||||
synchronized (this) {
|
||||
boolean flushed = osBD != null || osBIO != null || osNBTF != null || osNBTT != null && osENTCF != null || osENTCT != null;
|
||||
try {
|
||||
if (osBD != null) {
|
||||
osBD.close();
|
||||
@ -222,9 +221,6 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (!flushed) {
|
||||
throw new IOException("Empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,6 +48,7 @@ public abstract class FaweChangeSet implements ChangeSet, IBatchProcessor, Close
|
||||
private final String worldName;
|
||||
protected AtomicInteger waitingCombined = new AtomicInteger(0);
|
||||
protected AtomicInteger waitingAsync = new AtomicInteger(0);
|
||||
private boolean closed;
|
||||
|
||||
public static FaweChangeSet getDefaultChangeSet(World world, UUID uuid) {
|
||||
if (Settings.IMP.HISTORY.USE_DISK) {
|
||||
@ -80,6 +81,8 @@ public abstract class FaweChangeSet implements ChangeSet, IBatchProcessor, Close
|
||||
}
|
||||
|
||||
public void closeAsync() {
|
||||
if (closed) return;
|
||||
closed = true;
|
||||
waitingAsync.incrementAndGet();
|
||||
TaskManager.IMP.async(() -> {
|
||||
waitingAsync.decrementAndGet();
|
||||
@ -116,7 +119,10 @@ public abstract class FaweChangeSet implements ChangeSet, IBatchProcessor, Close
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
flush();
|
||||
if (!closed) {
|
||||
closed = true;
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void add(int x, int y, int z, int combinedFrom, int combinedTo);
|
||||
|
@ -77,6 +77,7 @@ import org.enginehub.piston.annotation.param.Switch;
|
||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
@ -151,7 +152,7 @@ public class RegionCommands {
|
||||
@Logging(REGION)
|
||||
public void test(Player player, EditSession editSession, @Selection Region region, @Arg(desc = "hello there") BiomeType biome) throws WorldEditException {
|
||||
System.out.println("Test start");
|
||||
editSession.addProcessor(new ChunkSendProcessor(editSession.getWorld(), () -> Stream.of(player)));
|
||||
editSession.addProcessor(new ChunkSendProcessor(editSession.getWorld(), () -> Collections.singleton(player)));
|
||||
editSession.addProcessor(NullProcessor.INSTANCE);
|
||||
FlatRegionFunction replace = new BiomeReplace(editSession, biome);
|
||||
FlatRegionVisitor visitor = new FlatRegionVisitor(Regions.asFlatRegion(region), replace);
|
||||
|
@ -23,6 +23,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.slf4j.LoggerFactory.getLogger;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.beta.IQueueExtent;
|
||||
import com.boydti.fawe.beta.implementation.IChunkExtent;
|
||||
import com.boydti.fawe.beta.implementation.processors.NullProcessor;
|
||||
import com.boydti.fawe.beta.implementation.processors.PersistentChunkSendProcessor;
|
||||
import com.boydti.fawe.config.BBC;
|
||||
@ -40,6 +42,7 @@ import com.boydti.fawe.object.mask.MaskedTargetBlock;
|
||||
import com.boydti.fawe.object.pattern.PatternTraverser;
|
||||
import com.boydti.fawe.util.BrushCache;
|
||||
import com.boydti.fawe.util.EditSessionBuilder;
|
||||
import com.boydti.fawe.util.ExtentTraverser;
|
||||
import com.boydti.fawe.util.MaskTraverser;
|
||||
import com.boydti.fawe.util.StringMan;
|
||||
import com.boydti.fawe.util.TaskManager;
|
||||
@ -58,6 +61,7 @@ import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extension.platform.Platform;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.MaskIntersection;
|
||||
@ -74,6 +78,8 @@ import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
@ -653,11 +659,20 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
|
||||
.combineStages(true);
|
||||
EditSession editSession = builder.build();
|
||||
|
||||
PersistentChunkSendProcessor previous = null;
|
||||
World world = editSession.getWorld();
|
||||
Supplier<Stream<Player>> players = () -> Stream.of(player);
|
||||
Supplier<Collection<Player>> players = () -> Collections.singleton(player);
|
||||
|
||||
PersistentChunkSendProcessor newVisualExtent = new PersistentChunkSendProcessor(world, previous, players);
|
||||
PersistentChunkSendProcessor newVisualExtent = new PersistentChunkSendProcessor(world, this.visualExtent, players);
|
||||
ExtentTraverser<IChunkExtent> traverser = new ExtentTraverser<>(editSession).find(IChunkExtent.class);
|
||||
if (traverser == null) {
|
||||
throw new IllegalStateException("No queue found");
|
||||
}
|
||||
|
||||
IChunkExtent chunkExtent = traverser.get();
|
||||
if (this.visualExtent != null) {
|
||||
this.visualExtent.init(chunkExtent);
|
||||
}
|
||||
newVisualExtent.init(chunkExtent);
|
||||
|
||||
editSession.addProcessor(newVisualExtent);
|
||||
editSession.addProcessor(NullProcessor.INSTANCE);
|
||||
@ -675,6 +690,8 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
|
||||
}
|
||||
}
|
||||
}
|
||||
editSession.flushQueue();
|
||||
|
||||
if (visualExtent != null) {
|
||||
// clear old data
|
||||
visualExtent.flush();
|
||||
|
@ -457,6 +457,7 @@ public final class PlatformCommandManager {
|
||||
c -> {
|
||||
c.accept(BrushCommandsRegistration.builder(), new BrushCommands(worldEdit));
|
||||
c.accept(ToolCommandsRegistration.builder(), new ToolCommands(worldEdit));
|
||||
c.accept(ToolUtilCommandsRegistration.builder(), new ToolUtilCommands(worldEdit));
|
||||
},
|
||||
manager -> {
|
||||
PaintBrushCommands.register(commandManagerService, manager, registration);
|
||||
|
Loading…
Reference in New Issue
Block a user