From dcc0c15c037aa675f085ad0d2adad5a204607593 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 21 Dec 2016 06:22:03 +1100 Subject: [PATCH] BREAKS OLD UNDO FILES + better compression Reduce block position entropy by encoding coordinates relative to last position --- .../boydti/fawe/bukkit/v0/ChunkListener.java | 15 +++++-- .../object/changeset/FaweStreamChangeSet.java | 42 +++++++++++-------- .../java/com/boydti/fawe/util/MainUtil.java | 1 - 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/v0/ChunkListener.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/v0/ChunkListener.java index 7ff689b7..f334c4df 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/v0/ChunkListener.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/v0/ChunkListener.java @@ -24,12 +24,15 @@ import org.bukkit.event.entity.ItemSpawnEvent; public class ChunkListener implements Listener { + int rateLimit = 0; + public ChunkListener() { if (Settings.TICK_LIMITER.ENABLED) { Bukkit.getPluginManager().registerEvents(ChunkListener.this, Fawe.imp().getPlugin()); TaskManager.IMP.repeat(new Runnable() { @Override public void run() { + rateLimit--; physicsFreeze = false; itemFreeze = false; counter.clear(); @@ -99,7 +102,10 @@ public class ChunkListener implements Listener { lastPhysY = y; if (++count.x == Settings.TICK_LIMITER.PHYSICS) { badChunks.add(MathMan.pairInt(cx, cz)); - Fawe.debug("[Tick Limiter] Detected and cancelled physics lag source at " + block.getLocation()); + if (rateLimit <= 0) { + rateLimit = 120; + Fawe.debug("[Tick Limiter] Detected and cancelled physics lag source at " + block.getLocation()); + } } return; } @@ -148,10 +154,13 @@ public class ChunkListener implements Listener { count.x = Settings.TICK_LIMITER.PHYSICS; cleanup(loc.getChunk()); badChunks.add(MathMan.pairInt(cx, cz)); - Fawe.debug("[Tick Limiter] Detected and cancelled item lag source at " + loc); + if (rateLimit <= 0) { + rateLimit = 120; + Fawe.debug("[Tick Limiter] Detected and cancelled item lag source at " + loc); + } } event.setCancelled(true); return; } } -} +} \ No newline at end of file diff --git a/core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java b/core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java index 402cf051..2bbc4123 100644 --- a/core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java +++ b/core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java @@ -124,13 +124,17 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet { } if (mode == 1 || mode == 4) { // small posDel = new FaweStreamPositionDelegate() { + int lx,ly,lz; @Override public void write(OutputStream out, int x, int y, int z) throws IOException { - byte b1 = (byte) y; - byte b2 = (byte) (x); - byte b3 = (byte) (z); - int x16 = (x >> 8) & 0xF; - int z16 = (z >> 8) & 0xF; + int rx = -lx + (lx = x); + int ry = -ly + (ly = y); + int rz = -lz + (lz = z); + byte b1 = (byte) (ry); + byte b2 = (byte) (rx); + byte b3 = (byte) (rz); + int x16 = (rx >> 8) & 0xF; + int z16 = (rz >> 8) & 0xF; byte b4 = MathMan.pair16(x16, z16); out.write(b1); out.write(b2); @@ -145,31 +149,33 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet { if (in.read(buffer) == -1) { throw new EOFException(); } - return (((buffer[1] & 0xFF) + ((MathMan.unpair16x(buffer[3])) << 8)) << 20) >> 20; + return lx = lx + ((((buffer[1] & 0xFF) + ((MathMan.unpair16x(buffer[3])) << 8)) << 20) >> 20); } @Override public int readY(InputStream in) { - return buffer[0] & 0xFF; + return (ly = ly + buffer[0]) & 0xFF; } @Override public int readZ(InputStream in) throws IOException { - return (((buffer[2] & 0xFF) + ((MathMan.unpair16y(buffer[3])) << 8)) << 20) >> 20; + return lz = lz + ((((buffer[2] & 0xFF) + ((MathMan.unpair16y(buffer[3])) << 8)) << 20) >> 20); } }; } else { posDel = new FaweStreamPositionDelegate() { - byte[] buffer = new byte[5]; - + int lx,ly,lz; @Override public void write(OutputStream stream, int x, int y, int z) throws IOException { - stream.write((x) & 0xff); - stream.write(((x) >> 8) & 0xff); - stream.write((z) & 0xff); - stream.write(((z) >> 8) & 0xff); - stream.write((byte) y); + int rx = -lx + (lx = x); + int ry = -ly + (ly = y); + int rz = -lz + (lz = z); + stream.write((rx) & 0xff); + stream.write(((rx) >> 8) & 0xff); + stream.write((rz) & 0xff); + stream.write(((rz) >> 8) & 0xff); + stream.write((byte) ry); } @Override @@ -177,17 +183,17 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet { if (is.read(buffer) == -1) { throw new EOFException(); } - return (buffer[0] & 0xFF) + (buffer[1] << 8); + return lx = (lx + (buffer[0] & 0xFF) + (buffer[1] << 8)); } @Override public int readY(InputStream is) throws IOException { - return buffer[4] & 0xFF; + return (ly = (ly + (buffer[4]))) & 0xFF; } @Override public int readZ(InputStream is) throws IOException { - return (buffer[2] & 0xFF) + (buffer[3] << 8); + return lz = (lz + (buffer[2] & 0xFF) + (buffer[3] << 8)); } }; } diff --git a/core/src/main/java/com/boydti/fawe/util/MainUtil.java b/core/src/main/java/com/boydti/fawe/util/MainUtil.java index 5b23d5c1..9a7d466e 100644 --- a/core/src/main/java/com/boydti/fawe/util/MainUtil.java +++ b/core/src/main/java/com/boydti/fawe/util/MainUtil.java @@ -283,7 +283,6 @@ public class MainUtil { return new FaweInputStream(is); } int amountAbs = Math.abs(amount); - LZ4Factory factory = LZ4Factory.fastestInstance(); if (amountAbs > 6) { if (amount > 0) { is = new BufferedInputStream(new GZIPInputStream(is, buffer));