Add SubsystemMainClass#getName() & init time stat

This commit is contained in:
JeremyStar™ 2024-07-16 14:50:39 +02:00
parent 481ce80535
commit bffe68c015
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
10 changed files with 83 additions and 49 deletions

View file

@ -319,14 +319,16 @@ public final class Engine implements SubsystemMainClass {
// Initialize subsystems
logger.info("Initializing engine subsystems");
long initTime;
for (DependencySubsystemVector vector : subsystems) {
logger.verb("Initializing subsystem " + vector.getMainClass().getClass().getName());
logger.diag("Initializing subsystem " + vector.getMainClass().getName() + " (" + vector.getMainClass().getClass().getName() + ")");
try {
vector.getMainClass().initializeSubsystem();
initTime = Miscellaneous.measureExecutionTime(() -> vector.getMainClass().initializeSubsystem());
} catch (Throwable throwable) {
logger.crash("An error occurred trying to initialize subsystem " + vector.getMainClass().getClass().getName() + ": " + throwable.getClass().getName() + (throwable.getMessage() == null ? "" : ": " + throwable.getMessage()));
logger.crash("An error occurred trying to initialize subsystem " + vector.getMainClass().getName() + " (" + vector.getMainClass().getClass().getName() + "): " + throwable.getClass().getName() + (throwable.getMessage() == null ? "" : ": " + throwable.getMessage()));
throw throwable;
}
logger.diag("Initialized subsystem " + vector.getMainClass().getName() + " (" + vector.getMainClass().getClass().getName() + ") in " + initTime + "ms");
}
// Update 'subsystems'
@ -363,6 +365,15 @@ public final class Engine implements SubsystemMainClass {
Runtime.getRuntime().exit(exitCode);
}
/**
* {@inheritDoc}
*/
@NotNull
@Override
public String getName() {
return "base";
}
/** {@inheritDoc} */
@Override
public void initializeSubsystem() {}

View file

@ -19,11 +19,16 @@
package de.staropensource.sosengine.base.annotations;
import de.staropensource.sosengine.base.classes.SubsystemMainClass;
import java.lang.annotation.*;
/**
* This annotation marks a class as a subsystem main class.
* <p>
* Make sure your subsystem implements {@link SubsystemMainClass}.
*
* @see SubsystemMainClass
* @since v1-alpha1
*/
@SuppressWarnings("unused")

View file

@ -20,6 +20,7 @@
package de.staropensource.sosengine.base.classes;
import de.staropensource.sosengine.base.Engine;
import de.staropensource.sosengine.base.annotations.EngineSubsystem;
import de.staropensource.sosengine.base.annotations.EventListener;
import de.staropensource.sosengine.base.internal.events.InternalEngineShutdownEvent;
import de.staropensource.sosengine.base.logging.LoggerInstance;
@ -29,6 +30,7 @@ import org.jetbrains.annotations.NotNull;
/**
* The interface for engine subsystem main classes.
*
* @see EngineSubsystem
* @since v1-alpha0
*/
@SuppressWarnings({ "unused" })
@ -41,6 +43,14 @@ public interface SubsystemMainClass {
*/
LoggerInstance logger = null;
/**
* Returns the name of this subsystem.
*
* @since v1-alpha2
*/
@NotNull
String getName();
/**
* Initializes this subsystem.
*

View file

@ -20,11 +20,4 @@
<p>Welcome to the sos!engine API documentation!<br/>
You are currently in the documentation for the <b>base</b> subsystem, the core of the engine.</p>
<p>The most interesting parts for developers wanting to use the engine are:</p>
<ul>
<li>{@link de.staropensource.sosengine.base.Engine} (main engine object)</li>
<li>{@link de.staropensource.sosengine.base.EngineConfiguration} (engine configuration)</li>
<li>stuff in {@link de.staropensource.sosengine.base.utility}</li>
<li>{@link de.staropensource.sosengine.base.classes.Placeholder} (for implementing custom placeholders)</li>
<li>{@link de.staropensource.sosengine.base.utility.PlaceholderEngine} (for adding those custom placeholders)</li>
</ul>
</body>

View file

@ -40,6 +40,8 @@ import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.system.MemoryUtil;
import java.util.Locale;
import static org.lwjgl.glfw.GLFW.*;
/**
@ -98,18 +100,21 @@ public final class OpenGlSubsystem implements ApiMainClass {
}
}
/** {@inheritDoc} */
@NotNull
@Override
public String getName() {
return getApiName().toLowerCase(Locale.ROOT);
}
/** {@inheritDoc} */
@Override
public void initializeSubsystem() {
long initTime = Miscellaneous.measureExecutionTime(() -> {
// Precompute event listeners
EventHelper.precomputeEventListeners(GraphicsErrorEvent.class);
// Register Graphics API
GraphicsSubsystem.getInstance().registerGraphicsApi(this);
});
logger.verb("Initialized subsystem in " + initTime + "ms");
}
/** {@inheritDoc} */

View file

@ -118,23 +118,25 @@ public final class GraphicsSubsystem implements SubsystemMainClass {
instance = this;
else {
instance.logger.crash("Graphics subsystem tried to initialize twice");
return;
}
}
/** {@inheritDoc} */
@NotNull
@Override
public String getName() {
return "graphics";
}
/** {@inheritDoc} */
@Override
public void initializeSubsystem() {
long initTime = Miscellaneous.measureExecutionTime(() -> {
// Initialize GraphicsSubsystemConfiguration and load it
new GraphicsSubsystemConfiguration();
GraphicsSubsystemConfiguration.getInstance().loadConfiguration();
// Precompute event listeners
precomputeEventListeners();
});
logger.verb("Initialized subsystem in " + initTime + "ms");
}
/**

View file

@ -37,6 +37,8 @@ import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFWErrorCallback;
import java.util.Locale;
import static org.lwjgl.glfw.GLFW.*;
/**
@ -96,18 +98,21 @@ public final class VulkanSubsystem implements ApiMainClass {
}
}
/** {@inheritDoc} */
@NotNull
@Override
public String getName() {
return getApiName().toLowerCase(Locale.ROOT);
}
/** {@inheritDoc} */
@Override
public void initializeSubsystem() {
long initTime = Miscellaneous.measureExecutionTime(() -> {
// Warn about instability
logger.warn("The Vulkan Graphics API is in an unfinished state. Trying to initialize the Graphics API will cause an engine crash.");
// Register Graphics API
GraphicsSubsystem.getInstance().registerGraphicsApi(this);
});
logger.verb("Initialized subsystem in " + initTime + "ms");
}
/** {@inheritDoc} */

View file

@ -17,11 +17,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
rootProject.name = 'sosengine'
rootProject.name = "sosengine"
include 'base'
include 'slf4j-compat'
include 'graphics'
include 'graphics:opengl'
include 'graphics:vulkan'
include 'testapp'
include "base"
include "slf4j-compat"
include "graphics"
include "graphics:opengl"
include "graphics:vulkan"

View file

@ -28,7 +28,6 @@ import de.staropensource.sosengine.base.logging.LoggerInstance;
import de.staropensource.sosengine.base.types.CodePart;
import de.staropensource.sosengine.base.types.DependencyVector;
import de.staropensource.sosengine.base.types.logging.LogIssuer;
import de.staropensource.sosengine.base.utility.Miscellaneous;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.slf4j.LoggerFactory;
@ -71,12 +70,17 @@ public class Slf4jCompatibilitySubsystem implements SubsystemMainClass {
}
}
/** {@inheritDoc} */
@NotNull
@Override
public String getName() {
return "slf4j-compat";
}
/** {@inheritDoc} */
@Override
public void initializeSubsystem() {
logger.verb("Initialized subsystem in " +
Miscellaneous.measureExecutionTime(() -> LoggerFactory.getLogger(CompatibilityLogger.class).debug("If you see this then the SLF4J Compatibility Subsystem is working!"))
+ "ms");
LoggerFactory.getLogger(CompatibilityLogger.class).debug("If you see this then the SLF4J Compatibility Subsystem is working!");
}
/** {@inheritDoc} */

View file

@ -42,8 +42,8 @@ dependencies {
implementation(project(":base"))
implementation(project(":slf4j-compat"))
implementation(project(":graphics"))
implementation project(":graphics:vulkan")
implementation project(":graphics:opengl")
implementation(project(":graphics:vulkan"))
implementation(project(":graphics:opengl"))
implementation("org.fusesource.jansi:jansi:${dependencyJansi}") // for some reason required or the build fails don"t ask me why
}