diff options
25 files changed, 251 insertions, 190 deletions
diff --git a/SConstruct b/SConstruct index 10982211ac..c3ecdafd45 100644 --- a/SConstruct +++ b/SConstruct @@ -22,6 +22,7 @@ platform_flags = {} # flags for each platform active_platforms = [] active_platform_ids = [] platform_exporters = [] +platform_apis = [] global_defaults = [] for x in glob.glob("platform/*"): @@ -34,6 +35,8 @@ for x in glob.glob("platform/*"): if (os.path.exists(x + "/export/export.cpp")): platform_exporters.append(x[9:]) + if (os.path.exists(x + "/api/api.cpp")): + platform_apis.append(x[9:]) if (os.path.exists(x + "/globals/global_defaults.cpp")): global_defaults.append(x[9:]) if (detect.is_active()): @@ -215,6 +218,7 @@ env_base.Append(CPPPATH=['#core', '#core/math', '#editor', '#drivers', '#']) # configure ENV for platform env_base.platform_exporters = platform_exporters +env_base.platform_apis = platform_apis """ sys.path.append("./platform/"+env_base["platform"]) @@ -438,6 +442,7 @@ if selected_platform in platform_list: SConscript("editor/SCsub") SConscript("drivers/SCsub") + SConscript("platform/SCsub") SConscript("modules/SCsub") SConscript("main/SCsub") diff --git a/doc/classes/@GlobalScope.xml b/doc/classes/@GlobalScope.xml index 31a0d3ccef..d9bdf0e3cf 100644 --- a/doc/classes/@GlobalScope.xml +++ b/doc/classes/@GlobalScope.xml @@ -44,6 +44,8 @@ <member name="JSON" type="JSON" setter="" getter=""> [JSON] singleton </member> + <member name="JavaScript" type="JavaScript" setter="" getter=""> + </member> <member name="Marshalls" type="Reference" setter="" getter=""> [Marshalls] singleton </member> diff --git a/doc/classes/JavaScript.xml b/doc/classes/JavaScript.xml new file mode 100644 index 0000000000..9dd386f08e --- /dev/null +++ b/doc/classes/JavaScript.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="JavaScript" inherits="Object" category="Core" version="3.0-alpha"> + <brief_description> + Singleton that connects the engine with the browser's JavaScript context in HTML5 export. + </brief_description> + <description> + The JavaScript singleton is implemented only in HTML5 export. It's used to access the browser's JavaScript context. This allows interaction with embedding pages or calling third-party JavaScript APIs. + </description> + <tutorials> + http://docs.godotengine.org/en/stable/learning/workflow/export/exporting_for_web.html#calling-javascript-from-script + </tutorials> + <demos> + </demos> + <methods> + <method name="eval"> + <return type="Variant"> + </return> + <argument index="0" name="code" type="String"> + </argument> + <argument index="1" name="use_global_execution_context" type="bool" default="false"> + </argument> + <description> + Execute the string [code]code[/code] as JavaScript code within the browser window. This is a call to the actual global JavaScript function [code]eval()[/code]. + If [code]use_global_execution_context[/code] is [code]true[/code], the code will be evaluated in the global execution context. Otherwise, it is evaluated in the execution context of a function within the engine's runtime environment. + </description> + </method> + </methods> + <constants> + </constants> +</class> diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 27f967cce7..dc747a55c7 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -4800,7 +4800,12 @@ EditorNode::EditorNode() { dock_tab_move_left->set_focus_mode(Control::FOCUS_NONE); dock_tab_move_left->connect("pressed", this, "_dock_move_left"); dock_hb->add_child(dock_tab_move_left); - dock_hb->add_spacer(); + + Label *dock_label = memnew(Label); + dock_label->set_text(TTR("Dock Position")); + dock_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); + dock_hb->add_child(dock_label); + dock_tab_move_right = memnew(ToolButton); dock_tab_move_right->set_icon(theme->get_icon("Forward", "EditorIcons")); dock_tab_move_right->set_focus_mode(Control::FOCUS_NONE); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 607ccaa4e7..85416a5700 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -1583,7 +1583,7 @@ void ScriptEditor::_update_script_names() { } } - if (_sort_list_on_update) { + if (_sort_list_on_update && !sedata.empty()) { sedata.sort(); // change actual order of tab_container so that the order can be rearranged by user diff --git a/main/main.cpp b/main/main.cpp index 3a87742528..023520017b 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -35,6 +35,7 @@ #include "message_queue.h" #include "modules/register_module_types.h" #include "os/os.h" +#include "platform/register_platform_apis.h" #include "project_settings.h" #include "scene/register_scene_types.h" #include "script_debugger_local.h" @@ -1108,6 +1109,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) { MAIN_PRINT("Main: Load Modules, Physics, Drivers, Scripts"); + register_platform_apis(); register_module_types(); initialize_physics(); @@ -1826,6 +1828,7 @@ void Main::cleanup() { unregister_driver_types(); unregister_module_types(); + unregister_platform_apis(); unregister_scene_types(); unregister_server_types(); diff --git a/methods.py b/methods.py index 6e4fecd67e..8fc7f87a41 100644 --- a/methods.py +++ b/methods.py @@ -1712,9 +1712,9 @@ def generate_vs_project(env, num_jobs): # to double quote off the directory. However, the path ends # in a backslash, so we need to remove this, lest it escape the # last double quote off, confusing MSBuild - env['MSVSBUILDCOM'] = build_commandline('scons --directory="$(ProjectDir.TrimEnd(\'\\\'))" platform=windows target=$(Configuration) tools=!tools! -j' + str(num_jobs)) - env['MSVSREBUILDCOM'] = build_commandline('scons --directory="$(ProjectDir.TrimEnd(\'\\\'))" platform=windows target=$(Configuration) tools=!tools! vsproj=yes -j' + str(num_jobs)) - env['MSVSCLEANCOM'] = build_commandline('scons --directory="$(ProjectDir.TrimEnd(\'\\\'))" --clean platform=windows target=$(Configuration) tools=!tools! -j' + str(num_jobs)) + env['MSVSBUILDCOM'] = build_commandline('scons --directory="$(ProjectDir.TrimEnd(\'\\\'))" platform=windows progress=no target=$(Configuration) tools=!tools! -j' + str(num_jobs)) + env['MSVSREBUILDCOM'] = build_commandline('scons --directory="$(ProjectDir.TrimEnd(\'\\\'))" platform=windows progress=no target=$(Configuration) tools=!tools! vsproj=yes -j' + str(num_jobs)) + env['MSVSCLEANCOM'] = build_commandline('scons --directory="$(ProjectDir.TrimEnd(\'\\\'))" --clean platform=windows progress=no target=$(Configuration) tools=!tools! -j' + str(num_jobs)) # This version information (Win32, x64, Debug, Release, Release_Debug seems to be # required for Visual Studio to understand that it needs to generate an NMAKE diff --git a/misc/dist/html/default.html b/misc/dist/html/default.html index 9fae34f97e..91193eea47 100644 --- a/misc/dist/html/default.html +++ b/misc/dist/html/default.html @@ -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) { diff --git a/modules/mono/mono_gd/gd_mono_field.cpp b/modules/mono/mono_gd/gd_mono_field.cpp index 1bee1115a6..eb34f9dd3f 100644 --- a/modules/mono/mono_gd/gd_mono_field.cpp +++ b/modules/mono/mono_gd/gd_mono_field.cpp @@ -41,7 +41,7 @@ void GDMonoField::set_value_raw(MonoObject *p_object, void *p_ptr) { void GDMonoField::set_value(MonoObject *p_object, const Variant &p_value) { #define SET_FROM_STRUCT_AND_BREAK(m_type) \ { \ - const m_type &val = p_value.operator m_type(); \ + const m_type &val = p_value.operator ::m_type(); \ MARSHALLED_OUT(m_type, val, raw); \ mono_field_set_value(p_object, mono_field, raw); \ break; \ diff --git a/modules/mono/mono_gd/gd_mono_marshal.cpp b/modules/mono/mono_gd/gd_mono_marshal.cpp index 9c415951bb..8bc2bb5096 100644 --- a/modules/mono/mono_gd/gd_mono_marshal.cpp +++ b/modules/mono/mono_gd/gd_mono_marshal.cpp @@ -36,7 +36,7 @@ namespace GDMonoMarshal { #define RETURN_BOXED_STRUCT(m_t, m_var_in) \ { \ - const m_t &m_in = m_var_in->operator m_t(); \ + const m_t &m_in = m_var_in->operator ::m_t(); \ MARSHALLED_OUT(m_t, m_in, raw); \ return mono_value_box(mono_domain_get(), CACHED_CLASS_RAW(m_t), raw); \ } diff --git a/platform/SCsub b/platform/SCsub new file mode 100644 index 0000000000..4ef23ab053 --- /dev/null +++ b/platform/SCsub @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +from compat import open_utf8 + +Import('env') +platform_sources = [] + +# Register platform-exclusive APIs +reg_apis_inc = '#include "register_platform_apis.h"\n' +reg_apis = 'void register_platform_apis() {\n' +unreg_apis = 'void unregister_platform_apis() {\n' +for platform in env.platform_apis: + platform_dir = env.Dir(platform) + platform_sources.append(platform_dir.File('api/api.cpp')) + reg_apis += '\tregister_' + platform + '_api();\n' + unreg_apis += '\tunregister_' + platform + '_api();\n' + reg_apis_inc += '#include "' + platform + '/api/api.h"\n' +reg_apis_inc += '\n' +reg_apis += '}\n\n' +unreg_apis += '}\n' +f = open_utf8('register_platform_apis.gen.cpp', 'w') +f.write(reg_apis_inc) +f.write(reg_apis) +f.write(unreg_apis) +f.close() +platform_sources.append('register_platform_apis.gen.cpp') + +env.Prepend(LIBS=env.Library('platform', platform_sources)) + +Export('env') diff --git a/platform/iphone/in_app_store.mm b/platform/iphone/in_app_store.mm index 9efd4b9891..25f4e1e166 100644 --- a/platform/iphone/in_app_store.mm +++ b/platform/iphone/in_app_store.mm @@ -92,6 +92,7 @@ void InAppStore::_bind_methods() { PoolRealArray prices; PoolStringArray ids; PoolStringArray localized_prices; + PoolStringArray currency_codes; for (int i = 0; i < [products count]; i++) { @@ -105,12 +106,14 @@ void InAppStore::_bind_methods() { prices.push_back([product.price doubleValue]); ids.push_back(String::utf8([product.productIdentifier UTF8String])); localized_prices.push_back(String::utf8([product.localizedPrice UTF8String])); + currency_codes.push_back(String::utf8([[[product priceLocale] objectForKey:NSLocaleCurrencyCode] UTF8String])); }; ret["titles"] = titles; ret["descriptions"] = descriptions; ret["prices"] = prices; ret["ids"] = ids; ret["localized_prices"] = localized_prices; + ret["currency_codes"] = currency_codes; PoolStringArray invalid_ids; diff --git a/platform/javascript/SCsub b/platform/javascript/SCsub index e3015d87b9..8d505a5829 100644 --- a/platform/javascript/SCsub +++ b/platform/javascript/SCsub @@ -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") diff --git a/platform/javascript/api/api.cpp b/platform/javascript/api/api.cpp new file mode 100644 index 0000000000..f2b2ca40bf --- /dev/null +++ b/platform/javascript/api/api.cpp @@ -0,0 +1,73 @@ +/*************************************************************************/ +/* api.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "api.h" +#include "engine.h" +#include "javascript_eval.h" + +static JavaScript *javascript_eval; + +void register_javascript_api() { + + ClassDB::register_virtual_class<JavaScript>(); + javascript_eval = memnew(JavaScript); + Engine::get_singleton()->add_singleton(Engine::Singleton("JavaScript", javascript_eval)); +} + +void unregister_javascript_api() { + + memdelete(javascript_eval); +} + +JavaScript *JavaScript::singleton = NULL; + +JavaScript *JavaScript::get_singleton() { + + return singleton; +} + +JavaScript::JavaScript() { + + ERR_FAIL_COND(singleton != NULL); + singleton = this; +} + +JavaScript::~JavaScript() {} + +void JavaScript::_bind_methods() { + + ClassDB::bind_method(D_METHOD("eval", "code", "use_global_execution_context"), &JavaScript::eval, DEFVAL(false)); +} + +#if !defined(JAVASCRIPT_ENABLED) || !defined(JAVASCRIPT_EVAL_ENABLED) +Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) { + + return Variant(); +} +#endif diff --git a/platform/javascript/api/api.h b/platform/javascript/api/api.h new file mode 100644 index 0000000000..53cd9239fc --- /dev/null +++ b/platform/javascript/api/api.h @@ -0,0 +1,31 @@ +/*************************************************************************/ +/* api.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +void register_javascript_api(); +void unregister_javascript_api(); diff --git a/platform/javascript/javascript_eval.h b/platform/javascript/api/javascript_eval.h index ed7cf383da..4d0b0b21ff 100644 --- a/platform/javascript/javascript_eval.h +++ b/platform/javascript/api/javascript_eval.h @@ -27,8 +27,6 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifdef JAVASCRIPT_EVAL_ENABLED - #ifndef JAVASCRIPT_EVAL_H #define JAVASCRIPT_EVAL_H @@ -52,4 +50,3 @@ public: }; #endif // JAVASCRIPT_EVAL_H -#endif // JAVASCRIPT_EVAL_ENABLED diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py index a2988d9c60..ba0b63a375 100644 --- a/platform/javascript/detect.py +++ b/platform/javascript/detect.py @@ -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']: diff --git a/platform/javascript/engine.js b/platform/javascript/engine.js index 99d1c20bbd..f3a7c49a95 100644 --- a/platform/javascript/engine.js +++ b/platform/javascript/engine.js @@ -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; }; diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp index 4a97bf4c32..d0d4b17874 100644 --- a/platform/javascript/export/export.cpp +++ b/platform/javascript/export/export.cpp @@ -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); diff --git a/platform/javascript/javascript_eval.cpp b/platform/javascript/javascript_eval.cpp index 1d737879f6..a755dcb5c4 100644 --- a/platform/javascript/javascript_eval.cpp +++ b/platform/javascript/javascript_eval.cpp @@ -29,16 +29,9 @@ /*************************************************************************/ #ifdef JAVASCRIPT_EVAL_ENABLED -#include "javascript_eval.h" +#include "api/javascript_eval.h" #include "emscripten.h" -JavaScript *JavaScript::singleton = NULL; - -JavaScript *JavaScript::get_singleton() { - - return singleton; -} - extern "C" EMSCRIPTEN_KEEPALIVE uint8_t *resize_poolbytearray_and_open_write(PoolByteArray *p_arr, PoolByteArray::Write *r_write, int p_len) { p_arr->resize(p_len); @@ -182,18 +175,4 @@ Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) { return Variant(); } -void JavaScript::_bind_methods() { - - ClassDB::bind_method(D_METHOD("eval", "code", "use_global_execution_context"), &JavaScript::eval, false); -} - -JavaScript::JavaScript() { - - ERR_FAIL_COND(singleton != NULL); - singleton = this; -} - -JavaScript::~JavaScript() { -} - #endif // JAVASCRIPT_EVAL_ENABLED diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index 77d81aec5d..c416baf0c9 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -512,11 +512,6 @@ void OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver, i #undef SET_EM_CALLBACK #undef EM_CHECK -#ifdef JAVASCRIPT_EVAL_ENABLED - javascript_eval = memnew(JavaScript); - Engine::get_singleton()->add_singleton(Engine::Singleton("JavaScript", javascript_eval)); -#endif - visual_server->init(); } diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h index f478f95dd2..85c185c10f 100644 --- a/platform/javascript/os_javascript.h +++ b/platform/javascript/os_javascript.h @@ -32,7 +32,6 @@ #include "audio_driver_javascript.h" #include "drivers/unix/os_unix.h" -#include "javascript_eval.h" #include "main/input_default.h" #include "os/input.h" #include "os/main_loop.h" @@ -67,10 +66,6 @@ class OS_JavaScript : public OS_Unix { PowerJavascript *power_manager; -#ifdef JAVASCRIPT_EVAL_ENABLED - JavaScript *javascript_eval; -#endif - static void _close_notification_funcs(const String &p_file, int p_flags); void process_joypads(); diff --git a/platform/javascript/pre_wasm.js b/platform/javascript/pre.js index be4383c8c9..311aa44fda 100644 --- a/platform/javascript/pre_wasm.js +++ b/platform/javascript/pre.js @@ -1,3 +1,2 @@ var Engine = { - USING_WASM: true, RuntimeEnvironment: function(Module) { diff --git a/platform/javascript/pre_asmjs.js b/platform/javascript/pre_asmjs.js deleted file mode 100644 index 3c497721b6..0000000000 --- a/platform/javascript/pre_asmjs.js +++ /dev/null @@ -1,3 +0,0 @@ -var Engine = { - USING_WASM: false, - RuntimeEnvironment: function(Module) { diff --git a/platform/register_platform_apis.h b/platform/register_platform_apis.h new file mode 100644 index 0000000000..37f98f6cd3 --- /dev/null +++ b/platform/register_platform_apis.h @@ -0,0 +1,36 @@ +/*************************************************************************/ +/* register_platform_apis.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef REGISTER_APIS_H +#define REGISTER_APIS_H + +void register_platform_apis(); +void unregister_platform_apis(); + +#endif |