Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebXR: Update for Emscripten 3.1.71 and later #100489

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ repos:
- --config
- platform/web/eslint.config.cjs
additional_dependencies:
- 'https://github.com/adamscott/eslint-plugin-ignore-c-preprocessors/releases/download/0.1.1/godotengine-eslint-plugin-ignore-c-preprocessors-0.1.1.tgz'
- "@eslint/js@^9.3.0"
- "@html-eslint/eslint-plugin@^0.24.1"
- "@html-eslint/parser@^0.24.1"
Expand Down
3 changes: 3 additions & 0 deletions modules/webxr/native/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import config from "../../../platform/web/eslint.config.cjs";

export default config;
5 changes: 5 additions & 0 deletions modules/webxr/native/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"include": [
"./*.js",
]
}
26 changes: 21 additions & 5 deletions modules/webxr/native/library_godot_webxr.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,17 @@
/**************************************************************************/

const GodotWebXR = {
$GodotWebXR__deps: ['$Browser', '$GL', '$GodotRuntime', '$runtimeKeepalivePush', '$runtimeKeepalivePop'],
$GodotWebXR__deps: [
#if EMSCRIPTEN_VERSION_IS_LESS_THAN(3,1,71)
'$Browser',
#else
'$MainLoop',
#endif
'$GL',
'$GodotRuntime',
'$runtimeKeepalivePush',
'$runtimeKeepalivePop',
],
$GodotWebXR: {
gl: null,

Expand Down Expand Up @@ -63,24 +73,30 @@ const GodotWebXR = {
}
},
monkeyPatchRequestAnimationFrame: (enable) => {
#if EMSCRIPTEN_VERSION_IS_LESS_THAN(3,1,71)
const MainLoop = Browser;
#endif
if (GodotWebXR.orig_requestAnimationFrame === null) {
GodotWebXR.orig_requestAnimationFrame = Browser.requestAnimationFrame;
GodotWebXR.orig_requestAnimationFrame = MainLoop.requestAnimationFrame;
}
Browser.requestAnimationFrame = enable
MainLoop.requestAnimationFrame = enable
? GodotWebXR.requestAnimationFrame
: GodotWebXR.orig_requestAnimationFrame;
},
pauseResumeMainLoop: () => {
#if EMSCRIPTEN_VERSION_IS_LESS_THAN(3,1,71)
const MainLoop = Browser.mainLoop;
#endif
// Once both GodotWebXR.session and GodotWebXR.space are set or
// unset, our monkey-patched requestAnimationFrame() should be
// enabled or disabled. When using the WebXR API Emulator, this
// gets picked up automatically, however, in the Oculus Browser
// on the Quest, we need to pause and resume the main loop.
Browser.mainLoop.pause();
MainLoop.pause();
runtimeKeepalivePush();
window.setTimeout(function () {
runtimeKeepalivePop();
Browser.mainLoop.resume();
MainLoop.resume();
}, 0);
},

Expand Down
1 change: 1 addition & 0 deletions platform/web/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ if env["target"] == "editor":
env.add_source_files(web_files, "editor/*.cpp")

sys_env = env.Clone()
sys_env.AddJSLibraries(["js/libs/library_godot_macros.js"], prepend=True)
sys_env.AddJSLibraries(
[
"js/libs/library_godot_audio.js",
Expand Down
7 changes: 5 additions & 2 deletions platform/web/emscripten_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,11 @@ def get_template_zip_path(env):
return "#bin/.web_zip"


def add_js_libraries(env, libraries):
env.Append(JS_LIBS=env.File(libraries))
def add_js_libraries(env, libraries, prepend=False):
if prepend:
env.Prepend(JS_LIBS=env.File(libraries))
else:
env.Append(JS_LIBS=env.File(libraries))


def add_js_pre(env, js_pre):
Expand Down
6 changes: 6 additions & 0 deletions platform/web/eslint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const htmlPlugin = require('@html-eslint/eslint-plugin');
const pluginJs = require('@eslint/js');
const pluginReference = require('eslint-plugin-html');
const stylistic = require('@stylistic/eslint-plugin');
const pluginIgnoreCPreprocessors = require("@godotengine/eslint-plugin-ignore-c-preprocessors").default;

if (process && process.env && process.env.npm_command && !fs.existsSync('./platform/web/eslint.config.cjs')) {
throw Error('eslint must be run from the Godot project root folder');
Expand All @@ -21,6 +22,7 @@ const emscriptenGlobals = {
'HEAPU8': true,
'IDBFS': true,
'LibraryManager': true,
'MainLoop': true,
'Module': true,
'UTF8ToString': true,
'_emscripten_webgl_get_current_context': true,
Expand Down Expand Up @@ -139,6 +141,10 @@ module.exports = [
// libraries and modules (browser)
{
files: ['js/libs/**/*.js', 'platform/web/js/libs/**/*.js', 'modules/**/*.js'],
plugins: {
"ignore-c-preprocessors": pluginIgnoreCPreprocessors
},
processor: "ignore-c-preprocessors/ignore-c-preprocessors",
languageOptions: {
globals: {
...globals.browser,
Expand Down
40 changes: 40 additions & 0 deletions platform/web/js/libs/library_godot_macros.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* eslint-disable */
{{{
/* eslint-enable */
globalThis.___EMSCRIPTEN_VERSION_PARSED = globalThis.EMSCRIPTEN_VERSION.split('.').map((n) => parseInt(n, 10));

globalThis.___SEMVER_IS_GREATER_THAN = (a, b, { orEqual = false } = {}) => {
const [aMajor, aMinor, aPatch] = a;
const [bMajor, bMinor, bPatch] = b;
if ((orEqual && aMajor >= bMajor) || aMajor > bMajor) {
if ((orEqual && aMinor >= bMinor) || aMinor > bMinor) {
if ((orEqual && aPatch >= bPatch) || aPatch > bPatch) {
return true;
}
}
}
return false;
};

globalThis.EMSCRIPTEN_VERSION_IS_GREATER_THAN = (major, minor, patch) => {
const isGreater = globalThis.___SEMVER_IS_GREATER_THAN(globalThis.___EMSCRIPTEN_VERSION_PARSED, [major, minor, patch]);
return isGreater;
};

globalThis.EMSCRIPTEN_VERSION_IS_GREATER_THAN_OR_EQUAL = (major, minor, patch) => {
const isGreaterOrEqual = globalThis.___SEMVER_IS_GREATER_THAN(globalThis.___EMSCRIPTEN_VERSION_PARSED, [major, minor, patch], { orEqual: true });
return isGreaterOrEqual;
};

globalThis.EMSCRIPTEN_VERSION_IS_LESS_THAN = (major, minor, patch) => {
const isGreaterOrEqual = globalThis.___SEMVER_IS_GREATER_THAN(globalThis.___EMSCRIPTEN_VERSION_PARSED, [major, minor, patch], { orEqual: true });
return !isGreaterOrEqual;
};

globalThis.EMSCRIPTEN_VERSION_IS_LESS_THAN_OR_EQUAL = (major, minor, patch) => {
const isGreater = globalThis.___SEMVER_IS_GREATER_THAN(globalThis.___EMSCRIPTEN_VERSION_PARSED, [major, minor, patch]);
return !isGreater;
};
/* eslint-disable */
}}}
/* eslint-enable */
7 changes: 7 additions & 0 deletions platform/web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions platform/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"devDependencies": {
"@eslint/js": "^9.12.0",
"@godotengine/eslint-plugin-ignore-c-preprocessors": "github:adamscott/eslint-plugin-ignore-c-preprocessors",
"@html-eslint/eslint-plugin": "^0.27.0",
"@html-eslint/parser": "^0.27.0",
"@stylistic/eslint-plugin": "^2.9.0",
Expand Down
Loading