Added support VSYNC and fixed crashreporter formatter

This commit is contained in:
Sergey Karmanov 2021-01-31 13:29:10 +03:00
parent bdb3bff570
commit 73d24d36f4
No known key found for this signature in database
GPG Key ID: 6409DC8BD2961AC0
11 changed files with 104 additions and 9 deletions

View File

@ -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());

View File

@ -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();
}
}

View File

@ -79,6 +79,7 @@ public class GraphicsInterface {
} else {
GraphicsBackend.setWindowed();
}
GraphicsBackend.setVSYNC(GraphicsBackend.isVSYNC());
}
}

View File

@ -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() {

View File

@ -203,13 +203,12 @@ public class CrashReports {
if (provider == null)
continue;
addSeparator(output);
try {
Map<String, String> buf = new HashMap<>();
provider.provideContext(buf);
if (!buf.isEmpty()) {
addSeparator(output);
output.append(StringUtil.center(provider.getName(), 80)).append("\n");
for (Map.Entry<String, String> entry : buf.entrySet()) {
output.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n");

View File

@ -26,12 +26,12 @@ public class RAMContextProvider implements ContextProvider {
@Override
public void provideContext(Map<String, String> 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"
);
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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<String, String> 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";
}
}

View File

@ -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",

View File

@ -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;

View File

@ -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)
LayerTestGUI.IsFullscreen = Fullscreen: %5s (F11)
LayerTestGUI.IsVSYNC = VSYNC: %5s (F12)

View File

@ -20,4 +20,5 @@ LayerTestGUI.PosDisplay.NA.Entity = Поз: сущность н/д
LayerTestGUI.SelectedBlockDisplay = %s Блок: %s
LayerTestGUI.SelectedTileDisplay = %s Плитка: %s
LayerTestGUI.PlacementModeHint = (Блок %s плитки: Ctrl + прокрутка)
LayerTestGUI.IsFullscreen = Полный экран: %5s (F11)
LayerTestGUI.IsFullscreen = Полный экран: %5s (F11)
LayerTestGUI.IsVSYNC = Верт. синхр.: %5s (F12)