Skip to content

Commit

Permalink
Dungine: remove libGDX and improve the ECS approach (thesis/concept s…
Browse files Browse the repository at this point in the history
…tudy) (#1652)

siehe #1652 (review)
  • Loading branch information
fwatermann authored Dec 1, 2024
1 parent da6ebac commit a0b9364
Show file tree
Hide file tree
Showing 278 changed files with 29,446 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.java]
indent_size = 2

[{*.fsh,*.gsh,*.vsh}]
indent_size = 2

[Makefile]
indent_style = tab

Expand Down
Binary file added dungine-demo/assets/animations/hero.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dungine-demo/assets/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dungine-demo/assets/images/skybox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dungine-demo/assets/models/capsule.glb
Binary file not shown.
Binary file added dungine-demo/assets/models/earth.glb
Binary file not shown.
Binary file added dungine-demo/assets/models/moon.glb
Binary file not shown.
Binary file added dungine-demo/assets/models/sun.glb
Binary file not shown.
13 changes: 13 additions & 0 deletions dungine-demo/assets/shaders/level.fsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#version 330 core

#include "/shaders/util/TextureAtlas.fsh"

in vec2 gsTexCoord;
flat in int gsAtlasEntry;


out vec4 color;

void main() {
color = textureAtlas(gsAtlasEntry, gsTexCoord);
}
37 changes: 37 additions & 0 deletions dungine-demo/assets/shaders/level.gsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#version 330 core

layout (points) in;
layout (triangle_strip, max_vertices = 4) out;

flat in int vsAtlasEntry[];

uniform mat4 uProjection;
uniform mat4 uView;
uniform mat4 uModel;

out vec2 gsTexCoord;
flat out int gsAtlasEntry;

void main() {
gl_Position = uProjection * uView * uModel * gl_in[0].gl_Position;
gsTexCoord = vec2(0.0, 0.0);
gsAtlasEntry = vsAtlasEntry[0];
EmitVertex();

gl_Position = uProjection * uView * uModel * (gl_in[0].gl_Position + vec4(0.0, 0.0, 1.0, 0.0));
gsTexCoord = vec2(0.0, 1.0);
gsAtlasEntry = vsAtlasEntry[0];
EmitVertex();

gl_Position = uProjection * uView * uModel * (gl_in[0].gl_Position + vec4(1.0, 0.0, 0.0, 0.0));
gsTexCoord = vec2(1.0, 0.0);
gsAtlasEntry = vsAtlasEntry[0];
EmitVertex();

gl_Position = uProjection * uView * uModel * (gl_in[0].gl_Position + vec4(1.0, 0.0, 1.0, 0.0));
gsTexCoord = vec2(1.0, 1.0);
gsAtlasEntry = vsAtlasEntry[0];
EmitVertex();

EndPrimitive();
}
11 changes: 11 additions & 0 deletions dungine-demo/assets/shaders/level.vsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#version 330 core

layout (location = 0) in vec3 aPosition;
layout (location = 1) in int aAtlasEntry;

flat out int vsAtlasEntry;

void main() {
gl_Position = vec4(aPosition, 1.0);
vsAtlasEntry = aAtlasEntry;
}
17 changes: 17 additions & 0 deletions dungine-demo/assets/shaders/level3d/chunk.fsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#version 330 core

#include "/shaders/util/TextureAtlas.fsh"

in vec2 gsTexCoord;
flat in int gsTextureIndex;

out vec4 fragColor;

void main() {
if (gsTextureIndex == -1) {
fragColor = vec4(1.0f, 0.08f, 0.58f, 1.0f);
return;
}
fragColor = textureAtlas(gsTextureIndex, gsTexCoord);
//fragColor = vec4(1.0f, 0, 0, 1.0f);
}
90 changes: 90 additions & 0 deletions dungine-demo/assets/shaders/level3d/chunk.gsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#version 330 core

#define FACE_UP 0x20
#define FACE_DOWN 0x10
#define FACE_NORTH 0x08
#define FACE_SOUTH 0x04
#define FACE_WEST 0x02
#define FACE_EAST 0x01

layout (points) in;
layout (triangle_strip, max_vertices = 24) out;

flat in int vsFaces[];
flat in ivec3 vsAtlasEntries[];

uniform mat4 uProjection;
uniform mat4 uView;
uniform mat4 uModel;

out vec2 gsTexCoord;
flat out int gsTextureIndex;

void vertex(int x, int y, int z, float u, float v, int entry);

void main() {
int faces = vsFaces[0];
if (faces == 0) {
//No faces to render
return;
}

if ((faces & FACE_UP) == FACE_UP) {
int atlasEntry = (vsAtlasEntries[0].x >> 16) & 0xFFFF;
vertex(0, 1, 0, 0, 0, atlasEntry);
vertex(0, 1, 1, 1, 0, atlasEntry);
vertex(1, 1, 0, 0, 1, atlasEntry);
vertex(1, 1, 1, 1, 1, atlasEntry);
EndPrimitive();
}
if ((faces & FACE_DOWN) == FACE_DOWN) {
int atlasEntry = (vsAtlasEntries[0].x) & 0xFFFF;
vertex(0, 0, 0, 0, 0, atlasEntry);
vertex(1, 0, 0, 1, 0, atlasEntry);
vertex(0, 0, 1, 0, 1, atlasEntry);
vertex(1, 0, 1, 1, 1, atlasEntry);
EndPrimitive();
}
if ((faces & FACE_NORTH) == FACE_NORTH) {
int atlasEntry = (vsAtlasEntries[0].y >> 16) & 0xFFFF;
vertex(0, 0, 1, 0, 0, atlasEntry);
vertex(1, 0, 1, 1, 0, atlasEntry);
vertex(0, 1, 1, 0, 1, atlasEntry);
vertex(1, 1, 1, 1, 1, atlasEntry);
EndPrimitive();
}
if ((faces & FACE_SOUTH) == FACE_SOUTH) {
int atlasEntry = (vsAtlasEntries[0].y) & 0xFFFF;
vertex(1, 0, 0, 0, 0, atlasEntry);
vertex(0, 0, 0, 1, 0, atlasEntry);
vertex(1, 1, 0, 0, 1, atlasEntry);
vertex(0, 1, 0, 1, 1, atlasEntry);
EndPrimitive();
}
if ((faces & FACE_WEST) == FACE_WEST) {
int atlasEntry = (vsAtlasEntries[0].z >> 16) & 0xFFFF;
vertex(0, 0, 0, 0, 0, atlasEntry);
vertex(0, 0, 1, 1, 0, atlasEntry);
vertex(0, 1, 0, 0, 1, atlasEntry);
vertex(0, 1, 1, 1, 1, atlasEntry);
EndPrimitive();
}
if ((faces & FACE_EAST) == FACE_EAST) {
int atlasEntry = (vsAtlasEntries[0].z) & 0xFFFF;
vertex(1, 0, 1, 0, 0, atlasEntry);
vertex(1, 0, 0, 1, 0, atlasEntry);
vertex(1, 1, 1, 0, 1, atlasEntry);
vertex(1, 1, 0, 1, 1, atlasEntry);
EndPrimitive();
}
}

void vertex(int x, int y, int z, float u, float v, int entry) {
vec3 pos = gl_in[0].gl_Position.xyz + vec3(x, y, z);
gl_Position = uProjection * uView * uModel * vec4(pos, 1.0f);
gsTexCoord = vec2(u, v);
gsTextureIndex = entry;
EmitVertex();
}


15 changes: 15 additions & 0 deletions dungine-demo/assets/shaders/level3d/chunk.vsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 330 core
#define MAX_ATLASENTRIES 65536

in ivec3 aPosition;
in int aFaces;
in ivec3 aAtlasEntries;

flat out int vsFaces;
flat out ivec3 vsAtlasEntries;

void main() {
gl_Position = vec4(aPosition, 1.0);
vsFaces = aFaces;
vsAtlasEntries = aAtlasEntries;
}
Binary file added dungine-demo/assets/sounds/music/main_menu.ogg
Binary file not shown.
Binary file added dungine-demo/assets/textures/back.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dungine-demo/assets/textures/floor_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dungine-demo/assets/textures/floor_damaged.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dungine-demo/assets/textures/floor_hole.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dungine-demo/assets/textures/skybox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dungine-demo/assets/textures/wall.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions dungine-demo/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform

plugins {
id 'application'
}


dependencies {
implementation project(":dungine")

// JUnit 4 and Mockito for testing
testImplementation supportDependencies.junit
testImplementation supportDependencies.mockito_core
}


sourceSets.main.java.srcDirs = ['src/']
sourceSets.main.resources.srcDirs = ['assets/']

sourceSets.test.java.srcDirs = ['test/']
sourceSets.test.resources.srcDirs = ['test_resources/']

application.mainClass = "dungine.Main"

OperatingSystem os = DefaultNativePlatform.currentOperatingSystem;
if(os.isMacOsX()) {
applicationDefaultJvmArgs = ["-XstartOnFirstThread"] // Required for MacOS
}

jar {
dependsOn ":dungine:jar"
manifest.attributes.put("Main-Class", "dungine.Main")
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
23 changes: 23 additions & 0 deletions dungine-demo/src/dungine/Dungine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package dungine;

import de.fwatermann.dungine.window.GameWindow;
import org.joml.Vector2i;

/** The `Dungine` class is the main entry point for the Dungine-Demo. */
public class Dungine extends GameWindow {

/**
* Constructs a new GameWindow.
*
* @param debug the debug state of the game window
*/
public Dungine(boolean debug) {
super("Dungine", new Vector2i(1280, 720), true, debug);
}

@Override
public void init() {}

@Override
public void cleanup() {}
}
24 changes: 24 additions & 0 deletions dungine-demo/src/dungine/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package dungine;

import dungine.state.StateMainMenu;
import dungine.state.StateTransition;

/**
* Main class of the Dungine demo application. It contains the main method that starts the Dungine
* game engine and initializes the game state.
*/
public class Main {

/**
* Main method of the Dungine demo application. It starts the Dungine game engine and initializes
* the game state.
*
* @param args Command-line arguments
*/
public static void main(String[] args) {
Dungine dungine = new Dungine(false);
dungine.setState(new StateMainMenu(dungine));
dungine.setStateTransition(new StateTransition(dungine));
dungine.start();
}
}
12 changes: 12 additions & 0 deletions dungine-demo/src/dungine/components/CameraComponent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package dungine.components;

import de.fwatermann.dungine.ecs.Component;

/** A component that marks an entity as the focus point of the camera. */
public class CameraComponent extends Component {

/** Constructs a new CameraComponent object. */
public CameraComponent() {
super(false);
}
}
Loading

0 comments on commit a0b9364

Please sign in to comment.