only gzip changed regions

This commit is contained in:
Leijurv 2018-08-21 12:18:54 -07:00
parent a64e07685b
commit 800078a75c
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
2 changed files with 15 additions and 15 deletions

View File

@ -17,8 +17,8 @@
package baritone.bot.chunk;
import baritone.bot.utils.pathing.PathingBlockType;
import baritone.bot.utils.GZIPUtils;
import baritone.bot.utils.pathing.PathingBlockType;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@ -52,9 +52,15 @@ public final class CachedRegion implements ICachedChunkAccess {
*/
private final int z;
/**
* Has this region been modified since its most recent load or save
*/
private boolean hasUnsavedChanges;
CachedRegion(int x, int z) {
this.x = x;
this.z = z;
this.hasUnsavedChanges = false;
}
@Override
@ -74,6 +80,7 @@ public final class CachedRegion implements ICachedChunkAccess {
} else {
chunk.updateContents(data);
}
hasUnsavedChanges = true;
}
private CachedChunk getChunk(int chunkX, int chunkZ) {
@ -92,6 +99,9 @@ public final class CachedRegion implements ICachedChunkAccess {
}
public final void save(String directory) {
if (!hasUnsavedChanges) {
return;
}
try {
Path path = Paths.get(directory);
if (!Files.exists(path))
@ -115,6 +125,7 @@ public final class CachedRegion implements ICachedChunkAccess {
}
}
}
hasUnsavedChanges = false;
} catch (IOException ignored) {}
}
@ -148,6 +159,7 @@ public final class CachedRegion implements ICachedChunkAccess {
}
}
}
hasUnsavedChanges = false;
} catch (IOException ignored) {}
}

View File

@ -54,18 +54,13 @@ public final class CachedWorld implements ICachedChunkAccess {
@Override
public final PathingBlockType getBlockType(int x, int y, int z) {
CachedRegion region = getOrCreateRegion(x >> 9, z >> 9);
if (region != null) {
return region.getBlockType(x & 511, y, z & 511);
}
return null;
return region.getBlockType(x & 511, y, z & 511);
}
@Override
public final void updateCachedChunk(int chunkX, int chunkZ, BitSet data) {
CachedRegion region = getOrCreateRegion(chunkX >> 5, chunkZ >> 5);
if (region != null) {
region.updateCachedChunk(chunkX & 31, chunkZ & 31, data);
}
region.updateCachedChunk(chunkX & 31, chunkZ & 31, data);
}
public final void save() {
@ -75,13 +70,6 @@ public final class CachedWorld implements ICachedChunkAccess {
});
}
public final void load() {
this.cachedRegions.values().forEach(region -> {
if (region != null)
region.load(this.directory);
});
}
/**
* Returns the region at the specified region coordinates
*