Disable voxy if on unsupported system
This commit is contained in:
@@ -1,15 +1,30 @@
|
||||
package me.cortex.voxy.client;
|
||||
|
||||
import me.cortex.voxy.client.core.gl.Capabilities;
|
||||
import me.cortex.voxy.common.Logger;
|
||||
import me.cortex.voxy.commonImpl.VoxyCommon;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
|
||||
|
||||
public class VoxyClient implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
|
||||
dispatcher.register(VoxyCommands.register());
|
||||
|
||||
ClientLifecycleEvents.CLIENT_STARTED.register(client->{
|
||||
boolean systemSupported = Capabilities.INSTANCE.compute && Capabilities.INSTANCE.indirectParameters;
|
||||
if (systemSupported) {
|
||||
VoxyCommon.setInstanceFactory(VoxyClientInstance::new);
|
||||
} else {
|
||||
Logger.error("Voxy is unsupported on your system.");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
|
||||
if (VoxyCommon.isAvailable()) {
|
||||
dispatcher.register(VoxyCommands.register());
|
||||
}
|
||||
});
|
||||
VoxyCommon.setInstanceFactory(VoxyClientInstance::new);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,25 +3,30 @@ package me.cortex.voxy.client.config;
|
||||
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||
import com.terraformersmc.modmenu.api.ModMenuApi;
|
||||
import me.cortex.voxy.common.Logger;
|
||||
import me.cortex.voxy.commonImpl.VoxyCommon;
|
||||
import net.caffeinemc.mods.sodium.client.gui.SodiumOptionsGUI;
|
||||
|
||||
public class ModMenuIntegration implements ModMenuApi {
|
||||
@Override
|
||||
public ConfigScreenFactory<?> getModConfigScreenFactory() {
|
||||
return parent -> {
|
||||
var screen = (SodiumOptionsGUI) SodiumOptionsGUI.createScreen(parent);
|
||||
//Sorry jelly and douira, please dont hurt me
|
||||
try {
|
||||
//We cant use .setPage() as that invokes rebuildGui, however the screen hasnt been initalized yet
|
||||
// causing things to crash
|
||||
var field = SodiumOptionsGUI.class.getDeclaredField("currentPage");
|
||||
field.setAccessible(true);
|
||||
field.set(screen, VoxyConfigScreenPages.voxyOptionPage);
|
||||
field.setAccessible(false);
|
||||
} catch (Exception e) {
|
||||
Logger.error("Failed to set the current page to voxy", e);
|
||||
if (VoxyCommon.isAvailable()) {
|
||||
var screen = (SodiumOptionsGUI) SodiumOptionsGUI.createScreen(parent);
|
||||
//Sorry jelly and douira, please dont hurt me
|
||||
try {
|
||||
//We cant use .setPage() as that invokes rebuildGui, however the screen hasnt been initalized yet
|
||||
// causing things to crash
|
||||
var field = SodiumOptionsGUI.class.getDeclaredField("currentPage");
|
||||
field.setAccessible(true);
|
||||
field.set(screen, VoxyConfigScreenPages.voxyOptionPage);
|
||||
field.setAccessible(false);
|
||||
} catch (Exception e) {
|
||||
Logger.error("Failed to set the current page to voxy", e);
|
||||
}
|
||||
return screen;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return screen;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.google.gson.FieldNamingPolicy;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import me.cortex.voxy.common.Logger;
|
||||
import me.cortex.voxy.commonImpl.VoxyCommon;
|
||||
import net.caffeinemc.mods.sodium.client.gui.options.storage.OptionStorage;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
@@ -32,23 +33,30 @@ public class VoxyConfig implements OptionStorage<VoxyConfig> {
|
||||
public boolean renderStatistics = false;
|
||||
|
||||
public static VoxyConfig loadOrCreate() {
|
||||
var path = getConfigPath();
|
||||
if (Files.exists(path)) {
|
||||
try (FileReader reader = new FileReader(path.toFile())) {
|
||||
var conf = GSON.fromJson(reader, VoxyConfig.class);
|
||||
if (conf != null) {
|
||||
conf.save();
|
||||
return conf;
|
||||
} else {
|
||||
Logger.error("Failed to load voxy config, resetting");
|
||||
if (VoxyCommon.isAvailable()) {
|
||||
var path = getConfigPath();
|
||||
if (Files.exists(path)) {
|
||||
try (FileReader reader = new FileReader(path.toFile())) {
|
||||
var conf = GSON.fromJson(reader, VoxyConfig.class);
|
||||
if (conf != null) {
|
||||
conf.save();
|
||||
return conf;
|
||||
} else {
|
||||
Logger.error("Failed to load voxy config, resetting");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Logger.error("Could not parse config", e);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Logger.error("Could not parse config",e);
|
||||
}
|
||||
var config = new VoxyConfig();
|
||||
config.save();
|
||||
return config;
|
||||
} else {
|
||||
var config = new VoxyConfig();
|
||||
config.enabled = false;
|
||||
config.enableRendering = false;
|
||||
return config;
|
||||
}
|
||||
var config = new VoxyConfig();
|
||||
config.save();
|
||||
return config;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
|
||||
@@ -20,8 +20,12 @@ public class Capabilities {
|
||||
public final boolean canQueryGpuMemory;
|
||||
public final long totalDedicatedMemory;//Bytes, dedicated memory
|
||||
public final long totalDynamicMemory;//Bytes, total allocation memory - dedicated memory
|
||||
public final boolean compute;
|
||||
public final boolean indirectParameters;
|
||||
public Capabilities() {
|
||||
var cap = GL.getCapabilities();
|
||||
this.compute = cap.glDispatchComputeIndirect != 0;
|
||||
this.indirectParameters = cap.glMultiDrawElementsIndirectCountARB != 0;
|
||||
this.meshShaders = cap.GL_NV_mesh_shader && cap.GL_NV_representative_fragment_test;
|
||||
this.canQueryGpuMemory = cap.GL_NVX_gpu_memory_info;
|
||||
//this.INT64_t = cap.GL_ARB_gpu_shader_int64 || cap.GL_AMD_gpu_shader_int64;
|
||||
|
||||
@@ -22,9 +22,11 @@ import java.util.function.Consumer;
|
||||
public class MixinClientLoginNetworkHandler {
|
||||
@Inject(method = "<init>", at = @At(value = "TAIL"))
|
||||
private void voxy$init(ClientConnection connection, MinecraftClient client, ServerInfo serverInfo, Screen parentScreen, boolean newWorld, Duration worldLoadTime, Consumer statusConsumer, CookieStorage cookieStorage, CallbackInfo ci) {
|
||||
VoxyClientInstance.isInGame = true;
|
||||
if (VoxyConfig.CONFIG.enabled) {
|
||||
VoxyCommon.createInstance();
|
||||
if (VoxyCommon.isAvailable()) {
|
||||
VoxyClientInstance.isInGame = true;
|
||||
if (VoxyConfig.CONFIG.enabled) {
|
||||
VoxyCommon.createInstance();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
public class MixinMinecraftClient {
|
||||
@Inject(method = "disconnect(Lnet/minecraft/client/gui/screen/Screen;Z)V", at = @At("TAIL"))
|
||||
private void voxy$injectWorldClose(CallbackInfo ci) {
|
||||
VoxyCommon.shutdownInstance();
|
||||
VoxyClientInstance.isInGame = false;
|
||||
if (VoxyCommon.isAvailable()) {
|
||||
VoxyCommon.shutdownInstance();
|
||||
VoxyClientInstance.isInGame = false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package me.cortex.voxy.client.mixin.sodium;
|
||||
|
||||
import me.cortex.voxy.client.config.VoxyConfigScreenPages;
|
||||
import me.cortex.voxy.commonImpl.VoxyCommon;
|
||||
import net.caffeinemc.mods.sodium.client.gui.SodiumOptionsGUI;
|
||||
import net.caffeinemc.mods.sodium.client.gui.options.OptionPage;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
@@ -19,6 +20,8 @@ public class MixinSodiumOptionsGUI {
|
||||
|
||||
@Inject(method = "<init>", at = @At("TAIL"))
|
||||
private void voxy$addConfigPage(Screen prevScreen, CallbackInfo ci) {
|
||||
this.pages.add(VoxyConfigScreenPages.voxyOptionPage = VoxyConfigScreenPages.page());
|
||||
if (VoxyCommon.isAvailable()) {
|
||||
this.pages.add(VoxyConfigScreenPages.voxyOptionPage = VoxyConfigScreenPages.page());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,12 +66,18 @@ public class VoxyCommon implements ModInitializer {
|
||||
}
|
||||
|
||||
public static void createInstance() {
|
||||
if (FACTORY == null) {
|
||||
//Logger.info("Voxy factory");
|
||||
return;
|
||||
}
|
||||
if (INSTANCE != null) {
|
||||
throw new IllegalStateException("Cannot create multiple instances");
|
||||
}
|
||||
if (FACTORY == null) {
|
||||
throw new IllegalStateException("Instance factory null");
|
||||
}
|
||||
INSTANCE = FACTORY.create();
|
||||
}
|
||||
|
||||
//Is voxy available in any capacity
|
||||
public static boolean isAvailable() {
|
||||
return FACTORY != null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user