Moved from storage_config.json to config.json

This commit is contained in:
mcrcortex
2024-02-22 17:15:06 +10:00
parent 8cd0d418b5
commit f2c4abb135
3 changed files with 36 additions and 23 deletions

View File

@@ -23,13 +23,13 @@ public class DistanceTracker {
private final int maxYSection;
private final int renderDistance;
public DistanceTracker(RenderTracker tracker, int[] lodRingScales, int renderDistance, int cacheDistance) {
public DistanceTracker(RenderTracker tracker, int[] lodRingScales, int renderDistance, int cacheDistance, int minY, int maxY) {
this.loDRings = new TransitionRing2D[lodRingScales.length];
this.cacheLoadRings = new TransitionRing2D[lodRingScales.length];
this.cacheUnloadRings = new TransitionRing2D[lodRingScales.length];
this.tracker = tracker;
this.minYSection = MinecraftClient.getInstance().world.getBottomSectionCoord()/2;//-128;
this.maxYSection = MinecraftClient.getInstance().world.getTopSectionCoord()/2;//128;
this.minYSection = minY;
this.maxYSection = maxY;
this.renderDistance = renderDistance;

View File

@@ -57,6 +57,7 @@ public class VoxelCore {
public VoxelCore(ContextSelectionSystem.Selection worldSelection) {
this.world = worldSelection.createEngine();
var cfg = worldSelection.getConfig();
System.out.println("Initializing voxy core");
//Trigger the shared index buffer loading
@@ -73,8 +74,20 @@ public class VoxelCore {
//To get to chunk scale multiply the scale by 2, the scale is after how many chunks does the lods halve
int q = VoxyConfig.CONFIG.qualityScale;
//TODO: add an option for cache load and unload distance
this.distanceTracker = new DistanceTracker(this.renderTracker, new int[]{q,q,q,q}, (VoxyConfig.CONFIG.renderDistance<0?VoxyConfig.CONFIG.renderDistance:((VoxyConfig.CONFIG.renderDistance+1)/2)), 3);
int minY = MinecraftClient.getInstance().world.getBottomSectionCoord()/2;
int maxY = MinecraftClient.getInstance().world.getTopSectionCoord()/2;
if (cfg.minYOverride != Integer.MAX_VALUE) {
minY = cfg.minYOverride;
}
if (cfg.maxYOverride != Integer.MIN_VALUE) {
maxY = cfg.maxYOverride;
}
this.distanceTracker = new DistanceTracker(this.renderTracker, new int[]{q,q,q,q},
(VoxyConfig.CONFIG.renderDistance<0?VoxyConfig.CONFIG.renderDistance:((VoxyConfig.CONFIG.renderDistance+1)/2)),
3, minY, maxY);
System.out.println("Distance tracker initialized");
this.postProcessing = new PostProcessing();

View File

@@ -22,11 +22,17 @@ import java.security.NoSuchAlgorithmException;
//Sets up a world engine with respect to the world the client is currently loaded into
// this is a bit tricky as each world has its own config, e.g. storage configuration
public class ContextSelectionSystem {
public static class WorldConfig {
public int minYOverride = Integer.MAX_VALUE;
public int maxYOverride = Integer.MIN_VALUE;
public StorageConfig storageConfig;
}
public static class Selection {
private final Path selectionFolder;
private final String worldId;
private StorageConfig storageConfig;
private WorldConfig config;
public Selection(Path selectionFolder, String worldId) {
this.selectionFolder = selectionFolder;
@@ -35,17 +41,18 @@ public class ContextSelectionSystem {
}
private void loadStorageConfigOrDefault() {
var json = this.selectionFolder.resolve("storage_config.json");
var json = this.selectionFolder.resolve("config.json");
if (Files.exists(json)) {
try {
this.storageConfig = Serialization.GSON.fromJson(Files.readString(json), StorageConfig.class);
this.config = Serialization.GSON.fromJson(Files.readString(json), WorldConfig.class);
return;
} catch (Exception e) {
System.err.println("Failed to load the storage configuration file, resetting it to default");
e.printStackTrace();
}
}
this.config = new WorldConfig();
//Load the default config
var baseDB = new RocksDBStorageBackend.Config();
@@ -57,7 +64,7 @@ public class ContextSelectionSystem {
compression.delegate = baseDB;
compression.compressor = compressor;
this.storageConfig = compression;
this.config.storageConfig = compression;
this.save();
}
@@ -67,18 +74,7 @@ public class ContextSelectionSystem {
ctx.setProperty(ConfigBuildCtx.BASE_SAVE_PATH, this.selectionFolder.toString());
ctx.setProperty(ConfigBuildCtx.WORLD_IDENTIFIER, this.worldId);
ctx.pushPath(ConfigBuildCtx.DEFAULT_STORAGE_PATH);
return this.storageConfig.build(ctx);
/*
var translocator = new TranslocatingStorageAdaptor.Config();
translocator.delegate = compression;
translocator.transforms.add(new TranslocatingStorageAdaptor.BoxTransform(0,5,0, 200, 64, 200, 0, -5, 0));
*/
//StorageBackend storage = new RocksDBStorageBackend(VoxyConfig.CONFIG.storagePath);
////StorageBackend storage = new FragmentedStorageBackendAdaptor(new File(VoxyConfig.CONFIG.storagePath));
//return new CompressionStorageAdaptor(new ZSTDCompressor(VoxyConfig.CONFIG.savingCompressionLevel), storage);
return this.config.storageConfig.build(ctx);
}
public WorldEngine createEngine() {
@@ -89,14 +85,18 @@ public class ContextSelectionSystem {
// or just have per world config, cause when creating the world engine doing the string substitution would
// make it automatically select the right id
public void save() {
var file = this.selectionFolder.resolve("storage_config.json");
var json = Serialization.GSON.toJson(this.storageConfig);
var file = this.selectionFolder.resolve("config.json");
var json = Serialization.GSON.toJson(this.config);
try {
Files.writeString(file, json);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public WorldConfig getConfig() {
return this.config;
}
}
//Gets dimension independent base world, if singleplayer, its the world name, if multiplayer, its the server ip