-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 650320d
Showing
34 changed files
with
1,117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
## Java | ||
|
||
*.class | ||
*.war | ||
*.ear | ||
hs_err_pid* | ||
|
||
## Android Studio and Intellij and Android in general | ||
.idea/ | ||
*.ipr | ||
*.iws | ||
*.iml | ||
com_crashlytics_export_strings.xml | ||
|
||
## Eclipse | ||
|
||
.classpath | ||
.project | ||
.metadata/ | ||
/core/bin/ | ||
/desktop/bin/ | ||
*.tmp | ||
*.bak | ||
*.swp | ||
*~.nib | ||
.settings/ | ||
.loadpath | ||
.externalToolBuilders/ | ||
*.launch | ||
|
||
## NetBeans | ||
|
||
/nbproject/private/ | ||
/core/nbproject/private/ | ||
/desktop/nbproject/private/ | ||
|
||
/build/ | ||
/core/build/ | ||
/desktop/build/ | ||
|
||
/nbbuild/ | ||
/core/nbbuild/ | ||
/desktop/nbbuild/ | ||
|
||
/dist/ | ||
/core/dist/ | ||
/desktop/dist/ | ||
|
||
/nbdist/ | ||
/core/nbdist/ | ||
/desktop/nbdist/ | ||
|
||
nbactions.xml | ||
nb-configuration.xml | ||
|
||
## OS Specific | ||
.DS_Store | ||
Thumbs.db | ||
|
||
## SPCK Specific | ||
build | ||
.gradle | ||
target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Project Spck | ||
|
||
```bash | ||
# Run from command line: | ||
$ ./gradlew run | ||
``` | ||
|
||
```bash | ||
# Package | ||
$ ./gradlew jlink | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
plugins { | ||
id("java") | ||
id("org.javamodularity.moduleplugin").version("1.7.0").apply(false) | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
mavenCentral() | ||
maven("https://oss.sonatype.org/content/repositories/snapshots/") | ||
} | ||
} | ||
|
||
subprojects { | ||
apply(plugin = "org.javamodularity.moduleplugin") | ||
group = "spck" | ||
version = "1.0.0" | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_16 | ||
targetCompatibility = JavaVersion.VERSION_16 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import org.gradle.nativeplatform.platform.internal.ArchitectureInternal | ||
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform | ||
import org.gradle.nativeplatform.platform.internal.DefaultOperatingSystem | ||
|
||
plugins { | ||
id("java-library") | ||
} | ||
|
||
val lwjglVersion = "3.3.0-SNAPSHOT" | ||
val jomlVersion = "1.10.1" | ||
val slf4jVersion = "1.8.0-beta4" | ||
val resourcesPath = "../resources" | ||
|
||
val currentOs: DefaultOperatingSystem = DefaultNativePlatform.getCurrentOperatingSystem() | ||
val currentArch: ArchitectureInternal = DefaultNativePlatform.getCurrentArchitecture() | ||
logger.quiet("[SPCK] System: ${currentOs.displayName} / ${currentArch.displayName}") | ||
|
||
fun specifyLwjglNatives(): String { | ||
val currentOs = DefaultNativePlatform.getCurrentOperatingSystem() | ||
val currentArch = DefaultNativePlatform.getCurrentArchitecture() | ||
when { | ||
currentOs.isMacOsX -> { | ||
if(currentArch.displayName.contains("aarch64")) { | ||
return "natives-macos-arm64" | ||
} | ||
return "natives-macos" | ||
} | ||
currentOs.isWindows -> { | ||
if(currentArch.displayName.contains("aarch64")) { | ||
return "natives-windows-arm64" | ||
} | ||
return "natives-windows" | ||
} | ||
currentOs.isLinux -> { | ||
return "natives-linux" | ||
} | ||
else -> throw Error("Unrecognized or unsupported Operating system.") | ||
} | ||
} | ||
|
||
val lwjglNatives = specifyLwjglNatives() | ||
|
||
logger.quiet("[SPCK] Natives in use: $lwjglNatives") | ||
logger.quiet("[SPCK] Resources path: $resourcesPath") | ||
|
||
sourceSets.main.get().resources.srcDirs(resourcesPath) | ||
|
||
dependencies { | ||
api(platform("org.lwjgl:lwjgl-bom:$lwjglVersion")) | ||
|
||
implementation("org.lwjgl", "lwjgl") | ||
api("org.lwjgl", "lwjgl-glfw") | ||
implementation("org.lwjgl", "lwjgl-opengl") | ||
implementation("org.lwjgl", "lwjgl", classifier = lwjglNatives) | ||
implementation("org.lwjgl", "lwjgl-glfw", classifier = lwjglNatives) | ||
implementation("org.lwjgl", "lwjgl-opengl", classifier = lwjglNatives) | ||
implementation("org.joml", "joml", jomlVersion) | ||
implementation("org.slf4j", "slf4j-api", slf4jVersion) | ||
implementation("org.slf4j", "slf4j-simple", slf4jVersion) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module spck.core { | ||
requires org.lwjgl; | ||
requires org.lwjgl.natives; | ||
requires org.lwjgl.opengl; | ||
requires org.lwjgl.opengl.natives; | ||
requires transitive org.lwjgl.glfw; | ||
requires org.lwjgl.glfw.natives; | ||
requires org.joml; | ||
requires org.slf4j; | ||
|
||
exports spck.core; | ||
exports spck.core.input; | ||
exports spck.core.props; | ||
exports spck.core.props.type; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package spck.core; | ||
|
||
import org.joml.Vector4f; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import spck.core.props.Preferences; | ||
import spck.core.render.Renderer; | ||
import spck.core.window.Window; | ||
|
||
public class Application { | ||
private static final Logger log = LoggerFactory.getLogger(Application.class); | ||
private final Window window; | ||
private final LifeCycleListener lifeCycleListener; | ||
private final Renderer renderer; | ||
|
||
public Application(LifeCycleListener lifeCycleListener, Preferences preferences) { | ||
if(Spck.app != null) { | ||
throw new SpckRuntimeException("Cannot run multiple applications"); | ||
} | ||
Spck.app = this; | ||
this.lifeCycleListener = lifeCycleListener; | ||
renderer = new Renderer(preferences.renderBackend, preferences.debug); | ||
window = new Window(preferences, renderer); | ||
} | ||
|
||
public void start() { | ||
log.info("Starting up application..."); | ||
|
||
window.create(); | ||
lifeCycleListener.onCreated(); | ||
|
||
loop(); | ||
|
||
log.info("Application is shutting down"); | ||
renderer.dispose(); | ||
window.dispose(); | ||
log.info("Terminated"); | ||
} | ||
|
||
public void stop() { | ||
window.close(); | ||
} | ||
|
||
private void loop() { | ||
long lastTime = System.nanoTime(); | ||
|
||
renderer.setClearColor(new Vector4f(1f, 1f, 1f, 1f)); | ||
renderer.setClearFlags(Spck.types.bufferBit.color); | ||
|
||
while (!window.shouldClose()) { | ||
renderer.clear(); | ||
long now = System.nanoTime(); | ||
long frameTimeNanos = now - lastTime; | ||
float frameTime = frameTimeNanos / 1_000_000_000f; | ||
lastTime = now; | ||
|
||
renderer.swapBuffers(frameTime); | ||
window.pollEvents(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package spck.core; | ||
|
||
public interface Disposable { | ||
void dispose(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package spck.core; | ||
|
||
public interface LifeCycleListener { | ||
default void onCreated() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package spck.core; | ||
|
||
import spck.core.input.InputManager; | ||
import spck.core.props.type.Types; | ||
|
||
public class Spck { | ||
public static final InputManager input = new InputManager(); | ||
public static Application app; | ||
public static Types types; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package spck.core; | ||
|
||
public class SpckRuntimeException extends RuntimeException { | ||
public SpckRuntimeException(String message) { | ||
super(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package spck.core.input; | ||
|
||
public class InputManager { | ||
private InputMultiplexer multiplexer; | ||
|
||
public void setMultiplexer(InputMultiplexer multiplexer) { | ||
this.multiplexer = multiplexer; | ||
} | ||
|
||
public void keyCallback(int key, int scancode, int action, int mods) { | ||
if(multiplexer != null) { | ||
multiplexer.keyCallback(key, scancode, action, mods); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package spck.core.input; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.lwjgl.glfw.GLFW.*; | ||
|
||
public class InputMultiplexer { | ||
private final List<InputProcessor> processors = new ArrayList<>(); | ||
|
||
public int addProcessor(InputProcessor processor) { | ||
processors.add(processor); | ||
return processors.size() - 1; | ||
} | ||
|
||
public void removeProcessor(int index) { | ||
processors.remove(index); | ||
} | ||
|
||
public void keyCallback(int key, int scancode, int action, int mods) { | ||
switch (action) { | ||
case GLFW_PRESS: | ||
for (InputProcessor processor : processors) { | ||
processor.onKeyPress(key); | ||
} | ||
break; | ||
case GLFW_RELEASE: | ||
for (InputProcessor processor : processors) { | ||
processor.onKeyReleased(key); | ||
} | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package spck.core.input; | ||
|
||
public interface InputProcessor { | ||
default void onKeyPress(int keyCode) {} | ||
|
||
default void onKeyReleased(int keyCode) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package spck.core.props; | ||
|
||
public enum Antialiasing { | ||
OFF(0), | ||
ANTIALISING_2X(2), | ||
ANTIALISING_4X(4), | ||
ANTIALISING_8X(8), | ||
ANTIALISING_16X(16); | ||
|
||
private int value; | ||
|
||
Antialiasing(int value) { | ||
this.value = value; | ||
} | ||
|
||
public int getValue() { | ||
return value; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package spck.core.props; | ||
|
||
import org.joml.Vector2i; | ||
|
||
public class Preferences { | ||
public enum RendererBackend { | ||
OPENGL, | ||
} | ||
|
||
public String title = "Project SPCK"; | ||
public RendererBackend renderBackend = RendererBackend.OPENGL; | ||
public Antialiasing antialiasing = Antialiasing.OFF; | ||
public Vector2i windowSize = new Vector2i(1280, 720); | ||
public boolean vSync = false; | ||
public boolean fullscreen = false; | ||
public boolean debug = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package spck.core.props.type; | ||
|
||
public class BufferBit { | ||
public final int color; | ||
public final int depth; | ||
public final int stencil; | ||
|
||
public BufferBit(int color, int depth, int stencil) { | ||
this.color = color; | ||
this.depth = depth; | ||
this.stencil = stencil; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package spck.core.props.type; | ||
|
||
public class Types { | ||
public final BufferBit bufferBit; | ||
|
||
public Types(BufferBit bufferBit) { | ||
this.bufferBit = bufferBit; | ||
} | ||
} |
Oops, something went wrong.