forked from StarOpenSource/Engine
Add SubsystemMainClass#getName() & init time stat
This commit is contained in:
parent
481ce80535
commit
bffe68c015
10 changed files with 83 additions and 49 deletions
|
@ -319,14 +319,16 @@ public final class Engine implements SubsystemMainClass {
|
||||||
|
|
||||||
// Initialize subsystems
|
// Initialize subsystems
|
||||||
logger.info("Initializing engine subsystems");
|
logger.info("Initializing engine subsystems");
|
||||||
|
long initTime;
|
||||||
for (DependencySubsystemVector vector : subsystems) {
|
for (DependencySubsystemVector vector : subsystems) {
|
||||||
logger.verb("Initializing subsystem " + vector.getMainClass().getClass().getName());
|
logger.diag("Initializing subsystem " + vector.getMainClass().getName() + " (" + vector.getMainClass().getClass().getName() + ")");
|
||||||
try {
|
try {
|
||||||
vector.getMainClass().initializeSubsystem();
|
initTime = Miscellaneous.measureExecutionTime(() -> vector.getMainClass().initializeSubsystem());
|
||||||
} catch (Throwable throwable) {
|
} 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;
|
throw throwable;
|
||||||
}
|
}
|
||||||
|
logger.diag("Initialized subsystem " + vector.getMainClass().getName() + " (" + vector.getMainClass().getClass().getName() + ") in " + initTime + "ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update 'subsystems'
|
// Update 'subsystems'
|
||||||
|
@ -363,6 +365,15 @@ public final class Engine implements SubsystemMainClass {
|
||||||
Runtime.getRuntime().exit(exitCode);
|
Runtime.getRuntime().exit(exitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "base";
|
||||||
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public void initializeSubsystem() {}
|
public void initializeSubsystem() {}
|
||||||
|
|
|
@ -19,11 +19,16 @@
|
||||||
|
|
||||||
package de.staropensource.sosengine.base.annotations;
|
package de.staropensource.sosengine.base.annotations;
|
||||||
|
|
||||||
|
import de.staropensource.sosengine.base.classes.SubsystemMainClass;
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This annotation marks a class as a subsystem main class.
|
* This annotation marks a class as a subsystem main class.
|
||||||
|
* <p>
|
||||||
|
* Make sure your subsystem implements {@link SubsystemMainClass}.
|
||||||
*
|
*
|
||||||
|
* @see SubsystemMainClass
|
||||||
* @since v1-alpha1
|
* @since v1-alpha1
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package de.staropensource.sosengine.base.classes;
|
package de.staropensource.sosengine.base.classes;
|
||||||
|
|
||||||
import de.staropensource.sosengine.base.Engine;
|
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.annotations.EventListener;
|
||||||
import de.staropensource.sosengine.base.internal.events.InternalEngineShutdownEvent;
|
import de.staropensource.sosengine.base.internal.events.InternalEngineShutdownEvent;
|
||||||
import de.staropensource.sosengine.base.logging.LoggerInstance;
|
import de.staropensource.sosengine.base.logging.LoggerInstance;
|
||||||
|
@ -29,6 +30,7 @@ import org.jetbrains.annotations.NotNull;
|
||||||
/**
|
/**
|
||||||
* The interface for engine subsystem main classes.
|
* The interface for engine subsystem main classes.
|
||||||
*
|
*
|
||||||
|
* @see EngineSubsystem
|
||||||
* @since v1-alpha0
|
* @since v1-alpha0
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "unused" })
|
@SuppressWarnings({ "unused" })
|
||||||
|
@ -41,6 +43,14 @@ public interface SubsystemMainClass {
|
||||||
*/
|
*/
|
||||||
LoggerInstance logger = null;
|
LoggerInstance logger = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of this subsystem.
|
||||||
|
*
|
||||||
|
* @since v1-alpha2
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
String getName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes this subsystem.
|
* Initializes this subsystem.
|
||||||
*
|
*
|
||||||
|
|
|
@ -20,11 +20,4 @@
|
||||||
<p>Welcome to the sos!engine API documentation!<br/>
|
<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>
|
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>
|
<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>
|
</body>
|
||||||
|
|
|
@ -40,6 +40,8 @@ import org.jetbrains.annotations.NotNull;
|
||||||
import org.lwjgl.glfw.GLFWErrorCallback;
|
import org.lwjgl.glfw.GLFWErrorCallback;
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import static org.lwjgl.glfw.GLFW.*;
|
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} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public void initializeSubsystem() {
|
public void initializeSubsystem() {
|
||||||
long initTime = Miscellaneous.measureExecutionTime(() -> {
|
// Precompute event listeners
|
||||||
// Precompute event listeners
|
EventHelper.precomputeEventListeners(GraphicsErrorEvent.class);
|
||||||
EventHelper.precomputeEventListeners(GraphicsErrorEvent.class);
|
|
||||||
|
|
||||||
// Register Graphics API
|
// Register Graphics API
|
||||||
GraphicsSubsystem.getInstance().registerGraphicsApi(this);
|
GraphicsSubsystem.getInstance().registerGraphicsApi(this);
|
||||||
});
|
|
||||||
|
|
||||||
logger.verb("Initialized subsystem in " + initTime + "ms");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
|
|
|
@ -118,23 +118,25 @@ public final class GraphicsSubsystem implements SubsystemMainClass {
|
||||||
instance = this;
|
instance = this;
|
||||||
else {
|
else {
|
||||||
instance.logger.crash("Graphics subsystem tried to initialize twice");
|
instance.logger.crash("Graphics subsystem tried to initialize twice");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "graphics";
|
||||||
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public void initializeSubsystem() {
|
public void initializeSubsystem() {
|
||||||
long initTime = Miscellaneous.measureExecutionTime(() -> {
|
// Initialize GraphicsSubsystemConfiguration and load it
|
||||||
// Initialize GraphicsSubsystemConfiguration and load it
|
new GraphicsSubsystemConfiguration();
|
||||||
new GraphicsSubsystemConfiguration();
|
GraphicsSubsystemConfiguration.getInstance().loadConfiguration();
|
||||||
GraphicsSubsystemConfiguration.getInstance().loadConfiguration();
|
|
||||||
|
|
||||||
// Precompute event listeners
|
// Precompute event listeners
|
||||||
precomputeEventListeners();
|
precomputeEventListeners();
|
||||||
});
|
|
||||||
|
|
||||||
logger.verb("Initialized subsystem in " + initTime + "ms");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -37,6 +37,8 @@ import lombok.Getter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.lwjgl.glfw.GLFWErrorCallback;
|
import org.lwjgl.glfw.GLFWErrorCallback;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import static org.lwjgl.glfw.GLFW.*;
|
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} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public void initializeSubsystem() {
|
public void initializeSubsystem() {
|
||||||
long initTime = Miscellaneous.measureExecutionTime(() -> {
|
// Warn about instability
|
||||||
// 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.");
|
||||||
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
|
// Register Graphics API
|
||||||
GraphicsSubsystem.getInstance().registerGraphicsApi(this);
|
GraphicsSubsystem.getInstance().registerGraphicsApi(this);
|
||||||
});
|
|
||||||
|
|
||||||
logger.verb("Initialized subsystem in " + initTime + "ms");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
|
|
|
@ -17,11 +17,10 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
rootProject.name = 'sosengine'
|
rootProject.name = "sosengine"
|
||||||
|
|
||||||
include 'base'
|
include "base"
|
||||||
include 'slf4j-compat'
|
include "slf4j-compat"
|
||||||
include 'graphics'
|
include "graphics"
|
||||||
include 'graphics:opengl'
|
include "graphics:opengl"
|
||||||
include 'graphics:vulkan'
|
include "graphics:vulkan"
|
||||||
include 'testapp'
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ import de.staropensource.sosengine.base.logging.LoggerInstance;
|
||||||
import de.staropensource.sosengine.base.types.CodePart;
|
import de.staropensource.sosengine.base.types.CodePart;
|
||||||
import de.staropensource.sosengine.base.types.DependencyVector;
|
import de.staropensource.sosengine.base.types.DependencyVector;
|
||||||
import de.staropensource.sosengine.base.types.logging.LogIssuer;
|
import de.staropensource.sosengine.base.types.logging.LogIssuer;
|
||||||
import de.staropensource.sosengine.base.utility.Miscellaneous;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -71,12 +70,17 @@ public class Slf4jCompatibilitySubsystem implements SubsystemMainClass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "slf4j-compat";
|
||||||
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public void initializeSubsystem() {
|
public void initializeSubsystem() {
|
||||||
logger.verb("Initialized subsystem in " +
|
LoggerFactory.getLogger(CompatibilityLogger.class).debug("If you see this then the SLF4J Compatibility Subsystem is working!");
|
||||||
Miscellaneous.measureExecutionTime(() -> LoggerFactory.getLogger(CompatibilityLogger.class).debug("If you see this then the SLF4J Compatibility Subsystem is working!"))
|
|
||||||
+ "ms");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
|
|
|
@ -42,8 +42,8 @@ dependencies {
|
||||||
implementation(project(":base"))
|
implementation(project(":base"))
|
||||||
implementation(project(":slf4j-compat"))
|
implementation(project(":slf4j-compat"))
|
||||||
implementation(project(":graphics"))
|
implementation(project(":graphics"))
|
||||||
implementation project(":graphics:vulkan")
|
implementation(project(":graphics:vulkan"))
|
||||||
implementation project(":graphics:opengl")
|
implementation(project(":graphics:opengl"))
|
||||||
implementation("org.fusesource.jansi:jansi:${dependencyJansi}") // for some reason required or the build fails don"t ask me why
|
implementation("org.fusesource.jansi:jansi:${dependencyJansi}") // for some reason required or the build fails don"t ask me why
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue