summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
Diffstat (limited to 'platform')
-rw-r--r--platform/android/AndroidManifest.xml.template10
-rw-r--r--platform/android/SCsub20
-rw-r--r--platform/android/build.gradle.template5
-rw-r--r--platform/android/detect.py58
-rw-r--r--platform/android/export/export.cpp3
-rw-r--r--platform/android/file_access_android.cpp7
-rw-r--r--platform/android/file_access_android.h3
-rw-r--r--platform/android/file_access_jandroid.cpp5
-rw-r--r--platform/android/file_access_jandroid.h3
-rw-r--r--platform/android/java/gradlew.bat180
-rw-r--r--platform/android/java/src/org/godotengine/godot/Godot.java25
-rw-r--r--platform/android/java/src/org/godotengine/godot/GodotLib.java2
-rw-r--r--platform/android/java/src/org/godotengine/godot/GodotView.java8
-rw-r--r--platform/android/java/src/org/godotengine/godot/input/GodotTextInputWrapper.java73
-rw-r--r--platform/android/java/src/org/godotengine/godot/utils/CustomSSLSocketFactory.java20
-rw-r--r--platform/android/java_glue.cpp79
-rw-r--r--platform/android/java_glue.h1
-rw-r--r--platform/android/os_android.cpp51
-rw-r--r--platform/android/os_android.h13
-rw-r--r--platform/android/platform_config.h1
-rw-r--r--platform/haiku/context_gl_haiku.cpp2
-rw-r--r--platform/haiku/context_gl_haiku.h2
-rw-r--r--platform/haiku/detect.py16
-rw-r--r--platform/haiku/haiku_direct_window.cpp8
-rw-r--r--platform/haiku/os_haiku.cpp17
-rw-r--r--platform/haiku/os_haiku.h6
-rw-r--r--platform/iphone/SCsub1
-rw-r--r--platform/iphone/app_delegate.mm26
-rw-r--r--platform/iphone/audio_driver_iphone.cpp187
-rw-r--r--platform/iphone/detect.py36
-rw-r--r--platform/iphone/export/export.cpp361
-rw-r--r--platform/iphone/game_center.h9
-rw-r--r--platform/iphone/game_center.mm73
-rw-r--r--platform/iphone/gl_view.h2
-rw-r--r--platform/iphone/gl_view.mm40
-rw-r--r--platform/iphone/godot_iphone.cpp7
-rw-r--r--platform/iphone/os_iphone.cpp48
-rw-r--r--platform/iphone/os_iphone.h17
-rw-r--r--platform/javascript/SCsub5
-rw-r--r--platform/javascript/audio_driver_javascript.cpp79
-rw-r--r--platform/javascript/audio_driver_javascript.h15
-rw-r--r--platform/javascript/audio_server_javascript.cpp853
-rw-r--r--platform/javascript/audio_server_javascript.h229
-rw-r--r--platform/javascript/detect.py23
-rw-r--r--platform/javascript/engine.js6
-rw-r--r--platform/javascript/javascript_eval.cpp82
-rw-r--r--platform/javascript/javascript_main.cpp16
-rw-r--r--platform/javascript/os_javascript.cpp46
-rw-r--r--platform/javascript/os_javascript.h16
-rw-r--r--platform/osx/SCsub14
-rw-r--r--platform/osx/audio_driver_osx.cpp301
-rw-r--r--platform/osx/audio_driver_osx.h85
-rw-r--r--platform/osx/crash_handler_osx.mm4
-rw-r--r--platform/osx/detect.py18
-rw-r--r--platform/osx/export/export.cpp466
-rw-r--r--platform/osx/os_osx.h30
-rw-r--r--platform/osx/os_osx.mm259
-rw-r--r--platform/server/detect.py61
-rw-r--r--platform/server/os_server.cpp12
-rw-r--r--platform/server/os_server.h5
-rw-r--r--platform/uwp/SCsub1
-rw-r--r--platform/uwp/detect.py4
-rw-r--r--platform/uwp/export/export.cpp6
-rw-r--r--platform/uwp/gl_context_egl.cpp36
-rw-r--r--platform/uwp/os_uwp.cpp77
-rw-r--r--platform/uwp/os_uwp.h10
-rw-r--r--platform/windows/SCsub14
-rw-r--r--platform/windows/context_gl_win.cpp2
-rw-r--r--platform/windows/context_gl_win.h2
-rw-r--r--platform/windows/crash_handler_win.cpp5
-rw-r--r--platform/windows/detect.py22
-rw-r--r--platform/windows/godot_win.cpp38
-rw-r--r--platform/windows/key_mapping_win.cpp2
-rw-r--r--platform/windows/os_windows.cpp189
-rw-r--r--platform/windows/os_windows.h17
-rw-r--r--platform/windows/windows_terminal_logger.cpp157
-rw-r--r--platform/windows/windows_terminal_logger.h (renamed from platform/iphone/audio_driver_iphone.h)43
-rw-r--r--platform/x11/SCsub9
-rw-r--r--platform/x11/context_gl_x11.cpp2
-rw-r--r--platform/x11/context_gl_x11.h2
-rw-r--r--platform/x11/crash_handler_x11.cpp4
-rw-r--r--platform/x11/detect.py120
-rw-r--r--platform/x11/os_x11.cpp145
-rw-r--r--platform/x11/os_x11.h13
84 files changed, 1951 insertions, 3019 deletions
diff --git a/platform/android/AndroidManifest.xml.template b/platform/android/AndroidManifest.xml.template
index be5afb406a..9d8eb951c4 100644
--- a/platform/android/AndroidManifest.xml.template
+++ b/platform/android/AndroidManifest.xml.template
@@ -17,7 +17,7 @@
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden|screenSize|smallestScreenSize">
-
+
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
@@ -26,7 +26,7 @@
<service android:name="org.godotengine.godot.GodotDownloaderService" />
-
+
$$ADD_APPLICATION_CHUNKS$$
@@ -200,6 +200,6 @@ $$ADD_PERMISSION_CHUNKS$$
<uses-permission android:name="godot.custom.18"/>
<uses-permission android:name="godot.custom.19"/>
-<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="23"/>
-
-</manifest>
+<uses-sdk android:minSdkVersion="18" android:targetSdkVersion="23"/>
+
+</manifest>
diff --git a/platform/android/SCsub b/platform/android/SCsub
index 87e7ee4747..7fa0262359 100644
--- a/platform/android/SCsub
+++ b/platform/android/SCsub
@@ -46,8 +46,18 @@ gradle_baseout = open_utf8(abspath + "/java/build.gradle", "w")
gradle_text = gradle_basein.read()
-
+gradle_maven_flat_text = ""
+if len(env.android_flat_dirs) > 0:
+ gradle_maven_flat_text += "flatDir {\n"
+ gradle_maven_flat_text += "\tdirs "
+ for x in env.android_flat_dirs:
+ gradle_maven_flat_text += "'" + x + "',"
+
+ gradle_maven_flat_text = gradle_maven_flat_text[:-1]
+ gradle_maven_flat_text += "\n\t}\n"
+
gradle_maven_repos_text = ""
+gradle_maven_repos_text += gradle_maven_flat_text
if len(env.android_maven_repos) > 0:
gradle_maven_repos_text += ""
@@ -73,7 +83,7 @@ for x in env.android_gradle_plugins:
gradle_classpath = ""
for x in env.android_gradle_classpath:
gradle_classpath += "\t\tclasspath \"" + x + "\"\n"
-
+
gradle_res_dirs_text = ""
for x in env.android_res_dirs:
@@ -93,13 +103,13 @@ gradle_asset_dirs_text = ""
gradle_default_config_text = ""
-minSdk = 14
+minSdk = 18
targetSdk = 23
for x in env.android_default_config:
- if x.startswith("minSdkVersion") and int(x.split(" ")[-1]) < minSdk:
+ if x.startswith("minSdkVersion") and int(x.split(" ")[-1]) < minSdk:
x = "minSdkVersion " + str(minSdk)
- if x.startswith("targetSdkVersion") and int(x.split(" ")[-1]) > targetSdk:
+ if x.startswith("targetSdkVersion") and int(x.split(" ")[-1]) > targetSdk:
x = "targetSdkVersion " + str(targetSdk)
gradle_default_config_text += x + "\n\t\t"
diff --git a/platform/android/build.gradle.template b/platform/android/build.gradle.template
index 1df56ce621..7cb6cf860a 100644
--- a/platform/android/build.gradle.template
+++ b/platform/android/build.gradle.template
@@ -1,6 +1,7 @@
buildscript {
repositories {
jcenter()
+ $$GRADLE_REPOSITORY_URLS$$
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
@@ -54,11 +55,11 @@ android {
]
res.srcDirs = [
'res'
- $$GRADLE_RES_DIRS$$
+ $$GRADLE_RES_DIRS$$
]
aidl.srcDirs = [
'aidl'
- $$GRADLE_AIDL_DIRS$$
+ $$GRADLE_AIDL_DIRS$$
]
assets.srcDirs = [
'assets'
diff --git a/platform/android/detect.py b/platform/android/detect.py
index c1ac54c587..4d5e586faf 100644
--- a/platform/android/detect.py
+++ b/platform/android/detect.py
@@ -18,20 +18,22 @@ def can_build():
def get_opts():
+ from SCons.Variables import BoolVariable, EnumVariable
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/arm64v8/x86)', "armv7"),
- ('android_neon', 'Enable NEON support (armv7 only)', "yes"),
- ('android_stl', 'Enable Android STL support (for modules)', "no")
+ EnumVariable('android_arch', 'Target architecture', "armv7", ('armv7', 'armv6', 'arm64v8', 'x86')),
+ BoolVariable('android_neon', 'Enable NEON support (armv7 only)', True),
+ BoolVariable('android_stl', 'Enable Android STL support (for modules)', False),
+ BoolVariable('ndk_unified_headers', 'Enable NDK unified headers', True)
]
def get_flags():
return [
- ('tools', 'no'),
+ ('tools', False),
]
@@ -93,7 +95,7 @@ def configure(env):
env['android_arch'] = 'armv7'
neon_text = ""
- if env["android_arch"] == "armv7" and env['android_neon'] == 'yes':
+ if env["android_arch"] == "armv7" and env['android_neon']:
neon_text = " (with NEON)"
print("Building for Android (" + env['android_arch'] + ")" + neon_text)
@@ -117,7 +119,7 @@ def configure(env):
target_subpath = "arm-linux-androideabi-4.9"
abi_subpath = "arm-linux-androideabi"
arch_subpath = "armeabi-v7a"
- if env['android_neon'] == 'yes':
+ if env['android_neon']:
env.extra_suffix = ".armv7.neon" + env.extra_suffix
else:
env.extra_suffix = ".armv7" + env.extra_suffix
@@ -177,12 +179,28 @@ def configure(env):
env['RANLIB'] = tools_path + "/ranlib"
env['AS'] = tools_path + "/as"
- sysroot = env["ANDROID_NDK_ROOT"] + "/platforms/" + env['ndk_platform'] + "/" + env['ARCH']
+ ndk_unified_headers = env['ndk_unified_headers']
+ ndk_version = get_ndk_version(env["ANDROID_NDK_ROOT"])
+
common_opts = ['-fno-integrated-as', '-gcc-toolchain', gcc_toolchain_path]
+ if not ndk_unified_headers and ndk_version != None and ndk_version[0] >= 16:
+ ndk_unified_headers = True
+ print("Turning NDK unified headers on (starting from r16)")
+
+ lib_sysroot = env["ANDROID_NDK_ROOT"] + "/platforms/" + env['ndk_platform'] + "/" + env['ARCH']
+
## Compile flags
- env.Append(CPPFLAGS=["-isystem", sysroot + "/usr/include"])
+ if ndk_unified_headers:
+ sysroot = env["ANDROID_NDK_ROOT"] + "/sysroot"
+ env.Append(CPPFLAGS=["-isystem", sysroot + "/usr/include"])
+ env.Append(CPPFLAGS=["-isystem", sysroot + "/usr/include/" + abi_subpath])
+ # For unified headers this define has to be set manually
+ env.Append(CPPFLAGS=["-D__ANDROID_API__=" + str(int(env['ndk_platform'].split("-")[1]))])
+ else:
+ env.Append(CPPFLAGS=["-isystem", lib_sysroot + "/usr/include"])
+
env.Append(CPPFLAGS='-fpic -ffunction-sections -funwind-tables -fstack-protector-strong -fvisibility=hidden -fno-strict-aliasing'.split())
env.Append(CPPFLAGS='-DNO_STATVFS -DGLES2_ENABLED'.split())
@@ -199,7 +217,7 @@ def configure(env):
elif env["android_arch"] == "armv7":
target_opts = ['-target', 'armv7-none-linux-androideabi']
env.Append(CPPFLAGS='-D__ARM_ARCH_7__ -D__ARM_ARCH_7A__ -march=armv7-a -mfloat-abi=softfp'.split())
- if env['android_neon'] == 'yes':
+ if env['android_neon']:
env['neon_enabled'] = True
env.Append(CPPFLAGS=['-mfpu=neon', '-D__ARM_NEON__'])
else:
@@ -213,7 +231,7 @@ def configure(env):
env.Append(CPPFLAGS=target_opts)
env.Append(CPPFLAGS=common_opts)
- if (env['android_stl'] == 'yes'):
+ if env['android_stl']:
env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/gnu-libstdc++/4.9/include"])
env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/gnu-libstdc++/4.9/libs/" + arch_subpath + "/include"])
env.Append(LIBPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/gnu-libstdc++/4.9/libs/" + arch_subpath])
@@ -223,7 +241,7 @@ def configure(env):
## Link flags
- env['LINKFLAGS'] = ['-shared', '--sysroot=' + sysroot, '-Wl,--warn-shared-textrel']
+ env['LINKFLAGS'] = ['-shared', '--sysroot=' + lib_sysroot, '-Wl,--warn-shared-textrel']
if env["android_arch"] == "armv7":
env.Append(LINKFLAGS='-Wl,--fix-cortex-a8'.split())
env.Append(LINKFLAGS='-Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now'.split())
@@ -243,7 +261,23 @@ def configure(env):
env.Append(LIBS=['OpenSLES', 'EGL', 'GLESv3', 'android', 'log', 'z', 'dl'])
# TODO: Move that to opus module's config
- if("module_opus_enabled" in env and env["module_opus_enabled"] != "no"):
+ if 'module_opus_enabled' in env and env['module_opus_enabled']:
if (env["android_arch"] == "armv6" or env["android_arch"] == "armv7"):
env.Append(CFLAGS=["-DOPUS_ARM_OPT"])
env.opus_fixed_point = "yes"
+
+# Return NDK version as [<major>,<minor>,<build>] or None if cannot be figured out (adapted from the Chromium project).
+def get_ndk_version (path):
+ if path == None:
+ return None
+ prop_file_path = os.path.join(path, "source.properties")
+ try:
+ with open(prop_file_path) as prop_file:
+ for line in prop_file:
+ key_value = map(lambda x: string.strip(x), line.split("="))
+ if key_value[0] == "Pkg.Revision":
+ version_parts = key_value[1].split("-")[0].split(".")
+ return map(int, version_parts[0:3])
+ except:
+ print("Could not read source prop file '%s'" % prop_file_path)
+ return None
diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp
index e3615e2298..79be1501a7 100644
--- a/platform/android/export/export.cpp
+++ b/platform/android/export/export.cpp
@@ -267,7 +267,6 @@ class EditorExportAndroid : public EditorExportPlatform {
if (different) {
- print_line("DIFFERENT!");
Vector<Device> ndevices;
for (int i = 0; i < ldevices.size(); i++) {
@@ -871,7 +870,7 @@ class EditorExportAndroid : public EditorExportPlatform {
String lang = str.substr(str.find_last("-") + 1, str.length()).replace("-", "_");
String prop = "application/config/name_" + lang;
- if (ProjectSettings::get_singleton()->has(prop)) {
+ if (ProjectSettings::get_singleton()->has_setting(prop)) {
str = ProjectSettings::get_singleton()->get(prop);
} else {
str = get_project_name(package_name);
diff --git a/platform/android/file_access_android.cpp b/platform/android/file_access_android.cpp
index f207b81b4b..0fdf9002d7 100644
--- a/platform/android/file_access_android.cpp
+++ b/platform/android/file_access_android.cpp
@@ -95,7 +95,7 @@ void FileAccessAndroid::seek_end(int64_t p_position) {
pos = len + p_position;
}
-size_t FileAccessAndroid::get_pos() const {
+size_t FileAccessAndroid::get_position() const {
return pos;
}
@@ -146,6 +146,11 @@ Error FileAccessAndroid::get_error() const {
return eof ? ERR_FILE_EOF : OK; //not sure what else it may happen
}
+void FileAccessAndroid::flush() {
+
+ ERR_FAIL();
+}
+
void FileAccessAndroid::store_8(uint8_t p_dest) {
ERR_FAIL();
diff --git a/platform/android/file_access_android.h b/platform/android/file_access_android.h
index c2ce2b0bfe..c8fedbe684 100644
--- a/platform/android/file_access_android.h
+++ b/platform/android/file_access_android.h
@@ -53,7 +53,7 @@ public:
virtual void seek(size_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
- virtual size_t get_pos() const; ///< get position in the file
+ virtual size_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF
@@ -63,6 +63,7 @@ public:
virtual Error get_error() const; ///< get last error
+ virtual void flush();
virtual void store_8(uint8_t p_dest); ///< store a byte
virtual bool file_exists(const String &p_path); ///< return true if a file exists
diff --git a/platform/android/file_access_jandroid.cpp b/platform/android/file_access_jandroid.cpp
index ad855c790d..980afd8f46 100644
--- a/platform/android/file_access_jandroid.cpp
+++ b/platform/android/file_access_jandroid.cpp
@@ -106,7 +106,7 @@ void FileAccessJAndroid::seek_end(int64_t p_position) {
seek(get_len());
}
-size_t FileAccessJAndroid::get_pos() const {
+size_t FileAccessJAndroid::get_position() const {
JNIEnv *env = ThreadAndroid::get_env();
ERR_FAIL_COND_V(!is_open(), 0);
@@ -157,6 +157,9 @@ Error FileAccessJAndroid::get_error() const {
return OK;
}
+void FileAccessJAndroid::flush() {
+}
+
void FileAccessJAndroid::store_8(uint8_t p_dest) {
}
diff --git a/platform/android/file_access_jandroid.h b/platform/android/file_access_jandroid.h
index 8060312182..368d2c98fa 100644
--- a/platform/android/file_access_jandroid.h
+++ b/platform/android/file_access_jandroid.h
@@ -57,7 +57,7 @@ public:
virtual void seek(size_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
- virtual size_t get_pos() const; ///< get position in the file
+ virtual size_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF
@@ -67,6 +67,7 @@ public:
virtual Error get_error() const; ///< get last error
+ virtual void flush();
virtual void store_8(uint8_t p_dest); ///< store a byte
virtual bool file_exists(const String &p_path); ///< return true if a file exists
diff --git a/platform/android/java/gradlew.bat b/platform/android/java/gradlew.bat
index aec99730b4..8a0b282aa6 100644
--- a/platform/android/java/gradlew.bat
+++ b/platform/android/java/gradlew.bat
@@ -1,90 +1,90 @@
-@if "%DEBUG%" == "" @echo off
-@rem ##########################################################################
-@rem
-@rem Gradle startup script for Windows
-@rem
-@rem ##########################################################################
-
-@rem Set local scope for the variables with windows NT shell
-if "%OS%"=="Windows_NT" setlocal
-
-@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-set DEFAULT_JVM_OPTS=
-
-set DIRNAME=%~dp0
-if "%DIRNAME%" == "" set DIRNAME=.
-set APP_BASE_NAME=%~n0
-set APP_HOME=%DIRNAME%
-
-@rem Find java.exe
-if defined JAVA_HOME goto findJavaFromJavaHome
-
-set JAVA_EXE=java.exe
-%JAVA_EXE% -version >NUL 2>&1
-if "%ERRORLEVEL%" == "0" goto init
-
-echo.
-echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:findJavaFromJavaHome
-set JAVA_HOME=%JAVA_HOME:"=%
-set JAVA_EXE=%JAVA_HOME%/bin/java.exe
-
-if exist "%JAVA_EXE%" goto init
-
-echo.
-echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:init
-@rem Get command-line arguments, handling Windowz variants
-
-if not "%OS%" == "Windows_NT" goto win9xME_args
-if "%@eval[2+2]" == "4" goto 4NT_args
-
-:win9xME_args
-@rem Slurp the command line arguments.
-set CMD_LINE_ARGS=
-set _SKIP=2
-
-:win9xME_args_slurp
-if "x%~1" == "x" goto execute
-
-set CMD_LINE_ARGS=%*
-goto execute
-
-:4NT_args
-@rem Get arguments from the 4NT Shell from JP Software
-set CMD_LINE_ARGS=%$
-
-:execute
-@rem Setup the command line
-
-set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
-
-@rem Execute Gradle
-"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
-
-:end
-@rem End local scope for the variables with windows NT shell
-if "%ERRORLEVEL%"=="0" goto mainEnd
-
-:fail
-rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
-rem the _cmd.exe /c_ return code!
-if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
-exit /b 1
-
-:mainEnd
-if "%OS%"=="Windows_NT" endlocal
-
-:omega
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/platform/android/java/src/org/godotengine/godot/Godot.java b/platform/android/java/src/org/godotengine/godot/Godot.java
index 53a90e4cfe..59fefc498f 100644
--- a/platform/android/java/src/org/godotengine/godot/Godot.java
+++ b/platform/android/java/src/org/godotengine/godot/Godot.java
@@ -191,6 +191,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
protected void onMainPause() {}
protected void onMainResume() {}
protected void onMainDestroy() {}
+ protected boolean onMainBackPressed() { return false; }
protected void onGLDrawFrame(GL10 gl) {}
protected void onGLSurfaceChanged(GL10 gl, int width, int height) {} // singletons will always miss first onGLSurfaceChanged call
@@ -277,6 +278,21 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
edittext.setView(mView);
io.setEdit(edittext);
+ final Godot godot = this;
+ mView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
+ @Override
+ public void onGlobalLayout() {
+ Point fullSize = new Point();
+ godot.getWindowManager().getDefaultDisplay().getSize(fullSize);
+ Rect gameSize = new Rect();
+ godot.mView.getWindowVisibleDisplayFrame(gameSize);
+
+ final int keyboardHeight = fullSize.y - gameSize.bottom;
+ Log.d("GODOT", "setVirtualKeyboardHeight: " + keyboardHeight);
+ GodotLib.setVirtualKeyboardHeight(keyboardHeight);
+ }
+ });
+
// Ad layout
adLayout = new RelativeLayout(this);
adLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
@@ -752,9 +768,16 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
*/
@Override public void onBackPressed() {
+ boolean shouldQuit = true;
+
+ for(int i=0;i<singleton_count;i++) {
+ if (singletons[i].onMainBackPressed()) {
+ shouldQuit = false;
+ }
+ }
System.out.printf("** BACK REQUEST!\n");
- if (mView != null) {
+ if (shouldQuit && mView != null) {
mView.queueEvent(new Runnable() {
@Override
public void run() {
diff --git a/platform/android/java/src/org/godotengine/godot/GodotLib.java b/platform/android/java/src/org/godotengine/godot/GodotLib.java
index 47a690140f..e0ed4cd38c 100644
--- a/platform/android/java/src/org/godotengine/godot/GodotLib.java
+++ b/platform/android/java/src/org/godotengine/godot/GodotLib.java
@@ -69,4 +69,6 @@ public class GodotLib {
public static native void callobject(int p_ID, String p_method, Object[] p_params);
public static native void calldeferred(int p_ID, String p_method, Object[] p_params);
+ public static native void setVirtualKeyboardHeight(int p_height);
+
}
diff --git a/platform/android/java/src/org/godotengine/godot/GodotView.java b/platform/android/java/src/org/godotengine/godot/GodotView.java
index 3c2ad7cc59..b807b952d4 100644
--- a/platform/android/java/src/org/godotengine/godot/GodotView.java
+++ b/platform/android/java/src/org/godotengine/godot/GodotView.java
@@ -285,13 +285,7 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
@Override public boolean onKeyDown(final int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
- queueEvent(new Runnable() {
- @Override
- public void run() {
- GodotLib.back();
- }
- });
-
+ activity.onBackPressed();
// press 'back' button should not terminate program
//normal handle 'back' event in game logic
return true;
diff --git a/platform/android/java/src/org/godotengine/godot/input/GodotTextInputWrapper.java b/platform/android/java/src/org/godotengine/godot/input/GodotTextInputWrapper.java
index 04669a3b0c..ac424ab9f8 100644
--- a/platform/android/java/src/org/godotengine/godot/input/GodotTextInputWrapper.java
+++ b/platform/android/java/src/org/godotengine/godot/input/GodotTextInputWrapper.java
@@ -88,79 +88,48 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
public void beforeTextChanged(final CharSequence pCharSequence, final int start, final int count, final int after) {
//Log.d(TAG, "beforeTextChanged(" + pCharSequence + ")start: " + start + ",count: " + count + ",after: " + after);
- for (int i=0;i<count;i++){
- mView.queueEvent(new Runnable() {
- @Override
- public void run() {
+ mView.queueEvent(new Runnable() {
+ @Override
+ public void run() {
+ for (int i = 0; i < count; ++i) {
GodotLib.key(KeyEvent.KEYCODE_DEL, 0, true);
GodotLib.key(KeyEvent.KEYCODE_DEL, 0, false);
}
- });
- }
+ }
+ });
}
@Override
public void onTextChanged(final CharSequence pCharSequence, final int start, final int before, final int count) {
//Log.d(TAG, "onTextChanged(" + pCharSequence + ")start: " + start + ",count: " + count + ",before: " + before);
- for (int i=start;i<start+count;i++){
- final int ch = pCharSequence.charAt(i);
- mView.queueEvent(new Runnable() {
- @Override
- public void run() {
+ mView.queueEvent(new Runnable() {
+ @Override
+ public void run() {
+ for (int i = start; i < start + count; ++i) {
+ final int ch = pCharSequence.charAt(i);
GodotLib.key(0, ch, true);
GodotLib.key(0, ch, false);
}
- });
- }
-
+ }
+ });
}
@Override
public boolean onEditorAction(final TextView pTextView, final int pActionID, final KeyEvent pKeyEvent) {
if (this.mEdit == pTextView && this.isFullScreenEdit()) {
- // user press the action button, delete all old text and insert new text
- for (int i = this.mOriginText.length(); i > 0; i--) {
- mView.queueEvent(new Runnable() {
- @Override
- public void run() {
- GodotLib.key(KeyEvent.KEYCODE_DEL, 0, true);
- GodotLib.key(KeyEvent.KEYCODE_DEL, 0, false);
- }
- });
+ final String characters = pKeyEvent.getCharacters();
- /*
- if (BuildConfig.DEBUG) {
- Log.d(TAG, "deleteBackward");
- }
- */
- }
- String text = pTextView.getText().toString();
-
- /* If user input nothing, translate "\n" to engine. */
- if (text.compareTo("") == 0) {
- text = "\n";
- }
-
- if ('\n' != text.charAt(text.length() - 1)) {
- text += '\n';
- }
-
- for(int i = 0; i < text.length(); i++) {
- final int ch = text.codePointAt(i);
- mView.queueEvent(new Runnable() {
- @Override
- public void run() {
+ mView.queueEvent(new Runnable() {
+ @Override
+ public void run() {
+ for (int i = 0; i < characters.length(); i++) {
+ final int ch = characters.codePointAt(i);
GodotLib.key(0, ch, true);
GodotLib.key(0, ch, false);
}
- });
- }
- /*
- if (BuildConfig.DEBUG) {
- Log.d(TAG, "insertText(" + insertText + ")");
- }
- */
+ }
+ });
}
if (pActionID == EditorInfo.IME_ACTION_DONE) {
diff --git a/platform/android/java/src/org/godotengine/godot/utils/CustomSSLSocketFactory.java b/platform/android/java/src/org/godotengine/godot/utils/CustomSSLSocketFactory.java
index c9532a5d01..3fc8c48397 100644
--- a/platform/android/java/src/org/godotengine/godot/utils/CustomSSLSocketFactory.java
+++ b/platform/android/java/src/org/godotengine/godot/utils/CustomSSLSocketFactory.java
@@ -36,12 +36,9 @@ import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
-import java.security.cert.CertificateException;
-import java.security.cert.X509Certificate;
import javax.net.ssl.SSLContext;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
+import javax.net.ssl.TrustManagerFactory;
import org.apache.http.conn.ssl.SSLSocketFactory;
@@ -56,19 +53,10 @@ public class CustomSSLSocketFactory extends SSLSocketFactory {
public CustomSSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
super(truststore);
- TrustManager tm = new X509TrustManager() {
- public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
- }
+ TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509");
+ tmf.init(truststore);
- public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
- }
-
- public X509Certificate[] getAcceptedIssuers() {
- return null;
- }
- };
-
- sslContext.init(null, new TrustManager[] { tm }, null);
+ sslContext.init(null, tmf.getTrustManagers(), null);
}
@Override
diff --git a/platform/android/java_glue.cpp b/platform/android/java_glue.cpp
index 509d1bf123..0b193f5882 100644
--- a/platform/android/java_glue.cpp
+++ b/platform/android/java_glue.cpp
@@ -602,21 +602,10 @@ struct TST {
TST tst;
-struct JAndroidPointerEvent {
-
- Vector<OS_Android::TouchPos> points;
- int pointer;
- int what;
-};
-
-static List<JAndroidPointerEvent> pointer_events;
-static List<Ref<InputEvent> > key_events;
-static List<OS_Android::JoypadEvent> joy_events;
static bool initialized = false;
static int step = 0;
static bool resized = false;
static bool resized_reload = false;
-static bool go_back_request = false;
static Size2 new_size;
static Vector3 accelerometer;
static Vector3 magnetometer;
@@ -624,8 +613,6 @@ static Vector3 gyroscope;
static HashMap<String, JNISingleton *> jni_singletons;
static jobject godot_io;
-static Vector<int> joy_device_ids;
-
typedef void (*GFXInitFunc)(void *ud, bool gl2);
static jmethodID _on_video_init = 0;
@@ -754,6 +741,18 @@ static void _alert(const String &p_message, const String &p_title) {
env->CallVoidMethod(_godot_instance, _alertDialog, jStrMessage, jStrTitle);
}
+// volatile because it can be changed from non-main thread and we need to
+// ensure the change is immediately visible to other threads.
+static volatile int virtual_keyboard_height;
+
+static int _get_vk_height() {
+ return virtual_keyboard_height;
+}
+
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setVirtualKeyboardHeight(JNIEnv *env, jobject obj, jint p_height) {
+ virtual_keyboard_height = p_height;
+}
+
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_initialize(JNIEnv *env, jobject obj, jobject activity, jboolean p_need_reload_hook, jobject p_asset_manager, jboolean p_use_apk_expansion) {
__android_log_print(ANDROID_LOG_INFO, "godot", "**INIT EVENT! - %p\n", env);
@@ -824,7 +823,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_initialize(JNIEnv *en
AudioDriverAndroid::setup(gob);
}
- os_android = new OS_Android(_gfx_init_func, env, _open_uri, _get_data_dir, _get_locale, _get_model, _get_screen_dpi, _show_vk, _hide_vk, _set_screen_orient, _get_unique_id, _get_system_dir, _play_video, _is_video_playing, _pause_video, _stop_video, _set_keep_screen_on, _alert, p_use_apk_expansion);
+ os_android = new OS_Android(_gfx_init_func, env, _open_uri, _get_data_dir, _get_locale, _get_model, _get_screen_dpi, _show_vk, _hide_vk, _get_vk_height, _set_screen_orient, _get_unique_id, _get_system_dir, _play_video, _is_video_playing, _pause_video, _stop_video, _set_keep_screen_on, _alert, p_use_apk_expansion);
os_android->set_need_reload_hooks(p_need_reload_hook);
char wd[500];
@@ -841,7 +840,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_initialize(JNIEnv *en
static void _initialize_java_modules() {
- if (!ProjectSettings::get_singleton()->has("android/modules")) {
+ if (!ProjectSettings::get_singleton()->has_setting("android/modules")) {
print_line("ANDROID MODULES: Nothing to load, aborting");
return;
}
@@ -986,7 +985,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_newcontext(JNIEnv *en
}
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_back(JNIEnv *env, jobject obj) {
- go_back_request = true;
+ os_android->main_loop_request_go_back();
}
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env, jobject obj) {
@@ -1011,36 +1010,6 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env, job
//__android_log_print(ANDROID_LOG_INFO,"godot","**STEP EVENT! - %p-%i\n",env,Thread::get_caller_id());
- while (pointer_events.size()) {
-
- JAndroidPointerEvent jpe = pointer_events.front()->get();
- os_android->process_touch(jpe.what, jpe.pointer, jpe.points);
-
- pointer_events.pop_front();
- }
-
- while (key_events.size()) {
-
- Ref<InputEvent> event = key_events.front()->get();
- os_android->process_event(event);
-
- key_events.pop_front();
- };
-
- while (joy_events.size()) {
-
- OS_Android::JoypadEvent event = joy_events.front()->get();
- os_android->process_joy_event(event);
-
- joy_events.pop_front();
- }
-
- if (go_back_request) {
-
- os_android->main_loop_request_go_back();
- go_back_request = false;
- }
-
os_android->process_accelerometer(accelerometer);
os_android->process_magnetometer(magnetometer);
@@ -1071,12 +1040,8 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch(JNIEnv *env, jo
points.push_back(tp);
}
- JAndroidPointerEvent jpe;
- jpe.pointer = pointer;
- jpe.points = points;
- jpe.what = ev;
+ os_android->process_touch(ev, pointer, points);
- pointer_events.push_back(jpe);
/*
if (os_android)
os_android->process_touch(ev,pointer,points);
@@ -1346,7 +1311,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv *env
jevent.index = p_button;
jevent.pressed = p_pressed;
- joy_events.push_back(jevent);
+ os_android->process_joy_event(jevent);
}
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyaxis(JNIEnv *env, jobject obj, jint p_device, jint p_axis, jfloat p_value) {
@@ -1357,7 +1322,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyaxis(JNIEnv *env,
jevent.index = p_axis;
jevent.value = p_value;
- joy_events.push_back(jevent);
+ os_android->process_joy_event(jevent);
}
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyhat(JNIEnv *env, jobject obj, jint p_device, jint p_hat_x, jint p_hat_y) {
@@ -1378,7 +1343,8 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyhat(JNIEnv *env, j
hat |= InputDefault::HAT_MASK_DOWN;
}
jevent.hat = hat;
- joy_events.push_back(jevent);
+
+ os_android->process_joy_event(jevent);
}
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyconnectionchanged(JNIEnv *env, jobject obj, jint p_device, jboolean p_connected, jstring p_name) {
@@ -1391,6 +1357,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyconnectionchanged(
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jobject obj, jint p_scancode, jint p_unicode_char, jboolean p_pressed) {
Ref<InputEventKey> ievent;
+ ievent.instance();
int val = p_unicode_char;
int scancode = android_get_keysym(p_scancode);
ievent->set_scancode(scancode);
@@ -1409,10 +1376,10 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jobj
ievent->set_unicode(KEY_ENTER);
} else if (p_scancode == 4) {
- go_back_request = true;
+ os_android->main_loop_request_go_back();
}
- key_events.push_back(ievent);
+ os_android->process_event(ievent);
}
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_accelerometer(JNIEnv *env, jobject obj, jfloat x, jfloat y, jfloat z) {
diff --git a/platform/android/java_glue.h b/platform/android/java_glue.h
index ec8ae9a0a6..0aa2489813 100644
--- a/platform/android/java_glue.h
+++ b/platform/android/java_glue.h
@@ -59,6 +59,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_method(JNIEnv *env, j
JNIEXPORT jstring JNICALL Java_org_godotengine_godot_GodotLib_getGlobal(JNIEnv *env, jobject obj, jstring path);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_callobject(JNIEnv *env, jobject p_obj, jint ID, jstring method, jobjectArray params);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_calldeferred(JNIEnv *env, jobject p_obj, jint ID, jstring method, jobjectArray params);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setVirtualKeyboardHeight(JNIEnv *env, jobject obj, jint p_height);
}
#endif
diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp
index dbea2d7531..9d43adf788 100644
--- a/platform/android/os_android.cpp
+++ b/platform/android/os_android.cpp
@@ -47,6 +47,15 @@
#include "file_access_jandroid.h"
#endif
+class AndroidLogger : public Logger {
+public:
+ virtual void logv(const char *p_format, va_list p_list, bool p_err) {
+ __android_log_vprint(p_err ? ANDROID_LOG_ERROR : ANDROID_LOG_INFO, "godot", p_format, p_list);
+ }
+
+ virtual ~AndroidLogger() {}
+};
+
int OS_Android::get_video_driver_count() const {
return 1;
@@ -111,6 +120,15 @@ void OS_Android::initialize_core() {
#endif
}
+void OS_Android::initialize_logger() {
+ Vector<Logger *> loggers;
+ loggers.push_back(memnew(AndroidLogger));
+ // FIXME: Reenable once we figure out how to get this properly in user://
+ // instead of littering the user's working dirs (res:// + pwd) with log files (GH-12277)
+ //loggers.push_back(memnew(RotatedFileLogger("user://logs/log.txt")));
+ _set_logger(memnew(CompositeLogger(loggers)));
+}
+
void OS_Android::set_opengl_extensions(const char *p_gl_extensions) {
ERR_FAIL_COND(!p_gl_extensions);
@@ -139,11 +157,6 @@ void OS_Android::initialize(const VideoMode &p_desired, int p_video_driver, int
AudioDriverManager::initialize(p_audio_driver);
- physics_server = memnew(PhysicsServerSW);
- physics_server->init();
- physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>();
- physics_2d_server->init();
-
input = memnew(InputDefault);
input->set_fallback_mapping("Default Android Gamepad");
@@ -162,23 +175,9 @@ void OS_Android::delete_main_loop() {
}
void OS_Android::finalize() {
-
memdelete(input);
}
-void OS_Android::vprint(const char *p_format, va_list p_list, bool p_stderr) {
-
- __android_log_vprint(p_stderr ? ANDROID_LOG_ERROR : ANDROID_LOG_INFO, "godot", p_format, p_list);
-}
-
-void OS_Android::print(const char *p_format, ...) {
-
- va_list argp;
- va_start(argp, p_format);
- __android_log_vprint(ANDROID_LOG_INFO, "godot", p_format, argp);
- va_end(argp);
-}
-
void OS_Android::alert(const String &p_alert, const String &p_title) {
//print("ALERT: %s\n", p_alert.utf8().get_data());
@@ -517,6 +516,15 @@ bool OS_Android::has_virtual_keyboard() const {
return true;
}
+int OS_Android::get_virtual_keyboard_height() const {
+ if (get_virtual_keyboard_height_func) {
+ return get_virtual_keyboard_height_func();
+ }
+
+ ERR_PRINT("Cannot obtain virtual keyboard height.");
+ return 0;
+}
+
void OS_Android::show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect) {
if (show_virtual_keyboard_func) {
@@ -702,7 +710,7 @@ bool OS_Android::_check_internal_feature_support(const String &p_feature) {
return p_feature == "mobile" || p_feature == "etc" || p_feature == "etc2"; //TODO support etc2 only if GLES3 driver is selected
}
-OS_Android::OS_Android(GFXInitFunc p_gfx_init_func, void *p_gfx_init_ud, OpenURIFunc p_open_uri_func, GetDataDirFunc p_get_data_dir_func, GetLocaleFunc p_get_locale_func, GetModelFunc p_get_model_func, GetScreenDPIFunc p_get_screen_dpi_func, ShowVirtualKeyboardFunc p_show_vk, HideVirtualKeyboardFunc p_hide_vk, SetScreenOrientationFunc p_screen_orient, GetUniqueIDFunc p_get_unique_id, GetSystemDirFunc p_get_sdir_func, VideoPlayFunc p_video_play_func, VideoIsPlayingFunc p_video_is_playing_func, VideoPauseFunc p_video_pause_func, VideoStopFunc p_video_stop_func, SetKeepScreenOnFunc p_set_keep_screen_on_func, AlertFunc p_alert_func, bool p_use_apk_expansion) {
+OS_Android::OS_Android(GFXInitFunc p_gfx_init_func, void *p_gfx_init_ud, OpenURIFunc p_open_uri_func, GetDataDirFunc p_get_data_dir_func, GetLocaleFunc p_get_locale_func, GetModelFunc p_get_model_func, GetScreenDPIFunc p_get_screen_dpi_func, ShowVirtualKeyboardFunc p_show_vk, HideVirtualKeyboardFunc p_hide_vk, VirtualKeyboardHeightFunc p_vk_height_func, SetScreenOrientationFunc p_screen_orient, GetUniqueIDFunc p_get_unique_id, GetSystemDirFunc p_get_sdir_func, VideoPlayFunc p_video_play_func, VideoIsPlayingFunc p_video_is_playing_func, VideoPauseFunc p_video_pause_func, VideoStopFunc p_video_stop_func, SetKeepScreenOnFunc p_set_keep_screen_on_func, AlertFunc p_alert_func, bool p_use_apk_expansion) {
use_apk_expansion = p_use_apk_expansion;
default_videomode.width = 800;
@@ -732,11 +740,14 @@ OS_Android::OS_Android(GFXInitFunc p_gfx_init_func, void *p_gfx_init_ud, OpenURI
show_virtual_keyboard_func = p_show_vk;
hide_virtual_keyboard_func = p_hide_vk;
+ get_virtual_keyboard_height_func = p_vk_height_func;
set_screen_orientation_func = p_screen_orient;
set_keep_screen_on_func = p_set_keep_screen_on_func;
alert_func = p_alert_func;
use_reload_hooks = false;
+
+ _set_logger(memnew(AndroidLogger));
}
OS_Android::~OS_Android() {
diff --git a/platform/android/os_android.h b/platform/android/os_android.h
index 119c14bff3..d9a66b4e3a 100644
--- a/platform/android/os_android.h
+++ b/platform/android/os_android.h
@@ -38,9 +38,6 @@
#include "os/main_loop.h"
//#include "power_android.h"
#include "servers/audio_server.h"
-#include "servers/physics/physics_server_sw.h"
-#include "servers/physics_2d/physics_2d_server_sw.h"
-#include "servers/physics_2d/physics_2d_server_wrap_mt.h"
#include "servers/visual/rasterizer.h"
#ifdef ANDROID_NATIVE_ACTIVITY
@@ -67,6 +64,7 @@ typedef void (*VideoPauseFunc)();
typedef void (*VideoStopFunc)();
typedef void (*SetKeepScreenOnFunc)(bool p_enabled);
typedef void (*AlertFunc)(const String &, const String &);
+typedef int (*VirtualKeyboardHeightFunc)();
class OS_Android : public OS_Unix {
public:
@@ -105,8 +103,6 @@ private:
bool use_16bits_fbo;
VisualServer *visual_server;
- PhysicsServer *physics_server;
- Physics2DServer *physics_2d_server;
mutable String data_dir_cache;
@@ -126,6 +122,7 @@ private:
GetScreenDPIFunc get_screen_dpi_func;
ShowVirtualKeyboardFunc show_virtual_keyboard_func;
HideVirtualKeyboardFunc hide_virtual_keyboard_func;
+ VirtualKeyboardHeightFunc get_virtual_keyboard_height_func;
SetScreenOrientationFunc set_screen_orientation_func;
GetUniqueIDFunc get_unique_id_func;
GetSystemDirFunc get_system_dir_func;
@@ -149,6 +146,7 @@ public:
virtual int get_audio_driver_count() const;
virtual const char *get_audio_driver_name(int p_driver) const;
+ virtual void initialize_logger();
virtual void initialize_core();
virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
@@ -161,8 +159,6 @@ public:
static OS *get_singleton();
- virtual void vprint(const char *p_format, va_list p_list, bool p_stderr = false);
- virtual void print(const char *p_format, ...);
virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
virtual void set_mouse_show(bool p_show);
@@ -202,6 +198,7 @@ public:
virtual bool has_virtual_keyboard() const;
virtual void show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2());
virtual void hide_virtual_keyboard();
+ virtual int get_virtual_keyboard_height() const;
void set_opengl_extensions(const char *p_gl_extensions);
void set_display_size(Size2 p_size);
@@ -241,7 +238,7 @@ public:
void joy_connection_changed(int p_device, bool p_connected, String p_name);
virtual bool _check_internal_feature_support(const String &p_feature);
- OS_Android(GFXInitFunc p_gfx_init_func, void *p_gfx_init_ud, OpenURIFunc p_open_uri_func, GetDataDirFunc p_get_data_dir_func, GetLocaleFunc p_get_locale_func, GetModelFunc p_get_model_func, GetScreenDPIFunc p_get_screen_dpi_func, ShowVirtualKeyboardFunc p_show_vk, HideVirtualKeyboardFunc p_hide_vk, SetScreenOrientationFunc p_screen_orient, GetUniqueIDFunc p_get_unique_id, GetSystemDirFunc p_get_sdir_func, VideoPlayFunc p_video_play_func, VideoIsPlayingFunc p_video_is_playing_func, VideoPauseFunc p_video_pause_func, VideoStopFunc p_video_stop_func, SetKeepScreenOnFunc p_set_keep_screen_on_func, AlertFunc p_alert_func, bool p_use_apk_expansion);
+ OS_Android(GFXInitFunc p_gfx_init_func, void *p_gfx_init_ud, OpenURIFunc p_open_uri_func, GetDataDirFunc p_get_data_dir_func, GetLocaleFunc p_get_locale_func, GetModelFunc p_get_model_func, GetScreenDPIFunc p_get_screen_dpi_func, ShowVirtualKeyboardFunc p_show_vk, HideVirtualKeyboardFunc p_hide_vk, VirtualKeyboardHeightFunc p_vk_height_func, SetScreenOrientationFunc p_screen_orient, GetUniqueIDFunc p_get_unique_id, GetSystemDirFunc p_get_sdir_func, VideoPlayFunc p_video_play_func, VideoIsPlayingFunc p_video_is_playing_func, VideoPauseFunc p_video_pause_func, VideoStopFunc p_video_stop_func, SetKeepScreenOnFunc p_set_keep_screen_on_func, AlertFunc p_alert_func, bool p_use_apk_expansion);
~OS_Android();
};
diff --git a/platform/android/platform_config.h b/platform/android/platform_config.h
index b1c3f027f3..b1f51c9256 100644
--- a/platform/android/platform_config.h
+++ b/platform/android/platform_config.h
@@ -28,3 +28,4 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include <alloca.h>
+#include <malloc.h>
diff --git a/platform/haiku/context_gl_haiku.cpp b/platform/haiku/context_gl_haiku.cpp
index 2b943df5ba..80d0bd78d5 100644
--- a/platform/haiku/context_gl_haiku.cpp
+++ b/platform/haiku/context_gl_haiku.cpp
@@ -29,7 +29,7 @@
/*************************************************************************/
#include "context_gl_haiku.h"
-#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED)
+#if defined(OPENGL_ENABLED)
ContextGL_Haiku::ContextGL_Haiku(HaikuDirectWindow *p_window) {
window = p_window;
diff --git a/platform/haiku/context_gl_haiku.h b/platform/haiku/context_gl_haiku.h
index 40daf43ab9..a9a13a2b7f 100644
--- a/platform/haiku/context_gl_haiku.h
+++ b/platform/haiku/context_gl_haiku.h
@@ -30,7 +30,7 @@
#ifndef CONTEXT_GL_HAIKU_H
#define CONTEXT_GL_HAIKU_H
-#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED)
+#if defined(OPENGL_ENABLED)
#include "drivers/gl_context/context_gl.h"
diff --git a/platform/haiku/detect.py b/platform/haiku/detect.py
index c0e003a3d2..50f9783dd2 100644
--- a/platform/haiku/detect.py
+++ b/platform/haiku/detect.py
@@ -19,9 +19,10 @@ def can_build():
def get_opts():
+ from SCons.Variables import EnumVariable
return [
- ('debug_release', 'Add debug symbols to release version', 'no')
+ EnumVariable('debug_symbols', 'Add debug symbols to release version', 'yes', ('yes', 'no', 'full')),
]
@@ -36,16 +37,21 @@ def configure(env):
## Build type
if (env["target"] == "release"):
- if (env["debug_release"] == "yes"):
+ env.Prepend(CCFLAGS=['-O3', '-ffast-math'])
+ if (env["debug_symbols"] == "yes"):
+ env.Prepend(CCFLAGS=['-g1'])
+ if (env["debug_symbols"] == "full"):
env.Prepend(CCFLAGS=['-g2'])
- else:
- env.Prepend(CCFLAGS=['-O3', '-ffast-math'])
elif (env["target"] == "release_debug"):
env.Prepend(CCFLAGS=['-O2', '-ffast-math', '-DDEBUG_ENABLED'])
+ if (env["debug_symbols"] == "yes"):
+ env.Prepend(CCFLAGS=['-g1'])
+ if (env["debug_symbols"] == "full"):
+ env.Prepend(CCFLAGS=['-g2'])
elif (env["target"] == "debug"):
- env.Prepend(CCFLAGS=['-g2', '-DDEBUG_ENABLED', '-DDEBUG_MEMORY_ENABLED'])
+ env.Prepend(CCFLAGS=['-g3', '-DDEBUG_ENABLED', '-DDEBUG_MEMORY_ENABLED'])
## Architecture
diff --git a/platform/haiku/haiku_direct_window.cpp b/platform/haiku/haiku_direct_window.cpp
index 572df493ff..24a8a4b17b 100644
--- a/platform/haiku/haiku_direct_window.cpp
+++ b/platform/haiku/haiku_direct_window.cpp
@@ -157,8 +157,8 @@ void HaikuDirectWindow::HandleMouseButton(BMessage *message) {
mouse_event.mouse_button.mod = GetKeyModifierState(modifiers);
mouse_event->get_button_mask() = GetMouseButtonState(buttons);
- mouse_event->get_pos().x = where.x;
- mouse_event->get_pos().y = where.y;
+ mouse_event->get_position().x = where.x;
+ mouse_event->get_position().y = where.y;
mouse_event.mouse_button.global_x = where.x;
mouse_event.mouse_button.global_y = where.y;
@@ -242,8 +242,8 @@ void HaikuDirectWindow::HandleMouseWheelChanged(BMessage *message) {
mouse_event->get_button_index() = wheel_delta_y < 0 ? 4 : 5;
mouse_event.mouse_button.mod = GetKeyModifierState(last_key_modifier_state);
mouse_event->get_button_mask() = last_button_mask;
- mouse_event->get_pos().x = last_mouse_position.x;
- mouse_event->get_pos().y = last_mouse_position.y;
+ mouse_event->get_position().x = last_mouse_position.x;
+ mouse_event->get_position().y = last_mouse_position.y;
mouse_event.mouse_button.global_x = last_mouse_position.x;
mouse_event.mouse_button.global_y = last_mouse_position.y;
diff --git a/platform/haiku/os_haiku.cpp b/platform/haiku/os_haiku.cpp
index 9f2f88bb4e..7a681d46f7 100644
--- a/platform/haiku/os_haiku.cpp
+++ b/platform/haiku/os_haiku.cpp
@@ -105,7 +105,7 @@ void OS_Haiku::initialize(const VideoMode &p_desired, int p_video_driver, int p_
window->SetFlags(flags);
}
-#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED)
+#if defined(OPENGL_ENABLED)
context_gl = memnew(ContextGL_Haiku(window));
context_gl->initialize();
context_gl->make_current();
@@ -130,13 +130,6 @@ void OS_Haiku::initialize(const VideoMode &p_desired, int p_video_driver, int p_
window->Show();
visual_server->init();
- physics_server = memnew(PhysicsServerSW);
- physics_server->init();
- physics_2d_server = memnew(Physics2DServerSW);
- // TODO: enable multithreaded PS
- //physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>();
- physics_2d_server->init();
-
AudioDriverManager::initialize(p_audio_driver);
power_manager = memnew(PowerHaiku);
@@ -153,15 +146,9 @@ void OS_Haiku::finalize() {
memdelete(visual_server);
memdelete(rasterizer);
- physics_server->finish();
- memdelete(physics_server);
-
- physics_2d_server->finish();
- memdelete(physics_2d_server);
-
memdelete(input);
-#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED)
+#if defined(OPENGL_ENABLED)
memdelete(context_gl);
#endif
}
diff --git a/platform/haiku/os_haiku.h b/platform/haiku/os_haiku.h
index d2fafb9129..501650c94f 100644
--- a/platform/haiku/os_haiku.h
+++ b/platform/haiku/os_haiku.h
@@ -38,8 +38,6 @@
#include "main/input_default.h"
#include "power_haiku.h"
#include "servers/audio_server.h"
-#include "servers/physics_2d/physics_2d_server_sw.h"
-#include "servers/physics_server.h"
#include "servers/visual/rasterizer.h"
#include "servers/visual_server.h"
@@ -52,15 +50,13 @@ private:
Rasterizer *rasterizer;
VisualServer *visual_server;
VideoMode current_video_mode;
- PhysicsServer *physics_server;
- Physics2DServer *physics_2d_server;
PowerHaiku *power_manager;
#ifdef MEDIA_KIT_ENABLED
AudioDriverMediaKit driver_media_kit;
#endif
-#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED)
+#if defined(OPENGL_ENABLED)
ContextGL_Haiku *context_gl;
#endif
diff --git a/platform/iphone/SCsub b/platform/iphone/SCsub
index 998d0a3f0d..61798c5f87 100644
--- a/platform/iphone/SCsub
+++ b/platform/iphone/SCsub
@@ -5,7 +5,6 @@ Import('env')
iphone_lib = [
'os_iphone.cpp',
- 'audio_driver_iphone.cpp',
'sem_iphone.cpp',
'gl_view.mm',
'main.m',
diff --git a/platform/iphone/app_delegate.mm b/platform/iphone/app_delegate.mm
index c7b65b476b..8f2893e69e 100644
--- a/platform/iphone/app_delegate.mm
+++ b/platform/iphone/app_delegate.mm
@@ -29,8 +29,8 @@
/*************************************************************************/
#import "app_delegate.h"
-#include "audio_driver_iphone.h"
#include "core/project_settings.h"
+#include "drivers/coreaudio/audio_driver_coreaudio.h"
#import "gl_view.h"
#include "main/main.h"
#include "os_iphone.h"
@@ -81,7 +81,7 @@ void _set_keep_screen_on(bool p_enabled) {
extern int gargc;
extern char **gargv;
-extern int iphone_main(int, int, int, char **);
+extern int iphone_main(int, int, int, char **, String);
extern void iphone_finish();
CMMotionManager *motionManager;
@@ -393,15 +393,6 @@ static int frame_count = 0;
};
++frame_count;
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
- NSUserDomainMask, YES);
- NSString *documentsDirectory = [paths objectAtIndex:0];
- // NSString *documentsDirectory = [[[NSFileManager defaultManager]
- // URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask]
- // lastObject];
- OSIPhone::get_singleton()->set_data_dir(
- String::utf8([documentsDirectory UTF8String]));
-
NSString *locale_code = [[NSLocale currentLocale] localeIdentifier];
OSIPhone::get_singleton()->set_locale(
String::utf8([locale_code UTF8String]));
@@ -604,7 +595,11 @@ static int frame_count = 0;
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES,
GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
- int err = iphone_main(backingWidth, backingHeight, gargc, gargv);
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
+ NSUserDomainMask, YES);
+ NSString *documentsDirectory = [paths objectAtIndex:0];
+
+ int err = iphone_main(backingWidth, backingHeight, gargc, gargv, String::utf8([documentsDirectory UTF8String]));
if (err != 0) {
// bail, things did not go very well for us, should probably output a message on screen with our error code...
exit(0);
@@ -643,6 +638,9 @@ static int frame_count = 0;
mainViewController = view_controller;
+ // prevent to stop music in another background app
+ [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil];
+
#ifdef MODULE_GAME_ANALYTICS_ENABLED
printf("********************* didFinishLaunchingWithOptions\n");
if (!ProjectSettings::get_singleton()->has("mobileapptracker/advertiser_id")) {
@@ -736,8 +734,8 @@ static int frame_count = 0;
};
// Fixed audio can not resume if it is interrupted cause by an incoming phone call
- if (AudioDriverIphone::get_singleton() != NULL)
- AudioDriverIphone::get_singleton()->start();
+ if (AudioDriverCoreAudio::get_singleton() != NULL)
+ AudioDriverCoreAudio::get_singleton()->start();
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
diff --git a/platform/iphone/audio_driver_iphone.cpp b/platform/iphone/audio_driver_iphone.cpp
deleted file mode 100644
index dbc5bdb654..0000000000
--- a/platform/iphone/audio_driver_iphone.cpp
+++ /dev/null
@@ -1,187 +0,0 @@
-/*************************************************************************/
-/* audio_driver_iphone.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#include "audio_driver_iphone.h"
-
-Error AudioDriverIphone::init() {
-
- active = false;
- channels = 2;
-
- AudioStreamBasicDescription strdesc;
- strdesc.mFormatID = kAudioFormatLinearPCM;
- strdesc.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
- strdesc.mChannelsPerFrame = channels;
- strdesc.mSampleRate = 44100;
- strdesc.mFramesPerPacket = 1;
- strdesc.mBitsPerChannel = 16;
- strdesc.mBytesPerFrame =
- strdesc.mBitsPerChannel * strdesc.mChannelsPerFrame / 8;
- strdesc.mBytesPerPacket =
- strdesc.mBytesPerFrame * strdesc.mFramesPerPacket;
-
- AURenderCallbackStruct callback;
- AudioComponentDescription desc;
- const AudioUnitElement output_bus = 0;
- const AudioUnitElement bus = output_bus;
- const AudioUnitScope scope = kAudioUnitScope_Input;
-
- zeromem(&desc, sizeof(desc));
- desc.componentType = kAudioUnitType_Output;
- desc.componentSubType = kAudioUnitSubType_RemoteIO; /* !!! FIXME: ? */
- AudioComponent comp = AudioComponentFindNext(NULL, &desc);
- desc.componentManufacturer = kAudioUnitManufacturer_Apple;
-
- OSStatus result = AudioComponentInstanceNew(comp, &audio_unit);
- ERR_FAIL_COND_V(result != noErr, FAILED);
- ERR_FAIL_COND_V(comp == NULL, FAILED);
-
- result = AudioUnitSetProperty(audio_unit,
- kAudioUnitProperty_StreamFormat,
- scope, bus, &strdesc, sizeof(strdesc));
- ERR_FAIL_COND_V(result != noErr, FAILED);
-
- zeromem(&callback, sizeof(AURenderCallbackStruct));
- callback.inputProc = &AudioDriverIphone::output_callback;
- callback.inputProcRefCon = this;
- result = AudioUnitSetProperty(audio_unit,
- kAudioUnitProperty_SetRenderCallback,
- scope, bus, &callback, sizeof(callback));
- ERR_FAIL_COND_V(result != noErr, FAILED);
-
- result = AudioUnitInitialize(audio_unit);
- ERR_FAIL_COND_V(result != noErr, FAILED);
-
- result = AudioOutputUnitStart(audio_unit);
- ERR_FAIL_COND_V(result != noErr, FAILED);
-
- const int samples = 1024;
- samples_in = memnew_arr(int32_t, samples); // whatever
- buffer_frames = samples / channels;
-
- return FAILED;
-};
-
-OSStatus AudioDriverIphone::output_callback(void *inRefCon,
- AudioUnitRenderActionFlags *ioActionFlags,
- const AudioTimeStamp *inTimeStamp,
- UInt32 inBusNumber, UInt32 inNumberFrames,
- AudioBufferList *ioData) {
-
- AudioBuffer *abuf;
- AudioDriverIphone *ad = (AudioDriverIphone *)inRefCon;
-
- bool mix = true;
-
- if (!ad->active)
- mix = false;
- else if (ad->mutex) {
- mix = ad->mutex->try_lock() == OK;
- };
-
- if (!mix) {
- for (unsigned int i = 0; i < ioData->mNumberBuffers; i++) {
- 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;
- 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++) {
-
- out[i] = ad->samples_in[i] >> 16;
- }
-
- frames_left -= frames;
- out += frames * ad->channels;
- };
- };
-
- if (ad->mutex)
- ad->mutex->unlock();
-
- return 0;
-};
-
-void AudioDriverIphone::start() {
- active = true;
- // Resume audio
- // iOS audio-thread stoped if it is interrupted cause by an incoming phone call
- // Use AudioOutputUnitStart to re-create audio-thread
- OSStatus result = AudioOutputUnitStart(audio_unit);
- ERR_FAIL_COND(result != noErr);
-};
-
-int AudioDriverIphone::get_mix_rate() const {
- return 44100;
-};
-
-AudioDriver::SpeakerMode AudioDriverIphone::get_speaker_mode() const {
- return SPEAKER_MODE_STEREO;
-};
-
-void AudioDriverIphone::lock() {
-
- if (active && mutex)
- mutex->lock();
-};
-
-void AudioDriverIphone::unlock() {
- if (active && mutex)
- mutex->unlock();
-};
-
-void AudioDriverIphone::finish() {
-
- memdelete_arr(samples_in);
-};
-
-AudioDriverIphone::AudioDriverIphone() {
-
- mutex = Mutex::create(); //NULL;
-};
-
-AudioDriverIphone::~AudioDriverIphone(){
-
-};
diff --git a/platform/iphone/detect.py b/platform/iphone/detect.py
index 0b81422fa3..993a93ff89 100644
--- a/platform/iphone/detect.py
+++ b/platform/iphone/detect.py
@@ -20,24 +20,24 @@ def can_build():
def get_opts():
-
+ from SCons.Variables import BoolVariable
return [
('IPHONEPLATFORM', 'Name of the iPhone platform', 'iPhoneOS'),
('IPHONEPATH', 'Path to iPhone toolchain', '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain'),
('IPHONESDK', 'Path to the iPhone SDK', '/Applications/Xcode.app/Contents/Developer/Platforms/${IPHONEPLATFORM}.platform/Developer/SDKs/${IPHONEPLATFORM}.sdk/'),
- ('game_center', 'Support for game center', 'yes'),
- ('store_kit', 'Support for in-app store', 'yes'),
- ('icloud', 'Support for iCloud', 'yes'),
- ('ios_exceptions', 'Enable exceptions', 'no'),
+ BoolVariable('game_center', 'Support for game center', True),
+ BoolVariable('store_kit', 'Support for in-app store', True),
+ BoolVariable('icloud', 'Support for iCloud', True),
+ BoolVariable('ios_exceptions', 'Enable exceptions', False),
('ios_triple', 'Triple for ios toolchain', ''),
- ('ios_sim', 'Build simulator binary', 'no'),
+ BoolVariable('ios_sim', 'Build simulator binary', False),
]
def get_flags():
return [
- ('tools', 'no'),
+ ('tools', False),
]
@@ -47,8 +47,8 @@ def configure(env):
if (env["target"].startswith("release")):
env.Append(CPPFLAGS=['-DNDEBUG', '-DNS_BLOCK_ASSERTIONS=1'])
- env.Append(CPPFLAGS=['-O2', '-flto', '-ftree-vectorize', '-fomit-frame-pointer', '-ffast-math', '-funsafe-math-optimizations'])
- env.Append(LINKFLAGS=['-O2', '-flto'])
+ env.Append(CPPFLAGS=['-O2', '-ftree-vectorize', '-fomit-frame-pointer', '-ffast-math', '-funsafe-math-optimizations'])
+ env.Append(LINKFLAGS=['-O2'])
if env["target"] == "release_debug":
env.Append(CPPFLAGS=['-DDEBUG_ENABLED'])
@@ -56,9 +56,13 @@ def configure(env):
elif (env["target"] == "debug"):
env.Append(CPPFLAGS=['-D_DEBUG', '-DDEBUG=1', '-gdwarf-2', '-O0', '-DDEBUG_ENABLED', '-DDEBUG_MEMORY_ENABLED'])
+ if (env["use_lto"]):
+ env.Append(CPPFLAGS=['-flto'])
+ env.Append(LINKFLAGS=['-flto'])
+
## Architecture
- if (env["ios_sim"] == "yes" or env["arch"] == "x86"): # i386, simulator
+ if env["ios_sim"] or env["arch"] == "x86": # i386, simulator
env["arch"] = "x86"
env["bits"] = "32"
elif (env["arch"] == "arm" or env["arch"] == "arm32" or env["arch"] == "armv7" or env["bits"] == "32"): # arm
@@ -91,7 +95,7 @@ def configure(env):
env.Append(CPPFLAGS=['-DNEED_LONG_INT'])
env.Append(CPPFLAGS=['-DLIBYUV_DISABLE_NEON'])
- if env['ios_exceptions'] == 'yes':
+ if env['ios_exceptions']:
env.Append(CPPFLAGS=['-fexceptions'])
else:
env.Append(CPPFLAGS=['-fno-exceptions'])
@@ -129,15 +133,15 @@ def configure(env):
])
# Feature options
- if env['game_center'] == 'yes':
+ if env['game_center']:
env.Append(CPPFLAGS=['-DGAME_CENTER_ENABLED'])
env.Append(LINKFLAGS=['-framework', 'GameKit'])
- if env['store_kit'] == 'yes':
+ if env['store_kit']:
env.Append(CPPFLAGS=['-DSTOREKIT_ENABLED'])
env.Append(LINKFLAGS=['-framework', 'StoreKit'])
- if env['icloud'] == 'yes':
+ if env['icloud']:
env.Append(CPPFLAGS=['-DICLOUD_ENABLED'])
env.Append(CPPPATH=['$IPHONESDK/usr/include',
@@ -148,10 +152,10 @@ def configure(env):
env['ENV']['CODESIGN_ALLOCATE'] = '/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate'
env.Append(CPPPATH=['#platform/iphone'])
- env.Append(CPPFLAGS=['-DIPHONE_ENABLED', '-DUNIX_ENABLED', '-DGLES2_ENABLED', '-DMPC_FIXED_POINT'])
+ env.Append(CPPFLAGS=['-DIPHONE_ENABLED', '-DUNIX_ENABLED', '-DGLES2_ENABLED', '-DMPC_FIXED_POINT', '-DCOREAUDIO_ENABLED'])
# TODO: Move that to opus module's config
- if("module_opus_enabled" in env and env["module_opus_enabled"] != "no"):
+ if 'module_opus_enabled' in env and env['module_opus_enabled']:
env.opus_fixed_point = "yes"
if (env["arch"] == "arm"):
env.Append(CFLAGS=["-DOPUS_ARM_OPT"])
diff --git a/platform/iphone/export/export.cpp b/platform/iphone/export/export.cpp
index 8bb7f23ead..0507ef19d6 100644
--- a/platform/iphone/export/export.cpp
+++ b/platform/iphone/export/export.cpp
@@ -52,7 +52,14 @@ class EditorExportPlatformIOS : public EditorExportPlatform {
Ref<ImageTexture> logo;
- void _fix_config_file(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &pfile, const String &p_name, const String &p_binary);
+ typedef Error (*FileHandler)(String p_file, void *p_userdata);
+ static Error _walk_dir_recursive(DirAccess *p_da, FileHandler p_handler, void *p_userdata);
+ static Error _codesign(String p_file, void *p_userdata);
+
+ void _fix_config_file(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &pfile, const String &p_name, const String &p_binary, bool p_debug);
+ static Error _export_dylibs(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total);
+ Error _export_loading_screens(const Ref<EditorExportPreset> &p_preset, const String &p_dest_dir);
+ Error _export_icons(const Ref<EditorExportPreset> &p_preset, const String &p_iconset_dir);
protected:
virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features);
@@ -63,7 +70,7 @@ public:
virtual String get_os_name() const { return "iOS"; }
virtual Ref<Texture> get_logo() const { return logo; }
- virtual String get_binary_extension() const { return "xcodeproj"; }
+ virtual String get_binary_extension() const { return "ipa"; }
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
@@ -96,16 +103,44 @@ void EditorExportPlatformIOS::get_export_options(List<ExportOption> *r_options)
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_package/debug", PROPERTY_HINT_GLOBAL_FILE, "zip"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_package/release", PROPERTY_HINT_GLOBAL_FILE, "zip"), ""));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/app_store_team_id"), ""));
+
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/provisioning_profile_uuid_debug"), ""));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/code_sign_identity_debug"), "iPhone Developer"));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_method_debug", PROPERTY_HINT_ENUM, "App Store,Development,Ad-Hoc,Enterprise"), 1));
+
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/provisioning_profile_uuid_release"), ""));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/code_sign_identity_release"), "iPhone Distribution"));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_method_release", PROPERTY_HINT_ENUM, "App Store,Development,Ad-Hoc,Enterprise"), 0));
+
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/name"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/info"), "Made with Godot Engine"));
- // r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "png"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/identifier"), "org.godotengine.iosgame"));
- r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), "godotiosgame"));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), "????"));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version"), "1.0"));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version"), "1.0"));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/bits_mode", PROPERTY_HINT_ENUM, "Fat (32 & 64 bits),64 bits,32 bits"), 1));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "required_icons/iphone_120x120", PROPERTY_HINT_FILE, "png"), "")); // Home screen on iPhone/iPod Touch with retina display
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "required_icons/ipad_76x76", PROPERTY_HINT_FILE, "png"), "")); // Home screen on iPad
+
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "optional_icons/iphone_180x180", PROPERTY_HINT_FILE, "png"), "")); // Home screen on iPhone with retina HD display
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "optional_icons/ipad_152x152", PROPERTY_HINT_FILE, "png"), "")); // Home screen on iPad with retina display
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "optional_icons/ipad_167x167", PROPERTY_HINT_FILE, "png"), "")); // Home screen on iPad Pro
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "optional_icons/spotlight_40x40", PROPERTY_HINT_FILE, "png"), "")); // Spotlight
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "optional_icons/spotlight_80x80", PROPERTY_HINT_FILE, "png"), "")); // Spotlight on devices with retina display
+
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "landscape_launch_screens/iphone_2208x1242", PROPERTY_HINT_FILE, "png"), "")); // iPhone 6 Plus, 6s Plus, 7 Plus
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "landscape_launch_screens/ipad_2732x2048", PROPERTY_HINT_FILE, "png"), "")); // 12.9-inch iPad Pro
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "landscape_launch_screens/ipad_2048x1536", PROPERTY_HINT_FILE, "png"), "")); // Other iPads
+
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "portrait_launch_screens/iphone_640x1136", PROPERTY_HINT_FILE, "png"), "")); // iPhone 5, 5s, SE
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "portrait_launch_screens/iphone_750x1334", PROPERTY_HINT_FILE, "png"), "")); // iPhone 6, 6s, 7
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "portrait_launch_screens/iphone_1242x2208", PROPERTY_HINT_FILE, "png"), "")); // iPhone 6 Plus, 6s Plus, 7 Plus
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "portrait_launch_screens/ipad_2048x2732", PROPERTY_HINT_FILE, "png"), "")); // 12.9-inch iPad Pro
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "portrait_launch_screens/ipad_1536x2048", PROPERTY_HINT_FILE, "png"), "")); // Other iPads
+
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/s3tc"), false));
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc"), false));
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc2"), true));
@@ -113,11 +148,17 @@ void EditorExportPlatformIOS::get_export_options(List<ExportOption> *r_options)
/* probably need some more info */
}
-void EditorExportPlatformIOS::_fix_config_file(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &pfile, const String &p_name, const String &p_binary) {
-
+void EditorExportPlatformIOS::_fix_config_file(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &pfile, const String &p_name, const String &p_binary, bool p_debug) {
+ static const String export_method_string[] = {
+ "app-store",
+ "development",
+ "ad-hoc",
+ "enterprise"
+ };
String str;
String strnew;
str.parse_utf8((const char *)pfile.ptr(), pfile.size());
+ print_line(str);
Vector<String> lines = str.split("\n");
for (int i = 0; i < lines.size(); i++) {
if (lines[i].find("$binary") != -1) {
@@ -136,6 +177,19 @@ void EditorExportPlatformIOS::_fix_config_file(const Ref<EditorExportPreset> &p_
strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n";
} else if (lines[i].find("$copyright") != -1) {
strnew += lines[i].replace("$copyright", p_preset->get("application/copyright")) + "\n";
+ } else if (lines[i].find("$team_id") != -1) {
+ strnew += lines[i].replace("$team_id", p_preset->get("application/app_store_team_id")) + "\n";
+ } else if (lines[i].find("$export_method") != -1) {
+ int export_method = p_preset->get(p_debug ? "application/export_method_debug" : "application/export_method_release");
+ strnew += lines[i].replace("$export_method", export_method_string[export_method]) + "\n";
+ } else if (lines[i].find("$provisioning_profile_uuid_release") != -1) {
+ strnew += lines[i].replace("$provisioning_profile_uuid_release", p_preset->get("application/provisioning_profile_uuid_release")) + "\n";
+ } else if (lines[i].find("$provisioning_profile_uuid_debug") != -1) {
+ strnew += lines[i].replace("$provisioning_profile_uuid_debug", p_preset->get("application/provisioning_profile_uuid_debug")) + "\n";
+ } else if (lines[i].find("$code_sign_identity_debug") != -1) {
+ strnew += lines[i].replace("$code_sign_identity_debug", p_preset->get("application/code_sign_identity_debug")) + "\n";
+ } else if (lines[i].find("$code_sign_identity_release") != -1) {
+ strnew += lines[i].replace("$code_sign_identity_release", p_preset->get("application/code_sign_identity_release")) + "\n";
} else {
strnew += lines[i] + "\n";
}
@@ -150,12 +204,214 @@ void EditorExportPlatformIOS::_fix_config_file(const Ref<EditorExportPreset> &p_
}
}
+Error EditorExportPlatformIOS::_export_dylibs(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total) {
+ if (!p_path.ends_with(".dylib")) return OK;
+ const String &dest_dir = *(String *)p_userdata;
+ String rel_path = p_path.replace_first("res://", "dylibs/");
+ DirAccess *dest_dir_access = DirAccess::open(dest_dir);
+ ERR_FAIL_COND_V(!dest_dir_access, ERR_CANT_OPEN);
+
+ String base_dir = rel_path.get_base_dir();
+ Error make_dir_err = OK;
+ if (!dest_dir_access->dir_exists(base_dir)) {
+ make_dir_err = dest_dir_access->make_dir_recursive(base_dir);
+ }
+ if (make_dir_err != OK) {
+ memdelete(dest_dir_access);
+ return make_dir_err;
+ }
+
+ Error copy_err = dest_dir_access->copy(p_path, dest_dir + rel_path);
+ memdelete(dest_dir_access);
+
+ return copy_err;
+}
+
+struct IconInfo {
+ const char *preset_key;
+ const char *idiom;
+ const char *export_name;
+ const char *actual_size_side;
+ const char *scale;
+ const char *unscaled_size;
+ bool is_required;
+};
+
+static const IconInfo icon_infos[] = {
+ { "required_icons/iphone_120x120", "iphone", "Icon-120.png", "120", "2x", "60x60", true },
+ { "required_icons/iphone_120x120", "iphone", "Icon-120.png", "120", "3x", "40x40", true },
+
+ { "required_icons/ipad_76x76", "ipad", "Icon-76.png", "76", "1x", "76x76", false },
+
+ { "optional_icons/iphone_180x180", "iphone", "Icon-180.png", "180", "3x", "60x60", false },
+
+ { "optional_icons/ipad_152x152", "ipad", "Icon-152.png", "152", "2x", "76x76", false },
+
+ { "optional_icons/ipad_167x167", "ipad", "Icon-167.png", "167", "2x", "83.5x83.5", false },
+
+ { "optional_icons/spotlight_40x40", "ipad", "Icon-40.png", "40", "1x", "40x40", false },
+
+ { "optional_icons/spotlight_80x80", "iphone", "Icon-80.png", "80", "2x", "40x40", false },
+ { "optional_icons/spotlight_80x80", "ipad", "Icon-80.png", "80", "2x", "40x40", false }
+
+};
+
+Error EditorExportPlatformIOS::_export_icons(const Ref<EditorExportPreset> &p_preset, const String &p_iconset_dir) {
+ String json_description = "{\"images\":[";
+ String sizes;
+
+ DirAccess *da = DirAccess::open(p_iconset_dir);
+ ERR_FAIL_COND_V(!da, ERR_CANT_OPEN);
+
+ for (int i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) {
+ IconInfo info = icon_infos[i];
+ String icon_path = p_preset->get(info.preset_key);
+ if (icon_path.length() == 0) {
+ if (info.is_required) {
+ ERR_PRINT("Required icon is not specified in the preset");
+ return ERR_UNCONFIGURED;
+ }
+ continue;
+ }
+ Error err = da->copy(icon_path, p_iconset_dir + info.export_name);
+ if (err) {
+ memdelete(da);
+ String err_str = String("Failed to export icon: ") + icon_path;
+ ERR_PRINT(err_str.utf8().get_data());
+ return err;
+ }
+ sizes += String(info.actual_size_side) + "\n";
+ if (i > 0) {
+ json_description += ",";
+ }
+ json_description += String("{");
+ json_description += String("\"idiom\":") + "\"" + info.idiom + "\",";
+ json_description += String("\"size\":") + "\"" + info.unscaled_size + "\",";
+ json_description += String("\"scale\":") + "\"" + info.scale + "\",";
+ json_description += String("\"filename\":") + "\"" + info.export_name + "\"";
+ json_description += String("}");
+ }
+ json_description += "]}";
+ memdelete(da);
+
+ FileAccess *json_file = FileAccess::open(p_iconset_dir + "Contents.json", FileAccess::WRITE);
+ ERR_FAIL_COND_V(!json_file, ERR_CANT_CREATE);
+ CharString json_utf8 = json_description.utf8();
+ json_file->store_buffer((const uint8_t *)json_utf8.get_data(), json_utf8.length());
+ memdelete(json_file);
+
+ FileAccess *sizes_file = FileAccess::open(p_iconset_dir + "sizes", FileAccess::WRITE);
+ ERR_FAIL_COND_V(!sizes_file, ERR_CANT_CREATE);
+ CharString sizes_utf8 = sizes.utf8();
+ sizes_file->store_buffer((const uint8_t *)sizes_utf8.get_data(), sizes_utf8.length());
+ memdelete(sizes_file);
+
+ return OK;
+}
+
+struct LoadingScreenInfo {
+ const char *preset_key;
+ const char *export_name;
+};
+
+static const LoadingScreenInfo loading_screen_infos[] = {
+ { "landscape_launch_screens/iphone_2208x1242", "Default-Landscape-736h@3x.png" },
+ { "landscape_launch_screens/ipad_2732x2048", "Default-Landscape-1366h@2x.png" },
+ { "landscape_launch_screens/ipad_2048x1536", "Default-Landscape@2x.png" },
+
+ { "portrait_launch_screens/iphone_640x1136", "Default-568h@2x.png" },
+ { "portrait_launch_screens/iphone_750x1334", "Default-667h@2x.png" },
+ { "portrait_launch_screens/iphone_1242x2208", "Default-Portrait-736h@3x.png" },
+ { "portrait_launch_screens/ipad_2048x2732", "Default-Portrait-1366h@2x.png" },
+ { "portrait_launch_screens/ipad_1536x2048", "Default-Portrait@2x.png" }
+};
+
+Error EditorExportPlatformIOS::_export_loading_screens(const Ref<EditorExportPreset> &p_preset, const String &p_dest_dir) {
+ DirAccess *da = DirAccess::open(p_dest_dir);
+ ERR_FAIL_COND_V(!da, ERR_CANT_OPEN);
+
+ for (int i = 0; i < sizeof(loading_screen_infos) / sizeof(loading_screen_infos[0]); ++i) {
+ LoadingScreenInfo info = loading_screen_infos[i];
+ String loading_screen_file = p_preset->get(info.preset_key);
+ Error err = da->copy(loading_screen_file, p_dest_dir + info.export_name);
+ if (err) {
+ memdelete(da);
+ String err_str = String("Failed to export loading screen: ") + loading_screen_file;
+ ERR_PRINT(err_str.utf8().get_data());
+ return err;
+ }
+ }
+ memdelete(da);
+
+ return OK;
+}
+
+Error EditorExportPlatformIOS::_walk_dir_recursive(DirAccess *p_da, FileHandler p_handler, void *p_userdata) {
+ Vector<String> dirs;
+ String path;
+ String current_dir = p_da->get_current_dir();
+ p_da->list_dir_begin();
+ while ((path = p_da->get_next()).length() != 0) {
+ if (p_da->current_is_dir()) {
+ if (path != "." && path != "..") {
+ dirs.push_back(path);
+ }
+ } else {
+ Error err = p_handler(current_dir + "/" + path, p_userdata);
+ if (err) {
+ p_da->list_dir_end();
+ return err;
+ }
+ }
+ }
+ p_da->list_dir_end();
+
+ for (int i = 0; i < dirs.size(); ++i) {
+ String dir = dirs[i];
+ p_da->change_dir(dir);
+ Error err = _walk_dir_recursive(p_da, p_handler, p_userdata);
+ p_da->change_dir("..");
+ if (err) {
+ return err;
+ }
+ }
+
+ return OK;
+}
+
+struct CodesignData {
+ const Ref<EditorExportPreset> &preset;
+ bool debug;
+
+ CodesignData(const Ref<EditorExportPreset> &p_preset, bool p_debug)
+ : preset(p_preset), debug(p_debug) {
+ }
+};
+
+Error EditorExportPlatformIOS::_codesign(String p_file, void *p_userdata) {
+ if (p_file.ends_with(".dylib")) {
+ CodesignData *data = (CodesignData *)p_userdata;
+ print_line(String("Signing ") + p_file);
+ List<String> codesign_args;
+ codesign_args.push_back("-f");
+ codesign_args.push_back("-s");
+ codesign_args.push_back(data->preset->get(data->debug ? "application/code_sign_identity_debug" : "application/code_sign_identity_release"));
+ codesign_args.push_back(p_file);
+ return OS::get_singleton()->execute("codesign", codesign_args, true);
+ }
+ return OK;
+}
+
Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
String src_pkg_name;
String dest_dir = p_path.get_base_dir() + "/";
String binary_name = p_path.get_file().get_basename();
- EditorProgress ep("export", "Exporting for iOS", 3);
+ EditorProgress ep("export", "Exporting for iOS", 5);
+
+ 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);
if (p_debug)
src_pkg_name = p_preset->get("custom_package/debug");
@@ -206,6 +462,15 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p
bool found_binary = false;
int total_size = 0;
+ Set<String> files_to_parse;
+ files_to_parse.insert("godot_ios/godot_ios-Info.plist");
+ files_to_parse.insert("godot_ios.xcodeproj/project.pbxproj");
+ files_to_parse.insert("export_options.plist");
+ files_to_parse.insert("godot_ios.xcodeproj/project.xcworkspace/contents.xcworkspacedata");
+ files_to_parse.insert("godot_ios.xcodeproj/xcshareddata/xcschemes/godot_ios.xcscheme");
+
+ print_line("Unzipping...");
+
while (ret == UNZ_OK) {
bool is_execute = false;
@@ -229,12 +494,9 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p
file = file.replace_first("iphone/", "");
- if (file == "godot_ios.xcodeproj/project.pbxproj") {
- print_line("parse pbxproj");
- _fix_config_file(p_preset, data, pkg_name, binary_name);
- } else if (file == "godot_ios/godot_ios-Info.plist") {
- print_line("parse plist");
- _fix_config_file(p_preset, data, pkg_name, binary_name);
+ if (files_to_parse.has(file)) {
+ print_line(String("parse ") + file);
+ _fix_config_file(p_preset, data, pkg_name, binary_name, p_debug);
} else if (file.begins_with("godot.iphone")) {
if (file != binary_to_use) {
ret = unzGoToNextFile(src_pkg_zip);
@@ -264,6 +526,7 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p
if (dir_err) {
ERR_PRINTS("Can't create '" + dir_name + "'.");
unzClose(src_pkg_zip);
+ memdelete(tmp_app_path);
return ERR_CANT_CREATE;
}
}
@@ -273,6 +536,7 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p
if (!f) {
ERR_PRINTS("Can't write '" + file + "'.");
unzClose(src_pkg_zip);
+ memdelete(tmp_app_path);
return ERR_CANT_CREATE;
};
f->store_buffer(data.ptr(), data.size());
@@ -295,26 +559,79 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p
if (!found_binary) {
ERR_PRINTS("Requested template binary '" + binary_to_use + "' not found. It might be missing from your template archive.");
- unzClose(src_pkg_zip);
+ memdelete(tmp_app_path);
return ERR_FILE_NOT_FOUND;
}
- ep.step("Making PKG", 1);
+ String iconset_dir = dest_dir + binary_name + "/Images.xcassets/AppIcon.appiconset/";
+ Error err = OK;
+ if (!tmp_app_path->dir_exists(iconset_dir)) {
+ Error err = tmp_app_path->make_dir_recursive(iconset_dir);
+ }
+ memdelete(tmp_app_path);
+ if (err)
+ return err;
+
+ err = _export_icons(p_preset, iconset_dir);
+ if (err)
+ return err;
+
+ err = _export_loading_screens(p_preset, dest_dir + binary_name + "/");
+ if (err)
+ return err;
+
+ ep.step("Making .pck", 1);
String pack_path = dest_dir + binary_name + ".pck";
- Error err = save_pack(p_preset, pack_path);
+ err = save_pack(p_preset, pack_path);
+ if (err)
+ return err;
- if (err) {
+ err = export_project_files(p_preset, _export_dylibs, &dest_dir);
+ if (err)
return err;
- }
#ifdef OSX_ENABLED
- /* and open up xcode with our new project.... */
- List<String> args;
- args.push_back(p_path);
- err = OS::get_singleton()->execute("/usr/bin/open", args, false);
+ ep.step("Code-signing dylibs", 2);
+ DirAccess *dylibs_dir = DirAccess::open(dest_dir + "dylibs");
+ ERR_FAIL_COND_V(!dylibs_dir, ERR_CANT_OPEN);
+ CodesignData codesign_data(p_preset, p_debug);
+ err = _walk_dir_recursive(dylibs_dir, _codesign, &codesign_data);
+ memdelete(dylibs_dir);
ERR_FAIL_COND_V(err, err);
+ ep.step("Making .xcarchive", 3);
+ String archive_path = p_path.get_basename() + ".xcarchive";
+ List<String> archive_args;
+ archive_args.push_back("-project");
+ archive_args.push_back(dest_dir + binary_name + ".xcodeproj");
+ archive_args.push_back("-scheme");
+ archive_args.push_back(binary_name);
+ archive_args.push_back("-sdk");
+ archive_args.push_back("iphoneos");
+ archive_args.push_back("-configuration");
+ archive_args.push_back(p_debug ? "Debug" : "Release");
+ archive_args.push_back("-destination");
+ archive_args.push_back("generic/platform=iOS");
+ archive_args.push_back("archive");
+ archive_args.push_back("-archivePath");
+ archive_args.push_back(archive_path);
+ err = OS::get_singleton()->execute("xcodebuild", archive_args, true);
+ ERR_FAIL_COND_V(err, err);
+
+ ep.step("Making .ipa", 4);
+ List<String> export_args;
+ export_args.push_back("-exportArchive");
+ export_args.push_back("-archivePath");
+ export_args.push_back(archive_path);
+ export_args.push_back("-exportOptionsPlist");
+ export_args.push_back(dest_dir + "export_options.plist");
+ export_args.push_back("-exportPath");
+ export_args.push_back(dest_dir);
+ err = OS::get_singleton()->execute("xcodebuild", export_args, true);
+ ERR_FAIL_COND_V(err, err);
+#else
+ print_line(".ipa can only be built on macOS. Leaving XCode project without building the package.");
#endif
return OK;
diff --git a/platform/iphone/game_center.h b/platform/iphone/game_center.h
index c0a7830fe9..21f40fa362 100644
--- a/platform/iphone/game_center.h
+++ b/platform/iphone/game_center.h
@@ -43,11 +43,13 @@ class GameCenter : public Object {
List<Variant> pending_events;
- bool connected;
+ bool authenticated;
+
+ void return_connect_error(const char *p_error_description);
public:
- Error connect();
- bool is_connected();
+ void connect();
+ bool is_authenticated();
Error post_score(Variant p_score);
Error award_achievement(Variant p_params);
@@ -55,6 +57,7 @@ public:
void request_achievements();
void request_achievement_descriptions();
Error show_game_center(Variant p_params);
+ Error request_identity_verification_signature();
void game_center_closed();
diff --git a/platform/iphone/game_center.mm b/platform/iphone/game_center.mm
index c05bdea005..531b80eee3 100644
--- a/platform/iphone/game_center.mm
+++ b/platform/iphone/game_center.mm
@@ -49,8 +49,7 @@ extern "C" {
GameCenter *GameCenter::instance = NULL;
void GameCenter::_bind_methods() {
- ClassDB::bind_method(D_METHOD("connect"), &GameCenter::connect);
- ClassDB::bind_method(D_METHOD("is_connected"), &GameCenter::is_connected);
+ ClassDB::bind_method(D_METHOD("is_authenticated"), &GameCenter::is_authenticated);
ClassDB::bind_method(D_METHOD("post_score"), &GameCenter::post_score);
ClassDB::bind_method(D_METHOD("award_achievement"), &GameCenter::award_achievement);
@@ -58,24 +57,41 @@ void GameCenter::_bind_methods() {
ClassDB::bind_method(D_METHOD("request_achievements"), &GameCenter::request_achievements);
ClassDB::bind_method(D_METHOD("request_achievement_descriptions"), &GameCenter::request_achievement_descriptions);
ClassDB::bind_method(D_METHOD("show_game_center"), &GameCenter::show_game_center);
+ ClassDB::bind_method(D_METHOD("request_identity_verification_signature"), &GameCenter::request_identity_verification_signature);
ClassDB::bind_method(D_METHOD("get_pending_event_count"), &GameCenter::get_pending_event_count);
ClassDB::bind_method(D_METHOD("pop_pending_event"), &GameCenter::pop_pending_event);
};
-Error GameCenter::connect() {
+void GameCenter::return_connect_error(const char *p_error_description) {
+ authenticated = false;
+ Dictionary ret;
+ ret["type"] = "authentication";
+ ret["result"] = "error";
+ ret["error_code"] = 0;
+ ret["error_description"] = p_error_description;
+ pending_events.push_back(ret);
+}
+
+void GameCenter::connect() {
//if this class isn't available, game center isn't implemented
if ((NSClassFromString(@"GKLocalPlayer")) == nil) {
- GameCenter::get_singleton()->connected = false;
- return ERR_UNAVAILABLE;
+ return_connect_error("GameCenter not available");
+ return;
}
GKLocalPlayer *player = [GKLocalPlayer localPlayer];
- ERR_FAIL_COND_V(![player respondsToSelector:@selector(authenticateHandler)], ERR_UNAVAILABLE);
+ if (![player respondsToSelector:@selector(authenticateHandler)]) {
+ return_connect_error("GameCenter doesn't respond to 'authenticateHandler'");
+ return;
+ }
ViewController *root_controller = (ViewController *)((AppDelegate *)[[UIApplication sharedApplication] delegate]).window.rootViewController;
- ERR_FAIL_COND_V(!root_controller, FAILED);
+ if (!root_controller) {
+ return_connect_error("Window doesn't have root ViewController");
+ return;
+ }
// This handler is called several times. First when the view needs to be shown, then again
// after the view is cancelled or the user logs in. Or if the user's already logged in, it's
@@ -89,23 +105,22 @@ Error GameCenter::connect() {
ret["type"] = "authentication";
if (player.isAuthenticated) {
ret["result"] = "ok";
- GameCenter::get_singleton()->connected = true;
+ ret["player_id"] = [player.playerID UTF8String];
+ GameCenter::get_singleton()->authenticated = true;
} else {
ret["result"] = "error";
ret["error_code"] = error.code;
ret["error_description"] = [error.localizedDescription UTF8String];
- GameCenter::get_singleton()->connected = false;
+ GameCenter::get_singleton()->authenticated = false;
};
pending_events.push_back(ret);
};
});
-
- return OK;
};
-bool GameCenter::is_connected() {
- return connected;
+bool GameCenter::is_authenticated() {
+ return authenticated;
};
Error GameCenter::post_score(Variant p_score) {
@@ -116,7 +131,7 @@ Error GameCenter::post_score(Variant p_score) {
String category = params["category"];
NSString *cat_str = [[[NSString alloc] initWithUTF8String:category.utf8().get_data()] autorelease];
- GKScore *reporter = [[[GKScore alloc] initWithCategory:cat_str] autorelease];
+ GKScore *reporter = [[[GKScore alloc] initWithLeaderboardIdentifier:cat_str] autorelease];
reporter.value = score;
ERR_FAIL_COND_V([GKScore respondsToSelector:@selector(reportScores)], ERR_UNAVAILABLE);
@@ -325,6 +340,34 @@ Error GameCenter::show_game_center(Variant p_params) {
return OK;
};
+Error GameCenter::request_identity_verification_signature() {
+
+ ERR_FAIL_COND_V(!is_authenticated(), ERR_UNAUTHORIZED);
+
+ GKLocalPlayer *player = [GKLocalPlayer localPlayer];
+ [player generateIdentityVerificationSignatureWithCompletionHandler:^(NSURL *publicKeyUrl, NSData *signature, NSData *salt, uint64_t timestamp, NSError *error) {
+
+ Dictionary ret;
+ ret["type"] = "identity_verification_signature";
+ if (error == nil) {
+ ret["result"] = "ok";
+ ret["public_key_url"] = [publicKeyUrl.absoluteString UTF8String];
+ ret["signature"] = [[signature base64EncodedStringWithOptions:0] UTF8String];
+ ret["salt"] = [[salt base64EncodedStringWithOptions:0] UTF8String];
+ ret["timestamp"] = timestamp;
+ ret["player_id"] = [player.playerID UTF8String];
+ } else {
+ ret["result"] = "error";
+ ret["error_code"] = error.code;
+ ret["error_description"] = [error.localizedDescription UTF8String];
+ };
+
+ pending_events.push_back(ret);
+ }];
+
+ return OK;
+};
+
void GameCenter::game_center_closed() {
Dictionary ret;
@@ -353,7 +396,7 @@ GameCenter *GameCenter::get_singleton() {
GameCenter::GameCenter() {
ERR_FAIL_COND(instance != NULL);
instance = this;
- connected = false;
+ authenticated = false;
};
GameCenter::~GameCenter(){};
diff --git a/platform/iphone/gl_view.h b/platform/iphone/gl_view.h
index a9fd8d5711..f7309396c6 100644
--- a/platform/iphone/gl_view.h
+++ b/platform/iphone/gl_view.h
@@ -100,6 +100,8 @@
- (void)destroyFramebuffer;
- (void)audioRouteChangeListenerCallback:(NSNotification *)notification;
+- (void)keyboardOnScreen:(NSNotification *)notification;
+- (void)keyboardHidden:(NSNotification *)notification;
@property NSTimeInterval animationInterval;
@property(nonatomic, assign) BOOL useCADisplayLink;
diff --git a/platform/iphone/gl_view.mm b/platform/iphone/gl_view.mm
index 3e206c3a2c..02da706cc5 100644
--- a/platform/iphone/gl_view.mm
+++ b/platform/iphone/gl_view.mm
@@ -63,6 +63,7 @@ void _pause_video();
void _focus_out_video();
void _unpause_video();
void _stop_video();
+CGFloat _points_to_pixels(CGFloat);
void _show_keyboard(String p_existing) {
keyboard_text = p_existing;
@@ -174,6 +175,19 @@ void _stop_video() {
video_playing = false;
}
+CGFloat _points_to_pixels(CGFloat points) {
+ float pixelPerInch;
+ if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+ pixelPerInch = 132;
+ } else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
+ pixelPerInch = 163;
+ } else {
+ pixelPerInch = 160;
+ }
+ CGFloat pointsPerInch = 72.0;
+ return (points / pointsPerInch * pixelPerInch);
+}
+
@implementation GLView
@synthesize animationInterval;
@@ -537,6 +551,20 @@ static void clear_touches() {
[self resignFirstResponder];
};
+- (void)keyboardOnScreen:(NSNotification *)notification {
+ NSDictionary *info = notification.userInfo;
+ NSValue *value = info[UIKeyboardFrameEndUserInfoKey];
+
+ CGRect rawFrame = [value CGRectValue];
+ CGRect keyboardFrame = [self convertRect:rawFrame fromView:nil];
+
+ OSIPhone::get_singleton()->set_virtual_keyboard_height(_points_to_pixels(keyboardFrame.size.height));
+}
+
+- (void)keyboardHidden:(NSNotification *)notification {
+ OSIPhone::get_singleton()->set_virtual_keyboard_height(0);
+}
+
- (void)deleteBackward {
if (keyboard_text.length())
keyboard_text.erase(keyboard_text.length() - 1, 1);
@@ -606,6 +634,18 @@ static void clear_touches() {
name:AVAudioSessionRouteChangeNotification
object:nil];
+ printf("******** adding observer for keyboard show/hide\n");
+ [[NSNotificationCenter defaultCenter]
+ addObserver:self
+ selector:@selector(keyboardOnScreen:)
+ name:UIKeyboardDidShowNotification
+ object:nil];
+ [[NSNotificationCenter defaultCenter]
+ addObserver:self
+ selector:@selector(keyboardHidden:)
+ name:UIKeyboardDidHideNotification
+ object:nil];
+
//self.autoresizesSubviews = YES;
//[self setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth];
diff --git a/platform/iphone/godot_iphone.cpp b/platform/iphone/godot_iphone.cpp
index 8c6d6d8da4..7d21d35e18 100644
--- a/platform/iphone/godot_iphone.cpp
+++ b/platform/iphone/godot_iphone.cpp
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "main/main.h"
#include "os_iphone.h"
+#include "ustring.h"
#include <stdio.h>
#include <string.h>
@@ -41,9 +42,9 @@ int add_path(int p_argc, char **p_args);
int add_cmdline(int p_argc, char **p_args);
};
-int iphone_main(int, int, int, char **);
+int iphone_main(int, int, int, char **, String);
-int iphone_main(int width, int height, int argc, char **argv) {
+int iphone_main(int width, int height, int argc, char **argv, String data_dir) {
int len = strlen(argv[0]);
@@ -63,7 +64,7 @@ int iphone_main(int width, int height, int argc, char **argv) {
char cwd[512];
getcwd(cwd, sizeof(cwd));
printf("cwd %s\n", cwd);
- os = new OSIPhone(width, height);
+ os = new OSIPhone(width, height, data_dir);
char *fargv[64];
for (int i = 0; i < argc; i++) {
diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp
index 0e3eeed114..13e3b7670a 100644
--- a/platform/iphone/os_iphone.cpp
+++ b/platform/iphone/os_iphone.cpp
@@ -35,13 +35,13 @@
#include "servers/visual/visual_server_raster.h"
//#include "servers/visual/visual_server_wrap_mt.h"
-#include "audio_driver_iphone.h"
#include "main/main.h"
#include "core/io/file_access_pack.h"
#include "core/os/dir_access.h"
#include "core/os/file_access.h"
#include "core/project_settings.h"
+#include "drivers/unix/syslog_logger.h"
#include "sem_iphone.h"
@@ -97,8 +97,19 @@ void OSIPhone::initialize_core() {
OS_Unix::initialize_core();
SemaphoreIphone::make_default();
+
+ set_data_dir(data_dir);
};
+void OSIPhone::initialize_logger() {
+ Vector<Logger *> loggers;
+ loggers.push_back(memnew(SyslogLogger));
+ // FIXME: Reenable once we figure out how to get this properly in user://
+ // instead of littering the user's working dirs (res:// + pwd) with log files (GH-12277)
+ //loggers.push_back(memnew(RotatedFileLogger("user://logs/log.txt")));
+ _set_logger(memnew(CompositeLogger(loggers)));
+}
+
void OSIPhone::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
supported_orientations = 0;
@@ -124,16 +135,8 @@ void OSIPhone::initialize(const VideoMode &p_desired, int p_video_driver, int p_
// reset this to what it should be, it will have been set to 0 after visual_server->init() is called
RasterizerStorageGLES3::system_fbo = gl_view_base_fb;
- audio_driver = memnew(AudioDriverIphone);
- audio_driver->set_singleton();
- audio_driver->init();
-
- // init physics servers
- physics_server = memnew(PhysicsServerSW);
- physics_server->init();
- //physics_2d_server = memnew( Physics2DServerSW );
- physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>();
- physics_2d_server->init();
+ AudioDriverManager::add_driver(&audio_driver);
+ AudioDriverManager::initialize(p_audio_driver);
input = memnew(InputDefault);
@@ -374,12 +377,6 @@ void OSIPhone::finalize() {
memdelete(visual_server);
// memdelete(rasterizer);
- physics_server->finish();
- memdelete(physics_server);
-
- physics_2d_server->finish();
- memdelete(physics_2d_server);
-
memdelete(input);
};
@@ -457,6 +454,14 @@ void OSIPhone::hide_virtual_keyboard() {
_hide_keyboard();
};
+void OSIPhone::set_virtual_keyboard_height(int p_height) {
+ virtual_keyboard_height = p_height;
+}
+
+int OSIPhone::get_virtual_keyboard_height() const {
+ return virtual_keyboard_height;
+}
+
Error OSIPhone::shell_open(String p_uri) {
return _shell_open(p_uri);
};
@@ -558,7 +563,7 @@ bool OSIPhone::_check_internal_feature_support(const String &p_feature) {
return p_feature == "mobile" || p_feature == "etc" || p_feature == "pvrtc" || p_feature == "etc2";
}
-OSIPhone::OSIPhone(int width, int height) {
+OSIPhone::OSIPhone(int width, int height, String p_data_dir) {
main_loop = NULL;
visual_server = NULL;
@@ -570,6 +575,13 @@ OSIPhone::OSIPhone(int width, int height) {
vm.resizable = false;
set_video_mode(vm);
event_count = 0;
+ virtual_keyboard_height = 0;
+
+ // can't call set_data_dir from here, since it requires DirAccess
+ // which is initialized in initialize_core
+ data_dir = p_data_dir;
+
+ _set_logger(memnew(SyslogLogger));
};
OSIPhone::~OSIPhone() {
diff --git a/platform/iphone/os_iphone.h b/platform/iphone/os_iphone.h
index 475dceebf2..eccd294d63 100644
--- a/platform/iphone/os_iphone.h
+++ b/platform/iphone/os_iphone.h
@@ -32,6 +32,7 @@
#ifndef OS_IPHONE_H
#define OS_IPHONE_H
+#include "drivers/coreaudio/audio_driver_coreaudio.h"
#include "drivers/unix/os_unix.h"
#include "os/input.h"
@@ -40,14 +41,9 @@
#include "in_app_store.h"
#include "main/input_default.h"
#include "servers/audio_server.h"
-#include "servers/physics/physics_server_sw.h"
-#include "servers/physics_2d/physics_2d_server_sw.h"
-#include "servers/physics_2d/physics_2d_server_wrap_mt.h"
#include "servers/visual/rasterizer.h"
#include "servers/visual_server.h"
-class AudioDriverIphone;
-
class OSIPhone : public OS_Unix {
public:
@@ -67,10 +63,8 @@ private:
uint8_t supported_orientations;
VisualServer *visual_server;
- PhysicsServer *physics_server;
- Physics2DServer *physics_2d_server;
- AudioDriverIphone *audio_driver;
+ AudioDriverCoreAudio audio_driver;
#ifdef GAME_CENTER_ENABLED
GameCenter *game_center;
@@ -91,6 +85,7 @@ private:
virtual VideoMode get_default_video_mode() const;
+ virtual void initialize_logger();
virtual void initialize_core();
virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
@@ -124,6 +119,8 @@ private:
InputDefault *input;
+ int virtual_keyboard_height;
+
public:
bool iterate();
@@ -133,6 +130,7 @@ public:
void mouse_move(int p_idx, int p_prev_x, int p_prev_y, int p_x, int p_y, bool p_use_as_mouse);
void touches_cancelled();
void key(uint32_t p_key, bool p_pressed);
+ void set_virtual_keyboard_height(int p_height);
int set_base_framebuffer(int p_fb);
@@ -168,6 +166,7 @@ public:
virtual bool has_virtual_keyboard() const;
virtual void show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2());
virtual void hide_virtual_keyboard();
+ virtual int get_virtual_keyboard_height() const;
virtual void set_cursor_shape(CursorShape p_shape);
@@ -197,7 +196,7 @@ public:
virtual void native_video_stop();
virtual bool _check_internal_feature_support(const String &p_feature);
- OSIPhone(int width, int height);
+ OSIPhone(int width, int height, String p_data_dir);
~OSIPhone();
};
diff --git a/platform/javascript/SCsub b/platform/javascript/SCsub
index e282041745..cfc0741318 100644
--- a/platform/javascript/SCsub
+++ b/platform/javascript/SCsub
@@ -6,7 +6,6 @@ javascript_files = [
"os_javascript.cpp",
"audio_driver_javascript.cpp",
"javascript_main.cpp",
- "audio_server_javascript.cpp",
"power_javascript.cpp",
"javascript_eval.cpp",
]
@@ -19,7 +18,7 @@ javascript_objects = []
for x in javascript_files:
javascript_objects.append(env_javascript.Object(x))
-env.Append(LINKFLAGS=["-s", "EXPORTED_FUNCTIONS=\"['_main','_audio_server_mix_function','_main_after_fs_sync','_send_notification']\""])
+env.Append(LINKFLAGS=["-s", "EXPORTED_FUNCTIONS=\"['_main','_main_after_fs_sync','_send_notification']\""])
# output file name without file extension
basename = "godot" + env["PROGSUFFIX"]
@@ -29,7 +28,7 @@ zip_dir = target_dir.Dir('.javascript_zip')
zip_files = env.InstallAs(zip_dir.File('godot.html'), '#misc/dist/html/default.html')
implicit_targets = []
-if env['wasm'] == 'yes':
+if env['wasm']:
wasm = target_dir.File(basename + '.wasm')
implicit_targets.append(wasm)
zip_files.append(InstallAs(zip_dir.File('godot.wasm'), wasm))
diff --git a/platform/javascript/audio_driver_javascript.cpp b/platform/javascript/audio_driver_javascript.cpp
index 4c0e5fd966..9633472cd2 100644
--- a/platform/javascript/audio_driver_javascript.cpp
+++ b/platform/javascript/audio_driver_javascript.cpp
@@ -29,31 +29,86 @@
/*************************************************************************/
#include "audio_driver_javascript.h"
-#include <string.h>
+#include <emscripten.h>
-#define MAX_NUMBER_INTERFACES 3
-#define MAX_NUMBER_OUTPUT_DEVICES 6
-
-/* Structure for passing information to callback function */
-
-//AudioDriverJavaScript* AudioDriverJavaScript::s_ad=NULL;
+AudioDriverJavaScript *AudioDriverJavaScript::singleton_js = NULL;
const char *AudioDriverJavaScript::get_name() const {
return "JavaScript";
}
+extern "C" EMSCRIPTEN_KEEPALIVE void js_audio_driver_mix_function(int p_frames) {
+
+ //print_line("MIXI! "+itos(p_frames));
+ AudioDriverJavaScript::singleton_js->mix_to_js(p_frames);
+}
+
+void AudioDriverJavaScript::mix_to_js(int p_frames) {
+
+ int todo = p_frames;
+ int offset = 0;
+
+ while (todo) {
+
+ int tomix = MIN(todo, INTERNAL_BUFFER_SIZE);
+
+ audio_server_process(p_frames, stream_buffer);
+ for (int i = 0; i < tomix * internal_buffer_channels; i++) {
+ internal_buffer[i] = float(stream_buffer[i] >> 16) / 32768.0;
+ }
+
+ /* clang-format off */
+ EM_ASM_ARGS({
+ var data = HEAPF32.subarray($0 / 4, $0 / 4 + $2 * 2);
+
+ for (var channel = 0; channel < _as_output_buffer.numberOfChannels; channel++) {
+ var outputData = _as_output_buffer.getChannelData(channel);
+ // Loop through samples
+ for (var sample = 0; sample < $2; sample++) {
+ // make output equal to the same as the input
+ outputData[sample + $1] = data[sample * 2 + channel];
+ }
+ }
+ }, internal_buffer, offset, tomix);
+ /* clang-format on */
+
+ todo -= tomix;
+ offset += tomix;
+ }
+}
+
Error AudioDriverJavaScript::init() {
return OK;
}
void AudioDriverJavaScript::start() {
+
+ internal_buffer = memnew_arr(float, INTERNAL_BUFFER_SIZE *internal_buffer_channels);
+ stream_buffer = memnew_arr(int32_t, INTERNAL_BUFFER_SIZE * 4); //max 4 channels
+
+ /* clang-format off */
+ mix_rate = EM_ASM_INT({
+ _as_audioctx = new (window.AudioContext || window.webkitAudioContext);
+ _as_script_node = _as_audioctx.createScriptProcessor($0, 0, $1);
+ _as_script_node.connect(_as_audioctx.destination);
+ console.log(_as_script_node.bufferSize);
+ var jsAudioDriverMixFunction = cwrap('js_audio_driver_mix_function', null, ['number']);
+
+ _as_script_node.onaudioprocess = function(audioProcessingEvent) {
+ // The output buffer contains the samples that will be modified and played
+ _as_output_buffer = audioProcessingEvent.outputBuffer;
+ jsAudioDriverMixFunction([_as_output_buffer.getChannelData(0).length]);
+ };
+ return _as_audioctx.sampleRate;
+ }, INTERNAL_BUFFER_SIZE, internal_buffer_channels);
+ /* clang-format on */
}
int AudioDriverJavaScript::get_mix_rate() const {
- return 44100;
+ return mix_rate;
}
AudioDriver::SpeakerMode AudioDriverJavaScript::get_speaker_mode() const {
@@ -63,7 +118,7 @@ AudioDriver::SpeakerMode AudioDriverJavaScript::get_speaker_mode() const {
void AudioDriverJavaScript::lock() {
- /*
+ /*no locking, as threads are not supported
if (active && mutex)
mutex->lock();
*/
@@ -71,7 +126,7 @@ void AudioDriverJavaScript::lock() {
void AudioDriverJavaScript::unlock() {
- /*
+ /*no locking, as threads are not supported
if (active && mutex)
mutex->unlock();
*/
@@ -81,4 +136,8 @@ void AudioDriverJavaScript::finish() {
}
AudioDriverJavaScript::AudioDriverJavaScript() {
+
+ internal_buffer_channels = 2;
+ mix_rate = DEFAULT_MIX_RATE;
+ singleton_js = this;
}
diff --git a/platform/javascript/audio_driver_javascript.h b/platform/javascript/audio_driver_javascript.h
index c5cebe800f..b265c4e030 100644
--- a/platform/javascript/audio_driver_javascript.h
+++ b/platform/javascript/audio_driver_javascript.h
@@ -32,10 +32,21 @@
#include "servers/audio_server.h"
-#include "os/mutex.h"
-
class AudioDriverJavaScript : public AudioDriver {
+
+ enum {
+ INTERNAL_BUFFER_SIZE = 4096,
+ };
+
+ int mix_rate;
+ float *internal_buffer;
+ int internal_buffer_channels;
+ int32_t *stream_buffer;
+
public:
+ void mix_to_js(int p_frames);
+ static AudioDriverJavaScript *singleton_js;
+
virtual const char *get_name() const;
virtual Error init();
diff --git a/platform/javascript/audio_server_javascript.cpp b/platform/javascript/audio_server_javascript.cpp
deleted file mode 100644
index ab9f66ce5b..0000000000
--- a/platform/javascript/audio_server_javascript.cpp
+++ /dev/null
@@ -1,853 +0,0 @@
-/*************************************************************************/
-/* audio_server_javascript.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#include "audio_server_javascript.h"
-
-// FIXME: Needs to be ported to the new AudioServer API in 3.0
-#if 0
-#include "emscripten.h"
-
-AudioMixer *AudioServerJavascript::get_mixer() {
-
- return NULL;
-}
-
-void AudioServerJavascript::audio_mixer_chunk_callback(int p_frames){
-
-
-}
-
-
-RID AudioServerJavascript::sample_create(SampleFormat p_format, bool p_stereo, int p_length) {
-
- Sample *sample = memnew( Sample );
- sample->format=p_format;
- sample->stereo=p_stereo;
- sample->length=p_length;
- sample->loop_begin=0;
- sample->loop_end=p_length;
- sample->loop_format=SAMPLE_LOOP_NONE;
- sample->mix_rate=44100;
- sample->index=-1;
-
- return sample_owner.make_rid(sample);
-
-}
-
-void AudioServerJavascript::sample_set_description(RID p_sample, const String& p_description){
-
-
-}
-String AudioServerJavascript::sample_get_description(RID p_sample) const{
-
- return String();
-}
-
-AudioServerJavascript::SampleFormat AudioServerJavascript::sample_get_format(RID p_sample) const{
-
- return SAMPLE_FORMAT_PCM8;
-}
-bool AudioServerJavascript::sample_is_stereo(RID p_sample) const{
-
- const Sample *sample = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!sample,false);
- return sample->stereo;
-
-}
-int AudioServerJavascript::sample_get_length(RID p_sample) const{
- const Sample *sample = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!sample,0);
- return sample->length;
-}
-const void* AudioServerJavascript::sample_get_data_ptr(RID p_sample) const{
-
- return NULL;
-}
-
-void AudioServerJavascript::sample_set_data(RID p_sample, const PoolVector<uint8_t>& p_buffer){
-
- Sample *sample = sample_owner.get(p_sample);
- ERR_FAIL_COND(!sample);
- int chans = sample->stereo?2:1;
-
- Vector<float> buffer;
- buffer.resize(sample->length*chans);
- PoolVector<uint8_t>::Read r=p_buffer.read();
- if (sample->format==SAMPLE_FORMAT_PCM8) {
- const int8_t*ptr = (const int8_t*)r.ptr();
- for(int i=0;i<sample->length*chans;i++) {
- buffer[i]=ptr[i]/128.0;
- }
- } else if (sample->format==SAMPLE_FORMAT_PCM16){
- const int16_t*ptr = (const int16_t*)r.ptr();
- for(int i=0;i<sample->length*chans;i++) {
- buffer[i]=ptr[i]/32768.0;
- }
- } else {
- ERR_EXPLAIN("Unsupported for now");
- ERR_FAIL();
- }
-
- sample->tmp_data=buffer;
-
-
-
-}
-PoolVector<uint8_t> AudioServerJavascript::sample_get_data(RID p_sample) const{
-
-
- return PoolVector<uint8_t>();
-}
-
-void AudioServerJavascript::sample_set_mix_rate(RID p_sample,int p_rate){
- Sample *sample = sample_owner.get(p_sample);
- ERR_FAIL_COND(!sample);
- sample->mix_rate=p_rate;
-
-}
-
-int AudioServerJavascript::sample_get_mix_rate(RID p_sample) const{
- const Sample *sample = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!sample,0);
- return sample->mix_rate;
-}
-
-
-void AudioServerJavascript::sample_set_loop_format(RID p_sample,SampleLoopFormat p_format){
-
- Sample *sample = sample_owner.get(p_sample);
- ERR_FAIL_COND(!sample);
- sample->loop_format=p_format;
-
-}
-
-AudioServerJavascript::SampleLoopFormat AudioServerJavascript::sample_get_loop_format(RID p_sample) const {
-
- const Sample *sample = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!sample,SAMPLE_LOOP_NONE);
- return sample->loop_format;
-}
-
-void AudioServerJavascript::sample_set_loop_begin(RID p_sample,int p_pos){
-
- Sample *sample = sample_owner.get(p_sample);
- ERR_FAIL_COND(!sample);
- sample->loop_begin=p_pos;
-
-}
-int AudioServerJavascript::sample_get_loop_begin(RID p_sample) const{
-
- const Sample *sample = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!sample,0);
- return sample->loop_begin;
-}
-
-void AudioServerJavascript::sample_set_loop_end(RID p_sample,int p_pos){
-
- Sample *sample = sample_owner.get(p_sample);
- ERR_FAIL_COND(!sample);
- sample->loop_end=p_pos;
-
-}
-int AudioServerJavascript::sample_get_loop_end(RID p_sample) const{
-
- const Sample *sample = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!sample,0);
- return sample->loop_end;
-}
-
-
-/* VOICE API */
-
-RID AudioServerJavascript::voice_create(){
-
- Voice *voice = memnew( Voice );
-
- voice->index=voice_base;
- voice->volume=1.0;
- voice->pan=0.0;
- voice->pan_depth=.0;
- voice->pan_height=0.0;
- voice->chorus=0;
- voice->reverb_type=REVERB_SMALL;
- voice->reverb=0;
- voice->mix_rate=-1;
- voice->positional=false;
- voice->active=false;
-
- /* clang-format off */
- EM_ASM_( {
- _as_voices[$0] = null;
- _as_voice_gain[$0] = _as_audioctx.createGain();
- _as_voice_pan[$0] = _as_audioctx.createStereoPanner();
- _as_voice_gain[$0].connect(_as_voice_pan[$0]);
- _as_voice_pan[$0].connect(_as_audioctx.destination);
- }, voice_base);
- /* clang-format on */
-
- voice_base++;
-
- return voice_owner.make_rid( voice );
-}
-
-void AudioServerJavascript::voice_play(RID p_voice, RID p_sample){
-
- Voice* voice=voice_owner.get(p_voice);
- ERR_FAIL_COND(!voice);
- Sample *sample=sample_owner.get(p_sample);
- ERR_FAIL_COND(!sample);
-
- // due to how webaudio works, sample cration is deferred until used
- // sorry! WebAudio absolutely sucks
-
-
- if (sample->index==-1) {
- //create sample if not created
- ERR_FAIL_COND(sample->tmp_data.size()==0);
- sample->index=sample_base;
- /* clang-format off */
- EM_ASM_({
- _as_samples[$0] = _as_audioctx.createBuffer($1, $2, $3);
- }, sample_base, sample->stereo ? 2 : 1, sample->length, sample->mix_rate);
- /* clang-format on */
-
- sample_base++;
- int chans = sample->stereo?2:1;
-
-
- for(int i=0;i<chans;i++) {
- /* clang-format off */
- EM_ASM_({
- _as_edited_buffer = _as_samples[$0].getChannelData($1);
- }, sample->index, i);
- /* clang-format on */
-
- for(int j=0;j<sample->length;j++) {
- /* clang-format off */
- EM_ASM_({
- _as_edited_buffer[$0] = $1;
- }, j, sample->tmp_data[j * chans + i]);
- /* clang-format on */
- }
- }
-
- sample->tmp_data.clear();
- }
-
-
- voice->sample_mix_rate=sample->mix_rate;
- if (voice->mix_rate==-1) {
- voice->mix_rate=voice->sample_mix_rate;
- }
-
- float freq_diff = Math::log(float(voice->mix_rate)/float(voice->sample_mix_rate))/Math::log(2.0);
- int detune = int(freq_diff*1200.0);
-
- /* clang-format off */
- EM_ASM_({
- if (_as_voices[$0] !== null) {
- _as_voices[$0].stop(); //stop and byebye
- }
- _as_voices[$0] = _as_audioctx.createBufferSource();
- _as_voices[$0].connect(_as_voice_gain[$0]);
- _as_voices[$0].buffer = _as_samples[$1];
- _as_voices[$0].loopStart.value = $1;
- _as_voices[$0].loopEnd.value = $2;
- _as_voices[$0].loop.value = $3;
- _as_voices[$0].detune.value = $6;
- _as_voice_pan[$0].pan.value = $4;
- _as_voice_gain[$0].gain.value = $5;
- _as_voices[$0].start();
- _as_voices[$0].onended = function() {
- _as_voices[$0].disconnect(_as_voice_gain[$0]);
- _as_voices[$0] = null;
- }
- }, voice->index, sample->index, sample->mix_rate * sample->loop_begin, sample->mix_rate * sample->loop_end, sample->loop_format != SAMPLE_LOOP_NONE, voice->pan, voice->volume * fx_volume_scale, detune);
- /* clang-format on */
-
- voice->active=true;
-}
-
-void AudioServerJavascript::voice_set_volume(RID p_voice, float p_volume){
-
- Voice* voice=voice_owner.get(p_voice);
- ERR_FAIL_COND(!voice);
-
- voice->volume=p_volume;
-
- if (voice->active) {
- /* clang-format off */
- EM_ASM_({
- _as_voice_gain[$0].gain.value = $1;
- }, voice->index, voice->volume * fx_volume_scale);
- /* clang-format on */
- }
-
-}
-void AudioServerJavascript::voice_set_pan(RID p_voice, float p_pan, float p_depth,float height){
-
- Voice* voice=voice_owner.get(p_voice);
- ERR_FAIL_COND(!voice);
-
- voice->pan=p_pan;
- voice->pan_depth=p_depth;
- voice->pan_height=height;
-
- if (voice->active) {
- /* clang-format off */
- EM_ASM_({
- _as_voice_pan[$0].pan.value = $1;
- }, voice->index, voice->pan);
- /* clang-format on */
- }
-}
-void AudioServerJavascript::voice_set_filter(RID p_voice, FilterType p_type, float p_cutoff, float p_resonance, float p_gain){
-
-}
-void AudioServerJavascript::voice_set_chorus(RID p_voice, float p_chorus ){
-
-}
-void AudioServerJavascript::voice_set_reverb(RID p_voice, ReverbRoomType p_room_type, float p_reverb){
-
-}
-void AudioServerJavascript::voice_set_mix_rate(RID p_voice, int p_mix_rate){
-
- Voice* voice=voice_owner.get(p_voice);
- ERR_FAIL_COND(!voice);
-
- voice->mix_rate=p_mix_rate;
-
- if (voice->active) {
-
- float freq_diff = Math::log(float(voice->mix_rate)/float(voice->sample_mix_rate))/Math::log(2.0);
- int detune = int(freq_diff*1200.0);
- /* clang-format off */
- EM_ASM_({
- _as_voices[$0].detune.value = $1;
- }, voice->index, detune);
- /* clang-format on */
- }
-}
-void AudioServerJavascript::voice_set_positional(RID p_voice, bool p_positional){
-
-}
-
-float AudioServerJavascript::voice_get_volume(RID p_voice) const{
-
- Voice* voice=voice_owner.get(p_voice);
- ERR_FAIL_COND_V(!voice,0);
-
- return voice->volume;
-}
-float AudioServerJavascript::voice_get_pan(RID p_voice) const{
-
- Voice* voice=voice_owner.get(p_voice);
- ERR_FAIL_COND_V(!voice,0);
-
- return voice->pan;
-}
-float AudioServerJavascript::voice_get_pan_depth(RID p_voice) const{
- Voice* voice=voice_owner.get(p_voice);
- ERR_FAIL_COND_V(!voice,0);
-
- return voice->pan_depth;
-}
-float AudioServerJavascript::voice_get_pan_height(RID p_voice) const{
-
- Voice* voice=voice_owner.get(p_voice);
- ERR_FAIL_COND_V(!voice,0);
-
- return voice->pan_height;
-}
-AudioServerJavascript::FilterType AudioServerJavascript::voice_get_filter_type(RID p_voice) const{
-
- return FILTER_NONE;
-}
-float AudioServerJavascript::voice_get_filter_cutoff(RID p_voice) const{
-
- return 0;
-}
-float AudioServerJavascript::voice_get_filter_resonance(RID p_voice) const{
-
- return 0;
-}
-float AudioServerJavascript::voice_get_chorus(RID p_voice) const{
-
- return 0;
-}
-AudioServerJavascript::ReverbRoomType AudioServerJavascript::voice_get_reverb_type(RID p_voice) const{
-
- return REVERB_SMALL;
-}
-float AudioServerJavascript::voice_get_reverb(RID p_voice) const{
-
- return 0;
-}
-
-int AudioServerJavascript::voice_get_mix_rate(RID p_voice) const{
-
- return 44100;
-}
-
-bool AudioServerJavascript::voice_is_positional(RID p_voice) const{
-
- return false;
-}
-
-void AudioServerJavascript::voice_stop(RID p_voice){
-
- Voice* voice=voice_owner.get(p_voice);
- ERR_FAIL_COND(!voice);
-
- if (voice->active) {
- /* clang-format off */
- EM_ASM_({
- if (_as_voices[$0] !== null) {
- _as_voices[$0].stop();
- _as_voices[$0].disconnect(_as_voice_gain[$0]);
- _as_voices[$0] = null;
- }
- }, voice->index);
- /* clang-format on */
-
- voice->active=false;
- }
-
-
-}
-bool AudioServerJavascript::voice_is_active(RID p_voice) const{
- Voice* voice=voice_owner.get(p_voice);
- ERR_FAIL_COND_V(!voice,false);
-
- return voice->active;
-}
-
-/* STREAM API */
-
-RID AudioServerJavascript::audio_stream_create(AudioStream *p_stream) {
-
-
- Stream *s = memnew(Stream);
- s->audio_stream=p_stream;
- s->event_stream=NULL;
- s->active=false;
- s->E=NULL;
- s->volume_scale=1.0;
- p_stream->set_mix_rate(webaudio_mix_rate);
-
- return stream_owner.make_rid(s);
-}
-
-RID AudioServerJavascript::event_stream_create(EventStream *p_stream) {
-
-
- Stream *s = memnew(Stream);
- s->audio_stream=NULL;
- s->event_stream=p_stream;
- s->active=false;
- s->E=NULL;
- s->volume_scale=1.0;
- //p_stream->set_mix_rate(AudioDriverJavascript::get_singleton()->get_mix_rate());
-
- return stream_owner.make_rid(s);
-
-
-}
-
-
-void AudioServerJavascript::stream_set_active(RID p_stream, bool p_active) {
-
-
- Stream *s = stream_owner.get(p_stream);
- ERR_FAIL_COND(!s);
-
- if (s->active==p_active)
- return;
-
- s->active=p_active;
- if (p_active)
- s->E=active_audio_streams.push_back(s);
- else {
- active_audio_streams.erase(s->E);
- s->E=NULL;
- }
-}
-
-bool AudioServerJavascript::stream_is_active(RID p_stream) const {
-
- Stream *s = stream_owner.get(p_stream);
- ERR_FAIL_COND_V(!s,false);
- return s->active;
-}
-
-void AudioServerJavascript::stream_set_volume_scale(RID p_stream, float p_scale) {
-
- Stream *s = stream_owner.get(p_stream);
- ERR_FAIL_COND(!s);
- s->volume_scale=p_scale;
-
-}
-
-float AudioServerJavascript::stream_set_volume_scale(RID p_stream) const {
-
- Stream *s = stream_owner.get(p_stream);
- ERR_FAIL_COND_V(!s,0);
- return s->volume_scale;
-
-}
-
-
-/* Audio Physics API */
-
-void AudioServerJavascript::free(RID p_id){
-
- if (voice_owner.owns(p_id)) {
- Voice* voice=voice_owner.get(p_id);
- ERR_FAIL_COND(!voice);
-
- if (voice->active) {
- /* clang-format off */
- EM_ASM_({
- if (_as_voices[$0] !== null) {
- _as_voices[$0].stop();
- _as_voices[$0].disconnect(_as_voice_gain[$0]);
- }
- }, voice->index);
- /* clang-format on */
- }
-
- /* clang-format off */
- EM_ASM_({
- delete _as_voices[$0];
- _as_voice_gain[$0].disconnect(_as_voice_pan[$0]);
- delete _as_voice_gain[$0];
- _as_voice_pan[$0].disconnect(_as_audioctx.destination);
- delete _as_voice_pan[$0];
- }, voice->index);
- /* clang-format on */
-
- voice_owner.free(p_id);
- memdelete(voice);
-
- } else if (sample_owner.owns(p_id)) {
-
- Sample *sample = sample_owner.get(p_id);
- ERR_FAIL_COND(!sample);
-
- /* clang-format off */
- EM_ASM_({
- delete _as_samples[$0];
- }, sample->index);
- /* clang-format on */
-
- sample_owner.free(p_id);
- memdelete(sample);
-
- } else if (stream_owner.owns(p_id)) {
-
-
- Stream *s=stream_owner.get(p_id);
-
- if (s->active) {
- stream_set_active(p_id,false);
- }
-
- memdelete(s);
- stream_owner.free(p_id);
- }
-}
-
-extern "C" {
-
-
-void audio_server_mix_function(int p_frames) {
-
- //print_line("MIXI! "+itos(p_frames));
- static_cast<AudioServerJavascript*>(AudioServerJavascript::get_singleton())->mix_to_js(p_frames);
-}
-
-}
-
-void AudioServerJavascript::mix_to_js(int p_frames) {
-
-
- //process in chunks to make sure to never process more than INTERNAL_BUFFER_SIZE
- int todo=p_frames;
- int offset=0;
-
- while(todo) {
-
- int tomix=MIN(todo,INTERNAL_BUFFER_SIZE);
- driver_process_chunk(tomix);
-
- /* clang-format off */
- EM_ASM_({
- var data = HEAPF32.subarray($0 / 4, $0 / 4 + $2 * 2);
-
- for (var channel = 0; channel < _as_output_buffer.numberOfChannels; channel++) {
- var outputData = _as_output_buffer.getChannelData(channel);
- // Loop through samples
- for (var sample = 0; sample < $2; sample++) {
- // make output equal to the same as the input
- outputData[sample + $1] = data[sample * 2 + channel];
- }
- }
- }, internal_buffer, offset, tomix);
- /* clang-format on */
-
- todo-=tomix;
- offset+=tomix;
- }
-}
-
-void AudioServerJavascript::init(){
-
- /*
- // clang-format off
- EM_ASM(
- console.log('server is ' + audio_server);
- );
- // clang-format on
- */
-
-
- //int latency = GLOBAL_DEF("javascript/audio_latency",16384);
-
- internal_buffer_channels=2;
- internal_buffer = memnew_arr(float,INTERNAL_BUFFER_SIZE*internal_buffer_channels);
- stream_buffer = memnew_arr(int32_t,INTERNAL_BUFFER_SIZE*4); //max 4 channels
-
- stream_volume=0.3;
-
- int buffer_latency=16384;
-
- /* clang-format off */
- EM_ASM_( {
- _as_script_node = _as_audioctx.createScriptProcessor($0, 0, 2);
- _as_script_node.connect(_as_audioctx.destination);
- console.log(_as_script_node.bufferSize);
-
- _as_script_node.onaudioprocess = function(audioProcessingEvent) {
- // The output buffer contains the samples that will be modified and played
- _as_output_buffer = audioProcessingEvent.outputBuffer;
- audio_server_mix_function(_as_output_buffer.getChannelData(0).length);
- }
- }, buffer_latency);
- /* clang-format on */
-
-
-}
-
-void AudioServerJavascript::finish(){
-
-}
-void AudioServerJavascript::update(){
-
- for(List<Stream*>::Element *E=active_audio_streams.front();E;) { //stream might be removed durnig this callback
-
- List<Stream*>::Element *N=E->next();
-
- if (E->get()->audio_stream)
- E->get()->audio_stream->update();
-
- E=N;
- }
-}
-
-/* MISC config */
-
-void AudioServerJavascript::lock(){
-
-}
-void AudioServerJavascript::unlock(){
-
-}
-int AudioServerJavascript::get_default_channel_count() const{
-
- return 1;
-}
-int AudioServerJavascript::get_default_mix_rate() const{
-
- return 44100;
-}
-
-void AudioServerJavascript::set_stream_global_volume_scale(float p_volume){
-
- stream_volume_scale=p_volume;
-}
-void AudioServerJavascript::set_fx_global_volume_scale(float p_volume){
-
- fx_volume_scale=p_volume;
-}
-void AudioServerJavascript::set_event_voice_global_volume_scale(float p_volume){
-
-}
-
-float AudioServerJavascript::get_stream_global_volume_scale() const{
- return 1;
-}
-float AudioServerJavascript::get_fx_global_volume_scale() const{
-
- return 1;
-}
-float AudioServerJavascript::get_event_voice_global_volume_scale() const{
-
- return 1;
-}
-
-uint32_t AudioServerJavascript::read_output_peak() const{
-
- return 0;
-}
-
-AudioServerJavascript *AudioServerJavascript::singleton=NULL;
-
-AudioServer *AudioServerJavascript::get_singleton() {
- return singleton;
-}
-
-double AudioServerJavascript::get_mix_time() const{
-
- return 0;
-}
-double AudioServerJavascript::get_output_delay() const {
-
- return 0;
-}
-
-
-void AudioServerJavascript::driver_process_chunk(int p_frames) {
-
-
-
- int samples=p_frames*internal_buffer_channels;
-
- for(int i=0;i<samples;i++) {
- internal_buffer[i]=0;
- }
-
-
- for(List<Stream*>::Element *E=active_audio_streams.front();E;E=E->next()) {
-
- ERR_CONTINUE(!E->get()->active); // bug?
-
-
- AudioStream *as=E->get()->audio_stream;
- if (!as)
- continue;
-
- int channels=as->get_channel_count();
- if (channels==0)
- continue; // does not want mix
- if (!as->mix(stream_buffer,p_frames))
- continue; //nothing was mixed!!
-
- int32_t stream_vol_scale=(stream_volume*stream_volume_scale*E->get()->volume_scale)*(1<<STREAM_SCALE_BITS);
-
-#define STRSCALE(m_val) ((((m_val >> STREAM_SCALE_BITS) * stream_vol_scale) >> 8) / 8388608.0)
- switch(channels) {
- case 1: {
-
- for(int i=0;i<p_frames;i++) {
-
- internal_buffer[(i<<1)+0]+=STRSCALE(stream_buffer[i]);
- internal_buffer[(i<<1)+1]+=STRSCALE(stream_buffer[i]);
- }
- } break;
- case 2: {
-
- for(int i=0;i<p_frames*2;i++) {
-
- internal_buffer[i]+=STRSCALE(stream_buffer[i]);
- }
- } break;
- case 4: {
-
- for(int i=0;i<p_frames;i++) {
-
- internal_buffer[(i<<2)+0]+=STRSCALE((stream_buffer[(i<<2)+0]+stream_buffer[(i<<2)+2])>>1);
- internal_buffer[(i<<2)+1]+=STRSCALE((stream_buffer[(i<<2)+1]+stream_buffer[(i<<2)+3])>>1);
- }
- } break;
-
-
- }
-
-#undef STRSCALE
- }
-}
-
-
-/*void AudioServerSW::driver_process(int p_frames,int32_t *p_buffer) {
-
-
- _output_delay=p_frames/double(AudioDriverSW::get_singleton()->get_mix_rate());
- //process in chunks to make sure to never process more than INTERNAL_BUFFER_SIZE
- int todo=p_frames;
- while(todo) {
-
- int tomix=MIN(todo,INTERNAL_BUFFER_SIZE);
- driver_process_chunk(tomix,p_buffer);
- p_buffer+=tomix;
- todo-=tomix;
- }
-
-
-}*/
-
-AudioServerJavascript::AudioServerJavascript() {
-
- singleton=this;
- sample_base=1;
- voice_base=1;
- /* clang-format off */
- EM_ASM(
- _as_samples = {};
- _as_voices = {};
- _as_voice_pan = {};
- _as_voice_gain = {};
-
- _as_audioctx = new (window.AudioContext || window.webkitAudioContext)();
-
- audio_server_mix_function = Module.cwrap('audio_server_mix_function', 'void', ['number']);
- );
- /* clang-format on */
-
- /* clang-format off */
- webaudio_mix_rate = EM_ASM_INT_V(
- return _as_audioctx.sampleRate;
- );
- /* clang-format on */
- print_line("WEBAUDIO MIX RATE: "+itos(webaudio_mix_rate));
- event_voice_scale=1.0;
- fx_volume_scale=1.0;
- stream_volume_scale=1.0;
-
-}
-#endif
diff --git a/platform/javascript/audio_server_javascript.h b/platform/javascript/audio_server_javascript.h
deleted file mode 100644
index 0773459f56..0000000000
--- a/platform/javascript/audio_server_javascript.h
+++ /dev/null
@@ -1,229 +0,0 @@
-/*************************************************************************/
-/* audio_server_javascript.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#ifndef AUDIO_SERVER_JAVASCRIPT_H
-#define AUDIO_SERVER_JAVASCRIPT_H
-
-// FIXME: Needs to be ported to the new AudioServer API in 3.0
-#if 0
-#include "servers/audio_server.h"
-
-class AudioServerJavascript : public AudioServer {
-
- GDCLASS(AudioServerJavascript,AudioServer);
-
- enum {
- INTERNAL_BUFFER_SIZE=4096,
- STREAM_SCALE_BITS=12
-
- };
-
- AudioMixer *get_mixer();
- void audio_mixer_chunk_callback(int p_frames);
-
- struct Sample {
- SampleFormat format;
- SampleLoopFormat loop_format;
- int loop_begin;
- int loop_end;
- int length;
- int index;
- int mix_rate;
- bool stereo;
-
- Vector<float> tmp_data;
- };
-
- mutable RID_Owner<Sample> sample_owner;
- int sample_base;
-
- struct Voice {
- int index;
- float volume;
- float pan;
- float pan_depth;
- float pan_height;
-
- float chorus;
- ReverbRoomType reverb_type;
- float reverb;
-
- int mix_rate;
- int sample_mix_rate;
- bool positional;
-
- bool active;
-
- };
-
- mutable RID_Owner<Voice> voice_owner;
-
- int voice_base;
-
- struct Stream {
- bool active;
- List<Stream*>::Element *E;
- AudioStream *audio_stream;
- EventStream *event_stream;
- float volume_scale;
- };
-
- List<Stream*> active_audio_streams;
-
- //List<Stream*> event_streams;
-
- float * internal_buffer;
- int internal_buffer_channels;
- int32_t * stream_buffer;
-
- mutable RID_Owner<Stream> stream_owner;
-
- float stream_volume;
- float stream_volume_scale;
-
- float event_voice_scale;
- float fx_volume_scale;
-
-
- void driver_process_chunk(int p_frames);
-
- int webaudio_mix_rate;
-
-
- static AudioServerJavascript *singleton;
-public:
-
- void mix_to_js(int p_frames);
- /* SAMPLE API */
-
- virtual RID sample_create(SampleFormat p_format, bool p_stereo, int p_length);
-
- virtual void sample_set_description(RID p_sample, const String& p_description);
- virtual String sample_get_description(RID p_sample) const;
-
- virtual SampleFormat sample_get_format(RID p_sample) const;
- virtual bool sample_is_stereo(RID p_sample) const;
- virtual int sample_get_length(RID p_sample) const;
- virtual const void* sample_get_data_ptr(RID p_sample) const;
-
-
- virtual void sample_set_data(RID p_sample, const PoolVector<uint8_t>& p_buffer);
- virtual PoolVector<uint8_t> sample_get_data(RID p_sample) const;
-
- virtual void sample_set_mix_rate(RID p_sample,int p_rate);
- virtual int sample_get_mix_rate(RID p_sample) const;
-
- virtual void sample_set_loop_format(RID p_sample,SampleLoopFormat p_format);
- virtual SampleLoopFormat sample_get_loop_format(RID p_sample) const;
-
- virtual void sample_set_loop_begin(RID p_sample,int p_pos);
- virtual int sample_get_loop_begin(RID p_sample) const;
-
- virtual void sample_set_loop_end(RID p_sample,int p_pos);
- virtual int sample_get_loop_end(RID p_sample) const;
-
-
- /* VOICE API */
-
- virtual RID voice_create();
-
- virtual void voice_play(RID p_voice, RID p_sample);
-
- virtual void voice_set_volume(RID p_voice, float p_volume);
- virtual void voice_set_pan(RID p_voice, float p_pan, float p_depth=0,float height=0); //pan and depth go from -1 to 1
- virtual void voice_set_filter(RID p_voice, FilterType p_type, float p_cutoff, float p_resonance, float p_gain=0);
- virtual void voice_set_chorus(RID p_voice, float p_chorus );
- virtual void voice_set_reverb(RID p_voice, ReverbRoomType p_room_type, float p_reverb);
- virtual void voice_set_mix_rate(RID p_voice, int p_mix_rate);
- virtual void voice_set_positional(RID p_voice, bool p_positional);
-
- virtual float voice_get_volume(RID p_voice) const;
- virtual float voice_get_pan(RID p_voice) const; //pan and depth go from -1 to 1
- virtual float voice_get_pan_depth(RID p_voice) const; //pan and depth go from -1 to 1
- virtual float voice_get_pan_height(RID p_voice) const; //pan and depth go from -1 to 1
- virtual FilterType voice_get_filter_type(RID p_voice) const;
- virtual float voice_get_filter_cutoff(RID p_voice) const;
- virtual float voice_get_filter_resonance(RID p_voice) const;
- virtual float voice_get_chorus(RID p_voice) const;
- virtual ReverbRoomType voice_get_reverb_type(RID p_voice) const;
- virtual float voice_get_reverb(RID p_voice) const;
-
- virtual int voice_get_mix_rate(RID p_voice) const;
- virtual bool voice_is_positional(RID p_voice) const;
-
- virtual void voice_stop(RID p_voice);
- virtual bool voice_is_active(RID p_voice) const;
-
- /* STREAM API */
-
- virtual RID audio_stream_create(AudioStream *p_stream);
- virtual RID event_stream_create(EventStream *p_stream);
-
- virtual void stream_set_active(RID p_stream, bool p_active);
- virtual bool stream_is_active(RID p_stream) const;
-
- virtual void stream_set_volume_scale(RID p_stream, float p_scale);
- virtual float stream_set_volume_scale(RID p_stream) const;
-
- /* Audio Physics API */
-
- virtual void free(RID p_id);
-
- virtual void init();
- virtual void finish();
- virtual void update();
-
- /* MISC config */
-
- virtual void lock();
- virtual void unlock();
- virtual int get_default_channel_count() const;
- virtual int get_default_mix_rate() const;
-
- virtual void set_stream_global_volume_scale(float p_volume);
- virtual void set_fx_global_volume_scale(float p_volume);
- virtual void set_event_voice_global_volume_scale(float p_volume);
-
- virtual float get_stream_global_volume_scale() const;
- virtual float get_fx_global_volume_scale() const;
- virtual float get_event_voice_global_volume_scale() const;
-
- virtual uint32_t read_output_peak() const;
-
- static AudioServer *get_singleton();
-
- virtual double get_mix_time() const; //useful for video -> audio sync
- virtual double get_output_delay() const;
-
-
- AudioServerJavascript();
-};
-
-#endif // AUDIO_SERVER_JAVASCRIPT_H
-#endif
diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py
index bea8f156af..a2988d9c60 100644
--- a/platform/javascript/detect.py
+++ b/platform/javascript/detect.py
@@ -13,22 +13,22 @@ def get_name():
def can_build():
- return ("EMSCRIPTEN_ROOT" in os.environ)
+ return ("EMSCRIPTEN_ROOT" in os.environ or "EMSCRIPTEN" in os.environ)
def get_opts():
-
+ from SCons.Variables import BoolVariable
return [
- ['wasm', 'Compile to WebAssembly', 'no'],
- ['javascript_eval', 'Enable JavaScript eval interface', 'yes'],
+ BoolVariable('wasm', 'Compile to WebAssembly', False),
+ BoolVariable('javascript_eval', 'Enable JavaScript eval interface', True),
]
def get_flags():
return [
- ('tools', 'no'),
- ('module_theora_enabled', 'no'),
+ ('tools', False),
+ ('module_theora_enabled', False),
]
@@ -66,7 +66,10 @@ def configure(env):
## Compiler configuration
env['ENV'] = os.environ
- env.PrependENVPath('PATH', os.environ['EMSCRIPTEN_ROOT'])
+ if ("EMSCRIPTEN_ROOT" in os.environ):
+ env.PrependENVPath('PATH', os.environ['EMSCRIPTEN_ROOT'])
+ elif ("EMSCRIPTEN" in os.environ):
+ env.PrependENVPath('PATH', os.environ['EMSCRIPTEN'])
env['CC'] = 'emcc'
env['CXX'] = 'em++'
env['LINK'] = 'emcc'
@@ -95,7 +98,7 @@ def configure(env):
# These flags help keep the file size down
env.Append(CPPFLAGS=["-fno-exceptions", '-DNO_SAFE_CAST', '-fno-rtti'])
- if env['javascript_eval'] == 'yes':
+ if env['javascript_eval']:
env.Append(CPPFLAGS=['-DJAVASCRIPT_EVAL_ENABLED'])
## Link flags
@@ -103,7 +106,7 @@ def configure(env):
env.Append(LINKFLAGS=['-s', 'EXTRA_EXPORTED_RUNTIME_METHODS="[\'FS\']"'])
env.Append(LINKFLAGS=['-s', 'USE_WEBGL2=1'])
- if (env['wasm'] == 'yes'):
+ if env['wasm']:
env.Append(LINKFLAGS=['-s', 'BINARYEN=1'])
# In contrast to asm.js, enabling memory growth on WebAssembly has no
# major performance impact, and causes only a negligible increase in
@@ -116,5 +119,5 @@ def configure(env):
env.Append(LINKFLAGS=['--memory-init-file', '1'])
# TODO: Move that to opus module's config
- if("module_opus_enabled" in env and env["module_opus_enabled"] != "no"):
+ if 'module_opus_enabled' in env and env['module_opus_enabled']:
env.opus_fixed_point = "yes"
diff --git a/platform/javascript/engine.js b/platform/javascript/engine.js
index 552f5a7e02..99d1c20bbd 100644
--- a/platform/javascript/engine.js
+++ b/platform/javascript/engine.js
@@ -84,10 +84,10 @@
rtenvOpts.print = stdout;
if (typeof stderr === 'function')
rtenvOpts.printErr = stderr;
- if (typeof WebAssembly === 'object' && initializer instanceof WebAssembly.Module) {
+ if (typeof WebAssembly === 'object' && initializer instanceof ArrayBuffer) {
rtenvOpts.instantiateWasm = function(imports, onSuccess) {
WebAssembly.instantiate(initializer, imports).then(function(result) {
- onSuccess(result);
+ onSuccess(result.instance);
});
return {};
};
@@ -241,7 +241,7 @@
return Promise.reject(new Error("Browser doesn't support WebAssembly"));
// TODO cache/retrieve module to/from idb
engineLoadPromise = loadPromise(basePath + '.wasm').then(function(xhr) {
- return WebAssembly.compile(xhr.response);
+ return xhr.response;
});
} else {
var asmjsPromise = loadPromise(basePath + '.asm.js').then(function(xhr) {
diff --git a/platform/javascript/javascript_eval.cpp b/platform/javascript/javascript_eval.cpp
index 74f8d80a76..1d737879f6 100644
--- a/platform/javascript/javascript_eval.cpp
+++ b/platform/javascript/javascript_eval.cpp
@@ -39,24 +39,41 @@ JavaScript *JavaScript::get_singleton() {
return singleton;
}
+extern "C" EMSCRIPTEN_KEEPALIVE uint8_t *resize_poolbytearray_and_open_write(PoolByteArray *p_arr, PoolByteArray::Write *r_write, int p_len) {
+
+ p_arr->resize(p_len);
+ *r_write = p_arr->write();
+ return r_write->ptr();
+}
+
Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) {
union {
- int i;
+ bool b;
double d;
char *s;
} js_data[4];
+
+ PoolByteArray arr;
+ PoolByteArray::Write arr_write;
+
/* clang-format off */
Variant::Type return_type = static_cast<Variant::Type>(EM_ASM_INT({
+ const CODE = $0;
+ const USE_GLOBAL_EXEC_CONTEXT = $1;
+ const PTR = $2;
+ const ELEM_LEN = $3;
+ const BYTEARRAY_PTR = $4;
+ const BYTEARRAY_WRITE_PTR = $5;
var eval_ret;
try {
- if ($3) { // p_use_global_exec_context
+ if (USE_GLOBAL_EXEC_CONTEXT) {
// indirect eval call grants global execution context
var global_eval = eval;
- eval_ret = global_eval(UTF8ToString($2));
+ eval_ret = global_eval(UTF8ToString(CODE));
} else {
- eval_ret = eval(UTF8ToString($2));
+ eval_ret = eval(UTF8ToString(CODE));
}
} catch (e) {
Module.printErr(e);
@@ -66,16 +83,11 @@ Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) {
switch (typeof eval_ret) {
case 'boolean':
- // bitwise op yields 32-bit int
- setValue($0, eval_ret|0, 'i32');
+ setValue(PTR, eval_ret, 'i32');
return 1; // BOOL
case 'number':
- if ((eval_ret|0)===eval_ret) {
- setValue($0, eval_ret|0, 'i32');
- return 2; // INT
- }
- setValue($0, eval_ret, 'double');
+ setValue(PTR, eval_ret, 'double');
return 3; // REAL
case 'string':
@@ -85,7 +97,7 @@ Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) {
if (array_ptr===0) {
throw new Error('String allocation failed (probably out of memory)');
}
- setValue($0, array_ptr|0 , '*');
+ setValue(PTR, array_ptr , '*');
stringToUTF8(eval_ret, array_ptr, array_len);
return 4; // STRING
} catch (e) {
@@ -102,41 +114,50 @@ Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) {
break;
}
- else if (typeof eval_ret.x==='number' && typeof eval_ret.y==='number') {
- setValue($0, eval_ret.x, 'double');
- setValue($0+$1, eval_ret.y, 'double');
+ if (ArrayBuffer.isView(eval_ret) && !(eval_ret instanceof Uint8Array)) {
+ eval_ret = new Uint8Array(eval_ret.buffer);
+ }
+ else if (eval_ret instanceof ArrayBuffer) {
+ eval_ret = new Uint8Array(eval_ret);
+ }
+ if (eval_ret instanceof Uint8Array) {
+ var bytes_ptr = ccall('resize_poolbytearray_and_open_write', 'number', ['number', 'number' ,'number'], [BYTEARRAY_PTR, BYTEARRAY_WRITE_PTR, eval_ret.length]);
+ HEAPU8.set(eval_ret, bytes_ptr);
+ return 20; // POOL_BYTE_ARRAY
+ }
+
+ if (typeof eval_ret.x==='number' && typeof eval_ret.y==='number') {
+ setValue(PTR, eval_ret.x, 'double');
+ setValue(PTR + ELEM_LEN, eval_ret.y, 'double');
if (typeof eval_ret.z==='number') {
- setValue($0+$1*2, eval_ret.z, 'double');
+ setValue(PTR + ELEM_LEN*2, eval_ret.z, 'double');
return 7; // VECTOR3
}
else if (typeof eval_ret.width==='number' && typeof eval_ret.height==='number') {
- setValue($0+$1*2, eval_ret.width, 'double');
- setValue($0+$1*3, eval_ret.height, 'double');
+ setValue(PTR + ELEM_LEN*2, eval_ret.width, 'double');
+ setValue(PTR + ELEM_LEN*3, eval_ret.height, 'double');
return 6; // RECT2
}
return 5; // VECTOR2
}
- else if (typeof eval_ret.r==='number' && typeof eval_ret.g==='number' && typeof eval_ret.b==='number') {
- // assume 8-bit rgb components since we're on the web
- setValue($0, eval_ret.r, 'double');
- setValue($0+$1, eval_ret.g, 'double');
- setValue($0+$1*2, eval_ret.b, 'double');
- setValue($0+$1*3, typeof eval_ret.a==='number' ? eval_ret.a : 1, 'double');
+ if (typeof eval_ret.r === 'number' && typeof eval_ret.g === 'number' && typeof eval_ret.b === 'number') {
+ setValue(PTR, eval_ret.r, 'double');
+ setValue(PTR + ELEM_LEN, eval_ret.g, 'double');
+ setValue(PTR + ELEM_LEN*2, eval_ret.b, 'double');
+ setValue(PTR + ELEM_LEN*3, typeof eval_ret.a === 'number' ? eval_ret.a : 1, 'double');
return 14; // COLOR
}
break;
}
return 0; // NIL
- }, js_data, sizeof *js_data, p_code.utf8().get_data(), p_use_global_exec_context));
+ }, p_code.utf8().get_data(), p_use_global_exec_context, js_data, sizeof *js_data, &arr, &arr_write));
/* clang-format on */
switch (return_type) {
case Variant::BOOL:
- return !!js_data->i;
- case Variant::INT:
- return js_data->i;
+ return js_data->b;
case Variant::REAL:
return js_data->d;
case Variant::STRING: {
@@ -153,7 +174,10 @@ Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) {
case Variant::RECT2:
return Rect2(js_data[0].d, js_data[1].d, js_data[2].d, js_data[3].d);
case Variant::COLOR:
- return Color(js_data[0].d / 255., js_data[1].d / 255., js_data[2].d / 255., js_data[3].d);
+ return Color(js_data[0].d, js_data[1].d, js_data[2].d, js_data[3].d);
+ case Variant::POOL_BYTE_ARRAY:
+ arr_write = PoolByteArray::Write();
+ return arr;
}
return Variant();
}
diff --git a/platform/javascript/javascript_main.cpp b/platform/javascript/javascript_main.cpp
index 4c948bf181..ed4f416cfd 100644
--- a/platform/javascript/javascript_main.cpp
+++ b/platform/javascript/javascript_main.cpp
@@ -39,8 +39,13 @@ static void main_loop() {
os->main_loop_iterate();
}
-extern "C" void main_after_fs_sync() {
+extern "C" void main_after_fs_sync(char *p_idbfs_err) {
+ String idbfs_err = String::utf8(p_idbfs_err);
+ if (!idbfs_err.empty()) {
+ print_line("IndexedDB not available: " + idbfs_err);
+ }
+ os->set_idbfs_available(idbfs_err.empty());
// Ease up compatibility
ResourceLoader::set_abort_on_missing_resources(false);
Main::start();
@@ -60,14 +65,7 @@ int main(int argc, char *argv[]) {
FS.mkdir('/userfs');
FS.mount(IDBFS, {}, '/userfs');
FS.syncfs(true, function(err) {
- if (err) {
- Module.setStatus('Failed to load persistent data\nPlease allow (third-party) cookies');
- Module.printErr('Failed to populate IDB file system: ' + err.message);
- Module.noExitRuntime = false;
- } else {
- Module.print('Successfully populated IDB file system');
- ccall('main_after_fs_sync', null);
- }
+ Module['ccall']('main_after_fs_sync', null, ['string'], [err ? err.message : ""])
});
);
/* clang-format on */
diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp
index 67d2a6e369..3a57de2646 100644
--- a/platform/javascript/os_javascript.cpp
+++ b/platform/javascript/os_javascript.cpp
@@ -85,6 +85,10 @@ void OS_JavaScript::initialize_core() {
FileAccess::make_default<FileAccessBufferedFA<FileAccessUnix> >(FileAccess::ACCESS_RESOURCES);
}
+void OS_JavaScript::initialize_logger() {
+ _set_logger(memnew(StdLogger));
+}
+
void OS_JavaScript::set_opengl_extensions(const char *p_gl_extensions) {
ERR_FAIL_COND(!p_gl_extensions);
@@ -172,14 +176,14 @@ static EM_BOOL _mousebutton_callback(int event_type, const EmscriptenMouseEvent
if (!is_canvas_focused()) {
focus_canvas();
}
- mask |= 1 << ev->get_button_index();
- } else if (mask & (1 << ev->get_button_index())) {
- mask &= ~(1 << ev->get_button_index());
+ mask |= ev->get_button_index();
+ } else if (mask & ev->get_button_index()) {
+ mask &= ~ev->get_button_index();
} else {
// release event, but press was outside the canvas, so ignore
return false;
}
- ev->set_button_mask(mask >> 1);
+ ev->set_button_mask(mask);
_input->parse_input_event(ev);
// prevent selection dragging
@@ -200,7 +204,7 @@ static EM_BOOL _mousemove_callback(int event_type, const EmscriptenMouseEvent *m
Ref<InputEventMouseMotion> ev;
ev.instance();
dom2godot_mod(mouse_event, ev);
- ev->set_button_mask(input_mask >> 1);
+ ev->set_button_mask(input_mask);
ev->set_position(pos);
ev->set_global_position(ev->get_position());
@@ -227,7 +231,7 @@ static EM_BOOL _wheel_callback(int event_type, const EmscriptenWheelEvent *wheel
Ref<InputEventMouseButton> ev;
ev.instance();
- ev->set_button_mask(_input->get_mouse_button_mask() >> 1);
+ ev->set_button_mask(_input->get_mouse_button_mask());
ev->set_position(_input->get_mouse_position());
ev->set_global_position(ev->get_position());
@@ -291,7 +295,7 @@ static EM_BOOL _touchpress_callback(int event_type, const EmscriptenTouchEvent *
Ref<InputEventMouseButton> ev_mouse;
ev_mouse.instance();
- ev_mouse->set_button_mask(_input->get_mouse_button_mask() >> 1);
+ ev_mouse->set_button_mask(_input->get_mouse_button_mask());
dom2godot_mod(touch_event, ev_mouse);
const EmscriptenTouchPoint &first_touch = touch_event->touches[lowest_id_index];
@@ -334,7 +338,7 @@ static EM_BOOL _touchmove_callback(int event_type, const EmscriptenTouchEvent *t
Ref<InputEventMouseMotion> ev_mouse;
ev_mouse.instance();
dom2godot_mod(touch_event, ev_mouse);
- ev_mouse->set_button_mask(_input->get_mouse_button_mask() >> 1);
+ ev_mouse->set_button_mask(_input->get_mouse_button_mask());
const EmscriptenTouchPoint &first_touch = touch_event->touches[lowest_id_index];
ev_mouse->set_position(Point2(first_touch.canvasX, first_touch.canvasY));
@@ -476,11 +480,6 @@ void OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver, i
print_line("Init Physicsserver");
- physics_server = memnew(PhysicsServerSW);
- physics_server->init();
- physics_2d_server = memnew(Physics2DServerSW);
- physics_2d_server->init();
-
input = memnew(InputDefault);
_input = input;
@@ -821,7 +820,7 @@ bool OS_JavaScript::main_loop_iterate() {
if (!main_loop)
return false;
- if (time_to_save_sync >= 0) {
+ if (idbfs_available && time_to_save_sync >= 0) {
int64_t newtime = get_ticks_msec();
int64_t elapsed = newtime - last_sync_time;
last_sync_time = newtime;
@@ -911,10 +910,10 @@ String OS_JavaScript::get_executable_path() const {
void OS_JavaScript::_close_notification_funcs(const String &p_file, int p_flags) {
- print_line("close " + p_file + " flags " + itos(p_flags));
- if (p_file.begins_with("/userfs") && p_flags & FileAccess::WRITE) {
- static_cast<OS_JavaScript *>(get_singleton())->last_sync_time = OS::get_singleton()->get_ticks_msec();
- static_cast<OS_JavaScript *>(get_singleton())->time_to_save_sync = 5000; //five seconds since last save
+ OS_JavaScript *os = static_cast<OS_JavaScript *>(get_singleton());
+ if (os->idbfs_available && p_file.begins_with("/userfs") && p_flags & FileAccess::WRITE) {
+ os->last_sync_time = OS::get_singleton()->get_ticks_msec();
+ os->time_to_save_sync = 5000; //five seconds since last save
}
}
@@ -989,6 +988,16 @@ bool OS_JavaScript::_check_internal_feature_support(const String &p_feature) {
return p_feature == "web" || p_feature == "s3tc"; // TODO check for these features really being available
}
+void OS_JavaScript::set_idbfs_available(bool p_idbfs_available) {
+
+ idbfs_available = p_idbfs_available;
+}
+
+bool OS_JavaScript::is_userfs_persistent() const {
+
+ return idbfs_available;
+}
+
OS_JavaScript::OS_JavaScript(const char *p_execpath, GetDataDirFunc p_get_data_dir_func) {
set_cmdline(p_execpath, get_cmdline_args());
main_loop = NULL;
@@ -1000,6 +1009,7 @@ OS_JavaScript::OS_JavaScript(const char *p_execpath, GetDataDirFunc p_get_data_d
get_data_dir_func = p_get_data_dir_func;
FileAccessUnix::close_notification_func = _close_notification_funcs;
+ idbfs_available = false;
time_to_save_sync = -1;
}
diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h
index 4c6469cb58..07720e95ec 100644
--- a/platform/javascript/os_javascript.h
+++ b/platform/javascript/os_javascript.h
@@ -31,7 +31,6 @@
#define OS_JAVASCRIPT_H
#include "audio_driver_javascript.h"
-#include "audio_server_javascript.h"
#include "drivers/unix/os_unix.h"
#include "javascript_eval.h"
#include "main/input_default.h"
@@ -39,8 +38,6 @@
#include "os/main_loop.h"
#include "power_javascript.h"
#include "servers/audio_server.h"
-#include "servers/physics/physics_server_sw.h"
-#include "servers/physics_2d/physics_2d_server_sw.h"
#include "servers/visual/rasterizer.h"
#include <emscripten/html5.h>
@@ -49,12 +46,11 @@ typedef String (*GetDataDirFunc)();
class OS_JavaScript : public OS_Unix {
+ bool idbfs_available;
int64_t time_to_save_sync;
int64_t last_sync_time;
VisualServer *visual_server;
- PhysicsServer *physics_server;
- Physics2DServer *physics_2d_server;
AudioDriverJavaScript audio_driver_javascript;
const char *gl_extensions;
@@ -92,6 +88,7 @@ public:
virtual int get_audio_driver_count() const;
virtual const char *get_audio_driver_name(int p_driver) const;
+ virtual void initialize_logger();
virtual void initialize_core();
virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
@@ -104,11 +101,6 @@ public:
//static OS* get_singleton();
- virtual void print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type) {
-
- OS::print_error(p_function, p_file, p_line, p_code, p_rationale, p_type);
- }
-
virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
virtual void set_mouse_mode(MouseMode p_mode);
@@ -140,6 +132,8 @@ public:
virtual bool can_draw() const;
+ virtual bool is_userfs_persistent() const;
+
virtual void set_cursor_shape(CursorShape p_shape);
void main_loop_begin();
@@ -171,6 +165,8 @@ public:
virtual bool _check_internal_feature_support(const String &p_feature);
+ void set_idbfs_available(bool p_idbfs_available);
+
OS_JavaScript(const char *p_execpath, GetDataDirFunc p_get_data_dir_func);
~OS_JavaScript();
};
diff --git a/platform/osx/SCsub b/platform/osx/SCsub
index 5b2de54535..be3950bc6d 100644
--- a/platform/osx/SCsub
+++ b/platform/osx/SCsub
@@ -1,20 +1,22 @@
#!/usr/bin/env python
+import os
Import('env')
+def make_debug(target, source, env):
+ os.system('dsymutil %s -o %s.dSYM' % (target[0], target[0]))
+
files = [
'crash_handler_osx.mm',
'os_osx.mm',
'godot_main_osx.mm',
- 'audio_driver_osx.cpp',
'sem_osx.cpp',
'dir_access_osx.mm',
'joypad_osx.cpp',
'power_osx.cpp',
]
-prog = env.Program('#bin/godot', files)
-if (env['target'] == "debug" or env['target'] == "release_debug"):
- # Build the .dSYM file for atos
- action = "dsymutil " + File(prog)[0].path + " -o " + File(prog)[0].path + ".dSYM"
- env.AddPostAction(prog, action)
+binary = env.Program('#bin/godot', files)
+if env["debug_symbols"] == "full" or env["debug_symbols"] == "yes":
+ env.AddPostAction(binary, make_debug)
+
diff --git a/platform/osx/audio_driver_osx.cpp b/platform/osx/audio_driver_osx.cpp
deleted file mode 100644
index 3b3ba60507..0000000000
--- a/platform/osx/audio_driver_osx.cpp
+++ /dev/null
@@ -1,301 +0,0 @@
-/*************************************************************************/
-/* audio_driver_osx.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#ifdef OSX_ENABLED
-
-#include "audio_driver_osx.h"
-#include "core/project_settings.h"
-#include "os/os.h"
-
-#define kOutputBus 0
-
-static OSStatus outputDeviceAddressCB(AudioObjectID inObjectID, UInt32 inNumberAddresses, const AudioObjectPropertyAddress *inAddresses, void *__nullable inClientData) {
- AudioDriverOSX *driver = (AudioDriverOSX *)inClientData;
-
- driver->reopen();
-
- return noErr;
-}
-
-Error AudioDriverOSX::initDevice() {
- AudioComponentDescription desc;
- zeromem(&desc, sizeof(desc));
- desc.componentType = kAudioUnitType_Output;
- desc.componentSubType = kAudioUnitSubType_HALOutput;
- desc.componentManufacturer = kAudioUnitManufacturer_Apple;
-
- AudioComponent comp = AudioComponentFindNext(NULL, &desc);
- ERR_FAIL_COND_V(comp == NULL, FAILED);
-
- OSStatus result = AudioComponentInstanceNew(comp, &audio_unit);
- ERR_FAIL_COND_V(result != noErr, FAILED);
-
- AudioStreamBasicDescription strdesc;
-
- zeromem(&strdesc, sizeof(strdesc));
- UInt32 size = sizeof(strdesc);
- result = AudioUnitGetProperty(audio_unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, kOutputBus, &strdesc, &size);
- ERR_FAIL_COND_V(result != noErr, FAILED);
-
- switch (strdesc.mChannelsPerFrame) {
- case 2: // Stereo
- case 4: // Surround 3.1
- case 6: // Surround 5.1
- case 8: // Surround 7.1
- channels = strdesc.mChannelsPerFrame;
- break;
-
- default:
- // Unknown number of channels, default to stereo
- channels = 2;
- break;
- }
-
- mix_rate = GLOBAL_DEF("audio/mix_rate", DEFAULT_MIX_RATE);
-
- zeromem(&strdesc, sizeof(strdesc));
- strdesc.mFormatID = kAudioFormatLinearPCM;
- strdesc.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
- strdesc.mChannelsPerFrame = channels;
- strdesc.mSampleRate = mix_rate;
- strdesc.mFramesPerPacket = 1;
- strdesc.mBitsPerChannel = 16;
- strdesc.mBytesPerFrame = strdesc.mBitsPerChannel * strdesc.mChannelsPerFrame / 8;
- strdesc.mBytesPerPacket = strdesc.mBytesPerFrame * strdesc.mFramesPerPacket;
-
- result = AudioUnitSetProperty(audio_unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, kOutputBus, &strdesc, sizeof(strdesc));
- ERR_FAIL_COND_V(result != noErr, FAILED);
-
- int latency = GLOBAL_DEF("audio/output_latency", DEFAULT_OUTPUT_LATENCY);
- // Sample rate is independent of channels (ref: https://stackoverflow.com/questions/11048825/audio-sample-frequency-rely-on-channels)
- buffer_frames = closest_power_of_2(latency * mix_rate / 1000);
-
- result = AudioUnitSetProperty(audio_unit, kAudioDevicePropertyBufferFrameSize, kAudioUnitScope_Global, kOutputBus, &buffer_frames, sizeof(UInt32));
- ERR_FAIL_COND_V(result != noErr, FAILED);
-
- buffer_size = buffer_frames * channels;
- samples_in.resize(buffer_size);
-
- if (OS::get_singleton()->is_stdout_verbose()) {
- print_line("CoreAudio: detected " + itos(channels) + " channels");
- print_line("CoreAudio: audio buffer frames: " + itos(buffer_frames) + " calculated latency: " + itos(buffer_frames * 1000 / mix_rate) + "ms");
- }
-
- AURenderCallbackStruct callback;
- zeromem(&callback, sizeof(AURenderCallbackStruct));
- callback.inputProc = &AudioDriverOSX::output_callback;
- callback.inputProcRefCon = this;
- result = AudioUnitSetProperty(audio_unit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, kOutputBus, &callback, sizeof(callback));
- ERR_FAIL_COND_V(result != noErr, FAILED);
-
- result = AudioUnitInitialize(audio_unit);
- ERR_FAIL_COND_V(result != noErr, FAILED);
-
- return OK;
-}
-
-Error AudioDriverOSX::finishDevice() {
- OSStatus result;
-
- if (active) {
- result = AudioOutputUnitStop(audio_unit);
- ERR_FAIL_COND_V(result != noErr, FAILED);
-
- active = false;
- }
-
- result = AudioUnitUninitialize(audio_unit);
- ERR_FAIL_COND_V(result != noErr, FAILED);
-
- return OK;
-}
-
-Error AudioDriverOSX::init() {
- OSStatus result;
-
- mutex = Mutex::create();
- active = false;
- channels = 2;
-
- outputDeviceAddress.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
- outputDeviceAddress.mScope = kAudioObjectPropertyScopeGlobal;
- outputDeviceAddress.mElement = kAudioObjectPropertyElementMaster;
-
- result = AudioObjectAddPropertyListener(kAudioObjectSystemObject, &outputDeviceAddress, &outputDeviceAddressCB, this);
- ERR_FAIL_COND_V(result != noErr, FAILED);
-
- return initDevice();
-};
-
-Error AudioDriverOSX::reopen() {
- bool restart = false;
-
- lock();
-
- if (active) {
- restart = true;
- }
-
- Error err = finishDevice();
- if (err != OK) {
- ERR_PRINT("finishDevice failed");
- unlock();
- return err;
- }
-
- err = initDevice();
- if (err != OK) {
- ERR_PRINT("initDevice failed");
- unlock();
- return err;
- }
-
- if (restart) {
- start();
- }
-
- unlock();
-
- return OK;
-}
-
-OSStatus AudioDriverOSX::output_callback(void *inRefCon,
- AudioUnitRenderActionFlags *ioActionFlags,
- const AudioTimeStamp *inTimeStamp,
- UInt32 inBusNumber, UInt32 inNumberFrames,
- AudioBufferList *ioData) {
-
- AudioDriverOSX *ad = (AudioDriverOSX *)inRefCon;
-
- if (!ad->active || !ad->try_lock()) {
- for (unsigned int i = 0; i < ioData->mNumberBuffers; i++) {
- AudioBuffer *abuf = &ioData->mBuffers[i];
- zeromem(abuf->mData, abuf->mDataByteSize);
- };
- return 0;
- };
-
- for (unsigned int i = 0; i < ioData->mNumberBuffers; i++) {
-
- 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->audio_server_process(frames, ad->samples_in.ptr());
-
- for (int j = 0; j < frames * ad->channels; j++) {
-
- out[j] = ad->samples_in[j] >> 16;
- }
-
- frames_left -= frames;
- out += frames * ad->channels;
- };
- };
-
- ad->unlock();
-
- return 0;
-};
-
-void AudioDriverOSX::start() {
- if (!active) {
- OSStatus result = AudioOutputUnitStart(audio_unit);
- if (result != noErr) {
- ERR_PRINT("AudioOutputUnitStart failed");
- } else {
- active = true;
- }
- }
-};
-
-int AudioDriverOSX::get_mix_rate() const {
- return mix_rate;
-};
-
-AudioDriver::SpeakerMode AudioDriverOSX::get_speaker_mode() const {
- return get_speaker_mode_by_total_channels(channels);
-};
-
-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() {
- finishDevice();
-
- OSStatus result = AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &outputDeviceAddress, &outputDeviceAddressCB, this);
- if (result != noErr) {
- ERR_PRINT("AudioObjectRemovePropertyListener failed");
- }
-
- AURenderCallbackStruct callback;
- zeromem(&callback, sizeof(AURenderCallbackStruct));
- result = AudioUnitSetProperty(audio_unit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, kOutputBus, &callback, sizeof(callback));
- if (result != noErr) {
- ERR_PRINT("AudioUnitSetProperty failed");
- }
-
- if (mutex) {
- memdelete(mutex);
- mutex = NULL;
- }
-};
-
-AudioDriverOSX::AudioDriverOSX() {
- active = false;
- mutex = NULL;
-
- mix_rate = 0;
- channels = 2;
-
- buffer_size = 0;
- buffer_frames = 0;
-
- samples_in.clear();
-};
-
-AudioDriverOSX::~AudioDriverOSX(){};
-
-#endif
diff --git a/platform/osx/audio_driver_osx.h b/platform/osx/audio_driver_osx.h
deleted file mode 100644
index a7e68c8141..0000000000
--- a/platform/osx/audio_driver_osx.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*************************************************************************/
-/* audio_driver_osx.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#ifdef OSX_ENABLED
-
-#ifndef AUDIO_DRIVER_OSX_H
-#define AUDIO_DRIVER_OSX_H
-
-#include "servers/audio_server.h"
-
-#include <AudioUnit/AudioUnit.h>
-#include <CoreAudio/AudioHardware.h>
-
-class AudioDriverOSX : public AudioDriver {
-
- AudioComponentInstance audio_unit;
- AudioObjectPropertyAddress outputDeviceAddress;
- bool active;
- Mutex *mutex;
-
- int mix_rate;
- unsigned int channels;
- unsigned int buffer_frames;
- unsigned int buffer_size;
-
- Vector<int32_t> samples_in;
-
- static OSStatus output_callback(void *inRefCon,
- AudioUnitRenderActionFlags *ioActionFlags,
- const AudioTimeStamp *inTimeStamp,
- UInt32 inBusNumber, UInt32 inNumberFrames,
- AudioBufferList *ioData);
-
- Error initDevice();
- Error finishDevice();
-
-public:
- const char *get_name() const {
- return "AudioUnit";
- };
-
- virtual Error init();
- virtual void start();
- virtual int get_mix_rate() const;
- virtual SpeakerMode get_speaker_mode() const;
- virtual void lock();
- virtual void unlock();
- virtual void finish();
-
- bool try_lock();
- Error reopen();
-
- AudioDriverOSX();
- ~AudioDriverOSX();
-};
-
-#endif
-
-#endif
diff --git a/platform/osx/crash_handler_osx.mm b/platform/osx/crash_handler_osx.mm
index 9239573734..5635fe0187 100644
--- a/platform/osx/crash_handler_osx.mm
+++ b/platform/osx/crash_handler_osx.mm
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "main/main.h"
#include "os_osx.h"
+#include "project_settings.h"
#include <string.h>
#include <unistd.h>
@@ -43,6 +44,7 @@
#include <dlfcn.h>
#include <execinfo.h>
#include <signal.h>
+#include <stdlib.h>
#include <mach-o/dyld.h>
#include <mach-o/getsect.h>
@@ -77,7 +79,7 @@ static void handle_crash(int sig) {
void *bt_buffer[256];
size_t size = backtrace(bt_buffer, 256);
String _execpath = OS::get_singleton()->get_executable_path();
- String msg = GLOBAL_GET("debug/settings/backtrace/message");
+ String msg = GLOBAL_GET("debug/settings/crash_handler/message");
// Dump the backtrace to stderr with a message to the user
fprintf(stderr, "%s: Program crashed with signal %d\n", __FUNCTION__, sig);
diff --git a/platform/osx/detect.py b/platform/osx/detect.py
index d3ebdfe992..31032659b6 100644
--- a/platform/osx/detect.py
+++ b/platform/osx/detect.py
@@ -19,9 +19,11 @@ def can_build():
def get_opts():
+ from SCons.Variables import EnumVariable
return [
('osxcross_sdk', 'OSXCross SDK version', 'darwin14'),
+ EnumVariable('debug_symbols', 'Add debug symbols to release version', 'yes', ('yes', 'no', 'full')),
]
@@ -36,10 +38,18 @@ def configure(env):
## Build type
if (env["target"] == "release"):
- env.Prepend(CCFLAGS=['-O2', '-ffast-math', '-fomit-frame-pointer', '-ftree-vectorize', '-msse2'])
+ env.Prepend(CCFLAGS=['-O3', '-ffast-math', '-fomit-frame-pointer', '-ftree-vectorize', '-msse2'])
+ if (env["debug_symbols"] == "yes"):
+ env.Prepend(CCFLAGS=['-g1'])
+ if (env["debug_symbols"] == "full"):
+ env.Prepend(CCFLAGS=['-g2'])
elif (env["target"] == "release_debug"):
env.Prepend(CCFLAGS=['-O2', '-DDEBUG_ENABLED'])
+ if (env["debug_symbols"] == "yes"):
+ env.Prepend(CCFLAGS=['-g1'])
+ if (env["debug_symbols"] == "full"):
+ env.Prepend(CCFLAGS=['-g2'])
elif (env["target"] == "debug"):
env.Prepend(CCFLAGS=['-g3', '-DDEBUG_ENABLED', '-DDEBUG_MEMORY_ENABLED'])
@@ -52,7 +62,7 @@ def configure(env):
## Compiler configuration
- if (not os.environ.has_key("OSXCROSS_ROOT")): # regular native build
+ if "OSXCROSS_ROOT" not in os.environ: # regular native build
if (env["bits"] == "fat"):
env.Append(CCFLAGS=['-arch', 'i386', '-arch', 'x86_64'])
env.Append(LINKFLAGS=['-arch', 'i386', '-arch', 'x86_64'])
@@ -87,13 +97,13 @@ def configure(env):
## Dependencies
- if (env['builtin_libtheora'] != 'no'):
+ if env['builtin_libtheora']:
env["x86_libtheora_opt_gcc"] = True
## Flags
env.Append(CPPPATH=['#platform/osx'])
- env.Append(CPPFLAGS=['-DOSX_ENABLED', '-DUNIX_ENABLED', '-DGLES2_ENABLED', '-DAPPLE_STYLE_KEYS'])
+ env.Append(CPPFLAGS=['-DOSX_ENABLED', '-DUNIX_ENABLED', '-DGLES2_ENABLED', '-DAPPLE_STYLE_KEYS', '-DCOREAUDIO_ENABLED'])
env.Append(LINKFLAGS=['-framework', 'Cocoa', '-framework', 'Carbon', '-framework', 'OpenGL', '-framework', 'AGL', '-framework', 'AudioUnit', '-framework', 'CoreAudio', '-lz', '-framework', 'IOKit', '-framework', 'ForceFeedback'])
env.Append(LIBS=['pthread'])
diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp
index 2ec76fe0dd..8a6f1dc04c 100644
--- a/platform/osx/export/export.cpp
+++ b/platform/osx/export/export.cpp
@@ -53,9 +53,16 @@ class EditorExportPlatformOSX : public EditorExportPlatform {
void _fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary);
void _make_icon(const Ref<Image> &p_icon, Vector<uint8_t> &p_data);
-#ifdef OSX_ENABLED
+
Error _code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path);
Error _create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name);
+
+#ifdef OSX_ENABLED
+ bool use_codesign() const { return true; }
+ bool use_dmg() const { return true; }
+#else
+ bool use_codesign() const { return false; }
+ bool use_dmg() const { return false; }
#endif
protected:
@@ -67,11 +74,7 @@ public:
virtual String get_os_name() const { return "OSX"; }
virtual Ref<Texture> get_logo() const { return logo; }
-#ifdef OSX_ENABLED
- virtual String get_binary_extension() const { return "dmg"; }
-#else
- virtual String get_binary_extension() const { return "zip"; }
-#endif
+ virtual String get_binary_extension() const { return use_dmg() ? "dmg" : "zip"; }
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
@@ -97,6 +100,16 @@ void EditorExportPlatformOSX::get_preset_features(const Ref<EditorExportPreset>
if (p_preset->get("texture_format/etc2")) {
r_features->push_back("etc2");
}
+
+ int bits = p_preset->get("application/bits_mode");
+
+ if (bits == 0 || bits == 1) {
+ r_features->push_back("64");
+ }
+
+ if (bits == 0 || bits == 2) {
+ r_features->push_back("32");
+ }
}
void EditorExportPlatformOSX::get_export_options(List<ExportOption> *r_options) {
@@ -210,7 +223,6 @@ void EditorExportPlatformOSX::_fix_plist(const Ref<EditorExportPreset> &p_preset
}
}
-#ifdef OSX_ENABLED
/**
If we're running the OSX version of the Godot editor we'll:
- export our application bundle to a temporary folder
@@ -220,6 +232,7 @@ void EditorExportPlatformOSX::_fix_plist(const Ref<EditorExportPreset> &p_preset
Error EditorExportPlatformOSX::_code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
List<String> args;
+
if (p_preset->get("codesign/entitlements") != "") {
/* this should point to our entitlements.plist file that sandboxes our application, I don't know if this should also be placed in our app bundle */
args.push_back("-entitlements");
@@ -229,14 +242,25 @@ Error EditorExportPlatformOSX::_code_sign(const Ref<EditorExportPreset> &p_prese
args.push_back(p_preset->get("codesign/identity"));
args.push_back("-v"); /* provide some more feedback */
args.push_back(p_path);
- Error err = OS::get_singleton()->execute("/usr/bin/codesign", args, true);
- ERR_FAIL_COND_V(err, err);
+
+ String str;
+ Error err = OS::get_singleton()->execute("codesign", args, true, NULL, &str, NULL, true);
+ ERR_FAIL_COND_V(err != OK, err);
+
+ print_line("codesign: " + str);
+ if (str.find("no identity found") != -1) {
+ EditorNode::add_io_error("codesign: no identity found");
+ return FAILED;
+ }
return OK;
}
Error EditorExportPlatformOSX::_create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name) {
List<String> args;
+
+ OS::get_singleton()->move_to_trash(p_dmg_path);
+
args.push_back("create");
args.push_back(p_dmg_path);
args.push_back("-volname");
@@ -245,8 +269,20 @@ Error EditorExportPlatformOSX::_create_dmg(const String &p_dmg_path, const Strin
args.push_back("HFS+");
args.push_back("-srcfolder");
args.push_back(p_app_path_name);
- Error err = OS::get_singleton()->execute("/usr/bin/hdiutil", args, true);
- ERR_FAIL_COND_V(err, err);
+
+ String str;
+ Error err = OS::get_singleton()->execute("hdiutil", args, true, NULL, &str, NULL, true);
+ ERR_FAIL_COND_V(err != OK, err);
+
+ print_line("hdiutil returned: " + str);
+ if (str.find("create failed") != -1) {
+ if (str.find("File exists") != -1) {
+ EditorNode::add_io_error("hdiutil: create failed - file exists");
+ } else {
+ EditorNode::add_io_error("hdiutil: create failed");
+ }
+ return FAILED;
+ }
return OK;
}
@@ -299,28 +335,45 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
else
pkg_name = "Unnamed";
- // We're on OSX so we can export to DMG, but first we create our application bundle
- String tmp_app_path_name = p_path.get_base_dir() + "/" + pkg_name + ".app";
- print_line("Exporting to " + tmp_app_path_name);
- DirAccess *tmp_app_path = DirAccess::create_for_path(tmp_app_path_name);
- ERR_FAIL_COND_V(!tmp_app_path, ERR_CANT_CREATE)
+ Error err = OK;
+ String tmp_app_path_name = "";
+ zlib_filefunc_def io2 = io;
+ FileAccess *dst_f = NULL;
+ io2.opaque = &dst_f;
+ zipFile dst_pkg_zip = NULL;
+
+ if (use_dmg()) {
+ // We're on OSX so we can export to DMG, but first we create our application bundle
+ tmp_app_path_name = EditorSettings::get_singleton()->get_settings_path() + "/tmp/" + pkg_name + ".app";
+ print_line("Exporting to " + tmp_app_path_name);
+ DirAccess *tmp_app_path = DirAccess::create_for_path(tmp_app_path_name);
+ if (!tmp_app_path) {
+ err = ERR_CANT_CREATE;
+ }
- ///@TODO We should delete the existing application bundle especially if we attempt to code sign it, but what is a safe way to do this? Maybe call system function so it moves to trash?
- // tmp_app_path->erase_contents_recursive();
+ // Create our folder structure or rely on unzip?
+ if (err == OK) {
+ print_line("Creating " + tmp_app_path_name + "/Contents/MacOS");
+ err = tmp_app_path->make_dir_recursive(tmp_app_path_name + "/Contents/MacOS");
+ }
- // Create our folder structure or rely on unzip?
- print_line("Creating " + tmp_app_path_name + "/Contents/MacOS");
- Error dir_err = tmp_app_path->make_dir_recursive(tmp_app_path_name + "/Contents/MacOS");
- ERR_FAIL_COND_V(dir_err, ERR_CANT_CREATE)
- print_line("Creating " + tmp_app_path_name + "/Contents/Resources");
- dir_err = tmp_app_path->make_dir_recursive(tmp_app_path_name + "/Contents/Resources");
- ERR_FAIL_COND_V(dir_err, ERR_CANT_CREATE)
+ if (err == OK) {
+ print_line("Creating " + tmp_app_path_name + "/Contents/Resources");
+ err = tmp_app_path->make_dir_recursive(tmp_app_path_name + "/Contents/Resources");
+ }
+ } else {
+ // Open our destination zip file
+ dst_pkg_zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, NULL, &io2);
+ if (!dst_pkg_zip) {
+ err = ERR_CANT_CREATE;
+ }
+ }
- /* Now process our template */
+ // Now process our template
bool found_binary = false;
int total_size = 0;
- while (ret == UNZ_OK) {
+ while (ret == UNZ_OK && err == OK) {
bool is_execute = false;
//get filename
@@ -382,287 +435,152 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
print_line("ADDING: " + file + " size: " + itos(data.size()));
total_size += data.size();
- /* write it into our application bundle */
- file = tmp_app_path_name + "/" + file;
-
- /* write the file, need to add chmod */
- FileAccess *f = FileAccess::open(file, FileAccess::WRITE);
- ERR_FAIL_COND_V(!f, ERR_CANT_CREATE)
- f->store_buffer(data.ptr(), data.size());
- f->close();
- memdelete(f);
-
- if (is_execute) {
- // we need execute rights on this file
- chmod(file.utf8().get_data(), 0755);
+ if (use_dmg()) {
+ // write it into our application bundle
+ file = tmp_app_path_name + "/" + file;
+
+ // write the file, need to add chmod
+ FileAccess *f = FileAccess::open(file, FileAccess::WRITE);
+ if (f) {
+ f->store_buffer(data.ptr(), data.size());
+ f->close();
+ if (is_execute) {
+ // Chmod with 0755 if the file is executable
+ f->_chmod(file, 0755);
+ }
+ memdelete(f);
+ } else {
+ err = ERR_CANT_CREATE;
+ }
} else {
- // seems to already be set correctly
- // chmod(file.utf8().get_data(), 0644);
+ // add it to our zip file
+ file = pkg_name + ".app/" + file;
+
+ zip_fileinfo fi;
+ fi.tmz_date.tm_hour = info.tmu_date.tm_hour;
+ fi.tmz_date.tm_min = info.tmu_date.tm_min;
+ fi.tmz_date.tm_sec = info.tmu_date.tm_sec;
+ fi.tmz_date.tm_mon = info.tmu_date.tm_mon;
+ fi.tmz_date.tm_mday = info.tmu_date.tm_mday;
+ fi.tmz_date.tm_year = info.tmu_date.tm_year;
+ fi.dosDate = info.dosDate;
+ fi.internal_fa = info.internal_fa;
+ fi.external_fa = info.external_fa;
+
+ int zerr = zipOpenNewFileInZip(dst_pkg_zip,
+ file.utf8().get_data(),
+ &fi,
+ NULL,
+ 0,
+ NULL,
+ 0,
+ NULL,
+ Z_DEFLATED,
+ Z_DEFAULT_COMPRESSION);
+
+ print_line("OPEN ERR: " + itos(zerr));
+ zerr = zipWriteInFileInZip(dst_pkg_zip, data.ptr(), data.size());
+ print_line("WRITE ERR: " + itos(zerr));
+ zipCloseFileInZip(dst_pkg_zip);
}
}
ret = unzGoToNextFile(src_pkg_zip);
}
- /* we're done with our source zip */
+ // we're done with our source zip
unzClose(src_pkg_zip);
if (!found_binary) {
ERR_PRINTS("Requested template binary '" + binary_to_use + "' not found. It might be missing from your template archive.");
- unzClose(src_pkg_zip);
- return ERR_FILE_NOT_FOUND;
- }
-
- ep.step("Making PKG", 1);
-
- String pack_path = tmp_app_path_name + "/Contents/Resources/" + pkg_name + ".pck";
- Error err = save_pack(p_preset, pack_path);
- // chmod(pack_path.utf8().get_data(), 0644);
-
- if (err) {
- return err;
- }
-
- /* see if we can code sign our new package */
- if (p_preset->get("codesign/identity") != "") {
- ep.step("Code signing bundle", 2);
-
- /* the order in which we code sign is important, this is a bit of a shame or we could do this in our loop that extracts the files from our ZIP */
-
- // start with our application
- err = _code_sign(p_preset, tmp_app_path_name + "/Contents/MacOS/" + pkg_name);
- ERR_FAIL_COND_V(err, err);
-
- ///@TODO we should check the contents of /Contents/Frameworks for frameworks to sign
-
- // we should probably loop through all resources and sign them?
- err = _code_sign(p_preset, tmp_app_path_name + "/Contents/Resources/icon.icns");
- ERR_FAIL_COND_V(err, err);
- err = _code_sign(p_preset, pack_path);
- ERR_FAIL_COND_V(err, err);
- err = _code_sign(p_preset, tmp_app_path_name + "/Contents/Info.plist");
- ERR_FAIL_COND_V(err, err);
- }
-
- /* and finally create a DMG */
- ep.step("Making DMG", 3);
- err = _create_dmg(p_path, pkg_name, tmp_app_path_name);
- ERR_FAIL_COND_V(err, err);
-
- return OK;
-}
-
-#else
-
-/**
- When exporting for OSX from any other platform we don't have access to code signing or creating DMGs so we'll wrap the bundle into a zip file.
-
- Should probably find a nicer way to have just one export method instead of duplicating the method like this but I would the code got very
- messy with switches inside of it.
-**/
-Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
-
- String src_pkg_name;
-
- EditorProgress ep("export", "Exporting for OSX", 104);
-
- if (p_debug)
- src_pkg_name = p_preset->get("custom_package/debug");
- else
- src_pkg_name = p_preset->get("custom_package/release");
-
- if (src_pkg_name == "") {
- String err;
- src_pkg_name = find_export_template("osx.zip", &err);
- if (src_pkg_name == "") {
- EditorNode::add_io_error(err);
- return ERR_FILE_NOT_FOUND;
- }
- }
-
- FileAccess *src_f = NULL;
- zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
-
- ep.step("Creating app", 0);
-
- unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io);
- if (!src_pkg_zip) {
-
- EditorNode::add_io_error("Could not find template app to export:\n" + src_pkg_name);
- return ERR_FILE_NOT_FOUND;
+ err = ERR_FILE_NOT_FOUND;
}
- ERR_FAIL_COND_V(!src_pkg_zip, ERR_CANT_OPEN);
- int ret = unzGoToFirstFile(src_pkg_zip);
+ if (err == OK) {
+ ep.step("Making PKG", 1);
- String binary_to_use = "godot_osx_" + String(p_debug ? "debug" : "release") + ".";
- int bits_mode = p_preset->get("application/bits_mode");
- binary_to_use += String(bits_mode == 0 ? "fat" : bits_mode == 1 ? "64" : "32");
+ if (use_dmg()) {
+ String pack_path = tmp_app_path_name + "/Contents/Resources/" + pkg_name + ".pck";
+ err = save_pack(p_preset, pack_path);
- print_line("binary: " + binary_to_use);
- String pkg_name;
- if (p_preset->get("application/name") != "")
- pkg_name = p_preset->get("application/name"); // app_name
- else if (String(ProjectSettings::get_singleton()->get("application/config/name")) != "")
- pkg_name = String(ProjectSettings::get_singleton()->get("application/config/name"));
- else
- pkg_name = "Unnamed";
-
- /* Open our destination zip file */
- zlib_filefunc_def io2 = io;
- FileAccess *dst_f = NULL;
- io2.opaque = &dst_f;
- zipFile dst_pkg_zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, NULL, &io2);
+ // see if we can code sign our new package
+ String identity = p_preset->get("codesign/identity");
+ if (err == OK && identity != "") {
+ ep.step("Code signing bundle", 2);
- bool found_binary = false;
+ // the order in which we code sign is important, this is a bit of a shame or we could do this in our loop that extracts the files from our ZIP
- while (ret == UNZ_OK) {
-
- //get filename
- unz_file_info info;
- char fname[16384];
- ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, NULL, 0, NULL, 0);
+ // start with our application
+ err = _code_sign(p_preset, tmp_app_path_name + "/Contents/MacOS/" + pkg_name);
- String file = fname;
-
- print_line("READ: " + file);
- Vector<uint8_t> data;
- data.resize(info.uncompressed_size);
-
- //read
- unzOpenCurrentFile(src_pkg_zip);
- unzReadCurrentFile(src_pkg_zip, data.ptr(), data.size());
- unzCloseCurrentFile(src_pkg_zip);
-
- //write
+ ///@TODO we should check the contents of /Contents/Frameworks for frameworks to sign
+ }
- file = file.replace_first("osx_template.app/", "");
+ if (err == OK && identity != "") {
+ // we should probably loop through all resources and sign them?
+ err = _code_sign(p_preset, tmp_app_path_name + "/Contents/Resources/icon.icns");
+ }
- if (file == "Contents/Info.plist") {
- print_line("parse plist");
- _fix_plist(p_preset, data, pkg_name);
- }
+ if (err == OK && identity != "") {
+ err = _code_sign(p_preset, pack_path);
+ }
- if (file.begins_with("Contents/MacOS/godot_")) {
- if (file != "Contents/MacOS/" + binary_to_use) {
- ret = unzGoToNextFile(src_pkg_zip);
- continue; //ignore!
+ if (err == OK && identity != "") {
+ err = _code_sign(p_preset, tmp_app_path_name + "/Contents/Info.plist");
}
- found_binary = true;
- file = "Contents/MacOS/" + pkg_name;
- }
- if (file == "Contents/Resources/icon.icns") {
- //see if there is an icon
- String iconpath;
- if (p_preset->get("application/icon") != "")
- iconpath = p_preset->get("application/icon");
- else
- iconpath = ProjectSettings::get_singleton()->get("application/config/icon");
- print_line("icon? " + iconpath);
- if (iconpath != "") {
- Ref<Image> icon;
- icon.instance();
- icon->load(iconpath);
- if (!icon->empty()) {
- print_line("loaded?");
- _make_icon(icon, data);
- }
+ // and finally create a DMG
+ if (err == OK) {
+ ep.step("Making DMG", 3);
+ err = _create_dmg(p_path, pkg_name, tmp_app_path_name);
}
- //bleh?
- }
- if (data.size() > 0) {
- print_line("ADDING: " + file + " size: " + itos(data.size()));
+ // Clean up temporary .app dir
+ OS::get_singleton()->move_to_trash(tmp_app_path_name);
+ } else {
- /* add it to our zip file */
- file = pkg_name + ".app/" + file;
-
- zip_fileinfo fi;
- fi.tmz_date.tm_hour = info.tmu_date.tm_hour;
- fi.tmz_date.tm_min = info.tmu_date.tm_min;
- fi.tmz_date.tm_sec = info.tmu_date.tm_sec;
- fi.tmz_date.tm_mon = info.tmu_date.tm_mon;
- fi.tmz_date.tm_mday = info.tmu_date.tm_mday;
- fi.tmz_date.tm_year = info.tmu_date.tm_year;
- fi.dosDate = info.dosDate;
- fi.internal_fa = info.internal_fa;
- fi.external_fa = info.external_fa;
-
- int err = zipOpenNewFileInZip(dst_pkg_zip,
- file.utf8().get_data(),
- &fi,
- NULL,
- 0,
- NULL,
- 0,
- NULL,
- Z_DEFLATED,
- Z_DEFAULT_COMPRESSION);
-
- print_line("OPEN ERR: " + itos(err));
- err = zipWriteInFileInZip(dst_pkg_zip, data.ptr(), data.size());
- print_line("WRITE ERR: " + itos(err));
- zipCloseFileInZip(dst_pkg_zip);
+ String pack_path = EditorSettings::get_singleton()->get_settings_path() + "/tmp/" + pkg_name + ".pck";
+ Error err = save_pack(p_preset, pack_path);
+
+ if (err == OK) {
+ zipOpenNewFileInZip(dst_pkg_zip,
+ (pkg_name + ".app/Contents/Resources/" + pkg_name + ".pck").utf8().get_data(),
+ NULL,
+ NULL,
+ 0,
+ NULL,
+ 0,
+ NULL,
+ Z_DEFLATED,
+ Z_DEFAULT_COMPRESSION);
+
+ FileAccess *pf = FileAccess::open(pack_path, FileAccess::READ);
+ if (pf) {
+ const int BSIZE = 16384;
+ uint8_t buf[BSIZE];
+
+ while (true) {
+
+ int r = pf->get_buffer(buf, BSIZE);
+ if (r <= 0)
+ break;
+ zipWriteInFileInZip(dst_pkg_zip, buf, r);
+ }
+ zipCloseFileInZip(dst_pkg_zip);
+ memdelete(pf);
+ } else {
+ err = ERR_CANT_OPEN;
+ }
+ }
}
-
- ret = unzGoToNextFile(src_pkg_zip);
- }
-
- if (!found_binary) {
- ERR_PRINTS("Requested template binary '" + binary_to_use + "' not found. It might be missing from your template archive.");
- zipClose(dst_pkg_zip, NULL);
- unzClose(src_pkg_zip);
- return ERR_FILE_NOT_FOUND;
}
- ep.step("Making PKG", 1);
-
- String pack_path = EditorSettings::get_singleton()->get_settings_path() + "/tmp/" + pkg_name + ".pck";
- Error err = save_pack(p_preset, pack_path);
-
- if (err) {
+ if (dst_pkg_zip) {
zipClose(dst_pkg_zip, NULL);
- unzClose(src_pkg_zip);
- return err;
}
- {
- //write datapack
-
- zipOpenNewFileInZip(dst_pkg_zip,
- (pkg_name + ".app/Contents/Resources/" + pkg_name + ".pck").utf8().get_data(),
- NULL,
- NULL,
- 0,
- NULL,
- 0,
- NULL,
- Z_DEFLATED,
- Z_DEFAULT_COMPRESSION);
-
- FileAccess *pf = FileAccess::open(pack_path, FileAccess::READ);
- ERR_FAIL_COND_V(!pf, ERR_CANT_OPEN);
- const int BSIZE = 16384;
- uint8_t buf[BSIZE];
-
- while (true) {
-
- int r = pf->get_buffer(buf, BSIZE);
- if (r <= 0)
- break;
- zipWriteInFileInZip(dst_pkg_zip, buf, r);
- }
- zipCloseFileInZip(dst_pkg_zip);
- memdelete(pf);
- }
-
- zipClose(dst_pkg_zip, NULL);
- unzClose(src_pkg_zip);
-
return OK;
}
-#endif
bool EditorExportPlatformOSX::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h
index 059dd5afd0..fba53f61b6 100644
--- a/platform/osx/os_osx.h
+++ b/platform/osx/os_osx.h
@@ -31,18 +31,13 @@
#define OS_OSX_H
#include "crash_handler_osx.h"
-#include "drivers/alsa/audio_driver_alsa.h"
-#include "drivers/rtaudio/audio_driver_rtaudio.h"
+#include "drivers/coreaudio/audio_driver_coreaudio.h"
#include "drivers/unix/os_unix.h"
#include "joypad_osx.h"
#include "main/input_default.h"
#include "os/input.h"
-#include "platform/osx/audio_driver_osx.h"
#include "power_osx.h"
#include "servers/audio_server.h"
-#include "servers/physics_2d/physics_2d_server_sw.h"
-#include "servers/physics_2d/physics_2d_server_wrap_mt.h"
-#include "servers/physics_server.h"
#include "servers/visual/rasterizer.h"
#include "servers/visual/visual_server_wrap_mt.h"
#include "servers/visual_server.h"
@@ -64,12 +59,9 @@ public:
List<String> args;
MainLoop *main_loop;
- PhysicsServer *physics_server;
- Physics2DServer *physics_2d_server;
-
IP_Unix *ip_unix;
- AudioDriverOSX audio_driver_osx;
+ AudioDriverCoreAudio audio_driver;
InputDefault *input;
JoypadOSX *joypad_osx;
@@ -114,21 +106,23 @@ public:
CrashHandler crash_handler;
float _mouse_scale(float p_scale) {
- if (display_scale > 1.0)
+ if (_display_scale() > 1.0)
return p_scale;
else
return 1.0;
}
- void _update_window();
+ float _display_scale() const;
+ float _display_scale(id screen) const;
- float display_scale;
+ void _update_window();
protected:
virtual int get_video_driver_count() const;
virtual const char *get_video_driver_name(int p_driver) const;
virtual VideoMode get_default_video_mode() const;
+ virtual void initialize_logger();
virtual void initialize_core();
virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
virtual void finalize();
@@ -143,8 +137,6 @@ public:
virtual String get_name();
- virtual void print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type = ERR_ERROR);
-
virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
virtual void set_cursor_shape(CursorShape p_shape);
@@ -152,7 +144,7 @@ public:
virtual void set_mouse_show(bool p_show);
virtual void set_mouse_grab(bool p_grab);
virtual bool is_mouse_grab_enabled() const;
- virtual void warp_mouse_pos(const Point2 &p_to);
+ virtual void warp_mouse_position(const Point2 &p_to);
virtual Point2 get_mouse_position() const;
virtual int get_mouse_button_state() const;
virtual void set_window_title(const String &p_title);
@@ -184,7 +176,6 @@ public:
virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen = 0) const;
virtual String get_executable_path() const;
- virtual String get_resource_dir() const;
virtual LatinKeyboardVariant get_latin_keyboard_variant() const;
@@ -222,6 +213,9 @@ public:
virtual bool _check_internal_feature_support(const String &p_feature);
+ virtual void set_use_vsync(bool p_enable);
+ virtual bool is_vsync_enabled() const;
+
void run();
void set_mouse_mode(MouseMode p_mode);
@@ -230,6 +224,8 @@ public:
void disable_crash_handler();
bool is_disable_crash_handler() const;
+ virtual Error move_to_trash(const String &p_path);
+
OS_OSX();
};
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index 111cdb0cf1..78acc97676 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -35,7 +35,6 @@
#include "os/keyboard.h"
#include "print_string.h"
#include "sem_osx.h"
-#include "servers/physics/physics_server_sw.h"
#include "servers/visual/visual_server_raster.h"
#include <Carbon/Carbon.h>
@@ -180,13 +179,13 @@ static bool mouse_down_control = false;
if (newBackingScaleFactor != oldBackingScaleFactor) {
//Set new display scale and window size
- OS_OSX::singleton->display_scale = newBackingScaleFactor;
+ float newDisplayScale = OS_OSX::singleton->is_hidpi_allowed() ? newBackingScaleFactor : 1.0;
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;
+ OS_OSX::singleton->window_size.width = fbRect.size.width * newDisplayScale;
+ OS_OSX::singleton->window_size.height = fbRect.size.height * newDisplayScale;
//Update context
if (OS_OSX::singleton->main_loop) {
@@ -206,8 +205,9 @@ static bool mouse_down_control = false;
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;
+ float displayScale = OS_OSX::singleton->_display_scale();
+ OS_OSX::singleton->window_size.width = fbRect.size.width * displayScale;
+ OS_OSX::singleton->window_size.height = fbRect.size.height * displayScale;
if (OS_OSX::singleton->main_loop) {
Main::force_redraw();
@@ -352,7 +352,8 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
- (NSRect)firstRectForCharacterRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange {
const NSRect contentRect = [OS_OSX::singleton->window_view frame];
- NSRect pointInWindowRect = NSMakeRect(OS_OSX::singleton->im_position.x / OS_OSX::singleton->display_scale, contentRect.size.height - (OS_OSX::singleton->im_position.y / OS_OSX::singleton->display_scale) - 1, 0, 0);
+ float displayScale = OS_OSX::singleton->_display_scale();
+ NSRect pointInWindowRect = NSMakeRect(OS_OSX::singleton->im_position.x / displayScale, contentRect.size.height - (OS_OSX::singleton->im_position.y / displayScale) - 1, 0, 0);
NSPoint pointOnScreen = [[OS_OSX::singleton->window_view window] convertRectToScreen:pointInWindowRect].origin;
return NSMakeRect(pointOnScreen.x, pointOnScreen.y, 0, 0);
@@ -940,15 +941,6 @@ void OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
kTISNotifySelectedKeyboardInputSourceChanged, NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
- if (is_hidpi_allowed() && [[NSScreen mainScreen] respondsToSelector:@selector(backingScaleFactor)]) {
- for (NSScreen *screen in [NSScreen screens]) {
- float s = [screen backingScaleFactor];
- if (s > display_scale) {
- display_scale = s;
- }
- }
- }
-
window_delegate = [[GodotWindowDelegate alloc] init];
// Don't use accumulation buffer support; it's not accelerated
@@ -972,10 +964,19 @@ void OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
window_view = [[GodotContentView alloc] init];
- window_size.width = p_desired.width * display_scale;
- window_size.height = p_desired.height * display_scale;
+ float displayScale = 1.0;
+ if (is_hidpi_allowed()) {
+ // note that mainScreen is not screen #0 but the one with the keyboard focus.
+ NSScreen *screen = [NSScreen mainScreen];
+ if ([screen respondsToSelector:@selector(backingScaleFactor)]) {
+ displayScale = fmax(displayScale, [screen backingScaleFactor]);
+ }
+ }
+
+ window_size.width = p_desired.width * displayScale;
+ window_size.height = p_desired.height * displayScale;
- if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6 && display_scale > 1) {
+ if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6 && displayScale > 1.0) {
[window_view setWantsBestResolutionOpenGLSurface:YES];
//if (current_videomode.resizable)
[window_object setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
@@ -1071,7 +1072,7 @@ void OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
bool use_gl2 = p_video_driver != 1;
- AudioDriverManager::add_driver(&audio_driver_osx);
+ AudioDriverManager::add_driver(&audio_driver);
// only opengl support here...
RasterizerGLES3::register_config();
@@ -1090,13 +1091,6 @@ void OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
AudioDriverManager::initialize(p_audio_driver);
- //
- physics_server = memnew(PhysicsServerSW);
- physics_server->init();
- //physics_2d_server = memnew( Physics2DServerSW );
- physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>();
- physics_2d_server->init();
-
input = memnew(InputDefault);
joypad_osx = memnew(JoypadOSX);
@@ -1118,12 +1112,6 @@ void OS_OSX::finalize() {
visual_server->finish();
memdelete(visual_server);
//memdelete(rasterizer);
-
- physics_server->finish();
- memdelete(physics_server);
-
- physics_2d_server->finish();
- memdelete(physics_2d_server);
}
void OS_OSX::set_main_loop(MainLoop *p_main_loop) {
@@ -1145,43 +1133,69 @@ String OS_OSX::get_name() {
return "OSX";
}
-void OS_OSX::print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type) {
-
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200
- if (!_print_error_enabled)
- return;
-
- const char *err_details;
- if (p_rationale && p_rationale[0])
- err_details = p_rationale;
- else
- err_details = p_code;
+class OSXTerminalLogger : public StdLogger {
+public:
+ virtual void log_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type = ERR_ERROR) {
+ if (!should_log(true)) {
+ return;
+ }
- switch (p_type) {
- case ERR_ERROR:
- os_log_error(OS_LOG_DEFAULT, "ERROR: %{public}s: %{public}s\nAt: %{public}s:%i.", p_function, err_details, p_file, p_line);
- print("\E[1;31mERROR: %s: \E[0m\E[1m%s\n", p_function, err_details);
- print("\E[0;31m At: %s:%i.\E[0m\n", p_file, p_line);
- break;
- case ERR_WARNING:
- os_log_info(OS_LOG_DEFAULT, "WARNING: %{public}s: %{public}s\nAt: %{public}s:%i.", p_function, err_details, p_file, p_line);
- print("\E[1;33mWARNING: %s: \E[0m\E[1m%s\n", p_function, err_details);
- print("\E[0;33m At: %s:%i.\E[0m\n", p_file, p_line);
- break;
- case ERR_SCRIPT:
- os_log_error(OS_LOG_DEFAULT, "SCRIPT ERROR: %{public}s: %{public}s\nAt: %{public}s:%i.", p_function, err_details, p_file, p_line);
- print("\E[1;35mSCRIPT ERROR: %s: \E[0m\E[1m%s\n", p_function, err_details);
- print("\E[0;35m At: %s:%i.\E[0m\n", p_file, p_line);
- break;
- case ERR_SHADER:
- os_log_error(OS_LOG_DEFAULT, "SHADER ERROR: %{public}s: %{public}s\nAt: %{public}s:%i.", p_function, err_details, p_file, p_line);
- print("\E[1;36mSHADER ERROR: %s: \E[0m\E[1m%s\n", p_function, err_details);
- print("\E[0;36m At: %s:%i.\E[0m\n", p_file, p_line);
- break;
+ const char *err_details;
+ if (p_rationale && p_rationale[0])
+ err_details = p_rationale;
+ else
+ err_details = p_code;
+
+ switch (p_type) {
+ case ERR_WARNING:
+ os_log_info(OS_LOG_DEFAULT,
+ "WARNING: %{public}s: %{public}s\nAt: %{public}s:%i.",
+ p_function, err_details, p_file, p_line);
+ logf_error("\E[1;33mWARNING: %s: \E[0m\E[1m%s\n", p_function,
+ err_details);
+ logf_error("\E[0;33m At: %s:%i.\E[0m\n", p_file, p_line);
+ break;
+ case ERR_SCRIPT:
+ os_log_error(OS_LOG_DEFAULT,
+ "SCRIPT ERROR: %{public}s: %{public}s\nAt: %{public}s:%i.",
+ p_function, err_details, p_file, p_line);
+ logf_error("\E[1;35mSCRIPT ERROR: %s: \E[0m\E[1m%s\n", p_function,
+ err_details);
+ logf_error("\E[0;35m At: %s:%i.\E[0m\n", p_file, p_line);
+ break;
+ case ERR_SHADER:
+ os_log_error(OS_LOG_DEFAULT,
+ "SHADER ERROR: %{public}s: %{public}s\nAt: %{public}s:%i.",
+ p_function, err_details, p_file, p_line);
+ logf_error("\E[1;36mSHADER ERROR: %s: \E[0m\E[1m%s\n", p_function,
+ err_details);
+ logf_error("\E[0;36m At: %s:%i.\E[0m\n", p_file, p_line);
+ break;
+ case ERR_ERROR:
+ default:
+ os_log_error(OS_LOG_DEFAULT,
+ "ERROR: %{public}s: %{public}s\nAt: %{public}s:%i.",
+ p_function, err_details, p_file, p_line);
+ logf_error("\E[1;31mERROR: %s: \E[0m\E[1m%s\n", p_function, err_details);
+ logf_error("\E[0;31m At: %s:%i.\E[0m\n", p_file, p_line);
+ break;
+ }
}
+};
+
#else
- OS_Unix::print_error(p_function, p_file, p_line, p_code, p_rationale, p_type);
+
+typedef UnixTerminalLogger OSXTerminalLogger;
#endif
+
+void OS_OSX::initialize_logger() {
+ Vector<Logger *> loggers;
+ loggers.push_back(memnew(OSXTerminalLogger));
+ // FIXME: Reenable once we figure out how to get this properly in user://
+ // instead of littering the user's working dirs (res:// + pwd) with log files (GH-12277)
+ //loggers.push_back(memnew(RotatedFileLogger("user://logs/log.txt")));
+ _set_logger(memnew(CompositeLogger(loggers)));
}
void OS_OSX::alert(const String &p_alert, const String &p_title) {
@@ -1240,7 +1254,7 @@ bool OS_OSX::is_mouse_grab_enabled() const {
return mouse_grab;
}
-void OS_OSX::warp_mouse_pos(const Point2 &p_to) {
+void OS_OSX::warp_mouse_position(const Point2 &p_to) {
//copied from windows impl with osx native calls
if (mouse_mode == MOUSE_MODE_CAPTURED) {
@@ -1250,7 +1264,8 @@ void OS_OSX::warp_mouse_pos(const Point2 &p_to) {
//local point in window coords
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);
+ float displayScale = _display_scale();
+ NSRect pointInWindowRect = NSMakeRect(p_to.x / displayScale, contentRect.size.height - (p_to.y / displayScale) - 1, 0, 0);
NSPoint pointOnScreen = [[window_view window] convertRectToScreen:pointInWindowRect].origin;
//point in scren coords
@@ -1451,17 +1466,17 @@ int OS_OSX::get_screen_count() const {
return [screenArray count];
};
+static int get_screen_index(NSScreen *screen) {
+ const NSUInteger index = [[NSScreen screens] indexOfObject:screen];
+ return index == NSNotFound ? 0 : index;
+}
+
int OS_OSX::get_current_screen() const {
- 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;
+ if (window_object) {
+ return get_screen_index([window_object screen]);
+ } else {
+ return get_screen_index([NSScreen mainScreen]);
}
- return 0;
};
void OS_OSX::set_current_screen(int p_screen) {
@@ -1476,12 +1491,7 @@ Point2 OS_OSX::get_screen_position(int p_screen) const {
NSArray *screenArray = [NSScreen screens];
if (p_screen < [screenArray count]) {
- float displayScale = 1.0;
-
- if (display_scale > 1.0 && [[screenArray objectAtIndex:p_screen] respondsToSelector:@selector(backingScaleFactor)]) {
- displayScale = [[screenArray objectAtIndex:p_screen] backingScaleFactor];
- }
-
+ float displayScale = _display_scale([screenArray objectAtIndex:p_screen]);
NSRect nsrect = [[screenArray objectAtIndex:p_screen] frame];
return Point2(nsrect.origin.x, nsrect.origin.y) * displayScale;
}
@@ -1496,12 +1506,7 @@ int OS_OSX::get_screen_dpi(int p_screen) const {
NSArray *screenArray = [NSScreen screens];
if (p_screen < [screenArray count]) {
- float displayScale = 1.0;
-
- if (display_scale > 1.0 && [[screenArray objectAtIndex:p_screen] respondsToSelector:@selector(backingScaleFactor)]) {
- displayScale = [[screenArray objectAtIndex:p_screen] backingScaleFactor];
- }
-
+ float displayScale = _display_scale([screenArray objectAtIndex:p_screen]);
NSDictionary *description = [[screenArray objectAtIndex:p_screen] deviceDescription];
NSSize displayPixelSize = [[description objectForKey:NSDeviceSize] sizeValue];
CGSize displayPhysicalSize = CGDisplayScreenSize(
@@ -1520,12 +1525,7 @@ Size2 OS_OSX::get_screen_size(int p_screen) const {
NSArray *screenArray = [NSScreen screens];
if (p_screen < [screenArray count]) {
- float displayScale = 1.0;
-
- if (display_scale > 1.0 && [[screenArray objectAtIndex:p_screen] respondsToSelector:@selector(backingScaleFactor)]) {
- displayScale = [[screenArray objectAtIndex:p_screen] backingScaleFactor];
- }
-
+ float displayScale = _display_scale([screenArray objectAtIndex:p_screen]);
// 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;
@@ -1559,10 +1559,28 @@ void OS_OSX::_update_window() {
}
}
+float OS_OSX::_display_scale() const {
+ if (window_object) {
+ return _display_scale([window_object screen]);
+ } else {
+ return _display_scale([NSScreen mainScreen]);
+ }
+}
+
+float OS_OSX::_display_scale(id screen) const {
+ if (is_hidpi_allowed()) {
+ if ([screen respondsToSelector:@selector(backingScaleFactor)]) {
+ return fmax(1.0, [screen backingScaleFactor]);
+ }
+ } else {
+ return 1.0;
+ }
+}
+
Point2 OS_OSX::get_window_position() const {
Size2 wp([window_object frame].origin.x, [window_object frame].origin.y);
- wp *= display_scale;
+ wp *= _display_scale();
return wp;
};
@@ -1570,10 +1588,11 @@ void OS_OSX::set_window_position(const Point2 &p_position) {
Size2 scr = get_screen_size();
NSPoint pos;
+ float displayScale = _display_scale();
- pos.x = p_position.x / display_scale;
+ pos.x = p_position.x / displayScale;
// For OS X the y starts at the bottom
- pos.y = (scr.height - p_position.y) / display_scale;
+ pos.y = (scr.height - p_position.y) / displayScale;
[window_object setFrameTopLeftPoint:pos];
@@ -1733,17 +1752,6 @@ String OS_OSX::get_executable_path() const {
}
}
-String OS_OSX::get_resource_dir() const {
- // start with our executable path
- String path = get_executable_path();
-
- int pos = path.find_last("/Contents/MacOS/");
- if (pos < 0)
- return OS::get_resource_dir();
-
- return path.substr(0, pos) + "/Contents/Resources/";
-}
-
// Returns string representation of keys, if they are printable.
//
static NSString *createStringForKeys(const CGKeyCode *keyCode, int length) {
@@ -1812,6 +1820,8 @@ OS::LatinKeyboardVariant OS_OSX::get_latin_keyboard_variant() const {
layout = LATIN_KEYBOARD_DVORAK;
} else if ([test isEqualToString:@"xvlcwk"]) {
layout = LATIN_KEYBOARD_NEO;
+ } else if ([test isEqualToString:@"qwfpgj"]) {
+ layout = LATIN_KEYBOARD_COLEMAK;
}
[test release];
@@ -1921,6 +1931,36 @@ int OS_OSX::get_power_percent_left() {
return power_manager->get_power_percent_left();
}
+Error OS_OSX::move_to_trash(const String &p_path) {
+ NSFileManager *fm = [NSFileManager defaultManager];
+ NSURL *url = [NSURL fileURLWithPath:@(p_path.utf8().get_data())];
+ NSError *err;
+
+ if (![fm trashItemAtURL:url resultingItemURL:nil error:&err]) {
+ ERR_PRINTS("trashItemAtURL error: " + String(err.localizedDescription.UTF8String));
+ return FAILED;
+ }
+
+ return OK;
+}
+
+void OS_OSX::set_use_vsync(bool p_enable) {
+ CGLContextObj ctx = CGLGetCurrentContext();
+ if (ctx) {
+ GLint swapInterval = p_enable ? 1 : 0;
+ CGLSetParameter(ctx, kCGLCPSwapInterval, &swapInterval);
+ }
+}
+
+bool OS_OSX::is_vsync_enabled() const {
+ GLint swapInterval = 0;
+ CGLContextObj ctx = CGLGetCurrentContext();
+ if (ctx) {
+ CGLGetParameter(ctx, kCGLCPSwapInterval, &swapInterval);
+ }
+ return swapInterval ? true : false;
+}
+
OS_OSX *OS_OSX::singleton = NULL;
OS_OSX::OS_OSX() {
@@ -2013,7 +2053,8 @@ OS_OSX::OS_OSX() {
minimized = false;
window_size = Vector2(1024, 600);
zoomed = false;
- display_scale = 1.0;
+
+ _set_logger(memnew(OSXTerminalLogger));
}
bool OS_OSX::_check_internal_feature_support(const String &p_feature) {
diff --git a/platform/server/detect.py b/platform/server/detect.py
index 2bb4b59e94..ffec2af933 100644
--- a/platform/server/detect.py
+++ b/platform/server/detect.py
@@ -12,6 +12,9 @@ def get_name():
def can_build():
+ # Doesn't build against Godot 3.0 for now, disable to avoid confusing users
+ return False
+
if (os.name != "posix" or sys.platform == "darwin"):
return False
@@ -19,9 +22,9 @@ def can_build():
def get_opts():
-
+ from SCons.Variables import BoolVariable
return [
- ('use_llvm', 'Use the LLVM compiler', 'no'),
+ BoolVariable('use_llvm', 'Use the LLVM compiler', False),
]
@@ -52,7 +55,7 @@ def configure(env):
## Compiler configuration
- if (env["use_llvm"] == "yes"):
+ if env['use_llvm']:
if ('clang++' not in env['CXX']):
env["CC"] = "clang"
env["CXX"] = "clang++"
@@ -64,66 +67,60 @@ def configure(env):
# FIXME: Check for existence of the libs before parsing their flags with pkg-config
- if (env['builtin_openssl'] == 'no'):
- # Currently not compatible with OpenSSL 1.1.0+
- # https://github.com/godotengine/godot/issues/8624
- import subprocess
- openssl_version = subprocess.check_output(['pkg-config', 'openssl', '--modversion']).strip('\n')
- if (openssl_version >= "1.1.0"):
- print("Error: Found system-installed OpenSSL %s, currently only supporting version 1.0.x." % openssl_version)
- print("Aborting.. You can compile with 'builtin_openssl=yes' to use the bundled version.\n")
- sys.exit(255)
-
+ if not env['builtin_openssl']:
env.ParseConfig('pkg-config openssl --cflags --libs')
- if (env['builtin_libwebp'] == 'no'):
+ if not env['builtin_libwebp']:
env.ParseConfig('pkg-config libwebp --cflags --libs')
# freetype depends on libpng and zlib, so bundling one of them while keeping others
# as shared libraries leads to weird issues
- if (env['builtin_freetype'] == 'yes' or env['builtin_libpng'] == 'yes' or env['builtin_zlib'] == 'yes'):
- env['builtin_freetype'] = 'yes'
- env['builtin_libpng'] = 'yes'
- env['builtin_zlib'] = 'yes'
+ if env['builtin_freetype'] or env['builtin_libpng'] or env['builtin_zlib']:
+ env['builtin_freetype'] = True
+ env['builtin_libpng'] = True
+ env['builtin_zlib'] = True
- if (env['builtin_freetype'] == 'no'):
+ if not env['builtin_freetype']:
env.ParseConfig('pkg-config freetype2 --cflags --libs')
- if (env['builtin_libpng'] == 'no'):
+ if not env['builtin_libpng']:
env.ParseConfig('pkg-config libpng --cflags --libs')
- if (env['builtin_enet'] == 'no'):
+ if not env['builtin_enet']:
env.ParseConfig('pkg-config libenet --cflags --libs')
- if (env['builtin_squish'] == 'no' and env["tools"] == "yes"):
+ if not env['builtin_squish'] and env['tools']:
env.ParseConfig('pkg-config libsquish --cflags --libs')
+ if not env['builtin_zstd']:
+ env.ParseConfig('pkg-config libzstd --cflags --libs')
+
# Sound and video libraries
# Keep the order as it triggers chained dependencies (ogg needed by others, etc.)
- if (env['builtin_libtheora'] == 'no'):
- env['builtin_libogg'] = 'no' # Needed to link against system libtheora
- env['builtin_libvorbis'] = 'no' # Needed to link against system libtheora
+ if not env['builtin_libtheora']:
+ env['builtin_libogg'] = False # Needed to link against system libtheora
+ env['builtin_libvorbis'] = False # Needed to link against system libtheora
env.ParseConfig('pkg-config theora theoradec --cflags --libs')
- if (env['builtin_libvpx'] == 'no'):
+ if not env['builtin_libvpx']:
env.ParseConfig('pkg-config vpx --cflags --libs')
- if (env['builtin_libvorbis'] == 'no'):
- env['builtin_libogg'] = 'no' # Needed to link against system libvorbis
+ if not env['builtin_libvorbis']:
+ env['builtin_libogg'] = False # Needed to link against system libvorbis
env.ParseConfig('pkg-config vorbis vorbisfile --cflags --libs')
- if (env['builtin_opus'] == 'no'):
- env['builtin_libogg'] = 'no' # Needed to link against system opus
+ if not env['builtin_opus']:
+ env['builtin_libogg'] = False # Needed to link against system opus
env.ParseConfig('pkg-config opus opusfile --cflags --libs')
- if (env['builtin_libogg'] == 'no'):
+ if not env['builtin_libogg']:
env.ParseConfig('pkg-config ogg --cflags --libs')
## Flags
# Linkflags below this line should typically stay the last ones
- if (env['builtin_zlib'] == 'no'):
+ if not env['builtin_zlib']:
env.ParseConfig('pkg-config zlib --cflags --libs')
env.Append(CPPPATH=['#platform/server'])
diff --git a/platform/server/os_server.cpp b/platform/server/os_server.cpp
index 300c5cffcc..80c04aa5ad 100644
--- a/platform/server/os_server.cpp
+++ b/platform/server/os_server.cpp
@@ -31,7 +31,6 @@
//#include "servers/visual/rasterizer_dummy.h"
#include "os_server.h"
#include "print_string.h"
-#include "servers/physics/physics_server_sw.h"
#include <stdio.h>
#include <stdlib.h>
@@ -75,11 +74,6 @@ void OS_Server::initialize(const VideoMode &p_desired, int p_video_driver, int p
ERR_FAIL_COND(!visual_server);
visual_server->init();
- //
- physics_server = memnew(PhysicsServerSW);
- physics_server->init();
- physics_2d_server = memnew(Physics2DServerSW);
- physics_2d_server->init();
input = memnew(InputDefault);
@@ -111,12 +105,6 @@ void OS_Server::finalize() {
memdelete(visual_server);
//memdelete(rasterizer);
- physics_server->finish();
- memdelete(physics_server);
-
- physics_2d_server->finish();
- memdelete(physics_2d_server);
-
memdelete(input);
args.clear();
diff --git a/platform/server/os_server.h b/platform/server/os_server.h
index ba12f649be..630c82ccdd 100644
--- a/platform/server/os_server.h
+++ b/platform/server/os_server.h
@@ -35,8 +35,6 @@
#include "drivers/unix/os_unix.h"
#include "main/input_default.h"
#include "servers/audio_server.h"
-#include "servers/physics_2d/physics_2d_server_sw.h"
-#include "servers/physics_server.h"
#include "servers/visual/rasterizer.h"
#include "servers/visual_server.h"
@@ -56,9 +54,6 @@ class OS_Server : public OS_Unix {
bool grab;
- PhysicsServer *physics_server;
- Physics2DServer *physics_2d_server;
-
virtual void delete_main_loop();
IP_Unix *ip_unix;
diff --git a/platform/uwp/SCsub b/platform/uwp/SCsub
index 7ee5aa2ac3..bbd329a7e5 100644
--- a/platform/uwp/SCsub
+++ b/platform/uwp/SCsub
@@ -8,6 +8,7 @@ files = [
'#platform/windows/packet_peer_udp_winsock.cpp',
'#platform/windows/stream_peer_winsock.cpp',
'#platform/windows/key_mapping_win.cpp',
+ '#platform/windows/windows_terminal_logger.cpp',
'joypad_uwp.cpp',
'power_uwp.cpp',
'gl_context_egl.cpp',
diff --git a/platform/uwp/detect.py b/platform/uwp/detect.py
index 23929dd804..af53f97446 100644
--- a/platform/uwp/detect.py
+++ b/platform/uwp/detect.py
@@ -33,8 +33,8 @@ def get_opts():
def get_flags():
return [
- ('tools', 'no'),
- ('xaudio2', 'yes'),
+ ('tools', False),
+ ('xaudio2', True),
]
diff --git a/platform/uwp/export/export.cpp b/platform/uwp/export/export.cpp
index 25d44c24b5..d66bcaa91c 100644
--- a/platform/uwp/export/export.cpp
+++ b/platform/uwp/export/export.cpp
@@ -471,7 +471,7 @@ void AppxPackager::add_file(String p_file_name, const uint8_t *p_buffer, size_t
meta.uncompressed_size = p_len;
meta.compressed_size = p_len;
meta.compressed = p_compress;
- meta.zip_offset = package->get_pos();
+ meta.zip_offset = package->get_position();
Vector<uint8_t> file_buffer;
@@ -619,11 +619,11 @@ void AppxPackager::finish() {
// Write central directory
EditorNode::progress_task_step("export", "Finishing package...", 6);
- central_dir_offset = package->get_pos();
+ central_dir_offset = package->get_position();
package->store_buffer(central_dir_data.ptr(), central_dir_data.size());
// End record
- end_of_central_dir_offset = package->get_pos();
+ end_of_central_dir_offset = package->get_position();
Vector<uint8_t> end_record = make_end_of_central_record();
package->store_buffer(end_record.ptr(), end_record.size());
diff --git a/platform/uwp/gl_context_egl.cpp b/platform/uwp/gl_context_egl.cpp
index dd186c97d6..ed3db65cdf 100644
--- a/platform/uwp/gl_context_egl.cpp
+++ b/platform/uwp/gl_context_egl.cpp
@@ -31,7 +31,7 @@
#include "EGL/eglext.h"
-using namespace Platform;
+using Platform::Exception;
void ContextEGL::release_current() {
@@ -103,23 +103,23 @@ Error ContextEGL::initialize() {
const EGLint displayAttributes[] =
{
- /*EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
- EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, 9,
- EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, 3,
- EGL_NONE,*/
- // These are the default display attributes, used to request ANGLE's D3D11 renderer.
- // eglInitialize will only succeed with these attributes if the hardware supports D3D11 Feature Level 10_0+.
- EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
-
- // EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER is an optimization that can have large performance benefits on mobile devices.
- // Its syntax is subject to change, though. Please update your Visual Studio templates if you experience compilation issues with it.
- //EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL_TRUE,
-
- // EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE is an option that enables ANGLE to automatically call
- // the IDXGIDevice3::Trim method on behalf of the application when it gets suspended.
- // Calling IDXGIDevice3::Trim when an application is suspended is a Windows Store application certification requirement.
- EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE, EGL_TRUE,
- EGL_NONE,
+ /*EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
+ EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, 9,
+ EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, 3,
+ EGL_NONE,*/
+ // These are the default display attributes, used to request ANGLE's D3D11 renderer.
+ // eglInitialize will only succeed with these attributes if the hardware supports D3D11 Feature Level 10_0+.
+ EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
+
+ // EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER is an optimization that can have large performance benefits on mobile devices.
+ // Its syntax is subject to change, though. Please update your Visual Studio templates if you experience compilation issues with it.
+ //EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL_TRUE,
+
+ // EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE is an option that enables ANGLE to automatically call
+ // the IDXGIDevice3::Trim method on behalf of the application when it gets suspended.
+ // Calling IDXGIDevice3::Trim when an application is suspended is a Windows Store application certification requirement.
+ EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE, EGL_TRUE,
+ EGL_NONE,
};
PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT = reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC>(eglGetProcAddress("eglGetPlatformDisplayEXT"));
diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp
index b909ccccd6..8db2a749df 100644
--- a/platform/uwp/os_uwp.cpp
+++ b/platform/uwp/os_uwp.cpp
@@ -40,6 +40,7 @@
#include "platform/windows/packet_peer_udp_winsock.h"
#include "platform/windows/stream_peer_winsock.h"
#include "platform/windows/tcp_server_winsock.h"
+#include "platform/windows/windows_terminal_logger.h"
#include "project_settings.h"
#include "servers/audio_server.h"
#include "servers/visual/visual_server_raster.h"
@@ -182,6 +183,15 @@ void OSUWP::initialize_core() {
cursor_shape = CURSOR_ARROW;
}
+void OSUWP::initialize_logger() {
+ Vector<Logger *> loggers;
+ loggers.push_back(memnew(WindowsTerminalLogger));
+ // FIXME: Reenable once we figure out how to get this properly in user://
+ // instead of littering the user's working dirs (res:// + pwd) with log files (GH-12277)
+ //loggers.push_back(memnew(RotatedFileLogger("user://logs/log.txt")));
+ _set_logger(memnew(CompositeLogger(loggers)));
+}
+
bool OSUWP::can_draw() const {
return !minimized;
@@ -254,13 +264,6 @@ void OSUWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_aud
}
*/
- //
- physics_server = memnew(PhysicsServerSW);
- physics_server->init();
-
- physics_2d_server = memnew(Physics2DServerSW);
- physics_2d_server->init();
-
visual_server->init();
input = memnew(InputDefault);
@@ -359,44 +362,12 @@ void OSUWP::finalize() {
memdelete(input);
- physics_server->finish();
- memdelete(physics_server);
-
- physics_2d_server->finish();
- memdelete(physics_2d_server);
-
joypad = nullptr;
}
void OSUWP::finalize_core() {
}
-void OSUWP::vprint(const char *p_format, va_list p_list, bool p_stderr) {
-
- char buf[16384 + 1];
- int len = vsnprintf(buf, 16384, p_format, p_list);
- if (len <= 0)
- return;
- buf[len] = 0;
-
- int wlen = MultiByteToWideChar(CP_UTF8, 0, buf, len, NULL, 0);
- if (wlen < 0)
- return;
-
- wchar_t *wbuf = (wchar_t *)malloc((len + 1) * sizeof(wchar_t));
- MultiByteToWideChar(CP_UTF8, 0, buf, len, wbuf, wlen);
- wbuf[wlen] = 0;
-
- if (p_stderr)
- fwprintf(stderr, L"%s", wbuf);
- else
- wprintf(L"%s", wbuf);
-
- free(wbuf);
-
- fflush(stdout);
-};
-
void OSUWP::alert(const String &p_alert, const String &p_title) {
Platform::String ^ alert = ref new Platform::String(p_alert.c_str());
@@ -520,30 +491,6 @@ OS::VideoMode OSUWP::get_video_mode(int p_screen) const {
void OSUWP::get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen) const {
}
-void OSUWP::print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type) {
-
- const char *err_details;
- if (p_rationale && p_rationale[0])
- err_details = p_rationale;
- else
- err_details = p_code;
-
- switch (p_type) {
- case ERR_ERROR:
- print("ERROR: %s: %s\n", p_function, err_details);
- print(" At: %s:%i\n", p_file, p_line);
- break;
- case ERR_WARNING:
- print("WARNING: %s: %s\n", p_function, err_details);
- print(" At: %s:%i\n", p_file, p_line);
- break;
- case ERR_SCRIPT:
- print("SCRIPT ERROR: %s: %s\n", p_function, err_details);
- print(" At: %s:%i\n", p_file, p_line);
- break;
- }
-}
-
String OSUWP::get_name() {
return "UWP";
@@ -716,7 +663,7 @@ void OSUWP::set_cursor_shape(CursorShape p_shape) {
cursor_shape = p_shape;
}
-Error OSUWP::execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id, String *r_pipe, int *r_exitcode) {
+Error OSUWP::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) {
return FAILED;
};
@@ -890,6 +837,8 @@ OSUWP::OSUWP() {
mouse_mode_changed = CreateEvent(NULL, TRUE, FALSE, L"os_mouse_mode_changed");
AudioDriverManager::add_driver(&audio_driver);
+
+ _set_logger(memnew(WindowsTerminalLogger));
}
OSUWP::~OSUWP() {
diff --git a/platform/uwp/os_uwp.h b/platform/uwp/os_uwp.h
index a7a5d32cb9..e46e4cc020 100644
--- a/platform/uwp/os_uwp.h
+++ b/platform/uwp/os_uwp.h
@@ -40,8 +40,6 @@
#include "os/os.h"
#include "power_uwp.h"
#include "servers/audio_server.h"
-#include "servers/physics/physics_server_sw.h"
-#include "servers/physics_2d/physics_2d_server_sw.h"
#include "servers/visual/rasterizer.h"
#include "servers/visual_server.h"
@@ -94,8 +92,6 @@ private:
int old_x, old_y;
Point2i center;
VisualServer *visual_server;
- PhysicsServer *physics_server;
- Physics2DServer *physics_2d_server;
int pressrc;
ContextEGL *gl_context;
@@ -163,6 +159,7 @@ protected:
virtual int get_audio_driver_count() const;
virtual const char *get_audio_driver_name(int p_driver) const;
+ virtual void initialize_logger();
virtual void initialize_core();
virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
@@ -180,9 +177,6 @@ public:
// Event to send to the app wrapper
HANDLE mouse_mode_changed;
- void print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type);
-
- virtual void vprint(const char *p_format, va_list p_list, bool p_stderr = false);
virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
String get_stdin_string(bool p_block);
@@ -217,7 +211,7 @@ public:
virtual void delay_usec(uint32_t p_usec) const;
virtual uint64_t get_ticks_usec() const;
- virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL);
+ virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL, bool read_stderr = false);
virtual Error kill(const ProcessID &p_pid);
virtual bool has_environment(const String &p_var) const;
diff --git a/platform/windows/SCsub b/platform/windows/SCsub
index b56a5c6a80..aa9eb3e69b 100644
--- a/platform/windows/SCsub
+++ b/platform/windows/SCsub
@@ -1,7 +1,12 @@
#!/usr/bin/env python
+import os
Import('env')
+def make_debug_mingw(target, source, env):
+ os.system('objcopy --only-keep-debug %s %s.debug' % (target[0], target[0]))
+ os.system('strip --strip-debug --strip-unneeded %s' % (target[0]))
+ os.system('objcopy --add-gnu-debuglink=%s.debug %s' % (target[0], target[0]))
common_win = [
"context_gl_win.cpp",
@@ -14,6 +19,7 @@ common_win = [
"stream_peer_winsock.cpp",
"joypad.cpp",
"power_windows.cpp",
+ "windows_terminal_logger.cpp"
]
restarget = "godot_res" + env["OBJSUFFIX"]
@@ -22,10 +28,14 @@ obj = env.RES(restarget, 'godot_res.rc')
common_win.append(obj)
-env.Program('#bin/godot', ['godot_win.cpp'] + common_win, PROGSUFFIX=env["PROGSUFFIX"])
+binary = env.Program('#bin/godot', ['godot_win.cpp'] + common_win, PROGSUFFIX=env["PROGSUFFIX"])
# Microsoft Visual Studio Project Generation
-if (env['vsproj']) == "yes":
+if env['vsproj']:
env.vs_srcs = env.vs_srcs + ["platform/windows/godot_win.cpp"]
for x in common_win:
env.vs_srcs = env.vs_srcs + ["platform/windows/" + str(x)]
+
+if not os.getenv("VCINSTALLDIR"):
+ if env["debug_symbols"] == "full" or env["debug_symbols"] == "yes":
+ env.AddPostAction(binary, make_debug_mingw)
diff --git a/platform/windows/context_gl_win.cpp b/platform/windows/context_gl_win.cpp
index 8640f27699..64b6d202a1 100644
--- a/platform/windows/context_gl_win.cpp
+++ b/platform/windows/context_gl_win.cpp
@@ -27,7 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) || defined(GLES2_ENABLED)
+#if defined(OPENGL_ENABLED) || defined(GLES2_ENABLED)
//
// C++ Implementation: context_gl_x11
diff --git a/platform/windows/context_gl_win.h b/platform/windows/context_gl_win.h
index 912d4d0133..0059cbc311 100644
--- a/platform/windows/context_gl_win.h
+++ b/platform/windows/context_gl_win.h
@@ -27,7 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) || defined(GLES2_ENABLED)
+#if defined(OPENGL_ENABLED) || defined(GLES2_ENABLED)
//
// C++ Interface: context_gl_x11
//
diff --git a/platform/windows/crash_handler_win.cpp b/platform/windows/crash_handler_win.cpp
index c9385f36d6..feea3911b2 100644
--- a/platform/windows/crash_handler_win.cpp
+++ b/platform/windows/crash_handler_win.cpp
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "main/main.h"
#include "os_windows.h"
+#include "project_settings.h"
#ifdef CRASH_HANDLER_EXCEPTION
@@ -116,7 +117,7 @@ DWORD CrashHandlerException(EXCEPTION_POINTERS *ep) {
DWORD cbNeeded;
std::vector<HMODULE> module_handles(1);
- if (OS::get_singleton() == NULL || OS::get_singleton()->is_disable_crash_handler()) {
+ if (OS::get_singleton() == NULL || OS::get_singleton()->is_disable_crash_handler() || IsDebuggerPresent()) {
return EXCEPTION_CONTINUE_SEARCH;
}
@@ -159,7 +160,7 @@ DWORD CrashHandlerException(EXCEPTION_POINTERS *ep) {
IMAGE_NT_HEADERS *h = ImageNtHeader(base);
DWORD image_type = h->FileHeader.Machine;
int n = 0;
- String msg = GLOBAL_GET("debug/settings/backtrace/message");
+ String msg = GLOBAL_GET("debug/settings/crash_handler/message");
fprintf(stderr, "Dumping the backtrace. %ls\n", msg.c_str());
diff --git a/platform/windows/detect.py b/platform/windows/detect.py
index 5bd9a78f49..fbb02c9d1b 100644
--- a/platform/windows/detect.py
+++ b/platform/windows/detect.py
@@ -44,11 +44,11 @@ def can_build():
if (os.system(mingw64 + test) == 0 or os.system(mingw32 + test) == 0):
return True
- print("Could not detect MinGW. Ensure its binaries are in your PATH or that MINGW32_PREFIX or MINGW64_PREFIX are properly defined.")
return False
def get_opts():
+ from SCons.Variables import BoolVariable, EnumVariable
mingw32 = ""
mingw64 = ""
@@ -64,6 +64,7 @@ def get_opts():
return [
('mingw_prefix_32', 'MinGW prefix (Win32)', mingw32),
('mingw_prefix_64', 'MinGW prefix (Win64)', mingw64),
+ EnumVariable('debug_symbols', 'Add debug symbols to release version', 'yes', ('yes', 'no', 'full')),
]
@@ -213,11 +214,20 @@ def configure(env):
env.Append(LINKFLAGS=['-Wl,--subsystem,windows'])
+ if (env["debug_symbols"] == "yes"):
+ env.Prepend(CCFLAGS=['-g1'])
+ if (env["debug_symbols"] == "full"):
+ env.Prepend(CCFLAGS=['-g2'])
+
elif (env["target"] == "release_debug"):
env.Append(CCFLAGS=['-O2', '-DDEBUG_ENABLED'])
+ if (env["debug_symbols"] == "yes"):
+ env.Prepend(CCFLAGS=['-g1'])
+ if (env["debug_symbols"] == "full"):
+ env.Prepend(CCFLAGS=['-g2'])
elif (env["target"] == "debug"):
- env.Append(CCFLAGS=['-g', '-DDEBUG_ENABLED', '-DDEBUG_MEMORY_ENABLED'])
+ env.Append(CCFLAGS=['-g3', '-DDEBUG_ENABLED', '-DDEBUG_MEMORY_ENABLED'])
## Compiler configuration
@@ -246,11 +256,15 @@ def configure(env):
env["CC"] = mingw_prefix + "gcc"
env['AS'] = mingw_prefix + "as"
env['CXX'] = mingw_prefix + "g++"
- env['AR'] = mingw_prefix + "ar"
- env['RANLIB'] = mingw_prefix + "ranlib"
+ env['AR'] = mingw_prefix + "gcc-ar"
+ env['RANLIB'] = mingw_prefix + "gcc-ranlib"
env['LD'] = mingw_prefix + "g++"
env["x86_libtheora_opt_gcc"] = True
+ if env['use_lto']:
+ env.Append(CCFLAGS=['-flto'])
+ env.Append(LINKFLAGS=['-flto=' + str(env.GetOption("num_jobs"))])
+
## Compile flags
env.Append(CCFLAGS=['-DWINDOWS_ENABLED', '-mwindows'])
diff --git a/platform/windows/godot_win.cpp b/platform/windows/godot_win.cpp
index 4450cb3670..cff2cbad42 100644
--- a/platform/windows/godot_win.cpp
+++ b/platform/windows/godot_win.cpp
@@ -156,32 +156,36 @@ int widechar_main(int argc, wchar_t **argv) {
return os.get_exit_code();
};
-int main(int _argc, char **_argv) {
-// _argc and _argv are ignored
-// we are going to use the WideChar version of them instead
+int _main() {
+ LPWSTR *wc_argv;
+ int argc;
+ int result;
-#ifdef CRASH_HANDLER_EXCEPTION
- __try {
-#endif
- LPWSTR *wc_argv;
- int argc;
- int result;
+ wc_argv = CommandLineToArgvW(GetCommandLineW(), &argc);
+
+ if (NULL == wc_argv) {
+ wprintf(L"CommandLineToArgvW failed\n");
+ return 0;
+ }
- wc_argv = CommandLineToArgvW(GetCommandLineW(), &argc);
+ result = widechar_main(argc, wc_argv);
- if (NULL == wc_argv) {
- wprintf(L"CommandLineToArgvW failed\n");
- return 0;
- }
+ LocalFree(wc_argv);
+ return result;
+}
- result = widechar_main(argc, wc_argv);
+int main(int _argc, char **_argv) {
+// _argc and _argv are ignored
+// we are going to use the WideChar version of them instead
- LocalFree(wc_argv);
- return result;
#ifdef CRASH_HANDLER_EXCEPTION
+ __try {
+ return _main();
} __except (CrashHandlerException(GetExceptionInformation())) {
return 1;
}
+#else
+ return _main();
#endif
}
diff --git a/platform/windows/key_mapping_win.cpp b/platform/windows/key_mapping_win.cpp
index 57f8e965de..76bb5d5723 100644
--- a/platform/windows/key_mapping_win.cpp
+++ b/platform/windows/key_mapping_win.cpp
@@ -50,7 +50,7 @@ static _WinTranslatePair _vk_to_keycode[] = {
{ KEY_CONTROL, VK_CONTROL }, //(0x11)
- { KEY_MENU, VK_MENU }, //(0x12)
+ { KEY_ALT, VK_MENU }, //(0x12)
{ KEY_PAUSE, VK_PAUSE }, //(0x13)
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index 461caf479c..01201beccb 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -42,12 +42,12 @@
#include "lang_table.h"
#include "main/main.h"
#include "packet_peer_udp_winsock.h"
-#include "project_settings.h"
#include "servers/audio_server.h"
#include "servers/visual/visual_server_raster.h"
#include "servers/visual/visual_server_wrap_mt.h"
#include "stream_peer_winsock.h"
#include "tcp_server_winsock.h"
+#include "windows_terminal_logger.h"
#include <process.h>
#include <regstr.h>
@@ -205,6 +205,15 @@ void OS_Windows::initialize_core() {
cursor_shape = CURSOR_ARROW;
}
+void OS_Windows::initialize_logger() {
+ Vector<Logger *> loggers;
+ loggers.push_back(memnew(WindowsTerminalLogger));
+ // FIXME: Reenable once we figure out how to get this properly in user://
+ // instead of littering the user's working dirs (res:// + pwd) with log files (GH-12277)
+ //loggers.push_back(memnew(RotatedFileLogger("user://logs/log.txt")));
+ _set_logger(memnew(CompositeLogger(loggers)));
+}
+
bool OS_Windows::can_draw() const {
return !minimized;
@@ -1048,12 +1057,6 @@ void OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
visual_server = memnew(VisualServerWrapMT(visual_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD));
}
- physics_server = memnew(PhysicsServerSW);
- physics_server->init();
-
- physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>();
- physics_2d_server->init();
-
if (!is_no_window_mode_enabled()) {
ShowWindow(hWnd, SW_SHOW); // Show The Window
SetForegroundWindow(hWnd); // Slightly Higher Priority
@@ -1215,12 +1218,6 @@ void OS_Windows::finalize() {
memdelete(debugger_connection_console);
}
*/
-
- physics_server->finish();
- memdelete(physics_server);
-
- physics_2d_server->finish();
- memdelete(physics_2d_server);
}
void OS_Windows::finalize_core() {
@@ -1231,38 +1228,6 @@ void OS_Windows::finalize_core() {
StreamPeerWinsock::cleanup();
}
-void OS_Windows::vprint(const char *p_format, va_list p_list, bool p_stderr) {
-
- const unsigned int BUFFER_SIZE = 16384;
- char buf[BUFFER_SIZE + 1]; // +1 for the terminating character
- int len = vsnprintf(buf, BUFFER_SIZE, p_format, p_list);
- if (len <= 0)
- return;
- if (len >= BUFFER_SIZE)
- len = BUFFER_SIZE; // Output is too big, will be truncated
- buf[len] = 0;
-
- int wlen = MultiByteToWideChar(CP_UTF8, 0, buf, len, NULL, 0);
- if (wlen < 0)
- return;
-
- wchar_t *wbuf = (wchar_t *)malloc((len + 1) * sizeof(wchar_t));
- MultiByteToWideChar(CP_UTF8, 0, buf, len, wbuf, wlen);
- wbuf[wlen] = 0;
-
- if (p_stderr)
- fwprintf(stderr, L"%ls", wbuf);
- else
- wprintf(L"%ls", wbuf);
-
-#ifdef STDOUT_FILE
-//vwfprintf(stdo,p_format,p_list);
-#endif
- free(wbuf);
-
- fflush(stdout);
-};
-
void OS_Windows::alert(const String &p_alert, const String &p_title) {
if (!is_no_window_mode_enabled())
@@ -1304,7 +1269,7 @@ OS_Windows::MouseMode OS_Windows::get_mouse_mode() const {
return mouse_mode;
}
-void OS_Windows::warp_mouse_pos(const Point2 &p_to) {
+void OS_Windows::warp_mouse_position(const Point2 &p_to) {
if (mouse_mode == MOUSE_MODE_CAPTURED) {
@@ -1676,107 +1641,6 @@ void OS_Windows::request_attention() {
FlashWindowEx(&info);
}
-void OS_Windows::print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type) {
-
- HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
- if (!hCon || hCon == INVALID_HANDLE_VALUE) {
-
- const char *err_details;
- if (p_rationale && p_rationale[0])
- err_details = p_rationale;
- else
- err_details = p_code;
-
- switch (p_type) {
- case ERR_ERROR:
- print("ERROR: %s: %s\n", p_function, err_details);
- print(" At: %s:%i\n", p_file, p_line);
- break;
- case ERR_WARNING:
- print("WARNING: %s: %s\n", p_function, err_details);
- print(" At: %s:%i\n", p_file, p_line);
- break;
- case ERR_SCRIPT:
- print("SCRIPT ERROR: %s: %s\n", p_function, err_details);
- print(" At: %s:%i\n", p_file, p_line);
- break;
- case ERR_SHADER:
- print("SHADER ERROR: %s: %s\n", p_function, err_details);
- print(" At: %s:%i\n", p_file, p_line);
- break;
- }
-
- } else {
-
- CONSOLE_SCREEN_BUFFER_INFO sbi; //original
- GetConsoleScreenBufferInfo(hCon, &sbi);
-
- WORD current_fg = sbi.wAttributes & (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
- WORD current_bg = sbi.wAttributes & (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY);
-
- uint32_t basecol = 0;
- switch (p_type) {
- case ERR_ERROR: basecol = FOREGROUND_RED; break;
- case ERR_WARNING: basecol = FOREGROUND_RED | FOREGROUND_GREEN; break;
- case ERR_SCRIPT: basecol = FOREGROUND_RED | FOREGROUND_BLUE; break;
- case ERR_SHADER: basecol = FOREGROUND_GREEN | FOREGROUND_BLUE; break;
- }
-
- basecol |= current_bg;
-
- if (p_rationale && p_rationale[0]) {
-
- SetConsoleTextAttribute(hCon, basecol | FOREGROUND_INTENSITY);
- switch (p_type) {
- case ERR_ERROR: print("ERROR: "); break;
- case ERR_WARNING: print("WARNING: "); break;
- case ERR_SCRIPT: print("SCRIPT ERROR: "); break;
- case ERR_SHADER: print("SHADER ERROR: "); break;
- }
-
- SetConsoleTextAttribute(hCon, current_fg | current_bg | FOREGROUND_INTENSITY);
- print("%s\n", p_rationale);
-
- SetConsoleTextAttribute(hCon, basecol);
- switch (p_type) {
- case ERR_ERROR: print(" At: "); break;
- case ERR_WARNING: print(" At: "); break;
- case ERR_SCRIPT: print(" At: "); break;
- case ERR_SHADER: print(" At: "); break;
- }
-
- SetConsoleTextAttribute(hCon, current_fg | current_bg);
- print("%s:%i\n", p_file, p_line);
-
- } else {
-
- SetConsoleTextAttribute(hCon, basecol | FOREGROUND_INTENSITY);
- switch (p_type) {
- case ERR_ERROR: print("ERROR: %s: ", p_function); break;
- case ERR_WARNING: print("WARNING: %s: ", p_function); break;
- case ERR_SCRIPT: print("SCRIPT ERROR: %s: ", p_function); break;
- case ERR_SHADER: print("SCRIPT ERROR: %s: ", p_function); break;
- }
-
- SetConsoleTextAttribute(hCon, current_fg | current_bg | FOREGROUND_INTENSITY);
- print("%s\n", p_code);
-
- SetConsoleTextAttribute(hCon, basecol);
- switch (p_type) {
- case ERR_ERROR: print(" At: "); break;
- case ERR_WARNING: print(" At: "); break;
- case ERR_SCRIPT: print(" At: "); break;
- case ERR_SHADER: print(" At: "); break;
- }
-
- SetConsoleTextAttribute(hCon, current_fg | current_bg);
- print("%s:%i\n", p_file, p_line);
- }
-
- SetConsoleTextAttribute(hCon, sbi.wAttributes);
- }
-}
-
String OS_Windows::get_name() {
return "Windows";
@@ -1937,7 +1801,7 @@ void OS_Windows::set_cursor_shape(CursorShape p_shape) {
cursor_shape = p_shape;
}
-Error OS_Windows::execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id, String *r_pipe, int *r_exitcode) {
+Error OS_Windows::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) {
if (p_blocking && r_pipe) {
@@ -2373,6 +2237,33 @@ bool OS_Windows::is_disable_crash_handler() const {
return crash_handler.is_disabled();
}
+Error OS_Windows::move_to_trash(const String &p_path) {
+ SHFILEOPSTRUCTA sf;
+ TCHAR *from = new TCHAR[p_path.length() + 2];
+ strcpy(from, p_path.utf8().get_data());
+ from[p_path.length()] = 0;
+ from[p_path.length() + 1] = 0;
+
+ sf.hwnd = hWnd;
+ sf.wFunc = FO_DELETE;
+ sf.pFrom = from;
+ sf.pTo = NULL;
+ sf.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION;
+ sf.fAnyOperationsAborted = FALSE;
+ sf.hNameMappings = NULL;
+ sf.lpszProgressTitle = NULL;
+
+ int ret = SHFileOperation(&sf);
+ delete[] from;
+
+ if (ret) {
+ ERR_PRINTS("SHFileOperation error: " + itos(ret));
+ return FAILED;
+ }
+
+ return OK;
+}
+
OS_Windows::OS_Windows(HINSTANCE _hInstance) {
key_event_pos = 0;
@@ -2402,6 +2293,8 @@ OS_Windows::OS_Windows(HINSTANCE _hInstance) {
#ifdef XAUDIO2_ENABLED
AudioDriverManager::add_driver(&driver_xaudio2);
#endif
+
+ _set_logger(memnew(WindowsTerminalLogger));
}
OS_Windows::~OS_Windows() {
diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h
index 1a01ac950d..c9c00b5e36 100644
--- a/platform/windows/os_windows.h
+++ b/platform/windows/os_windows.h
@@ -29,8 +29,8 @@
/*************************************************************************/
#ifndef OS_WINDOWS_H
#define OS_WINDOWS_H
-
#include "context_gl_win.h"
+#include "core/project_settings.h"
#include "crash_handler_win.h"
#include "drivers/rtaudio/audio_driver_rtaudio.h"
#include "drivers/wasapi/audio_driver_wasapi.h"
@@ -38,7 +38,6 @@
#include "os/os.h"
#include "power_windows.h"
#include "servers/audio_server.h"
-#include "servers/physics/physics_server_sw.h"
#include "servers/visual/rasterizer.h"
#include "servers/visual_server.h"
#ifdef XAUDIO2_ENABLED
@@ -47,8 +46,6 @@
#include "drivers/unix/ip_unix.h"
#include "key_mapping_win.h"
#include "main/input_default.h"
-#include "servers/physics_2d/physics_2d_server_sw.h"
-#include "servers/physics_2d/physics_2d_server_wrap_mt.h"
#include <fcntl.h>
#include <io.h>
@@ -90,8 +87,6 @@ class OS_Windows : public OS {
ContextGL_Win *gl_context;
#endif
VisualServer *visual_server;
- PhysicsServer *physics_server;
- Physics2DServer *physics_2d_server;
int pressrc;
HDC hDC; // Private GDI Device Context
HINSTANCE hInstance; // Holds The Instance Of The Application
@@ -152,6 +147,7 @@ protected:
virtual int get_audio_driver_count() const;
virtual const char *get_audio_driver_name(int p_driver) const;
+ virtual void initialize_logger();
virtual void initialize_core();
virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
@@ -180,16 +176,13 @@ protected:
public:
LRESULT WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
- void print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type);
-
- virtual void vprint(const char *p_format, va_list p_list, bool p_stderr = false);
virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
String get_stdin_string(bool p_block);
void set_mouse_mode(MouseMode p_mode);
MouseMode get_mouse_mode() const;
- virtual void warp_mouse_pos(const Point2 &p_to);
+ virtual void warp_mouse_position(const Point2 &p_to);
virtual Point2 get_mouse_position() const;
virtual int get_mouse_button_state() const;
virtual void set_window_title(const String &p_title);
@@ -242,7 +235,7 @@ public:
virtual void delay_usec(uint32_t p_usec) const;
virtual uint64_t get_ticks_usec() const;
- virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL);
+ virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL, bool read_stderr = false);
virtual Error kill(const ProcessID &p_pid);
virtual int get_process_id() const;
@@ -290,6 +283,8 @@ public:
void disable_crash_handler();
bool is_disable_crash_handler() const;
+ virtual Error move_to_trash(const String &p_path);
+
OS_Windows(HINSTANCE _hInstance);
~OS_Windows();
};
diff --git a/platform/windows/windows_terminal_logger.cpp b/platform/windows/windows_terminal_logger.cpp
new file mode 100644
index 0000000000..ef8140ffa7
--- /dev/null
+++ b/platform/windows/windows_terminal_logger.cpp
@@ -0,0 +1,157 @@
+/*************************************************************************/
+/* windows_terminal_logger.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#include "windows_terminal_logger.h"
+
+#ifdef WINDOWS_ENABLED
+
+#include <stdio.h>
+#include <windows.h>
+
+void WindowsTerminalLogger::logv(const char *p_format, va_list p_list, bool p_err) {
+ if (!should_log(p_err)) {
+ return;
+ }
+
+ const unsigned int BUFFER_SIZE = 16384;
+ char buf[BUFFER_SIZE + 1]; // +1 for the terminating character
+ int len = vsnprintf(buf, BUFFER_SIZE, p_format, p_list);
+ if (len <= 0)
+ return;
+ if (len >= BUFFER_SIZE)
+ len = BUFFER_SIZE; // Output is too big, will be truncated
+ buf[len] = 0;
+
+ int wlen = MultiByteToWideChar(CP_UTF8, 0, buf, len, NULL, 0);
+ if (wlen < 0)
+ return;
+
+ wchar_t *wbuf = (wchar_t *)malloc((len + 1) * sizeof(wchar_t));
+ MultiByteToWideChar(CP_UTF8, 0, buf, len, wbuf, wlen);
+ wbuf[wlen] = 0;
+
+ if (p_err)
+ fwprintf(stderr, L"%ls", wbuf);
+ else
+ wprintf(L"%ls", wbuf);
+
+ free(wbuf);
+
+#ifdef DEBUG_ENABLED
+ fflush(stdout);
+#endif
+}
+
+void WindowsTerminalLogger::log_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type) {
+ if (!should_log(true)) {
+ return;
+ }
+
+#ifndef UWP_ENABLED
+ HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
+ if (!hCon || hCon == INVALID_HANDLE_VALUE) {
+#endif
+ StdLogger::log_error(p_function, p_file, p_line, p_code, p_rationale, p_type);
+#ifndef UWP_ENABLED
+ } else {
+
+ CONSOLE_SCREEN_BUFFER_INFO sbi; //original
+ GetConsoleScreenBufferInfo(hCon, &sbi);
+
+ WORD current_fg = sbi.wAttributes & (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
+ WORD current_bg = sbi.wAttributes & (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY);
+
+ uint32_t basecol = 0;
+ switch (p_type) {
+ case ERR_ERROR: basecol = FOREGROUND_RED; break;
+ case ERR_WARNING: basecol = FOREGROUND_RED | FOREGROUND_GREEN; break;
+ case ERR_SCRIPT: basecol = FOREGROUND_RED | FOREGROUND_BLUE; break;
+ case ERR_SHADER: basecol = FOREGROUND_GREEN | FOREGROUND_BLUE; break;
+ }
+
+ basecol |= current_bg;
+
+ if (p_rationale && p_rationale[0]) {
+
+ SetConsoleTextAttribute(hCon, basecol | FOREGROUND_INTENSITY);
+ switch (p_type) {
+ case ERR_ERROR: logf("ERROR: "); break;
+ case ERR_WARNING: logf("WARNING: "); break;
+ case ERR_SCRIPT: logf("SCRIPT ERROR: "); break;
+ case ERR_SHADER: logf("SHADER ERROR: "); break;
+ }
+
+ SetConsoleTextAttribute(hCon, current_fg | current_bg | FOREGROUND_INTENSITY);
+ logf("%s\n", p_rationale);
+
+ SetConsoleTextAttribute(hCon, basecol);
+ switch (p_type) {
+ case ERR_ERROR: logf(" At: "); break;
+ case ERR_WARNING: logf(" At: "); break;
+ case ERR_SCRIPT: logf(" At: "); break;
+ case ERR_SHADER: logf(" At: "); break;
+ }
+
+ SetConsoleTextAttribute(hCon, current_fg | current_bg);
+ logf("%s:%i\n", p_file, p_line);
+
+ } else {
+
+ SetConsoleTextAttribute(hCon, basecol | FOREGROUND_INTENSITY);
+ switch (p_type) {
+ case ERR_ERROR: logf("ERROR: %s: ", p_function); break;
+ case ERR_WARNING: logf("WARNING: %s: ", p_function); break;
+ case ERR_SCRIPT: logf("SCRIPT ERROR: %s: ", p_function); break;
+ case ERR_SHADER: logf("SCRIPT ERROR: %s: ", p_function); break;
+ }
+
+ SetConsoleTextAttribute(hCon, current_fg | current_bg | FOREGROUND_INTENSITY);
+ logf("%s\n", p_code);
+
+ SetConsoleTextAttribute(hCon, basecol);
+ switch (p_type) {
+ case ERR_ERROR: logf(" At: "); break;
+ case ERR_WARNING: logf(" At: "); break;
+ case ERR_SCRIPT: logf(" At: "); break;
+ case ERR_SHADER: logf(" At: "); break;
+ }
+
+ SetConsoleTextAttribute(hCon, current_fg | current_bg);
+ logf("%s:%i\n", p_file, p_line);
+ }
+
+ SetConsoleTextAttribute(hCon, sbi.wAttributes);
+ }
+#endif
+}
+
+WindowsTerminalLogger::~WindowsTerminalLogger() {}
+
+#endif \ No newline at end of file
diff --git a/platform/iphone/audio_driver_iphone.h b/platform/windows/windows_terminal_logger.h
index 930ed168f7..f6b1a68d18 100644
--- a/platform/iphone/audio_driver_iphone.h
+++ b/platform/windows/windows_terminal_logger.h
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* audio_driver_iphone.h */
+/* windows_terminal_logger.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -28,39 +28,20 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "servers/audio_server.h"
+#ifndef WINDOWS_TERMINAL_LOGGER_H
+#define WINDOWS_TERMINAL_LOGGER_H
-#include <AudioUnit/AudioUnit.h>
+#ifdef WINDOWS_ENABLED
-class AudioDriverIphone : public AudioDriver {
-
- AudioComponentInstance audio_unit;
- bool active;
- Mutex *mutex;
-
- int channels;
- int32_t *samples_in;
- int buffer_frames;
-
- static OSStatus output_callback(void *inRefCon,
- AudioUnitRenderActionFlags *ioActionFlags,
- const AudioTimeStamp *inTimeStamp,
- UInt32 inBusNumber, UInt32 inNumberFrames,
- AudioBufferList *ioData);
+#include "io/logger.h"
+class WindowsTerminalLogger : public StdLogger {
public:
- const char *get_name() const {
- return "IPhone";
- };
+ virtual void logv(const char *p_format, va_list p_list, bool p_err);
+ virtual void log_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type = ERR_ERROR);
+ virtual ~WindowsTerminalLogger();
+};
- virtual Error init();
- virtual void start();
- virtual int get_mix_rate() const;
- virtual SpeakerMode get_speaker_mode() const;
- virtual void lock();
- virtual void unlock();
- virtual void finish();
+#endif
- AudioDriverIphone();
- ~AudioDriverIphone();
-};
+#endif \ No newline at end of file
diff --git a/platform/x11/SCsub b/platform/x11/SCsub
index 62717f3221..aabc49149f 100644
--- a/platform/x11/SCsub
+++ b/platform/x11/SCsub
@@ -1,7 +1,12 @@
#!/usr/bin/env python
+import os
Import('env')
+def make_debug(target, source, env):
+ os.system('objcopy --only-keep-debug %s %s.debug' % (target[0], target[0]))
+ os.system('strip --strip-debug --strip-unneeded %s' % (target[0]))
+ os.system('objcopy --add-gnu-debuglink=%s.debug %s' % (target[0], target[0]))
common_x11 = [
"context_gl_x11.cpp",
@@ -12,4 +17,6 @@ common_x11 = [
"power_x11.cpp",
]
-env.Program('#bin/godot', ['godot_x11.cpp'] + common_x11)
+binary = env.Program('#bin/godot', ['godot_x11.cpp'] + common_x11)
+if env["debug_symbols"] == "full" or env["debug_symbols"] == "yes":
+ env.AddPostAction(binary, make_debug)
diff --git a/platform/x11/context_gl_x11.cpp b/platform/x11/context_gl_x11.cpp
index 0cc9734119..4f9d4a84b9 100644
--- a/platform/x11/context_gl_x11.cpp
+++ b/platform/x11/context_gl_x11.cpp
@@ -30,7 +30,7 @@
#include "context_gl_x11.h"
#ifdef X11_ENABLED
-#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED)
+#if defined(OPENGL_ENABLED)
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
diff --git a/platform/x11/context_gl_x11.h b/platform/x11/context_gl_x11.h
index ba01b51d59..c37bac5e9b 100644
--- a/platform/x11/context_gl_x11.h
+++ b/platform/x11/context_gl_x11.h
@@ -35,7 +35,7 @@
*/
#ifdef X11_ENABLED
-#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED)
+#if defined(OPENGL_ENABLED)
#include "drivers/gl_context/context_gl.h"
#include "os/os.h"
diff --git a/platform/x11/crash_handler_x11.cpp b/platform/x11/crash_handler_x11.cpp
index c926b7799d..005a7459f9 100644
--- a/platform/x11/crash_handler_x11.cpp
+++ b/platform/x11/crash_handler_x11.cpp
@@ -33,12 +33,14 @@
#include "main/main.h"
#include "os_x11.h"
+#include "project_settings.h"
#ifdef CRASH_HANDLER_ENABLED
#include <cxxabi.h>
#include <dlfcn.h>
#include <execinfo.h>
#include <signal.h>
+#include <stdlib.h>
static void handle_crash(int sig) {
if (OS::get_singleton() == NULL)
@@ -47,7 +49,7 @@ static void handle_crash(int sig) {
void *bt_buffer[256];
size_t size = backtrace(bt_buffer, 256);
String _execpath = OS::get_singleton()->get_executable_path();
- String msg = GLOBAL_GET("debug/settings/backtrace/message");
+ String msg = GLOBAL_GET("debug/settings/crash_handler/message");
// Dump the backtrace to stderr with a message to the user
fprintf(stderr, "%s: Program crashed with signal %d\n", __FUNCTION__, sig);
diff --git a/platform/x11/detect.py b/platform/x11/detect.py
index d61175da60..6bd0ac8317 100644
--- a/platform/x11/detect.py
+++ b/platform/x11/detect.py
@@ -44,28 +44,27 @@ def can_build():
return True
-
def get_opts():
+ from SCons.Variables import BoolVariable, EnumVariable
return [
- ('use_llvm', 'Use the LLVM compiler', 'no'),
- ('use_static_cpp', 'Link stdc++ statically', 'no'),
- ('use_sanitizer', 'Use LLVM compiler address sanitizer', 'no'),
- ('use_leak_sanitizer', 'Use LLVM compiler memory leaks sanitizer (implies use_sanitizer)', 'no'),
- ('use_lto', 'Use link time optimization', 'no'),
- ('pulseaudio', 'Detect & use pulseaudio', 'yes'),
- ('udev', 'Use udev for gamepad connection callbacks', 'no'),
- ('debug_release', 'Add debug symbols to release version', 'no'),
+ BoolVariable('use_llvm', 'Use the LLVM compiler', False),
+ BoolVariable('use_static_cpp', 'Link stdc++ statically', False),
+ BoolVariable('use_sanitizer', 'Use LLVM compiler address sanitizer', False),
+ BoolVariable('use_leak_sanitizer', 'Use LLVM compiler memory leaks sanitizer (implies use_sanitizer)', False),
+ BoolVariable('pulseaudio', 'Detect & use pulseaudio', True),
+ BoolVariable('udev', 'Use udev for gamepad connection callbacks', False),
+ EnumVariable('debug_symbols', 'Add debug symbols to release version', 'yes', ('yes', 'no', 'full')),
]
def get_flags():
return [
- ('builtin_freetype', 'no'),
- ('builtin_libpng', 'no'),
- ('builtin_openssl', 'no'),
- ('builtin_zlib', 'no'),
+ ('builtin_freetype', False),
+ ('builtin_libpng', False),
+ ('builtin_openssl', False),
+ ('builtin_zlib', False),
]
@@ -77,16 +76,20 @@ def configure(env):
# -O3 -ffast-math is identical to -Ofast. We need to split it out so we can selectively disable
# -ffast-math in code for which it generates wrong results.
env.Prepend(CCFLAGS=['-O3', '-ffast-math'])
- if (env["debug_release"] == "yes"):
+ if (env["debug_symbols"] == "yes"):
+ env.Prepend(CCFLAGS=['-g1'])
+ if (env["debug_symbols"] == "full"):
env.Prepend(CCFLAGS=['-g2'])
elif (env["target"] == "release_debug"):
env.Prepend(CCFLAGS=['-O2', '-ffast-math', '-DDEBUG_ENABLED'])
- if (env["debug_release"] == "yes"):
+ if (env["debug_symbols"] == "yes"):
+ env.Prepend(CCFLAGS=['-g1'])
+ if (env["debug_symbols"] == "full"):
env.Prepend(CCFLAGS=['-g2'])
elif (env["target"] == "debug"):
- env.Prepend(CCFLAGS=['-g2', '-DDEBUG_ENABLED', '-DDEBUG_MEMORY_ENABLED'])
+ env.Prepend(CCFLAGS=['-g3', '-DDEBUG_ENABLED', '-DDEBUG_MEMORY_ENABLED'])
env.Append(LINKFLAGS=['-rdynamic'])
## Architecture
@@ -97,7 +100,11 @@ def configure(env):
## Compiler configuration
- if (env["use_llvm"] == "yes"):
+ if 'CXX' in env and 'clang' in env['CXX']:
+ # Convenience check to enforce the use_llvm overrides when CXX is clang(++)
+ env['use_llvm'] = True
+
+ if env['use_llvm']:
if ('clang++' not in env['CXX']):
env["CC"] = "clang"
env["CXX"] = "clang++"
@@ -106,17 +113,23 @@ def configure(env):
env.extra_suffix = ".llvm" + env.extra_suffix
# leak sanitizer requires (address) sanitizer
- if (env["use_sanitizer"] == "yes" or env["use_leak_sanitizer"] == "yes"):
+ if env['use_sanitizer'] or env['use_leak_sanitizer']:
env.Append(CCFLAGS=['-fsanitize=address', '-fno-omit-frame-pointer'])
env.Append(LINKFLAGS=['-fsanitize=address'])
env.extra_suffix += "s"
- if (env["use_leak_sanitizer"] == "yes"):
+ if env['use_leak_sanitizer']:
env.Append(CCFLAGS=['-fsanitize=leak'])
env.Append(LINKFLAGS=['-fsanitize=leak'])
- if (env["use_lto"] == "yes"):
+ if env['use_lto']:
env.Append(CCFLAGS=['-flto'])
- env.Append(LINKFLAGS=['-flto'])
+ if not env['use_llvm'] and env.GetOption("num_jobs") > 1:
+ env.Append(LINKFLAGS=['-flto=' + str(env.GetOption("num_jobs"))])
+ else:
+ env.Append(LINKFLAGS=['-flto'])
+ if not env['use_llvm']:
+ env['RANLIB'] = 'gcc-ranlib'
+ env['AR'] = 'gcc-ar'
env.Append(CCFLAGS=['-pipe'])
env.Append(LINKFLAGS=['-pipe'])
@@ -130,70 +143,64 @@ def configure(env):
# FIXME: Check for existence of the libs before parsing their flags with pkg-config
- if (env['builtin_openssl'] == 'no'):
- # Currently not compatible with OpenSSL 1.1.0+
- # https://github.com/godotengine/godot/issues/8624
- import subprocess
- openssl_version = subprocess.check_output(['pkg-config', 'openssl', '--modversion']).strip('\n')
- if (openssl_version >= "1.1.0"):
- print("Error: Found system-installed OpenSSL %s, currently only supporting version 1.0.x." % openssl_version)
- print("Aborting.. You can compile with 'builtin_openssl=yes' to use the bundled version.\n")
- sys.exit(255)
-
+ if not env['builtin_openssl']:
env.ParseConfig('pkg-config openssl --cflags --libs')
- if (env['builtin_libwebp'] == 'no'):
+ if not env['builtin_libwebp']:
env.ParseConfig('pkg-config libwebp --cflags --libs')
# freetype depends on libpng and zlib, so bundling one of them while keeping others
# as shared libraries leads to weird issues
- if (env['builtin_freetype'] == 'yes' or env['builtin_libpng'] == 'yes' or env['builtin_zlib'] == 'yes'):
- env['builtin_freetype'] = 'yes'
- env['builtin_libpng'] = 'yes'
- env['builtin_zlib'] = 'yes'
+ if env['builtin_freetype'] or env['builtin_libpng'] or env['builtin_zlib']:
+ env['builtin_freetype'] = True
+ env['builtin_libpng'] = True
+ env['builtin_zlib'] = True
- if (env['builtin_freetype'] == 'no'):
+ if not env['builtin_freetype']:
env.ParseConfig('pkg-config freetype2 --cflags --libs')
- if (env['builtin_libpng'] == 'no'):
+ if not env['builtin_libpng']:
env.ParseConfig('pkg-config libpng --cflags --libs')
- if (env['builtin_enet'] == 'no'):
+ if not env['builtin_enet']:
env.ParseConfig('pkg-config libenet --cflags --libs')
- if (env['builtin_squish'] == 'no' and env["tools"] == "yes"):
+ if not env['builtin_squish'] and env['tools']:
env.ParseConfig('pkg-config libsquish --cflags --libs')
+ if not env['builtin_zstd']:
+ env.ParseConfig('pkg-config libzstd --cflags --libs')
+
# Sound and video libraries
# Keep the order as it triggers chained dependencies (ogg needed by others, etc.)
- if (env['builtin_libtheora'] == 'no'):
- env['builtin_libogg'] = 'no' # Needed to link against system libtheora
- env['builtin_libvorbis'] = 'no' # Needed to link against system libtheora
+ if not env['builtin_libtheora']:
+ env['builtin_libogg'] = False # Needed to link against system libtheora
+ env['builtin_libvorbis'] = False # Needed to link against system libtheora
env.ParseConfig('pkg-config theora theoradec --cflags --libs')
- if (env['builtin_libvpx'] == 'no'):
+ if not env['builtin_libvpx']:
env.ParseConfig('pkg-config vpx --cflags --libs')
- if (env['builtin_libvorbis'] == 'no'):
- env['builtin_libogg'] = 'no' # Needed to link against system libvorbis
+ if not env['builtin_libvorbis']:
+ env['builtin_libogg'] = False # Needed to link against system libvorbis
env.ParseConfig('pkg-config vorbis vorbisfile --cflags --libs')
- if (env['builtin_opus'] == 'no'):
- env['builtin_libogg'] = 'no' # Needed to link against system opus
+ if not env['builtin_opus']:
+ env['builtin_libogg'] = False # Needed to link against system opus
env.ParseConfig('pkg-config opus opusfile --cflags --libs')
- if (env['builtin_libogg'] == 'no'):
+ if not env['builtin_libogg']:
env.ParseConfig('pkg-config ogg --cflags --libs')
- if (env['builtin_libtheora'] != 'no'):
+ if env['builtin_libtheora']:
list_of_x86 = ['x86_64', 'x86', 'i386', 'i586']
if any(platform.machine() in s for s in list_of_x86):
env["x86_libtheora_opt_gcc"] = True
# On Linux wchar_t should be 32-bits
# 16-bit library shouldn't be required due to compiler optimisations
- if (env['builtin_pcre2'] == 'no'):
+ if not env['builtin_pcre2']:
env.ParseConfig('pkg-config libpcre2-32 --cflags --libs')
## Flags
@@ -205,7 +212,7 @@ def configure(env):
else:
print("ALSA libraries not found, disabling driver")
- if (env["pulseaudio"] == "yes"):
+ if env['pulseaudio']:
if (os.system("pkg-config --exists libpulse-simple") == 0): # 0 means found
print("Enabling PulseAudio")
env.Append(CPPFLAGS=["-DPULSEAUDIO_ENABLED"])
@@ -216,7 +223,7 @@ def configure(env):
if (platform.system() == "Linux"):
env.Append(CPPFLAGS=["-DJOYDEV_ENABLED"])
- if (env["udev"] == "yes"):
+ if env['udev']:
if (os.system("pkg-config --exists libudev") == 0): # 0 means found
print("Enabling udev support")
env.Append(CPPFLAGS=["-DUDEV_ENABLED"])
@@ -225,7 +232,7 @@ def configure(env):
print("libudev development libraries not found, disabling udev support")
# Linkflags below this line should typically stay the last ones
- if (env['builtin_zlib'] == 'no'):
+ if not env['builtin_zlib']:
env.ParseConfig('pkg-config zlib --cflags --libs')
env.Append(CPPPATH=['#platform/x11'])
@@ -235,6 +242,9 @@ def configure(env):
if (platform.system() == "Linux"):
env.Append(LIBS=['dl'])
+ if (platform.system().find("BSD") >= 0):
+ env.Append(LIBS=['execinfo'])
+
## Cross-compilation
if (is64 and env["bits"] == "32"):
@@ -244,5 +254,5 @@ def configure(env):
env.Append(CPPFLAGS=['-m64'])
env.Append(LINKFLAGS=['-m64', '-L/usr/lib/i686-linux-gnu'])
- if (env["use_static_cpp"] == "yes"):
+ if env['use_static_cpp']:
env.Append(LINKFLAGS=['-static-libstdc++'])
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index 3e8709a11e..fbcc22c58e 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -32,9 +32,13 @@
#include "errno.h"
#include "key_mapping_x11.h"
#include "print_string.h"
-#include "servers/physics/physics_server_sw.h"
#include "servers/visual/visual_server_raster.h"
#include "servers/visual/visual_server_wrap_mt.h"
+
+#ifdef HAVE_MNTENT
+#include <mntent.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -234,7 +238,7 @@ void OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
// maybe contextgl wants to be in charge of creating the window
//print_line("def videomode "+itos(current_videomode.width)+","+itos(current_videomode.height));
-#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED)
+#if defined(OPENGL_ENABLED)
context_gl = memnew(ContextGL_X11(x11_display, x11_window, current_videomode, true));
context_gl->initialize();
@@ -457,12 +461,6 @@ void OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
requested = None;
visual_server->init();
- //
- physics_server = memnew(PhysicsServerSW);
- physics_server->init();
- //physics_2d_server = memnew( Physics2DServerSW );
- physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>();
- physics_2d_server->init();
input = memnew(InputDefault);
@@ -518,12 +516,6 @@ void OS_X11::finalize() {
memdelete(visual_server);
//memdelete(rasterizer);
- physics_server->finish();
- memdelete(physics_server);
-
- physics_2d_server->finish();
- memdelete(physics_2d_server);
-
memdelete(power_manager);
if (xrandr_handle)
@@ -532,7 +524,7 @@ void OS_X11::finalize() {
XUnmapWindow(x11_display, x11_window);
XDestroyWindow(x11_display, x11_window);
-#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED)
+#if defined(OPENGL_ENABLED)
memdelete(context_gl);
#endif
for (int i = 0; i < CURSOR_MAX; i++) {
@@ -613,7 +605,7 @@ void OS_X11::set_mouse_mode(MouseMode p_mode) {
XFlush(x11_display);
}
-void OS_X11::warp_mouse_pos(const Point2 &p_to) {
+void OS_X11::warp_mouse_position(const Point2 &p_to) {
if (mouse_mode == MOUSE_MODE_CAPTURED) {
@@ -708,6 +700,16 @@ void OS_X11::set_wm_fullscreen(bool p_enabled) {
XSetWMNormalHints(x11_display, x11_window, xsh);
XFree(xsh);
}
+
+ if (!p_enabled && !get_borderless_window()) {
+ // put decorations back if the window wasn't suppoesed to be borderless
+ Hints hints;
+ Atom property;
+ hints.flags = 2;
+ hints.decorations = 1;
+ property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True);
+ XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5);
+ }
}
int OS_X11::get_screen_count() const {
@@ -1928,7 +1930,7 @@ Error OS_X11::shell_open(String p_uri) {
Error ok;
List<String> args;
args.push_back(p_uri);
- ok = execute("/usr/bin/xdg-open", args, false);
+ ok = execute("xdg-open", args, false);
if (ok == OK)
return OK;
ok = execute("gnome-open", args, false);
@@ -1992,7 +1994,7 @@ String OS_X11::get_system_dir(SystemDir p_dir) const {
String pipe;
List<String> arg;
arg.push_back(xdgparam);
- Error err = const_cast<OS_X11 *>(this)->execute("/usr/bin/xdg-user-dir", arg, true, NULL, &pipe);
+ Error err = const_cast<OS_X11 *>(this)->execute("xdg-user-dir", arg, true, NULL, &pipe);
if (err != OK)
return ".";
return pipe.strip_edges();
@@ -2042,7 +2044,7 @@ void OS_X11::alert(const String &p_alert, const String &p_title) {
args.push_back(p_title);
args.push_back(p_alert);
- execute("/usr/bin/xmessage", args, true);
+ execute("xmessage", args, true);
}
void OS_X11::set_icon(const Ref<Image> &p_icon) {
@@ -2165,6 +2167,111 @@ bool OS_X11::is_disable_crash_handler() const {
return crash_handler.is_disabled();
}
+static String get_mountpoint(const String &p_path) {
+ struct stat s;
+ if (stat(p_path.utf8().get_data(), &s)) {
+ return "";
+ }
+
+#ifdef HAVE_MNTENT
+ dev_t dev = s.st_dev;
+ FILE *fd = setmntent("/proc/mounts", "r");
+ if (!fd) {
+ return "";
+ }
+
+ struct mntent mnt;
+ char buf[1024];
+ size_t buflen = 1024;
+ while (getmntent_r(fd, &mnt, buf, buflen)) {
+ if (!stat(mnt.mnt_dir, &s) && s.st_dev == dev) {
+ endmntent(fd);
+ return String(mnt.mnt_dir);
+ }
+ }
+
+ endmntent(fd);
+#endif
+ return "";
+}
+
+Error OS_X11::move_to_trash(const String &p_path) {
+ String trashcan = "";
+ String mnt = get_mountpoint(p_path);
+
+ if (mnt != "") {
+ String path(mnt + "/.Trash-" + itos(getuid()) + "/files");
+ struct stat s;
+ if (!stat(path.utf8().get_data(), &s)) {
+ trashcan = path;
+ }
+ }
+
+ if (trashcan == "") {
+ char *dhome = getenv("XDG_DATA_HOME");
+ if (dhome) {
+ trashcan = String(dhome) + "/Trash/files";
+ }
+ }
+
+ if (trashcan == "") {
+ char *home = getenv("HOME");
+ if (home) {
+ trashcan = String(home) + "/.local/share/Trash/files";
+ }
+ }
+
+ if (trashcan == "") {
+ ERR_PRINTS("move_to_trash: Could not determine trashcan location");
+ return FAILED;
+ }
+
+ List<String> args;
+ args.push_back("-p");
+ args.push_back(trashcan);
+ Error err = execute("mkdir", args, true);
+ if (err == OK) {
+ List<String> args2;
+ args2.push_back(p_path);
+ args2.push_back(trashcan);
+ err = execute("mv", args2, true);
+ }
+
+ return err;
+}
+
+OS::LatinKeyboardVariant OS_X11::get_latin_keyboard_variant() const {
+
+ XkbDescRec *xkbdesc = XkbAllocKeyboard();
+ ERR_FAIL_COND_V(!xkbdesc, LATIN_KEYBOARD_QWERTY);
+
+ XkbGetNames(x11_display, XkbSymbolsNameMask, xkbdesc);
+ ERR_FAIL_COND_V(!xkbdesc->names, LATIN_KEYBOARD_QWERTY);
+ ERR_FAIL_COND_V(!xkbdesc->names->symbols, LATIN_KEYBOARD_QWERTY);
+
+ char *layout = XGetAtomName(x11_display, xkbdesc->names->symbols);
+ ERR_FAIL_COND_V(!layout, LATIN_KEYBOARD_QWERTY);
+
+ Vector<String> info = String(layout).split("+");
+ ERR_FAIL_INDEX_V(1, info.size(), LATIN_KEYBOARD_QWERTY);
+
+ if (info[1].find("colemak") != -1) {
+ return LATIN_KEYBOARD_COLEMAK;
+ } else if (info[1].find("qwertz") != -1) {
+ return LATIN_KEYBOARD_QWERTZ;
+ } else if (info[1].find("azerty") != -1) {
+ return LATIN_KEYBOARD_AZERTY;
+ } else if (info[1].find("qzerty") != -1) {
+ return LATIN_KEYBOARD_QZERTY;
+ } else if (info[1].find("dvorak") != -1) {
+ return LATIN_KEYBOARD_DVORAK;
+ } else if (info[1].find("neo") != -1) {
+ return LATIN_KEYBOARD_NEO;
+ }
+
+ return LATIN_KEYBOARD_QWERTY;
+}
+
OS_X11::OS_X11() {
#ifdef PULSEAUDIO_ENABLED
diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h
index 0e2430c650..bfa8b5b375 100644
--- a/platform/x11/os_x11.h
+++ b/platform/x11/os_x11.h
@@ -42,9 +42,6 @@
#include "main/input_default.h"
#include "power_x11.h"
#include "servers/audio_server.h"
-#include "servers/physics_2d/physics_2d_server_sw.h"
-#include "servers/physics_2d/physics_2d_server_wrap_mt.h"
-#include "servers/physics_server.h"
#include "servers/visual/rasterizer.h"
#include <X11/Xcursor/Xcursor.h>
@@ -94,7 +91,7 @@ class OS_X11 : public OS_Unix {
int xdnd_version;
-#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED)
+#if defined(OPENGL_ENABLED)
ContextGL_X11 *context_gl;
#endif
//Rasterizer *rasterizer;
@@ -121,10 +118,8 @@ class OS_X11 : public OS_Unix {
uint64_t last_click_ms;
uint32_t last_button_state;
- PhysicsServer *physics_server;
unsigned int get_mouse_button_state(unsigned int p_x11_state);
void get_key_modifier_state(unsigned int p_x11_state, Ref<InputEventWithModifiers> state);
- Physics2DServer *physics_2d_server;
MouseMode mouse_mode;
Point2i center;
@@ -201,7 +196,7 @@ public:
void set_mouse_mode(MouseMode p_mode);
MouseMode get_mouse_mode() const;
- virtual void warp_mouse_pos(const Point2 &p_to);
+ virtual void warp_mouse_position(const Point2 &p_to);
virtual Point2 get_mouse_position() const;
virtual int get_mouse_button_state() const;
virtual void set_window_title(const String &p_title);
@@ -273,6 +268,10 @@ public:
void disable_crash_handler();
bool is_disable_crash_handler() const;
+ virtual Error move_to_trash(const String &p_path);
+
+ virtual LatinKeyboardVariant get_latin_keyboard_variant() const;
+
OS_X11();
};