diff --git a/src/main/java/ru/windcorp/progressia/ProgressiaLauncher.java b/src/main/java/ru/windcorp/progressia/ProgressiaLauncher.java index 4944f1c..c8935fc 100644 --- a/src/main/java/ru/windcorp/progressia/ProgressiaLauncher.java +++ b/src/main/java/ru/windcorp/progressia/ProgressiaLauncher.java @@ -40,6 +40,7 @@ public class ProgressiaLauncher { CrashReports.registerProvider(new OpenALContextProvider()); CrashReports.registerProvider(new ArgsContextProvider()); CrashReports.registerProvider(new LanguageContextProvider()); + CrashReports.registerProvider(new ScreenContextProvider()); // Analyzers CrashReports.registerAnalyzer(new OutOfMemoryAnalyzer()); diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/GraphicsBackend.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/GraphicsBackend.java index af69c93..a6aadfb 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/GraphicsBackend.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/GraphicsBackend.java @@ -39,10 +39,29 @@ public class GraphicsBackend { private static boolean faceCullingEnabled = false; private static boolean isFullscreen = false; + private static boolean isVSYNC = false; + private static boolean isGLFWInitialized = false; + private static boolean isOpenGLInitialized = false; private GraphicsBackend() { } + public static boolean isGLFWInitialized() { + return isGLFWInitialized; + } + + static void setGLFWInitialized(boolean isGLFWInitialized) { + GraphicsBackend.isGLFWInitialized = isGLFWInitialized; + } + + public static boolean isOpenGLInitialized() { + return isOpenGLInitialized; + } + + static void setOpenGLInitialized(boolean isOpenGLInitialized) { + GraphicsBackend.isOpenGLInitialized = isOpenGLInitialized; + } + public static void initialize() { startRenderThread(); } @@ -134,6 +153,10 @@ public class GraphicsBackend { return isFullscreen; } + public static boolean isVSYNC() { + return isVSYNC; + } + public static void setFullscreen() { GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowMonitor( @@ -159,4 +182,14 @@ public class GraphicsBackend { 0); isFullscreen = false; } + + public static void setVSYNC(boolean state) { + glfwSwapInterval(state ? 1 : 0); + isVSYNC = state; + } + + public static int getRefreshRate() { + GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); + return vidmode.refreshRate(); + } } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/GraphicsInterface.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/GraphicsInterface.java index be32b4c..1fb9695 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/GraphicsInterface.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/GraphicsInterface.java @@ -79,6 +79,7 @@ public class GraphicsInterface { } else { GraphicsBackend.setWindowed(); } + GraphicsBackend.setVSYNC(GraphicsBackend.isVSYNC()); } } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/LWJGLInitializer.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/LWJGLInitializer.java index af95b19..83c06c8 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/LWJGLInitializer.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/LWJGLInitializer.java @@ -50,6 +50,7 @@ class LWJGLInitializer { private static void initializeGLFW() { // TODO Do GLFW error handling: check glfwInit, setup error callback glfwInit(); + GraphicsBackend.setGLFWInitialized(true); } private static void createWindow() { @@ -67,7 +68,7 @@ class LWJGLInitializer { glfwSetInputMode(handle, GLFW_CURSOR, GLFW_CURSOR_DISABLED); glfwMakeContextCurrent(handle); - glfwSwapInterval(0); + glfwSwapInterval(0); // TODO: remove after config system is added } private static void positionWindow() { @@ -87,6 +88,7 @@ class LWJGLInitializer { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); RenderTaskQueue.schedule(OpenGLObjectTracker::deleteEnqueuedObjects); + GraphicsBackend.setOpenGLInitialized(true); } private static void setupWindowCallbacks() { diff --git a/src/main/java/ru/windcorp/progressia/common/util/crash/CrashReports.java b/src/main/java/ru/windcorp/progressia/common/util/crash/CrashReports.java index f33d4c5..ab0ec3e 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/crash/CrashReports.java +++ b/src/main/java/ru/windcorp/progressia/common/util/crash/CrashReports.java @@ -203,13 +203,12 @@ public class CrashReports { if (provider == null) continue; - addSeparator(output); - try { Map buf = new HashMap<>(); provider.provideContext(buf); if (!buf.isEmpty()) { + addSeparator(output); output.append(StringUtil.center(provider.getName(), 80)).append("\n"); for (Map.Entry entry : buf.entrySet()) { output.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n"); diff --git a/src/main/java/ru/windcorp/progressia/common/util/crash/providers/RAMContextProvider.java b/src/main/java/ru/windcorp/progressia/common/util/crash/providers/RAMContextProvider.java index e455d78..9c60921 100644 --- a/src/main/java/ru/windcorp/progressia/common/util/crash/providers/RAMContextProvider.java +++ b/src/main/java/ru/windcorp/progressia/common/util/crash/providers/RAMContextProvider.java @@ -26,12 +26,12 @@ public class RAMContextProvider implements ContextProvider { @Override public void provideContext(Map output) { - output.put("Max Memory", Long.toString(Runtime.getRuntime().maxMemory() / 1024 / 1024) + " MB"); - output.put("Total Memory", Long.toString(Runtime.getRuntime().totalMemory() / 1024 / 1024) + " MB"); - output.put("Free Memory", Long.toString(Runtime.getRuntime().freeMemory() / 1024 / 1024) + " MB"); + output.put("Max Memory", Runtime.getRuntime().maxMemory() / 1024 / 1024 + " MB"); + output.put("Total Memory", Runtime.getRuntime().totalMemory() / 1024 / 1024 + " MB"); + output.put("Free Memory", Runtime.getRuntime().freeMemory() / 1024 / 1024 + " MB"); output.put( "Used Memory", - Long.toString((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024) + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024 + " MB" ); } diff --git a/src/main/java/ru/windcorp/progressia/common/util/crash/providers/ScreenContextProvider.java b/src/main/java/ru/windcorp/progressia/common/util/crash/providers/ScreenContextProvider.java new file mode 100644 index 0000000..2b5f91c --- /dev/null +++ b/src/main/java/ru/windcorp/progressia/common/util/crash/providers/ScreenContextProvider.java @@ -0,0 +1,42 @@ +/* + * Progressia + * Copyright (C) 2020-2021 Wind Corporation and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package ru.windcorp.progressia.common.util.crash.providers; + +import ru.windcorp.progressia.client.graphics.backend.GraphicsBackend; +import ru.windcorp.progressia.client.graphics.backend.GraphicsInterface; +import ru.windcorp.progressia.common.util.crash.ContextProvider; + +import java.util.Map; + +public class ScreenContextProvider implements ContextProvider { + + @Override + public void provideContext(Map output) { + if (GraphicsBackend.isGLFWInitialized()) { + output.put("Refresh rate", GraphicsBackend.getRefreshRate() + " Hz"); + output.put("Size", GraphicsBackend.getFrameWidth() + "x" + GraphicsBackend.getFrameHeight()); + output.put("Fullscreen", GraphicsBackend.isFullscreen() ? "enabled" : "disabled"); + } + } + + @Override + public String getName() { + return "Screen Context Provider"; + } +} diff --git a/src/main/java/ru/windcorp/progressia/test/LayerTestGUI.java b/src/main/java/ru/windcorp/progressia/test/LayerTestGUI.java index 9d7b8fb..7c3f633 100755 --- a/src/main/java/ru/windcorp/progressia/test/LayerTestGUI.java +++ b/src/main/java/ru/windcorp/progressia/test/LayerTestGUI.java @@ -119,6 +119,14 @@ public class LayerTestGUI extends GUILayer { ) ); + panel.addChild( + new Label( + "VSYNCDisplay", + font, + tmp_dynFormat("LayerTestGUI.IsVSYNC", GraphicsBackend::isVSYNC) + ) + ); + panel.addChild( new DynamicLabel( "FPSDisplay", diff --git a/src/main/java/ru/windcorp/progressia/test/TestPlayerControls.java b/src/main/java/ru/windcorp/progressia/test/TestPlayerControls.java index 9183130..01ac685 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestPlayerControls.java +++ b/src/main/java/ru/windcorp/progressia/test/TestPlayerControls.java @@ -194,6 +194,13 @@ public class TestPlayerControls { updateGUI(); break; + case GLFW.GLFW_KEY_F12: + if (!event.isPress()) + return false; + GraphicsBackend.setVSYNC(!GraphicsBackend.isVSYNC()); + updateGUI(); + break; + case GLFW.GLFW_KEY_F3: if (!event.isPress()) return false; diff --git a/src/main/resources/assets/languages/en-US.lang b/src/main/resources/assets/languages/en-US.lang index 3524c66..a5a2341 100644 --- a/src/main/resources/assets/languages/en-US.lang +++ b/src/main/resources/assets/languages/en-US.lang @@ -20,4 +20,5 @@ LayerTestGUI.PosDisplay.NA.Entity = Pos: entity n/a LayerTestGUI.SelectedBlockDisplay = %s Block: %s LayerTestGUI.SelectedTileDisplay = %s Tile: %s LayerTestGUI.PlacementModeHint = (Blocks %s Tiles: Ctrl + Mouse Wheel) -LayerTestGUI.IsFullscreen = Fullscreen: %5s (F11) \ No newline at end of file +LayerTestGUI.IsFullscreen = Fullscreen: %5s (F11) +LayerTestGUI.IsVSYNC = VSYNC: %5s (F12) \ No newline at end of file diff --git a/src/main/resources/assets/languages/ru-RU.lang b/src/main/resources/assets/languages/ru-RU.lang index 4056ee1..a8b2645 100644 --- a/src/main/resources/assets/languages/ru-RU.lang +++ b/src/main/resources/assets/languages/ru-RU.lang @@ -20,4 +20,5 @@ LayerTestGUI.PosDisplay.NA.Entity = Поз: сущность н/д LayerTestGUI.SelectedBlockDisplay = %s Блок: %s LayerTestGUI.SelectedTileDisplay = %s Плитка: %s LayerTestGUI.PlacementModeHint = (Блок %s плитки: Ctrl + прокрутка) -LayerTestGUI.IsFullscreen = Полный экран: %5s (F11) \ No newline at end of file +LayerTestGUI.IsFullscreen = Полный экран: %5s (F11) +LayerTestGUI.IsVSYNC = Верт. синхр.: %5s (F12) \ No newline at end of file