Respect 'debugFrames' subsystem config option
Some checks failed
build-and-test / generate-javadoc (push) Failing after 58s
build-and-test / build (push) Failing after 1m4s
build-and-test / test (push) Has been cancelled

This commit is contained in:
JeremyStar™ 2024-10-14 16:02:35 +02:00
parent 7a7da3729c
commit 10e3b26ac0
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
2 changed files with 17 additions and 6 deletions

View file

@ -23,6 +23,7 @@ import de.staropensource.engine.base.implementable.Configuration;
import de.staropensource.engine.base.utility.PropertiesReader; import de.staropensource.engine.base.utility.PropertiesReader;
import de.staropensource.engine.windowing.event.RenderingErrorEvent; import de.staropensource.engine.windowing.event.RenderingErrorEvent;
import de.staropensource.engine.windowing.event.WindowingErrorEvent; import de.staropensource.engine.windowing.event.WindowingErrorEvent;
import de.staropensource.engine.windowing.implementable.api.ApiManagementClass;
import de.staropensource.engine.windowing.type.window.VsyncMode; import de.staropensource.engine.windowing.type.window.VsyncMode;
import lombok.Getter; import lombok.Getter;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -90,8 +91,11 @@ public final class WindowingSubsystemConfiguration extends Configuration {
private boolean debugInput; private boolean debugInput;
/** /**
* If enabled, will log the delta time average and FPS count * If enabled, will log the delta time average
* to the console every second. * and FPS count to the console every second.
* <p>
* Is applied during rendering thread startup
* and will not be applied after.
* *
* @since v1-alpha2 * @since v1-alpha2
* -- GETTER -- * -- GETTER --

View file

@ -19,6 +19,7 @@
package de.staropensource.engine.windowing.implementable.api; 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.logging.LoggerInstance;
import de.staropensource.engine.base.utility.Math; import de.staropensource.engine.base.utility.Math;
import de.staropensource.engine.base.utility.Miscellaneous; import de.staropensource.engine.base.utility.Miscellaneous;
@ -94,9 +95,15 @@ public abstract class ApiManagementClass {
long renderTime; // Amount of time spent rendering long renderTime; // Amount of time spent rendering
long sleepDuration; // Time spent sleeping the thread long sleepDuration; // Time spent sleeping the thread
LinkedList<Long> splitDeltaTime = new LinkedList<>(); // Used for calculating the delta time (render time average over one second) LinkedList<Long> 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) 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 // Run while the 'output' is empty
while (output.get().isEmpty()) { while (output.get().isEmpty()) {
renderTime = Miscellaneous.measureExecutionTime(() -> { renderTime = Miscellaneous.measureExecutionTime(() -> {
@ -121,11 +128,11 @@ public abstract class ApiManagementClass {
} }
// Calculate delta time and frame count every second // Calculate delta time and frame count every second
if (System.currentTimeMillis() >= reportDuration + 1000) { if (System.currentTimeMillis() >= reportDuration) {
deltaTime = Math.getMeanLong(splitDeltaTime); // Calculate delta time 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 splitDeltaTime.clear(); // Clear 'splitDeltaTime' list
} }
} }