mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2025-01-23 08:41:20 +01:00
Add configuration if gzip-compression should be used
This commit is contained in:
parent
2bc1f2dace
commit
3b5393202f
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
|
||||
@ -232,6 +234,8 @@ private MapConfig(ConfigurationNode node) throws IOException {
|
||||
|
||||
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 boolean isRenderEdges() {
|
||||
return renderEdges;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useGzipCompression() {
|
||||
return useGzip;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void checkOutdated(ConfigurationNode node) throws OutdatedConfigException {
|
||||
|
@ -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(),
|
||||
|
@ -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;
|
||||
@ -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 HiresModelManager(Path fileRoot, HiresModelRenderer renderer, Vector2i ti
|
||||
this.gridOrigin = gridOrigin;
|
||||
|
||||
this.savingExecutor = savingExecutor;
|
||||
this.useGzip = useGzip;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,7 +91,7 @@ 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()){
|
||||
@ -95,9 +99,9 @@ private void save(HiresModel model, String modelJson){
|
||||
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 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" : ""));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user