mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-11 20:13:55 +00:00
tile/biome/entity set
This commit is contained in:
@ -1,8 +1,12 @@
|
||||
package com.boydti.fawe.beta;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Interface for setting blocks
|
||||
*/
|
||||
@ -13,6 +17,12 @@ public interface ISetBlocks extends IBlocks {
|
||||
|
||||
boolean isEmpty();
|
||||
|
||||
void setTile(int x, int y, int z, CompoundTag tile);
|
||||
|
||||
void setEntity(CompoundTag tag);
|
||||
|
||||
void removeEntity(UUID uuid);
|
||||
|
||||
default void optimize() {
|
||||
|
||||
}
|
||||
|
@ -20,11 +20,13 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.ForkJoinTask;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.FutureTask;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
/**
|
||||
@ -34,7 +36,7 @@ public abstract class QueueHandler implements Trimable {
|
||||
private ForkJoinPool forkJoinPoolPrimary = new ForkJoinPool();
|
||||
private ForkJoinPool forkJoinPoolSecondary = new ForkJoinPool();
|
||||
private ThreadPoolExecutor blockingExecutor = FaweCache.newBlockingExecutor();
|
||||
private ConcurrentLinkedQueue<Runnable> syncTasks = new ConcurrentLinkedQueue();
|
||||
private ConcurrentLinkedQueue<FutureTask> syncTasks = new ConcurrentLinkedQueue();
|
||||
|
||||
private Map<World, WeakReference<WorldChunkCache>> chunkCache = new HashMap<>();
|
||||
private IterableThreadLocal<IQueueExtent> queuePool = new IterableThreadLocal<IQueueExtent>() {
|
||||
@ -44,6 +46,32 @@ public abstract class QueueHandler implements Trimable {
|
||||
}
|
||||
};
|
||||
|
||||
public <T> Future<T> async(Runnable run, T value) {
|
||||
return forkJoinPoolSecondary.submit(run, value);
|
||||
}
|
||||
|
||||
public <T> Future<T> async(Callable<T> call) {
|
||||
return forkJoinPoolSecondary.submit(call);
|
||||
}
|
||||
|
||||
public <T> Future<T> sync(Runnable run, T value) {
|
||||
FutureTask<T> result = new FutureTask<>(run, value);
|
||||
syncTasks.add(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public <T> Future<T> sync(Runnable run) {
|
||||
FutureTask<T> result = new FutureTask<>(run, null);
|
||||
syncTasks.add(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public <T> Future<T> sync(Callable<T> call) {
|
||||
FutureTask<T> result = new FutureTask<>(call);
|
||||
syncTasks.add(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public <T extends Future<T>> T submit(IChunk<T> chunk) {
|
||||
if (MemUtil.isMemoryFree()) {
|
||||
// return (T) forkJoinPoolSecondary.submit(chunk);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.boydti.fawe.beta.implementation.blocks;
|
||||
|
||||
import com.boydti.fawe.beta.ISetBlocks;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
@ -10,10 +11,10 @@ import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
public class CharSetBlocks extends CharBlocks implements ISetBlocks {
|
||||
private BiomeType[] biomes;
|
||||
private HashMap<Short, CompoundTag> tiles;
|
||||
private HashSet<CompoundTag> entities;
|
||||
private HashSet<UUID> entityRemoves;
|
||||
public BiomeType[] biomes;
|
||||
public HashMap<Short, CompoundTag> tiles;
|
||||
public HashSet<CompoundTag> entities;
|
||||
public HashSet<UUID> entityRemoves;
|
||||
|
||||
@Override
|
||||
public boolean setBiome(int x, int y, int z, BiomeType biome) {
|
||||
@ -30,6 +31,31 @@ public class CharSetBlocks extends CharBlocks implements ISetBlocks {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(int x, int y, int z, CompoundTag tile) {
|
||||
if (tiles == null) {
|
||||
tiles = new HashMap<>();
|
||||
}
|
||||
short pair = MathMan.tripleBlockCoord(x, y, z);
|
||||
tiles.put(pair, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEntity(CompoundTag tag) {
|
||||
if (entities == null) {
|
||||
entities = new HashSet<>();
|
||||
}
|
||||
entities.add(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEntity(UUID uuid) {
|
||||
if (entityRemoves == null) {
|
||||
entityRemoves = new HashSet<>();
|
||||
}
|
||||
entityRemoves.add(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
if (biomes != null) return false;
|
||||
@ -44,6 +70,9 @@ public class CharSetBlocks extends CharBlocks implements ISetBlocks {
|
||||
@Override
|
||||
public void reset() {
|
||||
biomes = null;
|
||||
tiles = null;
|
||||
entities = null;
|
||||
entityRemoves = null;
|
||||
super.reset();
|
||||
}
|
||||
}
|
@ -302,9 +302,11 @@ public class RegionCommands extends MethodCommands {
|
||||
for (BlockVector3 p : region) {
|
||||
queue.setBlock(p.getX(), p.getY(), p.getZ(), block);
|
||||
}
|
||||
long start2 = System.currentTimeMillis();
|
||||
queue.flush();
|
||||
long diff = System.currentTimeMillis() - start;
|
||||
System.out.println(diff);
|
||||
long diff2 = System.currentTimeMillis() - start2;
|
||||
System.out.println(diff + " | " + diff2);
|
||||
}
|
||||
|
||||
@Command(
|
||||
|
Reference in New Issue
Block a user