wip brush vis mode

This commit is contained in:
Jesse Boyd 2019-11-17 05:00:10 +11:00
parent 0b1a36bb7d
commit c3f86fd6da
2 changed files with 34 additions and 12 deletions

View File

@ -19,13 +19,15 @@ import java.util.function.Supplier;
import java.util.stream.Stream; import java.util.stream.Stream;
public class PersistentChunkSendProcessor extends ChunkSendProcessor { public class PersistentChunkSendProcessor extends ChunkSendProcessor {
private Long2ObjectLinkedOpenHashMap<Character> current; private final Long2ObjectLinkedOpenHashMap<Character> current;
private final IQueueExtent queue;
private Long2ObjectLinkedOpenHashMap<Character> previous; private Long2ObjectLinkedOpenHashMap<Character> previous;
public PersistentChunkSendProcessor(World world, IQueueExtent queue, PersistentChunkSendProcessor previous, Supplier<Stream<Player>> players) { public PersistentChunkSendProcessor(IQueueExtent queue, World world, PersistentChunkSendProcessor previous, Supplier<Stream<Player>> players) {
super(world, players); super(world, players);
this.current = new Long2ObjectLinkedOpenHashMap<>(); this.current = new Long2ObjectLinkedOpenHashMap<>();
this.previous = previous.current; this.previous = previous.current;
this.queue = queue;
} }
@Override @Override
@ -39,15 +41,25 @@ public class PersistentChunkSendProcessor extends ChunkSendProcessor {
return new CombinedBlocks(get, set, lastValue == null ? 0 : lastValue); return new CombinedBlocks(get, set, lastValue == null ? 0 : lastValue);
} }
public void flush(IQueueExtent extent) { public void flush() {
if (!previous.isEmpty()) { clear(previous);
previous = null;
}
public void clear() {
clear(current);
current.clear();
}
public void clear(Long2ObjectLinkedOpenHashMap<Character> current) {
if (current != null && !current.isEmpty()) {
Stream<Player> players = getPlayers().get(); Stream<Player> players = getPlayers().get();
for (Long2ObjectMap.Entry<Character> entry : previous.long2ObjectEntrySet()) { for (Long2ObjectMap.Entry<Character> entry : current.long2ObjectEntrySet()) {
long pair = entry.getLongKey(); long pair = entry.getLongKey();
int chunkX = MathMan.unpairIntX(pair); int chunkX = MathMan.unpairIntX(pair);
int chunkZ = MathMan.unpairIntY(pair); int chunkZ = MathMan.unpairIntY(pair);
BlockVector2 pos = BlockVector2.at(chunkX, chunkZ); BlockVector2 pos = BlockVector2.at(chunkX, chunkZ);
Supplier<IBlocks> chunk = () -> extent.getOrCreateChunk(pos.getX(), pos.getZ()); Supplier<IBlocks> chunk = () -> queue.getOrCreateChunk(pos.getX(), pos.getZ());
ChunkPacket packet = new ChunkPacket(pos.getX(), pos.getZ(), chunk, true); ChunkPacket packet = new ChunkPacket(pos.getX(), pos.getZ(), chunk, true);
char bitMask = entry.getValue(); char bitMask = entry.getValue();
if (players == null) { if (players == null) {

View File

@ -23,6 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger; import static org.slf4j.LoggerFactory.getLogger;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.beta.implementation.processors.NullProcessor;
import com.boydti.fawe.beta.implementation.processors.PersistentChunkSendProcessor; import com.boydti.fawe.beta.implementation.processors.PersistentChunkSendProcessor;
import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.BBC;
import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.object.RunnableVal;
@ -67,6 +68,7 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.session.request.Request; import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
@ -76,6 +78,8 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Supplier;
import java.util.stream.Stream;
import javax.annotation.Nullable; import javax.annotation.Nullable;
/** /**
@ -104,7 +108,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
private transient BrushSettings secondary = new BrushSettings(); private transient BrushSettings secondary = new BrushSettings();
private transient BrushSettings context = primary; private transient BrushSettings context = primary;
private transient VisualExtent visualExtent; private transient PersistentChunkSendProcessor visualExtent;
private transient Lock lock = new ReentrantLock(); private transient Lock lock = new ReentrantLock();
private transient BaseItem holder; private transient BaseItem holder;
@ -649,11 +653,17 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
.combineStages(true); .combineStages(true);
EditSession editSession = builder.build(); EditSession editSession = builder.build();
// processor = new PersistentChunkSendProcessor() PersistentChunkSendProcessor previous = null;
VisualExtent newVisualExtent = new VisualExtent(editSession, player); World world = editSession.getWorld();
Supplier<Stream<Player>> players = () -> Stream.of(player);
PersistentChunkSendProcessor newVisualExtent = new PersistentChunkSendProcessor(world, previous, players);
editSession.addProcessor(newVisualExtent);
editSession.addProcessor(NullProcessor.INSTANCE);
BlockVector3 position = getPosition(editSession, player); BlockVector3 position = getPosition(editSession, player);
if (position != null) { if (position != null) {
editSession.setExtent(newVisualExtent);
switch (mode) { switch (mode) {
case POINT: case POINT:
editSession.setBlock(position, VisualExtent.VISUALIZE_BLOCK_DEFAULT); editSession.setBlock(position, VisualExtent.VISUALIZE_BLOCK_DEFAULT);
@ -667,10 +677,10 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
} }
if (visualExtent != null) { if (visualExtent != null) {
// clear old data // clear old data
visualExtent.clear(); visualExtent.flush();
} }
visualExtent = newVisualExtent; visualExtent = newVisualExtent;
newVisualExtent.commit(); newVisualExtent.flush();
} }
public void clear(Player player) { public void clear(Player player) {