WIP rewrite of NMS pipeline

This commit is contained in:
Jesse Boyd 2019-04-25 20:32:27 +10:00
parent 8808ec89a0
commit 35fd159e79
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
14 changed files with 268 additions and 4 deletions

View File

@ -0,0 +1,29 @@
package com.boydti.fawe.bukkit.v1_13.beta;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import net.minecraft.server.v1_13_R2.Chunk;
import net.minecraft.server.v1_13_R2.ChunkSection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.UUID;
public class CachedChunk {
private GetBlocks get;
private SetBlocks set;
public CachedChunk(ReusableExtent parent) {
}
public void init(int X, int Z) {
}
}

View File

@ -0,0 +1,5 @@
package com.boydti.fawe.bukkit.v1_13.beta;
public class CharBlocks implements IBlocks {
protected char[][] blocks;
}

View File

@ -0,0 +1,7 @@
package com.boydti.fawe.bukkit.v1_13.beta;
import net.minecraft.server.v1_13_R2.ChunkSection;
public class CharGetBlocks extends CharBlocks implements IGetBlocks {
private ChunkSection[] sections;
}

View File

@ -0,0 +1,14 @@
package com.boydti.fawe.bukkit.v1_13.beta;
import com.sk89q.jnbt.CompoundTag;
import java.util.HashMap;
import java.util.HashSet;
import java.util.UUID;
public class CharSetBlocks extends CharBlocks implements ISetBlocks {
private byte[] biomes;
private HashMap<Short, CompoundTag> tiles;
private HashSet<CompoundTag> entities;
private HashSet<UUID> entityRemoves;
}

View File

@ -0,0 +1,5 @@
package com.boydti.fawe.bukkit.v1_13.beta;
public interface IBlocks {
}

View File

@ -0,0 +1,20 @@
package com.boydti.fawe.bukkit.v1_13.beta;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
public interface IChunk {
/* set */
void setBiome(int x, int z, BiomeType biome);
void setBlock(int x, int y, int z, BlockStateHolder holder);
/* get */
BiomeType getBiome(int x, int z);
BlockState getBlock(int x, int y, int z);
BaseBlock getFullBlock(int x, int y, int z);
}

View File

@ -0,0 +1,4 @@
package com.boydti.fawe.bukkit.v1_13.beta;
public interface IGetBlocks extends IBlocks {
}

View File

@ -0,0 +1,4 @@
package com.boydti.fawe.bukkit.v1_13.beta;
public interface ISetBlocks extends IBlocks {
}

View File

@ -0,0 +1,9 @@
package com.boydti.fawe.bukkit.v1_13.beta;
import net.minecraft.server.v1_13_R2.Chunk;
public class RegionCachedChunk extends CachedChunk {
public RegionCachedChunk(Chunk chunk) {
super(chunk);
}
}

View File

@ -0,0 +1,150 @@
package com.boydti.fawe.bukkit.v1_13.beta;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.jnbt.anvil.MCAFilter;
import com.boydti.fawe.util.TaskManager;
import com.boydti.fawe.wrappers.WorldWrapper;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import net.minecraft.server.v1_13_R2.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_13_R2.CraftWorld;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.ForkJoinPool;
import static com.google.common.base.Preconditions.checkNotNull;
public class ReusableExtent {
private WorldWrapper wrapped;
private World world;
private org.bukkit.World bukkitWorld;
private WorldServer nmsWorld;
private void reset() {
if (world != null) {
wrapped = null;
world = null;
bukkitWorld = null;
nmsWorld = null;
lowMemory = false;
}
}
public void init(World world) {
reset();
checkNotNull(world);
if (world instanceof EditSession) {
world = ((EditSession) world).getWorld();
}
checkNotNull(world);
if (world instanceof WorldWrapper) {
this.wrapped = (WorldWrapper) world;
world = WorldWrapper.unwrap(world);
} else {
this.world = WorldWrapper.wrap(world);
}
this.world = world;
if (world instanceof BukkitWorld) {
this.bukkitWorld = ((BukkitWorld) world).getWorld();
} else {
this.bukkitWorld = Bukkit.getWorld(world.getName());
}
checkNotNull(this.bukkitWorld);
CraftWorld craftWorld = ((CraftWorld) bukkitWorld);
this.nmsWorld = craftWorld.getHandle();
// Save world
}
private boolean lowMemory;
public void setLowMemory() {
lowMemory = true;
// set queue state to active
// trim cached chunks
}
private CachedChunk getCachedChunk(int x, int z) {
// check last
// otherwise create/load
// get cached chunk from bukkit
// otherwise load
// TODO load async (with paper)
if (lowMemory) {
if (Fawe.isMainThread()) {
// submit other chunks
next();
} else {
// wait until empty
}
}
}
void setBlock(int x, int y, int z, BlockStateHolder holder) {
CachedChunk chunk = getCachedChunk(x, z);
chunk.setBlock(x & 15, y, z & 15, holder);
}
void setBiome(int x, int z, BiomeType biome) {
CachedChunk chunk = getCachedChunk(x, z);
chunk.setBiome(x, z, biome);
}
BlockState getBlock(int x, int y, int z) {
CachedChunk chunk = getCachedChunk(x, z);
return chunk.getBlock(x & 15, y, z & 15);
}
BiomeType getBiome(int x, int z) {
CachedChunk chunk = getCachedChunk(x, z);
return chunk.getBiome(x, z);
}
public <T> void apply(Region region, MCAFilter<T> filter) { // TODO not MCAFilter, but another similar class
// TODO iterate by mca file
Set<BlockVector2> chunks = region.getChunks();
Iterator<BlockVector2> chunksIter = chunks.iterator();
ForkJoinPool pool = TaskManager.IMP.getPublicForkJoinPool();
for (int i = 0; i < Runtime.getRuntime().availableProcessors(); i++) {
pool.submit(new Runnable() {
@Override
public void run() {
while (true) {
BlockVector2 pos;
synchronized (chunksIter) {
if (!chunksIter.hasNext()) return;
pos = chunksIter.next();
}
int cx = pos.getX();
int cz = pos.getZ();
CachedChunk chunk = getCachedChunk(cx, cz);
try {
if (!filter.appliesChunk(cx, cz)) {
continue;
}
T value = filter.get();
chunk = filter.applyChunk(chunk, value);
if (chunk == null) continue;
// TODO if region contains all parts
chunk.filter(filter);
// else
chunk.filter(region, filter);
} finally {
// TODO submit chunk
}
}
}
});
}
}
}

View File

@ -0,0 +1,13 @@
package com.boydti.fawe.bukkit.v1_13.beta.holder;
import com.boydti.fawe.bukkit.v1_13.beta.IChunk;
public class ChunkHolder implements IChunk {
private ChunkHolder implementation;
public ChunkHolder() {
}
public ChunkHolder(IChunkH)
}

View File

@ -0,0 +1,7 @@
package com.boydti.fawe.bukkit.v1_13.beta.holder;
import com.boydti.fawe.bukkit.v1_13.beta.IChunk;
public class SetChunk extends ChunkHolder {
}

View File

@ -257,8 +257,8 @@ public class Settings extends Config {
public static class QUEUE {
@Comment({
"This should equal the number of processors you have",
" - Set this to 1 if you need reliable `/timings`"
})
@Final
public int PARALLEL_THREADS = Math.max(1, Runtime.getRuntime().availableProcessors());
@Create
public static PROGRESS PROGRESS;

View File

@ -78,9 +78,6 @@ public class MCAChunk extends FaweChunk<Void> {
}
public void write(NBTOutputStream nbtOut) throws IOException {
nbtOut.writeNamedTagName("", NBTConstants.TYPE_COMPOUND);
nbtOut.writeLazyCompoundTag("Level", out -> {
out.writeNamedTag("V", (byte) 1);