Multiple changes

Working on async schematic saving
Default plot clearing is now properly async (and somewhat slower)
Offline mode servers now default to lowercase (there has been ample time
to update)
Fixed some issues with plot expiry
Fixed some issues with UUID caching
Optimized UUID fetching from cache (marginal)
This commit is contained in:
boy0001
2015-07-19 23:12:48 +10:00
parent 404933c3a7
commit 9c635810b0
14 changed files with 210 additions and 140 deletions

View File

@ -80,30 +80,30 @@ public class BukkitHybridUtils extends HybridUtils {
final int ctz = tz >> 4;
final Random r = new Random();
AugmentedPopulator.initCache();
final int width = tx - bx + 1;
final int length = tz - bz + 1;
System.gc();
System.gc();
final short[][][] oldblocks = new short[256][width][length];
final short[][][] newblocks = new short[256][width][length];
final List<Chunk> chunks = new ArrayList<>();
final List<Chunk> processed_chunks = new ArrayList<>();
final List<ChunkLoc> chunks = new ArrayList<>();
final List<ChunkLoc> processed_chunks = new ArrayList<>();
for (int X = cbx; X <= ctx; X++) {
for (int Z = cbz; Z <= ctz; Z++) {
Chunk chunk = world.getChunkAt(X, Z);
chunks.add(chunk);
// Chunk chunk = world.getChunkAt(X, Z);
chunks.add(new ChunkLoc(X, Z));
}
}
final Runnable run = new Runnable() {
@Override
public void run() {
for (Chunk chunk : processed_chunks) {
short[][] result = gen.generateExtBlockSections(world, r, chunk.getX(), chunk.getZ(), base);
int X = chunk.getX();
int Z = chunk.getZ();
for (ChunkLoc chunk : processed_chunks) {
short[][] result = gen.generateExtBlockSections(world, r, chunk.x, chunk.z, base);
int X = chunk.x;
int Z = chunk.z;
int xb = ((X) << 4) - bx;
int zb = ((Z) << 4) - bz;
for (int i = 0; i < result.length; i++) {
@ -128,7 +128,6 @@ public class BukkitHybridUtils extends HybridUtils {
}
}
}
int size = width * length;
int[] changes = new int[size];
int[] faces = new int[size];
@ -176,7 +175,6 @@ public class BukkitHybridUtils extends HybridUtils {
i++;
}
}
// analyze plot
// put in analysis obj
@ -206,18 +204,16 @@ public class BukkitHybridUtils extends HybridUtils {
result.add(analysis.data_sd);
result.add(analysis.air_sd);
result.add(analysis.variety_sd);
Flag flag = new Flag(FlagManager.getFlag("analysis"), result);
FlagManager.addPlotFlag(plot, flag);
System.gc();
System.gc();
whenDone.value = analysis;
whenDone.run();
}
};
System.gc();
AugmentedPopulator.initCache();
TaskManager.index.increment();
final Integer currentIndex = TaskManager.index.toInteger();
final Integer task = TaskManager.runTaskRepeat(new Runnable() {
@ -229,10 +225,11 @@ public class BukkitHybridUtils extends HybridUtils {
TaskManager.runTaskAsync(run);
return;
}
Chunk chunk = chunks.remove(0);
ChunkLoc chunk = chunks.remove(0);
world.loadChunk(chunk.x, chunk.z);
processed_chunks.add(chunk);
int X = chunk.getX();
int Z = chunk.getZ();
int X = chunk.x;
int Z = chunk.z;
int minX;
int minZ;
int maxX;
@ -246,19 +243,24 @@ public class BukkitHybridUtils extends HybridUtils {
if (Z == ctz) maxZ = MathMan.mod(tz);
else maxZ = 16;
int xb = ((X) << 4) - bx;
int zb = ((Z) << 4) - bz;
int cbx = X << 4;
int cbz = Z << 4;
int xb = (cbx) - bx;
int zb = (cbz) - bz;
for (int x = minX; x <= maxX; x++) {
int xx = cbx + cbz;
for (int z = minZ; z <= maxZ; z++) {
int zz = cbz + z;
for (int y = 0; y < 256; y++) {
Block block = chunk.getBlock(x, y, z);
int xx = xb + x;
int zz = zb + z;
newblocks[y][xx][zz] = (short) block.getTypeId();
Block block = world.getBlockAt(xx, y, zz);
int xr = xb + x;
int zr = zb + z;
newblocks[y][xr][zr] = (short) block.getTypeId();
}
}
}
world.unloadChunkRequest(chunk.x, chunk.z, true);
}
}, 1);
TaskManager.tasks.put(currentIndex, task);

View File

@ -23,12 +23,14 @@ package com.intellectualcrafters.plot.generator;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.commands.Template;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.FileBytes;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
@ -173,68 +175,85 @@ public class HybridPlotManager extends ClassicPlotManager {
final Location pos2 = MainUtil.getPlotTopLocAbs(world, plot.id);
setWallFilling(dpw, plot.id, new PlotBlock[] { dpw.WALL_FILLING });
int p1x = pos1.getX();
int p1z = pos1.getZ();
int p2x = pos2.getX();
int p2z = pos2.getZ();
int bcx = p1x >> 4;
int bcz = p1z >> 4;
int tcx = p2x >> 4;
int tcz = p2z >> 4;
final int p1x = pos1.getX();
final int p1z = pos1.getZ();
final int p2x = pos2.getX();
final int p2z = pos2.getZ();
final int bcx = p1x >> 4;
final int bcz = p1z >> 4;
final int tcx = p2x >> 4;
final int tcz = p2z >> 4;
boolean canRegen = plotworld.TYPE == 0 && plotworld.TERRAIN == 0;
final boolean canRegen = plotworld.TYPE == 0 && plotworld.TERRAIN == 0;
final PlotBlock[] plotfloor = dpw.TOP_BLOCK;
final PlotBlock[] filling = dpw.MAIN_BLOCK;
final PlotBlock[] bedrock = (dpw.PLOT_BEDROCK ? new PlotBlock[] { new PlotBlock((short) 7, (byte) 0) } : filling);
PlotBlock air = new PlotBlock((short) 0, (byte) 0);
final PlotBlock air = new PlotBlock((short) 0, (byte) 0);
final ArrayList<ChunkLoc> chunks = new ArrayList<ChunkLoc>();
for (int x = bcx; x <= tcx; x++) {
for (int z = bcz; z <= tcz; z++) {
int xxb = x << 4;
int zzb = z << 4;
int xxt = xxb + 15;
int zzt = zzb + 15;
if (canRegen) {
if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z) {
BukkitUtil.regenerateChunk(world, x, z);
if (!MainUtil.canSendChunk) {
// BukkitUtil.refreshChunk(world, x, z);
}
continue;
}
}
if (x == bcx) {
xxb = p1x;
}
if (x == tcx) {
xxt = p2x;
}
if (z == bcz) {
zzb = p1z;
}
if (z == tcz) {
zzt = p2z;
}
BukkitUtil.setBiome(plot.world, xxb, zzb, xxt, zzt, dpw.PLOT_BIOME);
Location bot = new Location(world, xxb, 0, zzb);
Location top = new Location(world, xxt + 1, 1, zzt + 1);
MainUtil.setCuboidAsync(world, bot, top, bedrock);
bot.setY(1);
top.setY(dpw.PLOT_HEIGHT);
MainUtil.setCuboidAsync(world, bot, top, filling);
bot.setY(dpw.PLOT_HEIGHT);
top.setY(dpw.PLOT_HEIGHT + 1);
MainUtil.setCuboidAsync(world, bot, top, plotfloor);
bot.setY(dpw.PLOT_HEIGHT + 1);
top.setY(256);
MainUtil.setSimpleCuboidAsync(world, bot, top, air);
chunks.add(new ChunkLoc(x, z));
}
}
pastePlotSchematic(dpw, pos1, pos2);
final PlotBlock wall = isDelete ? dpw.WALL_BLOCK : dpw.CLAIMED_WALL_BLOCK;
setWall(dpw, plot.id, new PlotBlock[] { wall });
SetBlockQueue.addNotify(whenDone);
TaskManager.runTask(new Runnable() {
@Override
public void run() {
long start = System.currentTimeMillis();
while (chunks.size() > 0 && System.currentTimeMillis() - start < 20) {
ChunkLoc chunk = chunks.remove(0);
int x = chunk.x;
int z = chunk.z;
int xxb = x << 4;
int zzb = z << 4;
int xxt = xxb + 15;
int zzt = zzb + 15;
if (canRegen) {
if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z) {
BukkitUtil.regenerateChunk(world, x, z);
continue;
}
}
if (x == bcx) {
xxb = p1x;
}
if (x == tcx) {
xxt = p2x;
}
if (z == bcz) {
zzb = p1z;
}
if (z == tcz) {
zzt = p2z;
}
BukkitUtil.setBiome(plot.world, xxb, zzb, xxt, zzt, dpw.PLOT_BIOME);
Location bot = new Location(world, xxb, 0, zzb);
Location top = new Location(world, xxt + 1, 1, zzt + 1);
MainUtil.setCuboidAsync(world, bot, top, bedrock);
bot.setY(1);
top.setY(dpw.PLOT_HEIGHT);
MainUtil.setCuboidAsync(world, bot, top, filling);
bot.setY(dpw.PLOT_HEIGHT);
top.setY(dpw.PLOT_HEIGHT + 1);
MainUtil.setCuboidAsync(world, bot, top, plotfloor);
bot.setY(dpw.PLOT_HEIGHT + 1);
top.setY(256);
MainUtil.setSimpleCuboidAsync(world, bot, top, air);
}
if (chunks.size() != 0) {
TaskManager.runTaskLater(this, 1);
}
else {
pastePlotSchematic(dpw, pos1, pos2);
final PlotBlock wall = isDelete ? dpw.WALL_BLOCK : dpw.CLAIMED_WALL_BLOCK;
setWall(dpw, plot.id, new PlotBlock[] { wall });
SetBlockQueue.addNotify(whenDone);
}
}
});
return true;
}

View File

@ -50,13 +50,21 @@ public abstract class HybridUtils {
final int ty = get_ey(world, bx, tx, bz, tz, by);
final Location pos3 = new Location(world, bx, by, bz);
final Location pos4 = new Location(world, tx, ty, tz);
final CompoundTag sideroad = SchematicHandler.manager.getCompoundTag(world, pos1, pos2);
final CompoundTag intersection = SchematicHandler.manager.getCompoundTag(world, pos3, pos4);
final String dir = PS.get().IMP.getDirectory() + File.separator + "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + plot.world + File.separator;
SchematicHandler.manager.save(sideroad, dir + "sideroad.schematic");
SchematicHandler.manager.save(intersection, dir + "intersection.schematic");
plotworld.ROAD_SCHEMATIC_ENABLED = true;
plotworld.setupSchematics();
SchematicHandler.manager.getCompoundTag(world, pos1, pos2, new RunnableVal<CompoundTag>() {
@Override
public void run() {
SchematicHandler.manager.save(value, dir + "sideroad.schematic");
SchematicHandler.manager.getCompoundTag(world, pos3, pos4, new RunnableVal<CompoundTag>() {
@Override
public void run() {
SchematicHandler.manager.save(value, dir + "intersection.schematic");
plotworld.ROAD_SCHEMATIC_ENABLED = true;
plotworld.setupSchematics();
}
});
}
});
return true;
}