diff options
Diffstat (limited to 'platform/javascript')
| -rw-r--r-- | platform/javascript/audio_driver_javascript.cpp | 2 | ||||
| -rw-r--r-- | platform/javascript/audio_driver_javascript.h | 2 | ||||
| -rw-r--r-- | platform/javascript/audio_server_javascript.cpp | 2 | ||||
| -rw-r--r-- | platform/javascript/audio_server_javascript.h | 2 | ||||
| -rw-r--r-- | platform/javascript/detect.py | 9 | ||||
| -rw-r--r-- | platform/javascript/export/export.cpp | 101 | ||||
| -rw-r--r-- | platform/javascript/export/export.h | 2 | ||||
| -rw-r--r-- | platform/javascript/javascript_main.cpp | 2 | ||||
| -rw-r--r-- | platform/javascript/os_javascript.cpp | 70 | ||||
| -rw-r--r-- | platform/javascript/os_javascript.h | 10 | ||||
| -rw-r--r-- | platform/javascript/platform_config.h | 2 |
11 files changed, 164 insertions, 40 deletions
diff --git a/platform/javascript/audio_driver_javascript.cpp b/platform/javascript/audio_driver_javascript.cpp index cc053cf136..1b949e64f9 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-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 0356ca87f9..c674a8566e 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-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 a2c6740eaf..fbd5d2e1c0 100644 --- a/platform/javascript/audio_server_javascript.cpp +++ b/platform/javascript/audio_server_javascript.cpp @@ -33,7 +33,7 @@ void AudioServerJavascript::sample_set_description(RID p_sample, const String& p } -String AudioServerJavascript::sample_get_description(RID p_sample, const String& p_description) const{ +String AudioServerJavascript::sample_get_description(RID p_sample) const{ return String(); } diff --git a/platform/javascript/audio_server_javascript.h b/platform/javascript/audio_server_javascript.h index 450237d324..1dc90c48ee 100644 --- a/platform/javascript/audio_server_javascript.h +++ b/platform/javascript/audio_server_javascript.h @@ -95,7 +95,7 @@ public: virtual RID sample_create(SampleFormat p_format, bool p_stereo, int p_length); virtual void sample_set_description(RID p_sample, const String& p_description); - virtual String sample_get_description(RID p_sample, const String& p_description) const; + virtual String sample_get_description(RID p_sample) const; virtual SampleFormat sample_get_format(RID p_sample) const; virtual bool sample_is_stereo(RID p_sample) const; diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py index ec21bf6ee4..0a6c8b1457 100644 --- a/platform/javascript/detect.py +++ b/platform/javascript/detect.py @@ -80,7 +80,7 @@ def configure(env): env.opus_fixed_point="yes" env.Append(CPPFLAGS=["-fno-exceptions",'-DNO_SAFE_CAST','-fno-rtti']) - env.Append(CPPFLAGS=['-DJAVASCRIPT_ENABLED', '-DUNIX_ENABLED', '-DNO_FCNTL','-DMPC_FIXED_POINT','-DTYPED_METHOD_BIND','-DNO_THREADS']) + 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']) @@ -98,3 +98,10 @@ def configure(env): #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 = { 'HLSL9' : env.Builder(action = methods.build_hlsl_dx9_headers, suffix = 'hlsl.h',src_suffix = '.hlsl') } ) diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp index 9e2595f4a1..e055aeea56 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-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -50,6 +50,7 @@ class EditorExportPlatformJavaScript : public EditorExportPlatform { PACK_MULTIPLE_FILES }; + void _fix_html(Vector<uint8_t>& p_html, const String& p_name, bool p_debug); PackMode pack_mode; @@ -58,6 +59,12 @@ class EditorExportPlatformJavaScript : public EditorExportPlatform { int max_memory; int version_code; + String html_title; + String html_head_include; + String html_font_family; + String html_style_include; + bool html_controls_enabled; + Ref<ImageTexture> logo; protected: @@ -101,6 +108,16 @@ bool EditorExportPlatformJavaScript::_set(const StringName& p_name, const Varian show_run=p_value; else if (n=="options/memory_size") max_memory=p_value; + else if (n=="html/title") + html_title=p_value; + else if (n=="html/head_include") + html_head_include=p_value; + else if (n=="html/font_family") + html_font_family=p_value; + else if (n=="html/style_include") + html_style_include=p_value; + else if (n=="html/controls_enabled") + html_controls_enabled=p_value; else return false; @@ -119,6 +136,16 @@ bool EditorExportPlatformJavaScript::_get(const StringName& p_name,Variant &r_re r_ret=show_run; else if (n=="options/memory_size") r_ret=max_memory; + else if (n=="html/title") + r_ret=html_title; + else if (n=="html/head_include") + r_ret=html_head_include; + else if (n=="html/font_family") + r_ret=html_font_family; + else if (n=="html/style_include") + r_ret=html_style_include; + else if (n=="html/controls_enabled") + r_ret=html_controls_enabled; else return false; @@ -130,39 +157,47 @@ void EditorExportPlatformJavaScript::_get_property_list( List<PropertyInfo> *p_l p_list->push_back( PropertyInfo( Variant::STRING, "custom_package/release", PROPERTY_HINT_GLOBAL_FILE,"zip")); p_list->push_back( PropertyInfo( Variant::INT, "options/memory_size",PROPERTY_HINT_ENUM,"32mb,64mb,128mb,256mb,512mb,1024mb")); p_list->push_back( PropertyInfo( Variant::BOOL, "browser/enable_run")); + p_list->push_back( PropertyInfo( Variant::STRING, "html/title")); + p_list->push_back( PropertyInfo( Variant::STRING, "html/head_include",PROPERTY_HINT_MULTILINE_TEXT)); + p_list->push_back( PropertyInfo( Variant::STRING, "html/font_family")); + p_list->push_back( PropertyInfo( Variant::STRING, "html/style_include",PROPERTY_HINT_MULTILINE_TEXT)); + p_list->push_back( PropertyInfo( Variant::BOOL, "html/controls_enabled")); + //p_list->push_back( PropertyInfo( Variant::INT, "resources/pack_mode", PROPERTY_HINT_ENUM,"Copy,Single Exec.,Pack (.pck),Bundles (Optical)")); } -static void _fix_html(Vector<uint8_t>& html,const String& name,int max_memory) { +void EditorExportPlatformJavaScript::_fix_html(Vector<uint8_t>& p_html, const String& p_name, bool p_debug) { String str; String strnew; - str.parse_utf8((const char*)html.ptr(),html.size()); + str.parse_utf8((const char*)p_html.ptr(),p_html.size()); Vector<String> lines=str.split("\n"); for(int i=0;i<lines.size();i++) { - if (lines[i].find("$GODOTTMEM")!=-1) { - - strnew+=lines[i].replace("$GODOTTMEM",itos(max_memory*1024*1024))+"\n"; - } else if (lines[i].find("$GODOTFS")!=-1) { - strnew+=lines[i].replace("$GODOTFS",name+"fs.js")+"\n"; - } else if (lines[i].find("$GODOTMEM")!=-1) { - strnew+=lines[i].replace("$GODOTMEM",name+".mem")+"\n"; - } else if (lines[i].find("$GODOTJS")!=-1) { - strnew+=lines[i].replace("$GODOTJS",name+".js")+"\n"; - } else { - strnew+=lines[i]+"\n"; - } + 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_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")); + current_line = current_line.replace("$GODOT_HEAD_INCLUDE",html_head_include); + current_line = current_line.replace("$GODOT_STYLE_FONT_FAMILY",html_font_family); + current_line = current_line.replace("$GODOT_STYLE_INCLUDE",html_style_include); + current_line = current_line.replace("$GODOT_CONTROLS_ENABLED",html_controls_enabled?"true":"false"); + current_line = current_line.replace("$GODOT_DEBUG_ENABLED",p_debug?"true":"false"); + strnew += current_line+"\n"; } CharString cs = strnew.utf8(); - html.resize(cs.size()); + p_html.resize(cs.size()); for(int i=9;i<cs.size();i++) { - html[i]=cs[i]; + p_html[i]=cs[i]; } } @@ -205,18 +240,24 @@ Error EditorExportPlatformJavaScript::export_project(const String& p_path, bool EditorProgress ep("export","Exporting for javascript",104); - String template_path = EditorSettings::get_singleton()->get_settings_path()+"/templates/"; - - if (p_debug) { - - src_template=custom_debug_package!=""?custom_debug_package:template_path+"javascript_debug.zip"; - } else { - - src_template=custom_release_package!=""?custom_release_package:template_path+"javascript_release.zip"; + if (p_debug) + src_template=custom_debug_package; + else + src_template=custom_release_package; + if (src_template=="") { + String err; + if (p_debug) { + src_template=find_export_template("javascript_debug.zip", &err); + } else { + src_template=find_export_template("javascript_release.zip", &err); + } + if (src_template=="") { + EditorNode::add_io_error(err); + return ERR_FILE_NOT_FOUND; + } } - FileAccess *src_f=NULL; zlib_filefunc_def io = zipio_create_io_from_file(&src_f); @@ -268,7 +309,7 @@ Error EditorExportPlatformJavaScript::export_project(const String& p_path, bool if (file=="godot.html") { - _fix_html(data,p_path.get_file().basename(),1<<(max_memory+5)); + _fix_html(data,p_path.get_file().basename(), p_debug); file=p_path.get_file(); } if (file=="godotfs.js") { @@ -329,6 +370,9 @@ EditorExportPlatformJavaScript::EditorExportPlatformJavaScript() { logo = Ref<ImageTexture>( memnew( ImageTexture )); logo->create_from_image(img); max_memory=3; + html_title=""; + html_font_family="arial,sans-serif"; + html_controls_enabled=true; pack_mode=PACK_SINGLE_FILE; } @@ -337,9 +381,8 @@ bool EditorExportPlatformJavaScript::can_export(String *r_error) const { bool valid=true; String err; - String exe_path = EditorSettings::get_singleton()->get_settings_path()+"/templates/"; - if (!FileAccess::exists(exe_path+"javascript_debug.zip") || !FileAccess::exists(exe_path+"javascript_release.zip")) { + if (!exists_export_template("javascript_debug.zip") || !exists_export_template("javascript_release.zip")) { valid=false; err+="No export templates found.\nDownload and install export templates.\n"; } diff --git a/platform/javascript/export/export.h b/platform/javascript/export/export.h index a126675983..2105141e58 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-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 fb87dc848e..e66110b655 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-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 ae97bf990b..562733ab89 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-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -76,6 +76,14 @@ void OS_JavaScript::set_opengl_extensions(const char* p_gl_extensions) { gl_extensions=p_gl_extensions; } +static EM_BOOL joy_callback_func(int p_type, const EmscriptenGamepadEvent *p_event, void *p_user) { + OS_JavaScript *os = (OS_JavaScript*) OS::get_singleton(); + if (os) { + return os->joy_connection_changed(p_type, p_event); + } + return false; +} + void OS_JavaScript::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) { print_line("Init OS"); @@ -142,6 +150,8 @@ void OS_JavaScript::initialize(const VideoMode& p_desired,int p_video_driver,int input = memnew( InputDefault ); + emscripten_set_gamepadconnected_callback(NULL, true, &joy_callback_func); + emscripten_set_gamepaddisconnected_callback(NULL, true, &joy_callback_func); } void OS_JavaScript::set_main_loop( MainLoop * p_main_loop ) { @@ -296,7 +306,7 @@ bool OS_JavaScript::main_loop_iterate() { } - + process_joysticks(); return Main::iteration(); } @@ -605,6 +615,62 @@ void OS_JavaScript::_close_notification_funcs(const String& p_file,int p_flags) } } +void OS_JavaScript::process_joysticks() { + + int joy_count = emscripten_get_num_gamepads(); + for (int i = 0; i < joy_count; i++) { + EmscriptenGamepadEvent state; + emscripten_get_gamepad_status(i, &state); + if (state.connected) { + + int num_buttons = MIN(state.numButtons, 18); + int num_axes = MIN(state.numAxes, 8); + for (int j = 0; j < num_buttons; j++) { + + float value = state.analogButton[j]; + if (String(state.mapping) == "standard" && (j == 6 || j == 7)) { + InputDefault::JoyAxis jx; + jx.min = 0; + jx.value = value; + last_id = input->joy_axis(last_id, i, j, jx); + } + else { + last_id = input->joy_button(last_id, i, j, value); + } + } + for (int j = 0; j < num_axes; j++) { + + InputDefault::JoyAxis jx; + jx.min = -1; + jx.value = state.axis[j]; + last_id = input->joy_axis(last_id, i, j, jx); + } + } + } +} + +bool OS_JavaScript::joy_connection_changed(int p_type, const EmscriptenGamepadEvent *p_event) { + if (p_type == EMSCRIPTEN_EVENT_GAMEPADCONNECTED) { + + String guid = ""; + if (String(p_event->mapping) == "standard") + guid = "Default HTML5 Gamepad"; + input->joy_connection_changed(p_event->index, true, String(p_event->id), guid); + } + else { + input->joy_connection_changed(p_event->index, false, ""); + } + return true; +} + +bool OS_JavaScript::is_joy_known(int p_device) { + return input->is_joy_mapped(p_device); +} + +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) { diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h index 1e925fb8df..ec3a6cf911 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-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -41,6 +41,7 @@ #include "audio_server_javascript.h" #include "audio_driver_javascript.h" #include "main/input_default.h" +#include "emscripten/html5.h" typedef void (*GFXInitFunc)(void *ud,bool gl2,int w, int h, bool fs); typedef int (*OpenURIFunc)(const String&); @@ -90,6 +91,8 @@ private: static void _close_notification_funcs(const String& p_file,int p_flags); + void process_joysticks(); + public: // functions used by main to initialize/deintialize the OS @@ -163,6 +166,11 @@ public: void process_accelerometer(const Vector3& p_accelerometer); void process_touch(int p_what,int p_pointer, const Vector<TouchPos>& p_points); void push_input(const InputEvent& p_ev); + + virtual bool is_joy_known(int p_device); + 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(); diff --git a/platform/javascript/platform_config.h b/platform/javascript/platform_config.h index 1e7d066bb9..143f16c1fa 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-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ |