Emit asm.js code into a dedicated file for asm.js export

This helps prevent browser lockups during start-up at the cost of having
to distribute an extra file.
This commit is contained in:
eska 2016-11-30 22:47:19 +01:00
parent 17422f1f86
commit 5ede1a1226
3 changed files with 30 additions and 14 deletions

View File

@ -91,6 +91,7 @@ def configure(env):
env.Append(LINKFLAGS=['--compression', lzma_binpath + "," + lzma_decoder + "," + lzma_dec])
env.Append(LINKFLAGS=['-s', 'ASM_JS=1'])
env.Append(LINKFLAGS=['--separate-asm'])
env.Append(LINKFLAGS=['-O2'])
# env.Append(LINKFLAGS=['-g4'])

View File

@ -183,6 +183,7 @@ void EditorExportPlatformJavaScript::_fix_html(Vector<uint8_t>& p_html, const St
current_line = current_line.replace("$GODOT_FS",p_name+"fs.js");
current_line = current_line.replace("$GODOT_MEM",p_name+".mem");
current_line = current_line.replace("$GODOT_JS",p_name+".js");
current_line = current_line.replace("$GODOT_ASM",p_name+".asm.js");
current_line = current_line.replace("$GODOT_CANVAS_WIDTH",Globals::get_singleton()->get("display/width"));
current_line = current_line.replace("$GODOT_CANVAS_HEIGHT",Globals::get_singleton()->get("display/height"));
current_line = current_line.replace("$GODOT_HEAD_TITLE",!html_title.empty()?html_title:(String) Globals::get_singleton()->get("application/name"));
@ -323,6 +324,11 @@ Error EditorExportPlatformJavaScript::export_project(const String& p_path, bool
file=p_path.get_file().basename()+".js";
}
if (file=="godot.asm.js") {
file=p_path.get_file().basename()+".asm.js";
}
if (file=="godot.mem") {
//_fix_godot(data);

View File

@ -354,21 +354,30 @@
<script type="text/javascript" src="$GODOT_FS"></script>
<script>
(function() {
var memoryInitializer = "$GODOT_MEM";
if (typeof Module.locateFile === "function") {
var script = document.createElement('script');
script.src = "$GODOT_ASM";
script.onload = function() {
setTimeout(function() {
(function() {
var memoryInitializer = '$GODOT_MEM';
if (typeof Module.locateFile === 'function') {
memoryInitializer = Module.locateFile(memoryInitializer);
} else if (Module.memoryInitializerPrefixURL) {
memoryInitializer = Module.memoryInitializerPrefixURL + memoryInitializer;
}
var xhr = Module.memoryInitializerRequest = new XMLHttpRequest();
xhr.open("GET", memoryInitializer, true);
xhr.responseType = "arraybuffer";
xhr.open('GET', memoryInitializer, true);
xhr.responseType = 'arraybuffer';
xhr.send(null);
})();
var script = document.createElement("script");
var script = document.createElement('script');
script.src = "$GODOT_JS";
document.body.appendChild(script);
}, 1); // delaying even 1ms is enough to allow compilation memory to be reclaimed
};
document.body.appendChild(script);
})();
</script>
</body>
</html>