Skip to content
This repository was archived by the owner on Jun 19, 2024. It is now read-only.

Commit dcb9603

Browse files
authored
Merge pull request #59 from LabyMod/develop
Update to version 0.4.7
2 parents f574a56 + 66b2ea7 commit dcb9603

File tree

46 files changed

+1342
-35
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1342
-35
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ out/
33
.gradle/
44
.idea/
55
cmake-build-*/
6-
run/
6+
**/run/
77
bin/
88
.vscode/
99
.settings/

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.4.6
1+
0.4.7

buildSrc/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
plugins {
22
id("java-gradle-plugin")
3+
`kotlin-dsl`
34
}
45

6+
repositories {
7+
mavenCentral()
8+
}
59

610
gradlePlugin {
711
plugins {
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import org.apache.tools.ant.taskdefs.condition.Os
2+
3+
plugins {
4+
id("application")
5+
id("java-library")
6+
}
7+
8+
group = "com.labymedia"
9+
10+
fun lwjglClassifier(): String {
11+
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
12+
return "natives-windows"
13+
} else if (Os.isFamily(Os.FAMILY_MAC)) {
14+
return "natives-macos"
15+
} else if (Os.isFamily(Os.FAMILY_UNIX)) {
16+
return "natives-linux"
17+
} else {
18+
throw UnsupportedOperationException("This OS is not supported")
19+
}
20+
}
21+
22+
repositories {
23+
mavenCentral()
24+
}
25+
26+
dependencies {
27+
implementation(group = "org.lwjgl", name = "lwjgl", version = "3.2.2")
28+
runtimeOnly(group = "org.lwjgl", name = "lwjgl", version = "3.2.2", classifier = lwjglClassifier())
29+
30+
implementation(group = "org.lwjgl", name = "lwjgl-opengl", version = "3.2.2")
31+
runtimeOnly(group = "org.lwjgl", name = "lwjgl-opengl", version = "3.2.2", classifier = lwjglClassifier())
32+
33+
implementation(group = "org.lwjgl", name = "lwjgl-glfw", version = "3.2.2")
34+
runtimeOnly(group = "org.lwjgl", name = "lwjgl-glfw", version = "3.2.2", classifier = lwjglClassifier())
35+
36+
implementation(project(":ultralight-java-base"))
37+
implementation(project(":ultralight-java-databind"))
38+
implementation(project(":ultralight-java-gpu"))
39+
implementation(project(":ultralight-java-glfw-opengl-util"))
40+
41+
if (project.path != ":example:example-base") {
42+
implementation(project(":example:example-base"))
43+
}
44+
}
45+
46+
fun getBitName(): String {
47+
return if (System.getProperty("os.arch", "?").contains("64") ||
48+
System.getProperty("sun.arch.data.model", "?").contains("64")
49+
) {
50+
"64"
51+
} else {
52+
"32"
53+
}
54+
}
55+
56+
fun ultralightOsIdentifier(): String {
57+
return when {
58+
Os.isFamily(Os.FAMILY_WINDOWS) -> {
59+
"win-x${getBitName()}"
60+
}
61+
Os.isFamily(Os.FAMILY_MAC) -> {
62+
"mac-x${getBitName()}"
63+
}
64+
Os.isFamily(Os.FAMILY_UNIX) -> {
65+
"linux-x${getBitName()}"
66+
}
67+
else -> {
68+
throw UnsupportedOperationException("This OS is not supported")
69+
}
70+
}
71+
}
72+
73+
val runDir = file ("run")
74+
if (!runDir.exists() && !runDir.mkdirs()) {
75+
throw GradleException ("Failed to create run directory")
76+
}
77+
78+
79+
tasks.create("copyResources", Copy::class){
80+
println(File(project(":ultralight-java-native").buildDir, "cmake-gen-${ultralightOsIdentifier()}/ultralight-${ultralightOsIdentifier()}/bin"))
81+
from(File(project(":ultralight-java-native").buildDir, "cmake-gen-${ultralightOsIdentifier()}/ultralight-${ultralightOsIdentifier()}/bin"))
82+
include( "**/*.dll", "**/*.so", "**/*.dylib", "resources/*")
83+
into(runDir)
84+
}
85+
86+
tasks.getByName("run", JavaExec::class){
87+
workingDir = runDir
88+
dependsOn("copyResources")
89+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
plugins {
2+
id("ultralight-java.example-conventions")
3+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Ultralight Java - Java wrapper for the Ultralight web engine
3+
* Copyright (C) 2020 - 2021 LabyMedia and contributors
4+
*
5+
* This program is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation; either
8+
* version 3 of the License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18+
*/
19+
20+
package com.labymedia.ultralight.example.base;
21+
22+
import com.labymedia.ultralight.UltralightJava;
23+
import com.labymedia.ultralight.UltralightLoadException;
24+
import com.labymedia.ultralight.gpu.UltralightGPUDriverNativeUtil;
25+
import org.lwjgl.glfw.GLFW;
26+
27+
import java.io.File;
28+
import java.io.IOException;
29+
import java.nio.file.Files;
30+
import java.nio.file.Path;
31+
import java.nio.file.Paths;
32+
import java.nio.file.StandardCopyOption;
33+
34+
public abstract class UltralightExampleBase {
35+
36+
private final UltralightExampleConfiguration ultralightExampleConfiguration;
37+
38+
public UltralightExampleBase() {
39+
try {
40+
41+
this.ultralightExampleConfiguration = new UltralightExampleConfiguration();
42+
this.setupNatives();
43+
44+
this.configure(this.ultralightExampleConfiguration);
45+
46+
// Example resources
47+
extractResources();
48+
this.begin();
49+
} catch (UltralightLoadException exception) {
50+
//Process will end here. Just wrapped in a RuntimeException so no example has to create a constructor
51+
throw new RuntimeException(exception);
52+
}
53+
}
54+
55+
private void setupNatives() throws UltralightLoadException {
56+
// Get a directory to put natives into
57+
Path nativesDir = Paths.get(".");
58+
59+
// Get the existing native library path
60+
String libraryPath = System.getProperty("java.library.path");
61+
if (libraryPath != null) {
62+
// There is a path set already, append our natives dir
63+
libraryPath += File.pathSeparator + nativesDir.toAbsolutePath().toString();
64+
} else {
65+
// There is no path set, make our natives dir the current path
66+
libraryPath = nativesDir.toAbsolutePath().toString();
67+
}
68+
69+
// Set the path back
70+
System.setProperty("java.library.path", libraryPath);
71+
72+
// Extract the natives
73+
//
74+
// This only extracts the native library for ultralight-java-base, but not the other Ultralight libraries.
75+
// It is your task to get them into the run directory, possibly by extracting them on your own.
76+
UltralightJava.extractNativeLibrary(nativesDir);
77+
78+
// Load the native libraries from the given directory. This method makes sure everything is loaded in the
79+
// correct order. If you want to manually load all natives, either don't use this function or pass 'false' as
80+
// the second parameter.
81+
UltralightJava.load(nativesDir);
82+
UltralightGPUDriverNativeUtil.extractAndLoadNativeLibraries(nativesDir);
83+
84+
}
85+
86+
public void configure(UltralightExampleConfiguration ultralightExampleConfiguration) {
87+
}
88+
89+
public void begin() {
90+
}
91+
92+
/**
93+
* Helper function to set up the run directory with jar resources.
94+
*/
95+
private void extractResources() {
96+
try {
97+
for (String path : this.ultralightExampleConfiguration.getResourcesToExtract()) {
98+
Files.copy(
99+
UltralightExampleBase.class.getResourceAsStream("/" + path),
100+
Paths.get("./" + path),
101+
StandardCopyOption.REPLACE_EXISTING
102+
);
103+
}
104+
} catch (IOException e) {
105+
throw new RuntimeException(e);
106+
}
107+
}
108+
109+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Ultralight Java - Java wrapper for the Ultralight web engine
3+
* Copyright (C) 2020 - 2021 LabyMedia and contributors
4+
*
5+
* This program is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation; either
8+
* version 3 of the License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18+
*/
19+
20+
package com.labymedia.ultralight.example.base;
21+
22+
import java.util.Collection;
23+
import java.util.HashSet;
24+
25+
public class UltralightExampleConfiguration {
26+
27+
private final Collection<String> resourcesToExtract;
28+
29+
public UltralightExampleConfiguration() {
30+
this.resourcesToExtract = new HashSet<>();
31+
}
32+
33+
public UltralightExampleConfiguration extractResource(String path) {
34+
this.resourcesToExtract.add(path);
35+
return this;
36+
}
37+
38+
protected Collection<String> getResourcesToExtract() {
39+
return this.resourcesToExtract;
40+
}
41+
42+
}

example/lwjgl3-opengl/src/main/java/com/labymedia/ultralight/lwjgl3/opengl/ExampleApplication.java renamed to example/lwjgl3-opengl-old/src/main/java/com/labymedia/ultralight/lwjgl3/opengl/ExampleApplication.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public void run() {
234234
int frameCount = 0;
235235

236236
// Create the drawing helper, used to keep state for drawing the rotating triangle
237-
OpenGLDrawer drawer = new OpenGLDrawer();
237+
// OpenGLDrawer drawer = new OpenGLDrawer();
238238

239239
// Keep running until a window close is requested
240240
while (!glfwWindowShouldClose(window)) {
@@ -248,7 +248,7 @@ public void run() {
248248
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
249249

250250
// Draw the triangle and then Ultralight on top of it
251-
drawer.draw();
251+
// drawer.draw();
252252
webController.render();
253253

254254
// Super bad implementation of FPS display...

example/lwjgl3-opengl/src/main/java/com/labymedia/ultralight/lwjgl3/opengl/ExampleMain.java renamed to example/lwjgl3-opengl-old/src/main/java/com/labymedia/ultralight/lwjgl3/opengl/ExampleMain.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,8 @@ public static void main(String[] args) throws UltralightLoadException {
5959
// This only extracts the native library for ultralight-java-base, but not the other Ultralight libraries.
6060
// It is your task to get them into the run directory, possibly by extracting them on your own.
6161
UltralightJava.extractNativeLibrary(nativesDir);
62-
try {
63-
UltralightGPUDriverNativeUtil.extractAndLoadNativeLibraries(nativesDir);
64-
} catch (IOException exception) {
65-
throw new RuntimeException(exception);
66-
}
62+
63+
UltralightGPUDriverNativeUtil.load(nativesDir);
6764
// Load the native libraries from the given directory. This method makes sure everything is loaded in the
6865
// correct order. If you want to manually load all natives, either don't use this function or pass 'false' as
6966
// the second parameter.

0 commit comments

Comments
 (0)