Add configuration if gzip-compression should be used

This commit is contained in:
Blue (Lukas Rieger) 2020-01-18 14:34:20 +01:00
parent 2bc1f2dace
commit 3b5393202f
6 changed files with 46 additions and 8 deletions

View File

@ -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.

View File

@ -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.

View File

@ -201,6 +201,8 @@ public class MainConfig implements WebServerConfig {
private Vector3i min, max;
private boolean renderEdges;
private boolean useGzip;
private int hiresTileSize;
private float hiresViewDistance;
@ -231,6 +233,8 @@ public class MainConfig implements WebServerConfig {
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);
@ -310,6 +314,11 @@ public class MainConfig implements WebServerConfig {
return renderEdges;
}
@Override
public boolean useGzipCompression() {
return useGzip;
}
}
private void checkOutdated(ConfigurationNode node) throws OutdatedConfigException {

View File

@ -78,6 +78,13 @@ public interface RenderSettings {
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(),

View File

@ -27,6 +27,7 @@ package de.bluecolored.bluemap.core.render.hires;
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;
@ -58,11 +59,13 @@ 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;
@ -70,6 +73,7 @@ public class HiresModelManager {
this.gridOrigin = gridOrigin;
this.savingExecutor = savingExecutor;
this.useGzip = useGzip;
}
/**
@ -87,7 +91,7 @@ public class HiresModelManager {
}
private void save(HiresModel model, String modelJson){
File file = getFile(model.getTile());
File file = getFile(model.getTile(), useGzip);
try {
if (!file.exists()){
@ -95,9 +99,9 @@ public class HiresModelManager {
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);
){
@ -185,8 +189,8 @@ public class HiresModelManager {
/**
* 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" : ""));
}
}

View File

@ -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.