Skip to content

Commit a987f30

Browse files
committed
Introduce the new approach to LWJGL support
By compiling JNI code to Wasm loadable modules
1 parent 561b8b8 commit a987f30

File tree

8 files changed

+14
-20
lines changed

8 files changed

+14
-20
lines changed

Diff for: _headers

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
/cheerpj-natives/natives/lwjgl.js
1+
/libraries/*
22
Content-Type: application/octet-stream

Diff for: index.html

+5-9
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
<h1>Browsercraft</h1>
1919
<div class="desktop-only">
2020
<div class="container">
21-
<canvas width="854" height="480" tabindex="-1"></canvas>
22-
<div class="display"></div>
2321
<div class="intro">
2422
<p>
2523
This is a proof-of-concept demo of Minecraft 1.2.5 running unmodified in the browser.
@@ -34,6 +32,7 @@ <h1>Browsercraft</h1>
3432
</div>
3533
</div>
3634
<progress style="display: none"></progress>
35+
<div class="display"></div>
3736
</div>
3837
<div class="pagecontrols">
3938
<a href="https://twitter.com/intent/tweet?url=https://browsercraft.cheerpj.com" title="Share on X (formerly known as Twitter)">
@@ -66,18 +65,13 @@ <h2>What this is not</h2>
6665

6766
<h2>How it works</h2>
6867
<p>
69-
<a href="https://labs.leaningtech.com/cheerpj3/guides/Implementing-Java-native-methods-in-JavaScript">CheerpJ supports specifying JavaScript implementations of Java native methods.</a>
70-
We use this feature to implement portions of LWJGL (a library used by Minecraft for rendering, audio, input, etc.) in JavaScript. On desktop, LWJGL uses C++ implementations of these methods.
71-
</p>
72-
<p>
73-
<a href="https://github.com/leaningtech/cheerpj-natives/blob/main/natives/lwjgl.js">View the LWJGL implementation.</a>
68+
<b>CheerpJ</b> is a Java Virtual Machine written in WebAssembly and it runs entirely in your browser. CheerpJ can run any Java application, without modification and without requiring the source code. This demo demonstrate these capabilities by running an older version (1.2.5) of Minecraft and LWJGL entirely in the browser.
7469
</p>
7570
<p>
7671
This project is a work-in-progress and not everything works yet. In particular:
7772
</p>
7873
<ul>
7974
<li>Audio is not supported</li>
80-
<li>Many textures are not rendered correctly</li>
8175
<li>Probably other subtle problems</li>
8276
</ul>
8377
<p>
@@ -102,7 +96,9 @@ <h2>How it works</h2>
10296
import MinecraftClient from "./minecraft-web.js";
10397
await cheerpjInit({
10498
version: 8,
105-
javaProperties: ["java.library.path=/app/cheerpj-natives/natives", "org.lwjgl.util.NoChecks=true"],
99+
javaProperties: ["java.library.path=/app/libraries/"],
100+
libraries: {"libGL.so.1": "/app/libraries/gl4es.wasm", "libEGL.so.1": "/app/libraries/libegl.wasm", "libGLESv2.so.1": "/app/libraries/libgles.wasm"},
101+
enableX11:true
106102
});
107103
const mc = new MinecraftClient();
108104
</script>

Diff for: libraries/gl4es.wasm

2.54 MB
Binary file not shown.

Diff for: libraries/libegl.wasm

227 KB
Binary file not shown.

Diff for: libraries/libgles.wasm

229 KB
Binary file not shown.

Diff for: libraries/lwjgl.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var r = await fetch("/libraries/lwjgl2.wasm");
2+
var buf = await r.arrayBuffer();
3+
export default
4+
{
5+
wasmModule: buf
6+
}

Diff for: libraries/lwjgl2.wasm

1.7 MB
Binary file not shown.

Diff for: minecraft-web.js

+2-10
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,13 @@ export default class MinecraftClient {
4646
this.#button = document.querySelector('button');
4747
this.#button.addEventListener('click', () => this.run());
4848

49-
this.#canvas = document.querySelector('canvas');
50-
this.#canvas.width = 854;
51-
this.#canvas.height = 480;
52-
this.#canvas.tabIndex = -1;
53-
this.#canvas.style.display = 'none';
5449
this.#progress = document.querySelector('progress');
5550
this.#progress.style.display = 'none';
5651

5752
this.#intro = document.querySelector('.intro');
5853

5954
// CheerpJ needs an element to render to
6055
this.#display = document.querySelector('.display');
61-
this.#display.setAttribute('style', 'width:100%;height:100%;position:absolute;top:0;left:0px;visibility:hidden;');
6256
cheerpjCreateDisplay(-1, -1, this.#display);
6357

6458
this.#isRunning = false;
@@ -84,12 +78,10 @@ export default class MinecraftClient {
8478
}
8579
);
8680
this.#progress.style.display = 'none';
81+
this.#display.style.display = 'unset';
8782

88-
this.#canvas.style.display = 'unset';
89-
window.lwjglCanvasElement = this.#canvas;
90-
const exitCode = await cheerpjRunMain("net.minecraft.client.Minecraft", `/app/lwjgl-2.9.0.jar:/app/lwjgl_util-2.9.0.jar:${jarPath}`)
83+
const exitCode = await cheerpjRunMain("net.minecraft.client.Minecraft", `/app/lwjgl-2.9.3.jar:/app/lwjgl_util-2.9.3.jar:${jarPath}`)
9184

92-
this.#canvas.style.display = 'none';
9385
this.#isRunning = false;
9486

9587
return exitCode;

0 commit comments

Comments
 (0)