diff options
Diffstat (limited to 'platform')
23 files changed, 345 insertions, 157 deletions
diff --git a/platform/android/SCsub b/platform/android/SCsub index 7fb3c876be..b124a1a5a8 100644 --- a/platform/android/SCsub +++ b/platform/android/SCsub @@ -141,6 +141,8 @@ if env['android_arch'] == 'armv6': lib_arch_dir = 'armeabi' elif env['android_arch'] == 'armv7': lib_arch_dir = 'armeabi-v7a' +elif env['android_arch'] == 'arm64v8': + lib_arch_dir = 'arm64-v8a' elif env['android_arch'] == 'x86': lib_arch_dir = 'x86' else: diff --git a/platform/android/build.gradle.template b/platform/android/build.gradle.template index fd0907f820..1df56ce621 100644 --- a/platform/android/build.gradle.template +++ b/platform/android/build.gradle.template @@ -3,7 +3,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.1' + classpath 'com.android.tools.build:gradle:2.3.3' $$GRADLE_CLASSPATH$$ } } @@ -31,7 +31,7 @@ android { } compileSdkVersion 23 - buildToolsVersion "25.0.3" + buildToolsVersion "26.0.1" useLibrary 'org.apache.http.legacy' packagingOptions { diff --git a/platform/android/detect.py b/platform/android/detect.py index fae1df3f27..ad5bfb4949 100644 --- a/platform/android/detect.py +++ b/platform/android/detect.py @@ -22,7 +22,7 @@ def get_opts(): return [ ('ANDROID_NDK_ROOT', 'Path to the Android NDK', os.environ.get("ANDROID_NDK_ROOT", 0)), ('ndk_platform', 'Target platform (android-<api>, e.g. "android-18")', "android-18"), - ('android_arch', 'Target architecture (armv7/armv6/x86)', "armv7"), + ('android_arch', 'Target architecture (armv7/armv6/arm64v8/x86)', "armv7"), ('android_neon', 'Enable NEON support (armv7 only)', "yes"), ('android_stl', 'Enable Android STL support (for modules)', "no") ] @@ -89,7 +89,7 @@ def configure(env): ## Architecture - if env['android_arch'] not in ['armv7', 'armv6', 'x86']: + if env['android_arch'] not in ['armv7', 'armv6', 'arm64v8', 'x86']: env['android_arch'] = 'armv7' neon_text = "" @@ -99,18 +99,21 @@ def configure(env): can_vectorize = True if env['android_arch'] == 'x86': + env['ARCH'] = 'arch-x86' env.extra_suffix = ".x86" + env.extra_suffix target_subpath = "x86-4.9" abi_subpath = "i686-linux-android" arch_subpath = "x86" env["x86_libtheora_opt_gcc"] = True elif env['android_arch'] == 'armv6': + env['ARCH'] = 'arch-arm' env.extra_suffix = ".armv6" + env.extra_suffix target_subpath = "arm-linux-androideabi-4.9" abi_subpath = "arm-linux-androideabi" arch_subpath = "armeabi" can_vectorize = False elif env["android_arch"] == "armv7": + env['ARCH'] = 'arch-arm' target_subpath = "arm-linux-androideabi-4.9" abi_subpath = "arm-linux-androideabi" arch_subpath = "armeabi-v7a" @@ -118,6 +121,12 @@ def configure(env): env.extra_suffix = ".armv7.neon" + env.extra_suffix else: env.extra_suffix = ".armv7" + env.extra_suffix + elif env["android_arch"] == "arm64v8": + env['ARCH'] = 'arch-arm64' + target_subpath = "aarch64-linux-android-4.9" + abi_subpath = "aarch64-linux-android" + arch_subpath = "arm64-v8a" + env.extra_suffix = ".armv8" + env.extra_suffix ## Build type @@ -149,6 +158,8 @@ def configure(env): elif (sys.platform.startswith('win')): if (platform.machine().endswith('64')): host_subpath = "windows-x86_64" + if env["android_arch"] == "arm64v8": + mt_link = False else: mt_link = False host_subpath = "windows" @@ -166,11 +177,6 @@ def configure(env): env['RANLIB'] = tools_path + "/ranlib" env['AS'] = tools_path + "/as" - if env['android_arch'] == 'x86': - env['ARCH'] = 'arch-x86' - else: - env['ARCH'] = 'arch-arm' - sysroot = env["ANDROID_NDK_ROOT"] + "/platforms/" + env['ndk_platform'] + "/" + env['ARCH'] common_opts = ['-fno-integrated-as', '-gcc-toolchain', gcc_toolchain_path] @@ -199,6 +205,11 @@ def configure(env): else: env.Append(CPPFLAGS=['-mfpu=vfpv3-d16']) + elif env["android_arch"] == "arm64v8": + target_opts = ['-target', 'aarch64-none-linux-android'] + env.Append(CPPFLAGS=['-D__ARM_ARCH_8A__']) + env.Append(CPPFLAGS=['-mfix-cortex-a53-835769']) + env.Append(CPPFLAGS=target_opts) env.Append(CPPFLAGS=common_opts) @@ -213,7 +224,8 @@ def configure(env): ## Link flags env['LINKFLAGS'] = ['-shared', '--sysroot=' + sysroot, '-Wl,--warn-shared-textrel'] - env.Append(LINKFLAGS=string.split('-Wl,--fix-cortex-a8')) + if env["android_arch"] == "armv7": + env.Append(LINKFLAGS=string.split('-Wl,--fix-cortex-a8')) env.Append(LINKFLAGS=string.split('-Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now')) env.Append(LINKFLAGS=string.split('-Wl,-soname,libgodot_android.so -Wl,--gc-sections')) if mt_link: diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index 97f239c4da..3c52834d92 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -219,6 +219,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { bool use_32_fb; bool immersive; bool export_arm; + bool export_arm64; bool export_x86; String apk_expansion_salt; String apk_expansion_pkey; @@ -319,6 +320,8 @@ bool EditorExportPlatformAndroid::_set(const StringName& p_name, const Variant& _signed=p_value; else if (n=="architecture/arm") export_arm=p_value; + else if (n=="architecture/arm64") + export_arm64=p_value; else if (n=="architecture/x86") export_x86=p_value; else if (n=="screen/use_32_bits_view") @@ -392,6 +395,8 @@ bool EditorExportPlatformAndroid::_get(const StringName& p_name,Variant &r_ret) r_ret=_signed; else if (n=="architecture/arm") r_ret=export_arm; + else if (n=="architecture/arm64") + r_ret=export_arm64; else if (n=="architecture/x86") r_ret=export_x86; else if (n=="screen/use_32_bits_view") @@ -1164,6 +1169,10 @@ Error EditorExportPlatformAndroid::export_project(const String& p_path, bool p_d skip=true; } + if (file.match("lib/arm64*/libgodot_android.so") && !export_arm64) { + skip = true; + } + if (file.begins_with("META-INF") && _signed) { skip=true; } @@ -1801,6 +1810,7 @@ EditorExportPlatformAndroid::EditorExportPlatformAndroid() { immersive=true; export_arm=true; + export_arm64=false; export_x86=false; @@ -2050,6 +2060,7 @@ class EditorExportAndroid : public EditorExportPlatform { String id; String name; String description; + int release; }; struct APKExportData { @@ -2123,6 +2134,7 @@ class EditorExportAndroid : public EditorExportPlatform { if (ea->devices[j].id == ldevices[i]) { d.description = ea->devices[j].description; d.name = ea->devices[j].name; + d.release = ea->devices[j].release; } } @@ -2143,6 +2155,7 @@ class EditorExportAndroid : public EditorExportPlatform { String vendor; String device; d.description + "Device ID: " + d.id + "\n"; + d.release = 0; for (int j = 0; j < props.size(); j++) { String p = props[j]; @@ -2153,7 +2166,9 @@ class EditorExportAndroid : public EditorExportPlatform { } else if (p.begins_with("ro.build.display.id=")) { d.description += "Build: " + p.get_slice("=", 1).strip_edges() + "\n"; } else if (p.begins_with("ro.build.version.release=")) { - d.description += "Release: " + p.get_slice("=", 1).strip_edges() + "\n"; + const String release_str = p.get_slice("=", 1).strip_edges(); + d.description += "Release: " + release_str + "\n"; + d.release = release_str.to_int(); } else if (p.begins_with("ro.product.cpu.abi=")) { d.description += "CPU: " + p.get_slice("=", 1).strip_edges() + "\n"; } else if (p.begins_with("ro.product.manufacturer=")) { @@ -3005,15 +3020,19 @@ public: if (use_adb_over_usb) { args.clear(); + args.push_back("-s"); + args.push_back(devices[p_device].id); args.push_back("reverse"); args.push_back("--remove-all"); err = OS::get_singleton()->execute(adb, args, true, NULL, NULL, &rv); - int port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port"); + int dbg_port = EditorSettings::get_singleton()->get("network/debug/remote_port"); args.clear(); + args.push_back("-s"); + args.push_back(devices[p_device].id); args.push_back("reverse"); - args.push_back("tcp:" + itos(port)); - args.push_back("tcp:" + itos(port)); + args.push_back("tcp:" + itos(dbg_port)); + args.push_back("tcp:" + itos(dbg_port)); err = OS::get_singleton()->execute(adb, args, true, NULL, NULL, &rv); print_line("Reverse result: " + itos(rv)); @@ -3021,6 +3040,8 @@ public: int fs_port = EditorSettings::get_singleton()->get("filesystem/file_server/port"); args.clear(); + args.push_back("-s"); + args.push_back(devices[p_device].id); args.push_back("reverse"); args.push_back("tcp:" + itos(fs_port)); args.push_back("tcp:" + itos(fs_port)); @@ -3036,7 +3057,10 @@ public: args.push_back("shell"); args.push_back("am"); args.push_back("start"); - args.push_back("--user 0"); + if ((bool)EditorSettings::get_singleton()->get("export/android/force_system_user") && devices[p_device].release >= 17) { // Multi-user introduced in Android 17 + args.push_back("--user"); + args.push_back("0"); + } args.push_back("-a"); args.push_back("android.intent.action.MAIN"); args.push_back("-n"); @@ -3044,7 +3068,7 @@ public: err = OS::get_singleton()->execute(adb, args, true, NULL, NULL, &rv); if (err || rv != 0) { - EditorNode::add_io_error("Could not execute ondevice."); + EditorNode::add_io_error("Could not execute on device."); device_lock->unlock(); return ERR_CANT_CREATE; } @@ -3162,6 +3186,7 @@ public: bool export_x86 = p_preset->get("architecture/x86"); bool export_arm = p_preset->get("architecture/arm"); + bool export_arm64 = p_preset->get("architecture/arm64"); bool use_32_fb = p_preset->get("screen/use_32_bits_view"); bool immersive = p_preset->get("screen/immersive_mode"); @@ -3253,6 +3278,10 @@ public: skip = true; } + if (file.match("lib/arm64*/libgodot_android.so") && !export_arm64) { + skip = true; + } + if (file.begins_with("META-INF") && _signed) { skip = true; } @@ -3586,6 +3615,7 @@ void register_android_exporter() { EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/android/debug_keystore", PROPERTY_HINT_GLOBAL_FILE, "keystore")); EDITOR_DEF("export/android/debug_keystore_user", "androiddebugkey"); EDITOR_DEF("export/android/debug_keystore_pass", "android"); + EDITOR_DEF("export/android/force_system_user", false); EDITOR_DEF("export/android/timestamping_authority_url", ""); EDITOR_DEF("export/android/use_remote_debug_over_adb", false); diff --git a/platform/android/java/gradle.properties b/platform/android/java/gradle.properties new file mode 100644 index 0000000000..aac7c9b461 --- /dev/null +++ b/platform/android/java/gradle.properties @@ -0,0 +1,17 @@ +# Project-wide Gradle settings. + +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. + +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html + +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx1536m + +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true diff --git a/platform/android/java/gradle/wrapper/gradle-wrapper.jar b/platform/android/java/gradle/wrapper/gradle-wrapper.jar Binary files differindex 8c0fb64a86..13372aef5e 100644 --- a/platform/android/java/gradle/wrapper/gradle-wrapper.jar +++ b/platform/android/java/gradle/wrapper/gradle-wrapper.jar diff --git a/platform/android/java/gradle/wrapper/gradle-wrapper.properties b/platform/android/java/gradle/wrapper/gradle-wrapper.properties index a11cc1b825..ee6901c9d7 100644 --- a/platform/android/java/gradle/wrapper/gradle-wrapper.properties +++ b/platform/android/java/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,6 @@ -#Fri May 12 08:50:03 KST 2017 +#Sat Jul 29 16:10:03 ICT 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-bin.zip -org.gradle.jvmargs=-Xmx1536M +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip diff --git a/platform/android/java/gradlew b/platform/android/java/gradlew index 91a7e269e1..9d82f78915 100755 --- a/platform/android/java/gradlew +++ b/platform/android/java/gradlew @@ -42,11 +42,6 @@ case "`uname`" in ;; esac -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - # Attempt to set APP_HOME # Resolve links: $0 may be a link PRG="$0" @@ -61,9 +56,9 @@ while [ -h "$PRG" ] ; do fi done SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- +cd "`dirname \"$PRG\"`/" >/dev/null APP_HOME="`pwd -P`" -cd "$SAVED" >&- +cd "$SAVED" >/dev/null CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -114,6 +109,7 @@ fi if $cygwin ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` diff --git a/platform/android/java_class_wrapper.cpp b/platform/android/java_class_wrapper.cpp index 56a27fa0e0..52ff9cd562 100644 --- a/platform/android/java_class_wrapper.cpp +++ b/platform/android/java_class_wrapper.cpp @@ -190,7 +190,7 @@ bool JavaClass::_call_method(JavaObject *p_instance, const StringName &p_method, argv[i].i = *p_args[i]; } break; case ARG_TYPE_LONG: { - argv[i].j = *p_args[i]; + argv[i].j = (int64_t)*p_args[i]; } break; case ARG_TYPE_FLOAT: { argv[i].f = *p_args[i]; @@ -350,7 +350,7 @@ bool JavaClass::_call_method(JavaObject *p_instance, const StringName &p_method, Array arr = *p_args[i]; jlongArray a = env->NewLongArray(arr.size()); for (int j = 0; j < arr.size(); j++) { - jlong val = arr[j]; + jlong val = (int64_t)arr[j]; env->SetLongArrayRegion(a, j, 1, &val); } argv[i].l = a; @@ -460,9 +460,9 @@ bool JavaClass::_call_method(JavaObject *p_instance, const StringName &p_method, case ARG_TYPE_LONG: { if (method->_static) { - ret = env->CallStaticLongMethodA(_class, method->method, argv); + ret = (int64_t)env->CallStaticLongMethodA(_class, method->method, argv); } else { - ret = env->CallLongMethodA(p_instance->instance, method->method, argv); + ret = (int64_t)env->CallLongMethodA(p_instance->instance, method->method, argv); } } break; @@ -680,7 +680,7 @@ bool JavaClass::_convert_object_to_variant(JNIEnv *env, jobject obj, Variant &va } break; case ARG_TYPE_LONG | ARG_NUMBER_CLASS_BIT: { - var = env->CallLongMethod(obj, JavaClassWrapper::singleton->Long_longValue); + var = (int64_t)env->CallLongMethod(obj, JavaClassWrapper::singleton->Long_longValue); return true; } break; @@ -802,7 +802,7 @@ bool JavaClass::_convert_object_to_variant(JNIEnv *env, jobject obj, Variant &va jlong val; env->GetLongArrayRegion((jlongArray)arr, 0, 1, &val); - ret.push_back(val); + ret.push_back((int64_t)val); } var = ret; diff --git a/platform/haiku/key_mapping_haiku.cpp b/platform/haiku/key_mapping_haiku.cpp index 9df7b2f047..3db31fa3e4 100644 --- a/platform/haiku/key_mapping_haiku.cpp +++ b/platform/haiku/key_mapping_haiku.cpp @@ -83,7 +83,7 @@ static _HaikuTranslatePair _fn_to_keycode[] = { static _HaikuTranslatePair _hb_to_keycode[] = { { KEY_BACKSPACE, B_BACKSPACE }, { KEY_TAB, B_TAB }, - { KEY_RETURN, B_RETURN }, + { KEY_ENTER, B_RETURN }, { KEY_CAPSLOCK, B_CAPS_LOCK }, { KEY_ESCAPE, B_ESCAPE }, { KEY_SPACE, B_SPACE }, diff --git a/platform/iphone/gl_view.mm b/platform/iphone/gl_view.mm index 4b137b7ffa..f2778e8165 100644 --- a/platform/iphone/gl_view.mm +++ b/platform/iphone/gl_view.mm @@ -29,8 +29,8 @@ /*************************************************************************/ #import "gl_view.h" -#include "core/project_settings.h" #include "core/os/keyboard.h" +#include "core/project_settings.h" #include "os_iphone.h" #include "servers/audio_server.h" diff --git a/platform/iphone/ios.mm b/platform/iphone/ios.mm index e9c164393b..6c95903241 100644 --- a/platform/iphone/ios.mm +++ b/platform/iphone/ios.mm @@ -36,7 +36,7 @@ void iOS::_bind_methods() { ClassDB::bind_method(D_METHOD("get_rate_url", "app_id"), &iOS::get_rate_url); }; -void iOS::alert(const char* p_alert, const char* p_title) { +void iOS::alert(const char *p_alert, const char *p_title) { UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:[NSString stringWithUTF8String:p_title] message:[NSString stringWithUTF8String:p_alert] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] autorelease]; [alert show]; } diff --git a/platform/javascript/dom_keys.h b/platform/javascript/dom_keys.h index 979731d157..4b8b764c45 100644 --- a/platform/javascript/dom_keys.h +++ b/platform/javascript/dom_keys.h @@ -249,7 +249,7 @@ int dom2godot_scancode(int dom_keycode) { case DOM_VK_RETURN: case DOM_VK_ENTER: // unused according to MDN - return KEY_RETURN; + return KEY_ENTER; case DOM_VK_SHIFT: return KEY_SHIFT; case DOM_VK_CONTROL: return KEY_CONTROL; diff --git a/platform/osx/audio_driver_osx.cpp b/platform/osx/audio_driver_osx.cpp index dabc7989c0..d7a91b1653 100644 --- a/platform/osx/audio_driver_osx.cpp +++ b/platform/osx/audio_driver_osx.cpp @@ -103,6 +103,7 @@ Error AudioDriverOSX::finishDevice() { Error AudioDriverOSX::init() { OSStatus result; + mutex = Mutex::create(); active = false; channels = 2; @@ -159,43 +160,30 @@ OSStatus AudioDriverOSX::output_callback(void *inRefCon, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData) { - AudioBuffer *abuf; AudioDriverOSX *ad = (AudioDriverOSX *)inRefCon; - bool mix = true; - - if (!ad->active) - mix = false; - else if (ad->mutex) { - mix = ad->mutex->try_lock() == OK; - }; - - if (!mix) { + if (!ad->active || !ad->try_lock()) { for (unsigned int i = 0; i < ioData->mNumberBuffers; i++) { - abuf = &ioData->mBuffers[i]; + AudioBuffer *abuf = &ioData->mBuffers[i]; zeromem(abuf->mData, abuf->mDataByteSize); }; return 0; }; - int frames_left; - for (unsigned int i = 0; i < ioData->mNumberBuffers; i++) { - abuf = &ioData->mBuffers[i]; - frames_left = inNumberFrames; + AudioBuffer *abuf = &ioData->mBuffers[i]; + int frames_left = inNumberFrames; int16_t *out = (int16_t *)abuf->mData; while (frames_left) { int frames = MIN(frames_left, ad->buffer_frames); - //ad->lock(); ad->audio_server_process(frames, ad->samples_in); - //ad->unlock(); - for (int i = 0; i < frames * ad->channels; i++) { + for (int j = 0; j < frames * ad->channels; j++) { - out[i] = ad->samples_in[i] >> 16; + out[j] = ad->samples_in[j] >> 16; } frames_left -= frames; @@ -203,8 +191,7 @@ OSStatus AudioDriverOSX::output_callback(void *inRefCon, }; }; - if (ad->mutex) - ad->mutex->unlock(); + ad->unlock(); return 0; }; @@ -232,11 +219,18 @@ void AudioDriverOSX::lock() { if (mutex) mutex->lock(); }; + void AudioDriverOSX::unlock() { if (mutex) mutex->unlock(); }; +bool AudioDriverOSX::try_lock() { + if (mutex) + return mutex->try_lock() == OK; + return true; +} + void AudioDriverOSX::finish() { OSStatus result; @@ -247,16 +241,22 @@ void AudioDriverOSX::finish() { ERR_PRINT("AudioObjectRemovePropertyListener failed"); } - memdelete_arr(samples_in); + if (mutex) { + memdelete(mutex); + mutex = NULL; + } + + if (samples_in) { + memdelete_arr(samples_in); + samples_in = NULL; + } }; AudioDriverOSX::AudioDriverOSX() { - - mutex = Mutex::create(); //NULL; + mutex = NULL; + samples_in = NULL; }; -AudioDriverOSX::~AudioDriverOSX(){ - -}; +AudioDriverOSX::~AudioDriverOSX(){}; #endif diff --git a/platform/osx/audio_driver_osx.h b/platform/osx/audio_driver_osx.h index d6d00b7970..287c9d6cbf 100644 --- a/platform/osx/audio_driver_osx.h +++ b/platform/osx/audio_driver_osx.h @@ -70,6 +70,7 @@ public: virtual void unlock(); virtual void finish(); + bool try_lock(); Error reopen(); AudioDriverOSX(); diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index 44f4334786..cb9dd1dd8e 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -101,11 +101,7 @@ public: bool maximized; bool zoomed; - Vector<Rect2> screens; - Vector<int> screen_dpi; - Size2 window_size; - int current_screen; Rect2 restore_rect; power_osx *power_manager; diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 924417fb36..b45647b8bb 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -152,6 +152,46 @@ static bool mouse_down_control = false; return NO; } +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 +- (void)windowDidEnterFullScreen:(NSNotification *)notification { + OS_OSX::singleton->zoomed = true; +} + +- (void)windowDidExitFullScreen:(NSNotification *)notification { + OS_OSX::singleton->zoomed = false; +} +#endif // MAC_OS_X_VERSION_MAX_ALLOWED + +- (void)windowDidChangeBackingProperties:(NSNotification *)notification { + if (!OS_OSX::singleton) + return; + + NSWindow *window = (NSWindow *)[notification object]; + CGFloat newBackingScaleFactor = [window backingScaleFactor]; + CGFloat oldBackingScaleFactor = [[[notification userInfo] objectForKey:@"NSBackingPropertyOldScaleFactorKey"] doubleValue]; + + if (newBackingScaleFactor != oldBackingScaleFactor) { + //Set new display scale and window size + OS_OSX::singleton->display_scale = newBackingScaleFactor; + + const NSRect contentRect = [OS_OSX::singleton->window_view frame]; + const NSRect fbRect = contentRect; //convertRectToBacking(contentRect); + + OS_OSX::singleton->window_size.width = fbRect.size.width * OS_OSX::singleton->display_scale; + OS_OSX::singleton->window_size.height = fbRect.size.height * OS_OSX::singleton->display_scale; + + //Update context + if (OS_OSX::singleton->main_loop) { + [OS_OSX::singleton->context update]; + + //Force window resize ??? + NSRect frame = [OS_OSX::singleton->window_object frame]; + [OS_OSX::singleton->window_object setFrame:NSMakeRect(frame.origin.x, frame.origin.y, 1, 1) display:YES]; + [OS_OSX::singleton->window_object setFrame:frame display:YES]; + } + } +} + - (void)windowDidResize:(NSNotification *)notification { [OS_OSX::singleton->context update]; @@ -161,6 +201,12 @@ static bool mouse_down_control = false; OS_OSX::singleton->window_size.width = fbRect.size.width * OS_OSX::singleton->display_scale; OS_OSX::singleton->window_size.height = fbRect.size.height * OS_OSX::singleton->display_scale; + if (OS_OSX::singleton->main_loop) { + Main::force_redraw(); + //Event retrieval blocks until resize is over. Call Main::iteration() directly. + Main::iteration(); + } + /* _GodotInputFramebufferSize(window, fbRect.size.width, fbRect.size.height); _GodotInputWindowSize(window, contentRect.size.width, contentRect.size.height); @@ -472,7 +518,7 @@ static int translateKey(unsigned int key) { /* 21 */ KEY_BRACELEFT, /* 22 */ KEY_I, /* 23 */ KEY_P, - /* 24 */ KEY_RETURN, + /* 24 */ KEY_ENTER, /* 25 */ KEY_L, /* 26 */ KEY_J, /* 27 */ KEY_APOSTROPHE, @@ -512,7 +558,7 @@ static int translateKey(unsigned int key) { /* 49 */ KEY_UNKNOWN, /* VolumeDown */ /* 4a */ KEY_UNKNOWN, /* Mute */ /* 4b */ KEY_KP_DIVIDE, - /* 4c */ KEY_ENTER, + /* 4c */ KEY_KP_ENTER, /* 4d */ KEY_UNKNOWN, /* 4e */ KEY_KP_SUBTRACT, /* 4f */ KEY_UNKNOWN, @@ -930,33 +976,6 @@ void OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_au _ensure_data_dir(); - NSArray *screenArray = [NSScreen screens]; - printf("nscreen count %i\n", (int)[screenArray count]); - for (int i = 0; i < [screenArray count]; i++) { - - float displayScale = 1.0; - - if (display_scale > 1.0 && [[screenArray objectAtIndex:i] respondsToSelector:@selector(backingScaleFactor)]) { - displayScale = [[screenArray objectAtIndex:i] backingScaleFactor]; - } - - // Note: Use frame to get the whole screen size - NSRect nsrect = [[screenArray objectAtIndex:i] frame]; - Rect2 rect = Rect2(nsrect.origin.x, nsrect.origin.y, nsrect.size.width, nsrect.size.height); - rect.position *= displayScale; - rect.size *= displayScale; - screens.push_back(rect); - - NSDictionary *description = [[screenArray objectAtIndex:i] deviceDescription]; - NSSize displayPixelSize = [[description objectForKey:NSDeviceSize] sizeValue]; - CGSize displayPhysicalSize = CGDisplayScreenSize( - [[description objectForKey:@"NSScreenNumber"] unsignedIntValue]); - - //printf("width: %i pwidth %i rect width %i\n",int(displayPixelSize.width*displayScale),int(displayPhysicalSize.width*displayScale),int(nsrect.size.width)); - int dpi = (displayPixelSize.width * 25.4f / displayPhysicalSize.width) * displayScale; - - screen_dpi.push_back(dpi); - }; restore_rect = Rect2(get_window_position(), get_window_size()); } @@ -977,8 +996,6 @@ void OS_OSX::finalize() { physics_2d_server->finish(); memdelete(physics_2d_server); - - screens.clear(); } void OS_OSX::set_main_loop(MainLoop *p_main_loop) { @@ -1064,18 +1081,13 @@ void OS_OSX::warp_mouse_pos(const Point2 &p_to) { mouse_y = p_to.y; } else { //set OS position - /* this code has not been tested, please be a kind soul and fix it if it fails! */ - //local point in window coords - NSPoint localPoint = { p_to.x, p_to.y }; - - NSPoint pointInWindow = [window_view convertPoint:localPoint toView:nil]; - NSRect pointInWindowRect; - pointInWindowRect.origin = pointInWindow; + const NSRect contentRect = [window_view frame]; + NSRect pointInWindowRect = NSMakeRect(p_to.x / display_scale, contentRect.size.height - (p_to.y / display_scale) - 1, 0, 0); NSPoint pointOnScreen = [[window_view window] convertRectToScreen:pointInWindowRect].origin; //point in scren coords - CGPoint lMouseWarpPos = { pointOnScreen.x, pointOnScreen.y }; + CGPoint lMouseWarpPos = { pointOnScreen.x, CGDisplayBounds(CGMainDisplayID()).size.height - pointOnScreen.y }; //do the warping CGEventSourceRef lEventRef = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState); @@ -1228,37 +1240,80 @@ void OS_OSX::get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen) con } int OS_OSX::get_screen_count() const { - - return screens.size(); + NSArray *screenArray = [NSScreen screens]; + return [screenArray count]; }; int OS_OSX::get_current_screen() const { - - return current_screen; + Vector2 wpos = get_window_position(); + + int count = get_screen_count(); + for (int i = 0; i < count; i++) { + Point2 pos = get_screen_position(i); + Size2 size = get_screen_size(i); + if ((wpos.x >= pos.x && wpos.x < pos.x + size.width) && (wpos.y >= pos.y && wpos.y < pos.y + size.height)) + return i; + } + return 0; }; void OS_OSX::set_current_screen(int p_screen) { - - current_screen = p_screen; + Vector2 wpos = get_window_position() - get_screen_position(get_current_screen()); + set_window_position(wpos + get_screen_position(p_screen)); }; Point2 OS_OSX::get_screen_position(int p_screen) const { + NSArray *screenArray = [NSScreen screens]; + if (p_screen < [screenArray count]) { + float displayScale = 1.0; - ERR_FAIL_INDEX_V(p_screen, screens.size(), Point2()); - return screens[p_screen].position; -}; + if (display_scale > 1.0 && [[screenArray objectAtIndex:p_screen] respondsToSelector:@selector(backingScaleFactor)]) { + displayScale = [[screenArray objectAtIndex:p_screen] backingScaleFactor]; + } + + NSRect nsrect = [[screenArray objectAtIndex:p_screen] frame]; + return Point2(nsrect.origin.x, nsrect.origin.y) * displayScale; + } + + return Point2(); +} int OS_OSX::get_screen_dpi(int p_screen) const { + NSArray *screenArray = [NSScreen screens]; + if (p_screen < [screenArray count]) { + float displayScale = 1.0; - ERR_FAIL_INDEX_V(p_screen, screens.size(), 72); - return screen_dpi[p_screen]; + if (display_scale > 1.0 && [[screenArray objectAtIndex:p_screen] respondsToSelector:@selector(backingScaleFactor)]) { + displayScale = [[screenArray objectAtIndex:p_screen] backingScaleFactor]; + } + + NSDictionary *description = [[screenArray objectAtIndex:p_screen] deviceDescription]; + NSSize displayPixelSize = [[description objectForKey:NSDeviceSize] sizeValue]; + CGSize displayPhysicalSize = CGDisplayScreenSize( + [[description objectForKey:@"NSScreenNumber"] unsignedIntValue]); + + return (displayPixelSize.width * 25.4f / displayPhysicalSize.width) * displayScale; + } + + return 72; } Size2 OS_OSX::get_screen_size(int p_screen) const { + NSArray *screenArray = [NSScreen screens]; + if (p_screen < [screenArray count]) { + float displayScale = 1.0; - ERR_FAIL_INDEX_V(p_screen, screens.size(), Point2()); - return screens[p_screen].size; -}; + if (display_scale > 1.0 && [[screenArray objectAtIndex:p_screen] respondsToSelector:@selector(backingScaleFactor)]) { + displayScale = [[screenArray objectAtIndex:p_screen] backingScaleFactor]; + } + + // Note: Use frame to get the whole screen size + NSRect nsrect = [[screenArray objectAtIndex:p_screen] frame]; + return Size2(nsrect.size.width, nsrect.size.height) * displayScale; + } + + return Size2(); +} void OS_OSX::_update_window() { bool borderless_full = false; @@ -1383,7 +1438,7 @@ void OS_OSX::set_window_maximized(bool p_enabled) { if (p_enabled) { restore_rect = Rect2(get_window_position(), get_window_size()); - [window_object setFrame:[[[NSScreen screens] objectAtIndex:current_screen] visibleFrame] display:YES]; + [window_object setFrame:[[[NSScreen screens] objectAtIndex:get_current_screen()] visibleFrame] display:YES]; } else { set_window_size(restore_rect.size); set_window_position(restore_rect.position); @@ -1661,12 +1716,52 @@ OS_OSX::OS_OSX() { // In case we are unbundled, make us a proper UI application [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; -#if 0 // Menu bar setup must go between sharedApplication above and // finishLaunching below, in order to properly emulate the behavior // of NSApplicationMain - createMenuBar(); -#endif + NSMenuItem *menu_item; + NSString *title; + + NSString *nsappname = [[[NSBundle mainBundle] performSelector:@selector(localizedInfoDictionary)] objectForKey:@"CFBundleName"]; + if (nsappname == nil) + nsappname = [[NSProcessInfo processInfo] processName]; + + // Setup Apple menu + NSMenu *apple_menu = [[NSMenu alloc] initWithTitle:@""]; + title = [NSString stringWithFormat:NSLocalizedString(@"About %@", nil), nsappname]; + [apple_menu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; + + [apple_menu addItem:[NSMenuItem separatorItem]]; + + NSMenu *services = [[NSMenu alloc] initWithTitle:@""]; + menu_item = [apple_menu addItemWithTitle:NSLocalizedString(@"Services", nil) action:nil keyEquivalent:@""]; + [apple_menu setSubmenu:services forItem:menu_item]; + [NSApp setServicesMenu:services]; + [services release]; + + [apple_menu addItem:[NSMenuItem separatorItem]]; + + title = [NSString stringWithFormat:NSLocalizedString(@"Hide %@", nil), nsappname]; + [apple_menu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"]; + + menu_item = [apple_menu addItemWithTitle:NSLocalizedString(@"Hide Others", nil) action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; + [menu_item setKeyEquivalentModifierMask:(NSAlternateKeyMask | NSCommandKeyMask)]; + + [apple_menu addItemWithTitle:NSLocalizedString(@"Show all", nil) action:@selector(unhideAllApplications:) keyEquivalent:@""]; + + [apple_menu addItem:[NSMenuItem separatorItem]]; + + title = [NSString stringWithFormat:NSLocalizedString(@"Quit %@", nil), nsappname]; + [apple_menu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"]; + + // Setup menu bar + NSMenu *main_menu = [[NSMenu alloc] initWithTitle:@""]; + menu_item = [main_menu addItemWithTitle:@"" action:nil keyEquivalent:@""]; + [main_menu setSubmenu:apple_menu forItem:menu_item]; + [NSApp setMainMenu:main_menu]; + + [main_menu release]; + [apple_menu release]; [NSApp finishLaunching]; @@ -1676,8 +1771,6 @@ OS_OSX::OS_OSX() { cursor_shape = CURSOR_ARROW; - current_screen = 0; - maximized = false; minimized = false; window_size = Vector2(1024, 600); diff --git a/platform/uwp/joypad_uwp.cpp b/platform/uwp/joypad_uwp.cpp index 34e36f7b66..f3d4eb99c8 100644 --- a/platform/uwp/joypad_uwp.cpp +++ b/platform/uwp/joypad_uwp.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "joypad_uwp.h" +#include "core/os/os.h" using namespace Windows::Gaming::Input; using namespace Windows::Foundation; @@ -45,27 +46,44 @@ void JoypadUWP::process_controllers() { for (int i = 0; i < MAX_CONTROLLERS; i++) { - if (!controllers[i].connected) break; + ControllerDevice &joy = controllers[i]; - switch (controllers[i].type) { + if (!joy.connected) break; + + switch (joy.type) { case ControllerType::GAMEPAD_CONTROLLER: { - GamepadReading reading = ((Gamepad ^)controllers[i].controller_reference)->GetCurrentReading(); + GamepadReading reading = ((Gamepad ^) joy.controller_reference)->GetCurrentReading(); int button_mask = (int)GamepadButtons::Menu; for (int j = 0; j < 14; j++) { - input->joy_button(controllers[i].id, j, (int)reading.Buttons & button_mask); + input->joy_button(joy.id, j, (int)reading.Buttons & button_mask); button_mask *= 2; } - input->joy_axis(controllers[i].id, JOY_AXIS_0, axis_correct(reading.LeftThumbstickX)); - input->joy_axis(controllers[i].id, JOY_AXIS_1, axis_correct(reading.LeftThumbstickY, true)); - input->joy_axis(controllers[i].id, JOY_AXIS_2, axis_correct(reading.RightThumbstickX)); - input->joy_axis(controllers[i].id, JOY_AXIS_3, axis_correct(reading.RightThumbstickY, true)); - input->joy_axis(controllers[i].id, JOY_AXIS_4, axis_correct(reading.LeftTrigger, false, true)); - input->joy_axis(controllers[i].id, JOY_AXIS_5, axis_correct(reading.RightTrigger, false, true)); + input->joy_axis(joy.id, JOY_AXIS_0, axis_correct(reading.LeftThumbstickX)); + input->joy_axis(joy.id, JOY_AXIS_1, axis_correct(reading.LeftThumbstickY, true)); + input->joy_axis(joy.id, JOY_AXIS_2, axis_correct(reading.RightThumbstickX)); + input->joy_axis(joy.id, JOY_AXIS_3, axis_correct(reading.RightThumbstickY, true)); + input->joy_axis(joy.id, JOY_AXIS_4, axis_correct(reading.LeftTrigger, false, true)); + input->joy_axis(joy.id, JOY_AXIS_5, axis_correct(reading.RightTrigger, false, true)); + + uint64_t timestamp = input->get_joy_vibration_timestamp(joy.id); + if (timestamp > joy.ff_timestamp) { + Vector2 strength = input->get_joy_vibration_strength(joy.id); + float duration = input->get_joy_vibration_duration(joy.id); + if (strength.x == 0 && strength.y == 0) { + joypad_vibration_stop(i, timestamp); + } else { + joypad_vibration_start(i, strength.x, strength.y, duration, timestamp); + } + } else if (joy.vibrating && joy.ff_end_timestamp != 0) { + uint64_t current_time = OS::get_singleton()->get_ticks_usec(); + if (current_time >= joy.ff_end_timestamp) + joypad_vibration_stop(i, current_time); + } break; } @@ -122,15 +140,7 @@ void JoypadUWP::OnGamepadRemoved(Platform::Object ^ sender, Windows::Gaming::Inp ERR_FAIL_COND(idx == -1); - for (int i = idx + 1; i < MAX_CONTROLLERS - 1; i++) { - - if (!controllers[i].connected) { - break; - } - - controllers[i - 1] = controllers[i]; - } - controllers[MAX_CONTROLLERS - 1] = ControllerDevice(); + controllers[idx] = ControllerDevice(); input->joy_connection_changed(idx, false, "Xbox Controller"); } @@ -144,3 +154,30 @@ InputDefault::JoyAxis JoypadUWP::axis_correct(double p_val, bool p_negate, bool return jx; } + +void JoypadUWP::joypad_vibration_start(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp) { + ControllerDevice &joy = controllers[p_device]; + if (joy.connected) { + GamepadVibration vibration; + vibration.LeftMotor = p_strong_magnitude; + vibration.RightMotor = p_weak_magnitude; + ((Gamepad ^) joy.controller_reference)->Vibration = vibration; + + joy.ff_timestamp = p_timestamp; + joy.ff_end_timestamp = p_duration == 0 ? 0 : p_timestamp + (uint64_t)(p_duration * 1000000.0); + joy.vibrating = true; + } +} + +void JoypadUWP::joypad_vibration_stop(int p_device, uint64_t p_timestamp) { + ControllerDevice &joy = controllers[p_device]; + if (joy.connected) { + GamepadVibration vibration; + vibration.LeftMotor = 0.0; + vibration.RightMotor = 0.0; + ((Gamepad ^) joy.controller_reference)->Vibration = vibration; + + joy.ff_timestamp = p_timestamp; + joy.vibrating = false; + } +} diff --git a/platform/uwp/joypad_uwp.h b/platform/uwp/joypad_uwp.h index 7337ffb3ce..c55e1e7ab7 100644 --- a/platform/uwp/joypad_uwp.h +++ b/platform/uwp/joypad_uwp.h @@ -62,11 +62,17 @@ private: int id; bool connected; ControllerType type; + float ff_timestamp; + float ff_end_timestamp; + bool vibrating; ControllerDevice() { id = -1; connected = false; type = ControllerType::GAMEPAD_CONTROLLER; + ff_timestamp = 0.0f; + ff_end_timestamp = 0.0f; + vibrating = false; } }; @@ -78,6 +84,8 @@ private: void OnGamepadRemoved(Platform::Object ^ sender, Windows::Gaming::Input::Gamepad ^ value); InputDefault::JoyAxis axis_correct(double p_val, bool p_negate = false, bool p_trigger = false) const; + void joypad_vibration_start(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp); + void joypad_vibration_stop(int p_device, uint64_t p_timestamp); }; #endif diff --git a/platform/windows/key_mapping_win.cpp b/platform/windows/key_mapping_win.cpp index bffacb3a82..83e2af72b2 100644 --- a/platform/windows/key_mapping_win.cpp +++ b/platform/windows/key_mapping_win.cpp @@ -44,7 +44,7 @@ static _WinTranslatePair _vk_to_keycode[] = { //VK_CLEAR (0x0C) - { KEY_RETURN, VK_RETURN }, //(0x0D) + { KEY_ENTER, VK_RETURN }, //(0x0D) { KEY_SHIFT, VK_SHIFT }, //(0x10) diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index c091c7d022..9cab19fffb 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -805,7 +805,12 @@ void OS_Windows::process_key_events() { k->set_pressed(ke.uMsg == WM_KEYDOWN); - k->set_scancode(KeyMappingWindows::get_keysym(ke.wParam)); + if ((ke.lParam & (1 << 24)) && (ke.wParam == VK_RETURN)) { + // Special case for Numpad Enter key + k->set_scancode(KEY_KP_ENTER); + } else { + k->set_scancode(KeyMappingWindows::get_keysym(ke.wParam)); + } if (i + 1 < key_event_pos && key_event_buffer[i + 1].uMsg == WM_CHAR) { k->set_unicode(key_event_buffer[i + 1].wParam); @@ -1187,10 +1192,6 @@ void OS_Windows::finalize() { main_loop = NULL; - for (int i = 0; i < get_audio_driver_count(); i++) { - AudioDriverManager::get_driver(i)->finish(); - } - memdelete(joypad); memdelete(input); diff --git a/platform/x11/key_mapping_x11.cpp b/platform/x11/key_mapping_x11.cpp index 1d7eb1692c..32a9806b22 100644 --- a/platform/x11/key_mapping_x11.cpp +++ b/platform/x11/key_mapping_x11.cpp @@ -44,7 +44,7 @@ static _XTranslatePair _xkeysym_to_keycode[] = { { XK_Tab, KEY_TAB }, { XK_ISO_Left_Tab, KEY_BACKTAB }, { XK_BackSpace, KEY_BACKSPACE }, - { XK_Return, KEY_RETURN }, + { XK_Return, KEY_ENTER }, { XK_Insert, KEY_INSERT }, { XK_Delete, KEY_DELETE }, { XK_Clear, KEY_DELETE }, @@ -78,7 +78,7 @@ static _XTranslatePair _xkeysym_to_keycode[] = { { XK_Help, KEY_HELP }, { XK_KP_Space, KEY_SPACE }, { XK_KP_Tab, KEY_TAB }, - { XK_KP_Enter, KEY_ENTER }, + { XK_KP_Enter, KEY_KP_ENTER }, { XK_Home, KEY_HOME }, { XK_Left, KEY_LEFT }, { XK_Up, KEY_UP }, diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 1dde328eda..ade3a0a0c5 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -529,10 +529,6 @@ void OS_X11::finalize() { memdelete(main_loop); main_loop = NULL; - for (int i = 0; i < get_audio_driver_count(); i++) { - AudioDriverManager::get_driver(i)->finish(); - } - /* if (debugger_connection_console) { memdelete(debugger_connection_console); |