Added support VSYNC and fixed crashreporter formatter
This commit is contained in:
parent
bdb3bff570
commit
73d24d36f4
@ -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());
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -79,6 +79,7 @@ public class GraphicsInterface {
|
||||
} else {
|
||||
GraphicsBackend.setWindowed();
|
||||
}
|
||||
GraphicsBackend.setVSYNC(GraphicsBackend.isVSYNC());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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");
|
||||
|
@ -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"
|
||||
);
|
||||
}
|
||||
|
@ -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";
|
||||
}
|
||||
}
|
@ -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",
|
||||
|
@ -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;
|
||||
|
@ -21,3 +21,4 @@ LayerTestGUI.SelectedBlockDisplay = %s Block: %s
|
||||
LayerTestGUI.SelectedTileDisplay = %s Tile: %s
|
||||
LayerTestGUI.PlacementModeHint = (Blocks %s Tiles: Ctrl + Mouse Wheel)
|
||||
LayerTestGUI.IsFullscreen = Fullscreen: %5s (F11)
|
||||
LayerTestGUI.IsVSYNC = VSYNC: %5s (F12)
|
@ -21,3 +21,4 @@ LayerTestGUI.SelectedBlockDisplay = %s Блок: %s
|
||||
LayerTestGUI.SelectedTileDisplay = %s Плитка: %s
|
||||
LayerTestGUI.PlacementModeHint = (Блок %s плитки: Ctrl + прокрутка)
|
||||
LayerTestGUI.IsFullscreen = Полный экран: %5s (F11)
|
||||
LayerTestGUI.IsVSYNC = Верт. синхр.: %5s (F12)
|
Reference in New Issue
Block a user