Remove asm.js support from HTML5 platform

Since WebGL 2.0 is required, requiring WebAssembly support as well has
little impact on compatibility.
This commit is contained in:
Leon Krause 2017-11-18 05:50:26 +01:00
parent 63283eca55
commit ddf21ca016
7 changed files with 25 additions and 148 deletions

View file

@ -230,7 +230,6 @@ $GODOT_HEAD_INCLUDE
(function() {
const BASENAME = '$GODOT_BASENAME';
const MEMORY_SIZE = $GODOT_TOTAL_MEMORY;
const DEBUG_ENABLED = $GODOT_DEBUG_ENABLED;
const INDETERMINATE_STATUS_STEP_MS = 100;
@ -247,7 +246,6 @@ $GODOT_HEAD_INCLUDE
setStatusMode('indeterminate');
game.setCanvas(canvas);
game.setAsmjsMemorySize(MEMORY_SIZE);
function setStatusMode(mode) {

View file

@ -21,37 +21,21 @@ for x in javascript_files:
env.Append(LINKFLAGS=["-s", "EXPORTED_FUNCTIONS=\"['_main','_main_after_fs_sync','_send_notification']\""])
# output file name without file extension
basename = "godot" + env["PROGSUFFIX"]
target_dir = env.Dir("#bin")
zip_dir = target_dir.Dir('.javascript_zip')
zip_files = env.InstallAs(zip_dir.File('godot.html'), '#misc/dist/html/default.html')
implicit_targets = []
if env['wasm']:
wasm = target_dir.File(basename + '.wasm')
implicit_targets.append(wasm)
zip_files.append(InstallAs(zip_dir.File('godot.wasm'), wasm))
prejs = env.File('pre_wasm.js')
else:
asmjs_files = [target_dir.File(basename + '.asm.js'), target_dir.File(basename + '.js.mem')]
implicit_targets.extend(asmjs_files)
zip_files.append(InstallAs([zip_dir.File('godot.asm.js'), zip_dir.File('godot.mem')], asmjs_files))
prejs = env.File('pre_asmjs.js')
js = env.Program(['#bin/godot'] + implicit_targets, javascript_objects, PROGSUFFIX=env['PROGSUFFIX'] + '.js')[0];
zip_files.append(InstallAs(zip_dir.File('godot.js'), js))
build = env.Program(['#bin/godot', target_dir.File('godot' + env['PROGSUFFIX'] + '.wasm')], javascript_objects, PROGSUFFIX=env['PROGSUFFIX'] + '.js');
js_libraries = []
js_libraries.append(env.File('http_request.js'))
for lib in js_libraries:
env.Append(LINKFLAGS=['--js-library', lib.path])
env.Depends(js, js_libraries)
env.Depends(build, js_libraries)
prejs = env.File('pre.js')
postjs = env.File('engine.js')
env.Depends(js, [prejs, postjs])
env.Append(LINKFLAGS=['--pre-js', prejs.path])
env.Append(LINKFLAGS=['--post-js', postjs.path])
env.Depends(build, [prejs, postjs])
zip_dir = target_dir.Dir('.javascript_zip')
zip_files = env.InstallAs([zip_dir.File('godot.js'), zip_dir.File('godot.wasm'), zip_dir.File('godot.html')], build + ['#misc/dist/html/default.html'])
Zip('#bin/godot', zip_files, ZIPSUFFIX=env['PROGSUFFIX'] + env['ZIPSUFFIX'], ZIPROOT=zip_dir, ZIPCOMSTR="Archving $SOURCES as $TARGET")

View file

@ -19,7 +19,6 @@ def can_build():
def get_opts():
from SCons.Variables import BoolVariable
return [
BoolVariable('wasm', 'Compile to WebAssembly', False),
BoolVariable('javascript_eval', 'Enable JavaScript eval interface', True),
]
@ -106,17 +105,11 @@ def configure(env):
env.Append(LINKFLAGS=['-s', 'EXTRA_EXPORTED_RUNTIME_METHODS="[\'FS\']"'])
env.Append(LINKFLAGS=['-s', 'USE_WEBGL2=1'])
if env['wasm']:
env.Append(LINKFLAGS=['-s', 'BINARYEN=1'])
# In contrast to asm.js, enabling memory growth on WebAssembly has no
# major performance impact, and causes only a negligible increase in
# memory size.
env.Append(LINKFLAGS=['-s', 'ALLOW_MEMORY_GROWTH=1'])
env.extra_suffix = '.webassembly' + env.extra_suffix
else:
env.Append(LINKFLAGS=['-s', 'ASM_JS=1'])
env.Append(LINKFLAGS=['--separate-asm'])
env.Append(LINKFLAGS=['--memory-init-file', '1'])
env.Append(LINKFLAGS=['-s', 'BINARYEN=1'])
# In contrast to asm.js, enabling memory growth on WebAssembly has no
# major performance impact, and causes only a negligible increase in
# memory size.
env.Append(LINKFLAGS=['-s', 'ALLOW_MEMORY_GROWTH=1'])
# TODO: Move that to opus module's config
if 'module_opus_enabled' in env and env['module_opus_enabled']:

View file

@ -5,7 +5,6 @@
(function() {
var engine = Engine;
var USING_WASM = engine.USING_WASM;
var DOWNLOAD_ATTEMPTS_MAX = 4;
var basePath = null;
@ -34,7 +33,6 @@
var gameInitPromise = null;
var unloadAfterInit = true;
var memorySize = 268435456;
var progressFunc = null;
var pckProgressTracker = {};
@ -91,10 +89,6 @@
});
return {};
};
} else if (initializer.asm && initializer.mem) {
rtenvOpts.asm = initializer.asm;
rtenvOpts.memoryInitializerRequest = initializer.mem;
rtenvOpts.TOTAL_MEMORY = memorySize;
} else {
throw new Error("Invalid initializer");
}
@ -190,10 +184,6 @@
canvas = elem;
};
this.setAsmjsMemorySize = function(size) {
memorySize = size;
};
this.setUnloadAfterInit = function(enabled) {
if (enabled && !unloadAfterInit && gameInitPromise) {
@ -236,22 +226,12 @@
if (newBasePath !== undefined) basePath = getBasePath(newBasePath);
if (engineLoadPromise === null) {
if (USING_WASM) {
if (typeof WebAssembly !== 'object')
return Promise.reject(new Error("Browser doesn't support WebAssembly"));
// TODO cache/retrieve module to/from idb
engineLoadPromise = loadPromise(basePath + '.wasm').then(function(xhr) {
return xhr.response;
});
} else {
var asmjsPromise = loadPromise(basePath + '.asm.js').then(function(xhr) {
return asmjsModulePromise(xhr.response);
});
var memPromise = loadPromise(basePath + '.mem');
engineLoadPromise = Promise.all([asmjsPromise, memPromise]).then(function(values) {
return { asm: values[0], mem: values[1] };
});
}
if (typeof WebAssembly !== 'object')
return Promise.reject(new Error("Browser doesn't support WebAssembly"));
// TODO cache/retrieve module to/from idb
engineLoadPromise = loadPromise(basePath + '.wasm').then(function(xhr) {
return xhr.response;
});
engineLoadPromise = engineLoadPromise.catch(function(err) {
engineLoadPromise = null;
throw err;
@ -260,33 +240,6 @@
return engineLoadPromise;
};
function asmjsModulePromise(module) {
var elem = document.createElement('script');
var script = new Blob([
'Engine.asm = (function() { var Module = {};',
module,
'return Module.asm; })();'
]);
var url = URL.createObjectURL(script);
elem.src = url;
return new Promise(function(resolve, reject) {
elem.addEventListener('load', function() {
URL.revokeObjectURL(url);
var asm = Engine.asm;
Engine.asm = undefined;
setTimeout(function() {
// delay to reclaim compilation memory
resolve(asm);
}, 1);
});
elem.addEventListener('error', function() {
URL.revokeObjectURL(url);
reject("asm.js faiilure");
});
document.body.appendChild(elem);
});
}
Engine.unloadEngine = function() {
engineLoadPromise = null;
};

View file

@ -35,8 +35,6 @@
#define EXPORT_TEMPLATE_WEBASSEMBLY_RELEASE "webassembly_release.zip"
#define EXPORT_TEMPLATE_WEBASSEMBLY_DEBUG "webassembly_debug.zip"
#define EXPORT_TEMPLATE_ASMJS_RELEASE "javascript_release.zip"
#define EXPORT_TEMPLATE_ASMJS_DEBUG "javascript_debug.zip"
class EditorExportPlatformJavaScript : public EditorExportPlatform {
@ -47,18 +45,11 @@ class EditorExportPlatformJavaScript : public EditorExportPlatform {
bool runnable_when_last_polled;
void _fix_html(Vector<uint8_t> &p_html, const Ref<EditorExportPreset> &p_preset, const String &p_name, bool p_debug);
void _fix_fsloader_js(Vector<uint8_t> &p_js, const String &p_pack_name, uint64_t p_pack_size);
public:
enum Target {
TARGET_WEBASSEMBLY,
TARGET_ASMJS
};
virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features);
virtual void get_export_options(List<ExportOption> *r_options);
virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const;
virtual String get_name() const;
virtual String get_os_name() const;
@ -90,17 +81,9 @@ void EditorExportPlatformJavaScript::_fix_html(Vector<uint8_t> &p_html, const Re
String str_export;
Vector<String> lines = str_template.split("\n");
int memory_mb;
if (p_preset->get("options/target").operator int() != TARGET_ASMJS)
// WebAssembly allows memory growth, so start with a reasonable default
memory_mb = 1 << 4;
else
memory_mb = 1 << (p_preset->get("options/memory_size").operator int() + 5);
for (int i = 0; i < lines.size(); i++) {
String current_line = lines[i];
current_line = current_line.replace("$GODOT_TOTAL_MEMORY", itos(memory_mb * 1024 * 1024));
current_line = current_line.replace("$GODOT_BASENAME", p_name);
current_line = current_line.replace("$GODOT_HEAD_INCLUDE", p_preset->get("html/head_include"));
current_line = current_line.replace("$GODOT_DEBUG_ENABLED", p_debug ? "true" : "false");
@ -129,8 +112,6 @@ void EditorExportPlatformJavaScript::get_preset_features(const Ref<EditorExportP
void EditorExportPlatformJavaScript::get_export_options(List<ExportOption> *r_options) {
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "options/target", PROPERTY_HINT_ENUM, "WebAssembly,asm.js"), TARGET_WEBASSEMBLY));
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "options/memory_size", PROPERTY_HINT_ENUM, "32 MB,64 MB,128 MB,256 MB,512 MB,1 GB"), 3));
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/s3tc"), false));
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc"), true));
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc2"), false));
@ -139,14 +120,6 @@ void EditorExportPlatformJavaScript::get_export_options(List<ExportOption> *r_op
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "zip"), ""));
}
bool EditorExportPlatformJavaScript::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const {
if (p_option == "options/memory_size") {
return p_options["options/target"].operator int() == TARGET_ASMJS;
}
return true;
}
String EditorExportPlatformJavaScript::get_name() const {
return "HTML5";
@ -166,17 +139,10 @@ bool EditorExportPlatformJavaScript::can_export(const Ref<EditorExportPreset> &p
r_missing_templates = false;
if (p_preset->get("options/target").operator int() == TARGET_WEBASSEMBLY) {
if (find_export_template(EXPORT_TEMPLATE_WEBASSEMBLY_RELEASE) == String())
r_missing_templates = true;
else if (find_export_template(EXPORT_TEMPLATE_WEBASSEMBLY_DEBUG) == String())
r_missing_templates = true;
} else {
if (find_export_template(EXPORT_TEMPLATE_ASMJS_RELEASE) == String())
r_missing_templates = true;
else if (find_export_template(EXPORT_TEMPLATE_ASMJS_DEBUG) == String())
r_missing_templates = true;
}
if (find_export_template(EXPORT_TEMPLATE_WEBASSEMBLY_RELEASE) == String())
r_missing_templates = true;
else if (find_export_template(EXPORT_TEMPLATE_WEBASSEMBLY_DEBUG) == String())
r_missing_templates = true;
return !r_missing_templates;
}
@ -197,17 +163,10 @@ Error EditorExportPlatformJavaScript::export_project(const Ref<EditorExportPrese
if (template_path == String()) {
if (p_preset->get("options/target").operator int() == TARGET_WEBASSEMBLY) {
if (p_debug)
template_path = find_export_template(EXPORT_TEMPLATE_WEBASSEMBLY_DEBUG);
else
template_path = find_export_template(EXPORT_TEMPLATE_WEBASSEMBLY_RELEASE);
} else {
if (p_debug)
template_path = find_export_template(EXPORT_TEMPLATE_ASMJS_DEBUG);
else
template_path = find_export_template(EXPORT_TEMPLATE_ASMJS_RELEASE);
}
if (p_debug)
template_path = find_export_template(EXPORT_TEMPLATE_WEBASSEMBLY_DEBUG);
else
template_path = find_export_template(EXPORT_TEMPLATE_WEBASSEMBLY_RELEASE);
}
if (template_path != String() && !FileAccess::exists(template_path)) {
@ -270,12 +229,6 @@ Error EditorExportPlatformJavaScript::export_project(const Ref<EditorExportPrese
} else if (file == "godot.wasm") {
file = p_path.get_file().get_basename() + ".wasm";
} else if (file == "godot.asm.js") {
file = p_path.get_file().get_basename() + ".asm.js";
} else if (file == "godot.mem") {
file = p_path.get_file().get_basename() + ".mem";
}
String dst = p_path.get_base_dir().plus_file(file);

View file

@ -1,3 +1,2 @@
var Engine = {
USING_WASM: true,
RuntimeEnvironment: function(Module) {

View file

@ -1,3 +0,0 @@
var Engine = {
USING_WASM: false,
RuntimeEnvironment: function(Module) {