Optimizations

This commit is contained in:
boy0001 2015-02-16 02:29:50 +11:00
parent dd152ce28e
commit e7ea40c4a8

View File

@ -137,7 +137,6 @@ public class ChunkManager {
index.increment();
final int relX = newPos.getBlockX() - pos1.getBlockX();
final int relZ = newPos.getBlockZ() - pos1.getBlockZ();
System.out.print(relX + "," + relZ);
final RegionWrapper region = new RegionWrapper(pos1.getBlockX(), pos2.getBlockX(), pos1.getBlockZ(), pos2.getBlockZ());
final World world = pos1.getWorld();
@ -177,20 +176,20 @@ public class ChunkManager {
final int loadTask = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
@Override
public void run() {
long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < 25) {
if (toGenerate.size() == 0) {
Bukkit.getScheduler().cancelTask(tasks.get(currentIndex));
tasks.remove(currentIndex);
TaskManager.runTask(new Runnable() {
@Override
public void run() {
System.out.print("================== SETTING BLOCKS ===================");
index.increment();
// Copy entities
initMaps();
for (int x = c3x; x <= c4x; x ++) {
for (int z = c3z; z <= c4z; z ++) {
Chunk chunk = world.getChunkAt(x, z);
System.out.print("SAVING ENTITIES: " + chunk);
chunks.add(chunk);
chunk.load(false);
saveEntitiesIn(chunk, region);
@ -204,11 +203,9 @@ public class ChunkManager {
final Integer task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
@Override
public void run() {
System.out.print(" - " + mx.intValue());
long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < 20) {
while (System.currentTimeMillis() - start < 25) {
int x = mx.intValue();
System.out.print(x);
for (int z = sz; z <= ez; z++) {
saveBlocks(world, maxY, x, z);
for (int y = 1; y <= maxY; y++) {
@ -219,7 +216,7 @@ public class ChunkManager {
}
}
mx.increment();
if (x + 1 == ex) { // done!
if (x == ex) { // done!
restoreBlocks(world, relX, relZ);
AbstractSetBlock.setBlockManager.update(chunks);
for (Chunk chunk : chunks) {
@ -233,6 +230,7 @@ public class ChunkManager {
}
};
}, 1, 1);
tasks.put(currentIndex, task);
}
});
@ -242,7 +240,7 @@ public class ChunkManager {
toGenerate.remove(0);
chunk.load(true);
chunks.add(chunk);
System.out.print("GENERATING CHUNK: " + chunk);
}
}
}, 1l, 1l);
tasks.put(currentIndex, loadTask);