919bbf8077
- 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.
33 lines
888 B
JavaScript
33 lines
888 B
JavaScript
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();
|
|
});
|
|
}
|
|
};
|