WIP VisualExtent

This commit is contained in:
Jesse Boyd
2019-11-16 00:20:14 +00:00
parent 49baebeaa3
commit 0b1a36bb7d
23 changed files with 339 additions and 95 deletions

View File

@ -1,6 +1,8 @@
package com.boydti.fawe.beta.implementation.chunk;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.CombinedBlocks;
import com.boydti.fawe.beta.IBlocks;
import com.boydti.fawe.beta.IQueueChunk;
import com.boydti.fawe.beta.implementation.filter.block.ChunkFilterBlock;
import com.boydti.fawe.beta.Filter;

View File

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

View File

@ -19,6 +19,11 @@ public class BatchProcessorHolder implements IBatchProcessorHolder {
return getProcessor().processSet(chunk, get, set);
}
@Override
public void flush() {
getProcessor().flush();
}
@Override
public void setProcessor(IBatchProcessor set) {
this.processor = set;

View File

@ -1,6 +1,8 @@
package com.boydti.fawe.beta.implementation.processors;
import com.boydti.fawe.beta.CombinedBlocks;
import com.boydti.fawe.beta.IBatchProcessor;
import com.boydti.fawe.beta.IBlocks;
import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.IChunkGet;
import com.boydti.fawe.beta.IChunkSet;
@ -16,18 +18,41 @@ import java.util.stream.Stream;
public class ChunkSendProcessor implements IBatchProcessor {
private final Supplier<Stream<Player>> players;
private final World world;
private final boolean full;
public ChunkSendProcessor(World world, Supplier<Stream<Player>> players) {
this(world, players, false);
}
public ChunkSendProcessor(World world, Supplier<Stream<Player>> players, boolean full) {
this.players = players;
this.world = world;
this.full = full;
}
public World getWorld() {
return world;
}
public Supplier<Stream<Player>> getPlayers() {
return players;
}
@Override
public IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) {
int chunkX = chunk.getX();
int chunkZ = chunk.getZ();
boolean replaceAll = set.hasBiomes();
ChunkPacket packet = new ChunkPacket(chunkX, chunkZ, () -> set, replaceAll);
IBlocks blocks;
boolean full = this.full;
if (full) {
blocks = set;
} else {
blocks = combine(chunk, get, set);
if (set.hasBiomes()) {
full = true;
}
}
ChunkPacket packet = new ChunkPacket(chunkX, chunkZ, () -> blocks, full);
Stream<Player> stream = this.players.get();
if (stream == null) {
world.sendFakeChunk(null, packet);
@ -38,8 +63,12 @@ public class ChunkSendProcessor implements IBatchProcessor {
return set;
}
public IBlocks combine(IChunk chunk, IChunkGet get, IChunkSet set) {
return new CombinedBlocks(get, set, 0);
}
@Override
public Extent construct(Extent child) {
return null;
throw new UnsupportedOperationException("Processing only");
}
}

View File

@ -106,6 +106,11 @@ public class MultiBatchProcessor implements IBatchProcessor {
return this;
}
@Override
public void flush() {
for (IBatchProcessor processor : this.processors) processor.flush();
}
@Override
public String toString() {
return super.toString() + "{" + StringMan.join(processors, ",") + "}";

View File

@ -0,0 +1,61 @@
package com.boydti.fawe.beta.implementation.processors;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.beta.CombinedBlocks;
import com.boydti.fawe.beta.IBlocks;
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.packet.ChunkPacket;
import com.boydti.fawe.util.MathMan;
import com.sk89q.worldedit.entity.Player;
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 java.util.function.Supplier;
import java.util.stream.Stream;
public class PersistentChunkSendProcessor extends ChunkSendProcessor {
private Long2ObjectLinkedOpenHashMap<Character> current;
private Long2ObjectLinkedOpenHashMap<Character> previous;
public PersistentChunkSendProcessor(World world, IQueueExtent queue, PersistentChunkSendProcessor previous, Supplier<Stream<Player>> players) {
super(world, players);
this.current = new Long2ObjectLinkedOpenHashMap<>();
this.previous = previous.current;
}
@Override
public IBlocks combine(IChunk chunk, IChunkGet get, IChunkSet set) {
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);
}
public void flush(IQueueExtent extent) {
if (!previous.isEmpty()) {
Stream<Player> players = getPlayers().get();
for (Long2ObjectMap.Entry<Character> entry : previous.long2ObjectEntrySet()) {
long pair = entry.getLongKey();
int chunkX = MathMan.unpairIntX(pair);
int chunkZ = MathMan.unpairIntY(pair);
BlockVector2 pos = BlockVector2.at(chunkX, chunkZ);
Supplier<IBlocks> chunk = () -> extent.getOrCreateChunk(pos.getX(), pos.getZ());
ChunkPacket packet = new ChunkPacket(pos.getX(), pos.getZ(), chunk, true);
char bitMask = entry.getValue();
if (players == null) {
getWorld().sendFakeChunk(null, packet);
} else {
players.forEach(player -> getWorld().sendFakeChunk(player, packet));
}
}
}
}
}