Compare commits

..

No commits in common. "develop" and "v1-alpha8" have entirely different histories.

71 changed files with 3067 additions and 1901 deletions

3
.gitignore vendored
View file

@ -42,6 +42,3 @@ bin/
### Mac OS ### ### Mac OS ###
.DS_Store .DS_Store
### Java ###
hs_err_pid*.log

View file

@ -19,11 +19,8 @@
package de.staropensource.engine.base; package de.staropensource.engine.base;
import de.staropensource.engine.base.annotation.EngineSubsystem;
import de.staropensource.engine.base.event.LogEvent;
import de.staropensource.engine.base.implementable.Configuration; import de.staropensource.engine.base.implementable.Configuration;
import de.staropensource.engine.base.implementable.ShortcodeParser; import de.staropensource.engine.base.implementable.ShortcodeParser;
import de.staropensource.engine.base.implementable.SubsystemClass;
import de.staropensource.engine.base.logging.Logger; import de.staropensource.engine.base.logging.Logger;
import de.staropensource.engine.base.logging.backend.async.LoggingThread; import de.staropensource.engine.base.logging.backend.async.LoggingThread;
import de.staropensource.engine.base.type.EngineState; import de.staropensource.engine.base.type.EngineState;
@ -69,11 +66,11 @@ public final class EngineConfiguration extends Configuration {
private static EngineConfiguration instance; private static EngineConfiguration instance;
/** /**
* Contains the configuration prefix. * Contains prefix properties must begin with.
* *
* @since v1-alpha0 * @since v1-alpha0
* -- GETTER -- * -- GETTER --
* Returns the configuration prefix. * Returns prefix properties must begin with.
* *
* @return property group * @return property group
* @since v1-alpha0 * @since v1-alpha0
@ -82,196 +79,132 @@ public final class EngineConfiguration extends Configuration {
/** /**
* Contains if debugging options should be allowed. * If enabled, allows for unintentional behaviour
* All debugging options will be forcefully set to * and excess logging. Unless you want to debug or work
* {@code false} if this option is set to {@code false}. * on a sensitive part of the engine, don't enable this!
* *
* @since v1-alpha0 * @since v1-alpha0
* -- GETTER -- * -- GETTER --
* Returns if debugging options should be allowed. * Gets the value for {@link #debug}.
* All debugging options will be forcefully set to
* {@code false} if this option is set to {@code false}.
* *
* @return debugging enabled? * @return variable value
* @see #debug
* @since v1-alpha0 * @since v1-alpha0
*/ */
private boolean debug; private boolean debug;
/** /**
* Contains whether or not to log * If enabled, all called events will be logged.
* events being emitted.
* <p>
* This will cause all events to
* be logged, with the exception
* of the {@link LogEvent}.
* *
* @since v1-alpha0 * @since v1-alpha0
* -- GETTER -- * -- GETTER --
* Returns whether or not to log * Gets the value for {@link #debugEvents}.
* events being emitted.
* <p>
* This will cause all events to
* be logged, with the exception
* of the {@link LogEvent}.
* *
* @return detailed event logging enabled? * @return variable value
* @see #debugEvents
* @since v1-alpha0 * @since v1-alpha0
*/ */
private boolean debugEvents; private boolean debugEvents;
/** /**
* Contains whether or not to automatically discover * If enabled, will try to automatically initialize every
* and initialize any class extending {@link SubsystemClass} * subsystem found though reflection.
* whilst being annotated with {@link EngineSubsystem}.
* <p> * <p>
* This mechanism may fail in certain situations, where * This however may fail in certain situation, where manual
* manual subsystem initialization may be desired. Make * subsystem initialization may be required. For this reason,
* sure to disable this setting before engine startup * this can be turned off before the engine initializes. Please
* and then initialize all subsystems manually. * note though that dependency resolution between subsystems
* won't be performed, be careful when initializing subsystems manually.
* *
* @see Engine * @see Engine
* @since v1-alpha5 * @since v1-alpha2
* -- GETTER -- * -- GETTER --
* Returns whether or not to automatically discover * Gets the value for {@link #initialPerformSubsystemInitialization}.
* and initialize any class extending {@link SubsystemClass}
* whilst being annotated with {@link EngineSubsystem}.
* <p>
* This mechanism may fail in certain situations, where
* manual subsystem initialization may be desired. Make
* sure to disable this setting before engine startup
* and then initialize all subsystems manually.
* *
* @return automatically discover and initialize subsystems? * @return variable value
* @see #initialPerformSubsystemInitialization
* @since v1-alpha5 * @since v1-alpha5
*/ */
private boolean initialPerformSubsystemInitialization; private boolean initialPerformSubsystemInitialization;
/** /**
* Contains a set of class names to try to load * Will try to load the specified classes as subsystems,
* and initialize as subsystems. Will only take effect * if reflective classpath scanning is disabled.
* if {@link #initialPerformSubsystemInitialization} is
* turned off.
* *
* @since v1-alpha5 * @since v1-alpha5
* -- GETTER -- * -- GETTER --
* Returns a set of class names to try to load * Gets the value for {@link #initialIncludeSubsystemClasses}.
* and initialize as subsystems. Will only take effect
* if {@link #getInitialIncludeSubsystemClasses()} is
* turned off.
* *
* @return set of class names to try and initialize as subsystems * @return variable value
* @see #initialIncludeSubsystemClasses
* @since v1-alpha5 * @since v1-alpha5
*/ */
private Set<@NotNull String> initialIncludeSubsystemClasses; private Set<@NotNull String> initialIncludeSubsystemClasses;
/** /**
* Contains whether or not to complain about invalid * If enabled, will cause {@link ShortcodeParser} to print
* shortcodes. * invalid shortcodes as {@link LogLevel#SILENT_WARNING}s.
* <p>
* Requires the active log level to be set at least
* to {@link LogLevel#SILENT_WARNING} to have effect.
* *
* @see ShortcodeParser
* @see #logLevel * @see #logLevel
* @since v1-alpha0 * @since v1-alpha0
* -- GETTER -- * -- GETTER --
* Returns whether or not to complain about invalid * Gets the value for {@link #errorShortcodeParser}.
* shortcodes.
* <p>
* Requires the active log level to be set at least
* to {@link LogLevel#SILENT_WARNING} to have effect.
* *
* @return complain about invalid shortcodes? * @return variable value
* @see #getLogLevel() * @see #errorShortcodeParser
* @since v1-alpha0 * @since v1-alpha0
*/ */
private boolean errorShortcodeParser; private boolean errorShortcodeParser;
/** /**
* Contains if to log asynchronously. * If enabled, will makes the {@link Logger} work asynchronous,
* <p> * in a separate platform thread. Don't disable unless you want
* If enabled, will cause a logging thread * your application to run <b>extremely</b> slowly.
* to spawn. All log messages will be queued
* and printed after a set delay
* ({@link #logPollingSpeed}).
* Highly recommended to keep enabled, or
* the performance of your application will
* very likely suffer.
* *
* @see #logPollingSpeed * @see #logPollingSpeed
* @see Thread
* @since v1-alpha0 * @since v1-alpha0
* -- GETTER -- * -- GETTER --
* Returns if to log asynchronously. * Gets the value for {@link #optimizeLogging}.
* <p>
* If enabled, will cause a logging thread
* to spawn. All log messages will be queued
* and printed after a set delay
* ({@link #getLogPollingSpeed()}).
* Highly recommended to keep enabled, or
* the performance of your application will
* very likely suffer.
* *
* @return log asynchronously? * @return variable value
* @see #getLogPollingSpeed() * @see #optimizeLogging
* @since v1-alpha0 * @since v1-alpha0
*/ */
private boolean optimizeLogging; private boolean optimizeLogging;
/** /**
* Contains whether or not to emit events * If enabled, will make all events asynchronous,
* asynchronously. * in separate virtual threads. Don't disable unless you
* <p> * want your application to run slower.
* This will cause a
* <a href="https://openjdk.org/jeps/444">VirtualThread</a>
* to spawn every time an event is emitted.
* *
* @see VirtualThread
* @since v1-alpha0 * @since v1-alpha0
* -- GETTER -- * -- GETTER --
* Contains whether or not to emit events * Gets the value for {@link #optimizeEvents}.
* asynchronously.
* <p>
* This will cause a
* <a href="https://openjdk.org/jeps/444">VirtualThread</a>
* to spawn every time an event is emitted.
* *
* @return emit events asynchronously? * @return variable value
* @see #optimizeEvents
* @since v1-alpha0 * @since v1-alpha0
*/ */
private boolean optimizeEvents; private boolean optimizeEvents;
/** /**
* Contains the minimum allowed log level. * Contains which logger levels are allowed
* <p> * by setting the minimum logger level.
* The priority list is as follows (from high to low priority):
* <ul>
* <li>{@link LogLevel#CRASH}</li>
* <li>{@link LogLevel#ERROR}</li>
* <li>{@link LogLevel#WARNING}</li>
* <li>{@link LogLevel#INFORMATIONAL}</li>
* <li>{@link LogLevel#SILENT_WARNING}</li>
* <li>{@link LogLevel#VERBOSE}</li>
* <li>{@link LogLevel#DIAGNOSTIC}</li>
* </ul>
* *
* @see Logger
* @since v1-alpha0 * @since v1-alpha0
* -- GETTER -- * -- GETTER --
* Returns the minimum allowed log level. * Gets the value for {@link #logLevel}.
* <p>
* The priority list is as follows (from high to low priority):
* <ul>
* <li>{@link LogLevel#CRASH}</li>
* <li>{@link LogLevel#ERROR}</li>
* <li>{@link LogLevel#WARNING}</li>
* <li>{@link LogLevel#INFORMATIONAL}</li>
* <li>{@link LogLevel#SILENT_WARNING}</li>
* <li>{@link LogLevel#VERBOSE}</li>
* <li>{@link LogLevel#DIAGNOSTIC}</li>
* </ul>
* *
* @return minimum allowed log level * @return variable value
* @see #logLevel
* @since v1-alpha0 * @since v1-alpha0
*/ */
private LogLevel logLevel; private LogLevel logLevel;
@ -293,118 +226,75 @@ public final class EngineConfiguration extends Configuration {
* <li><code>lineNumber</code></li> * <li><code>lineNumber</code></li>
* </ul> * </ul>
* *
* @see Logger
* @since v1-alpha8 * @since v1-alpha8
* -- GETTER -- * -- GETTER --
* Returns a comma-separated list of optional * Gets the value for {@link #logFeatures}
* features to add to the final log output.
* <p>
* Available features (in order of appearance):
* <ul>
* <li><code>formatting</code></li>
* <li><code>runtime</code></li>
* <li><code>date</code></li>
* <li><code>time</code></li>
* <li><code>shortIssuerClass</code></li>
* <li><code>moduleName</code></li>
* <li><code>moduleVersion</code> (requires <code>moduleName</code>)</li>
* <li><code>methodName</code></li>
* <li><code>lineNumber</code></li>
* </ul>
* *
* @return optional features to enable * @return variable value
* @see #logFeatures
* @since v1-alpha8 * @since v1-alpha8
*/ */
private Set<@NotNull String> logFeatures; private Set<@NotNull String> logFeatures;
/** /**
* Contains how fast the logging thread will * Contains how fast the logging thread will
* poll for queued messages in milliseconds. * poll for queued messages. This also causes
* This also causes messages to be buffered. * messages to be buffered.
* <p> * <p>
* Only applies if {@code optimizeLogging} is turned on. * Only applies if {@code optimizeLogging} is turned on.
* Values below {@code 1} will poll for queued messages * Values below {@code 1} will poll for queued
* as fast as it can. This however has pretty much no * messages as fast as it can. This however has pretty much
* benefit. Leave it at {@code 5}, it works quite well. * no benefit. Leave it at {@code 5}, it works quite well.
* *
* @see #optimizeLogging * @see #optimizeLogging
* @since v1-alpha4 * @since v1-alpha4
* -- GETTER -- * -- GETTER --
* Contains how fast the logging thread will * Gets the value for {@link #logPollingSpeed}.
* poll for queued messages, in milliseconds.
* This also causes messages to be buffered.
* <p>
* Only applies if {@code optimizeLogging} is turned on.
* Values below {@code 1} will poll for queued messages
* as fast as it can. This however has pretty much no
* benefit. Leave it at {@code 5}, it works quite well.
* *
* @return logging thread polling speed in milliseconds * @return variable value
* @see #isOptimizeLogging() * @see #logPollingSpeed
* @since v1-alpha4 * @since v1-alpha4
*/ */
private int logPollingSpeed; private int logPollingSpeed;
/** /**
* Contains whether or not to forcefully write * If enabled, will force sos!engine's logging infrastructure to use
* to the standard output instead of the * <a href="https://www.man7.org/linux/man-pages/man3/stderr.3.html">the standard output</a>
* standard error stream. * instead of <a href="https://www.man7.org/linux/man-pages/man3/stderr.3.html">the standard error</a>
* <p> * for logging the {@code ERROR} and {@code CRASH} log levels.
* This only applies to the {@link LogLevel#ERROR} and
* {@link LogLevel#CRASH} log levels, as these use
* the standard error stream by default.
* *
* @see <a href="https://man7.org/linux/man-pages/man3/stderr.3.html">man page about standard streams</a>
* @since v1-alpha0 * @since v1-alpha0
* -- GETTER -- * -- GETTER --
* Contains whether or not to forcefully write * Gets the value for {@link #logForceStandardOutput}.
* to the standard output instead of the
* standard error stream.
* <p>
* This only applies to the {@link LogLevel#ERROR} and
* {@link LogLevel#CRASH} log levels, as these use
* the standard error stream by default.
* *
* @return force use stdout? * @return variable value
* @see <a href="https://man7.org/linux/man-pages/man3/stderr.3.html">man page about standard streams</a> * @see #logForceStandardOutput
* @since v1-alpha0 * @since v1-alpha0
*/ */
private boolean logForceStandardOutput; private boolean logForceStandardOutput;
/** /**
* Contains if to truncate the full path * Will truncate the path of types when using
* of a class when invoking using their * their {@code toString} method.
* {@link #toString()} method.
* <p> * <p>
* Here's an example: Lets say that you have a * Here's an example: Lets say that you
* {@link Vec2f} instance and want to convert * have a {@link Vec2f} and to convert it
* it to a String. You can do that by using * to a String, which you can do with
* {@link Vec2f}'s {@link Vec2f#toString()} * {@link Vec2f#toString()}. With this flag
* method. With this flag disabled it will * disabled it would return
* return * {@code de.staropensource.engine.base.types.vectors.}{@link Vec2i}{@code (x=64 y=64)},
* {@code de.staropensource.engine.base.types.vectors.}{@link Vec2i}{@code (x=64 y=64)}. * with it however it would just return
* With this flag enabled however the method will return
* {@link Vec2i}{@code (x=64 y=64)}, * {@link Vec2i}{@code (x=64 y=64)},
* which is much smaller. * which is much smaller.
* *
* @since v1-alpha2 * @since v1-alpha2
* -- GETTER -- * -- GETTER --
* Returns if to truncate the full path * Gets the value for {@link #hideFullTypePath}.
* of a class when invoking using their
* {@link #toString()} method.
* <p>
* Here's an example: Lets say that you have a
* {@link Vec2f} instance and want to convert
* it to a String. You can do that by using
* {@link Vec2f}'s {@link Vec2f#toString()}
* method. With this flag disabled it will
* return
* {@code de.staropensource.engine.base.types.vectors.}{@link Vec2i}{@code (x=64 y=64)}.
* With this flag enabled however the method will return
* {@link Vec2i}{@code (x=64 y=64)},
* which is much smaller.
* *
* @return truncate class paths? * @return variable value
* @see #hideFullTypePath
* @since v1-alpha2 * @since v1-alpha2
*/ */
private boolean hideFullTypePath; private boolean hideFullTypePath;

View file

@ -30,7 +30,8 @@ tasks.register("javadocAll", Javadoc) {
":base", ":base",
":ansi", ":ansi",
":slf4j-compat", ":slf4j-compat",
":rendering", ":windowing",
":windowing:glfw",
":notification", ":notification",
] ]

View file

@ -78,7 +78,7 @@ This avoids unnecessary bloat, having too many dependencies in your project whil
size and memory footprint of your project. size and memory footprint of your project.
## Official subsystems ## Official subsystems
Besides the `base` engine, there are two stable subsystem and two experimental subsystems. Besides the `base` engine, there are two stable subsystem and three experimental subsystems.
There may be other subsystems out there. Please note though that they are not maintained There may be other subsystems out there. Please note though that they are not maintained
by the StarOpenSource Project directly and are not automatically updated with the engine. by the StarOpenSource Project directly and are not automatically updated with the engine.
@ -86,7 +86,8 @@ by the StarOpenSource Project directly and are not automatically updated with th
- [`ansi`](https://git.staropensource.de/StarOpenSource/Engine/src/branch/develop/ansi): Provides an ANSI logger and a ShortcodeParserSkeleton implementation for all your terminal formatting needs - [`ansi`](https://git.staropensource.de/StarOpenSource/Engine/src/branch/develop/ansi): Provides an ANSI logger and a ShortcodeParserSkeleton implementation for all your terminal formatting needs
- [`slf4j-compat`](https://git.staropensource.de/StarOpenSource/Engine/src/branch/develop/slf4j-compat): Provides a [SLF4J](https://slf4j.org/) compatibility logger for redirecting all log calls to the engine's logging system - [`slf4j-compat`](https://git.staropensource.de/StarOpenSource/Engine/src/branch/develop/slf4j-compat): Provides a [SLF4J](https://slf4j.org/) compatibility logger for redirecting all log calls to the engine's logging system
### Experimental ### Experimental
- [`rendering`](https://git.staropensource.de/StarOpenSource/Engine/src/branch/develop/rendering): Provides an API for creating, managing and rendering windows - [`windowing`](https://git.staropensource.de/StarOpenSource/Engine/src/branch/develop/windowing): Provides abstract APIs for creating and managing windows as well as monitors
- [`windowing-glfw`](https://git.staropensource.de/StarOpenSource/Engine/src/branch/develop/windowing/glfw): Windowing API; allows using [GLFW](https://glfw.org) for creating windows
- [`notification`](https://git.staropensource.de/StarOpenSource/Engine/src/branch/develop/notification): Provides an API for sending and receiving notifications inside a program - [`notification`](https://git.staropensource.de/StarOpenSource/Engine/src/branch/develop/notification): Provides an API for sending and receiving notifications inside a program
## API documentation ## API documentation

View file

@ -15,11 +15,11 @@
"typecheck": "tsc" "typecheck": "tsc"
}, },
"dependencies": { "dependencies": {
"@docusaurus/core": "3.6.1", "@docusaurus/core": "3.6.0",
"@docusaurus/plugin-client-redirects": "^3.6.1", "@docusaurus/plugin-client-redirects": "^3.6.0",
"@docusaurus/plugin-content-docs": "^3.6.1", "@docusaurus/plugin-content-docs": "^3.6.0",
"@docusaurus/plugin-sitemap": "^3.6.1", "@docusaurus/plugin-sitemap": "^3.6.0",
"@docusaurus/preset-classic": "3.6.1", "@docusaurus/preset-classic": "3.6.0",
"@mdx-js/react": "^3.0.1", "@mdx-js/react": "^3.0.1",
"clsx": "^2.1.0", "clsx": "^2.1.0",
"prism-react-renderer": "^2.3.1", "prism-react-renderer": "^2.3.1",
@ -27,9 +27,9 @@
"react-dom": "^18.2.0" "react-dom": "^18.2.0"
}, },
"devDependencies": { "devDependencies": {
"@docusaurus/module-type-aliases": "3.6.1", "@docusaurus/module-type-aliases": "3.6.0",
"@docusaurus/tsconfig": "3.6.1", "@docusaurus/tsconfig": "3.6.0",
"@docusaurus/types": "3.6.1", "@docusaurus/types": "3.6.0",
"@types/node": "^20.12.5", "@types/node": "^20.12.5",
"typescript": "~5.4.4" "typescript": "~5.4.4"
}, },

View file

@ -21,7 +21,7 @@
versioningCodename=Sugarcookie versioningCodename=Sugarcookie
versioningVersion=1 versioningVersion=1
versioningType=alpha versioningType=alpha
versioningTyperelease=9 versioningTyperelease=8
versioningFork= versioningFork=
# Java # Java

View file

@ -1,323 +0,0 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.engine.rendering;
import de.staropensource.engine.base.annotation.EngineSubsystem;
import de.staropensource.engine.base.annotation.EventListener;
import de.staropensource.engine.base.implementable.SubsystemClass;
import de.staropensource.engine.base.implementable.helper.EventHelper;
import de.staropensource.engine.base.logging.Logger;
import de.staropensource.engine.base.type.EventPriority;
import de.staropensource.engine.base.utility.Math;
import de.staropensource.engine.base.utility.information.EngineInformation;
import de.staropensource.engine.base.implementation.versioning.StarOpenSourceVersioningSystem;
import de.staropensource.engine.base.event.InternalEngineShutdownEvent;
import de.staropensource.engine.base.type.DependencyVector;
import de.staropensource.engine.base.utility.Miscellaneous;
import de.staropensource.engine.rendering.event.InputEvent;
import de.staropensource.engine.rendering.event.RenderingErrorEvent;
import de.staropensource.engine.rendering.exception.NotOnMainThreadException;
import de.staropensource.engine.rendering.type.Window;
import de.staropensource.engine.rendering.type.window.VsyncMode;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.*;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.concurrent.atomic.AtomicReference;
import static org.lwjgl.glfw.GLFW.*;
/**
* Main class of the {@code rendering} subsystem.
*
* @since v1-alpha9
*/
@EngineSubsystem
@SuppressWarnings({ "JavadocDeclaration" })
public final class RenderingSubsystem extends SubsystemClass {
/**
* Contains the class instance.
*
* @since v1-alpha9
* -- GETTER --
* Returns the class instance.
*
* @return class instance unless the subsystem is uninitialized
* @since v1-alpha9
*/
@Getter
private static RenderingSubsystem instance = null;
/**
* The {@link GLFWErrorCallback} to use.
* <p>
* Only declared publicly for freeing during engine shutdown.
*
* @since v1-alpha2
*/
private GLFWErrorCallback errorCallback = null;
// -----> Subsystem
/**
* Initializes this subsystem.
*
* @since v1-alpha9
*/
public RenderingSubsystem() {
// Only allow one instance
if (instance == null)
instance = this;
else
Logger.crash("Only one instance of this class is allowed, use getInstance() instead of creating a new instance");
}
/** {@inheritDoc} */
@Override
public @NotNull String getName() {
return "rendering";
}
/** {@inheritDoc} */
@Override
public @NotNull DependencyVector getDependencyVector() {
return new DependencyVector.Builder()
.setIdentifier(getName())
.setVersioningSystem(StarOpenSourceVersioningSystem.class)
.setVersion(EngineInformation.getVersioningString())
.build();
}
/** {@inheritDoc} */
@Override
public void initializeSubsystem() {
if (!Miscellaneous.onMainThread())
Logger.crash("Unable to initialize the rendering subsystem whilst running on a non-main thread", new NotOnMainThreadException());
// Initialize WindowingSubsystemConfiguration and load it
new RenderingSubsystemConfiguration().loadConfiguration();
// Precompute event listeners
cacheEvents();
initGlfw();
// Warn about subsystem and API instability
Logger.warn("The rendering subsystem is experimental. Subsystem and API stability are not guaranteed.");
}
/**
* Caches all windowing subsystem events.
*
* @since v1-alpha9
*/
private void cacheEvents() {
EventHelper.cacheEvent(RenderingErrorEvent.class);
EventHelper.cacheEvent(InputEvent.class);
}
/**
* Initializes GLFW.
*
* @since v1-alpha9
*/
private void initGlfw() {
try {
Logger.verb("Initializing GLFW");
// Set error callback
Logger.diag("Setting error callback");
errorCallback = GLFWErrorCallback.create((error, description) -> new RenderingErrorEvent().callEvent("GLFW: " + GLFWErrorCallback.getDescription(description) + " [" + error + "]")).set();
// Set init hints
Logger.diag("Setting initialization hints");
switch (RenderingSubsystemConfiguration.getInstance().getInitialPlatform()) {
case ANY -> glfwInitHint(GLFW_PLATFORM, GLFW_ANY_PLATFORM);
case WAYLAND -> tryPlatform(GLFW_PLATFORM_WAYLAND);
case X11 -> tryPlatform(GLFW_PLATFORM_X11);
case WIN32 -> tryPlatform(GLFW_PLATFORM_WIN32);
case COCOA -> tryPlatform(GLFW_PLATFORM_COCOA);
case NONE -> glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_NULL);
}
glfwInitHint(GLFW_WAYLAND_LIBDECOR, RenderingSubsystemConfiguration.getInstance().isInitialDisableLibdecor() ? GLFW_WAYLAND_DISABLE_LIBDECOR : GLFW_WAYLAND_PREFER_LIBDECOR);
// Initialize GLFW
Logger.diag("Invoking glfwInit");
if (!glfwInit())
Logger.crash("Failed to initialize GLFW");
} catch (UnsatisfiedLinkError error) {
Logger.crash("Failed to load LWJGL native libraries", error);
}
}
/**
* Shuts the subsystem down.
*
* @since v1-alpha9
*/
@EventListener(event = InternalEngineShutdownEvent.class)
@SuppressWarnings({ "unused" })
protected static void shutdownSubsystem() {
if (instance == null)
return;
Logger.verb("Shutting down");
long shutdownTime = Miscellaneous.measureExecutionTime(() -> {
// Close all windows
for (Window window : Window.getWindows())
window.close();
instance.errorCallback.free();
glfwTerminate();
});
Logger.info("Shut down in " + shutdownTime + "ms");
}
/**
* Logs about rendering errors.
*
* @see RenderingSubsystemConfiguration#errorRenderingFailures
* @since v1-alpha9
*/
@EventListener(event = RenderingErrorEvent.class, priority = EventPriority.EXCLUSIVELY_IMPORTANT)
private static void logRenderingError(@NotNull String error) {
Logger.error("Rendering error occurred: " + error);
}
// -----> APIs
/**
* Renders all windows once.
* To render all windows continuously, invoke
* {@link #runRenderLoop(Runnable)} instead.
*
* @return map of windows and their {@link Throwable}s
* @throws NotOnMainThreadException if not running on the main thread
* @since v1-alpha9
*/
public LinkedHashMap<@NotNull Window, @NotNull Throwable> renderWindows() throws NotOnMainThreadException {
// Ensure running on the main thread
if (!Miscellaneous.onMainThread())
throw new NotOnMainThreadException();
LinkedHashMap<@NotNull Window, @NotNull Throwable> throwables = new LinkedHashMap<>();
// Update and render all windows
for (Window window : Window.getWindows()) {
if (!window.isRendering())
continue;
try {
window.updateState();
window.render();
} catch (Throwable throwable) {
Logger.error("Rendering window " + window + " failed: Threw throwable " + throwable.getClass().getName() + (throwable.getMessage() == null ? "" : ": " + throwable.getMessage()));
throwables.put(window, throwable);
}
}
// Poll for events
glfwPollEvents();
return throwables;
}
/**
* Renders all windows continuously.
* To render all windows just once, invoke
* {@link #renderWindows()} instead.
* <p>
* Immediately returns when a {@link #renderWindows()} call fails.
*
* @param frameCode code which shall be invoked before a frame is rendered
* @return see {@link #renderWindows()} (on failure)
* @throws NotOnMainThreadException if not running on the main thread
* @since v1-alpha9
*/
public LinkedHashMap<@NotNull Window, @NotNull Throwable> runRenderLoop(@NotNull Runnable frameCode) throws NotOnMainThreadException {
// Ensure running on the main thread
if (!Miscellaneous.onMainThread())
throw new NotOnMainThreadException();
// Define variables
AtomicReference<LinkedHashMap<@NotNull Window, @NotNull Throwable>> output = new AtomicReference<>(new LinkedHashMap<>()); // runRenderLoop output
long renderTime; // Amount of time spent rendering
long sleepDuration; // Time spent sleeping the thread
LinkedList<Long> splitDeltaTime = new LinkedList<>(); // Used for calculating the delta time (render time average over one second)
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 (!RenderingSubsystemConfiguration.getInstance().isDebugFrames())
reportDuration = Long.MAX_VALUE;
// Run while the 'output' is empty
while (output.get().isEmpty()) {
renderTime = Miscellaneous.measureExecutionTime(() -> {
output.set(renderWindows());
frameCode.run();
});
if (RenderingSubsystemConfiguration.getInstance().getVsyncMode() != VsyncMode.OFF)
// V-Sync is enabled, no need for manual busy waiting
sleepDuration = 0L;
else
// Calculate amount of time the thread should spend sleeping
sleepDuration = (long) (1d / RenderingSubsystemConfiguration.getInstance().getMaximumFramesPerSecond() * 1000d) - renderTime;
// Add render and sleep time to list used for calculating the delta time value
splitDeltaTime.add(renderTime + sleepDuration);
// Busy wait unless V-Sync is enabled
if (RenderingSubsystemConfiguration.getInstance().getVsyncMode() == VsyncMode.OFF && RenderingSubsystemConfiguration.getInstance().getMaximumFramesPerSecond() >= 1) {
sleepDuration += System.currentTimeMillis();
while (System.currentTimeMillis() < sleepDuration)
Thread.onSpinWait();
}
// Calculate delta time and frame count every second
if (System.currentTimeMillis() >= reportDuration) {
deltaTime = Math.getMeanLong(splitDeltaTime); // Calculate delta time
Logger.diag("Delta time average: " + deltaTime + " | Frames/s: " + 1000 / deltaTime); // Print delta time and frame count to console
reportDuration = System.currentTimeMillis() + 1000; // Update 'reportDuration'
splitDeltaTime.clear(); // Clear 'splitDeltaTime' list
}
}
return output.get();
}
// -----> Utility methods
/**
* Checks if the specified platform is compatible,
* and if so, specifies it as the platform to use.
*
* @param platform platform to try
* @since v1-alpha9
*/
private void tryPlatform(int platform) {
if (glfwPlatformSupported(platform))
glfwInitHint(GLFW_PLATFORM, platform);
else
glfwInitHint(GLFW_PLATFORM, GLFW_ANY_PLATFORM);
}
}

View file

@ -1,311 +0,0 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.engine.rendering;
import de.staropensource.engine.base.implementable.Configuration;
import de.staropensource.engine.base.logging.Logger;
import de.staropensource.engine.base.utility.PropertiesReader;
import de.staropensource.engine.rendering.event.RenderingErrorEvent;
import de.staropensource.engine.rendering.type.window.RenderingPlatform;
import de.staropensource.engine.rendering.type.window.VsyncMode;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Provides the configuration for the rendering subsystem.
*
* @since v1-alpha9
*/
@Getter
@SuppressWarnings({ "JavadocDeclaration" })
public final class RenderingSubsystemConfiguration extends Configuration {
/**
* Contains the class instance.
*
* @since v1-alpha9
* -- GETTER --
* Returns the class instance.
*
* @return class instance unless {@link RenderingSubsystem} is uninitialized
* @since v1-alpha9
*/
@Getter
private static RenderingSubsystemConfiguration instance;
/**
* Contains the configuration prefix.
*
* @since v1-alpha9
* -- GETTER --
* Returns the configuration prefix.
*
* @return property group
* @since v1-alpha9
*/
@Getter
public final @NotNull String group = "sosengine.rendering.";
/**
* Contains if debugging options should be allowed.
* All debugging options will be forcefully set to
* {@code false} if this option is set to {@code false}.
*
* @since v1-alpha9
* -- GETTER --
* Returns if debugging options should be allowed.
* All debugging options will be forcefully set to
* {@code false} if this option is set to {@code false}.
*
* @return debugging enabled?
* @since v1-alpha9
*/
private boolean debug;
/**
* Contains whether or not key presses
* and releases should be logged.
*
* @since v1-alpha9
* -- GETTER --
* Returns whether or not key presses
* and releases should be logged.
*
* @return log key presses and releases?
* @since v1-alpha9
*/
private boolean debugInput;
/**
* Contains whether or not the delta time and
* FPS count should be logged to the console
* every second.
* <p>
* Changes will no longer be picked up as
* soon as the rendering loop is running.
*
* @since v1-alpha9
* -- GETTER --
* Returns whether or not the delta time and
* FPS count should be logged to the console
* every second.
* <p>
* Changes will no longer be picked up as
* soon as the rendering loop is running.
*
* @return print delta time and FPS count?
* @since v1-alpha9
*/
private boolean debugFrames;
/**
* Contains the platform GLFW shall try initialising.
*
* @since v1-alpha9
* -- GETTER --
* Returns the platform GLFW shall try initialising.
*
* @return GLFW platform
* @since v1-alpha9
*/
private RenderingPlatform initialPlatform;
/**
* Contains whether or not to disable support for
* <a href="https://gitlab.freedesktop.org/libdecor/libdecor">libdecor</a>.
* <p>
* Only affects the {@link RenderingPlatform#WAYLAND} platform.
*
* @since v1-alpha9
* -- GETTER --
* Returns whether or not to disable support for
* <a href="https://gitlab.freedesktop.org/libdecor/libdecor">libdecor</a>.
* <p>
* Only affects the {@link RenderingPlatform#WAYLAND} platform.
*
* @return libdecor support disabled?
* @since v1-alpha9
*/
private boolean initialDisableLibdecor;
/**
* Contains whether or not rendering
* errors should be logged.
* <p>
* The {@link RenderingErrorEvent} will
* be emitted anyway, regardless of the
* value of this variable.
*
* @see RenderingErrorEvent
* @since v1-alpha9
* -- GETTER --
* Returns whether or not rendering
* errors should be logged.
* <p>
* The {@link RenderingErrorEvent} will
* be emitted anyway, regardless of the
* value of this variable.
*
* @return log rendering failures?
* @see RenderingErrorEvent
* @since v1-alpha9
*/
private boolean errorRenderingFailures;
/**
* Contains which {@link VsyncMode} to use.
* <p>
* This setting determines if and how V-Sync
* will operate, which (if enabled) tries to
* synchronize the frame rate to the monitor's
* refresh rate. See {@link VsyncMode}
* for more information.
*
* @see VsyncMode
* @since v1-alpha9
* -- GETTER --
* Returns which {@link VsyncMode} to use.
* <p>
* This setting determines if and how V-Sync
* will operate, which (if enabled) tries to
* synchronize the frame rate to the monitor's
* refresh rate. See {@link VsyncMode}
* for more information.
*
* @return active V-Sync mode
* @see VsyncMode
* @since v1-alpha9
*/
private VsyncMode vsyncMode;
/**
* Contains the maximum value of frames
* which can be rendered per second.
* <p>
* This value will have no effect on
* windows with V-Sync enabled.
* Set to {@code 0} for effectively
* no limit. Not recommended.
*
* @since v1-alpha9
* -- GETTER --
* Returns the maximum value of frames
* which can be rendered per second.
* <p>
* This value will have no effect on
* windows with V-Sync enabled.
* Set to {@code 0} for effectively
* no limit. Not recommended.
*
* @return maximum amount of frames per second
* @since v1-alpha9
*/
private int maximumFramesPerSecond;
/**
* Creates and initializes an instance of this class.
*
* @see RenderingSubsystem
* @since v1-alpha9
*/
RenderingSubsystemConfiguration() {
instance = this;
loadDefaultConfiguration();
}
/** {@inheritDoc} */
@Override
protected void matchProperty(@NotNull PropertiesReader parser, @NotNull String property) {
switch (property) {
case "debug" -> debug = parser.getBoolean(group + property);
case "debugInput" -> debugInput = parser.getBoolean(group + property);
case "debugFrames" -> debugFrames = parser.getBoolean(group + property);
case "initialPlatform" -> {
try {
initialPlatform = RenderingPlatform.valueOf(parser.getString(group + property).toUpperCase());
} catch (IllegalArgumentException ignored) {
Logger.error("Platform " + parser.getString(group + property) + " is not valid");
}
}
case "initialDisableLibdecor" -> initialDisableLibdecor = parser.getBoolean(group + property);
case "errorRenderingFailures" -> errorRenderingFailures = parser.getBoolean(group + property);
case "vsyncMode" -> {
try {
vsyncMode = VsyncMode.valueOf(parser.getString(group + property).toUpperCase());
} catch (IllegalArgumentException exception) {
Logger.error("V-Sync mode " + parser.getString(group + property) + " is not valid");
}
}
case "maximumFramesPerSecond" -> maximumFramesPerSecond = parser.getInteger(group + property, true);
}
}
/** {@inheritDoc} */
@Override
protected void processSettings(@NotNull PropertiesReader parser) {
// Disable all debug options if 'debug' is disabled
if (!debug) {
debugInput = false;
debugFrames = false;
}
}
/** {@inheritDoc} */
@Override
public void loadDefaultConfiguration() {
debug = false;
debugInput = false;
debugFrames = false;
initialPlatform = RenderingPlatform.ANY;
initialDisableLibdecor = false;
errorRenderingFailures = true;
vsyncMode = VsyncMode.ON;
maximumFramesPerSecond = 60;
}
/** {@inheritDoc} */
@Override
public @Nullable Object getSetting(@NotNull String setting) {
switch (setting) {
case "debug" -> { return debug; }
case "debugInput" -> { return debugInput; }
case "debugFrames" -> { return debugFrames; }
case "initialPlatform" -> { return initialPlatform; }
case "disableLibdecor" -> { return initialDisableLibdecor; }
case "errorRenderingFailures" -> { return errorRenderingFailures; }
case "vsyncMode" -> { return vsyncMode; }
case "maximumFramesPerSecond" -> { return maximumFramesPerSecond; }
default -> { return null; }
}
}
}

View file

@ -1,33 +0,0 @@
/**
* The {@code rendering} subsystem, responsible for
* initializing and managing windows and rendering APIs.
*
* @since v1-alpha9
*/
module sosengine.rendering {
// Dependencies
// -> Engine
requires transitive sosengine.base;
// -> Libraries
requires transitive static lombok;
requires transitive org.jetbrains.annotations;
requires org.lwjgl.stb;
requires org.lwjgl.glfw;
requires org.lwjgl.bgfx;
// API access
exports de.staropensource.engine.rendering;
exports de.staropensource.engine.rendering.event;
exports de.staropensource.engine.rendering.exception;
exports de.staropensource.engine.rendering.type;
exports de.staropensource.engine.rendering.type.input;
exports de.staropensource.engine.rendering.type.window;
// Reflection access
opens de.staropensource.engine.rendering;
opens de.staropensource.engine.rendering.event;
opens de.staropensource.engine.rendering.exception;
opens de.staropensource.engine.rendering.type;
opens de.staropensource.engine.rendering.type.input;
opens de.staropensource.engine.rendering.type.window;
}

View file

@ -17,12 +17,13 @@
* 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.setName("sos!engine") rootProject.setName("sosengine")
include("base") include("base")
include("testing") include("testing")
include("ansi") include("ansi")
include("slf4j-compat") include("slf4j-compat")
include("notification") include("notification")
include("rendering") include("windowing")
include("windowing:glfw")
include("testapp") include("testapp")

View file

@ -39,9 +39,10 @@ dependencies {
// Project // Project
implementation(project(":base")) implementation(project(":base"))
implementation(project(":rendering")) implementation(project(":windowing"))
runtimeOnly(project(":ansi")) runtimeOnly(project(":ansi"))
runtimeOnly(project(":slf4j-compat")) runtimeOnly(project(":slf4j-compat"))
runtimeOnly(project(":windowing:glfw"))
} }
// Fix delombok task // Fix delombok task

View file

@ -26,11 +26,11 @@ import de.staropensource.engine.base.implementable.helper.EventHelper;
import de.staropensource.engine.base.logging.Logger; import de.staropensource.engine.base.logging.Logger;
import de.staropensource.engine.base.type.vector.Vec2i; import de.staropensource.engine.base.type.vector.Vec2i;
import de.staropensource.engine.base.utility.Miscellaneous; import de.staropensource.engine.base.utility.Miscellaneous;
import de.staropensource.engine.rendering.RenderingSubsystem; import de.staropensource.engine.windowing.WindowingSubsystem;
import de.staropensource.engine.rendering.event.InputEvent; import de.staropensource.engine.windowing.event.InputEvent;
import de.staropensource.engine.rendering.type.Window; import de.staropensource.engine.windowing.implementable.Window;
import de.staropensource.engine.rendering.type.input.Key; import de.staropensource.engine.windowing.type.input.Key;
import de.staropensource.engine.rendering.type.input.KeyState; import de.staropensource.engine.windowing.type.input.KeyState;
import lombok.Getter; import lombok.Getter;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -119,6 +119,10 @@ public final class Main {
// Say hello to the world! // Say hello to the world!
Logger.info("Hello world!"); Logger.info("Hello world!");
// Choose windowing API to use
if (!WindowingSubsystem.getInstance().setApi())
Logger.crash("No windowing API is compatible");
// Create window // Create window
Window window; Window window;
try { try {
@ -135,13 +139,12 @@ public final class Main {
return; return;
} }
if (window == null)
Logger.crash("'window' is null");
// Render loop // Render loop
LinkedHashMap<@NotNull Window, @NotNull Throwable> renderLoopFailures = RenderingSubsystem LinkedHashMap<@NotNull Window, @NotNull Throwable> renderLoopFailures = WindowingSubsystem
.getInstance() .getInstance()
.runRenderLoop(() -> { .getApi()
.getManagement()
.runRenderLoopContinuously(() -> {
if (shutdown || window.isClosureRequested()) if (shutdown || window.isClosureRequested())
Engine.getInstance().shutdown(); Engine.getInstance().shutdown();
}); });

View file

@ -7,5 +7,5 @@
open module sosengine.testapp { open module sosengine.testapp {
// Dependencies // Dependencies
// -> Engine // -> Engine
requires sosengine.rendering; requires sosengine.windowing;
} }

109
windowing/build.gradle Normal file
View file

@ -0,0 +1,109 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// Plugins
plugins {
id("java")
id("io.freefair.lombok") version("${pluginLombok}")
id("maven-publish")
}
// Dependencies
dependencies {
// Lombok
compileOnly("org.projectlombok:lombok:${dependencyLombok}")
annotationProcessor("org.projectlombok:lombok:${dependencyLombok}")
// JetBrains Annotations
compileOnly("org.jetbrains:annotations:${dependencyJetbrainsAnnotations}")
// Project
implementation(project(":base"))
}
// Javadoc configuration
javadoc {
outputs.upToDateWhen { false } // Force task execution
dependsOn(delombok) // Make sure the source is delomboked first
javadoc {
setClasspath(files(project.sourceSets.main.compileClasspath)) // Include dependencies
options {
if (new File(projectDir, "src/main/javadoc/theme.css").exists())
stylesheetFile = new File(projectDir, "src/main/javadoc/theme.css") // Theming is cool :3
setMemberLevel(JavadocMemberLevel.PUBLIC) // Only display public stuff
setOverview("src/main/javadoc/overview.html") // We want a custom overview page to greet the visitor
setLocale("en_US") //
addStringOption("Xwerror", "-quiet") // Fail build on warning
setJFlags([
"-Duser.language=en_US" // See above
])
}
}
}
// Include javadoc and source jar during publishing
java {
withJavadocJar()
withSourcesJar()
}
// Build publishing configuration
// Note: You can safely ignore any errors or warnings thrown by your IDE here
publishing {
repositories {
maven {
name = "staropensource"
url = uri("https://mvn.staropensource.de/engine")
credentials(org.gradle.api.credentials.PasswordCredentials)
authentication {
//noinspection GroovyAssignabilityCheck
basic (BasicAuthentication)
}
}
}
publications {
//noinspection GroovyAssignabilityCheck
maven (MavenPublication) {
groupId = group
artifactId = project.getName()
version = version
//noinspection GroovyAssignabilityCheck
from components.java
}
}
}
// Fix delombok task
delombok.doFirst {
File target = file("${project.projectDir}/src/main/module-info.java")
File source = file("${project.projectDir}/src/main/java/module-info.java")
target.delete()
source.renameTo(target)
}
delombok.doLast {
File target = file("${project.projectDir}/src/main/java/module-info.java")
File source = file("${project.projectDir}/src/main/module-info.java")
target.delete()
source.renameTo(target)
}

2
windowing/glfw/README.md Normal file
View file

@ -0,0 +1,2 @@
# The `glfw` subsystem
This subsystem provides a Windowing API using [LWJGL](https://lwjgl.org)'s [GLFW](https://glfw.org) bindings.

View file

@ -61,17 +61,16 @@ dependencies {
// LWJGL // LWJGL
implementation(platform("org.lwjgl:lwjgl-bom:${dependencyLwjgl}")) implementation(platform("org.lwjgl:lwjgl-bom:${dependencyLwjgl}"))
implementation("org.lwjgl:lwjgl") implementation("org.lwjgl:lwjgl")
implementation("org.lwjgl:lwjgl-stb")
implementation("org.lwjgl:lwjgl-glfw") implementation("org.lwjgl:lwjgl-glfw")
implementation("org.lwjgl:lwjgl-bgfx") implementation("org.lwjgl:lwjgl-stb")
runtimeOnly("org.lwjgl:lwjgl::${dependencyLwjglNatives}") runtimeOnly("org.lwjgl:lwjgl::${dependencyLwjglNatives}")
runtimeOnly("org.lwjgl:lwjgl-stb::${dependencyLwjglNatives}")
runtimeOnly("org.lwjgl:lwjgl-glfw::${dependencyLwjglNatives}") runtimeOnly("org.lwjgl:lwjgl-glfw::${dependencyLwjglNatives}")
runtimeOnly("org.lwjgl:lwjgl-bgfx::${dependencyLwjglNatives}") runtimeOnly("org.lwjgl:lwjgl-stb::${dependencyLwjglNatives}")
if (project.dependencyLwjglNatives == "natives-macos" || project.dependencyLwjglNatives == "natives-macos-arm64") runtimeOnly("org.lwjgl:lwjgl-vulkan::${dependencyLwjglNatives}") if (project.dependencyLwjglNatives == "natives-macos" || project.dependencyLwjglNatives == "natives-macos-arm64") runtimeOnly("org.lwjgl:lwjgl-vulkan::${dependencyLwjglNatives}")
// Project // Project
implementation(project(":base")) implementation(project(":base"))
implementation(project(":windowing"))
} }
// Javadoc configuration // Javadoc configuration
@ -97,6 +96,26 @@ javadoc {
} }
} }
// Unit testing configuration
test {
useJUnitPlatform()
// Pass test configuration to test VMs
Map<String, String> testConfiguration = new HashMap<>()
for (String property : project.properties.keySet())
if (property.startsWith("test."))
testConfiguration.put(property, project.properties.get(property).toString())
systemProperties(testConfiguration)
setMaxParallelForks(project.hasProperty("jobs") ? Integer.parseInt((String) project.property("jobs")) : 8)
setForkEvery(1)
setFailFast(true)
testLogging {
events("passed", "skipped", "failed")
}
}
// Include javadoc and source jar during publishing // Include javadoc and source jar during publishing
java { java {
withJavadocJar() withJavadocJar()

1
windowing/glfw/gradle Symbolic link
View file

@ -0,0 +1 @@
../../gradle

1
windowing/glfw/gradlew vendored Symbolic link
View file

@ -0,0 +1 @@
../../gradlew

1
windowing/glfw/gradlew.bat vendored Symbolic link
View file

@ -0,0 +1 @@
../../gradlew.bat

View file

@ -0,0 +1,218 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.engine.windowing.glfw;
import de.staropensource.engine.base.annotation.EngineSubsystem;
import de.staropensource.engine.base.logging.Logger;
import de.staropensource.engine.base.utility.information.EngineInformation;
import de.staropensource.engine.base.implementation.versioning.StarOpenSourceVersioningSystem;
import de.staropensource.engine.base.type.DependencyVector;
import de.staropensource.engine.base.utility.Miscellaneous;
import de.staropensource.engine.windowing.WindowingSubsystem;
import de.staropensource.engine.windowing.implementable.api.ApiClass;
import de.staropensource.engine.windowing.implementable.api.ApiInternalClass;
import de.staropensource.engine.windowing.implementable.api.ApiManagementClass;
import de.staropensource.engine.windowing.event.WindowingErrorEvent;
import de.staropensource.engine.windowing.exception.NotOnMainThreadException;
import de.staropensource.engine.windowing.glfw.implementation.GlfwInternalClass;
import de.staropensource.engine.windowing.glfw.implementation.GlfwManagementClass;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.glfw.GLFWErrorCallbackI;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import static org.lwjgl.glfw.GLFW.*;
/**
* The main class of the GLFW subsystem.
*
* @since v1-alpha2
*/
@EngineSubsystem
@SuppressWarnings({ "JavadocDeclaration" })
public final class GlfwSubsystem extends ApiClass {
/**
* Contains the class instance.
*
* @since v1-alpha0
* -- GETTER --
* Returns the class instance.
*
* @return class instance unless the subsystem is uninitialized
* @since v1-alpha0
*/
@Getter
private static GlfwSubsystem instance = null;
/**
* Contains the internal API class.
*
* @see ApiInternalClass
* @since v1-alpha4
* -- GETTER --
* {@inheritDoc}
*/
@Getter
private ApiInternalClass internalApi;
/**
* Contains the management class.
*
* @see ApiManagementClass
* @since v1-alpha4
* -- GETTER --
* {@inheritDoc}
*/
@Getter
private ApiManagementClass management;
/**
* The {@link GLFWErrorCallback} to use.
* <p>
* Only declared publicly for freeing during engine shutdown.
*
* @since v1-alpha2
*/
private GLFWErrorCallback errorCallback = null;
/**
* Initializes this subsystem.
*
* @since v1-alpha2
*/
public GlfwSubsystem() {
// Check if subsystem has already initialized
if (instance == null)
instance = this;
else
Logger.crash("The subsystem tried to initialize twice");
}
/** {@inheritDoc} */
@Override
public void initializeSubsystem() {
// Initialize configuration
new GlfwSubsystemConfiguration();
// Register API
WindowingSubsystem.getInstance().registerApi(this);
}
/** {@inheritDoc} */
@Override
public void initializeApi() {
Logger.verb("Initializing GLFW");
try {
if (!Miscellaneous.onMainThread()) {
Logger.crash("Unable to initialize GLFW on a non-main thread", new NotOnMainThreadException(), true);
return;
}
// Set error callback
errorCallback = GLFWErrorCallback.create(new GLFWErrorCallbackI() {
/**
* {@inheritDoc}
*/
@Override
public void invoke(int error, long description) {
new WindowingErrorEvent().callEvent(description + " (" + error + ")");
}
}).set();
// Set init hints
switch (GlfwSubsystemConfiguration.getInstance().getPlatform()) {
case ANY -> glfwInitHint(GLFW_PLATFORM, GLFW_ANY_PLATFORM);
case WAYLAND -> tryPlatform(GLFW_PLATFORM_WAYLAND);
case X11 -> tryPlatform(GLFW_PLATFORM_X11);
case WIN32 -> tryPlatform(GLFW_PLATFORM_WIN32);
case COCOA -> tryPlatform(GLFW_PLATFORM_COCOA);
case NONE -> glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_NULL);
}
glfwInitHint(GLFW_WAYLAND_LIBDECOR, GlfwSubsystemConfiguration.getInstance().isDisableLibdecor() ? GLFW_WAYLAND_DISABLE_LIBDECOR : GLFW_WAYLAND_PREFER_LIBDECOR);
// Initialize GLFW
if (!glfwInit())
Logger.crash("Failed to initialize GLFW");
// Initialize classes
internalApi = new GlfwInternalClass();
management = new GlfwManagementClass();
} catch (UnsatisfiedLinkError error) {
Logger.crash("Failed to load LWJGL native libraries", error);
}
}
/** {@inheritDoc} */
@Override
public void shutdownApi() {
Logger.verb("Terminating GLFW");
errorCallback.free();
if (Miscellaneous.onMainThread())
glfwTerminate();
else
Logger.crash("Unable to terminate GLFW on a non-main thread. Did you call Engine#shutdown or Logger#crash from another thread?", new NotOnMainThreadException(), true);
}
/** {@inheritDoc} */
@Override
public @NotNull String getName() {
return getApiName().toLowerCase(Locale.ROOT);
}
/** {@inheritDoc} */
@Override
public String getApiName() {
return "GLFW";
}
/** {@inheritDoc} */
@Override
public @NotNull DependencyVector getDependencyVector() {
Set<@NotNull String> dependencies = new HashSet<>();
dependencies.add("windowing");
return new DependencyVector.Builder()
.setIdentifier(getName())
.setVersioningSystem(StarOpenSourceVersioningSystem.class)
.setVersion(EngineInformation.getVersioningString())
.setDependencies(dependencies)
.build();
}
/**
* Checks if the specified platform is compatible,
* and if so, specifies it as the platform to use.
*
* @param platform platform to try
* @since v1-alpha2
*/
private void tryPlatform(int platform) {
if (glfwPlatformSupported(platform))
glfwInitHint(GLFW_PLATFORM, platform);
else
glfwInitHint(GLFW_PLATFORM, GLFW_ANY_PLATFORM);
}
}

View file

@ -0,0 +1,139 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.engine.windowing.glfw;
import de.staropensource.engine.base.implementable.Configuration;
import de.staropensource.engine.base.logging.Logger;
import de.staropensource.engine.base.utility.PropertiesReader;
import de.staropensource.engine.windowing.glfw.type.GlfwPlatform;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Provides the GLFW subsystem configuration.
*
* @since v1-alpha2
*/
@Getter
@SuppressWarnings({ "JavadocDeclaration" })
public final class GlfwSubsystemConfiguration extends Configuration {
/**
* Contains the class instance.
*
* @since v1-alpha2
* -- GETTER --
* Returns the class instance.
*
* @return class instance unless {@link GlfwSubsystem} is uninitialized
* @since v1-alpha2
*/
@Getter
private static GlfwSubsystemConfiguration instance;
/**
* Defines prefix properties must begin with.
*
* @since v1-alpha2
* -- GETTER --
* Returns prefix properties must begin with.
*
* @return property group
* @since v1-alpha2
*/
private final @NotNull String group = "sosengine.windowing.glfw.";
/**
* Contains the platform GLFW will try to initialize with.
*
* @since v1-alpha2
* -- GETTER --
* Gets the value for {@link #platform}.
*
* @return variable value
* @see #platform
* @since v1-alpha2
*/
private GlfwPlatform platform;
/**
* If {@code true}, will disable support for
* <a href="https://gitlab.freedesktop.org/libdecor/libdecor">libdecor</a>.
* <p>
* Only affects the {@link GlfwPlatform#WAYLAND} platform.
*
* @since v1-alpha2
* -- GETTER --
* Gets the value for {@link #disableLibdecor}.
*
* @return variable value
* @see #disableLibdecor
* @since v1-alpha2
*/
private boolean disableLibdecor;
/**
* Creates and initializes an instance of this class.
*
* @see GlfwSubsystem
* @since v1-alpha6
*/
GlfwSubsystemConfiguration() {
instance = this;
loadDefaultConfiguration();
}
/** {@inheritDoc} */
@Override
protected void matchProperty(@NotNull PropertiesReader parser, @NotNull String property) {
switch (property) {
case "platform" -> {
try {
platform = GlfwPlatform.valueOf(parser.getString(group + property).toUpperCase());
} catch (IllegalArgumentException ignored) {
Logger.error("Platform " + parser.getString(group + property) + " is not valid");
}
}
case "disableLibdecor" -> disableLibdecor = parser.getBoolean(group + property);
}
}
/** {@inheritDoc} */
@Override
protected void processSettings(@NotNull PropertiesReader parser) {}
/** {@inheritDoc} */
@Override
public void loadDefaultConfiguration() {
platform = GlfwPlatform.ANY;
disableLibdecor = false;
}
/** {@inheritDoc} */
@Override
public @Nullable Object getSetting(@NotNull String setting) {
return switch (setting) {
case "platform" -> platform;
case "disableLibdecor" -> disableLibdecor;
default -> null;
};
}
}

View file

@ -17,13 +17,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.staropensource.engine.rendering.callback; package de.staropensource.engine.windowing.glfw.callback;
import de.staropensource.engine.rendering.type.Window; import de.staropensource.engine.windowing.implementable.Window;
import de.staropensource.engine.rendering.event.InputEvent; import de.staropensource.engine.windowing.event.InputEvent;
import de.staropensource.engine.rendering.callback.WindowCallback; import de.staropensource.engine.windowing.glfw.implementable.WindowCallback;
import de.staropensource.engine.rendering.type.input.Key; import de.staropensource.engine.windowing.type.input.Key;
import de.staropensource.engine.rendering.type.input.KeyState; import de.staropensource.engine.windowing.type.input.KeyState;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFWKeyCallbackI; import org.lwjgl.glfw.GLFWKeyCallbackI;
@ -32,7 +32,7 @@ import static org.lwjgl.glfw.GLFW.*;
/** /**
* A {@link GLFWKeyCallbackI} implementation, which emits {@link InputEvent}. * A {@link GLFWKeyCallbackI} implementation, which emits {@link InputEvent}.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
public final class KeyCallback extends WindowCallback implements GLFWKeyCallbackI { public final class KeyCallback extends WindowCallback implements GLFWKeyCallbackI {
/** /**
@ -40,7 +40,7 @@ public final class KeyCallback extends WindowCallback implements GLFWKeyCallback
* and making too many allocations, which would potentially decrease * and making too many allocations, which would potentially decrease
* performance. * performance.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
private static final InputEvent event = new InputEvent(); private static final InputEvent event = new InputEvent();
@ -48,7 +48,7 @@ public final class KeyCallback extends WindowCallback implements GLFWKeyCallback
* Creates and initializes an instance of this class. * Creates and initializes an instance of this class.
* *
* @param window {@link Window} class * @param window {@link Window} class
* @since v1-alpha9 * @since v1-alpha2
*/ */
public KeyCallback(@NotNull Window window) { public KeyCallback(@NotNull Window window) {
super(window); super(window);

View file

@ -17,12 +17,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.staropensource.engine.rendering.callback; package de.staropensource.engine.windowing.glfw.callback;
import de.staropensource.engine.rendering.type.Window; import de.staropensource.engine.windowing.implementable.Window;
import de.staropensource.engine.rendering.event.InputEvent; import de.staropensource.engine.windowing.event.InputEvent;
import de.staropensource.engine.rendering.type.input.Key; import de.staropensource.engine.windowing.glfw.implementable.WindowCallback;
import de.staropensource.engine.rendering.type.input.KeyState; import de.staropensource.engine.windowing.type.input.Key;
import de.staropensource.engine.windowing.type.input.KeyState;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFWMouseButtonCallbackI; import org.lwjgl.glfw.GLFWMouseButtonCallbackI;
@ -31,7 +32,7 @@ import static org.lwjgl.glfw.GLFW.*;
/** /**
* A {@link GLFWMouseButtonCallbackI} implementation, which forward them to {@link InputEvent}. * A {@link GLFWMouseButtonCallbackI} implementation, which forward them to {@link InputEvent}.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
public final class MouseButtonCallback extends WindowCallback implements GLFWMouseButtonCallbackI { public final class MouseButtonCallback extends WindowCallback implements GLFWMouseButtonCallbackI {
/** /**
@ -39,7 +40,7 @@ public final class MouseButtonCallback extends WindowCallback implements GLFWMou
* and making too many allocations, which would potentially decrease * and making too many allocations, which would potentially decrease
* performance. * performance.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
private static final InputEvent event = new InputEvent(); private static final InputEvent event = new InputEvent();
@ -47,7 +48,7 @@ public final class MouseButtonCallback extends WindowCallback implements GLFWMou
* Creates and initializes an instance of this class. * Creates and initializes an instance of this class.
* *
* @param window {@link Window} class * @param window {@link Window} class
* @since v1-alpha9 * @since v1-alpha2
*/ */
public MouseButtonCallback(@NotNull Window window) { public MouseButtonCallback(@NotNull Window window) {
super(window); super(window);
@ -71,7 +72,7 @@ public final class MouseButtonCallback extends WindowCallback implements GLFWMou
case GLFW_MOUSE_BUTTON_RIGHT -> Key.MOUSE_RIGHT; case GLFW_MOUSE_BUTTON_RIGHT -> Key.MOUSE_RIGHT;
case GLFW_MOUSE_BUTTON_4, GLFW_MOUSE_BUTTON_5, case GLFW_MOUSE_BUTTON_4, GLFW_MOUSE_BUTTON_5,
GLFW_MOUSE_BUTTON_6, GLFW_MOUSE_BUTTON_7, GLFW_MOUSE_BUTTON_6, GLFW_MOUSE_BUTTON_7,
GLFW_MOUSE_BUTTON_8 -> Key.UNKNOWN_MOUSE_BUTTON; GLFW_MOUSE_BUTTON_8 -> Key.UNKNOWN_MOUSE;
default -> throw new IllegalStateException("Mouse button " + key + " is invalid"); default -> throw new IllegalStateException("Mouse button " + key + " is invalid");
}, },
// Key state // Key state

View file

@ -20,6 +20,6 @@
/** /**
* Callbacks, which emit {@link de.staropensource.engine.base.implementable.Event}s. * Callbacks, which emit {@link de.staropensource.engine.base.implementable.Event}s.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
package de.staropensource.engine.rendering.callback; package de.staropensource.engine.windowing.glfw.callback;

View file

@ -17,9 +17,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.staropensource.engine.rendering.callback; package de.staropensource.engine.windowing.glfw.implementable;
import de.staropensource.engine.rendering.type.Window; import de.staropensource.engine.windowing.implementable.Window;
import lombok.Getter; import lombok.Getter;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -27,7 +27,7 @@ import org.jetbrains.annotations.NotNull;
* Abstract class used for easily implementing * Abstract class used for easily implementing
* callbacks which require a {@link Window} instance. * callbacks which require a {@link Window} instance.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
@Getter @Getter
@SuppressWarnings({ "JavadocDeclaration" }) @SuppressWarnings({ "JavadocDeclaration" })
@ -36,13 +36,13 @@ public class WindowCallback {
* Refers to the {@link Window} instance * Refers to the {@link Window} instance
* this callback is tied to. * this callback is tied to.
* *
* @since v1-alpha9 * @since v1-alpha2
* -- GETTER -- * -- GETTER --
* Returns the {@link Window} instance * Returns the {@link Window} instance
* this callback is tied to. * this callback is tied to.
* *
* @return attached {@link Window} instance * @return attached {@link Window} instance
* @since v1-alpha9 * @since v1-alpha2
*/ */
private final @NotNull Window attachedWindow; private final @NotNull Window attachedWindow;
@ -50,7 +50,7 @@ public class WindowCallback {
* Creates and initializes an instance of this abstract class. * Creates and initializes an instance of this abstract class.
* *
* @param window {@link Window} class * @param window {@link Window} class
* @since v1-alpha9 * @since v1-alpha2
*/ */
public WindowCallback(@NotNull Window window) { public WindowCallback(@NotNull Window window) {
this.attachedWindow = window; this.attachedWindow = window;

View file

@ -0,0 +1,25 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Interfaces and abstract classes which can be used for implementing classes.
*
* @since v1-alpha6
*/
package de.staropensource.engine.windowing.glfw.implementable;

View file

@ -0,0 +1,82 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.engine.windowing.glfw.implementation;
import de.staropensource.engine.windowing.implementable.Monitor;
import de.staropensource.engine.windowing.implementable.api.ApiInternalClass;
import de.staropensource.engine.windowing.exception.NoMonitorsFoundException;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.PointerBuffer;
import java.util.LinkedHashSet;
import static org.lwjgl.glfw.GLFW.glfwGetMonitors;
/**
* The internal API class for GLFW-powered windowing APIs.
*
* @since v1-alpha2
*/
@Getter
@Setter
@SuppressWarnings({ "JavadocDeclaration" })
public final class GlfwInternalClass implements ApiInternalClass {
/**
* Contains a class which extends the {@link GlfwWindow} class.
*
* @since v1-alpha4
* -- GETTER --
* {@inheritDoc}
* -- SETTER --
* Sets a class which extends the {@link GlfwWindow} class.
*
* @param windowClass new window class
* @since v1-alpha4
*/
private @NotNull Class<? extends GlfwWindow> windowClass = GlfwWindow.class;
/**
* Creates and initializes an instance of this class.
*
* @since v1-alpha2
*/
public GlfwInternalClass() {}
/**
* Returns all connected monitors.
*
* @return connected monitors
* @since v1-alpha2
*/
@Override
public @NotNull LinkedHashSet<@NotNull Monitor> getMonitors() throws NoMonitorsFoundException {
PointerBuffer monitors = glfwGetMonitors();
LinkedHashSet<@NotNull Monitor> output = new LinkedHashSet<>();
if (monitors == null)
throw new NoMonitorsFoundException();
while (monitors.hasRemaining())
output.add(new GlfwMonitor(monitors.get()));
return output;
}
}

View file

@ -0,0 +1,92 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.engine.windowing.glfw.implementation;
import de.staropensource.engine.base.logging.Logger;
import de.staropensource.engine.base.utility.Miscellaneous;
import de.staropensource.engine.windowing.implementable.api.ApiManagementClass;
import de.staropensource.engine.windowing.implementable.Window;
import de.staropensource.engine.windowing.exception.NotOnMainThreadException;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import java.util.*;
import static org.lwjgl.glfw.GLFW.*;
/**
* The abstract management class for GLFW-powered windowing APIs.
*
* @since v1-alpha2
*/
@Getter
public final class GlfwManagementClass extends ApiManagementClass {
/**
* Creates and initializes an instance of this class.
*
* @since v1-alpha2
*/
public GlfwManagementClass() {}
/** {@inheritDoc} */
@Override
public boolean mustRunOnMainThread() {
return true;
}
/** {@inheritDoc} */
@Override
public @NotNull LinkedHashMap<@NotNull Window, @NotNull Throwable> runRenderLoop() {
// Ensure running on the main thread
if (!Miscellaneous.onMainThread())
throw new NotOnMainThreadException();
LinkedHashMap<@NotNull Window, @NotNull Throwable> throwables = new LinkedHashMap<>();
// Update and render all windows
for (Window window : Window.getWindows()) {
if (!window.isRendering())
continue;
try {
window.updateState();
window.render();
} catch (Throwable throwable) {
Logger.error("Rendering window " + window + " failed: Threw throwable " + throwable.getClass().getName() + (throwable.getMessage() == null ? "" : ": " + throwable.getMessage()));
throwables.put(window, throwable);
}
}
// Poll for events
glfwPollEvents();
return throwables;
}
/** {@inheritDoc} */
@Override
public @NotNull LinkedHashMap<@NotNull Window, @NotNull Throwable> runRenderLoopContinuously(@NotNull Runnable frameCode) {
// Ensure running on the main thread
if (!Miscellaneous.onMainThread())
throw new NotOnMainThreadException();
return super.runRenderLoopContinuously(frameCode);
}
}

View file

@ -0,0 +1,118 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.engine.windowing.glfw.implementation;
import de.staropensource.engine.base.type.vector.Vec2i;
import de.staropensource.engine.windowing.implementable.Monitor;
import de.staropensource.engine.windowing.exception.InvalidMonitorException;
import lombok.SneakyThrows;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFWVidMode;
import java.util.Objects;
import static org.lwjgl.glfw.GLFW.*;
/**
* Represents a monitor. A GLFW-powered monitor. Wait... aren't monitors powered by... power?
*
* @since v1-alpha2
*/
@SuppressWarnings({ "JavadocDeclaration" })
public final class GlfwMonitor extends Monitor {
/**
* Contains the {@link #identifier} as a long.
*
* @since v1-alpha2
* -- GETTER --
* Returns the monitor identifier as a long.
*
* @return monitor identifier as a long
* @since v1-alpha2
*/
private final long identifierLong;
/**
* Creates and initializes an instance of this class.
*
* @param identifier glfw monitor pointer
* @since v1-alpha2
*/
@SneakyThrows
public GlfwMonitor(long identifier) throws InvalidMonitorException {
// Set identifier
setIdentifier(String.valueOf(identifier));
identifierLong = identifier;
// Check if connected
checkConnected();
}
/** {@inheritDoc} */
@SneakyThrows
public void checkConnected() throws InvalidMonitorException {
super.checkConnected();
}
/** {@inheritDoc} */
@Override
public boolean isConnected() {
return glfwGetMonitorName(identifierLong) != null;
}
/**
* Returns the monitor name.
*
* @return monitor name
* @since v1-alpha2
*/
@Override
public @NotNull String getName() throws InvalidMonitorException {
checkConnected();
return Objects.requireNonNull(glfwGetMonitorName(identifierLong));
}
/**
* Returns the monitor size.
*
* @return monitor size
* @since v1-alpha2
*/
@Override
public @NotNull Vec2i getSize() throws InvalidMonitorException {
checkConnected();
GLFWVidMode videoMode = Objects.requireNonNull(glfwGetVideoMode(identifierLong));
return new Vec2i(videoMode.width(), videoMode.height());
}
/**
* Returns the monitor refresh rate.
*
* @return monitor refresh rate
* @since v1-alpha2
*/
@Override
public short getRefreshRate() throws InvalidMonitorException {
checkConnected();
return (short) Objects.requireNonNull(glfwGetVideoMode(identifierLong)).refreshRate();
}
}

View file

@ -0,0 +1,566 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.engine.windowing.glfw.implementation;
import de.staropensource.engine.base.logging.Logger;
import de.staropensource.engine.base.type.vector.Vec2i;
import de.staropensource.engine.base.utility.Miscellaneous;
import de.staropensource.engine.windowing.WindowingSubsystemConfiguration;
import de.staropensource.engine.windowing.event.InputEvent;
import de.staropensource.engine.windowing.event.RenderingErrorEvent;
import de.staropensource.engine.windowing.exception.NotOnMainThreadException;
import de.staropensource.engine.windowing.exception.WindowCreationFailureException;
import de.staropensource.engine.windowing.glfw.callback.KeyCallback;
import de.staropensource.engine.windowing.glfw.callback.MouseButtonCallback;
import de.staropensource.engine.windowing.implementable.Monitor;
import de.staropensource.engine.windowing.implementable.Window;
import de.staropensource.engine.windowing.type.window.VsyncMode;
import de.staropensource.engine.windowing.type.window.WindowMode;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFWImage;
import org.lwjgl.glfw.GLFWKeyCallback;
import org.lwjgl.glfw.GLFWMouseButtonCallback;
import org.lwjgl.stb.STBImage;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.system.MemoryUtil;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import static org.lwjgl.glfw.GLFW.*;
/**
* Abstract class for implementing GLFW-powered windows in a windowing API.
*
* @since v1-alpha2
*/
@SuppressWarnings({ "JavadocDeclaration" })
public final class GlfwWindow extends Window {
/**
* Contains the {@link #identifier} used by GLFW.
*
* @since v1-alpha2
* -- GETTER --
* Returns the window identifier used by GLFW.
*
* @return GLFW identifier
* @since v1-alpha2
*/
@Getter
private long identifierLong;
/**
* Contains the code to execute in {@link #render()}.
*
* @since v1-alpha8
* -- GETTER --
* Returns the code to execute in {@link #render()}.
*
* @return rendering code
* @since v1-alpha8
* -- SETTER --
* Sets the code to execute in {@link #render()}
*
* @param renderCode new rendering code
* @since v1-alpha8
*/
@Getter
@Setter
private @NotNull Runnable renderCode = () -> glfwSwapBuffers(identifierLong);
/**
* Contains the {@link GLFWKeyCallback} used for emitting {@link InputEvent}s.
*
* @since v1-alpha2
*/
private GLFWKeyCallback keyCallback;
/**
* Contains the {@link GLFWMouseButtonCallback} used for emitting {@link InputEvent}s.
*
* @since v1-alpha2
*/
private GLFWMouseButtonCallback mouseButtonCallback;
// ------------------------------------------------ [ Window (de)initialization ] ------------------------------------------------ //
/**
* Creates and initializes an instance of this class.
*
* @param name name
* @param title title
* @param icons icons
* @param size size
* @param minimumSize minimum size
* @param maximumSize maximum size
* @param position position
* @param windowMode window mode
* @param monitor monitor
* @param resizable resizable flag
* @param borderless borderless flag
* @param focusable focusable flag
* @param onTop on top flag
* @param transparent transparency flag
* @param rendering rendering flag
* @throws Exception stuff thrown by the {@link #initializeWindow()} and {@link #render()} methods of the implementing windowing API
* @since v1-alpha2
*/
public GlfwWindow(@NotNull String name, @NotNull String title, @NotNull Path @Nullable [] icons, @NotNull Vec2i size, @NotNull Vec2i minimumSize, @NotNull Vec2i maximumSize, @NotNull Vec2i position, @NotNull WindowMode windowMode, @NotNull Monitor monitor, boolean resizable, boolean borderless, boolean focusable, boolean onTop, boolean transparent, boolean rendering) throws Exception {
super(name, title, icons, size, minimumSize, maximumSize, position, windowMode, monitor, resizable, borderless, focusable, onTop, transparent, rendering);
}
/** {@inheritDoc} */
@Override
protected void initializeWindow() {
createGlfwWindow();
}
/**
* (Re-)Creates the associated GLFW window.
*
* @since v1-alpha2
*/
public void createGlfwWindow() throws WindowCreationFailureException {
// Ensure running on the main thread
if (!Miscellaneous.onMainThread())
throw new NotOnMainThreadException();
// Get current focus and destroy existing window
boolean focused = true;
if (getIdentifier() != null) {
focused = isFocused();
closeGlfwWindow();
}
// Set window hints
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // The window's visibility is later changed in setWindowState, this is just for setting up the window
glfwWindowHint(GLFW_POSITION_X, getPosition().getX());
glfwWindowHint(GLFW_POSITION_Y, getPosition().getY());
glfwWindowHint(GLFW_CENTER_CURSOR, 0);
glfwWindowHint(GLFW_FOCUSED, Miscellaneous.getIntegerizedBoolean(focused));
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, Miscellaneous.getIntegerizedBoolean(isTransparent()));
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_FALSE);
glfwWindowHintString(GLFW_WAYLAND_APP_ID, getName());
glfwWindowHintString(GLFW_X11_CLASS_NAME, getName());
glfwWindowHintString(GLFW_X11_INSTANCE_NAME, getName());
// Create window
long identifier = glfwCreateWindow(getSize().getX(), getSize().getY(), getTitle(), MemoryUtil.NULL, MemoryUtil.NULL);
if (identifier == MemoryUtil.NULL) {
new RenderingErrorEvent().callEvent("Unable to create window: Identifier is null");
throw new WindowCreationFailureException();
}
// Set identifier
identifierLong = identifier;
setIdentifier(String.valueOf(identifier));
// Own context
ownContext();
// Set swap interval based on V-Sync mode setting
glfwSwapInterval(WindowingSubsystemConfiguration.getInstance().getVsyncMode() == VsyncMode.ON ? 1 : 0);
// Create callbacks
keyCallback = GLFWKeyCallback.create(new KeyCallback(this));
mouseButtonCallback = GLFWMouseButtonCallback.create(new MouseButtonCallback(this));
// Set callback
glfwSetKeyCallback(identifierLong, keyCallback);
glfwSetMouseButtonCallback(identifier, mouseButtonCallback);
// Update the window state
setIcons(getIcons());
setSize(getSize());
setMinimumSize(getMinimumSize());
setMaximumSize(getMaximumSize());
setWindowMode(getWindowMode());
}
/**
* Closes the associated GLFW window.
*
* @since v1-alpha2
*/
public void closeGlfwWindow() throws WindowCreationFailureException {
// Ensure running on the main thread
if (!Miscellaneous.onMainThread())
throw new NotOnMainThreadException();
// Close callbacks
keyCallback.close();
mouseButtonCallback.close();
// Destroy the window
glfwDestroyWindow(identifierLong);
}
/** {@inheritDoc} */
public void terminate() {
setTerminated(true);
closeGlfwWindow();
}
// ------------------------------------------------ [ State updates ] ------------------------------------------------ //
/**
* Updates the window state.
*
* @since v1-alpha2
*/
@Override
public void updateState() {
// Ensure the window is not terminated
if (isTerminated())
return;
// Ensure running on the main thread
if (!Miscellaneous.onMainThread())
throw new NotOnMainThreadException();
// Update window mode
if (Miscellaneous.getBooleanizedInteger(glfwGetWindowAttrib(identifierLong, GLFW_ICONIFIED)))
super.setWindowMode(WindowMode.MINIMIZED);
else if (Miscellaneous.getBooleanizedInteger(glfwGetWindowAttrib(identifierLong, GLFW_MAXIMIZED)))
super.setWindowMode(WindowMode.MAXIMIZED);
else if (Miscellaneous.getBooleanizedInteger(glfwGetWindowAttrib(identifierLong, GLFW_VISIBLE)))
super.setWindowMode(WindowMode.WINDOWED);
else if (Miscellaneous.getBooleanizedInteger(glfwGetWindowAttrib(identifierLong, GLFW_VISIBLE)))
super.setWindowMode(WindowMode.HIDDEN);
// Update monitor
if (!getMonitor().isConnected()) {
Monitor newMonitor = null;
for (Monitor monitor : Monitor.getMonitors())
if (monitor.isConnected())
newMonitor = monitor;
if (newMonitor == null)
Logger.crash("Unable to set a new target monitor for window " + getUniqueIdentifier() + " as no monitors are connected to the system");
setMonitor(Objects.requireNonNull(newMonitor));
}
// Update vectors
try (MemoryStack stack = MemoryStack.stackPush()) {
IntBuffer width = stack.mallocInt(2);
IntBuffer height = stack.mallocInt(2);
glfwGetWindowSize(identifierLong, width, height);
super.setSize(new Vec2i(width.get(), height.get()));
glfwGetWindowPos(identifierLong, width, height);
super.setPosition(new Vec2i(width.get(), height.get()));
}
// Update booleans
super.setResizable(Miscellaneous.getBooleanizedInteger(glfwGetWindowAttrib(identifierLong, GLFW_RESIZABLE)));
super.setOnTop(Miscellaneous.getBooleanizedInteger(glfwGetWindowAttrib(identifierLong, GLFW_FLOATING)));
super.setTransparent(Miscellaneous.getBooleanizedInteger(glfwGetWindowAttrib(identifierLong, GLFW_TRANSPARENT_FRAMEBUFFER)));
}
// ------------------------------------------------ [ Rendering ] ------------------------------------------------ //
/** {@inheritDoc} */
@Override
public void render() throws NotOnMainThreadException {
// Ensure the window is not terminated
if (isTerminated())
return;
// Ensure rendering is enabled
if (!isRendering())
return;
// Ensure running on the main thread
if (!Miscellaneous.onMainThread())
throw new NotOnMainThreadException();
renderCode.run();
}
// ------------------------------------------------ [ GLFW handling ] ------------------------------------------------ //
/**
* Updates the OpenGL context.
*
* @since v1-alpha2
*/
public void ownContext() {
glfwMakeContextCurrent(identifierLong);
}
// ------------------------------------------------ [ Information/Action methods ] ------------------------------------------------ //
/** {@inheritDoc} */
@Override
public boolean isClosureRequested() {
// Ensure the window is not terminated
if (isTerminated())
return false;
return glfwWindowShouldClose(identifierLong);
}
/** {@inheritDoc} */
@Override
public boolean isFocused() {
// Ensure the window is not terminated
if (isTerminated())
return false;
return Miscellaneous.getTristatedInteger(glfwGetWindowAttrib(identifierLong, GLFW_FOCUSED)).toBoolean();
}
/** {@inheritDoc} */
public void focus() {
// Ensure the window is not terminated
if (isTerminated())
return;
glfwFocusWindow(identifierLong);
}
/** {@inheritDoc} */
public void requestAttention() {
// Ensure the window is not terminated
if (isTerminated())
return;
glfwRequestWindowAttention(identifierLong);
}
// ------------------------------------------------ [ Setter overrides ] ------------------------------------------------ //
/** {@inheritDoc} */
@Override
public void setName(@NotNull String name) {
// Ensure the window is not terminated
if (isTerminated())
return;
super.setName(name);
createGlfwWindow();
}
/** {@inheritDoc} */
@Override
public void setTitle(@NotNull String title) {
// Ensure the window is not terminated
if (isTerminated())
return;
super.setTitle(title);
glfwSetWindowTitle(identifierLong, title);
}
/** {@inheritDoc} */
@ApiStatus.Experimental
@Override
public void setIcons(@NotNull Path @Nullable [] icons) {
// Ensure the window is not terminated
if (isTerminated())
return;
this.icons = icons;
if (icons != null)
try (GLFWImage.Buffer iconsBuffer = GLFWImage.malloc(icons.length)) {
Logger.warn("GlfwWindow#setIcons is experimental and may cause engine or JVM crashes. Here be dragons!");
Logger.diag("icons.length = " + icons.length);
List<ByteBuffer> iconBuffers = new ArrayList<>();
IntBuffer width = MemoryUtil.memAllocInt(1);
IntBuffer height = MemoryUtil.memAllocInt(1);
IntBuffer channels = MemoryUtil.memAllocInt(1);
for (Path filepath : icons) {
Logger.diag("iterating icons » " + iconBuffers.size() + " » " + filepath);
// Load icon
Logger.diag("loading icon");
iconBuffers.add(STBImage.stbi_load(filepath.toAbsolutePath().toString(), width, height, channels, 4));
if (iconBuffers.getLast() == null) {
Logger.warn("Icon " + iconsBuffer.position() + " could not be loaded" + (STBImage.stbi_failure_reason() == null ? "" : ": " + STBImage.stbi_failure_reason()));
continue;
}
// Save into 'iconsBuffer'
Logger.diag("saving into buffer");
iconsBuffer
.position(iconsBuffer.position() + 1)
.width(width.get(0))
.height(height.get(0))
.pixels(iconBuffers.getLast());
}
Logger.diag("out of iteration");
// Set icons
Logger.diag("setting position");
iconsBuffer.position(0);
Logger.diag("setting icons");
Logger.flush();
glfwSetWindowIcon(identifierLong, iconsBuffer);
// Free icons
Logger.diag("freeing icons");
for (ByteBuffer buffer : iconBuffers)
if (buffer != null) {
Logger.diag("freeing buffer");
STBImage.stbi_image_free(buffer);
} else
Logger.diag("skipping null buffer");
}
}
/** {@inheritDoc} */
@Override
public void setSize(@NotNull Vec2i size) {
// Ensure the window is not terminated
if (isTerminated())
return;
super.setSize(size);
glfwSetWindowSize(identifierLong, size.getX(), size.getY());
}
/** {@inheritDoc} */
@Override
public void setMinimumSize(@NotNull Vec2i minimumSize) {
// Ensure the window is not terminated
if (isTerminated())
return;
super.setMinimumSize(minimumSize);
glfwSetWindowSizeLimits(identifierLong, minimumSize.getX(), minimumSize.getY(), getMaximumSize().getX(), getMaximumSize().getY());
}
/** {@inheritDoc} */
@Override
public void setMaximumSize(@NotNull Vec2i maximumSize) {
// Ensure the window is not terminated
if (isTerminated())
return;
super.setMaximumSize(maximumSize);
glfwSetWindowSizeLimits(identifierLong, getMinimumSize().getX(), getMinimumSize().getY(), maximumSize.getX(), maximumSize.getY());
}
/** {@inheritDoc} */
@Override
public void setPosition(@NotNull Vec2i position) {
// Ensure the window is not terminated
if (isTerminated())
return;
super.setPosition(position);
glfwSetWindowSize(identifierLong, position.getX(), position.getY());
}
/** {@inheritDoc} */
@Override
public void setWindowMode(@NotNull WindowMode windowMode) {
// Ensure the window is not terminated
if (isTerminated())
return;
super.setWindowMode(windowMode);
switch (windowMode) {
case HIDDEN -> glfwHideWindow(identifierLong);
case WINDOWED -> {
glfwShowWindow(identifierLong);
glfwRestoreWindow(identifierLong);
}
case MINIMIZED -> {
glfwShowWindow(identifierLong);
glfwIconifyWindow(identifierLong);
}
case MAXIMIZED -> {
glfwShowWindow(identifierLong);
glfwRestoreWindow(identifierLong);
glfwMaximizeWindow(identifierLong);
}
case BORDERLESS_FULLSCREEN -> {
glfwShowWindow(identifierLong);
glfwRestoreWindow(identifierLong);
// TODO
}
case EXCLUSIVE_FULLSCREEN -> {
glfwShowWindow(identifierLong);
glfwRestoreWindow(identifierLong);
// TODO
}
}
}
/** {@inheritDoc} */
@Override
public void setResizable(boolean resizable) {
// Ensure the window is not terminated
if (isTerminated())
return;
super.setResizable(resizable);
}
/** {@inheritDoc} */
@Override
public void setBorderless(boolean borderless) {
// Ensure the window is not terminated
if (isTerminated())
return;
super.setBorderless(borderless);
}
/** {@inheritDoc} */
@Override
public void setFocusable(boolean focusable) {
// Ensure the window is not terminated
if (isTerminated())
return;
super.setFocusable(focusable);
}
/** {@inheritDoc} */
@Override
public void setOnTop(boolean onTop) {
// Ensure the window is not terminated
if (isTerminated())
return;
super.setOnTop(onTop);
}
/** {@inheritDoc} */
@Override
public void setTransparent(boolean transparent) {
// Ensure the window is not terminated
if (isTerminated())
return;
super.setTransparent(transparent);
createGlfwWindow();
}
}

View file

@ -0,0 +1,25 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Implementations for various interfaces and abstract classes.
*
* @since v1-alpha6
*/
package de.staropensource.engine.windowing.glfw.implementation;

View file

@ -0,0 +1,25 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Code of the GLFW subsystem.
*
* @since v1-alpha2
*/
package de.staropensource.engine.windowing.glfw;

View file

@ -17,53 +17,53 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.staropensource.engine.rendering.type.window; package de.staropensource.engine.windowing.glfw.type;
/** /**
* Represents all available platforms. * Contains all available platforms which GLFW can be initialized with.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
public enum RenderingPlatform { public enum GlfwPlatform {
/** /**
* Allows the subsystem to autodetect the platform to use. * Allows GLFW to autodetect the platform to use.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
ANY, ANY,
/** /**
* Prefer initializing with the Wayland platform. * Prefer initializing with the Wayland platform.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
WAYLAND, WAYLAND,
/** /**
* Prefer initializing with the X11 platform. * Prefer initializing with the X11 platform.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
X11, X11,
/** /**
* Prefer initializing with the Win32 platform. * Prefer initializing with the Win32 platform.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
WIN32, WIN32,
/** /**
* Prefer initializing with the Cocoa platform. * Prefer initializing with the Cocoa platform.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
COCOA, COCOA,
/** /**
* Prefer initializing without any platform. * Prefer initializing without any platform.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
NONE NONE
} }

View file

@ -0,0 +1,25 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Data types in form of enums and classes.
*
* @since v1-alpha2
*/
package de.staropensource.engine.windowing.glfw.type;

View file

@ -0,0 +1,25 @@
/**
* The {@code glfw} subsystem and windowing API, which makes it
* possible to create {@link Window} using the GLFW library.
*
* @since v1-alpha4
*/
module sosengine.windowing.glfw {
// Dependencies
// -> Engine
requires transitive sosengine.base;
requires transitive sosengine.windowing;
// -> Libraries
requires transitive static lombok;
requires transitive org.jetbrains.annotations;
requires org.lwjgl.glfw;
requires org.lwjgl.stb;
// API access
exports de.staropensource.engine.windowing.glfw;
exports de.staropensource.engine.windowing.glfw.implementation;
// Reflection access
opens de.staropensource.engine.windowing.glfw;
opens de.staropensource.engine.windowing.glfw.implementation;
}

View file

@ -0,0 +1,24 @@
<!--
~ STAROPENSOURCE ENGINE SOURCE FILE
~ Copyright (c) 2024 The StarOpenSource Engine Authors
~ Licensed under the GNU Affero General Public License v3
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU Affero 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 Affero General Public License for more details.
~
~ You should have received a copy of the GNU Affero General Public License
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<body>
<p>Welcome to the sos!engine API documentation!<br/>
You are currently in the documentation for the <b>glfw</b> subsystem, allowing Graphics APIs to easily implement window and monitor support.</p>
<p>This subsystem does not provide any utility for your application, as it's meant to be used by Graphics APIs and just implements interfaces and classes from the <b>graphics</b> subsystem.</p>
</body>

View file

@ -0,0 +1 @@
../../../../../src/main/javadoc/theme.css

View file

@ -0,0 +1,235 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.engine.windowing;
import de.staropensource.engine.base.annotation.EngineSubsystem;
import de.staropensource.engine.base.annotation.EventListener;
import de.staropensource.engine.base.implementable.SubsystemClass;
import de.staropensource.engine.base.implementable.helper.EventHelper;
import de.staropensource.engine.base.logging.Logger;
import de.staropensource.engine.base.utility.information.EngineInformation;
import de.staropensource.engine.base.implementation.versioning.StarOpenSourceVersioningSystem;
import de.staropensource.engine.base.event.InternalEngineShutdownEvent;
import de.staropensource.engine.base.type.DependencyVector;
import de.staropensource.engine.base.utility.Miscellaneous;
import de.staropensource.engine.windowing.implementable.api.ApiClass;
import de.staropensource.engine.windowing.event.InputEvent;
import de.staropensource.engine.windowing.event.RenderingErrorEvent;
import de.staropensource.engine.windowing.event.WindowingErrorEvent;
import de.staropensource.engine.windowing.event.WindowingShutdownEvent;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
/**
* Main class of the {@code windowing} subsystem.
*
* @since v1-alpha0
*/
@EngineSubsystem
@SuppressWarnings({ "JavadocDeclaration" })
public final class WindowingSubsystem extends SubsystemClass {
/**
* Contains the class instance.
*
* @since v1-alpha0
* -- GETTER --
* Returns the class instance.
*
* @return class instance unless the subsystem is uninitialized
* @since v1-alpha0
*/
@Getter
private static WindowingSubsystem instance = null;
/**
* Contains a list of all registered windowing APIs.
*
* @see ApiClass
* @since v1-alpha0
* -- GETTER --
* Returns a list of all registered windowing APIs.
*
* @return list of all registered windowing APIs
* @see ApiClass
* @since v1-alpha0
*/
@Getter
private final @NotNull Map<@NotNull String, @NotNull ApiClass> registeredApis = new HashMap<>();
/**
* Contains a reference to the active windowing API main class.
*
* @see ApiClass
* @since v1-alpha0
* -- GETTER --
* Returns a reference to the active windowing API main class.
*
* @return windowing API main class reference
* @see ApiClass
* @since v1-alpha0
*/
@Getter
private ApiClass api = null;
/**
* Initializes this subsystem.
*
* @since v1-alpha0
*/
public WindowingSubsystem() {
// Only allow one instance
if (instance == null)
instance = this;
else
Logger.crash("Only one instance of this class is allowed, use getInstance() instead of creating a new instance");
}
/** {@inheritDoc} */
@Override
public @NotNull String getName() {
return "windowing";
}
/** {@inheritDoc} */
@Override
public void initializeSubsystem() {
// Initialize WindowingSubsystemConfiguration and load it
new WindowingSubsystemConfiguration().loadConfiguration();
// Precompute event listeners
cacheEvents();
// Warn about subsystem and API instability
Logger.warn("The windowing subsystem is experimental. Subsystem and API stability are not guaranteed.");
}
/**
* Caches all windowing subsystem events.
*
* @since v1-alpha0
*/
public static void cacheEvents() {
EventHelper.cacheEvent(RenderingErrorEvent.class);
EventHelper.cacheEvent(WindowingShutdownEvent.class);
EventHelper.cacheEvent(WindowingErrorEvent.class);
EventHelper.cacheEvent(InputEvent.class);
}
/** {@inheritDoc} */
@Override
public @NotNull DependencyVector getDependencyVector() {
return new DependencyVector.Builder()
.setIdentifier(getName())
.setVersioningSystem(StarOpenSourceVersioningSystem.class)
.setVersion(EngineInformation.getVersioningString())
.build();
}
/**
* Shuts the subsystem down.
*
* @since v1-alpha0
*/
@EventListener(event = InternalEngineShutdownEvent.class)
@SuppressWarnings({ "unused" })
protected static void shutdownSubsystem() {
Logger.verb("Shutting down");
long shutdownTime = Miscellaneous.measureExecutionTime(() -> {
new WindowingShutdownEvent().callEvent();
if (instance.api != null)
instance.api.shutdownApi();
});
Logger.info("Shut down in " + shutdownTime + "ms");
}
/**
* Registers a windowing API.
*
* @param mainClass main class of the windowing API
* @since v1-alpha4
*/
public void registerApi(@NotNull ApiClass mainClass) {
Logger.verb("Registering windowing API " + mainClass.getApiName() + " (" + mainClass.getClass().getName() + ")");
Object[] output = Miscellaneous.getMapValues(registeredApis, mainClass).toArray();
if (output.length == 0 || output[0] == null)
registeredApis.put(mainClass.getApiName(), mainClass);
}
/**
* Chooses a windowing API to use automatically based on hardware support.
*
* @return if a compatible windowing API has been chosen
* @see #setApi(String)
* @since v1-alpha4
*/
public boolean setApi() {
Logger.verb("Choosing a windowing API");
if (registeredApis.isEmpty())
return false;
// Initialize first API in list.
api = registeredApis.get(registeredApis.keySet().toArray(new String[0])[0]);
try {
Logger.diag("Initializing windowing API \"" + api.getApiName() + "\"");
Logger.diag("Initialized windowing API \"" + api.getApiName() + "\" in " + Miscellaneous.measureExecutionTime(() -> api.initializeApi()) + "ms");
} catch (Throwable throwable) {
Logger.crash("Windowing API \"" + api.getApiName() + "\" failed to initialize", throwable, true);
throw throwable;
}
return true;
}
/**
* Sets the windowing API to use.
*
* @param name name of the windowing API
* @return if the windowing API has been found
* @see #setApi()
* @since v1-alpha4
*/
@SuppressWarnings({ "unused" })
public boolean setApi(@NotNull String name) {
if (!registeredApis.containsKey(name))
return false;
Logger.verb("Setting windowing API " + name);
if (api == null)
api = registeredApis.get(name);
else
Logger.crash("Unable to set windowing API: windowing API " + api.getApiName() + " already registered");
// Initialize API
Logger.diag("Initializing windowing API " + api.getApiName());
Logger.diag("Initialized windowing API " + api.getApiName() + " in " + Miscellaneous.measureExecutionTime(() -> api.initializeApi()) + "ms");
return true;
}
}

View file

@ -0,0 +1,246 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.engine.windowing;
import de.staropensource.engine.base.implementable.Configuration;
import de.staropensource.engine.base.logging.Logger;
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;
import org.jetbrains.annotations.Nullable;
/**
* Provides the configuration of the windowing subsystem.
*
* @since v1-alpha0
*/
@Getter
@SuppressWarnings({ "JavadocDeclaration" })
public final class WindowingSubsystemConfiguration extends Configuration {
/**
* Contains the class instance.
*
* @since v1-alpha0
* -- GETTER --
* Returns the class instance.
*
* @return class instance unless {@link WindowingSubsystem} is uninitialized
* @since v1-alpha0
*/
@Getter
private static WindowingSubsystemConfiguration instance;
/**
* Defines the group every property must start with to be recognized as a subsystem configuration setting.
*
* @since v1-alpha0
* -- GETTER --
* Returns the group that every property must start with to be recognized as a subsystem configuration setting.
*
* @return property group
* @since v1-alpha0
*/
@Getter
public final @NotNull String group = "sosengine.windowing.";
/**
* If enabled, allows for unintentional behaviour and excess logging.
* Unless you want to debug or work on a sensitive part of the subsystem, don't enable this!
*
* @since v1-alpha0
* -- GETTER --
* Gets the value for {@link #debug}.
*
* @return variable value
* @see WindowingSubsystemConfiguration#debug
* @since v1-alpha0
*/
private boolean debug;
/**
* If enabled, will log all keys being pressed or released.
*
* @since v1-alpha2
* -- GETTER --
* Gets the value for {@link #debugInput}.
*
* @return variable value
* @see WindowingSubsystemConfiguration#debugInput
* @since v1-alpha2
*/
private boolean debugInput;
/**
* If enabled, will log the delta time average
* and FPS count to the console every second.
* <p>
* Is applied during rendering thread startup
* and will not be applied after.
*
* @since v1-alpha2
* -- GETTER --
* Gets the value for {@link #debugFrames}.
*
* @return variable value
* @see #debugFrames
* @since v1-alpha2
*/
private boolean debugFrames;
/**
* Causes windowing errors will be logged, if enabled.
*
* @see WindowingErrorEvent
* @since v1-alpha4
* -- GETTER --
* Gets the value for {@link #errorWindowingFailure}.
*
* @return variable value
* @see WindowingSubsystemConfiguration#errorWindowingFailure
* @since v1-alpha4
*/
private boolean errorWindowingFailure;
/**
* Causes rendering errors will be logged, if enabled.
*
* @see RenderingErrorEvent
* @since v1-alpha4
* -- GETTER --
* Gets the value for {@link #errorRenderingFailure}.
*
* @return variable value
* @see WindowingSubsystemConfiguration#errorRenderingFailure
* @since v1-alpha4
*/
private boolean errorRenderingFailure;
/**
* Contains how many frames can be rendered per second.
* <p>
* This setting determines if and how V-Sync will operate, which
* (if enabled) tries to synchronize the frame rate to the monitor's
* refresh rate. See {@link VsyncMode} for more information.
*
* @since v1-alpha2
* -- GETTER --
* Gets the value for {@link #vsyncMode}.
*
* @return variable value
* @see #vsyncMode
* @since v1-alpha2
*/
private VsyncMode vsyncMode;
/**
* Contains how many frames can be rendered per second.
* <p>
* This value will have no effect on windows with V-Sync enabled.
* Set to {@code 0} for no limit.
*
* @since v1-alpha2
* -- GETTER --
* Gets the value for {@link #maximumFramesPerSecond}.
*
* @return variable value
* @see #maximumFramesPerSecond
* @since v1-alpha2
*/
private int maximumFramesPerSecond;
/**
* Creates and initializes an instance of this class.
*
* @see WindowingSubsystem
* @since v1-alpha6
*/
WindowingSubsystemConfiguration() {
instance = this;
loadDefaultConfiguration();
}
/** {@inheritDoc} */
@Override
protected void matchProperty(@NotNull PropertiesReader parser, @NotNull String property) {
switch (property) {
case "debug" -> debug = parser.getBoolean(group + property);
case "debugInput" -> debugInput = parser.getBoolean(group + property);
case "debugFrames" -> debugFrames = parser.getBoolean(group + property);
case "errorWindowingFailure" -> errorWindowingFailure = parser.getBoolean(group + property);
case "errorRenderingFailure" -> errorRenderingFailure = parser.getBoolean(group + property);
case "vsyncMode" -> {
try {
vsyncMode = VsyncMode.valueOf(parser.getString(group + property).toUpperCase());
} catch (IllegalArgumentException exception) {
Logger.error("V-Sync mode " + parser.getString(group + property) + " is not valid");
}
}
case "maximumFramesPerSecond" -> maximumFramesPerSecond = parser.getInteger(group + property, true);
}
}
/** {@inheritDoc} */
@Override
protected void processSettings(@NotNull PropertiesReader parser) {
// Disable all debug options if 'debug' is disabled
if (!debug) {
debugInput = false;
debugFrames = false;
}
}
/** {@inheritDoc} */
@Override
public void loadDefaultConfiguration() {
debug = false;
debugInput = false;
debugFrames = false;
errorWindowingFailure = true;
errorRenderingFailure = true;
vsyncMode = VsyncMode.ON;
maximumFramesPerSecond = 60;
}
/** {@inheritDoc} */
@Override
public @Nullable Object getSetting(@NotNull String setting) {
switch (setting) {
case "debug" -> { return debug; }
case "debugInput" -> { return debugInput; }
case "debugFrames" -> { return debugFrames; }
case "errorWindowingFailure" -> { return errorWindowingFailure; }
case "errorRenderingFailure" -> { return errorRenderingFailure; }
case "vsyncMode" -> { return vsyncMode; }
case "maximumFramesPerSecond" -> { return maximumFramesPerSecond; }
default -> { return null; }
}
}
}

View file

@ -17,28 +17,28 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.staropensource.engine.rendering.event; package de.staropensource.engine.windowing.event;
import de.staropensource.engine.base.implementable.Event; import de.staropensource.engine.base.implementable.Event;
import de.staropensource.engine.base.implementable.helper.EventHelper; import de.staropensource.engine.base.implementable.helper.EventHelper;
import de.staropensource.engine.base.logging.Logger; import de.staropensource.engine.base.logging.Logger;
import de.staropensource.engine.rendering.RenderingSubsystemConfiguration; import de.staropensource.engine.windowing.WindowingSubsystemConfiguration;
import de.staropensource.engine.rendering.type.Window; import de.staropensource.engine.windowing.implementable.Window;
import de.staropensource.engine.rendering.type.input.Key; import de.staropensource.engine.windowing.type.input.Key;
import de.staropensource.engine.rendering.type.input.KeyState; import de.staropensource.engine.windowing.type.input.KeyState;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
/** /**
* Called when a key or button is pressed. * Called when a key or button is pressed.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
public final class InputEvent implements Event { public final class InputEvent implements Event {
/** /**
* Creates and initializes an instance of this event. * Creates and initializes an instance of this event.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
public InputEvent() {} public InputEvent() {}
@ -57,10 +57,10 @@ public final class InputEvent implements Event {
* @param window window the input originated from. May be {@code null}, depending on the windowing API * @param window window the input originated from. May be {@code null}, depending on the windowing API
* @param key key * @param key key
* @param state key state * @param state key state
* @since v1-alpha9 * @since v1-alpha0
*/ */
public void callEvent(@Nullable Window window, @NotNull Key key, @NotNull KeyState state) { public void callEvent(@Nullable Window window, @NotNull Key key, @NotNull KeyState state) {
if (RenderingSubsystemConfiguration.getInstance().isDebugInput()) if (WindowingSubsystemConfiguration.getInstance().isDebugInput())
Logger.diag("Got input event: window=" + (window == null ? "\\<null>" : window.getUniqueIdentifier()) + " key=" + key.name() + " state=" + state.name()); Logger.diag("Got input event: window=" + (window == null ? "\\<null>" : window.getUniqueIdentifier()) + " key=" + key.name() + " state=" + state.name());
EventHelper.invokeAnnotatedMethods(getClass(), window, key, state); EventHelper.invokeAnnotatedMethods(getClass(), window, key, state);

View file

@ -17,28 +17,27 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.staropensource.engine.rendering.event; package de.staropensource.engine.windowing.event;
import de.staropensource.engine.base.implementable.Event; import de.staropensource.engine.base.implementable.Event;
import de.staropensource.engine.base.implementable.helper.EventHelper; import de.staropensource.engine.base.implementable.helper.EventHelper;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
/** /**
* Emitted when a rendering error occurs. * Called when an error occurs in the renderer API (e.g. OpenGL, Vulkan).
* *
* @since v1-alpha9 * @since v1-alpha0
*/ */
public final class RenderingErrorEvent implements Event { public final class RenderingErrorEvent implements Event {
/** /**
* Creates and initializes an instance of this event. * Creates and initializes an instance of this event.
* *
* @since v1-alpha9 * @since v1-alpha0
*/ */
public RenderingErrorEvent() {} public RenderingErrorEvent() {}
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @deprecated use the {@code callEvent} method with arguments * @deprecated use the {@code callEvent} method with arguments
* @see #callEvent(String) * @see #callEvent(String)
*/ */
@ -50,7 +49,7 @@ public final class RenderingErrorEvent implements Event {
* Emits the event and calls all event listeners. * Emits the event and calls all event listeners.
* *
* @param error error description * @param error error description
* @since v1-alpha9 * @since v1-alpha0
*/ */
public void callEvent(@NotNull String error) { public void callEvent(@NotNull String error) {
EventHelper.invokeAnnotatedMethods(getClass(), error); EventHelper.invokeAnnotatedMethods(getClass(), error);

View file

@ -0,0 +1,58 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.engine.windowing.event;
import de.staropensource.engine.base.implementable.Event;
import de.staropensource.engine.base.implementable.helper.EventHelper;
import org.jetbrains.annotations.NotNull;
/**
* Called when an error occurs in the windowing API.
*
* @since v1-alpha0
*/
public final class WindowingErrorEvent implements Event {
/**
* Creates and initializes an instance of this event.
*
* @since v1-alpha0
*/
public WindowingErrorEvent() {}
/**
* {@inheritDoc}
*
* @deprecated use the {@code callEvent} method with arguments
* @see #callEvent(String)
*/
@Deprecated
@Override
public void callEvent() {}
/**
* Emits the event and calls all event listeners.
*
* @param error error description
* @since v1-alpha0
*/
public void callEvent(@NotNull String error) {
EventHelper.invokeAnnotatedMethods(getClass(), error);
}
}

View file

@ -0,0 +1,44 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.engine.windowing.event;
import de.staropensource.engine.base.implementable.Event;
import de.staropensource.engine.base.implementable.helper.EventHelper;
/**
* Called when the windowing API shuts down.
*
* @since v1-alpha0
*/
public final class WindowingShutdownEvent implements Event {
/**
* Creates and initializes an instance of this event.
*
* @since v1-alpha0
*/
public WindowingShutdownEvent() {}
/** {@inheritDoc} */
@Override
public void callEvent() {
EventHelper.invokeAnnotatedMethods(getClass());
}
}

View file

@ -20,6 +20,6 @@
/** /**
* Events. There's nothing more to say. * Events. There's nothing more to say.
* *
* @since v1-alpha9 * @since v1-alpha0
*/ */
package de.staropensource.engine.rendering.event; package de.staropensource.engine.windowing.event;

View file

@ -17,18 +17,18 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.staropensource.engine.rendering.exception; package de.staropensource.engine.windowing.exception;
/** /**
* Thrown when the specified monitor does not exist. * Thrown when the specified monitor does not exist.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
public final class InvalidMonitorException extends RuntimeException { public final class InvalidMonitorException extends RuntimeException {
/** /**
* Creates and initializes an instance of this exception. * Creates and initializes an instance of this exception.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
public InvalidMonitorException() {} public InvalidMonitorException() {}
} }

View file

@ -17,18 +17,18 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.staropensource.engine.rendering.exception; package de.staropensource.engine.windowing.exception;
/** /**
* Thrown when trying to access one or more monitors but none are found. * Thrown when trying to access one or more monitors but none are found.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
public final class NoMonitorsFoundException extends RuntimeException { public final class NoMonitorsFoundException extends RuntimeException {
/** /**
* Creates and initializes an instance of this exception. * Creates and initializes an instance of this exception.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
public NoMonitorsFoundException() {} public NoMonitorsFoundException() {}
} }

View file

@ -17,18 +17,18 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.staropensource.engine.rendering.exception; package de.staropensource.engine.windowing.exception;
/** /**
* Thrown when trying to communicate with a windowing API over a non-main thread. * Thrown when trying to communicate with a windowing API over a non-main thread.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
public final class NotOnMainThreadException extends RuntimeException { public final class NotOnMainThreadException extends RuntimeException {
/** /**
* Creates and initializes an instance of this exception. * Creates and initializes an instance of this exception.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
public NotOnMainThreadException() {} public NotOnMainThreadException() {}
} }

View file

@ -17,21 +17,21 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.staropensource.engine.rendering.exception; package de.staropensource.engine.windowing.exception;
import de.staropensource.engine.rendering.type.Window; import de.staropensource.engine.windowing.implementable.Window;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
/** /**
* Thrown when a {@link Window} cannot be created. * Thrown when a {@link Window} cannot be created.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
public final class WindowCreationFailureException extends RuntimeException { public final class WindowCreationFailureException extends RuntimeException {
/** /**
* Creates and initializes an instance of this exception. * Creates and initializes an instance of this exception.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
public WindowCreationFailureException() {} public WindowCreationFailureException() {}
@ -39,7 +39,7 @@ public final class WindowCreationFailureException extends RuntimeException {
* Creates and initializes an instance of this exception. * Creates and initializes an instance of this exception.
* *
* @param message error message * @param message error message
* @since v1-alpha9 * @since v1-alpha2
*/ */
public WindowCreationFailureException(@NotNull String message) { public WindowCreationFailureException(@NotNull String message) {
super(message); super(message);

View file

@ -23,6 +23,6 @@
* These aren't meant for the windowing subsystem, * These aren't meant for the windowing subsystem,
* but instead for windowing APIs, which may throw them. * but instead for windowing APIs, which may throw them.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
package de.staropensource.engine.rendering.exception; package de.staropensource.engine.windowing.exception;

View file

@ -17,45 +17,43 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.staropensource.engine.rendering.type; package de.staropensource.engine.windowing.implementable;
import de.staropensource.engine.base.type.vector.Vec2i; import de.staropensource.engine.base.type.vector.Vec2i;
import de.staropensource.engine.rendering.exception.InvalidMonitorException; import de.staropensource.engine.windowing.WindowingSubsystem;
import de.staropensource.engine.rendering.exception.NoMonitorsFoundException; import de.staropensource.engine.windowing.exception.InvalidMonitorException;
import de.staropensource.engine.windowing.exception.NoMonitorsFoundException;
import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.lwjgl.PointerBuffer;
import org.lwjgl.glfw.GLFWVidMode;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import static org.lwjgl.glfw.GLFW.*;
/** /**
* Abstract class for implementing monitors in a windowing API. * Abstract class for implementing monitors in a windowing API.
* <p> * <p>
* Note that monitors stop working unannounced when disconnected, * Note that monitors stop working unannounced when disconnected,
* call {@link #isConnected()} before using to avoid unexpected behaviour. * call {@link #isConnected()} before using to avoid unexpected behaviour.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
@SuppressWarnings({ "JavadocDeclaration" }) @SuppressWarnings({ "JavadocDeclaration" })
public final class Monitor { public abstract class Monitor {
/** /**
* Contains the unique identifier. * Contains the unique identifier.
* <p> * <p>
* This identifier is unique to every monitor and does not change during runtime. * This identifier is unique to every monitor and does not change during runtime.
* *
* @since v1-alpha9 * @since v1-alpha2
* -- GETTER -- * -- GETTER --
* Returns the unique identifier. * Returns the unique identifier.
* <p> * <p>
* This identifier is unique to every monitor and does not change during runtime. * This identifier is unique to every monitor and does not change during runtime.
* *
* @return unique identifier * @return unique identifier
* @since v1-alpha9 * @since v1-alpha2
*/ */
@Getter @Getter
private final UUID uniqueIdentifier = UUID.randomUUID(); private final UUID uniqueIdentifier = UUID.randomUUID();
@ -65,59 +63,47 @@ public final class Monitor {
* <p> * <p>
* This identifier is used by the windowing API to refer to a monitor and may change during runtime. * This identifier is used by the windowing API to refer to a monitor and may change during runtime.
* *
* @since v1-alpha9 * @since v1-alpha1
* -- GETTER -- * -- GETTER --
* Returns the monitor identifier. * Returns the monitor identifier.
* <p> * <p>
* This identifier is used by the windowing API to refer to a monitor and may change during runtime. * This identifier is used by the windowing API to refer to a monitor and may change during runtime.
* *
* @return monitor identifier * @return monitor identifier
* @since v1-alpha9 * @since v1-alpha2
* -- SETTER -- * -- SETTER --
* Sets the monitor identifier. * Sets the monitor identifier.
* <p> * <p>
* This identifier is used by the windowing API to refer to a monitor and may change during runtime. * This identifier is used by the windowing API to refer to a monitor and may change during runtime.
* *
* @param identifier new monitor identifier * @param identifier new monitor identifier
* @since v1-alpha9 * @since v1-alpha2
*/ */
private final long identifier; @Setter(AccessLevel.PROTECTED)
private String identifier = null;
/** /**
* Creates and initializes an instance of this abstract class. * Creates and initializes an instance of this abstract class.
* *
* @throws InvalidMonitorException if the monitor isn't connected * @since v1-alpha2
* @since v1-alpha9
*/ */
public Monitor(long identifier) throws InvalidMonitorException { public Monitor() {}
this.identifier = identifier;
checkConnected();
}
/** /**
* Returns a set of all connected monitors. * Returns all connected monitors.
* *
* @return connected monitors * @return connected monitors
* @since v1-alpha9 * @since v1-alpha2
*/ */
public static @NotNull LinkedHashSet<@NotNull Monitor> getMonitors() throws NoMonitorsFoundException { public static @NotNull LinkedHashSet<@NotNull Monitor> getMonitors() throws NoMonitorsFoundException {
PointerBuffer monitors = glfwGetMonitors(); return WindowingSubsystem.getInstance().getApi().getInternalApi().getMonitors();
LinkedHashSet<@NotNull Monitor> output = new LinkedHashSet<>();
if (monitors == null)
throw new NoMonitorsFoundException();
while (monitors.hasRemaining())
output.add(new Monitor(monitors.get()));
return output;
} }
/** /**
* Checks if this monitor is actually connected. * Checks if the monitor is actually connected.
* If not, throws an {@link InvalidMonitorException}. * If not, throws an {@link InvalidMonitorException}.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
public void checkConnected() throws InvalidMonitorException, NoMonitorsFoundException { public void checkConnected() throws InvalidMonitorException, NoMonitorsFoundException {
if (!isConnected()) if (!isConnected())
@ -125,48 +111,34 @@ public final class Monitor {
} }
/** /**
* Checks if this monitor is connected. * Checks if the monitor is connected or not.
* *
* @return connection status * @return connection status
* @since v1-alpha9 * @since v1-alpha2
*/ */
public boolean isConnected() throws NoMonitorsFoundException { public abstract boolean isConnected() throws NoMonitorsFoundException;
return glfwGetMonitorName(identifier) != null;
}
/** /**
* Returns the name of this monitor. * Returns the monitor name.
* *
* @return monitor name * @return monitor name
* @since v1-alpha9 * @since v1-alpha2
*/ */
public @NotNull String getName() throws InvalidMonitorException, NoMonitorsFoundException { public abstract @NotNull String getName() throws InvalidMonitorException, NoMonitorsFoundException;
checkConnected();
return Objects.requireNonNull(glfwGetMonitorName(identifier));
}
/** /**
* Returns size of this monitor. * Returns the monitor size.
* *
* @return monitor size * @return monitor size
* @since v1-alpha9 * @since v1-alpha2
*/ */
public @NotNull Vec2i getSize() throws InvalidMonitorException, NoMonitorsFoundException { public abstract @NotNull Vec2i getSize() throws InvalidMonitorException, NoMonitorsFoundException;
checkConnected();
GLFWVidMode videoMode = Objects.requireNonNull(glfwGetVideoMode(identifier));
return new Vec2i(videoMode.width(), videoMode.height());
}
/** /**
* Returns refresh rate of this monitor in hertz. * Returns the monitor refresh rate.
* *
* @return monitor refresh rate * @return monitor refresh rate
* @since v1-alpha9 * @since v1-alpha2
*/ */
public short getRefreshRate() throws InvalidMonitorException, NoMonitorsFoundException { public abstract short getRefreshRate() throws InvalidMonitorException, NoMonitorsFoundException;
checkConnected();
return (short) Objects.requireNonNull(glfwGetVideoMode(identifier)).refreshRate();
}
} }

View file

@ -0,0 +1,84 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.engine.windowing.implementable.api;
import de.staropensource.engine.base.Engine;
import de.staropensource.engine.base.implementable.SubsystemClass;
import org.jetbrains.annotations.NotNull;
/**
* Abstract class for building windowing API main classes.
*
* @since v1-alpha0
*/
public abstract class ApiClass extends SubsystemClass {
/**
* Creates and initializes an instance of this abstract class.
*
* @since v1-alpha2
*/
public ApiClass() {}
/**
* Initializes the windowing API.
*
* @since v1-alpha0
*/
public abstract void initializeApi();
/**
* Shuts the windowing API down.
* <p>
* Called when the engine shuts down.
*
* @see Engine#shutdown()
* @see Engine#shutdown(int)
* @since v1-alpha0
*/
public abstract void shutdownApi();
/**
* Returns the name of the windowing API.
*
* @return windowing API name
* @since v1-alpha0
*/
public abstract String getApiName();
/**
* Returns the windowing API's internal API access class.
*
* @return a {@link ApiInternalClass}
* @see ApiInternalClass
* @since v1-alpha2
*/
@NotNull
public abstract ApiInternalClass getInternalApi();
/**
* Returns the windowing API's management class.
*
* @return a {@link ApiManagementClass}
* @see ApiManagementClass
* @since v1-alpha0
*/
@NotNull
public abstract ApiManagementClass getManagement();
}

View file

@ -0,0 +1,54 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.engine.windowing.implementable.api;
import de.staropensource.engine.windowing.implementable.Monitor;
import de.staropensource.engine.windowing.implementable.Window;
import de.staropensource.engine.windowing.exception.NoMonitorsFoundException;
import org.jetbrains.annotations.NotNull;
import java.util.LinkedHashSet;
/**
* Interface for internal API access classes.
* These are used exclusively by the windowing
* subsystem's code.
*
* @since v1-alpha2
*/
public interface ApiInternalClass {
/**
* Returns the {@link Window} class of the windowing API.
*
* @return {@link Window} class
* @since v1-alpha2
*/
@NotNull
Class<? extends Window> getWindowClass();
/**
* Returns all connected monitors.
*
* @return connected monitors
* @since v1-alpha2
*/
@NotNull
LinkedHashSet<@NotNull Monitor> getMonitors() throws NoMonitorsFoundException;
}

View file

@ -0,0 +1,125 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.engine.windowing.implementable.api;
import de.staropensource.engine.base.logging.Logger;
import de.staropensource.engine.base.utility.Math;
import de.staropensource.engine.base.utility.Miscellaneous;
import de.staropensource.engine.windowing.WindowingSubsystemConfiguration;
import de.staropensource.engine.windowing.implementable.Window;
import de.staropensource.engine.windowing.type.window.VsyncMode;
import org.jetbrains.annotations.NotNull;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.concurrent.atomic.AtomicReference;
/**
* Interface for building windowing API management classes.
* These are used for interfacing with the windowing API directly.
*
* @since v1-alpha0
*/
public abstract class ApiManagementClass {
/**
* Creates and initializes an instance of this abstract class.
*
* @since v1-alpha2
*/
public ApiManagementClass() {}
/**
* Returns if this windowing API must be interacted with on the main thread.
*
* @return {@code true} if windowing API must be interacted with on the main thread, {@code false} otherwise
* @since v1-alpha2
*/
public abstract boolean mustRunOnMainThread();
/**
* Runs the render loop <b>once</b>.
* To run the render loop continuously, see {@link #runRenderLoopContinuously(Runnable)}.
*
* @return map of windows and their thrown throwables
* @since v1-alpha2
*/
public abstract LinkedHashMap<@NotNull Window, @NotNull Throwable> runRenderLoop();
/**
* Runs the render loop <b>for ever</b>.
* To run the render loop only once, see {@link #runRenderLoop()}.
* <p>
* Immediately returns with when a {@link #runRenderLoop()} call fails.
*
* @param frameCode code that should be invoked on during a frame. will be counted to frame time
* @return see {@link #runRenderLoop()}
* @since v1-alpha2
*/
public LinkedHashMap<@NotNull Window, @NotNull Throwable> runRenderLoopContinuously(@NotNull Runnable frameCode) {
// Define variables
AtomicReference<LinkedHashMap<@NotNull Window, @NotNull Throwable>> output = new AtomicReference<>(new LinkedHashMap<>()); // runRenderLoop output
long renderTime; // Amount of time spent rendering
long sleepDuration; // Time spent sleeping the thread
LinkedList<Long> splitDeltaTime = new LinkedList<>(); // Used for calculating the delta time (render time average over one second)
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(() -> {
output.set(runRenderLoop());
frameCode.run();
});
if (WindowingSubsystemConfiguration.getInstance().getVsyncMode() != VsyncMode.OFF)
// V-Sync is enabled, no need for manual busy waiting
sleepDuration = 0L;
else
// Calculate amount of time the thread should spend sleeping
sleepDuration = (long) (1d / WindowingSubsystemConfiguration.getInstance().getMaximumFramesPerSecond() * 1000d) - renderTime;
// Add render and sleep time to list used for calculating the delta time value
splitDeltaTime.add(renderTime + sleepDuration);
// Busy wait unless V-Sync is enabled
if (WindowingSubsystemConfiguration.getInstance().getVsyncMode() == VsyncMode.OFF && WindowingSubsystemConfiguration.getInstance().getMaximumFramesPerSecond() >= 1) {
sleepDuration += System.currentTimeMillis();
while (System.currentTimeMillis() < sleepDuration)
Thread.onSpinWait();
}
// Calculate delta time and frame count every second
if (System.currentTimeMillis() >= reportDuration) {
deltaTime = Math.getMeanLong(splitDeltaTime); // Calculate delta time
Logger.diag("Delta time average: " + deltaTime + " | Frames/s: " + 1000 / deltaTime); // Print delta time and frame count to console
reportDuration = System.currentTimeMillis() + 1000; // Update 'reportDuration'
splitDeltaTime.clear(); // Clear 'splitDeltaTime' list
}
}
return output.get();
}
}

View file

@ -0,0 +1,25 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Contains classes starting with {@code Api*}.
*
* @since v1-alpha2
*/
package de.staropensource.engine.windowing.implementable.api;

View file

@ -0,0 +1,27 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Interfaces and abstract classes which can be used for implementing classes.
* <p>
* These are not to be confused with data types. See {@link de.staropensource.engine.windowing.type}.
*
* @since v1-alpha0
*/
package de.staropensource.engine.windowing.implementable;

View file

@ -20,6 +20,6 @@
/** /**
* Code of the windowing subsystem. * Code of the windowing subsystem.
* *
* @since v1-alpha9 * @since v1-alpha0
*/ */
package de.staropensource.engine.rendering; package de.staropensource.engine.windowing;

View file

@ -17,590 +17,590 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.staropensource.engine.rendering.type.input; package de.staropensource.engine.windowing.type.input;
/** /**
* Contains a list of keys which can be recognized by the engine. * Contains a list of keys which can be recognized by the engine.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
public enum Key { public enum Key {
/** /**
* An unknown key. * An unknown key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
UNKNOWN_KEY, UNKNOWN_KEY,
/** /**
* An unknown mouse button. * An unknown mouse button.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
UNKNOWN_MOUSE_BUTTON, UNKNOWN_MOUSE,
/** /**
* The left mouse button. * The left mouse button.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
MOUSE_LEFT, MOUSE_LEFT,
/** /**
* The middle mouse button. * The middle mouse button.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
MOUSE_MIDDLE, MOUSE_MIDDLE,
/** /**
* The right mouse button. * The right mouse button.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
MOUSE_RIGHT, MOUSE_RIGHT,
/** /**
* The {@code ALT} modifier key. * The {@code ALT} modifier key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
ALT, ALT,
/** /**
* The {@code '} key. * The {@code '} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
APOSTROPHE, APOSTROPHE,
/** /**
* The {@code DOWN} arrow key. * The {@code DOWN} arrow key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
ARROW_DOWN, ARROW_DOWN,
/** /**
* The {@code LEFT} arrow key. * The {@code LEFT} arrow key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
ARROW_LEFT, ARROW_LEFT,
/** /**
* The {@code RIGHT} arrow key. * The {@code RIGHT} arrow key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
ARROW_RIGHT, ARROW_RIGHT,
/** /**
* The {@code UP} arrow key. * The {@code UP} arrow key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
ARROW_UP, ARROW_UP,
/** /**
* The {@code \} key. * The {@code \} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
BACKSLASH, BACKSLASH,
/** /**
* The {@code BACKSPACE} key. * The {@code BACKSPACE} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
BACKSPACE, BACKSPACE,
/** /**
* The left {@code [} key. * The left {@code [} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
BRACKET_LEFT, BRACKET_LEFT,
/** /**
* The right {@code ]} key. * The right {@code ]} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
BRACKET_RIGHT, BRACKET_RIGHT,
/** /**
* THE {@code CAPSLOCK} KEY. * THE {@code CAPSLOCK} KEY.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
CAPS_LOCK, CAPS_LOCK,
/** /**
* The {@code ,} key. * The {@code ,} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
COMMA, COMMA,
/** /**
* The left {@code CTRL} modifier key. * The left {@code CTRL} modifier key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
CONTROL_LEFT, CONTROL_LEFT,
/** /**
* The right {@code CTRL} modifier key. * The right {@code CTRL} modifier key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
CONTROL_RIGHT, CONTROL_RIGHT,
/** /**
* The {@code DEL} key. * The {@code DEL} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
DELETE, DELETE,
/** /**
* The {@code END} key. * The {@code END} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
END, END,
/** /**
* The {@code ENTER} key. * The {@code ENTER} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
ENTER, ENTER,
/** /**
* The {@code =} key. * The {@code =} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
EQUAL, EQUAL,
/** /**
* The {@code ESC} key. * The {@code ESC} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
ESCAPE, ESCAPE,
/** /**
* The {@code F1} key. * The {@code F1} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
FUNCTION_1, FUNCTION_1,
/** /**
* The {@code F2} key. * The {@code F2} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
FUNCTION_2, FUNCTION_2,
/** /**
* The {@code F3} key. * The {@code F3} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
FUNCTION_3, FUNCTION_3,
/** /**
* The {@code F4} key. * The {@code F4} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
FUNCTION_4, FUNCTION_4,
/** /**
* The {@code F5} key. * The {@code F5} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
FUNCTION_5, FUNCTION_5,
/** /**
* The {@code F6} key. * The {@code F6} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
FUNCTION_6, FUNCTION_6,
/** /**
* The {@code F7} key. * The {@code F7} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
FUNCTION_7, FUNCTION_7,
/** /**
* The {@code F8} key. * The {@code F8} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
FUNCTION_8, FUNCTION_8,
/** /**
* The {@code F9} key. * The {@code F9} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
FUNCTION_9, FUNCTION_9,
/** /**
* The {@code F10} key. * The {@code F10} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
FUNCTION_10, FUNCTION_10,
/** /**
* The {@code F11} key. * The {@code F11} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
FUNCTION_11, FUNCTION_11,
/** /**
* The {@code F12} key. * The {@code F12} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
FUNCTION_12, FUNCTION_12,
/** /**
* The {@code F13} key. * The {@code F13} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
FUNCTION_13, FUNCTION_13,
/** /**
* The {@code F14} key. * The {@code F14} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
FUNCTION_14, FUNCTION_14,
/** /**
* The {@code F15} key. * The {@code F15} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
FUNCTION_15, FUNCTION_15,
/** /**
* The {@code F16} key. * The {@code F16} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
FUNCTION_16, FUNCTION_16,
/** /**
* The {@code F17} key. * The {@code F17} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
FUNCTION_17, FUNCTION_17,
/** /**
* The {@code F18} key. * The {@code F18} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
FUNCTION_18, FUNCTION_18,
/** /**
* The {@code F19} key. * The {@code F19} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
FUNCTION_19, FUNCTION_19,
/** /**
* The {@code F20} key. * The {@code F20} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
FUNCTION_20, FUNCTION_20,
/** /**
* The {@code F21} key. * The {@code F21} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
FUNCTION_21, FUNCTION_21,
/** /**
* The {@code F22} key. * The {@code F22} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
FUNCTION_22, FUNCTION_22,
/** /**
* The {@code F23} key. * The {@code F23} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
FUNCTION_23, FUNCTION_23,
/** /**
* The {@code F24} key. * The {@code F24} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
FUNCTION_24, FUNCTION_24,
/** /**
* The {@code F25} key. * The {@code F25} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
FUNCTION_25, FUNCTION_25,
/** /**
* The {@code `} key. * The {@code `} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
GRAVE, GRAVE,
/** /**
* The {@code HOME} key. * The {@code HOME} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
HOME, HOME,
/** /**
* THe {@code INS} key. * THe {@code INS} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
INSERT, INSERT,
/** /**
* The {@code +} key on your keypad. * The {@code +} key on your keypad.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
KEYPAD_ADD, KEYPAD_ADD,
/** /**
* The {@code -} key on your keypad. * The {@code -} key on your keypad.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
KEYPAD_DECIMAL, KEYPAD_DECIMAL,
/** /**
* The {@code /} key on your keypad. * The {@code /} key on your keypad.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
KEYPAD_DIVIDE, KEYPAD_DIVIDE,
/** /**
* The {@code ENTER} key on your keypad. * The {@code ENTER} key on your keypad.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
KEYPAD_ENTER, KEYPAD_ENTER,
/** /**
* The {@code =} key on your keypad. * The {@code =} key on your keypad.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
KEYPAD_EQUAL, KEYPAD_EQUAL,
/** /**
* The {@code *} key on your keypad. * The {@code *} key on your keypad.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
KEYPAD_MULTIPLY, KEYPAD_MULTIPLY,
/** /**
* The number {@code 0} key on your keypad. * The number {@code 0} key on your keypad.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
KEYPAD_NUMBER_0, KEYPAD_NUMBER_0,
/** /**
* The number {@code 1} key on your keypad. * The number {@code 1} key on your keypad.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
KEYPAD_NUMBER_1, KEYPAD_NUMBER_1,
/** /**
* The number {@code 2} key on your keypad. * The number {@code 2} key on your keypad.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
KEYPAD_NUMBER_2, KEYPAD_NUMBER_2,
/** /**
* The number {@code 3} key on your keypad. * The number {@code 3} key on your keypad.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
KEYPAD_NUMBER_3, KEYPAD_NUMBER_3,
/** /**
* The number {@code 4} key on your keypad. * The number {@code 4} key on your keypad.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
KEYPAD_NUMBER_4, KEYPAD_NUMBER_4,
/** /**
* The number {@code 5} key on your keypad. * The number {@code 5} key on your keypad.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
KEYPAD_NUMBER_5, KEYPAD_NUMBER_5,
/** /**
* The number {@code 6} key on your keypad. * The number {@code 6} key on your keypad.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
KEYPAD_NUMBER_6, KEYPAD_NUMBER_6,
/** /**
* The number {@code 7} key on your keypad. * The number {@code 7} key on your keypad.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
KEYPAD_NUMBER_7, KEYPAD_NUMBER_7,
/** /**
* The number {@code 8} key on your keypad. * The number {@code 8} key on your keypad.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
KEYPAD_NUMBER_8, KEYPAD_NUMBER_8,
/** /**
* The number {@code 9} key on your keypad. * The number {@code 9} key on your keypad.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
KEYPAD_NUMBER_9, KEYPAD_NUMBER_9,
/** /**
* The {@code -} key on your keypad. * The {@code -} key on your keypad.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
KEYPAD_SUBTRACT, KEYPAD_SUBTRACT,
/** /**
* The letter {@code A} key. * The letter {@code A} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_A, LETTER_A,
/** /**
* The letter {@code B} key. * The letter {@code B} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_B, LETTER_B,
/** /**
* The letter {@code C} key. * The letter {@code C} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_C, LETTER_C,
/** /**
* The letter {@code D} key. * The letter {@code D} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_D, LETTER_D,
/** /**
* The letter {@code E} key. * The letter {@code E} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_E, LETTER_E,
/** /**
* The letter {@code F} key. * The letter {@code F} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_F, LETTER_F,
/** /**
* The letter {@code G} key. * The letter {@code G} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_G, LETTER_G,
/** /**
* The letter {@code H} key. * The letter {@code H} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_H, LETTER_H,
/** /**
* The letter {@code I} key. * The letter {@code I} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_I, LETTER_I,
/** /**
* The letter {@code J} key. * The letter {@code J} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_J, LETTER_J,
/** /**
* The letter {@code K} key. * The letter {@code K} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_K, LETTER_K,
/** /**
* The letter {@code L} key. * The letter {@code L} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_L, LETTER_L,
/** /**
* The letter {@code M} key. * The letter {@code M} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_M, LETTER_M,
/** /**
* The letter {@code N} key. * The letter {@code N} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_N, LETTER_N,
/** /**
* The letter {@code O} key. * The letter {@code O} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_O, LETTER_O,
/** /**
* The letter {@code P} key. * The letter {@code P} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_P, LETTER_P,
/** /**
* The letter {@code Q} key. * The letter {@code Q} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_Q, LETTER_Q,
/** /**
* The letter {@code R} key. * The letter {@code R} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_R, LETTER_R,
/** /**
* The letter {@code S} key. * The letter {@code S} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_S, LETTER_S,
/** /**
* The letter {@code T} key. * The letter {@code T} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_T, LETTER_T,
/** /**
* The letter {@code U} key. * The letter {@code U} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_U, LETTER_U,
/** /**
* The letter {@code V} key. * The letter {@code V} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_V, LETTER_V,
/** /**
* The letter {@code W} key. * The letter {@code W} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_W, LETTER_W,
/** /**
* The letter {@code X} key. * The letter {@code X} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_X, LETTER_X,
/** /**
* The letter {@code Y} key. * The letter {@code Y} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_Y, LETTER_Y,
/** /**
* The letter {@code Z} key. * The letter {@code Z} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
LETTER_Z, LETTER_Z,
/** /**
* The {@code MENU} key, which brings up the right click menu. * The {@code MENU} key, which brings up the right click menu.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
MENU, MENU,
/** /**
@ -608,151 +608,151 @@ public enum Key {
* <p> * <p>
* Windows users will recognize this key as the Windows key. * Windows users will recognize this key as the Windows key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
META, META,
/** /**
* The {@code -} key. * The {@code -} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
MINUS, MINUS,
/** /**
* The number {@code 0}. * The number {@code 0}.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
NUMBER_0, NUMBER_0,
/** /**
* The number {@code 1}. * The number {@code 1}.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
NUMBER_1, NUMBER_1,
/** /**
* The number {@code 2}. * The number {@code 2}.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
NUMBER_2, NUMBER_2,
/** /**
* The number {@code 3}. * The number {@code 3}.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
NUMBER_3, NUMBER_3,
/** /**
* The number {@code 4}. * The number {@code 4}.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
NUMBER_4, NUMBER_4,
/** /**
* The number {@code 5}. * The number {@code 5}.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
NUMBER_5, NUMBER_5,
/** /**
* The number {@code 6}. * The number {@code 6}.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
NUMBER_6, NUMBER_6,
/** /**
* The number {@code 7}. * The number {@code 7}.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
NUMBER_7, NUMBER_7,
/** /**
* The number {@code 8}. * The number {@code 8}.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
NUMBER_8, NUMBER_8,
/** /**
* The number {@code 9}. * The number {@code 9}.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
NUMBER_9, NUMBER_9,
/** /**
* The {@code NUM} key. * The {@code NUM} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
NUM_LOCK, NUM_LOCK,
/** /**
* The {@code PAGE DOWN} key. * The {@code PAGE DOWN} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
PAGE_DOWN, PAGE_DOWN,
/** /**
* The {@code PAGE UP} key. * The {@code PAGE UP} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
PAGE_UP, PAGE_UP,
/** /**
* The {@code PAUSE} key. * The {@code PAUSE} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
PAUSE, PAUSE,
/** /**
* The {@code .} key. * The {@code .} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
PERIOD, PERIOD,
/** /**
* The {@code PRINT} key. * The {@code PRINT} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
PRINT, PRINT,
/** /**
* The {@code SCROLL} key. * The {@code SCROLL} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
SCROLL_LOCK, SCROLL_LOCK,
/** /**
* The {@code ;} key. * The {@code ;} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
SEMICOLON, SEMICOLON,
/** /**
* The left {@code SHIFT} modifier key. * The left {@code SHIFT} modifier key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
SHIFT_LEFT, SHIFT_LEFT,
/** /**
* The right {@code SHIFT} modifier key. * The right {@code SHIFT} modifier key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
SHIFT_RIGHT, SHIFT_RIGHT,
/** /**
* The {@code /} key. * The {@code /} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
SLASH, SLASH,
/** /**
* The {@code ENTER} key. * The {@code ENTER} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
SPACE, SPACE,
/** /**
* The {@code TAB} key. * The {@code TAB} key.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
TAB, TAB,
} }

View file

@ -17,26 +17,26 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.staropensource.engine.rendering.type.input; package de.staropensource.engine.windowing.type.input;
/** /**
* Contains in which state a key is. * Contains in which state a key is.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
@SuppressWarnings({ "unused" }) @SuppressWarnings({ "unused" })
public enum KeyState { public enum KeyState {
/** /**
* Indicates that a key is pressed. * Indicates that a key is pressed.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
PRESSED, PRESSED,
/** /**
* Indicates that a key is released. * Indicates that a key is released.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
RELEASED, RELEASED,
} }

View file

@ -20,6 +20,6 @@
/** /**
* Data types related to input. * Data types related to input.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
package de.staropensource.engine.rendering.type.input; package de.staropensource.engine.windowing.type.input;

View file

@ -20,6 +20,6 @@
/** /**
* Data types in form of enums and classes. * Data types in form of enums and classes.
* *
* @since v1-alpha9 * @since v1-alpha1
*/ */
package de.staropensource.engine.rendering.type; package de.staropensource.engine.windowing.type;

View file

@ -17,30 +17,29 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.staropensource.engine.rendering.type.window; package de.staropensource.engine.windowing.type.window;
import de.staropensource.engine.rendering.RenderingSubsystemConfiguration; import de.staropensource.engine.windowing.WindowingSubsystemConfiguration;
/** /**
* Controls how <a href="https://en.wikipedia.org/wiki/Screen_tearing#Vertical_synchronization">V-Sync</a> operates. * Controls how <a href="https://en.wikipedia.org/wiki/Screen_tearing#Vertical_synchronization">V-Sync</a> operates.
* *
* @since v1-alpha9 * @since v1-alpha1
*/ */
public enum VsyncMode { public enum VsyncMode {
/** /**
* Disables V-Sync. The frame rate will be uncapped and will allow * Disables V-Sync. The frame rate will be uncapped and will allow
* for processing an unlimited amount of frames (if not limited by * for processing an unlimited amount of frames (if not limited by
* {@link RenderingSubsystemConfiguration#maximumFramesPerSecond}). * {@link WindowingSubsystemConfiguration#maximumFramesPerSecond}).
* *
* @since v1-alpha9 * @since v1-alpha1
*/ */
OFF, OFF,
/** /**
* Enables V-Sync and will cap the window's frame rate * Enables V-Sync and will cap the window's frame rate at the refresh rate of the target monitor.
* at the refresh rate of the target monitor.
* *
* @since v1-alpha9 * @since v1-alpha1
*/ */
ON ON
} }

View file

@ -17,18 +17,18 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.staropensource.engine.rendering.type.window; package de.staropensource.engine.windowing.type.window;
/** /**
* Contains how a window should be displayed. * Contains how a window should be displayed.
* *
* @since v1-alpha9 * @since v1-alpha1
*/ */
public enum WindowMode { public enum WindowMode {
/** /**
* Marks the window as hidden, making it invisible and unable to be interacted with. * Marks the window as hidden, making it invisible and unable to be interacted with.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
HIDDEN, HIDDEN,
@ -36,7 +36,7 @@ public enum WindowMode {
* Marks the window as windowed, which * Marks the window as windowed, which
* will allow the user to drag around the window freely. * will allow the user to drag around the window freely.
* *
* @since v1-alpha9 * @since v1-alpha1
*/ */
WINDOWED, WINDOWED,
@ -45,7 +45,7 @@ public enum WindowMode {
* summoned back into {@link #WINDOWED} mode by the user * summoned back into {@link #WINDOWED} mode by the user
* by (for example) clicking an icon or {@code ALT+TAB}-ing. * by (for example) clicking an icon or {@code ALT+TAB}-ing.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
MINIMIZED, MINIMIZED,
@ -53,7 +53,7 @@ public enum WindowMode {
* Same as {@link #WINDOWED}, but will make the window occupy * Same as {@link #WINDOWED}, but will make the window occupy
* most of the screen space, except for windows/bars/docks. * most of the screen space, except for windows/bars/docks.
* *
* @since v1-alpha9 * @since v1-alpha2
*/ */
MAXIMIZED, MAXIMIZED,
@ -61,25 +61,20 @@ public enum WindowMode {
* Makes the window will have the same * Makes the window will have the same
* size as the monitor it is currently on. * size as the monitor it is currently on.
* *
* @since v1-alpha9 * @since v1-alpha1
*/ */
BORDERLESS_FULLSCREEN, BORDERLESS_FULLSCREEN,
/** /**
* Makes the window occupy the entire * Makes the window occupy the entire monitor it is currently on
* monitor it is currently on without * without allowing other windows to occupy the same space.
* allowing other windows to occupy
* the same space.
* <p> * <p>
* This will increase rendering * This will increase rendering throughput as the window manager
* throughput as the window manager * or compositor does not need to care about other windows occupying
* or compositor does not need to * the same monitor. Use (and recommend) this mode if you/your users
* care about other windows occupying
* the same monitor. Use (and recommend)
* this mode if you/your users
* want more frames per second. * want more frames per second.
* *
* @since v1-alpha9 * @since v1-alpha1
*/ */
EXCLUSIVE_FULLSCREEN EXCLUSIVE_FULLSCREEN
} }

View file

@ -20,6 +20,6 @@
/** /**
* Data types related to windows. * Data types related to windows.
* *
* @since v1-alpha9 * @since v1-alpha1
*/ */
package de.staropensource.engine.rendering.type.window; package de.staropensource.engine.windowing.type.window;

View file

@ -0,0 +1,32 @@
/**
* The {@code windowing} subsystem, which provides abstractions and
* APIs, which allow the creation and management of windows.
*
* @since v1-alpha4
*/
module sosengine.windowing {
// Dependencies
// -> Engine
requires transitive sosengine.base;
// -> Libraries
requires transitive static lombok;
requires transitive org.jetbrains.annotations;
// API access
exports de.staropensource.engine.windowing;
exports de.staropensource.engine.windowing.implementable;
exports de.staropensource.engine.windowing.implementable.api;
exports de.staropensource.engine.windowing.event;
exports de.staropensource.engine.windowing.exception;
exports de.staropensource.engine.windowing.type.input;
exports de.staropensource.engine.windowing.type.window;
// Reflection access
opens de.staropensource.engine.windowing;
opens de.staropensource.engine.windowing.implementable;
opens de.staropensource.engine.windowing.implementable.api;
opens de.staropensource.engine.windowing.event;
opens de.staropensource.engine.windowing.exception;
opens de.staropensource.engine.windowing.type.input;
opens de.staropensource.engine.windowing.type.window;
}