Serialization changes
This commit is contained in:
@@ -16,11 +16,12 @@ public class Voxy implements ClientModInitializer {
|
|||||||
static {
|
static {
|
||||||
ModContainer mod = (ModContainer) FabricLoader.getInstance().getModContainer("voxy").orElseThrow(NullPointerException::new);
|
ModContainer mod = (ModContainer) FabricLoader.getInstance().getModContainer("voxy").orElseThrow(NullPointerException::new);
|
||||||
VERSION = mod.getMetadata().getVersion().getFriendlyString();
|
VERSION = mod.getMetadata().getVersion().getFriendlyString();
|
||||||
|
|
||||||
|
Serialization.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitializeClient() {
|
public void onInitializeClient() {
|
||||||
Serialization.init();
|
|
||||||
|
|
||||||
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
|
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
|
||||||
dispatcher.register(WorldImportCommand.register());
|
dispatcher.register(WorldImportCommand.register());
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package me.cortex.voxy.client.config;
|
|||||||
import com.google.gson.FieldNamingPolicy;
|
import com.google.gson.FieldNamingPolicy;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
|
import me.cortex.voxy.client.saver.ContextSelectionSystem;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import org.lwjgl.opengl.GL;
|
import org.lwjgl.opengl.GL;
|
||||||
|
|
||||||
@@ -30,13 +31,19 @@ public class VoxyConfig {
|
|||||||
public int savingThreads = 4;
|
public int savingThreads = 4;
|
||||||
public int renderThreads = 5;
|
public int renderThreads = 5;
|
||||||
public boolean useMeshShaderIfPossible = true;
|
public boolean useMeshShaderIfPossible = true;
|
||||||
|
public String defaultSaveConfig;
|
||||||
|
|
||||||
|
|
||||||
public static VoxyConfig loadOrCreate() {
|
public static VoxyConfig loadOrCreate() {
|
||||||
var path = getConfigPath();
|
var path = getConfigPath();
|
||||||
if (Files.exists(path)) {
|
if (Files.exists(path)) {
|
||||||
try (FileReader reader = new FileReader(path.toFile())) {
|
try (FileReader reader = new FileReader(path.toFile())) {
|
||||||
return GSON.fromJson(reader, VoxyConfig.class);
|
var cfg = GSON.fromJson(reader, VoxyConfig.class);
|
||||||
|
if (cfg.defaultSaveConfig == null) {
|
||||||
|
//Shitty gson being a pain TODO: replace with a proper fix
|
||||||
|
cfg.defaultSaveConfig = ContextSelectionSystem.DEFAULT_STORAGE_CONFIG;
|
||||||
|
}
|
||||||
|
return cfg;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("Could not parse config");
|
System.err.println("Could not parse config");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -145,6 +145,7 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer<Gl46Viewport>
|
|||||||
//glPointSize(10);
|
//glPointSize(10);
|
||||||
//TODO: replace glMultiDrawElementsIndirectCountARB with glMultiDrawElementsIndirect on intel gpus, since it performs so much better
|
//TODO: replace glMultiDrawElementsIndirectCountARB with glMultiDrawElementsIndirect on intel gpus, since it performs so much better
|
||||||
//glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, 0, drawCnt, 0);
|
//glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, 0, drawCnt, 0);
|
||||||
|
//glLineWidth(2);
|
||||||
glMultiDrawElementsIndirectCountARB(GL_TRIANGLES, GL_UNSIGNED_SHORT, 0, 0, (int) (this.geometry.getSectionCount()*4.4), 0);
|
glMultiDrawElementsIndirectCountARB(GL_TRIANGLES, GL_UNSIGNED_SHORT, 0, 0, (int) (this.geometry.getSectionCount()*4.4), 0);
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,23 @@ public class ContextSelectionSystem {
|
|||||||
public int maxYOverride = Integer.MIN_VALUE;
|
public int maxYOverride = Integer.MIN_VALUE;
|
||||||
public StorageConfig storageConfig;
|
public StorageConfig storageConfig;
|
||||||
}
|
}
|
||||||
|
public static final String DEFAULT_STORAGE_CONFIG;
|
||||||
|
static {
|
||||||
|
var config = new WorldConfig();
|
||||||
|
|
||||||
|
//Load the default config
|
||||||
|
var baseDB = new RocksDBStorageBackend.Config();
|
||||||
|
|
||||||
|
var compressor = new ZSTDCompressor.Config();
|
||||||
|
compressor.compressionLevel = 7;
|
||||||
|
|
||||||
|
var compression = new CompressionStorageAdaptor.Config();
|
||||||
|
compression.delegate = baseDB;
|
||||||
|
compression.compressor = compressor;
|
||||||
|
|
||||||
|
config.storageConfig = compression;
|
||||||
|
DEFAULT_STORAGE_CONFIG = Serialization.GSON.toJson(config);
|
||||||
|
}
|
||||||
|
|
||||||
public static class Selection {
|
public static class Selection {
|
||||||
private final Path selectionFolder;
|
private final Path selectionFolder;
|
||||||
@@ -46,27 +63,22 @@ public class ContextSelectionSystem {
|
|||||||
if (Files.exists(json)) {
|
if (Files.exists(json)) {
|
||||||
try {
|
try {
|
||||||
this.config = Serialization.GSON.fromJson(Files.readString(json), WorldConfig.class);
|
this.config = Serialization.GSON.fromJson(Files.readString(json), WorldConfig.class);
|
||||||
|
if (this.config == null) {
|
||||||
|
throw new IllegalStateException("Config deserialization null, reverting to default");
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("Failed to load the storage configuration file, resetting it to default");
|
System.err.println("Failed to load the storage configuration file, resetting it to default");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.config = new WorldConfig();
|
|
||||||
|
|
||||||
//Load the default config
|
|
||||||
var baseDB = new RocksDBStorageBackend.Config();
|
|
||||||
|
|
||||||
var compressor = new ZSTDCompressor.Config();
|
|
||||||
compressor.compressionLevel = 7;
|
|
||||||
|
|
||||||
var compression = new CompressionStorageAdaptor.Config();
|
|
||||||
compression.delegate = baseDB;
|
|
||||||
compression.compressor = compressor;
|
|
||||||
|
|
||||||
this.config.storageConfig = compression;
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.config = Serialization.GSON.fromJson(VoxyConfig.CONFIG.defaultSaveConfig, WorldConfig.class);
|
||||||
this.save();
|
this.save();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("Failed to deserialize the default config, aborting!", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public StorageBackend createStorageBackend() {
|
public StorageBackend createStorageBackend() {
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import com.google.gson.*;
|
|||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.JsonReader;
|
||||||
import com.google.gson.stream.JsonWriter;
|
import com.google.gson.stream.JsonWriter;
|
||||||
|
import me.cortex.voxy.common.storage.config.CompressorConfig;
|
||||||
|
import me.cortex.voxy.common.storage.config.StorageConfig;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
@@ -89,6 +91,13 @@ public class Serialization {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
try {
|
||||||
|
Class.forName(CompressorConfig.class.getName());
|
||||||
|
Class.forName(StorageConfig.class.getName());
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
String BASE_SEARCH_PACKAGE = "me.cortex.voxy";
|
String BASE_SEARCH_PACKAGE = "me.cortex.voxy";
|
||||||
|
|
||||||
Map<Class<?>, GsonConfigSerialization<?>> serializers = new HashMap<>();
|
Map<Class<?>, GsonConfigSerialization<?>> serializers = new HashMap<>();
|
||||||
@@ -109,6 +118,9 @@ public class Serialization {
|
|||||||
if (clzName.contains("VoxyConfigScreenFactory")) {
|
if (clzName.contains("VoxyConfigScreenFactory")) {
|
||||||
continue;//Dont want to modmenu incase it doesnt exist
|
continue;//Dont want to modmenu incase it doesnt exist
|
||||||
}
|
}
|
||||||
|
if (clzName.endsWith("VoxyConfig")) {
|
||||||
|
continue;//Special case to prevent recursive loading pain
|
||||||
|
}
|
||||||
|
|
||||||
if (clzName.equals(Serialization.class.getName())) {
|
if (clzName.equals(Serialization.class.getName())) {
|
||||||
continue;//Dont want to load ourselves
|
continue;//Dont want to load ourselves
|
||||||
|
|||||||
Reference in New Issue
Block a user