You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-06 12:20:30 +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. - Enable lto support (saves ~2MiB in release). - Enable optional closure compiler pass for JS and generated code. - Enable optional pthreads support. - Can now build with tools=yes (not much to see yet). - Dropped some deprecated code for older toolchains.
This commit is contained in:
33
platform/javascript/engine/loader.js
Normal file
33
platform/javascript/engine/loader.js
Normal file
@@ -0,0 +1,33 @@
|
||||
var Loader = /** @constructor */ function() {
|
||||
|
||||
this.env = null;
|
||||
|
||||
this.init = function(loadPromise, basePath, config) {
|
||||
var me = this;
|
||||
return new Promise(function(resolve, reject) {
|
||||
var cfg = config || {};
|
||||
cfg['locateFile'] = Utils.createLocateRewrite(basePath);
|
||||
cfg['instantiateWasm'] = Utils.createInstantiatePromise(loadPromise);
|
||||
loadPromise = null;
|
||||
Godot(cfg).then(function(module) {
|
||||
me.env = module;
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
this.start = function(preloadedFiles, args) {
|
||||
var me = this;
|
||||
return new Promise(function(resolve, reject) {
|
||||
if (!me.env) {
|
||||
reject(new Error('The engine must be initialized before it can be started'));
|
||||
}
|
||||
preloadedFiles.forEach(function(file) {
|
||||
Utils.copyToFS(me.env['FS'], file.path, file.buffer);
|
||||
});
|
||||
preloadedFiles.length = 0; // Clear memory
|
||||
me.env['callMain'](args);
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user