From 10e3b26ac08e1104b946c8ab8d514accf00f7224 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Mon, 14 Oct 2024 16:02:35 +0200 Subject: [PATCH] Respect 'debugFrames' subsystem config option --- .../WindowingSubsystemConfiguration.java | 8 ++++++-- .../implementable/api/ApiManagementClass.java | 15 +++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/windowing/src/main/java/de/staropensource/engine/windowing/WindowingSubsystemConfiguration.java b/windowing/src/main/java/de/staropensource/engine/windowing/WindowingSubsystemConfiguration.java index ab7bfebfa..eb8b296eb 100644 --- a/windowing/src/main/java/de/staropensource/engine/windowing/WindowingSubsystemConfiguration.java +++ b/windowing/src/main/java/de/staropensource/engine/windowing/WindowingSubsystemConfiguration.java @@ -23,6 +23,7 @@ import de.staropensource.engine.base.implementable.Configuration; import de.staropensource.engine.base.utility.PropertiesReader; import de.staropensource.engine.windowing.event.RenderingErrorEvent; import de.staropensource.engine.windowing.event.WindowingErrorEvent; +import de.staropensource.engine.windowing.implementable.api.ApiManagementClass; import de.staropensource.engine.windowing.type.window.VsyncMode; import lombok.Getter; import org.jetbrains.annotations.NotNull; @@ -90,8 +91,11 @@ public final class WindowingSubsystemConfiguration extends Configuration { private boolean debugInput; /** - * If enabled, will log the delta time average and FPS count - * to the console every second. + * If enabled, will log the delta time average + * and FPS count to the console every second. + *

+ * Is applied during rendering thread startup + * and will not be applied after. * * @since v1-alpha2 * -- GETTER -- diff --git a/windowing/src/main/java/de/staropensource/engine/windowing/implementable/api/ApiManagementClass.java b/windowing/src/main/java/de/staropensource/engine/windowing/implementable/api/ApiManagementClass.java index ebcee2c4e..b2eb1a38a 100644 --- a/windowing/src/main/java/de/staropensource/engine/windowing/implementable/api/ApiManagementClass.java +++ b/windowing/src/main/java/de/staropensource/engine/windowing/implementable/api/ApiManagementClass.java @@ -19,6 +19,7 @@ package de.staropensource.engine.windowing.implementable.api; +import de.staropensource.engine.base.EngineConfiguration; import de.staropensource.engine.base.logging.LoggerInstance; import de.staropensource.engine.base.utility.Math; import de.staropensource.engine.base.utility.Miscellaneous; @@ -94,9 +95,15 @@ public abstract class ApiManagementClass { long renderTime; // Amount of time spent rendering long sleepDuration; // Time spent sleeping the thread LinkedList splitDeltaTime = new LinkedList<>(); // Used for calculating the delta time (render time average over one second) - long reportDuration = System.currentTimeMillis(); // Used for determining when to report frame count and delta time + long reportDuration = System.currentTimeMillis() + 1000; // Used for determining when to report frame count and delta time double deltaTime; // Contains the average render time over one second (delta time) + // Check if delta time and frame count shall be printed to console. + // Unless this code is ran 292 billion years into the future, + // this should sufficiently disable the reporting feature. + if (WindowingSubsystemConfiguration.getInstance().isDebugFrames()) + reportDuration = Long.MAX_VALUE; + // Run while the 'output' is empty while (output.get().isEmpty()) { renderTime = Miscellaneous.measureExecutionTime(() -> { @@ -121,11 +128,11 @@ public abstract class ApiManagementClass { } // Calculate delta time and frame count every second - if (System.currentTimeMillis() >= reportDuration + 1000) { + if (System.currentTimeMillis() >= reportDuration) { deltaTime = Math.getMeanLong(splitDeltaTime); // Calculate delta time - logger.info("Delta time average: " + deltaTime + " | Frames/s: " + 1000 / deltaTime); // Print delta time and frame count to console + logger.diag("Delta time average: " + deltaTime + " | Frames/s: " + 1000 / deltaTime); // Print delta time and frame count to console - reportDuration = System.currentTimeMillis(); // Update 'reportDuration' + reportDuration = System.currentTimeMillis() + 1000; // Update 'reportDuration' splitDeltaTime.clear(); // Clear 'splitDeltaTime' list } }