diff --git a/platform/javascript/SCsub b/platform/javascript/SCsub index 22af436470f..59e5aa175d2 100644 --- a/platform/javascript/SCsub +++ b/platform/javascript/SCsub @@ -10,8 +10,6 @@ javascript_files = [ "javascript_eval.cpp" ] -#obj = env.SharedObject('godot_javascript.cpp') - env_javascript = env.Clone() if env['target'] == "profile": env_javascript.Append(CPPFLAGS=['-DPROFILER_ENABLED']) @@ -21,9 +19,19 @@ for x in javascript_files: javascript_objects.append( env_javascript.Object( x ) ) env.Append(LINKFLAGS=["-s","EXPORTED_FUNCTIONS=\"['_main','_audio_server_mix_function','_main_after_fs_sync']\""]) +env.Append(LINKFLAGS=["--shell-file",'"platform/javascript/godot_shell.html"']) -prog = None +build = env.Program('#bin/godot',javascript_objects,PROGSUFFIX=env["PROGSUFFIX"]+".html") -#env_javascript.SharedLibrary("#platform/javascript/libgodot_javascript.so",[javascript_objects]) +def make_html_shell(target, source, env): + html_path = target[0].rstr() + assert html_path[:4] == 'bin/' + assert html_path[-5:] == '.html' + basename = html_path[4:-5] + with open(html_path, 'r+') as html_file: + fixed_html = html_file.read().replace('.html.mem', '.mem').replace(basename, '$GODOT_BASE') + html_file.seek(0) + html_file.truncate() + html_file.write(fixed_html) -env.Program('#bin/godot',javascript_objects,PROGSUFFIX=env["PROGSUFFIX"]+".html") +env.AddPostAction(build, Action(make_html_shell, "Creating HTML shell file")) diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py index b1277bfc05c..b6a6a453b33 100644 --- a/platform/javascript/detect.py +++ b/platform/javascript/detect.py @@ -18,6 +18,7 @@ def can_build(): def get_opts(): return [ + ['wasm','Compile to WebAssembly','no'], ['javascript_eval','Enable JavaScript eval interface','yes'], ] @@ -42,7 +43,6 @@ def configure(env): em_path=os.environ["EMSCRIPTEN_ROOT"] env['ENV']['PATH'] = em_path+":"+env['ENV']['PATH'] - env['CC'] = em_path+'/emcc' env['CXX'] = em_path+'/emcc' #env['AR'] = em_path+"/emar" @@ -77,14 +77,20 @@ def configure(env): env.Append(CPPFLAGS=['-DJAVASCRIPT_ENABLED', '-DUNIX_ENABLED', '-DPTHREAD_NO_RENAME', '-DNO_FCNTL','-DMPC_FIXED_POINT','-DTYPED_METHOD_BIND','-DNO_THREADS']) env.Append(CPPFLAGS=['-DGLES2_ENABLED']) env.Append(CPPFLAGS=['-DGLES_NO_CLIENT_ARRAYS']) - env.Append(CPPFLAGS=['-s','ASM_JS=1']) env.Append(CPPFLAGS=['-s','FULL_ES2=1']) # env.Append(CPPFLAGS=['-DANDROID_ENABLED', '-DUNIX_ENABLED','-DMPC_FIXED_POINT']) + if env['wasm'] == 'yes': + env.Append(LINKFLAGS=['-s','BINARYEN=1']) + env.Append(LINKFLAGS=['-s','\'BINARYEN_METHOD="native-wasm"\'']) + env["PROGSUFFIX"]+=".webassembly" + else: + env.Append(CPPFLAGS=['-s','ASM_JS=1']) + env.Append(LINKFLAGS=['-s','ASM_JS=1']) + if env['javascript_eval'] == 'yes': env.Append(CPPFLAGS=['-DJAVASCRIPT_EVAL_ENABLED']) - env.Append(LINKFLAGS=['-s','ASM_JS=1']) env.Append(LINKFLAGS=['-O2']) #env.Append(LINKFLAGS=['-g4']) diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp index f934916aa26..721aef3e505 100644 --- a/platform/javascript/export/export.cpp +++ b/platform/javascript/export/export.cpp @@ -180,9 +180,7 @@ void EditorExportPlatformJavaScript::_fix_html(Vector& p_html, const St String current_line = lines[i]; current_line = current_line.replace("$GODOT_TMEM",itos((1<<(max_memory+5))*1024*1024)); - 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_BASE",p_name); 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")); @@ -319,16 +317,19 @@ Error EditorExportPlatformJavaScript::export_project(const String& p_path, bool } if (file=="godot.js") { - //_fix_godot(data); file=p_path.get_file().basename()+".js"; } if (file=="godot.mem") { - //_fix_godot(data); file=p_path.get_file().basename()+".mem"; } + if (file=="godot.wasm") { + + file=p_path.get_file().basename()+".wasm"; + } + String dst = p_path.get_base_dir().plus_file(file); FileAccess *f=FileAccess::open(dst,FileAccess::WRITE); if (!f) { diff --git a/tools/dist/html_fs/godot.html b/platform/javascript/godot_shell.html similarity index 93% rename from tools/dist/html_fs/godot.html rename to platform/javascript/godot_shell.html index c354826e1f0..3170d2bb9ed 100644 --- a/tools/dist/html_fs/godot.html +++ b/platform/javascript/godot_shell.html @@ -351,24 +351,7 @@ }; }; //]]> - - + + {{{ SCRIPT }}}