diff --git a/README.md b/README.md index a21406dd..d690f08c 100644 --- a/README.md +++ b/README.md @@ -1 +1,4 @@ -#TODO README \ No newline at end of file +# Overview +Optimize worldedit +# Main resource page +https://www.spigotmc.org/resources/13932/ \ No newline at end of file diff --git a/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java b/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java index 6091fe59..f41afeb7 100644 --- a/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java +++ b/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java @@ -4,6 +4,8 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.Map; @@ -13,6 +15,7 @@ import java.util.zip.GZIPOutputStream; import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweCache; +import com.boydti.fawe.config.Settings; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; @@ -53,7 +56,7 @@ public class DiskStorageHistory implements ChangeSet, FlushableChangeSet { * [contents]... * { short rel x, short rel z, unsigned byte y, short combinedFrom, short combinedTo } */ - private GZIPOutputStream osBD; + private OutputStream osBD; // NBT From private NBTOutputStream osNBTF; @@ -159,7 +162,7 @@ public class DiskStorageHistory implements ChangeSet, FlushableChangeSet { int idTo = to.getId(); int combinedTo = (FaweCache.hasData(idTo) ? ((idTo << 4) + to.getData()) : (idTo << 4)); CompoundTag nbtTo = FaweCache.hasNBT(idTo) ? to.getNbtData() : null; - GZIPOutputStream stream = getBAOS(x, y, z); + OutputStream stream = getBAOS(x, y, z); //x stream.write((x - ox) & 0xff); stream.write(((x - ox) >> 8) & 0xff); @@ -197,13 +200,14 @@ public class DiskStorageHistory implements ChangeSet, FlushableChangeSet { } } - private GZIPOutputStream getBAOS(int x, int y, int z) throws IOException { + private OutputStream getBAOS(int x, int y, int z) throws IOException { if (osBD != null) { return osBD; } bdFile.getParentFile().mkdirs(); bdFile.createNewFile(); - osBD = new GZIPOutputStream(new FileOutputStream(bdFile), true); + FileOutputStream stream = new FileOutputStream(bdFile); + osBD = Settings.COMPRESS_HISTORY ? new GZIPOutputStream(stream, true) : stream; ox = x; oz = z; osBD.write((byte) (ox >> 24)); @@ -277,7 +281,8 @@ public class DiskStorageHistory implements ChangeSet, FlushableChangeSet { final NBTInputStream nbtf = osNBTF != null ? new NBTInputStream(new GZIPInputStream(new FileInputStream(nbtfFile))) : null; final NBTInputStream nbtt = osNBTT != null ? new NBTInputStream(new GZIPInputStream(new FileInputStream(nbttFile))) : null; - final GZIPInputStream gis = new GZIPInputStream(new FileInputStream(bdFile)); + FileInputStream fis = new FileInputStream(bdFile); + final InputStream gis = Settings.COMPRESS_HISTORY ? new GZIPInputStream(fis) : fis; gis.skip(8); return new Iterator() { diff --git a/src/main/java/com/boydti/fawe/object/changeset/MemoryOptimizedHistory.java b/src/main/java/com/boydti/fawe/object/changeset/MemoryOptimizedHistory.java index 42905ba0..3bc956e5 100644 --- a/src/main/java/com/boydti/fawe/object/changeset/MemoryOptimizedHistory.java +++ b/src/main/java/com/boydti/fawe/object/changeset/MemoryOptimizedHistory.java @@ -3,6 +3,8 @@ package com.boydti.fawe.object.changeset; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Iterator; @@ -12,6 +14,7 @@ import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; import com.boydti.fawe.FaweCache; +import com.boydti.fawe.config.Settings; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.ReflectionUtils; import com.google.common.collect.Iterators; @@ -37,7 +40,7 @@ public class MemoryOptimizedHistory implements ChangeSet, FlushableChangeSet { private byte[] ids; private ByteArrayOutputStream idsStream; - private GZIPOutputStream idsStreamZip; + private OutputStream idsStreamZip; private ArrayDeque entities; @@ -71,7 +74,7 @@ public class MemoryOptimizedHistory implements ChangeSet, FlushableChangeSet { int idTo = to.getId(); int combinedTo = (FaweCache.hasData(idTo) ? ((idTo << 4) + to.getData()) : (idTo << 4)); CompoundTag nbtTo = FaweCache.hasNBT(idTo) ? to.getNbtData() : null; - GZIPOutputStream stream = getBAOS(x, y, z); + OutputStream stream = getBAOS(x, y, z); //x stream.write((x - ox) & 0xff); stream.write(((x - ox) >> 8) & 0xff); @@ -119,12 +122,12 @@ public class MemoryOptimizedHistory implements ChangeSet, FlushableChangeSet { } } - private GZIPOutputStream getBAOS(int x, int y, int z) throws IOException { + private OutputStream getBAOS(int x, int y, int z) throws IOException { if (idsStreamZip != null) { return idsStreamZip; } idsStream = new ByteArrayOutputStream(9216); - idsStreamZip = new GZIPOutputStream(idsStream, true); + idsStreamZip = Settings.COMPRESS_HISTORY ? new GZIPOutputStream(idsStream, true) : idsStream; ox = x; oz = z; return idsStreamZip; @@ -139,7 +142,8 @@ public class MemoryOptimizedHistory implements ChangeSet, FlushableChangeSet { if (ids == null) { idsIterator = new ArrayList().iterator(); } else { - final GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(ids)); + ByteArrayInputStream bais = new ByteArrayInputStream(ids); + final InputStream gis = Settings.COMPRESS_HISTORY ? new GZIPInputStream(bais) : bais; idsIterator = new Iterator() { private final Iterator lastFromIter = fromTags != null ? fromTags.iterator() : null; diff --git a/src/main/java/com/sk89q/worldedit/EditSession.java b/src/main/java/com/sk89q/worldedit/EditSession.java index 4dc232cb..927563e7 100644 --- a/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/src/main/java/com/sk89q/worldedit/EditSession.java @@ -46,7 +46,6 @@ import com.boydti.fawe.object.EditSessionWrapper; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.NullChangeSet; import com.boydti.fawe.object.RegionWrapper; -import com.boydti.fawe.object.changeset.CPUOptimizedHistory; import com.boydti.fawe.object.changeset.DiskStorageHistory; import com.boydti.fawe.object.changeset.MemoryOptimizedHistory; import com.boydti.fawe.object.extent.FastWorldEditExtent; @@ -244,8 +243,7 @@ public class EditSession implements Extent { this.changeSet = new NullChangeSet(); return; } - - this.changeSet = Settings.STORE_HISTORY_ON_DISK ? new DiskStorageHistory(actor.getUniqueId().toString()) : Settings.COMPRESS_HISTORY ? new MemoryOptimizedHistory() : new CPUOptimizedHistory(); + this.changeSet = Settings.STORE_HISTORY_ON_DISK ? new DiskStorageHistory(actor.getUniqueId().toString()) : new MemoryOptimizedHistory(); Extent extent; final String name = actor.getName(); final FawePlayer fp = FawePlayer.wrap(name);