Skip to content

Commit

Permalink
Add configuration if gzip-compression should be used
Browse files Browse the repository at this point in the history
  • Loading branch information
TBlueF committed Jan 18, 2020
1 parent 2bc1f2d commit 3b53932
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 8 deletions.
6 changes: 6 additions & 0 deletions BlueMapBukkit/src/main/resources/bluemap-bukkit.conf
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ maps: [
# Default is enabled
renderEdges: true

# With this set to true, the generated files for this world are compressed using gzip to save A LOT of space.
# Files will be only 5% as big with compression!
# Note: If you are using NGINX or Apache to host your map, you can configure them to serve the compressed files directly.
# This is much better than disabling the compression.
useCompression: true

# HIRES is the high-resolution render of the map. Where you see every block.
hires {
# Defines the size of one map-tile in blocks.
Expand Down
6 changes: 6 additions & 0 deletions BlueMapCLI/src/main/resources/bluemap-cli.conf
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ maps: [
# Default is enabled
renderEdges: true

# With this set to true, the generated files for this world are compressed using gzip to save A LOT of space.
# Files will be only 5% as big with compression!
# Note: If you are using NGINX or Apache to host your map, you can configure them to serve the compressed files directly.
# This is much better than disabling the compression.
useCompression: true

# HIRES is the high-resolution render of the map. Where you see every block.
hires {
# Defines the size of one map-tile in blocks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ public class MapConfig implements RenderSettings {
private Vector3i min, max;
private boolean renderEdges;

private boolean useGzip;

private int hiresTileSize;
private float hiresViewDistance;

Expand Down Expand Up @@ -231,6 +233,8 @@ private MapConfig(ConfigurationNode node) throws IOException {
this.max = new Vector3i(maxX, maxY, maxZ);

this.renderEdges = node.getNode("renderEdges").getBoolean(true);

this.renderEdges = node.getNode("useCompression").getBoolean(true);

this.hiresTileSize = node.getNode("hires", "tileSize").getInt(32);
this.hiresViewDistance = node.getNode("hires", "viewDistance").getFloat(4.5f);
Expand Down Expand Up @@ -310,6 +314,11 @@ public boolean isRenderEdges() {
return renderEdges;
}

@Override
public boolean useGzipCompression() {
return useGzip;
}

}

private void checkOutdated(ConfigurationNode node) throws OutdatedConfigException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ default boolean isRenderEdges() {
return true;
}

/**
* If gzip compression will be used to compress the generated files
*/
default boolean useGzipCompression() {
return true;
}

default RenderSettings copy() {
return new StaticRenderSettings(
getAmbientOcclusionStrenght(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -58,18 +59,21 @@ public class HiresModelManager {

private ExecutorService savingExecutor;

private boolean useGzip;

public HiresModelManager(Path fileRoot, ResourcePack resourcePack, RenderSettings renderSettings, Vector2i tileSize, ExecutorService savingExecutor) {
this(fileRoot, new HiresModelRenderer(resourcePack, renderSettings), tileSize, new Vector2i(2, 2), savingExecutor);
this(fileRoot, new HiresModelRenderer(resourcePack, renderSettings), tileSize, new Vector2i(2, 2), savingExecutor, renderSettings.useGzipCompression());
}

public HiresModelManager(Path fileRoot, HiresModelRenderer renderer, Vector2i tileSize, Vector2i gridOrigin, ExecutorService savingExecutor) {
public HiresModelManager(Path fileRoot, HiresModelRenderer renderer, Vector2i tileSize, Vector2i gridOrigin, ExecutorService savingExecutor, boolean useGzip) {
this.fileRoot = fileRoot;
this.renderer = renderer;

this.tileSize = tileSize;
this.gridOrigin = gridOrigin;

this.savingExecutor = savingExecutor;
this.useGzip = useGzip;
}

/**
Expand All @@ -87,17 +91,17 @@ private void save(final HiresModel model) {
}

private void save(HiresModel model, String modelJson){
File file = getFile(model.getTile());
File file = getFile(model.getTile(), useGzip);

try {
if (!file.exists()){
file.getParentFile().mkdirs();
file.createNewFile();
}

FileOutputStream fos = new FileOutputStream(file);
GZIPOutputStream zos = new GZIPOutputStream(fos);
OutputStreamWriter osw = new OutputStreamWriter(zos, StandardCharsets.UTF_8);
OutputStream os = new FileOutputStream(file);
if (useGzip) os = new GZIPOutputStream(os);
OutputStreamWriter osw = new OutputStreamWriter(os, StandardCharsets.UTF_8);
try (
PrintWriter pw = new PrintWriter(osw);
){
Expand Down Expand Up @@ -185,8 +189,8 @@ public Vector2i posToTile(Vector3d pos){
/**
* Returns the file for a tile
*/
public File getFile(Vector2i tilePos){
return FileUtils.coordsToFile(fileRoot, tilePos, "json.gz");
public File getFile(Vector2i tilePos, boolean gzip){
return FileUtils.coordsToFile(fileRoot, tilePos, "json" + (gzip ? ".gz" : ""));
}

}
6 changes: 6 additions & 0 deletions BlueMapSponge/src/main/resources/bluemap-sponge.conf
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ maps: [
# Default is enabled
renderEdges: true

# With this set to true, the generated files for this world are compressed using gzip to save A LOT of space.
# Files will be only 5% as big with compression!
# Note: If you are using NGINX or Apache to host your map, you can configure them to serve the compressed files directly.
# This is much better than disabling the compression.
useCompression: true

# HIRES is the high-resolution render of the map. Where you see every block.
hires {
# Defines the size of one map-tile in blocks.
Expand Down

0 comments on commit 3b53932

Please sign in to comment.