From fa219e02d74f9b249270b6610a88319925908f89 Mon Sep 17 00:00:00 2001 From: eska Date: Fri, 21 Oct 2016 00:02:44 +0200 Subject: Remove JavaScript compilation option `compress`. This functionality has been removed from Emscripten in version 1.36.13, server-side compression is recommended instead. --- platform/javascript/detect.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'platform/javascript') diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py index aeff5a1a34..7144476302 100644 --- a/platform/javascript/detect.py +++ b/platform/javascript/detect.py @@ -18,8 +18,7 @@ def can_build(): def get_opts(): return [ - ['compress','Compress JS Executable','no'], - ['javascript_eval','Enable JavaScript eval interface','yes'] + ['javascript_eval','Enable JavaScript eval interface','yes'], ] def get_flags(): @@ -94,12 +93,6 @@ def configure(env): if env['javascript_eval'] == 'yes': env.Append(CPPFLAGS=['-DJAVASCRIPT_EVAL_ENABLED']) - if (env["compress"]=="yes"): - lzma_binpath = em_path+"/third_party/lzma.js/lzma-native" - lzma_decoder = em_path+"/third_party/lzma.js/lzma-decoder.js" - lzma_dec = "LZMA.decompress" - env.Append(LINKFLAGS=['--compression',lzma_binpath+","+lzma_decoder+","+lzma_dec]) - env.Append(LINKFLAGS=['-s','ASM_JS=1']) env.Append(LINKFLAGS=['-O2']) #env.Append(LINKFLAGS=['-g4']) -- cgit v1.2.3 From d6f2862429399844ebdd16b61da3a3c9d14fba36 Mon Sep 17 00:00:00 2001 From: eska Date: Sun, 30 Oct 2016 23:10:17 +0100 Subject: Add option 'wasm' to compile to WebAssembly in web export WebAssembly is still experimental, so disabled by default. The HTML shell file now uses $GODOT_BASE, a placeholder for the base filename, instead of $GODOT_JS, $GODOT_MEM and $GODOT_FS. --- platform/javascript/SCsub | 24 ++- platform/javascript/detect.py | 12 +- platform/javascript/export/export.cpp | 11 +- platform/javascript/godot_shell.html | 357 ++++++++++++++++++++++++++++++++++ 4 files changed, 388 insertions(+), 16 deletions(-) create mode 100644 platform/javascript/godot_shell.html (limited to 'platform/javascript') diff --git a/platform/javascript/SCsub b/platform/javascript/SCsub index 22af436470..59e5aa175d 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']\""]) - -prog = None - -#env_javascript.SharedLibrary("#platform/javascript/libgodot_javascript.so",[javascript_objects]) - -env.Program('#bin/godot',javascript_objects,PROGSUFFIX=env["PROGSUFFIX"]+".html") +env.Append(LINKFLAGS=["--shell-file",'"platform/javascript/godot_shell.html"']) + +build = env.Program('#bin/godot',javascript_objects,PROGSUFFIX=env["PROGSUFFIX"]+".html") + +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.AddPostAction(build, Action(make_html_shell, "Creating HTML shell file")) diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py index b1277bfc05..b6a6a453b3 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 f934916aa2..721aef3e50 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/platform/javascript/godot_shell.html b/platform/javascript/godot_shell.html new file mode 100644 index 0000000000..3170d2bb9e --- /dev/null +++ b/platform/javascript/godot_shell.html @@ -0,0 +1,357 @@ + + + + + $GODOT_HEAD_TITLE + $GODOT_HEAD_INCLUDE + + + +
+ + HTML5 canvas appears to be unsupported in the current browser.
Please try updating or use a different browser. +
+
+ Loading page... +
+
+ + + +
+
+ + + + + + {{{ SCRIPT }}} + + -- cgit v1.2.3 From 97c8508f5e4f57b1048830d44e76e1f4517fd449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Sun, 30 Oct 2016 18:44:57 +0100 Subject: style: Start applying PEP8 to Python files, indentation issues Done with `autopep8 --select=E1`, fixes: - E101 - Reindent all lines. - E112 - Fix under-indented comments. - E113 - Fix over-indented comments. - E115 - Fix under-indented comments. - E116 - Fix over-indented comments. - E121 - Fix a badly indented line. - E122 - Fix a badly indented line. - E123 - Fix a badly indented line. - E124 - Fix a badly indented line. - E125 - Fix indentation undistinguish from the next logical line. - E126 - Fix a badly indented line. - E127 - Fix a badly indented line. - E128 - Fix a badly indented line. - E129 - Fix a badly indented line. --- platform/javascript/SCsub | 14 ++--- platform/javascript/detect.py | 136 +++++++++++++++++++++--------------------- 2 files changed, 75 insertions(+), 75 deletions(-) (limited to 'platform/javascript') diff --git a/platform/javascript/SCsub b/platform/javascript/SCsub index 59e5aa175d..07852ac206 100644 --- a/platform/javascript/SCsub +++ b/platform/javascript/SCsub @@ -3,20 +3,20 @@ Import('env') javascript_files = [ - "os_javascript.cpp", - "audio_driver_javascript.cpp", - "javascript_main.cpp", - "audio_server_javascript.cpp", - "javascript_eval.cpp" + "os_javascript.cpp", + "audio_driver_javascript.cpp", + "javascript_main.cpp", + "audio_server_javascript.cpp", + "javascript_eval.cpp" ] env_javascript = env.Clone() if env['target'] == "profile": - env_javascript.Append(CPPFLAGS=['-DPROFILER_ENABLED']) + env_javascript.Append(CPPFLAGS=['-DPROFILER_ENABLED']) javascript_objects=[] for x in javascript_files: - javascript_objects.append( env_javascript.Object( x ) ) + 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"']) diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py index b6a6a453b3..ce6149c250 100644 --- a/platform/javascript/detect.py +++ b/platform/javascript/detect.py @@ -3,103 +3,103 @@ import sys import string def is_active(): - return True + return True def get_name(): - return "JavaScript" + return "JavaScript" def can_build(): - import os - if (not os.environ.has_key("EMSCRIPTEN_ROOT")): - return False - return True + import os + if (not os.environ.has_key("EMSCRIPTEN_ROOT")): + return False + return True def get_opts(): - return [ - ['wasm','Compile to WebAssembly','no'], - ['javascript_eval','Enable JavaScript eval interface','yes'], - ] + return [ + ['wasm','Compile to WebAssembly','no'], + ['javascript_eval','Enable JavaScript eval interface','yes'], + ] def get_flags(): - return [ - ('tools', 'no'), - ('builtin_zlib', 'yes'), - ('module_etc1_enabled', 'no'), - ('module_mpc_enabled', 'no'), - ('module_theora_enabled', 'no'), - ] + return [ + ('tools', 'no'), + ('builtin_zlib', 'yes'), + ('module_etc1_enabled', 'no'), + ('module_mpc_enabled', 'no'), + ('module_theora_enabled', 'no'), + ] def configure(env): - env['ENV'] = os.environ; - env.use_windows_spawn_fix('javascript') + env['ENV'] = os.environ; + env.use_windows_spawn_fix('javascript') - env.Append(CPPPATH=['#platform/javascript']) + env.Append(CPPPATH=['#platform/javascript']) - em_path=os.environ["EMSCRIPTEN_ROOT"] + 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" - env['AR'] = em_path+"/emcc" - env['ARFLAGS'] = "-o" + env['ENV']['PATH'] = em_path+":"+env['ENV']['PATH'] + env['CC'] = em_path+'/emcc' + env['CXX'] = em_path+'/emcc' + #env['AR'] = em_path+"/emar" + env['AR'] = em_path+"/emcc" + env['ARFLAGS'] = "-o" # env['RANLIB'] = em_path+"/emranlib" - env['RANLIB'] = em_path + "/emcc" - env['OBJSUFFIX'] = '.bc' - env['LIBSUFFIX'] = '.bc' - env['CCCOM'] = "$CC -o $TARGET $CFLAGS $CCFLAGS $_CCCOMCOM $SOURCES" - env['CXXCOM'] = "$CC -o $TARGET $CFLAGS $CCFLAGS $_CCCOMCOM $SOURCES" + env['RANLIB'] = em_path + "/emcc" + env['OBJSUFFIX'] = '.bc' + env['LIBSUFFIX'] = '.bc' + env['CCCOM'] = "$CC -o $TARGET $CFLAGS $CCFLAGS $_CCCOMCOM $SOURCES" + env['CXXCOM'] = "$CC -o $TARGET $CFLAGS $CCFLAGS $_CCCOMCOM $SOURCES" # env.Append(LIBS=['c','m','stdc++','log','GLESv1_CM','GLESv2']) # env["LINKFLAGS"]= string.split(" -g --sysroot="+ld_sysroot+" -Wl,--no-undefined -Wl,-z,noexecstack ") - if (env["target"]=="release"): - env.Append(CCFLAGS=['-O2']) - elif (env["target"]=="release_debug"): - env.Append(CCFLAGS=['-O2','-DDEBUG_ENABLED']) - elif (env["target"]=="debug"): - env.Append(CCFLAGS=['-D_DEBUG', '-Wall', '-O2', '-DDEBUG_ENABLED']) - #env.Append(CCFLAGS=['-D_DEBUG', '-Wall', '-g4', '-DDEBUG_ENABLED']) - env.Append(CPPFLAGS=['-DDEBUG_MEMORY_ALLOC']) - - # TODO: Move that to opus module's config - if("module_opus_enabled" in env and env["module_opus_enabled"] != "no"): - env.opus_fixed_point = "yes" - - env.Append(CPPFLAGS=["-fno-exceptions",'-DNO_SAFE_CAST','-fno-rtti']) - 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','FULL_ES2=1']) + if (env["target"]=="release"): + env.Append(CCFLAGS=['-O2']) + elif (env["target"]=="release_debug"): + env.Append(CCFLAGS=['-O2','-DDEBUG_ENABLED']) + elif (env["target"]=="debug"): + env.Append(CCFLAGS=['-D_DEBUG', '-Wall', '-O2', '-DDEBUG_ENABLED']) + #env.Append(CCFLAGS=['-D_DEBUG', '-Wall', '-g4', '-DDEBUG_ENABLED']) + env.Append(CPPFLAGS=['-DDEBUG_MEMORY_ALLOC']) + + # TODO: Move that to opus module's config + if("module_opus_enabled" in env and env["module_opus_enabled"] != "no"): + env.opus_fixed_point = "yes" + + env.Append(CPPFLAGS=["-fno-exceptions",'-DNO_SAFE_CAST','-fno-rtti']) + 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','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['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']) + if env['javascript_eval'] == 'yes': + env.Append(CPPFLAGS=['-DJAVASCRIPT_EVAL_ENABLED']) - env.Append(LINKFLAGS=['-O2']) - #env.Append(LINKFLAGS=['-g4']) + env.Append(LINKFLAGS=['-O2']) + #env.Append(LINKFLAGS=['-g4']) - #print "CCCOM is:", env.subst('$CCCOM') - #print "P: ", env['p'], " Platofrm: ", env['platform'] + #print "CCCOM is:", env.subst('$CCCOM') + #print "P: ", env['p'], " Platofrm: ", env['platform'] - import methods + import methods - env.Append( BUILDERS = { 'GLSL120' : env.Builder(action = methods.build_legacygl_headers, suffix = 'glsl.h',src_suffix = '.glsl') } ) - env.Append( BUILDERS = { 'GLSL' : env.Builder(action = methods.build_glsl_headers, suffix = 'glsl.h',src_suffix = '.glsl') } ) - env.Append( BUILDERS = { 'GLSL120GLES' : env.Builder(action = methods.build_gles2_headers, suffix = 'glsl.h',src_suffix = '.glsl') } ) - #env.Append( BUILDERS = { 'HLSL9' : env.Builder(action = methods.build_hlsl_dx9_headers, suffix = 'hlsl.h',src_suffix = '.hlsl') } ) + env.Append( BUILDERS = { 'GLSL120' : env.Builder(action = methods.build_legacygl_headers, suffix = 'glsl.h',src_suffix = '.glsl') } ) + env.Append( BUILDERS = { 'GLSL' : env.Builder(action = methods.build_glsl_headers, suffix = 'glsl.h',src_suffix = '.glsl') } ) + env.Append( BUILDERS = { 'GLSL120GLES' : env.Builder(action = methods.build_gles2_headers, suffix = 'glsl.h',src_suffix = '.glsl') } ) + #env.Append( BUILDERS = { 'HLSL9' : env.Builder(action = methods.build_hlsl_dx9_headers, suffix = 'hlsl.h',src_suffix = '.hlsl') } ) -- cgit v1.2.3 From d4c17700aa2f36f69978beda04e42ff2749de270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Sun, 30 Oct 2016 18:57:40 +0100 Subject: style: Fix PEP8 whitespace issues in Python files Done with `autopep8 --select=E2,W2`, fixes: - E201 - Remove extraneous whitespace. - E202 - Remove extraneous whitespace. - E203 - Remove extraneous whitespace. - E211 - Remove extraneous whitespace. - E221 - Fix extraneous whitespace around keywords. - E222 - Fix extraneous whitespace around keywords. - E223 - Fix extraneous whitespace around keywords. - E224 - Remove extraneous whitespace around operator. - E225 - Fix missing whitespace around operator. - E226 - Fix missing whitespace around operator. - E227 - Fix missing whitespace around operator. - E228 - Fix missing whitespace around operator. - E231 - Add missing whitespace. - E231 - Fix various deprecated code (via lib2to3). - E241 - Fix extraneous whitespace around keywords. - E242 - Remove extraneous whitespace around operator. - E251 - Remove whitespace around parameter '=' sign. - E261 - Fix spacing after comment hash. - E262 - Fix spacing after comment hash. - E265 - Format block comments. - E271 - Fix extraneous whitespace around keywords. - E272 - Fix extraneous whitespace around keywords. - E273 - Fix extraneous whitespace around keywords. - E274 - Fix extraneous whitespace around keywords. - W291 - Remove trailing whitespace. - W293 - Remove trailing whitespace. --- platform/javascript/SCsub | 28 ++++++++++++------------ platform/javascript/detect.py | 50 +++++++++++++++++++++---------------------- 2 files changed, 39 insertions(+), 39 deletions(-) (limited to 'platform/javascript') diff --git a/platform/javascript/SCsub b/platform/javascript/SCsub index 07852ac206..5d5cd1590a 100644 --- a/platform/javascript/SCsub +++ b/platform/javascript/SCsub @@ -14,24 +14,24 @@ env_javascript = env.Clone() if env['target'] == "profile": env_javascript.Append(CPPFLAGS=['-DPROFILER_ENABLED']) -javascript_objects=[] +javascript_objects = [] for x in javascript_files: - javascript_objects.append( env_javascript.Object( x ) ) + 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"']) +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"']) -build = env.Program('#bin/godot',javascript_objects,PROGSUFFIX=env["PROGSUFFIX"]+".html") +build = env.Program('#bin/godot', javascript_objects, PROGSUFFIX=env["PROGSUFFIX"] + ".html") 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) + 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.AddPostAction(build, Action(make_html_shell, "Creating HTML shell file")) diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py index ce6149c250..56b41a49ac 100644 --- a/platform/javascript/detect.py +++ b/platform/javascript/detect.py @@ -18,8 +18,8 @@ def can_build(): def get_opts(): return [ - ['wasm','Compile to WebAssembly','no'], - ['javascript_eval','Enable JavaScript eval interface','yes'], + ['wasm', 'Compile to WebAssembly', 'no'], + ['javascript_eval', 'Enable JavaScript eval interface', 'yes'], ] def get_flags(): @@ -40,13 +40,13 @@ def configure(env): env.Append(CPPPATH=['#platform/javascript']) - em_path=os.environ["EMSCRIPTEN_ROOT"] + 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['ENV']['PATH'] = em_path + ":" + env['ENV']['PATH'] + env['CC'] = em_path + '/emcc' + env['CXX'] = em_path + '/emcc' #env['AR'] = em_path+"/emar" - env['AR'] = em_path+"/emcc" + env['AR'] = em_path + "/emcc" env['ARFLAGS'] = "-o" # env['RANLIB'] = em_path+"/emranlib" @@ -60,11 +60,11 @@ def configure(env): # env["LINKFLAGS"]= string.split(" -g --sysroot="+ld_sysroot+" -Wl,--no-undefined -Wl,-z,noexecstack ") - if (env["target"]=="release"): + if (env["target"] == "release"): env.Append(CCFLAGS=['-O2']) - elif (env["target"]=="release_debug"): - env.Append(CCFLAGS=['-O2','-DDEBUG_ENABLED']) - elif (env["target"]=="debug"): + elif (env["target"] == "release_debug"): + env.Append(CCFLAGS=['-O2', '-DDEBUG_ENABLED']) + elif (env["target"] == "debug"): env.Append(CCFLAGS=['-D_DEBUG', '-Wall', '-O2', '-DDEBUG_ENABLED']) #env.Append(CCFLAGS=['-D_DEBUG', '-Wall', '-g4', '-DDEBUG_ENABLED']) env.Append(CPPFLAGS=['-DDEBUG_MEMORY_ALLOC']) @@ -73,33 +73,33 @@ def configure(env): if("module_opus_enabled" in env and env["module_opus_enabled"] != "no"): env.opus_fixed_point = "yes" - env.Append(CPPFLAGS=["-fno-exceptions",'-DNO_SAFE_CAST','-fno-rtti']) - env.Append(CPPFLAGS=['-DJAVASCRIPT_ENABLED', '-DUNIX_ENABLED', '-DPTHREAD_NO_RENAME', '-DNO_FCNTL','-DMPC_FIXED_POINT','-DTYPED_METHOD_BIND','-DNO_THREADS']) + env.Append(CPPFLAGS=["-fno-exceptions", '-DNO_SAFE_CAST', '-fno-rtti']) + 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','FULL_ES2=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" + 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']) + 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=['-O2']) - #env.Append(LINKFLAGS=['-g4']) + # env.Append(LINKFLAGS=['-g4']) - #print "CCCOM is:", env.subst('$CCCOM') - #print "P: ", env['p'], " Platofrm: ", env['platform'] + # print "CCCOM is:", env.subst('$CCCOM') + # print "P: ", env['p'], " Platofrm: ", env['platform'] import methods - env.Append( BUILDERS = { 'GLSL120' : env.Builder(action = methods.build_legacygl_headers, suffix = 'glsl.h',src_suffix = '.glsl') } ) - env.Append( BUILDERS = { 'GLSL' : env.Builder(action = methods.build_glsl_headers, suffix = 'glsl.h',src_suffix = '.glsl') } ) - env.Append( BUILDERS = { 'GLSL120GLES' : env.Builder(action = methods.build_gles2_headers, suffix = 'glsl.h',src_suffix = '.glsl') } ) + env.Append(BUILDERS={'GLSL120': env.Builder(action=methods.build_legacygl_headers, suffix='glsl.h', src_suffix='.glsl')}) + env.Append(BUILDERS={'GLSL': env.Builder(action=methods.build_glsl_headers, suffix='glsl.h', src_suffix='.glsl')}) + env.Append(BUILDERS={'GLSL120GLES': env.Builder(action=methods.build_gles2_headers, suffix='glsl.h', src_suffix='.glsl')}) #env.Append( BUILDERS = { 'HLSL9' : env.Builder(action = methods.build_hlsl_dx9_headers, suffix = 'hlsl.h',src_suffix = '.hlsl') } ) -- cgit v1.2.3 From 817dd7ccbb166b27c93706dffc5c0c0d59fd87f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Sun, 30 Oct 2016 19:05:14 +0100 Subject: style: Fix PEP8 blank lines issues in Python files Done with `autopep8 --select=E3,W3`, fixes: - E301 - Add missing blank line. - E302 - Add missing 2 blank lines. - E303 - Remove extra blank lines. - E304 - Remove blank line following function decorator. - E309 - Add missing blank line. - W391 - Remove trailing blank lines. --- platform/javascript/detect.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'platform/javascript') diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py index 56b41a49ac..04a6bc9cc3 100644 --- a/platform/javascript/detect.py +++ b/platform/javascript/detect.py @@ -2,12 +2,15 @@ import os import sys import string + def is_active(): return True + def get_name(): return "JavaScript" + def can_build(): import os @@ -15,6 +18,7 @@ def can_build(): return False return True + def get_opts(): return [ @@ -22,6 +26,7 @@ def get_opts(): ['javascript_eval', 'Enable JavaScript eval interface', 'yes'], ] + def get_flags(): return [ @@ -33,7 +38,6 @@ def get_flags(): ] - def configure(env): env['ENV'] = os.environ; env.use_windows_spawn_fix('javascript') -- cgit v1.2.3 From f34151ff0f91e8f0df8eaf829334b2205eb7da3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Tue, 1 Nov 2016 00:24:30 +0100 Subject: style: Various other PEP8 fixes in Python files Done with `autopep8 --select=E7`, fixes: - E701 - Put colon-separated compound statement on separate lines. - E702 - Put semicolon-separated compound statement on separate lines. - E703 - Put semicolon-separated compound statement on separate lines. - E711 - Fix comparison with None. - E712 - Fix (trivial case of) comparison with boolean. - E713 - Fix (trivial case of) non-membership check. - E721 - Fix various deprecated code (via lib2to3). --- platform/javascript/detect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'platform/javascript') diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py index 04a6bc9cc3..ec99392987 100644 --- a/platform/javascript/detect.py +++ b/platform/javascript/detect.py @@ -39,7 +39,7 @@ def get_flags(): def configure(env): - env['ENV'] = os.environ; + env['ENV'] = os.environ env.use_windows_spawn_fix('javascript') env.Append(CPPPATH=['#platform/javascript']) -- cgit v1.2.3 From cc95d4448c6005c3007c8460f09b8be1595eb3c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 3 Nov 2016 00:23:55 +0100 Subject: scons: Reorder options for clarity Also prefix all thirdparty-related toggles with `builtin`. --- platform/javascript/detect.py | 1 - 1 file changed, 1 deletion(-) (limited to 'platform/javascript') diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py index ec99392987..9bc204a94a 100644 --- a/platform/javascript/detect.py +++ b/platform/javascript/detect.py @@ -31,7 +31,6 @@ def get_flags(): return [ ('tools', 'no'), - ('builtin_zlib', 'yes'), ('module_etc1_enabled', 'no'), ('module_mpc_enabled', 'no'), ('module_theora_enabled', 'no'), -- cgit v1.2.3 From 82addf2ffe18c49d437ee6d425e3470817f0dc85 Mon Sep 17 00:00:00 2001 From: eska Date: Fri, 11 Nov 2016 03:58:03 +0100 Subject: Enable memory growth in WebAssembly builds This allows setting TOTAL_MEMORY during runtime at the cost of reserving a bit more memory. --- platform/javascript/detect.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'platform/javascript') diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py index 9bc204a94a..1ee3358888 100644 --- a/platform/javascript/detect.py +++ b/platform/javascript/detect.py @@ -76,6 +76,7 @@ def configure(env): if("module_opus_enabled" in env and env["module_opus_enabled"] != "no"): env.opus_fixed_point = "yes" + # These flags help keep the file size down env.Append(CPPFLAGS=["-fno-exceptions", '-DNO_SAFE_CAST', '-fno-rtti']) 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']) @@ -86,6 +87,12 @@ def configure(env): if env['wasm'] == 'yes': env.Append(LINKFLAGS=['-s', 'BINARYEN=1']) env.Append(LINKFLAGS=['-s', '\'BINARYEN_METHOD="native-wasm"\'']) + # Maximum memory size is baked into the WebAssembly binary during + # compilation, so we need to enable memory growth to allow setting + # TOTAL_MEMORY at runtime. The value set at runtime must be higher than + # what is set during compilation, check TOTAL_MEMORY in Emscripten's + # src/settings.js for the default. + env.Append(LINKFLAGS=['-s', 'ALLOW_MEMORY_GROWTH=1']) env["PROGSUFFIX"] += ".webassembly" else: env.Append(CPPFLAGS=['-s', 'ASM_JS=1']) -- cgit v1.2.3 From d87b1d1338472514e96c3cd8857d050d54a9d1e7 Mon Sep 17 00:00:00 2001 From: eska Date: Sun, 13 Nov 2016 14:10:00 +0100 Subject: Remove explicit BINARYEN_METHOD for WebAssembly build This option is the default since Binaryen version 21. --- platform/javascript/detect.py | 1 - 1 file changed, 1 deletion(-) (limited to 'platform/javascript') diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py index 1ee3358888..35352becf8 100644 --- a/platform/javascript/detect.py +++ b/platform/javascript/detect.py @@ -86,7 +86,6 @@ def configure(env): if env['wasm'] == 'yes': env.Append(LINKFLAGS=['-s', 'BINARYEN=1']) - env.Append(LINKFLAGS=['-s', '\'BINARYEN_METHOD="native-wasm"\'']) # Maximum memory size is baked into the WebAssembly binary during # compilation, so we need to enable memory growth to allow setting # TOTAL_MEMORY at runtime. The value set at runtime must be higher than -- cgit v1.2.3 From a6ae3204fb577cc61f09fa15c803669d477e2f42 Mon Sep 17 00:00:00 2001 From: eska Date: Fri, 18 Nov 2016 18:52:44 +0100 Subject: OS additions and fixes for WebAssembly/asm.js - Implement alert, shell_open, set_window_title - Add locale lookup, fixes #2477 - Print without color control sequences - Move get_executable_path implementation to OS_JavaScript --- platform/javascript/javascript_main.cpp | 2 +- platform/javascript/os_javascript.cpp | 84 ++++++++++++++++----------------- platform/javascript/os_javascript.h | 17 ++++--- 3 files changed, 49 insertions(+), 54 deletions(-) (limited to 'platform/javascript') diff --git a/platform/javascript/javascript_main.cpp b/platform/javascript/javascript_main.cpp index d9342cfe10..af12384bc9 100644 --- a/platform/javascript/javascript_main.cpp +++ b/platform/javascript/javascript_main.cpp @@ -148,7 +148,7 @@ int main(int argc, char *argv[]) { /* Initialize the window */ printf("let it go!\n"); glutInit(&argc, argv); - os = new OS_JavaScript(_gfx_init,NULL,NULL,NULL,NULL); + os = new OS_JavaScript(_gfx_init,NULL,NULL); #if 0 char *args[]={"-test","gui","-v",NULL}; Error err = Main::setup("apk",3,args); diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index e802a7e9cb..2a025ff6c0 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -37,6 +37,7 @@ #include "main/main.h" #include "core/globals.h" +#include "stdlib.h" #include "emscripten.h" #include "dom_keys.h" @@ -89,7 +90,9 @@ static InputEvent _setup_key_event(const EmscriptenKeyboardEvent *emscripten_eve ev.key.scancode = dom2godot_scancode(emscripten_event->keyCode); String unicode = String::utf8(emscripten_event->key); + // check if empty or multi-character (e.g. `CapsLock`) if (unicode.length()!=1) { + // might be empty as well, but better than nonsense unicode = String::utf8(emscripten_event->charValue); } if (unicode.length()==1) { @@ -153,6 +156,25 @@ void OS_JavaScript::initialize(const VideoMode& p_desired,int p_video_driver,int default_videomode=p_desired; + // find locale, emscripten only sets "C" + char locale_ptr[16]; + EM_ASM_({ + var locale = ""; + if (Module.locale) { + // best case: server-side script reads Accept-Language early and + // defines the locale to be read here + locale = Module.locale; + } else { + // no luck, use what the JS engine can tell us + // if this turns out not compatible enough, add tests for + // browserLanguage, systemLanguage and userLanguage + locale = navigator.languages ? navigator.languages[0] : navigator.language; + } + locale = locale.split('.')[0]; + stringToUTF8(locale, $0, 16); + }, locale_ptr); + setenv("LANG", locale_ptr, true); + print_line("Init Audio"); AudioDriverManagerSW::add_driver(&audio_driver_javascript); @@ -254,32 +276,11 @@ void OS_JavaScript::finalize() { memdelete(input); } +void OS_JavaScript::alert(const String& p_alert,const String& p_title) { -void OS_JavaScript::vprint(const char* p_format, va_list p_list, bool p_stderr) { - - if (p_stderr) { - - vfprintf(stderr,p_format,p_list); - fflush(stderr); - } else { - - vprintf(p_format,p_list); - fflush(stdout); - } -} - -void OS_JavaScript::print(const char *p_format, ... ) { - - va_list argp; - va_start(argp, p_format); - vprintf(p_format, argp ); - va_end(argp); - -} - -void OS_JavaScript::alert(const String& p_alert) { - - print("ALERT: %s\n",p_alert.utf8().get_data()); + EM_ASM_({ + window.alert(UTF8ToString($0)); + }, p_alert.utf8().get_data()); } @@ -306,9 +307,12 @@ int OS_JavaScript::get_mouse_button_state() const { return 0; } -void OS_JavaScript::set_window_title(const String& p_title) { +void OS_JavaScript::set_window_title(const String& p_title) { + EM_ASM_({ + document.title = UTF8ToString($0); + }, p_title.utf8().get_data()); } //interesting byt not yet @@ -664,25 +668,17 @@ void OS_JavaScript::reload_gfx() { } Error OS_JavaScript::shell_open(String p_uri) { - - if (open_uri_func) - return open_uri_func(p_uri)?ERR_CANT_OPEN:OK; - return ERR_UNAVAILABLE; -}; + EM_ASM_({ + window.open(UTF8ToString($0), '_blank'); + }, p_uri.utf8().get_data()); + return OK; +} String OS_JavaScript::get_resource_dir() const { return "/"; //javascript has it's own filesystem for resources inside the APK } -String OS_JavaScript::get_locale() const { - - if (get_locale_func) - return get_locale_func(); - return OS_Unix::get_locale(); -} - - String OS_JavaScript::get_data_dir() const { //if (get_data_dir_func) @@ -691,6 +687,10 @@ String OS_JavaScript::get_data_dir() const { //return Globals::get_singleton()->get_singleton_object("GodotOS")->call("get_data_dir"); }; +String OS_JavaScript::get_executable_path() const { + + return String(); +} void OS_JavaScript::_close_notification_funcs(const String& p_file,int p_flags) { @@ -757,9 +757,7 @@ String OS_JavaScript::get_joy_guid(int p_device) const { return input->get_joy_guid_remapped(p_device); } -OS_JavaScript::OS_JavaScript(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, OpenURIFunc p_open_uri_func, GetDataDirFunc p_get_data_dir_func,GetLocaleFunc p_get_locale_func) { - - +OS_JavaScript::OS_JavaScript(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, GetDataDirFunc p_get_data_dir_func) { default_videomode.width=800; default_videomode.height=600; default_videomode.fullscreen=true; @@ -772,9 +770,7 @@ OS_JavaScript::OS_JavaScript(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, Ope gl_extensions=NULL; rasterizer=NULL; - open_uri_func=p_open_uri_func; get_data_dir_func=p_get_data_dir_func; - get_locale_func=p_get_locale_func; FileAccessUnix::close_notification_func=_close_notification_funcs; time_to_save_sync=-1; diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h index 5b7904805b..2dd14010eb 100644 --- a/platform/javascript/os_javascript.h +++ b/platform/javascript/os_javascript.h @@ -45,9 +45,7 @@ #include "javascript_eval.h" typedef void (*GFXInitFunc)(void *ud,bool gl2,int w, int h, bool fs); -typedef int (*OpenURIFunc)(const String&); typedef String (*GetDataDirFunc)(); -typedef String (*GetLocaleFunc)(); class OS_JavaScript : public OS_Unix { public: @@ -85,9 +83,7 @@ private: VideoMode default_videomode; MainLoop * main_loop; - OpenURIFunc open_uri_func; GetDataDirFunc get_data_dir_func; - GetLocaleFunc get_locale_func; #ifdef JAVASCRIPT_EVAL_ENABLED JavaScript* javascript_eval; @@ -121,9 +117,12 @@ public: //static OS* get_singleton(); - virtual void vprint(const char* p_format, va_list p_list, bool p_stderr=false); - virtual void print(const char *p_format, ... ); - virtual void alert(const String& p_alert); + virtual void print_error(const char* p_function, const char* p_file, int p_line, const char *p_code, const char* p_rationale, ErrorType p_type) { + + OS::print_error(p_function, p_file, p_line, p_code, p_rationale, p_type); + } + + virtual void alert(const String& p_alert,const String& p_title="ALERT!"); virtual void set_mouse_show(bool p_show); @@ -164,8 +163,8 @@ public: virtual Error shell_open(String p_uri); virtual String get_data_dir() const; + String get_executable_path() const; virtual String get_resource_dir() const; - virtual String get_locale() const; void process_accelerometer(const Vector3& p_accelerometer); void process_touch(int p_what,int p_pointer, const Vector& p_points); @@ -175,7 +174,7 @@ public: virtual String get_joy_guid(int p_device) const; bool joy_connection_changed(int p_type, const EmscriptenGamepadEvent *p_event); - OS_JavaScript(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, OpenURIFunc p_open_uri_func, GetDataDirFunc p_get_data_dir_func,GetLocaleFunc p_get_locale_func); + OS_JavaScript(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, GetDataDirFunc p_get_data_dir_func); ~OS_JavaScript(); }; -- cgit v1.2.3 From 30e9ea5a8203e0f059c533def90c42f7ca7dc7c5 Mon Sep 17 00:00:00 2001 From: eska Date: Wed, 23 Nov 2016 23:53:38 +0100 Subject: Fix some mouse bugs in WebAssembly/asm.js - Emit mouse wheel release events - Set button masks, fixes #5092 --- platform/javascript/javascript_main.cpp | 11 ++++++++--- platform/javascript/os_javascript.cpp | 10 ++++++++-- platform/javascript/os_javascript.h | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) (limited to 'platform/javascript') diff --git a/platform/javascript/javascript_main.cpp b/platform/javascript/javascript_main.cpp index af12384bc9..586ccc9b4e 100644 --- a/platform/javascript/javascript_main.cpp +++ b/platform/javascript/javascript_main.cpp @@ -66,11 +66,12 @@ static void _glut_mouse_button(int button, int state, int x, int y) { if (ev.mouse_button.button_index<4) { if (ev.mouse_button.pressed) { - _mouse_button_mask|=1<push_input(ev); + if (ev.mouse_button.button_index==BUTTON_WHEEL_UP || ev.mouse_button.button_index==BUTTON_WHEEL_DOWN) { + // GLUT doesn't send release events for mouse wheel, so send manually + ev.mouse_button.pressed=false; + os->push_input(ev); + } } @@ -162,7 +168,6 @@ int main(int argc, char *argv[]) { glutMouseFunc(_glut_mouse_button); glutMotionFunc(_glut_mouse_motion); - glutMotionFunc(_glut_mouse_motion); glutPassiveMotionFunc(_glut_mouse_motion); diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index 2a025ff6c0..6464dfdd1d 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -299,13 +299,15 @@ bool OS_JavaScript::is_mouse_grab_enabled() const { //*sigh* technology has evolved so much since i was a kid.. return false; } + Point2 OS_JavaScript::get_mouse_pos() const { - return Point2(); + return input->get_mouse_pos(); } + int OS_JavaScript::get_mouse_button_state() const { - return 0; + return last_button_mask; } void OS_JavaScript::set_window_title(const String& p_title) { @@ -427,6 +429,9 @@ void OS_JavaScript::push_input(const InputEvent& p_ev) { if (ev.type==InputEvent::MOUSE_MOTION) { input->set_mouse_pos(Point2(ev.mouse_motion.x, ev.mouse_motion.y)); } + else if (ev.type==InputEvent::MOUSE_BUTTON) { + last_button_mask = ev.mouse_button.button_mask; + } input->parse_input_event(p_ev); } @@ -765,6 +770,7 @@ OS_JavaScript::OS_JavaScript(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, Get gfx_init_func=p_gfx_init_func; gfx_init_ud=p_gfx_init_ud; + last_button_mask=0; main_loop=NULL; last_id=1; gl_extensions=NULL; diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h index 2dd14010eb..bdbf482ca9 100644 --- a/platform/javascript/os_javascript.h +++ b/platform/javascript/os_javascript.h @@ -59,6 +59,7 @@ private: Vector touch; Point2 last_mouse; + int last_button_mask; unsigned int last_id; GFXInitFunc gfx_init_func; void*gfx_init_ud; -- cgit v1.2.3 From 3e1b437315778a99db669c28277352d7a4e86f36 Mon Sep 17 00:00:00 2001 From: eska Date: Sat, 26 Nov 2016 13:13:16 +0100 Subject: Add window features in web export - Add 'window' (canvas) resize, maximize and fullscreen - Implement get_screen_size - Fix fullscreen resolution --- platform/javascript/os_javascript.cpp | 187 +++++++++++++++++++++++++++------- platform/javascript/os_javascript.h | 12 ++- 2 files changed, 161 insertions(+), 38 deletions(-) (limited to 'platform/javascript') diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index 6464dfdd1d..14af9b3e37 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -78,6 +78,59 @@ void OS_JavaScript::set_opengl_extensions(const char* p_gl_extensions) { gl_extensions=p_gl_extensions; } +static EM_BOOL _browser_resize_callback(int event_type, const EmscriptenUiEvent *ui_event, void *user_data) { + + ERR_FAIL_COND_V(event_type!=EMSCRIPTEN_EVENT_RESIZE, false); + + OS_JavaScript* os = static_cast(user_data); + + // the order in which _browser_resize_callback and + // _fullscreen_change_callback are called is browser-dependent, + // so try adjusting for fullscreen in both + if (os->is_window_fullscreen() || os->is_window_maximized()) { + + OS::VideoMode vm = os->get_video_mode(); + vm.width = ui_event->windowInnerWidth; + vm.height = ui_event->windowInnerHeight; + os->set_video_mode(vm); + emscripten_set_canvas_size(ui_event->windowInnerWidth, ui_event->windowInnerHeight); + } + return false; +} + +static Size2 _windowed_size; + +static EM_BOOL _fullscreen_change_callback(int event_type, const EmscriptenFullscreenChangeEvent *event, void *user_data) { + + ERR_FAIL_COND_V(event_type!=EMSCRIPTEN_EVENT_FULLSCREENCHANGE, false); + + OS_JavaScript* os = static_cast(user_data); + String id = String::utf8(event->id); + + // empty id is canvas + if (id.empty() || id=="canvas") { + + OS::VideoMode vm = os->get_video_mode(); + // this event property is the only reliable information on + // browser fullscreen state + vm.fullscreen = event->isFullscreen; + + if (event->isFullscreen) { + vm.width = event->screenWidth; + vm.height = event->screenHeight; + os->set_video_mode(vm); + emscripten_set_canvas_size(vm.width, vm.height); + } + else { + os->set_video_mode(vm); + if (!os->is_window_maximized()) { + os->set_window_size(_windowed_size); + } + } + } + return false; +} + static InputEvent _setup_key_event(const EmscriptenKeyboardEvent *emscripten_event) { InputEvent ev; @@ -154,7 +207,11 @@ void OS_JavaScript::initialize(const VideoMode& p_desired,int p_video_driver,int if (gfx_init_func) gfx_init_func(gfx_init_ud,use_gl2,p_desired.width,p_desired.height,p_desired.fullscreen); - default_videomode=p_desired; + // nothing to do here, can't fulfil fullscreen request due to + // browser security, window size is already set from HTML + video_mode=p_desired; + video_mode.fullscreen=false; + _windowed_size=get_window_size(); // find locale, emscripten only sets "C" char locale_ptr[16]; @@ -232,26 +289,23 @@ void OS_JavaScript::initialize(const VideoMode& p_desired,int p_video_driver,int input = memnew( InputDefault ); - EMSCRIPTEN_RESULT result = emscripten_set_keydown_callback(NULL, this , true, &_keydown_callback); - if (result!=EMSCRIPTEN_RESULT_SUCCESS) { - ERR_PRINTS( "Error while setting Emscripten keydown callback: Code " + itos(result) ); - } - result = emscripten_set_keypress_callback(NULL, this, true, &_keypress_callback); - if (result!=EMSCRIPTEN_RESULT_SUCCESS) { - ERR_PRINTS( "Error while setting Emscripten keypress callback: Code " + itos(result) ); - } - result = emscripten_set_keyup_callback(NULL, this, true, &_keyup_callback); - if (result!=EMSCRIPTEN_RESULT_SUCCESS) { - ERR_PRINTS( "Error while setting Emscripten keyup callback: Code " + itos(result) ); - } - result = emscripten_set_gamepadconnected_callback(NULL, true, &joy_callback_func); - if (result!=EMSCRIPTEN_RESULT_SUCCESS) { - ERR_PRINTS( "Error while setting Emscripten gamepadconnected callback: Code " + itos(result) ); - } - result = emscripten_set_gamepaddisconnected_callback(NULL, true, &joy_callback_func); - if (result!=EMSCRIPTEN_RESULT_SUCCESS) { - ERR_PRINTS( "Error while setting Emscripten gamepaddisconnected callback: Code " + itos(result) ); - } +#define EM_CHECK(ev) if (result!=EMSCRIPTEN_RESULT_SUCCESS)\ + ERR_PRINTS("Error while setting " #ev " callback: Code " + itos(result)) +#define SET_EM_CALLBACK(ev, cb) result = emscripten_set_##ev##_callback(NULL, this, true, &cb); EM_CHECK(ev) +#define SET_EM_CALLBACK_NODATA(ev, cb) result = emscripten_set_##ev##_callback(NULL, true, &cb); EM_CHECK(ev) + + EMSCRIPTEN_RESULT result; + SET_EM_CALLBACK(keydown, _keydown_callback) + SET_EM_CALLBACK(keypress, _keypress_callback) + SET_EM_CALLBACK(keyup, _keyup_callback) + SET_EM_CALLBACK(resize, _browser_resize_callback) + SET_EM_CALLBACK(fullscreenchange, _fullscreen_change_callback) + SET_EM_CALLBACK_NODATA(gamepadconnected, joy_callback_func) + SET_EM_CALLBACK_NODATA(gamepaddisconnected, joy_callback_func) + +#undef SET_EM_CALLBACK_NODATA +#undef SET_EM_CALLBACK +#undef EM_CHECK #ifdef JAVASCRIPT_EVAL_ENABLED javascript_eval = memnew(JavaScript); @@ -323,22 +377,92 @@ void OS_JavaScript::set_window_title(const String& p_title) { void OS_JavaScript::set_video_mode(const VideoMode& p_video_mode,int p_screen) { - + video_mode = p_video_mode; } OS::VideoMode OS_JavaScript::get_video_mode(int p_screen) const { - return default_videomode; + return video_mode; +} + +Size2 OS_JavaScript::get_screen_size(int p_screen) const { + + ERR_FAIL_COND_V(p_screen!=0, Size2()); + + EmscriptenFullscreenChangeEvent ev; + EMSCRIPTEN_RESULT result = emscripten_get_fullscreen_status(&ev); + ERR_FAIL_COND_V(result!=EMSCRIPTEN_RESULT_SUCCESS, Size2()); + return Size2(ev.screenWidth, ev.screenHeight); +} + +void OS_JavaScript::set_window_size(const Size2 p_size) { + + window_maximized = false; + if (is_window_fullscreen()) { + set_window_fullscreen(false); + } + _windowed_size = p_size; + video_mode.width = p_size.x; + video_mode.height = p_size.y; + emscripten_set_canvas_size(p_size.x, p_size.y); } Size2 OS_JavaScript::get_window_size() const { - return Vector2(default_videomode.width,default_videomode.height); + int canvas[3]; + emscripten_get_canvas_size(canvas, canvas+1, canvas+2); + return Size2(canvas[0], canvas[1]); +} + +void OS_JavaScript::set_window_maximized(bool p_enabled) { + + window_maximized = p_enabled; + if (p_enabled) { + + if (is_window_fullscreen()) { + // _browser_resize callback will set canvas size + set_window_fullscreen(false); + } + else { + video_mode.width = EM_ASM_INT_V(return window.innerWidth); + video_mode.height = EM_ASM_INT_V(return window.innerHeight); + emscripten_set_canvas_size(video_mode.width, video_mode.height); + } + } + else { + set_window_size(_windowed_size); + } +} + +void OS_JavaScript::set_window_fullscreen(bool p_enable) { + + if (p_enable==is_window_fullscreen()) { + return; + } + + // only requesting changes here, if successful, canvas is resized in + // _browser_resize_callback or _fullscreen_change_callback + EMSCRIPTEN_RESULT result; + if (p_enable) { + EM_ASM(Module.requestFullscreen(false, false);); + } + else { + result = emscripten_exit_fullscreen(); + if (result!=EMSCRIPTEN_RESULT_SUCCESS) { + ERR_PRINTS("Failed to exit fullscreen: Code " + itos(result)); + } + } +} + +bool OS_JavaScript::is_window_fullscreen() const { + + return video_mode.fullscreen; } void OS_JavaScript::get_fullscreen_mode_list(List *p_list,int p_screen) const { - p_list->push_back(default_videomode); + Size2 screen = get_screen_size(); + p_list->push_back(OS::VideoMode(screen.width, screen.height, true)); } String OS_JavaScript::get_name() { @@ -658,16 +782,10 @@ void OS_JavaScript::main_loop_request_quit() { main_loop->notification(MainLoop::NOTIFICATION_WM_QUIT_REQUEST); } -void OS_JavaScript::set_display_size(Size2 p_size) { - - default_videomode.width=p_size.x; - default_videomode.height=p_size.y; -} - void OS_JavaScript::reload_gfx() { if (gfx_init_func) - gfx_init_func(gfx_init_ud,use_gl2,default_videomode.width,default_videomode.height,default_videomode.fullscreen); + gfx_init_func(gfx_init_ud,use_gl2,video_mode.width,video_mode.height,video_mode.fullscreen); if (rasterizer) rasterizer->reload_vram(); } @@ -763,10 +881,6 @@ String OS_JavaScript::get_joy_guid(int p_device) const { } OS_JavaScript::OS_JavaScript(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, GetDataDirFunc p_get_data_dir_func) { - default_videomode.width=800; - default_videomode.height=600; - default_videomode.fullscreen=true; - default_videomode.resizable=false; gfx_init_func=p_gfx_init_func; gfx_init_ud=p_gfx_init_ud; @@ -775,6 +889,7 @@ OS_JavaScript::OS_JavaScript(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, Get last_id=1; gl_extensions=NULL; rasterizer=NULL; + window_maximized=false; get_data_dir_func=p_get_data_dir_func; FileAccessUnix::close_notification_func=_close_notification_funcs; diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h index bdbf482ca9..95bd64dfe4 100644 --- a/platform/javascript/os_javascript.h +++ b/platform/javascript/os_javascript.h @@ -81,7 +81,8 @@ private: const char* gl_extensions; InputDefault *input; - VideoMode default_videomode; + bool window_maximized; + VideoMode video_mode; MainLoop * main_loop; GetDataDirFunc get_data_dir_func; @@ -140,7 +141,15 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const; + virtual Size2 get_screen_size(int p_screen=0) const; + + virtual void set_window_size(const Size2); virtual Size2 get_window_size() const; + virtual void set_window_maximized(bool p_enabled); + virtual bool is_window_maximized() const { return window_maximized; } + virtual void set_window_fullscreen(bool p_enable); + virtual bool is_window_fullscreen() const; + virtual String get_name(); virtual MainLoop *get_main_loop() const; @@ -158,7 +167,6 @@ public: virtual bool has_touchscreen_ui_hint() const; void set_opengl_extensions(const char* p_gl_extensions); - void set_display_size(Size2 p_size); void reload_gfx(); -- cgit v1.2.3 From 290d79f26c0c6cd00a35ae64fb6eecacedbb3937 Mon Sep 17 00:00:00 2001 From: eska Date: Wed, 30 Nov 2016 22:47:19 +0100 Subject: 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. --- platform/javascript/detect.py | 1 + platform/javascript/export/export.cpp | 5 +++++ 2 files changed, 6 insertions(+) (limited to 'platform/javascript') diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py index 35352becf8..2cb6874000 100644 --- a/platform/javascript/detect.py +++ b/platform/javascript/detect.py @@ -96,6 +96,7 @@ def configure(env): else: env.Append(CPPFLAGS=['-s', 'ASM_JS=1']) env.Append(LINKFLAGS=['-s', 'ASM_JS=1']) + env.Append(LINKFLAGS=['--separate-asm']) if env['javascript_eval'] == 'yes': env.Append(CPPFLAGS=['-DJAVASCRIPT_EVAL_ENABLED']) diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp index 721aef3e50..ab64ffbb45 100644 --- a/platform/javascript/export/export.cpp +++ b/platform/javascript/export/export.cpp @@ -320,6 +320,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") { file=p_path.get_file().basename()+".mem"; -- cgit v1.2.3 From c7bc44d5ad9aae4902280012f7654e2318cd910e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Sun, 1 Jan 2017 22:01:57 +0100 Subject: Welcome in 2017, dear changelog reader! That year should bring the long-awaited OpenGL ES 3.0 compatible renderer with state-of-the-art rendering techniques tuned to work as low as middle end handheld devices - without compromising with the possibilities given for higher end desktop games of course. Great times ahead for the Godot community and the gamers that will play our games! --- platform/javascript/audio_driver_javascript.cpp | 2 +- platform/javascript/audio_driver_javascript.h | 2 +- platform/javascript/audio_server_javascript.cpp | 2 +- platform/javascript/audio_server_javascript.h | 2 +- platform/javascript/dom_keys.h | 2 +- platform/javascript/export/export.cpp | 2 +- platform/javascript/export/export.h | 2 +- platform/javascript/javascript_eval.cpp | 2 +- platform/javascript/javascript_eval.h | 2 +- platform/javascript/javascript_main.cpp | 2 +- platform/javascript/os_javascript.cpp | 2 +- platform/javascript/os_javascript.h | 2 +- platform/javascript/platform_config.h | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) (limited to 'platform/javascript') diff --git a/platform/javascript/audio_driver_javascript.cpp b/platform/javascript/audio_driver_javascript.cpp index 1b949e64f9..579cbaed3c 100644 --- a/platform/javascript/audio_driver_javascript.cpp +++ b/platform/javascript/audio_driver_javascript.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/javascript/audio_driver_javascript.h b/platform/javascript/audio_driver_javascript.h index c674a8566e..528b45569d 100644 --- a/platform/javascript/audio_driver_javascript.h +++ b/platform/javascript/audio_driver_javascript.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/javascript/audio_server_javascript.cpp b/platform/javascript/audio_server_javascript.cpp index 71a7e77266..fec553df04 100644 --- a/platform/javascript/audio_server_javascript.cpp +++ b/platform/javascript/audio_server_javascript.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/javascript/audio_server_javascript.h b/platform/javascript/audio_server_javascript.h index e27192cd93..95c16db3ee 100644 --- a/platform/javascript/audio_server_javascript.h +++ b/platform/javascript/audio_server_javascript.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/javascript/dom_keys.h b/platform/javascript/dom_keys.h index 282b632e93..5ef212ce4a 100644 --- a/platform/javascript/dom_keys.h +++ b/platform/javascript/dom_keys.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp index ab64ffbb45..f2b63ff12f 100644 --- a/platform/javascript/export/export.cpp +++ b/platform/javascript/export/export.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/javascript/export/export.h b/platform/javascript/export/export.h index 2105141e58..59c0a67e6d 100644 --- a/platform/javascript/export/export.h +++ b/platform/javascript/export/export.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/javascript/javascript_eval.cpp b/platform/javascript/javascript_eval.cpp index e642300bda..7bbe0ae99b 100644 --- a/platform/javascript/javascript_eval.cpp +++ b/platform/javascript/javascript_eval.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/javascript/javascript_eval.h b/platform/javascript/javascript_eval.h index e5f6268076..9b2c91f25e 100644 --- a/platform/javascript/javascript_eval.h +++ b/platform/javascript/javascript_eval.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/javascript/javascript_main.cpp b/platform/javascript/javascript_main.cpp index 586ccc9b4e..4c47594810 100644 --- a/platform/javascript/javascript_main.cpp +++ b/platform/javascript/javascript_main.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index 14af9b3e37..f1b67021f0 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h index 95bd64dfe4..4cdc88f4f9 100644 --- a/platform/javascript/os_javascript.h +++ b/platform/javascript/os_javascript.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/javascript/platform_config.h b/platform/javascript/platform_config.h index 143f16c1fa..cdef185ff0 100644 --- a/platform/javascript/platform_config.h +++ b/platform/javascript/platform_config.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ -- cgit v1.2.3