diff options
Diffstat (limited to 'platform')
38 files changed, 378 insertions, 256 deletions
diff --git a/platform/SCsub b/platform/SCsub index 20c89ae8c6..38bab59d74 100644 --- a/platform/SCsub +++ b/platform/SCsub @@ -29,4 +29,4 @@ with open_utf8('register_platform_apis.gen.cpp', 'w') as f: env.add_source_files(env.platform_sources, 'register_platform_apis.gen.cpp') lib = env.add_library('platform', env.platform_sources) -env.Prepend(LIBS=lib) +env.Prepend(LIBS=[lib]) diff --git a/platform/android/audio_driver_opensl.cpp b/platform/android/audio_driver_opensl.cpp index 1232fc7453..711088c158 100644 --- a/platform/android/audio_driver_opensl.cpp +++ b/platform/android/audio_driver_opensl.cpp @@ -97,17 +97,10 @@ Error AudioDriverOpenSL::init() { { (SLuint32)SL_ENGINEOPTION_THREADSAFE, (SLuint32)SL_BOOLEAN_TRUE } }; res = slCreateEngine(&sl, 1, EngineOption, 0, NULL, NULL); - if (res != SL_RESULT_SUCCESS) { + ERR_FAIL_COND_V_MSG(res != SL_RESULT_SUCCESS, ERR_INVALID_PARAMETER, "Could not initialize OpenSL."); - ERR_EXPLAIN("Could not Initialize OpenSL"); - ERR_FAIL_V(ERR_INVALID_PARAMETER); - } res = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); - if (res != SL_RESULT_SUCCESS) { - - ERR_EXPLAIN("Could not Realize OpenSL"); - ERR_FAIL_V(ERR_INVALID_PARAMETER); - } + ERR_FAIL_COND_V_MSG(res != SL_RESULT_SUCCESS, ERR_INVALID_PARAMETER, "Could not realize OpenSL."); return OK; } @@ -215,8 +208,8 @@ void AudioDriverOpenSL::_record_buffer_callback(SLAndroidSimpleBufferQueueItf qu for (int i = 0; i < rec_buffer.size(); i++) { int32_t sample = rec_buffer[i] << 16; - input_buffer_write(sample); - input_buffer_write(sample); // call twice to convert to Stereo + capture_buffer_write(sample); + capture_buffer_write(sample); // call twice to convert to Stereo } SLresult res = (*recordBufferQueueItf)->Enqueue(recordBufferQueueItf, rec_buffer.ptrw(), rec_buffer.size() * sizeof(int16_t)); @@ -287,7 +280,7 @@ Error AudioDriverOpenSL::capture_init_device() { const int rec_buffer_frames = 2048; rec_buffer.resize(rec_buffer_frames); - input_buffer_init(rec_buffer_frames); + capture_buffer_init(rec_buffer_frames); res = (*recordBufferQueueItf)->Enqueue(recordBufferQueueItf, rec_buffer.ptrw(), rec_buffer.size() * sizeof(int16_t)); ERR_FAIL_COND_V(res != SL_RESULT_SUCCESS, ERR_CANT_OPEN); diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index 1b9d31d752..16e49e8a38 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -32,6 +32,7 @@ #include "core/io/marshalls.h" #include "core/io/zip_io.h" +#include "core/os/dir_access.h" #include "core/os/file_access.h" #include "core/os/os.h" #include "core/project_settings.h" @@ -725,8 +726,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { uint32_t string_at = decode_uint32(&p_manifest[st_offset + i * 4]); string_at += st_offset + string_count * 4; - ERR_EXPLAIN("Unimplemented, can't read utf8 string table."); - ERR_FAIL_COND(string_flags & UTF8_FLAG); + ERR_FAIL_COND_MSG(string_flags & UTF8_FLAG, "Unimplemented, can't read UTF-8 string table."); if (string_flags & UTF8_FLAG) { @@ -847,6 +847,136 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { uint32_t name = decode_uint32(&p_manifest[iofs + 12]); String tname = string_table[name]; + int dof_index = p_preset->get("graphics/degrees_of_freedom"); // 0: none, 1: 3dof and 6dof, 2: 6dof + + if (tname == "uses-feature" && dof_index > 0) { + if (xr_mode_index == 0) { + WARN_PRINT("VR DOF feature setting is only valid for oculus HMDs with an XR mode set to VR"); + } + ofs += 24; // skip over end tag + + // save manifest ending so we can restore it + Vector<uint8_t> manifest_end; + uint32_t manifest_cur_size = p_manifest.size(); + + manifest_end.resize(p_manifest.size() - ofs); + memcpy(manifest_end.ptrw(), &p_manifest[ofs], manifest_end.size()); + + int32_t attr_name_string = string_table.find("name"); + ERR_FAIL_COND_MSG(attr_name_string == -1, "Template does not have 'name' attribute."); + + int32_t ns_android_string = string_table.find("http://schemas.android.com/apk/res/android"); + if (ns_android_string == -1) { + string_table.push_back("http://schemas.android.com/apk/res/android"); + ns_android_string = string_table.size() - 1; + } + + int32_t attr_uses_permission_string = string_table.find("uses-feature"); + if (attr_uses_permission_string == -1) { + string_table.push_back("uses-feature"); + attr_uses_permission_string = string_table.size() - 1; + } + + int32_t attr_required_string = string_table.find("required"); + if (attr_required_string == -1) { + string_table.push_back("required"); + attr_required_string = string_table.size() - 1; + } + + int32_t attr_version_string = string_table.find("version"); + if (attr_version_string == -1) { + string_table.push_back("version"); + attr_version_string = string_table.size() - 1; + } + + String required_value_string; + if (dof_index == 1) { + required_value_string = "false"; + } else if (dof_index == 2) { + required_value_string = "true"; + } else { + ERR_FAIL_MSG("Unknown DoF index: " + itos(dof_index) + "."); + } + int32_t required_value = string_table.find(required_value_string); + if (required_value == -1) { + string_table.push_back(required_value_string); + required_value = string_table.size() - 1; + } + + int32_t version_value = string_table.find("1"); + if (version_value == -1) { + string_table.push_back("1"); + version_value = string_table.size() - 1; + } + + int32_t feature_string = string_table.find("android.hardware.vr.headtracking"); + if (feature_string == -1) { + string_table.push_back("android.hardware.vr.headtracking"); + feature_string = string_table.size() - 1; + } + + { + manifest_cur_size += 96 + 20; // node and three attrs + end node + p_manifest.resize(manifest_cur_size); + + // start tag + encode_uint16(0x102, &p_manifest.write[ofs]); // type + encode_uint16(16, &p_manifest.write[ofs + 2]); // headersize + encode_uint32(96, &p_manifest.write[ofs + 4]); // size + encode_uint32(0, &p_manifest.write[ofs + 8]); // lineno + encode_uint32(-1, &p_manifest.write[ofs + 12]); // comment + encode_uint32(-1, &p_manifest.write[ofs + 16]); // ns + encode_uint32(attr_uses_permission_string, &p_manifest.write[ofs + 20]); // name + encode_uint16(20, &p_manifest.write[ofs + 24]); // attr_start + encode_uint16(20, &p_manifest.write[ofs + 26]); // attr_size + encode_uint16(3, &p_manifest.write[ofs + 28]); // num_attrs + encode_uint16(0, &p_manifest.write[ofs + 30]); // id_index + encode_uint16(0, &p_manifest.write[ofs + 32]); // class_index + encode_uint16(0, &p_manifest.write[ofs + 34]); // style_index + + // android:name attribute + encode_uint32(ns_android_string, &p_manifest.write[ofs + 36]); // ns + encode_uint32(attr_name_string, &p_manifest.write[ofs + 40]); // 'name' + encode_uint32(feature_string, &p_manifest.write[ofs + 44]); // raw_value + encode_uint16(8, &p_manifest.write[ofs + 48]); // typedvalue_size + p_manifest.write[ofs + 50] = 0; // typedvalue_always0 + p_manifest.write[ofs + 51] = 0x03; // typedvalue_type (string) + encode_uint32(feature_string, &p_manifest.write[ofs + 52]); // typedvalue reference + + // android:required attribute + encode_uint32(ns_android_string, &p_manifest.write[ofs + 56]); // ns + encode_uint32(attr_required_string, &p_manifest.write[ofs + 60]); // 'name' + encode_uint32(required_value, &p_manifest.write[ofs + 64]); // raw_value + encode_uint16(8, &p_manifest.write[ofs + 68]); // typedvalue_size + p_manifest.write[ofs + 70] = 0; // typedvalue_always0 + p_manifest.write[ofs + 71] = 0x03; // typedvalue_type (string) + encode_uint32(required_value, &p_manifest.write[ofs + 72]); // typedvalue reference + + // android:version attribute + encode_uint32(ns_android_string, &p_manifest.write[ofs + 76]); // ns + encode_uint32(attr_version_string, &p_manifest.write[ofs + 80]); // 'name' + encode_uint32(version_value, &p_manifest.write[ofs + 84]); // raw_value + encode_uint16(8, &p_manifest.write[ofs + 88]); // typedvalue_size + p_manifest.write[ofs + 90] = 0; // typedvalue_always0 + p_manifest.write[ofs + 91] = 0x03; // typedvalue_type (string) + encode_uint32(version_value, &p_manifest.write[ofs + 92]); // typedvalue reference + + ofs += 96; + + // end tag + encode_uint16(0x103, &p_manifest.write[ofs]); // type + encode_uint16(16, &p_manifest.write[ofs + 2]); // headersize + encode_uint32(24, &p_manifest.write[ofs + 4]); // size + encode_uint32(0, &p_manifest.write[ofs + 8]); // lineno + encode_uint32(-1, &p_manifest.write[ofs + 12]); // comment + encode_uint32(-1, &p_manifest.write[ofs + 16]); // ns + encode_uint32(attr_uses_permission_string, &p_manifest.write[ofs + 20]); // name + + ofs += 24; + } + memcpy(&p_manifest.write[ofs], manifest_end.ptr(), manifest_end.size()); + ofs -= 24; // go back over back end + } if (tname == "manifest") { // save manifest ending so we can restore it @@ -857,12 +987,10 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { memcpy(manifest_end.ptrw(), &p_manifest[ofs], manifest_end.size()); int32_t attr_name_string = string_table.find("name"); - ERR_EXPLAIN("Template does not have 'name' attribute"); - ERR_FAIL_COND(attr_name_string == -1); + ERR_FAIL_COND_MSG(attr_name_string == -1, "Template does not have 'name' attribute."); int32_t ns_android_string = string_table.find("android"); - ERR_EXPLAIN("Template does not have 'android' namespace"); - ERR_FAIL_COND(ns_android_string == -1); + ERR_FAIL_COND_MSG(ns_android_string == -1, "Template does not have 'android' namespace."); int32_t attr_uses_permission_string = string_table.find("uses-permission"); if (attr_uses_permission_string == -1) { @@ -1156,6 +1284,7 @@ public: virtual void get_export_options(List<ExportOption> *r_options) { r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "graphics/xr_mode", PROPERTY_HINT_ENUM, "Regular,Oculus Mobile VR"), 0)); + r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "graphics/degrees_of_freedom", PROPERTY_HINT_ENUM, "None,3DOF and 6DOF,6DOF"), 0)); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "graphics/32_bits_framebuffer"), true)); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "one_click_deploy/clear_previous_install"), true)); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_package/debug", PROPERTY_HINT_GLOBAL_FILE, "*.apk"), "")); @@ -1270,8 +1399,9 @@ public: return ERR_UNCONFIGURED; } - //export_temp + // Export_temp APK. if (ep.step("Exporting APK", 0)) { + device_lock->unlock(); return ERR_SKIP; } @@ -1281,11 +1411,20 @@ public: if (use_reverse) p_debug_flags |= DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST; - String export_to = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpexport.apk"); - Error err = export_project(p_preset, true, export_to, p_debug_flags); - if (err) { - device_lock->unlock(); - return err; + String tmp_export_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpexport.apk"); + +#define CLEANUP_AND_RETURN(m_err) \ + { \ + DirAccess::remove_file_or_error(tmp_export_path); \ + device_lock->unlock(); \ + return m_err; \ + } + + // Export to temporary APK before sending to device. + Error err = export_project(p_preset, true, tmp_export_path, p_debug_flags); + + if (err != OK) { + CLEANUP_AND_RETURN(err); } List<String> args; @@ -1297,7 +1436,7 @@ public: if (remove_prev) { if (ep.step("Uninstalling...", 1)) { - return ERR_SKIP; + CLEANUP_AND_RETURN(ERR_SKIP); } print_line("Uninstalling previous version: " + devices[p_device].name); @@ -1312,7 +1451,7 @@ public: print_line("Installing to device (please wait...): " + devices[p_device].name); if (ep.step("Installing to device (please wait...)", 2)) { - return ERR_SKIP; + CLEANUP_AND_RETURN(ERR_SKIP); } args.clear(); @@ -1320,13 +1459,12 @@ public: args.push_back(devices[p_device].id); args.push_back("install"); args.push_back("-r"); - args.push_back(export_to); + args.push_back(tmp_export_path); err = OS::get_singleton()->execute(adb, args, true, NULL, NULL, &rv); if (err || rv != 0) { EditorNode::add_io_error("Could not install to device."); - device_lock->unlock(); - return ERR_CANT_CREATE; + CLEANUP_AND_RETURN(ERR_CANT_CREATE); } if (use_remote) { @@ -1380,7 +1518,7 @@ public: } if (ep.step("Running on Device...", 3)) { - return ERR_SKIP; + CLEANUP_AND_RETURN(ERR_SKIP); } args.clear(); args.push_back("-s"); @@ -1400,11 +1538,11 @@ public: err = OS::get_singleton()->execute(adb, args, true, NULL, NULL, &rv); if (err || rv != 0) { EditorNode::add_io_error("Could not execute on device."); - device_lock->unlock(); - return ERR_CANT_CREATE; + CLEANUP_AND_RETURN(ERR_CANT_CREATE); } - device_lock->unlock(); - return OK; + + CLEANUP_AND_RETURN(OK); +#undef CLEANUP_AND_RETURN } virtual Ref<Texture> get_run_icon() const { @@ -1895,8 +2033,16 @@ public: zlib_filefunc_def io2 = io; FileAccess *dst_f = NULL; io2.opaque = &dst_f; - String unaligned_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpexport-unaligned.apk"); - zipFile unaligned_apk = zipOpen2(unaligned_path.utf8().get_data(), APPEND_STATUS_CREATE, NULL, &io2); + + String tmp_unaligned_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpexport-unaligned.apk"); + +#define CLEANUP_AND_RETURN(m_err) \ + { \ + DirAccess::remove_file_or_error(tmp_unaligned_path); \ + return m_err; \ + } + + zipFile unaligned_apk = zipOpen2(tmp_unaligned_path.utf8().get_data(), APPEND_STATUS_CREATE, NULL, &io2); bool use_32_fb = p_preset->get("graphics/32_bits_framebuffer"); bool immersive = p_preset->get("screen/immersive_mode"); @@ -2024,7 +2170,7 @@ public: } if (ep.step("Adding Files...", 1)) { - return ERR_SKIP; + CLEANUP_AND_RETURN(ERR_SKIP); } Error err = OK; Vector<String> cl = cmdline.strip_edges().split(" "); @@ -2056,7 +2202,7 @@ public: unzClose(pkg); EditorNode::add_io_error("Could not write expansion package file: " + apkfname); - return OK; + CLEANUP_AND_RETURN(ERR_SKIP); } cl.push_back("--use_apk_expansion"); @@ -2143,8 +2289,8 @@ public: zipClose(unaligned_apk, NULL); unzClose(pkg); - if (err) { - return err; + if (err != OK) { + CLEANUP_AND_RETURN(err); } if (_signed) { @@ -2152,7 +2298,7 @@ public: String jarsigner = EditorSettings::get_singleton()->get("export/android/jarsigner"); if (!FileAccess::exists(jarsigner)) { EditorNode::add_io_error("'jarsigner' could not be found.\nPlease supply a path in the Editor Settings.\nThe resulting APK is unsigned."); - return OK; + CLEANUP_AND_RETURN(OK); } String keystore; @@ -2172,7 +2318,7 @@ public: } if (ep.step("Signing debug APK...", 103)) { - return ERR_SKIP; + CLEANUP_AND_RETURN(ERR_SKIP); } } else { @@ -2181,13 +2327,13 @@ public: user = release_username; if (ep.step("Signing release APK...", 103)) { - return ERR_SKIP; + CLEANUP_AND_RETURN(ERR_SKIP); } } if (!FileAccess::exists(keystore)) { EditorNode::add_io_error("Could not find keystore, unable to export."); - return ERR_FILE_CANT_OPEN; + CLEANUP_AND_RETURN(ERR_FILE_CANT_OPEN); } List<String> args; @@ -2205,30 +2351,30 @@ public: args.push_back(keystore); args.push_back("-storepass"); args.push_back(password); - args.push_back(unaligned_path); + args.push_back(tmp_unaligned_path); args.push_back(user); int retval; OS::get_singleton()->execute(jarsigner, args, true, NULL, NULL, &retval); if (retval) { EditorNode::add_io_error("'jarsigner' returned with error #" + itos(retval)); - return ERR_CANT_CREATE; + CLEANUP_AND_RETURN(ERR_CANT_CREATE); } if (ep.step("Verifying APK...", 104)) { - return ERR_SKIP; + CLEANUP_AND_RETURN(ERR_SKIP); } args.clear(); args.push_back("-verify"); args.push_back("-keystore"); args.push_back(keystore); - args.push_back(unaligned_path); + args.push_back(tmp_unaligned_path); args.push_back("-verbose"); OS::get_singleton()->execute(jarsigner, args, true, NULL, NULL, &retval); if (retval) { EditorNode::add_io_error("'jarsigner' verification of APK failed. Make sure to use a jarsigner from OpenJDK 8."); - return ERR_CANT_CREATE; + CLEANUP_AND_RETURN(ERR_CANT_CREATE); } } @@ -2237,14 +2383,14 @@ public: static const int ZIP_ALIGNMENT = 4; if (ep.step("Aligning APK...", 105)) { - return ERR_SKIP; + CLEANUP_AND_RETURN(ERR_SKIP); } - unzFile tmp_unaligned = unzOpen2(unaligned_path.utf8().get_data(), &io); + unzFile tmp_unaligned = unzOpen2(tmp_unaligned_path.utf8().get_data(), &io); if (!tmp_unaligned) { - EditorNode::add_io_error("Could not find temp unaligned APK."); - return ERR_FILE_NOT_FOUND; + EditorNode::add_io_error("Could not unzip temporary unaligned APK."); + CLEANUP_AND_RETURN(ERR_FILE_NOT_FOUND); } ret = unzGoToFirstFile(tmp_unaligned); @@ -2314,7 +2460,7 @@ public: zipClose(final_apk, NULL); unzClose(tmp_unaligned); - return OK; + CLEANUP_AND_RETURN(OK); } virtual void get_platform_features(List<String> *r_features) { diff --git a/platform/android/java/src/org/godotengine/godot/Godot.java b/platform/android/java/src/org/godotengine/godot/Godot.java index 6e1841fa8b..f493b5f33f 100644 --- a/platform/android/java/src/org/godotengine/godot/Godot.java +++ b/platform/android/java/src/org/godotengine/godot/Godot.java @@ -56,6 +56,7 @@ import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.os.Messenger; +import android.os.Vibrator; import android.provider.Settings.Secure; import android.support.v4.content.ContextCompat; import android.view.Display; @@ -98,6 +99,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC static final int MAX_SINGLETONS = 64; static final int REQUEST_RECORD_AUDIO_PERMISSION = 1; static final int REQUEST_CAMERA_PERMISSION = 2; + static final int REQUEST_VIBRATE_PERMISSION = 3; private IStub mDownloaderClientStub; private IDownloaderService mRemoteService; private TextView mStatusText; @@ -324,6 +326,15 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC }); } + public void vibrate(int p_duration_ms) { + if (requestPermission("VIBRATE")) { + Vibrator v = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE); + if (v != null) { + v.vibrate(p_duration_ms); + } + } + } + public void restart() { // HACK: // @@ -625,6 +636,10 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC GodotLib.ondestroy(this); super.onDestroy(); + + // TODO: This is a temp solution. The proper fix will involve tracking down and properly shutting down each + // native Godot components that is started in Godot#onVideoInit. + forceQuit(); } @Override @@ -985,6 +1000,13 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC return false; } } + + if (p_name.equals("VIBRATE")) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.VIBRATE) != PackageManager.PERMISSION_GRANTED) { + requestPermissions(new String[] { Manifest.permission.VIBRATE }, REQUEST_VIBRATE_PERMISSION); + return false; + } + } return true; } diff --git a/platform/android/java_godot_lib_jni.cpp b/platform/android/java_godot_lib_jni.cpp index 77f077456e..1159e93166 100644 --- a/platform/android/java_godot_lib_jni.cpp +++ b/platform/android/java_godot_lib_jni.cpp @@ -686,20 +686,11 @@ static void _initialize_java_modules() { print_line("Loading Android module: " + m); jstring strClassName = env->NewStringUTF(m.utf8().get_data()); jclass singletonClass = (jclass)env->CallObjectMethod(cls, findClass, strClassName); - - if (!singletonClass) { - - ERR_EXPLAIN("Couldn't find singleton for class: " + m); - ERR_CONTINUE(!singletonClass); - } + ERR_CONTINUE_MSG(!singletonClass, "Couldn't find singleton for class: " + m + "."); jmethodID initialize = env->GetStaticMethodID(singletonClass, "initialize", "(Landroid/app/Activity;)Lorg/godotengine/godot/Godot$SingletonBase;"); + ERR_CONTINUE_MSG(!initialize, "Couldn't find proper initialize function 'public static Godot.SingletonBase Class::initialize(Activity p_activity)' initializer for singleton class: " + m + "."); - if (!initialize) { - - ERR_EXPLAIN("Couldn't find proper initialize function 'public static Godot.SingletonBase Class::initialize(Activity p_activity)' initializer for singleton class: " + m); - ERR_CONTINUE(!initialize); - } jobject obj = env->CallStaticObjectMethod(singletonClass, initialize, godot_java->get_activity()); env->NewGlobalRef(obj); } diff --git a/platform/android/java_godot_wrapper.cpp b/platform/android/java_godot_wrapper.cpp index 339b14974c..c7dc1d124c 100644 --- a/platform/android/java_godot_wrapper.cpp +++ b/platform/android/java_godot_wrapper.cpp @@ -62,6 +62,7 @@ GodotJavaWrapper::GodotJavaWrapper(JNIEnv *p_env, jobject p_godot_instance) { _init_input_devices = p_env->GetMethodID(cls, "initInputDevices", "()V"); _get_surface = p_env->GetMethodID(cls, "getSurface", "()Landroid/view/Surface;"); _is_activity_resumed = p_env->GetMethodID(cls, "isActivityResumed", "()Z"); + _vibrate = p_env->GetMethodID(cls, "vibrate", "(I)V"); } GodotJavaWrapper::~GodotJavaWrapper() { @@ -211,3 +212,10 @@ bool GodotJavaWrapper::is_activity_resumed() { return false; } } + +void GodotJavaWrapper::vibrate(int p_duration_ms) { + if (_vibrate) { + JNIEnv *env = ThreadAndroid::get_env(); + env->CallVoidMethod(godot_instance, _vibrate, p_duration_ms); + } +} diff --git a/platform/android/java_godot_wrapper.h b/platform/android/java_godot_wrapper.h index 82c2a5d122..3e0e950180 100644 --- a/platform/android/java_godot_wrapper.h +++ b/platform/android/java_godot_wrapper.h @@ -57,6 +57,7 @@ private: jmethodID _init_input_devices = 0; jmethodID _get_surface = 0; jmethodID _is_activity_resumed = 0; + jmethodID _vibrate = 0; public: GodotJavaWrapper(JNIEnv *p_env, jobject p_godot_instance); @@ -82,6 +83,7 @@ public: void init_input_devices(); jobject get_surface(); bool is_activity_resumed(); + void vibrate(int p_duration_ms); }; #endif /* !JAVA_GODOT_WRAPPER_H */ diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index ebc319e57d..9b2df50f6c 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -71,8 +71,7 @@ const char *OS_Android::get_video_driver_name(int p_driver) const { case VIDEO_DRIVER_GLES2: return "GLES2"; } - ERR_EXPLAIN("Invalid video driver index " + itos(p_driver)); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Invalid video driver index: " + itos(p_driver) + "."); } int OS_Android::get_audio_driver_count() const { @@ -223,10 +222,7 @@ bool OS_Android::request_permission(const String &p_name) { Error OS_Android::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) { p_library_handle = dlopen(p_path.utf8().get_data(), RTLD_NOW); - if (!p_library_handle) { - ERR_EXPLAIN("Can't open dynamic library: " + p_path + ". Error: " + dlerror()); - ERR_FAIL_V(ERR_CANT_OPEN); - } + ERR_FAIL_COND_V_MSG(!p_library_handle, ERR_CANT_OPEN, "Can't open dynamic library: " + p_path + ", error: " + dlerror() + "."); return OK; } @@ -704,6 +700,10 @@ String OS_Android::get_joy_guid(int p_device) const { return input->get_joy_guid_remapped(p_device); } +void OS_Android::vibrate_handheld(int p_duration_ms) { + godot_java->vibrate(p_duration_ms); +} + bool OS_Android::_check_internal_feature_support(const String &p_feature) { if (p_feature == "mobile") { //TODO support etc2 only if GLES3 driver is selected diff --git a/platform/android/os_android.h b/platform/android/os_android.h index e74d4cfd43..a17941f7c0 100644 --- a/platform/android/os_android.h +++ b/platform/android/os_android.h @@ -198,6 +198,7 @@ public: virtual bool is_joy_known(int p_device); virtual String get_joy_guid(int p_device) const; void joy_connection_changed(int p_device, bool p_connected, String p_name); + void vibrate_handheld(int p_duration_ms); virtual bool _check_internal_feature_support(const String &p_feature); OS_Android(GodotJavaWrapper *p_godot_java, GodotIOJavaWrapper *p_godot_io_java, bool p_use_apk_expansion); diff --git a/platform/android/thread_jandroid.h b/platform/android/thread_jandroid.h index 1e1c00ab39..0b6e1f4b4a 100644 --- a/platform/android/thread_jandroid.h +++ b/platform/android/thread_jandroid.h @@ -31,10 +31,6 @@ #ifndef THREAD_POSIX_H #define THREAD_POSIX_H -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - #include "core/os/thread.h" #include <jni.h> #include <pthread.h> diff --git a/platform/iphone/app_delegate.mm b/platform/iphone/app_delegate.mm index 64405bfa5b..3f1230faa8 100644 --- a/platform/iphone/app_delegate.mm +++ b/platform/iphone/app_delegate.mm @@ -37,6 +37,7 @@ #include "os_iphone.h" #import "GameController/GameController.h" +#import <AudioToolbox/AudioServices.h> #define kFilteringFactor 0.1 #define kRenderingFrequency 60 @@ -61,6 +62,10 @@ void _set_keep_screen_on(bool p_enabled) { [[UIApplication sharedApplication] setIdleTimerDisabled:(BOOL)p_enabled]; }; +void _vibrate() { + AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); +}; + @implementation AppDelegate @synthesize window; diff --git a/platform/iphone/export/export.cpp b/platform/iphone/export/export.cpp index a179b36bd5..1cbf4d6a70 100644 --- a/platform/iphone/export/export.cpp +++ b/platform/iphone/export/export.cpp @@ -768,8 +768,7 @@ Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir DirAccess *da = DirAccess::create_for_path(asset); if (!da) { memdelete(filesystem_da); - ERR_EXPLAIN("Can't create directory: " + asset); - ERR_FAIL_V(ERR_CANT_CREATE); + ERR_FAIL_V_MSG(ERR_CANT_CREATE, "Can't create directory: " + asset + "."); } bool file_exists = da->file_exists(asset); bool dir_exists = da->dir_exists(asset); @@ -848,8 +847,7 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p EditorProgress ep("export", "Exporting for iOS", 5, true); String team_id = p_preset->get("application/app_store_team_id"); - ERR_EXPLAIN("App Store Team ID not specified - cannot configure the project."); - ERR_FAIL_COND_V(team_id.length() == 0, ERR_CANT_OPEN); + ERR_FAIL_COND_V_MSG(team_id.length() == 0, ERR_CANT_OPEN, "App Store Team ID not specified - cannot configure the project."); if (p_debug) src_pkg_name = p_preset->get("custom_package/debug"); diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp index f5fce66059..353078c51c 100644 --- a/platform/iphone/os_iphone.cpp +++ b/platform/iphone/os_iphone.cpp @@ -64,8 +64,7 @@ const char *OSIPhone::get_video_driver_name(int p_driver) const { case VIDEO_DRIVER_GLES2: return "GLES2"; } - ERR_EXPLAIN("Invalid video driver index " + itos(p_driver)); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Invalid video driver index: " + itos(p_driver) + "."); }; OSIPhone *OSIPhone::get_singleton() { @@ -471,6 +470,7 @@ extern void _show_keyboard(String p_existing); extern void _hide_keyboard(); extern Error _shell_open(String p_uri); extern void _set_keep_screen_on(bool p_enabled); +extern void _vibrate(); void OSIPhone::show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect) { _show_keyboard(p_existing_text); @@ -586,6 +586,11 @@ void OSIPhone::native_video_stop() { _stop_video(); } +void OSIPhone::vibrate_handheld(int p_duration_ms) { + // iOS does not support duration for vibration + _vibrate(); +} + bool OSIPhone::_check_internal_feature_support(const String &p_feature) { return p_feature == "mobile"; diff --git a/platform/iphone/os_iphone.h b/platform/iphone/os_iphone.h index c16c29a858..804ba0b1af 100644 --- a/platform/iphone/os_iphone.h +++ b/platform/iphone/os_iphone.h @@ -195,6 +195,7 @@ public: virtual void native_video_unpause(); virtual void native_video_focus_out(); virtual void native_video_stop(); + virtual void vibrate_handheld(int p_duration_ms = 500); virtual bool _check_internal_feature_support(const String &p_feature); OSIPhone(int width, int height, String p_data_dir); diff --git a/platform/iphone/view_controller.h b/platform/iphone/view_controller.h index fc18661f62..68e3bc64fc 100644 --- a/platform/iphone/view_controller.h +++ b/platform/iphone/view_controller.h @@ -39,6 +39,10 @@ - (void)didReceiveMemoryWarning; +- (void)viewDidLoad; + +- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures; + - (BOOL)prefersStatusBarHidden; @end diff --git a/platform/iphone/view_controller.mm b/platform/iphone/view_controller.mm index 0358abf9e2..e52ad92bf2 100644 --- a/platform/iphone/view_controller.mm +++ b/platform/iphone/view_controller.mm @@ -83,6 +83,18 @@ int add_cmdline(int p_argc, char **p_args) { printf("*********** did receive memory warning!\n"); }; +- (void)viewDidLoad { + [super viewDidLoad]; + + if (@available(iOS 11.0, *)) { + [self setNeedsUpdateOfScreenEdgesDeferringSystemGestures]; + } +} + +- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures { + return UIRectEdgeAll; +} + - (BOOL)shouldAutorotate { switch (OS::get_singleton()->get_screen_orientation()) { case OS::SCREEN_SENSOR: diff --git a/platform/javascript/audio_driver_javascript.cpp b/platform/javascript/audio_driver_javascript.cpp index 163826f828..b359699d3a 100644 --- a/platform/javascript/audio_driver_javascript.cpp +++ b/platform/javascript/audio_driver_javascript.cpp @@ -63,7 +63,7 @@ void AudioDriverJavaScript::mix_to_js() { void AudioDriverJavaScript::process_capture(float sample) { int32_t sample32 = int32_t(sample * 32768.f) * (1U << 16); - input_buffer_write(sample32); + capture_buffer_write(sample32); } Error AudioDriverJavaScript::init() { @@ -198,7 +198,7 @@ void AudioDriverJavaScript::finish() { Error AudioDriverJavaScript::capture_start() { - input_buffer_init(buffer_length); + capture_buffer_init(buffer_length); /* clang-format off */ EM_ASM({ @@ -245,8 +245,6 @@ Error AudioDriverJavaScript::capture_stop() { }); /* clang-format on */ - input_buffer.clear(); - return OK; } diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py index ac43392700..a0d6ac9214 100644 --- a/platform/javascript/detect.py +++ b/platform/javascript/detect.py @@ -141,3 +141,6 @@ def configure(env): # TODO: Reevaluate usage of this setting now that engine.js manages engine runtime. env.Append(LINKFLAGS=['-s', 'NO_EXIT_RUNTIME=1']) + + #adding flag due to issue with emscripten 1.38.41 callMain method https://github.com/emscripten-core/emscripten/blob/incoming/ChangeLog.md#v13841-08072019 + env.Append(LINKFLAGS=['-s', 'EXTRA_EXPORTED_RUNTIME_METHODS=["callMain"]']) diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp index c68b420c61..69dd038709 100644 --- a/platform/javascript/export/export.cpp +++ b/platform/javascript/export/export.cpp @@ -362,12 +362,21 @@ int EditorExportPlatformJavaScript::get_device_count() const { Error EditorExportPlatformJavaScript::run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags) { - String path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp_export.html"); + String basepath = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp_js_export"); + String path = basepath + ".html"; Error err = export_project(p_preset, true, path, p_debug_flags); - if (err) { + if (err != OK) { + // Export generates several files, clean them up on failure. + DirAccess::remove_file_or_error(basepath + ".html"); + DirAccess::remove_file_or_error(basepath + ".js"); + DirAccess::remove_file_or_error(basepath + ".pck"); + DirAccess::remove_file_or_error(basepath + ".png"); + DirAccess::remove_file_or_error(basepath + ".wasm"); return err; } OS::get_singleton()->shell_open(String("file://") + path); + // FIXME: Find out how to clean up export files after running the successfully + // exported game. Might not be trivial. return OK; } diff --git a/platform/javascript/http_client_javascript.cpp b/platform/javascript/http_client_javascript.cpp index b4bab9a999..e6e933811f 100644 --- a/platform/javascript/http_client_javascript.cpp +++ b/platform/javascript/http_client_javascript.cpp @@ -68,21 +68,18 @@ Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl, void HTTPClient::set_connection(const Ref<StreamPeer> &p_connection) { - ERR_EXPLAIN("Accessing an HTTPClient's StreamPeer is not supported for the HTML5 platform"); - ERR_FAIL(); + ERR_FAIL_MSG("Accessing an HTTPClient's StreamPeer is not supported for the HTML5 platform."); } Ref<StreamPeer> HTTPClient::get_connection() const { - ERR_EXPLAIN("Accessing an HTTPClient's StreamPeer is not supported for the HTML5 platform"); - ERR_FAIL_V(REF()); + ERR_FAIL_V_MSG(REF(), "Accessing an HTTPClient's StreamPeer is not supported for the HTML5 platform."); } Error HTTPClient::prepare_request(Method p_method, const String &p_url, const Vector<String> &p_headers) { ERR_FAIL_INDEX_V(p_method, METHOD_MAX, ERR_INVALID_PARAMETER); - ERR_EXPLAIN("HTTP methods TRACE and CONNECT are not supported for the HTML5 platform"); - ERR_FAIL_COND_V(p_method == METHOD_TRACE || p_method == METHOD_CONNECT, ERR_UNAVAILABLE); + ERR_FAIL_COND_V_MSG(p_method == METHOD_TRACE || p_method == METHOD_CONNECT, ERR_UNAVAILABLE, "HTTP methods TRACE and CONNECT are not supported for the HTML5 platform."); ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(host.empty(), ERR_UNCONFIGURED); ERR_FAIL_COND_V(port < 0, ERR_UNCONFIGURED); @@ -201,8 +198,7 @@ PoolByteArray HTTPClient::read_response_body_chunk() { void HTTPClient::set_blocking_mode(bool p_enable) { - ERR_EXPLAIN("HTTPClient blocking mode is not supported for the HTML5 platform"); - ERR_FAIL_COND(p_enable); + ERR_FAIL_COND_MSG(p_enable, "HTTPClient blocking mode is not supported for the HTML5 platform."); } bool HTTPClient::is_blocking_mode_enabled() const { diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index 5363cd4af7..0179bf813d 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -192,9 +192,8 @@ void OS_JavaScript::set_window_fullscreen(bool p_enabled) { strategy.filteringMode = EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT; strategy.canvasResizedCallback = NULL; EMSCRIPTEN_RESULT result = emscripten_request_fullscreen_strategy(NULL, false, &strategy); - ERR_EXPLAIN("Enabling fullscreen is only possible from an input callback for the HTML5 platform"); - ERR_FAIL_COND(result == EMSCRIPTEN_RESULT_FAILED_NOT_DEFERRED); - ERR_FAIL_COND(result != EMSCRIPTEN_RESULT_SUCCESS); + ERR_FAIL_COND_MSG(result == EMSCRIPTEN_RESULT_FAILED_NOT_DEFERRED, "Enabling fullscreen is only possible from an input callback for the HTML5 platform."); + ERR_FAIL_COND_MSG(result != EMSCRIPTEN_RESULT_SUCCESS, "Enabling fullscreen is only possible from an input callback for the HTML5 platform."); // Not fullscreen yet, so prevent "windowed" canvas dimensions from // being overwritten. entering_fullscreen = true; @@ -582,8 +581,7 @@ void OS_JavaScript::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_s void OS_JavaScript::set_mouse_mode(OS::MouseMode p_mode) { - ERR_EXPLAIN("MOUSE_MODE_CONFINED is not supported for the HTML5 platform"); - ERR_FAIL_COND(p_mode == MOUSE_MODE_CONFINED); + ERR_FAIL_COND_MSG(p_mode == MOUSE_MODE_CONFINED, "MOUSE_MODE_CONFINED is not supported for the HTML5 platform."); if (p_mode == get_mouse_mode()) return; @@ -602,9 +600,8 @@ void OS_JavaScript::set_mouse_mode(OS::MouseMode p_mode) { } else if (p_mode == MOUSE_MODE_CAPTURED) { EMSCRIPTEN_RESULT result = emscripten_request_pointerlock("canvas", false); - ERR_EXPLAIN("MOUSE_MODE_CAPTURED can only be entered from within an appropriate input callback"); - ERR_FAIL_COND(result == EMSCRIPTEN_RESULT_FAILED_NOT_DEFERRED); - ERR_FAIL_COND(result != EMSCRIPTEN_RESULT_SUCCESS); + ERR_FAIL_COND_MSG(result == EMSCRIPTEN_RESULT_FAILED_NOT_DEFERRED, "MOUSE_MODE_CAPTURED can only be entered from within an appropriate input callback."); + ERR_FAIL_COND_MSG(result != EMSCRIPTEN_RESULT_SUCCESS, "MOUSE_MODE_CAPTURED can only be entered from within an appropriate input callback."); // set_css_cursor must be called before set_cursor_shape to make the cursor visible set_css_cursor(godot2dom_cursor(cursor_shape)); set_cursor_shape(cursor_shape); @@ -810,8 +807,7 @@ const char *OS_JavaScript::get_video_driver_name(int p_driver) const { case VIDEO_DRIVER_GLES2: return "GLES2"; } - ERR_EXPLAIN("Invalid video driver index " + itos(p_driver)); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Invalid video driver index: " + itos(p_driver) + "."); } // Audio @@ -846,8 +842,7 @@ void OS_JavaScript::set_clipboard(const String &p_text) { return 0; }, p_text.utf8().get_data()); /* clang-format on */ - ERR_EXPLAIN("Clipboard API is not supported."); - ERR_FAIL_COND(err); + ERR_FAIL_COND_MSG(err, "Clipboard API is not supported."); } String OS_JavaScript::get_clipboard() const { @@ -1117,20 +1112,17 @@ void OS_JavaScript::finalize() { Error OS_JavaScript::execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id, String *r_pipe, int *r_exitcode, bool read_stderr, Mutex *p_pipe_mutex) { - ERR_EXPLAIN("OS::execute() is not available on the HTML5 platform"); - ERR_FAIL_V(ERR_UNAVAILABLE); + ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "OS::execute() is not available on the HTML5 platform."); } Error OS_JavaScript::kill(const ProcessID &p_pid) { - ERR_EXPLAIN("OS::kill() is not available on the HTML5 platform"); - ERR_FAIL_V(ERR_UNAVAILABLE); + ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "OS::kill() is not available on the HTML5 platform."); } int OS_JavaScript::get_process_id() const { - ERR_EXPLAIN("OS::get_process_id() is not available on the HTML5 platform"); - ERR_FAIL_V(0); + ERR_FAIL_V_MSG(0, "OS::get_process_id() is not available on the HTML5 platform."); } extern "C" EMSCRIPTEN_KEEPALIVE void send_notification(int p_notification) { diff --git a/platform/osx/dir_access_osx.h b/platform/osx/dir_access_osx.h index e1aa038c61..c5951a570e 100644 --- a/platform/osx/dir_access_osx.h +++ b/platform/osx/dir_access_osx.h @@ -41,9 +41,6 @@ #include "core/os/dir_access.h" #include "drivers/unix/dir_access_unix.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class DirAccessOSX : public DirAccessUnix { protected: virtual String fix_unicode_name(const char *p_name) const; diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp index 8cabc45250..56b0a44dbc 100644 --- a/platform/osx/export/export.cpp +++ b/platform/osx/export/export.cpp @@ -29,9 +29,11 @@ /*************************************************************************/ #include "export.h" + #include "core/io/marshalls.h" #include "core/io/resource_saver.h" #include "core/io/zip_io.h" +#include "core/os/dir_access.h" #include "core/os/file_access.h" #include "core/os/os.h" #include "core/project_settings.h" @@ -244,13 +246,17 @@ void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_ copy->resize(icon_infos[i].size, icon_infos[i].size); if (icon_infos[i].is_png) { - //encode png icon + // Encode PNG icon. it->create_from_image(copy); String path = EditorSettings::get_singleton()->get_cache_dir().plus_file("icon.png"); ResourceSaver::save(path, it); FileAccess *f = FileAccess::open(path, FileAccess::READ); - ERR_FAIL_COND(!f); + if (!f) { + // Clean up generated file. + DirAccess::remove_file_or_error(path); + ERR_FAIL(); + } int ofs = data.size(); uint32_t len = f->get_len(); @@ -261,6 +267,10 @@ void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_ len = BSWAP32(len); copymem(&data.write[ofs], icon_infos[i].name, 4); encode_uint32(len, &data.write[ofs + 4]); + + // Clean up generated file. + DirAccess::remove_file_or_error(path); + } else { PoolVector<uint8_t> src_data = copy->get_data(); @@ -561,7 +571,6 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p } } } - //bleh? } if (data.size() > 0) { @@ -687,7 +696,8 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p // Clean up temporary .app dir OS::get_singleton()->move_to_trash(tmp_app_path_name); - } else { + + } else { // pck String pack_path = EditorSettings::get_singleton()->get_cache_dir().plus_file(pkg_name + ".pck"); @@ -747,6 +757,9 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p zipCloseFileInZip(dst_pkg_zip); } } + + // Clean up generated file. + DirAccess::remove_file_or_error(pack_path); } } diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index a83d5084ed..9cb2915701 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -51,9 +51,6 @@ #include <CoreVideo/CoreVideo.h> #undef CursorShape -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class OS_OSX : public OS_Unix { public: diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index a48f784529..ab77897b08 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -1719,10 +1719,7 @@ Error OS_OSX::open_dynamic_library(const String p_path, void *&p_library_handle, } p_library_handle = dlopen(path.utf8().get_data(), RTLD_NOW); - if (!p_library_handle) { - ERR_EXPLAIN("Can't open dynamic library: " + p_path + ". Error: " + dlerror()); - ERR_FAIL_V(ERR_CANT_OPEN); - } + ERR_FAIL_COND_V_MSG(!p_library_handle, ERR_CANT_OPEN, "Can't open dynamic library: " + p_path + ", error: " + dlerror() + "."); return OK; } @@ -1962,15 +1959,10 @@ void OS_OSX::set_native_icon(const String &p_filename) { memdelete(f); NSData *icon_data = [[[NSData alloc] initWithBytes:&data.write[0] length:len] autorelease]; - if (!icon_data) { - ERR_EXPLAIN("Error reading icon data"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!icon_data, "Error reading icon data."); + NSImage *icon = [[[NSImage alloc] initWithData:icon_data] autorelease]; - if (!icon) { - ERR_EXPLAIN("Error loading icon"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!icon, "Error loading icon."); [NSApp setApplicationIconImage:icon]; } diff --git a/platform/server/detect.py b/platform/server/detect.py index 185dce8128..b6028c20e3 100644 --- a/platform/server/detect.py +++ b/platform/server/detect.py @@ -35,6 +35,7 @@ def get_opts(): BoolVariable('use_ubsan', 'Use LLVM/GCC compiler undefined behavior sanitizer (UBSAN)', False), BoolVariable('use_asan', 'Use LLVM/GCC compiler address sanitizer (ASAN))', False), BoolVariable('use_lsan', 'Use LLVM/GCC compiler leak sanitizer (LSAN))', False), + BoolVariable('use_tsan', 'Use LLVM/GCC compiler thread sanitizer (TSAN))', False), EnumVariable('debug_symbols', 'Add debugging symbols to release builds', 'yes', ('yes', 'no', 'full')), BoolVariable('separate_debug_symbols', 'Create a separate file containing debugging symbols', False), BoolVariable('execinfo', 'Use libexecinfo on systems where glibc is not available', False), @@ -99,7 +100,7 @@ def configure(env): env.extra_suffix = ".llvm" + env.extra_suffix - if env['use_ubsan'] or env['use_asan'] or env['use_lsan']: + if env['use_ubsan'] or env['use_asan'] or env['use_lsan'] or env['use_tsan']: env.extra_suffix += "s" if env['use_ubsan']: @@ -114,6 +115,10 @@ def configure(env): env.Append(CCFLAGS=['-fsanitize=leak']) env.Append(LINKFLAGS=['-fsanitize=leak']) + if env['use_tsan']: + env.Append(CCFLAGS=['-fsanitize=thread']) + env.Append(LINKFLAGS=['-fsanitize=thread']) + if env['use_lto']: env.Append(CCFLAGS=['-flto']) if not env['use_llvm'] and env.GetOption("num_jobs") > 1: diff --git a/platform/server/os_server.h b/platform/server/os_server.h index dbdae6afb1..b8119288ff 100644 --- a/platform/server/os_server.h +++ b/platform/server/os_server.h @@ -47,9 +47,6 @@ #include "servers/visual_server.h" #undef CursorShape -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class OS_Server : public OS_Unix { diff --git a/platform/uwp/export/export.cpp b/platform/uwp/export/export.cpp index 75ce422e9e..ea110b11ca 100644 --- a/platform/uwp/export/export.cpp +++ b/platform/uwp/export/export.cpp @@ -30,10 +30,11 @@ #include "export.h" #include "core/bind/core_bind.h" +#include "core/crypto/crypto_core.h" #include "core/io/marshalls.h" #include "core/io/zip_io.h" -#include "core/math/crypto_core.h" #include "core/object.h" +#include "core/os/dir_access.h" #include "core/os/file_access.h" #include "core/project_settings.h" #include "core/version.h" @@ -133,8 +134,6 @@ class AppxPackager { String progress_task; FileAccess *package; - String tmp_blockmap_file_path; - String tmp_content_types_file_path; Set<String> mime_types; @@ -146,8 +145,8 @@ class AppxPackager { String hash_block(const uint8_t *p_block_data, size_t p_block_len); - void make_block_map(); - void make_content_types(); + void make_block_map(const String &p_path); + void make_content_types(const String &p_path); _FORCE_INLINE_ unsigned int buf_put_int16(uint16_t p_val, uint8_t *p_buf) { for (int i = 0; i < 2; i++) { @@ -208,9 +207,9 @@ String AppxPackager::hash_block(const uint8_t *p_block_data, size_t p_block_len) return String(base64); } -void AppxPackager::make_block_map() { +void AppxPackager::make_block_map(const String &p_path) { - FileAccess *tmp_file = FileAccess::open(tmp_blockmap_file_path, FileAccess::WRITE); + FileAccess *tmp_file = FileAccess::open(p_path, FileAccess::WRITE); tmp_file->store_string("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"); tmp_file->store_string("<BlockMap xmlns=\"http://schemas.microsoft.com/appx/2010/blockmap\" HashMethod=\"http://www.w3.org/2001/04/xmlenc#sha256\">"); @@ -253,9 +252,9 @@ String AppxPackager::content_type(String p_extension) { return "application/octet-stream"; } -void AppxPackager::make_content_types() { +void AppxPackager::make_content_types(const String &p_path) { - FileAccess *tmp_file = FileAccess::open(tmp_content_types_file_path, FileAccess::WRITE); + FileAccess *tmp_file = FileAccess::open(p_path, FileAccess::WRITE); tmp_file->store_string("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); tmp_file->store_string("<Types xmlns=\"http://schemas.openxmlformats.org/package/2006/content-types\">"); @@ -458,8 +457,6 @@ void AppxPackager::init(FileAccess *p_fa) { package = p_fa; central_dir_offset = 0; end_of_central_dir_offset = 0; - tmp_blockmap_file_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpblockmap.xml"); - tmp_content_types_file_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpcontenttypes.xml"); } Error AppxPackager::add_file(String p_file_name, const uint8_t *p_buffer, size_t p_len, int p_file_no, int p_total_files, bool p_compress) { @@ -591,7 +588,9 @@ void AppxPackager::finish() { // Create and add block map file EditorNode::progress_task_step("export", "Creating block map...", 4); - make_block_map(); + const String &tmp_blockmap_file_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpblockmap.xml"); + make_block_map(tmp_blockmap_file_path); + FileAccess *blockmap_file = FileAccess::open(tmp_blockmap_file_path, FileAccess::READ); Vector<uint8_t> blockmap_buffer; blockmap_buffer.resize(blockmap_file->get_len()); @@ -604,8 +603,11 @@ void AppxPackager::finish() { memdelete(blockmap_file); // Add content types + EditorNode::progress_task_step("export", "Setting content types...", 5); - make_content_types(); + + const String &tmp_content_types_file_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpcontenttypes.xml"); + make_content_types(tmp_content_types_file_path); FileAccess *types_file = FileAccess::open(tmp_content_types_file_path, FileAccess::READ); Vector<uint8_t> types_buffer; @@ -618,6 +620,10 @@ void AppxPackager::finish() { types_file->close(); memdelete(types_file); + // Cleanup generated files. + DirAccess::remove_file_or_error(tmp_blockmap_file_path); + DirAccess::remove_file_or_error(tmp_content_types_file_path); + // Pre-process central directory before signing for (int i = 0; i < file_metadata.size(); i++) { store_central_dir_header(file_metadata[i]); @@ -901,8 +907,7 @@ class EditorExportPlatformUWP : public EditorExportPlatform { String err_string = "Couldn't save temp logo file."; EditorNode::add_io_error(err_string); - ERR_EXPLAIN(err_string); - ERR_FAIL_V(data); + ERR_FAIL_V_MSG(data, err_string); } FileAccess *f = FileAccess::open(tmp_path, FileAccess::READ, &err); @@ -910,10 +915,10 @@ class EditorExportPlatformUWP : public EditorExportPlatform { if (err != OK) { String err_string = "Couldn't open temp logo file."; - + // Cleanup generated file. + DirAccess::remove_file_or_error(tmp_path); EditorNode::add_io_error(err_string); - ERR_EXPLAIN(err_string); - ERR_FAIL_V(data); + ERR_FAIL_V_MSG(data, err_string); } data.resize(f->get_len()); @@ -921,31 +926,7 @@ class EditorExportPlatformUWP : public EditorExportPlatform { f->close(); memdelete(f); - - // Delete temp file - DirAccess *dir = DirAccess::open(tmp_path.get_base_dir(), &err); - - if (err != OK) { - - String err_string = "Couldn't open temp path to remove temp logo file."; - - EditorNode::add_io_error(err_string); - ERR_EXPLAIN(err_string); - ERR_FAIL_V(data); - } - - err = dir->remove(tmp_path); - - memdelete(dir); - - if (err != OK) { - - String err_string = "Couldn't remove temp logo file."; - - EditorNode::add_io_error(err_string); - ERR_EXPLAIN(err_string); - ERR_FAIL_V(data); - } + DirAccess::remove_file_or_error(tmp_path); return data; } diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp index 9d9be44ce5..60f2290355 100644 --- a/platform/uwp/os_uwp.cpp +++ b/platform/uwp/os_uwp.cpp @@ -835,11 +835,7 @@ Error OS_UWP::open_dynamic_library(const String p_path, void *&p_library_handle, String full_path = "game/" + p_path; p_library_handle = (void *)LoadPackagedLibrary(full_path.c_str(), 0); - - if (!p_library_handle) { - ERR_EXPLAIN("Can't open dynamic library: " + full_path + ". Error: " + format_error_message(GetLastError())); - ERR_FAIL_V(ERR_CANT_OPEN); - } + ERR_FAIL_COND_V_MSG(!p_library_handle, ERR_CANT_OPEN, "Can't open dynamic library: " + full_path + ", error: " + format_error_message(GetLastError()) + "."); return OK; } @@ -854,8 +850,7 @@ Error OS_UWP::get_dynamic_library_symbol_handle(void *p_library_handle, const St p_symbol_handle = (void *)GetProcAddress((HMODULE)p_library_handle, p_name.utf8().get_data()); if (!p_symbol_handle) { if (!p_optional) { - ERR_EXPLAIN("Can't resolve symbol " + p_name + ". Error: " + String::num(GetLastError())); - ERR_FAIL_V(ERR_CANT_RESOLVE); + ERR_FAIL_V_MSG(ERR_CANT_RESOLVE, "Can't resolve symbol " + p_name + ", error: " + String::num(GetLastError()) + "."); } else { return ERR_CANT_RESOLVE; } diff --git a/platform/uwp/os_uwp.h b/platform/uwp/os_uwp.h index b7a7248f19..370cab6a9b 100644 --- a/platform/uwp/os_uwp.h +++ b/platform/uwp/os_uwp.h @@ -50,9 +50,6 @@ #include <stdio.h> #include <windows.h> -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class OS_UWP : public OS { public: diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 07470cec92..be325381bb 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -719,7 +719,7 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) pressrc = 0; } } - } else if (mouse_mode != MOUSE_MODE_CAPTURED) { + } else { // for reasons unknown to mankind, wheel comes in screen coordinates POINT coords; coords.x = mb->get_position().x; @@ -1435,16 +1435,13 @@ void OS_Windows::set_clipboard(const String &p_text) { String text = p_text.replace("\n", "\r\n"); if (!OpenClipboard(hWnd)) { - ERR_EXPLAIN("Unable to open clipboard."); - ERR_FAIL(); - }; + ERR_FAIL_MSG("Unable to open clipboard."); + } EmptyClipboard(); HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE, (text.length() + 1) * sizeof(CharType)); - if (mem == NULL) { - ERR_EXPLAIN("Unable to allocate memory for clipboard contents."); - ERR_FAIL(); - }; + ERR_FAIL_COND_MSG(mem == NULL, "Unable to allocate memory for clipboard contents."); + LPWSTR lptstrCopy = (LPWSTR)GlobalLock(mem); memcpy(lptstrCopy, text.c_str(), (text.length() + 1) * sizeof(CharType)); GlobalUnlock(mem); @@ -1454,10 +1451,8 @@ void OS_Windows::set_clipboard(const String &p_text) { // set the CF_TEXT version (not needed?) CharString utf8 = text.utf8(); mem = GlobalAlloc(GMEM_MOVEABLE, utf8.length() + 1); - if (mem == NULL) { - ERR_EXPLAIN("Unable to allocate memory for clipboard contents."); - ERR_FAIL(); - }; + ERR_FAIL_COND_MSG(mem == NULL, "Unable to allocate memory for clipboard contents."); + LPTSTR ptr = (LPTSTR)GlobalLock(mem); memcpy(ptr, utf8.get_data(), utf8.length()); ptr[utf8.length()] = 0; @@ -1472,8 +1467,7 @@ String OS_Windows::get_clipboard() const { String ret; if (!OpenClipboard(hWnd)) { - ERR_EXPLAIN("Unable to open clipboard."); - ERR_FAIL_V(""); + ERR_FAIL_V_MSG("", "Unable to open clipboard."); }; if (IsClipboardFormatAvailable(CF_UNICODETEXT)) { @@ -2135,15 +2129,12 @@ Error OS_Windows::open_dynamic_library(const String p_path, void *&p_library_han } p_library_handle = (void *)LoadLibraryExW(path.c_str(), NULL, (p_also_set_library_path && has_dll_directory_api) ? LOAD_LIBRARY_SEARCH_DEFAULT_DIRS : 0); + ERR_FAIL_COND_V_MSG(!p_library_handle, ERR_CANT_OPEN, "Can't open dynamic library: " + p_path + ", error: " + format_error_message(GetLastError()) + "."); if (cookie) { remove_dll_directory(cookie); } - if (!p_library_handle) { - ERR_EXPLAIN("Can't open dynamic library: " + p_path + ". Error: " + format_error_message(GetLastError())); - ERR_FAIL_V(ERR_CANT_OPEN); - } return OK; } @@ -2158,8 +2149,7 @@ Error OS_Windows::get_dynamic_library_symbol_handle(void *p_library_handle, cons p_symbol_handle = (void *)GetProcAddress((HMODULE)p_library_handle, p_name.utf8().get_data()); if (!p_symbol_handle) { if (!p_optional) { - ERR_EXPLAIN("Can't resolve symbol " + p_name + ". Error: " + String::num(GetLastError())); - ERR_FAIL_V(ERR_CANT_RESOLVE); + ERR_FAIL_V_MSG(ERR_CANT_RESOLVE, "Can't resolve symbol " + p_name + ", error: " + String::num(GetLastError()) + "."); } else { return ERR_CANT_RESOLVE; } @@ -2686,10 +2676,7 @@ void OS_Windows::set_native_icon(const String &p_filename) { pos += sizeof(WORD); f->seek(pos); - if (icon_dir->idType != 1) { - ERR_EXPLAIN("Invalid icon file format!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(icon_dir->idType != 1, "Invalid icon file format!"); icon_dir->idCount = f->get_32(); pos += sizeof(WORD); @@ -2722,10 +2709,7 @@ void OS_Windows::set_native_icon(const String &p_filename) { } } - if (big_icon_index == -1) { - ERR_EXPLAIN("No valid icons found!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(big_icon_index == -1, "No valid icons found!"); if (small_icon_index == -1) { WARN_PRINTS("No small icon found, reusing " + itos(big_icon_width) + "x" + itos(big_icon_width) + " @" + itos(big_icon_cc) + " icon!"); @@ -2741,10 +2725,7 @@ void OS_Windows::set_native_icon(const String &p_filename) { f->seek(pos); f->get_buffer((uint8_t *)&data_big.write[0], bytecount_big); HICON icon_big = CreateIconFromResource((PBYTE)&data_big.write[0], bytecount_big, TRUE, 0x00030000); - if (!icon_big) { - ERR_EXPLAIN("Could not create " + itos(big_icon_width) + "x" + itos(big_icon_width) + " @" + itos(big_icon_cc) + " icon, error: " + format_error_message(GetLastError())); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!icon_big, "Could not create " + itos(big_icon_width) + "x" + itos(big_icon_width) + " @" + itos(big_icon_cc) + " icon, error: " + format_error_message(GetLastError()) + "."); // Read the small icon DWORD bytecount_small = icon_dir->idEntries[small_icon_index].dwBytesInRes; @@ -2754,10 +2735,7 @@ void OS_Windows::set_native_icon(const String &p_filename) { f->seek(pos); f->get_buffer((uint8_t *)&data_small.write[0], bytecount_small); HICON icon_small = CreateIconFromResource((PBYTE)&data_small.write[0], bytecount_small, TRUE, 0x00030000); - if (!icon_small) { - ERR_EXPLAIN("Could not create 16x16 @" + itos(small_icon_cc) + " icon, error: " + format_error_message(GetLastError())); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!icon_small, "Could not create 16x16 @" + itos(small_icon_cc) + " icon, error: " + format_error_message(GetLastError()) + "."); // Online tradition says to be sure last error is cleared and set the small icon first int err = 0; @@ -2765,17 +2743,11 @@ void OS_Windows::set_native_icon(const String &p_filename) { SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)icon_small); err = GetLastError(); - if (err) { - ERR_EXPLAIN("Error setting ICON_SMALL: " + format_error_message(err)); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(err, "Error setting ICON_SMALL: " + format_error_message(err) + "."); SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)icon_big); err = GetLastError(); - if (err) { - ERR_EXPLAIN("Error setting ICON_BIG: " + format_error_message(err)); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(err, "Error setting ICON_BIG: " + format_error_message(err) + "."); memdelete(f); memdelete(icon_dir); diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index ce55328173..915d025e3b 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -56,10 +56,6 @@ #include <windows.h> #include <windowsx.h> -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - typedef struct { BYTE bWidth; // Width, in pixels, of the image BYTE bHeight; // Height, in pixels, of the image diff --git a/platform/x11/context_gl_x11.h b/platform/x11/context_gl_x11.h index 46420df48b..095ce2154b 100644 --- a/platform/x11/context_gl_x11.h +++ b/platform/x11/context_gl_x11.h @@ -31,9 +31,6 @@ #ifndef CONTEXT_GL_X11_H #define CONTEXT_GL_X11_H -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ #ifdef X11_ENABLED #if defined(OPENGL_ENABLED) diff --git a/platform/x11/detect.py b/platform/x11/detect.py index f3a486df02..b8ff97279d 100644 --- a/platform/x11/detect.py +++ b/platform/x11/detect.py @@ -64,6 +64,7 @@ def get_opts(): BoolVariable('use_ubsan', 'Use LLVM/GCC compiler undefined behavior sanitizer (UBSAN)', False), BoolVariable('use_asan', 'Use LLVM/GCC compiler address sanitizer (ASAN))', False), BoolVariable('use_lsan', 'Use LLVM/GCC compiler leak sanitizer (LSAN))', False), + BoolVariable('use_tsan', 'Use LLVM/GCC compiler thread sanitizer (TSAN))', False), BoolVariable('pulseaudio', 'Detect and use PulseAudio', True), BoolVariable('udev', 'Use udev for gamepad connection callbacks', False), EnumVariable('debug_symbols', 'Add debugging symbols to release builds', 'yes', ('yes', 'no', 'full')), @@ -140,7 +141,7 @@ def configure(env): print("Using LLD with GCC is not supported yet, try compiling with 'use_llvm=yes'.") sys.exit(255) - if env['use_ubsan'] or env['use_asan'] or env['use_lsan']: + if env['use_ubsan'] or env['use_asan'] or env['use_lsan'] or env['use_tsan']: env.extra_suffix += "s" if env['use_ubsan']: @@ -155,6 +156,10 @@ def configure(env): env.Append(CCFLAGS=['-fsanitize=leak']) env.Append(LINKFLAGS=['-fsanitize=leak']) + if env['use_tsan']: + env.Append(CCFLAGS=['-fsanitize=thread']) + env.Append(LINKFLAGS=['-fsanitize=thread']) + if env['use_lto']: if not env['use_llvm'] and env.GetOption("num_jobs") > 1: env.Append(CCFLAGS=['-flto']) diff --git a/platform/x11/export/export.cpp b/platform/x11/export/export.cpp index 8767aac517..6e66173463 100644 --- a/platform/x11/export/export.cpp +++ b/platform/x11/export/export.cpp @@ -85,8 +85,7 @@ static Error fixup_embedded_pck(const String &p_path, int64_t p_embedded_start, if (bits == 32 && p_embedded_size >= 0x100000000) { f->close(); - ERR_EXPLAIN("32-bit executables cannot have embedded data >= 4 GiB"); - ERR_FAIL_V(ERR_INVALID_DATA); + ERR_FAIL_V_MSG(ERR_INVALID_DATA, "32-bit executables cannot have embedded data >= 4 GiB."); } // Get info about the section header table diff --git a/platform/x11/key_mapping_x11.h b/platform/x11/key_mapping_x11.h index 853fe7954a..4e25d6a6ed 100644 --- a/platform/x11/key_mapping_x11.h +++ b/platform/x11/key_mapping_x11.h @@ -31,9 +31,6 @@ #ifndef KEY_MAPPING_X11_H #define KEY_MAPPING_X11_H -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ #include <X11/XF86keysym.h> #include <X11/Xlib.h> #define XK_MISCELLANY diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 0d1e702d04..ca72393e43 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -1518,9 +1518,12 @@ void OS_X11::set_window_maximized(bool p_enabled) { XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); - if (is_window_maximize_allowed()) { - while (p_enabled && !is_window_maximized()) { - // Wait for effective resizing (so the GLX context is too). + if (p_enabled && is_window_maximize_allowed()) { + // Wait for effective resizing (so the GLX context is too). + // Give up after 0.5s, it's not going to happen on this WM. + // https://github.com/godotengine/godot/issues/19978 + for (int attempt = 0; !is_window_maximized() && attempt < 50; attempt++) { + usleep(10000); } } diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index a4c22cf08a..e6c2effacf 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -77,9 +77,6 @@ typedef struct _xrr_monitor_info { } xrr_monitor_info; #undef CursorShape -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class OS_X11 : public OS_Unix { |