mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2025-02-23 07:51:43 +01:00
Also use config with lowres model compression
This commit is contained in:
parent
5ea1fbb4c5
commit
aaaaf7e18a
@ -116,7 +116,8 @@ public void renderMaps() throws IOException {
|
|||||||
LowresModelManager lowresModelManager = new LowresModelManager(
|
LowresModelManager lowresModelManager = new LowresModelManager(
|
||||||
config.getWebDataPath().resolve(mapConfig.getId()).resolve("lowres"),
|
config.getWebDataPath().resolve(mapConfig.getId()).resolve("lowres"),
|
||||||
new Vector2i(mapConfig.getLowresPointsPerLowresTile(), mapConfig.getLowresPointsPerLowresTile()),
|
new Vector2i(mapConfig.getLowresPointsPerLowresTile(), mapConfig.getLowresPointsPerLowresTile()),
|
||||||
new Vector2i(mapConfig.getLowresPointsPerHiresTile(), mapConfig.getLowresPointsPerHiresTile())
|
new Vector2i(mapConfig.getLowresPointsPerHiresTile(), mapConfig.getLowresPointsPerHiresTile()),
|
||||||
|
mapConfig.useGzipCompression()
|
||||||
);
|
);
|
||||||
|
|
||||||
TileRenderer tileRenderer = new TileRenderer(hiresModelManager, lowresModelManager);
|
TileRenderer tileRenderer = new TileRenderer(hiresModelManager, lowresModelManager);
|
||||||
|
@ -190,7 +190,8 @@ public synchronized void load() throws IOException, ParseResourceException {
|
|||||||
LowresModelManager lowresModelManager = new LowresModelManager(
|
LowresModelManager lowresModelManager = new LowresModelManager(
|
||||||
config.getWebDataPath().resolve(id).resolve("lowres"),
|
config.getWebDataPath().resolve(id).resolve("lowres"),
|
||||||
new Vector2i(mapConfig.getLowresPointsPerLowresTile(), mapConfig.getLowresPointsPerLowresTile()),
|
new Vector2i(mapConfig.getLowresPointsPerLowresTile(), mapConfig.getLowresPointsPerLowresTile()),
|
||||||
new Vector2i(mapConfig.getLowresPointsPerHiresTile(), mapConfig.getLowresPointsPerHiresTile())
|
new Vector2i(mapConfig.getLowresPointsPerHiresTile(), mapConfig.getLowresPointsPerHiresTile()),
|
||||||
|
mapConfig.useGzipCompression()
|
||||||
);
|
);
|
||||||
|
|
||||||
TileRenderer tileRenderer = new TileRenderer(hiresModelManager, lowresModelManager);
|
TileRenderer tileRenderer = new TileRenderer(hiresModelManager, lowresModelManager);
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@ -95,7 +96,7 @@ public void update(Vector2i point, float height, Vector3f color){
|
|||||||
* Saves this model to its file
|
* Saves this model to its file
|
||||||
* @param force if this is false, the model is only saved if it has any changes
|
* @param force if this is false, the model is only saved if it has any changes
|
||||||
*/
|
*/
|
||||||
public void save(File file, boolean force) throws IOException {
|
public void save(File file, boolean force, boolean useGzip) throws IOException {
|
||||||
if (!force && !hasUnsavedChanges) return;
|
if (!force && !hasUnsavedChanges) return;
|
||||||
this.hasUnsavedChanges = false;
|
this.hasUnsavedChanges = false;
|
||||||
|
|
||||||
@ -118,9 +119,9 @@ public void save(File file, boolean force) throws IOException {
|
|||||||
throw new IOException("Failed to get write-access to file: " + file, e);
|
throw new IOException("Failed to get write-access to file: " + file, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileOutputStream fos = new FileOutputStream(file);
|
OutputStream os = new FileOutputStream(file);
|
||||||
GZIPOutputStream zos = new GZIPOutputStream(fos);
|
if (useGzip) os = new GZIPOutputStream(os);
|
||||||
OutputStreamWriter osw = new OutputStreamWriter(zos, StandardCharsets.UTF_8);
|
OutputStreamWriter osw = new OutputStreamWriter(os, StandardCharsets.UTF_8);
|
||||||
try (
|
try (
|
||||||
PrintWriter pw = new PrintWriter(osw);
|
PrintWriter pw = new PrintWriter(osw);
|
||||||
){
|
){
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -58,14 +59,18 @@ public class LowresModelManager {
|
|||||||
private Vector2i pointsPerHiresTile;
|
private Vector2i pointsPerHiresTile;
|
||||||
|
|
||||||
private Map<File, CachedModel> models;
|
private Map<File, CachedModel> models;
|
||||||
|
|
||||||
|
private boolean useGzip;
|
||||||
|
|
||||||
public LowresModelManager(Path fileRoot, Vector2i gridSize, Vector2i pointsPerHiresTile) {
|
public LowresModelManager(Path fileRoot, Vector2i gridSize, Vector2i pointsPerHiresTile, boolean useGzip) {
|
||||||
this.fileRoot = fileRoot;
|
this.fileRoot = fileRoot;
|
||||||
|
|
||||||
this.gridSize = gridSize;
|
this.gridSize = gridSize;
|
||||||
this.pointsPerHiresTile = pointsPerHiresTile;
|
this.pointsPerHiresTile = pointsPerHiresTile;
|
||||||
|
|
||||||
models = new ConcurrentHashMap<>();
|
models = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
this.useGzip = useGzip;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -166,13 +171,13 @@ public void update(UUID world, Vector2i point, float height, Vector3f color) thr
|
|||||||
/**
|
/**
|
||||||
* Returns the file for a tile
|
* Returns the file for a tile
|
||||||
*/
|
*/
|
||||||
public File getFile(Vector2i tile){
|
public File getFile(Vector2i tile, boolean useGzip){
|
||||||
return FileUtils.coordsToFile(fileRoot, tile, "json.gz");
|
return FileUtils.coordsToFile(fileRoot, tile, "json" + (useGzip ? ".gz" : ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
private LowresModel getModel(UUID world, Vector2i tile) throws IOException {
|
private LowresModel getModel(UUID world, Vector2i tile) throws IOException {
|
||||||
|
|
||||||
File modelFile = getFile(tile);
|
File modelFile = getFile(tile, useGzip);
|
||||||
CachedModel model = models.get(modelFile);
|
CachedModel model = models.get(modelFile);
|
||||||
|
|
||||||
if (model == null){
|
if (model == null){
|
||||||
@ -181,11 +186,10 @@ private LowresModel getModel(UUID world, Vector2i tile) throws IOException {
|
|||||||
if (model == null){
|
if (model == null){
|
||||||
if (modelFile.exists()){
|
if (modelFile.exists()){
|
||||||
|
|
||||||
FileInputStream fis = new FileInputStream(modelFile);
|
InputStream is = new FileInputStream(modelFile);
|
||||||
try(
|
if (useGzip) is = new GZIPInputStream(is);
|
||||||
GZIPInputStream zis = new GZIPInputStream(fis);
|
try {
|
||||||
){
|
String json = IOUtils.toString(is, StandardCharsets.UTF_8);
|
||||||
String json = IOUtils.toString(zis, StandardCharsets.UTF_8);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
model = new CachedModel(world, tile, BufferGeometry.fromJson(json));
|
model = new CachedModel(world, tile, BufferGeometry.fromJson(json));
|
||||||
@ -194,6 +198,8 @@ private LowresModel getModel(UUID world, Vector2i tile) throws IOException {
|
|||||||
//gridFile.renameTo(gridFile.toPath().getParent().resolve(gridFile.getName() + ".broken").toFile());
|
//gridFile.renameTo(gridFile.toPath().getParent().resolve(gridFile.getName() + ".broken").toFile());
|
||||||
modelFile.delete();
|
modelFile.delete();
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
is.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -238,10 +244,10 @@ public synchronized void tidyUpModelCache() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void saveAndRemoveModel(CachedModel model) {
|
private synchronized void saveAndRemoveModel(CachedModel model) {
|
||||||
File modelFile = getFile(model.getTile());
|
File modelFile = getFile(model.getTile(), useGzip);
|
||||||
models.remove(modelFile);
|
models.remove(modelFile);
|
||||||
try {
|
try {
|
||||||
model.save(modelFile, false);
|
model.save(modelFile, false, useGzip);
|
||||||
//logger.logDebug("Saved and unloaded lowres tile: " + model.getTile());
|
//logger.logDebug("Saved and unloaded lowres tile: " + model.getTile());
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Logger.global.logError("Failed to save and unload lowres-model: " + modelFile, ex);
|
Logger.global.logError("Failed to save and unload lowres-model: " + modelFile, ex);
|
||||||
@ -249,9 +255,9 @@ private synchronized void saveAndRemoveModel(CachedModel model) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void saveModel(CachedModel model) {
|
private void saveModel(CachedModel model) {
|
||||||
File modelFile = getFile(model.getTile());
|
File modelFile = getFile(model.getTile(), useGzip);
|
||||||
try {
|
try {
|
||||||
model.save(modelFile, false);
|
model.save(modelFile, false, useGzip);
|
||||||
//logger.logDebug("Saved lowres tile: " + model.getTile());
|
//logger.logDebug("Saved lowres tile: " + model.getTile());
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Logger.global.logError("Failed to save lowres-model: " + modelFile, ex);
|
Logger.global.logError("Failed to save lowres-model: " + modelFile, ex);
|
||||||
|
Loading…
Reference in New Issue
Block a user