diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/Launcher.java b/HMCL/src/main/java/org/jackhuang/hmcl/Launcher.java index 35e428fb5..a558c4b74 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/Launcher.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/Launcher.java @@ -75,13 +75,7 @@ public final class Launcher extends Application { CookieHandler.setDefault(COOKIE_MANAGER); LOG.info("JavaFX Version: " + System.getProperty("javafx.runtime.version")); - try { - Object pipeline = Class.forName("com.sun.prism.GraphicsPipeline").getMethod("getPipeline").invoke(null); - LOG.info("Prism pipeline: " + (pipeline == null ? "null" : pipeline.getClass().getName())); - } catch (Throwable e) { - LOG.warning("Failed to get prism pipeline", e); - } - + LOG.info("Prism Pipeline: " + FXUtils.GRAPHICS_PIPELINE); LOG.info("Dark Mode: " + Optional.ofNullable(FXUtils.DARK_MODE).map(ObservableBooleanValue::get).orElse(false)); LOG.info("Reduced Motion: " + Objects.requireNonNullElse(FXUtils.REDUCED_MOTION, false)); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java index a4273bb1c..d0e379b80 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java @@ -72,6 +72,8 @@ import static org.jackhuang.hmcl.util.i18n.I18n.i18n; public final class Controllers { public static final String JAVA_VERSION_TIP = "javaVersion"; + public static final String JAVA_INTERPRETED_MODE_TIP = "javaInterpretedMode"; + public static final String SOFTWARE_RENDERING = "softwareRendering"; public static final int MIN_WIDTH = 800 + 2 + 16; // bg width + border width*2 + shadow width*2 public static final int MIN_HEIGHT = 450 + 2 + 40 + 16; // bg height + border width*2 + toolbar height + shadow width*2 @@ -347,6 +349,24 @@ public final class Controllers { } } + // Check whether JIT is enabled in the current environment + if (!JavaRuntime.CURRENT_JIT_ENABLED && !Boolean.TRUE.equals(config().getShownTips().get(JAVA_INTERPRETED_MODE_TIP))) { + Controllers.dialog(new MessageDialogPane.Builder(i18n("warning.java_interpreted_mode"), i18n("message.warning"), MessageType.WARNING) + .ok(null) + .addCancel(i18n("button.do_not_show_again"), () -> + config().getShownTips().put(JAVA_INTERPRETED_MODE_TIP, true)) + .build()); + } + + // Check whether hardware acceleration is enabled + if (!FXUtils.GPU_ACCELERATION_ENABLED && !Boolean.TRUE.equals(config().getShownTips().get(SOFTWARE_RENDERING))) { + Controllers.dialog(new MessageDialogPane.Builder(i18n("warning.software_rendering"), i18n("message.warning"), MessageType.WARNING) + .ok(null) + .addCancel(i18n("button.do_not_show_again"), () -> + config().getShownTips().put(SOFTWARE_RENDERING, true)) + .build()); + } + if (globalConfig().getAgreementVersion() < 1) { JFXDialogLayout agreementPane = new JFXDialogLayout(); agreementPane.setHeading(new Label(i18n("launcher.agreement"))); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java index e74c14d96..869596dee 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java @@ -109,6 +109,25 @@ public final class FXUtils { public static final int JAVAFX_MAJOR_VERSION; + public static final String GRAPHICS_PIPELINE; + public static final boolean GPU_ACCELERATION_ENABLED; + + static { + String pipelineName = ""; + + try { + Object pipeline = Class.forName("com.sun.prism.GraphicsPipeline").getMethod("getPipeline").invoke(null); + if (pipeline != null) { + pipelineName = pipeline.getClass().getName(); + } + } catch (Throwable e) { + LOG.warning("Failed to get prism pipeline", e); + } + + GRAPHICS_PIPELINE = pipelineName; + GPU_ACCELERATION_ENABLED = !pipelineName.endsWith(".SWPipeline"); + } + /// @see Platform.Preferences public static final @Nullable ObservableMap PREFERENCES; public static final @Nullable ObservableBooleanValue DARK_MODE; diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index dc7870f10..74b875480 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -179,6 +179,7 @@ button.change_source=Change Download Source button.clear=Clear button.copy_and_exit=Copy and Exit button.delete=Delete +button.do_not_show_again=Don't show again button.edit=Edit button.install=Install button.export=Export @@ -1487,6 +1488,11 @@ version.search.prompt=Enter the version name to search version.settings=Settings version.update=Update Modpack +warning.java_interpreted_mode=HMCL is running in an interpreted Java environment, which will greatly affect performance.\n\ + \n\ + We recommend using a Java with JIT support to launch HMCL for the best experience. +warning.software_rendering=HMCL is currently using software rendering, which will greatly affect performance. + wiki.tooltip=Minecraft Wiki Page wiki.version.game=https://minecraft.wiki/w/Java_Edition_%s wiki.version.game.snapshot=https://minecraft.wiki/w/Java_Edition_%s diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh.properties b/HMCL/src/main/resources/assets/lang/I18N_zh.properties index 1a80ef8e1..df3bb58a5 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh.properties @@ -182,6 +182,7 @@ button.change_source=切換下載源 button.clear=清除 button.copy_and_exit=複製並退出 button.delete=刪除 +button.do_not_show_again=不再顯示 button.edit=編輯 button.install=安裝 button.export=匯出 @@ -1271,6 +1272,9 @@ version.search.prompt=輸入版本名稱進行搜尋 version.settings=遊戲設定 version.update=更新模組包 +warning.java_interpreted_mode=HMCL 正在執行於直譯器模式的 Java 環境中,效能將會受到很大影響。\n我們建議你使用支援 JIT 的 Java 啟動 HMCL 以獲得最佳體驗。 +warning.software_rendering=HMCL 正在使用軟體渲染,效能將會受到很大影響。 + wiki.tooltip=Minecraft Wiki 頁面 wiki.version.game=https://zh.minecraft.wiki/w/Java版%s wiki.version.game.snapshot=https://zh.minecraft.wiki/w/%s diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties index 210f9b908..a02189c66 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -190,6 +190,7 @@ button.change_source=切换下载源 button.clear=清除 button.copy_and_exit=复制并退出 button.delete=删除 +button.do_not_show_again=不再显示 button.edit=修改 button.install=安装 button.export=导出 @@ -1282,6 +1283,9 @@ version.search.prompt=输入版本名称进行搜索 version.settings=游戏设置 version.update=更新整合包 +warning.java_interpreted_mode=HMCL 正在运行在解释器模式的 Java 环境中,性能将会受到很大影响。\n我们建议你使用支持 JIT 的 Java 启动 HMCL 以获取最佳体验。 +warning.software_rendering=HMCL 正在使用软件渲染,性能将会受到很大影响。\n你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。 + wiki.tooltip=Minecraft Wiki 页面 wiki.version.game=https://zh.minecraft.wiki/w/Java版%s wiki.version.game.snapshot=https://zh.minecraft.wiki/w/%s diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/java/JavaRuntime.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/java/JavaRuntime.java index dffdab18e..d8be0f8ac 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/java/JavaRuntime.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/java/JavaRuntime.java @@ -130,6 +130,7 @@ public final class JavaRuntime implements Comparable { public static final JavaRuntime CURRENT_JAVA; public static final int CURRENT_VERSION; + public static final boolean CURRENT_JIT_ENABLED; public static JavaRuntime getDefault() { return CURRENT_JAVA; @@ -152,5 +153,9 @@ public final class JavaRuntime implements Comparable { CURRENT_JAVA = executable != null ? JavaRuntime.of(executable, JavaInfo.CURRENT_ENVIRONMENT, false) : null; CURRENT_VERSION = JavaInfo.CURRENT_ENVIRONMENT.getParsedVersion(); + + String vmInfo = System.getProperty("java.vm.info", ""); + CURRENT_JIT_ENABLED = !vmInfo.contains("interpreted mode") // HotSpot + && !vmInfo.contains("JIT disabled"); // J9 } } diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index f98540797..529164fa6 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -10,7 +10,7 @@ - +