mirror of
https://github.com/godotengine/godot.git
synced 2025-10-31 21:51:22 +00:00
[HTML5] Refactor JS, threads support, closures.
- Refactored the Engine code, splitted across files. - Use MODULARIZE option to build emscripten code into it's own closure. - Optional closure compiler run for JS and generated code. - Enable lto support (saves ~2MiB in release). - Can now build with tools=yes (not much to see yet). - Dropped some deprecated code for older toolchains. - Add onExit, and onExecute JS function. - Add files drag and drop support. - Add support for low precessor usage mode (via offscreen render, swap).
This commit is contained in:
parent
93e20a4cd4
commit
21c9f37757
18 changed files with 1097 additions and 627 deletions
51
platform/javascript/engine/utils.js
Normal file
51
platform/javascript/engine/utils.js
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
var Utils = {
|
||||
|
||||
createLocateRewrite: function(execName) {
|
||||
function rw(path) {
|
||||
if (path.endsWith('.worker.js')) {
|
||||
return execName + '.worker.js';
|
||||
} else if (path.endsWith('.js')) {
|
||||
return execName + '.js';
|
||||
} else if (path.endsWith('.wasm')) {
|
||||
return execName + '.wasm';
|
||||
}
|
||||
}
|
||||
return rw;
|
||||
},
|
||||
|
||||
createInstantiatePromise: function(wasmLoader) {
|
||||
function instantiateWasm(imports, onSuccess) {
|
||||
wasmLoader.then(function(xhr) {
|
||||
WebAssembly.instantiate(xhr.response, imports).then(function(result) {
|
||||
onSuccess(result['instance'], result['module']);
|
||||
});
|
||||
});
|
||||
wasmLoader = null;
|
||||
return {};
|
||||
};
|
||||
|
||||
return instantiateWasm;
|
||||
},
|
||||
|
||||
findCanvas: function() {
|
||||
var nodes = document.getElementsByTagName('canvas');
|
||||
if (nodes.length && nodes[0] instanceof HTMLCanvasElement) {
|
||||
return nodes[0];
|
||||
}
|
||||
throw new Error("No canvas found");
|
||||
},
|
||||
|
||||
isWebGLAvailable: function(majorVersion = 1) {
|
||||
|
||||
var testContext = false;
|
||||
try {
|
||||
var testCanvas = document.createElement('canvas');
|
||||
if (majorVersion === 1) {
|
||||
testContext = testCanvas.getContext('webgl') || testCanvas.getContext('experimental-webgl');
|
||||
} else if (majorVersion === 2) {
|
||||
testContext = testCanvas.getContext('webgl2') || testCanvas.getContext('experimental-webgl2');
|
||||
}
|
||||
} catch (e) {}
|
||||
return !!testContext;
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue