From 800078a75cfda321d1aebb6250af272e23e91cc7 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 21 Aug 2018 12:18:54 -0700 Subject: [PATCH] only gzip changed regions --- .../java/baritone/bot/chunk/CachedRegion.java | 14 +++++++++++++- .../java/baritone/bot/chunk/CachedWorld.java | 16 ++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/baritone/bot/chunk/CachedRegion.java b/src/main/java/baritone/bot/chunk/CachedRegion.java index b7bc3580..b0cda611 100644 --- a/src/main/java/baritone/bot/chunk/CachedRegion.java +++ b/src/main/java/baritone/bot/chunk/CachedRegion.java @@ -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) {} } diff --git a/src/main/java/baritone/bot/chunk/CachedWorld.java b/src/main/java/baritone/bot/chunk/CachedWorld.java index d5c5c04a..eb7513a3 100644 --- a/src/main/java/baritone/bot/chunk/CachedWorld.java +++ b/src/main/java/baritone/bot/chunk/CachedWorld.java @@ -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 *