From 228211a22bc34ccc915031c85a138287513417df Mon Sep 17 00:00:00 2001 From: paradust7 <102263465+paradust7@users.noreply.github.com> Date: Wed, 3 Jan 2024 09:37:12 +0000 Subject: [PATCH] Pull in merge of minetest & irrlicht upstream --- apply_patches.sh | 2 +- common.sh | 2 +- emsdk_emcc.patch | 12 ------------ emsdk_safeheap.patch | 45 ++++++++++++++++++++++++++++++++++++++++++++ fetch_sources.sh | 4 ++-- incremental.sh | 1 + install_emsdk.sh | 4 ++-- static/launcher.js | 14 +++++++------- 8 files changed, 59 insertions(+), 25 deletions(-) delete mode 100644 emsdk_emcc.patch create mode 100644 emsdk_safeheap.patch diff --git a/apply_patches.sh b/apply_patches.sh index 0e9a8f0..dcdb7b8 100755 --- a/apply_patches.sh +++ b/apply_patches.sh @@ -10,7 +10,7 @@ fi EMSDK_ROOT="$1" cd "$EMSDK_ROOT" -patch -p1 < "$BASE_DIR/emsdk_emcc.patch" +patch -p1 < "$BASE_DIR/emsdk_safeheap.patch" patch -p1 < "$BASE_DIR/emsdk_file_packager.patch" patch -p1 < "$BASE_DIR/emsdk_dirperms.patch" patch -p1 < "$BASE_DIR/emsdk_setlk.patch" diff --git a/common.sh b/common.sh index f64f259..63e1286 100644 --- a/common.sh +++ b/common.sh @@ -60,7 +60,7 @@ export MAKEFLAGS="-j$(nproc)" export CFLAGS="$COMMON_CFLAGS -pthread -sUSE_PTHREADS=1 -fexceptions" export CXXFLAGS="$COMMON_CFLAGS -pthread -sUSE_PTHREADS=1 -fexceptions" -export LDFLAGS="$COMMON_LDFLAGS -pthread -sUSE_PTHREADS=1 -fexceptions -sEXIT_RUNTIME" +export LDFLAGS="$COMMON_LDFLAGS -pthread -sUSE_PTHREADS=1 -fexceptions" export EMSDK_ROOT="$EMSDK" export EMSDK_SYSLIB="${EMSDK_ROOT}/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten" diff --git a/emsdk_emcc.patch b/emsdk_emcc.patch deleted file mode 100644 index a4f459a..0000000 --- a/emsdk_emcc.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff -urN emsdk/upstream/emscripten/emcc.py emsdk-fixed/upstream/emscripten/emcc.py ---- emsdk/upstream/emscripten/emcc.py 2022-11-07 20:04:28.000000000 +0000 -+++ emsdk-fixed/upstream/emscripten/emcc.py 2022-11-11 02:48:00.766940527 +0000 -@@ -632,6 +632,8 @@ - cmd = config.JS_ENGINES[0] - if settings.WASM_BIGINT: - cmd += shared.node_bigint_flags() -+ if settings.USE_PTHREADS: -+ cmd.append('--experimental-wasm-threads') - cmd = shared.shlex_join(cmd) - if not os.path.isabs(cmd[0]): - # TODO: use whereis etc. And how about non-*NIX? diff --git a/emsdk_safeheap.patch b/emsdk_safeheap.patch new file mode 100644 index 0000000..9b8cc87 --- /dev/null +++ b/emsdk_safeheap.patch @@ -0,0 +1,45 @@ +--- emsdk/upstream/emscripten/src/library_html5.js 2023-12-13 13:05:05.000000000 +0000 ++++ emsdk-fixed/upstream/emscripten/src/library_html5.js 2024-01-03 07:06:34.904379178 +0000 +@@ -476,16 +476,16 @@ + #if !DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR + if (Module['canvas']) { + var rect = getBoundingClientRect(Module['canvas']); +- HEAP32[idx + {{{ C_STRUCTS.EmscriptenMouseEvent.canvasX / 4 }}}] = e.clientX - rect.left; +- HEAP32[idx + {{{ C_STRUCTS.EmscriptenMouseEvent.canvasY / 4 }}}] = e.clientY - rect.top; ++ HEAP32[idx + {{{ C_STRUCTS.EmscriptenMouseEvent.canvasX / 4 }}}] = Math.round(e.clientX - rect.left); ++ HEAP32[idx + {{{ C_STRUCTS.EmscriptenMouseEvent.canvasY / 4 }}}] = Math.round(e.clientY - rect.top); + } else { // Canvas is not initialized, return 0. + HEAP32[idx + {{{ C_STRUCTS.EmscriptenMouseEvent.canvasX / 4 }}}] = 0; + HEAP32[idx + {{{ C_STRUCTS.EmscriptenMouseEvent.canvasY / 4 }}}] = 0; + } + #endif + var rect = getBoundingClientRect(target); +- HEAP32[idx + {{{ C_STRUCTS.EmscriptenMouseEvent.targetX / 4 }}}] = e.clientX - rect.left; +- HEAP32[idx + {{{ C_STRUCTS.EmscriptenMouseEvent.targetY / 4 }}}] = e.clientY - rect.top; ++ HEAP32[idx + {{{ C_STRUCTS.EmscriptenMouseEvent.targetX / 4 }}}] = Math.round(e.clientX - rect.left); ++ HEAP32[idx + {{{ C_STRUCTS.EmscriptenMouseEvent.targetY / 4 }}}] = Math.round(e.clientY - rect.top); + + #if MIN_SAFARI_VERSION <= 80000 || MIN_CHROME_VERSION <= 21 // https://caniuse.com/#search=movementX + #if MIN_CHROME_VERSION <= 76 +@@ -705,7 +705,9 @@ + #else + var uiEvent = JSEvents.uiEvent; + #endif +- {{{ makeSetValue('uiEvent', C_STRUCTS.EmscriptenUiEvent.detail, 'e.detail', 'i32') }}}; ++ let edetail = Math.round(e.detail); ++ if (Number.isNaN(edetail)) edetail = 0; ++ {{{ makeSetValue('uiEvent', C_STRUCTS.EmscriptenUiEvent.detail, 'edetail', 'i32') }}}; + {{{ makeSetValue('uiEvent', C_STRUCTS.EmscriptenUiEvent.documentBodyClientWidth, 'b.clientWidth', 'i32') }}}; + {{{ makeSetValue('uiEvent', C_STRUCTS.EmscriptenUiEvent.documentBodyClientHeight, 'b.clientHeight', 'i32') }}}; + {{{ makeSetValue('uiEvent', C_STRUCTS.EmscriptenUiEvent.windowInnerWidth, 'innerWidth', 'i32') }}}; +@@ -1944,8 +1946,8 @@ + HEAP32[idx + {{{ C_STRUCTS.EmscriptenTouchPoint.pageY / 4}}}] = t.pageY; + HEAP32[idx + {{{ C_STRUCTS.EmscriptenTouchPoint.isChanged / 4}}}] = t.isChanged; + HEAP32[idx + {{{ C_STRUCTS.EmscriptenTouchPoint.onTarget / 4}}}] = t.onTarget; +- HEAP32[idx + {{{ C_STRUCTS.EmscriptenTouchPoint.targetX / 4}}}] = t.clientX - targetRect.left; +- HEAP32[idx + {{{ C_STRUCTS.EmscriptenTouchPoint.targetY / 4}}}] = t.clientY - targetRect.top; ++ HEAP32[idx + {{{ C_STRUCTS.EmscriptenTouchPoint.targetX / 4}}}] = Math.round(t.clientX - targetRect.left); ++ HEAP32[idx + {{{ C_STRUCTS.EmscriptenTouchPoint.targetY / 4}}}] = Math.round(t.clientY - targetRect.top); + #if !DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR + HEAP32[idx + {{{ C_STRUCTS.EmscriptenTouchPoint.canvasX / 4}}}] = canvasRect ? t.clientX - canvasRect.left : 0; + HEAP32[idx + {{{ C_STRUCTS.EmscriptenTouchPoint.canvasY / 4}}}] = canvasRect ? t.clientY - canvasRect.top : 0; diff --git a/fetch_sources.sh b/fetch_sources.sh index 18cb206..904434e 100755 --- a/fetch_sources.sh +++ b/fetch_sources.sh @@ -31,8 +31,8 @@ getrepo minetest_game "https://github.com/minetest/minetest_game.git" 99a7193095 # These repos are part of the fork getrepo webshims "https://github.com/paradust7/webshims.git" 91c3fe85d2cb7f85cc8e19d3f53dc8f252a69ff7 -getrepo minetest "https://github.com/paradust7/minetest.git" 20368d3a8d797f06c1a33aeb660f9ca4f5798595 -getrepo irrlichtmt "https://github.com/paradust7/irrlicht.git" 5a79e1ae2bb0346e261152a21261af0531c2e4bf +getrepo minetest "https://github.com/paradust7/minetest.git" 126082a0a225836b2e584c8c5a8a43ea808d30a7 +getrepo irrlichtmt "https://github.com/paradust7/irrlicht.git" 883bbad7b70825258aec2a6e22860bd57596f7f8 # Make irrlichtmt symlink pushd "$SOURCES_DIR"/minetest/lib diff --git a/incremental.sh b/incremental.sh index 47366c0..171d318 100755 --- a/incremental.sh +++ b/incremental.sh @@ -4,4 +4,5 @@ export INCREMENTAL=true ./build_minetest.sh +./build_fsroot.sh ./build_www.sh diff --git a/install_emsdk.sh b/install_emsdk.sh index 193e7f1..f0e7104 100755 --- a/install_emsdk.sh +++ b/install_emsdk.sh @@ -8,8 +8,8 @@ rm -rf emsdk git clone https://github.com/emscripten-core/emsdk.git pushd emsdk -./emsdk install 3.1.25 -./emsdk activate 3.1.25 +./emsdk install 3.1.51 +./emsdk activate 3.1.51 popd ./apply_patches.sh emsdk diff --git a/static/launcher.js b/static/launcher.js index e4cc509..fb4bed2 100644 --- a/static/launcher.js +++ b/static/launcher.js @@ -276,7 +276,7 @@ function makeArgv(args) { const argv = _malloc((args.length + 1) * 4); let i; for (i = 0; i < args.length; i++) { - HEAPU32[(argv >>> 2) + i] = allocateUTF8(args[i]); + HEAPU32[(argv >>> 2) + i] = stringToNewUTF8(args[i]); } HEAPU32[(argv >>> 2) + i] = 0; // argv[argc] == NULL return [i, argv]; @@ -345,10 +345,10 @@ Module['printErr'] = Module['print']; // This probably should be the default behavior, but doesn't seem to be for WasmFS. const workerInject = ` Module['print'] = (text) => { - postMessage({cmd: 'print', text: text, threadId: Module['_pthread_self']()}); + postMessage({cmd: 'callHandler', handler: 'print', args: [text], threadId: Module['_pthread_self']()}); }; Module['printErr'] = (text) => { - postMessage({cmd: 'printErr', text: text, threadId: Module['_pthread_self']()}); + postMessage({cmd: 'callHandler', handler: 'printErr', args: [text], threadId: Module['_pthread_self']()}); }; importScripts('minetest.js'); `; @@ -662,7 +662,7 @@ class MinetestLauncher { HEAPU8.set(arr, data + offset); offset += arr.byteLength; } - emloop_install_pack(allocateUTF8(name), data, received); + emloop_install_pack(stringToNewUTF8(name), data, received); _free(data); mtScheduler.setCondition(installedCond); if (this.onprogress) { @@ -733,7 +733,7 @@ class MinetestLauncher { activateBody(); fixGeometry(); if (this.minetestConf) { - const confBuf = allocateUTF8(this.minetestConf) + const confBuf = stringToNewUTF8(this.minetestConf) emloop_set_minetest_conf(confBuf); _free(confBuf); } @@ -741,11 +741,11 @@ class MinetestLauncher { // Setup emsocket // TODO: emsocket should export the helpers for this emsocket_init(); - const proxyBuf = allocateUTF8(this.proxyUrl); + const proxyBuf = stringToNewUTF8(this.proxyUrl); emsocket_set_proxy(proxyBuf); _free(proxyBuf); if (this.vpn) { - const vpnBuf = allocateUTF8(this.vpn); + const vpnBuf = stringToNewUTF8(this.vpn); emsocket_set_vpn(vpnBuf); _free(vpnBuf); }