diff --git a/.gitignore b/.gitignore index c7c4201..05359dd 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ ## User settings xcuserdata/ +.vscode/ ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) *.xcscmblueprint diff --git a/SConstruct b/SConstruct index f96fa46..de41d9e 100644 --- a/SConstruct +++ b/SConstruct @@ -1,4 +1,7 @@ #!/usr/bin/env python + +EnsureSConsVersion(0, 98, 1) + import os import sys import subprocess @@ -19,6 +22,7 @@ opts = Variables([], ARGUMENTS) env = DefaultEnvironment() # Define our options +opts.Add(EnumVariable('platform', 'Platform build', 'iphone', ['', 'iphone', 'tvos'])) opts.Add(EnumVariable('target', "Compilation target", 'debug', ['debug', 'release', "release_debug"])) opts.Add(EnumVariable('arch', "Compilation Architecture", '', ['', 'arm64', 'armv7', 'x86_64'])) opts.Add(BoolVariable('simulator', "Compilation platform", 'no')) @@ -27,9 +31,15 @@ opts.Add(PathVariable('target_path', 'The path where the lib is installed.', 'bi opts.Add(EnumVariable('plugin', 'Plugin to build', '', ['', 'apn', 'arkit', 'camera', 'icloud', 'gamecenter', 'inappstore', 'photo_picker'])) opts.Add(EnumVariable('version', 'Godot version to target', '', ['', '3.x', '4.0'])) + +opts.Add('sdk_version', 'SDK version ', '10.0') # Updates the environment with the option variables. opts.Update(env) + +# Generates help for the -h scons option. +Help(opts.GenerateHelpText(env)) + # Process some arguments if env['use_llvm']: env['CC'] = 'clang' @@ -47,6 +57,15 @@ if env['version'] == '': print("No valid Godot version selected.") quit(); +if env['platform'] == '': + print("No valid platform selected.") + quit(); + +if env['sdk_version'] == '': + print("sdk version invalid.") + quit(); + + # For the reference: # - CCFLAGS are compilation flags shared between C and C++ # - CFLAGS are for C-specific compilation flags @@ -55,20 +74,39 @@ if env['version'] == '': # - CPPDEFINES are for pre-processor defines # - LINKFLAGS are for linking flags + # Enable Obj-C modules env.Append(CCFLAGS=["-fmodules", "-fcxx-modules"]) -if env['simulator']: - sdk_name = 'iphonesimulator' - env.Append(CCFLAGS=['-mios-simulator-version-min=10.0']) - env.Append(LINKFLAGS=["-mios-simulator-version-min=10.0"]) -else: - sdk_name = 'iphoneos' - env.Append(CCFLAGS=['-miphoneos-version-min=10.0']) - env.Append(LINKFLAGS=["-miphoneos-version-min=10.0"]) + +if env['platform'] == 'iphone': + sdk_def_enable = '-DIPHONE_ENABLED' + sdk_def = 'IPHONESDK' + if env['simulator']: + sdk_name = 'iphonesimulator' + flag_version_min = '-mios-simulator-version-min=' + else: + sdk_name = 'iphoneos' + flag_version_min = '-miphoneos-version-min=' +elif env['platform'] == 'tvos' : + sdk_def_enable = '-DTVOS_ENABLED' + sdk_def = "TVOSSDK" + + # tvOS requires Bitcode. + env.Append(CCFLAGS=["-fembed-bitcode"]) + env.Append(LINKFLAGS=["-bitcode_bundle"]) + + if env['simulator']: + sdk_name = 'appletvsimulator' + flag_version_min = '-mappletvsimulator-version-min=' + else: + sdk_name = 'appletvos' + flag_version_min = '-mappletvos-version-min=' try: sdk_path = decode_utf8(subprocess.check_output(['xcrun', '--sdk', sdk_name, '--show-sdk-path']).strip()) + if sdk_path : + env[sdk_def] = sdk_path #SDK IPHONESDK=sdk_path except (subprocess.CalledProcessError, OSError): raise ValueError("Failed to find SDK path while running xcrun --sdk {} --show-sdk-path.".format(sdk_name)) @@ -82,13 +120,18 @@ env.Append(CCFLAGS=[ # '-Wextra', ]) -env.Append(CCFLAGS=['-arch', env['arch'], "-isysroot", "$IPHONESDK", "-stdlib=libc++", '-isysroot', sdk_path]) + + +env.Append(CCFLAGS=['-isysroot', sdk_path, flag_version_min + env['sdk_version']]) +env.Append(LINKFLAGS=['-isysroot', sdk_path, flag_version_min + env['sdk_version'], '-F' + sdk_path]) + +env.Append(CCFLAGS=['-arch', env['arch'], '-stdlib=libc++']) env.Append(CCFLAGS=['-DPTRCALL_ENABLED']) env.Prepend(CXXFLAGS=[ '-DNEED_LONG_INT', '-DLIBYUV_DISABLE_NEON', - '-DIPHONE_ENABLED', '-DUNIX_ENABLED', '-DCOREAUDIO_ENABLED' + sdk_def_enable, '-DUNIX_ENABLED', '-DCOREAUDIO_ENABLED' ]) -env.Append(LINKFLAGS=["-arch", env['arch'], '-isysroot', sdk_path, '-F' + sdk_path]) +env.Append(LINKFLAGS=["-arch", env['arch'], '-F' + sdk_path]) if env['arch'] == 'armv7': env.Prepend(CXXFLAGS=['-fno-aligned-allocation']) @@ -97,6 +140,14 @@ if env['version'] == '3.x': env.Prepend(CFLAGS=['-std=gnu11']) env.Prepend(CXXFLAGS=['-DGLES_ENABLED', '-std=gnu++14']) + env.Prepend( + CPPPATH=[ + sdk_path + "/usr/include", + sdk_path + "/System/Library/Frameworks/OpenGLES.framework/Headers", + sdk_path + "/System/Library/Frameworks/AudioUnit.framework/Headers", + ] + ) + if env['target'] == 'debug': env.Prepend(CXXFLAGS=[ '-gdwarf-2', '-O0', @@ -151,33 +202,34 @@ else: print("No valid version to set flags for.") quit(); -# Adding header files -env.Append(CPPPATH=[ - '.', - 'godot', - 'godot/main', - 'godot/core', - 'godot/core/os', - 'godot/core/platform', - 'godot/platform/iphone', - 'godot/modules', - 'godot/scene', - 'godot/servers', - 'godot/drivers', - 'godot/thirdparty', -]) +if env['platform'] == 'iphone' : + + # Adding header files + env.Append(CPPPATH=[ + '.', + 'godot', + 'godot/platform/iphone', + ]) + +elif env['platform'] == 'tvos' : + # Adding header files + env.Append(CPPPATH=[ + '.', + 'godot', + 'godot/platform/tvos', + ]) + # tweak this if you want to use different folders, or more folders, to store your source code in. sources = Glob('plugins/' + env['plugin'] + '/*.cpp') sources.append(Glob('plugins/' + env['plugin'] + '/*.mm')) sources.append(Glob('plugins/' + env['plugin'] + '/*.m')) -# lib.-..a -library_platform = env["arch"] + "-" + ("simulator" if env["simulator"] else "iphone") -library_name = env['plugin'] + "." + library_platform + "." + env["target"] + ".a" +# lib.-...a +# lib.-..a +library_platform = env['arch'] + '-' + env['platform'] + ('.simulator' if env['simulator'] else '') +library_name = env['plugin'] + "." + library_platform + "." + env['target'] + '.a' library = env.StaticLibrary(target=env['target_path'] + library_name, source=sources) Default(library) -# Generates help for the -h scons option. -Help(opts.GenerateHelpText(env)) diff --git a/godot b/godot index 207fb16..783a8a0 160000 --- a/godot +++ b/godot @@ -1 +1 @@ -Subproject commit 207fb165bfd1fefd1b4339c9427a569b19d0dcae +Subproject commit 783a8a07f7f938a9a6284eda599abc255142dd66 diff --git a/plugins/inappstore/in_app_store.mm b/plugins/inappstore/in_app_store.mm index 5c20be6..5536f74 100644 --- a/plugins/inappstore/in_app_store.mm +++ b/plugins/inappstore/in_app_store.mm @@ -231,6 +231,15 @@ - (void)finishTransactionWithProductID:(NSString *)productID { self.pendingTransactions[productID] = nil; } +- (BOOL)paymentQueue:(SKPaymentQueue *)queue shouldAddStorePayment:(SKPayment *)payment forProduct:(SKProduct *)product { + Dictionary ret; + ret["type"] = "purchase_deferred"; + ret["result"] = "ok"; + ret["product_id"] = String::utf8([payment.productIdentifier UTF8String]); + InAppStore::get_singleton()->_post_event(ret); + return false; +} + - (void)reset { [self.pendingTransactions removeAllObjects]; } @@ -425,13 +434,13 @@ - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)tran } InAppStore::InAppStore() { - ERR_FAIL_COND(instance != NULL); instance = this; products_request_delegate = [[GodotProductsDelegate alloc] init]; transactions_observer = [[GodotTransactionsObserver alloc] init]; [[SKPaymentQueue defaultQueue] addTransactionObserver:transactions_observer]; + NSLog(@"*** InAppStore init!"); } void InAppStore::finish_transaction(String product_id) { @@ -451,4 +460,6 @@ - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)tran products_request_delegate = nil; [[SKPaymentQueue defaultQueue] removeTransactionObserver:transactions_observer]; transactions_observer = nil; + + instance = NULL; } diff --git a/scripts/generate_static_library.sh b/scripts/generate_static_library.sh index 5f6f7bd..6efdb16 100755 --- a/scripts/generate_static_library.sh +++ b/scripts/generate_static_library.sh @@ -1,18 +1,27 @@ #!/bin/bash set -e -# Compile static libraries - # ARM64 Device -scons target=$2 arch=arm64 plugin=$1 version=$3 -# ARM7 Device -scons target=$2 arch=armv7 plugin=$1 version=$3 +scons platform=$4 target=$2 arch=arm64 plugin=$1 version=$3 +if [[$4 == "iphone"]] then; + #ARMv7 Device + scons platform=$4 target=$2 arch=arm7 plugin=$1 version=$3 +fi + # x86_64 Simulator -scons target=$2 arch=x86_64 simulator=yes plugin=$1 version=$3 +scons platform=$4 target=$2 arch=x86_64 simulator=yes plugin=$1 version=$3 +# ARM64 Simulator +scons platform=$4 target=$2 arch=arm64 simulator=yes plugin=$1 version=$3 -# Creating a fat libraries for device and simulator -# lib.-..a -lipo -create "./bin/lib$1.x86_64-simulator.$2.a" \ - "./bin/lib$1.armv7-iphone.$2.a" \ - "./bin/lib$1.arm64-iphone.$2.a" \ - -output "./bin/$1.$2.a" \ No newline at end of file +if [[$4 == "iphone"]] then; + lipo -create "./bin/lib$1.x86_64-$4.simulator.$2.a" \ + "./bin/lib$1.arm64-$4.simulator.$2.a" \ + "./bin/lib$1.arm64-$4.$2.a" \ + "./bin/lib$1.armv7-$4.$2.a" \ + -output "./bin/$1.$4-$2.a" +elif [[$4 == "tvos"]] then; + lipo -create "./bin/lib$1.x86_64-$4.simulator.$2.a" \ + "./bin/lib$1.arm64-$4.simulator.$2.a" \ + "./bin/lib$1.arm64-$4.$2.a" \ + -output "./bin/$1.$4-$2.a" +fi diff --git a/scripts/generate_xcframework.sh b/scripts/generate_xcframework.sh old mode 100755 new mode 100644 index 57b44a6..da414b1 --- a/scripts/generate_xcframework.sh +++ b/scripts/generate_xcframework.sh @@ -1,24 +1,30 @@ #!/bin/bash set -e -# Compile static libraries +# Compile static libraries_ # ARM64 Device -scons target=$2 arch=arm64 plugin=$1 version=$3 -# ARM7 Device -scons target=$2 arch=armv7 plugin=$1 version=$3 +scons platform=$4 target=$2 arch=arm64 plugin=$1 version=$3 +if [[$4 == "iphone"]] then; + # ARMv7 Device + scons platform=$4 target=$2 arch=arm7 plugin=$1 version=$3 +fi + # x86_64 Simulator -scons target=$2 arch=x86_64 simulator=yes plugin=$1 version=$3 +scons platform=$4 target=$2 arch=x86_64 simulator=yes plugin=$1 version=$3 # ARM64 Simulator -scons target=$2 arch=arm64 simulator=yes plugin=$1 version=$3 +scons platform=$4 target=$2 arch=arm64 simulator=yes plugin=$1 version=$3 # Creating a fat libraries for device and simulator -# lib.-..a -lipo -create "./bin/lib$1.x86_64-simulator.$2.a" "./bin/lib$1.arm64-simulator.$2.a" -output "./bin/$1-simulator.$2.a" -lipo -create "./bin/lib$1.armv7-iphone.$2.a" "./bin/lib$1.arm64-iphone.$2.a" -output "./bin/$1-device.$2.a" - +# lib.-...a +lipo -create "./bin/lib$1.x86_64-$4.simulator.$2.a" "./bin/lib$1.arm64-$4.simulator.$2.a" -output "./bin/$4/$1-simulator.$2.a" +if [[$4 == "iphone"]] then; + lipo -create "./bin/lib$1.arm64-$4.$2.a" "./bin/lib$1.armv7-$4.$2.a" -output "./bin/$4/$1-device.$2.a" +else + lipo -create "./bin/lib$1.arm64-$4.$2.a" -output "./bin/$4/$1-device.$2.a" +fi # Creating a xcframework xcodebuild -create-xcframework \ - -library "./bin/$1-device.$2.a" \ - -library "./bin/$1-simulator.$2.a" \ - -output "./bin/$1.$2.xcframework" + -library "./bin/$4/$1-device.$2.a" \ + -library "./bin/$4/$1-simulator.$2.a" \ + -output "./bin/$4/$1.$2.xcframework" diff --git a/scripts/release_static_library.sh b/scripts/release_static_library.sh index 80758b8..eb34419 100755 --- a/scripts/release_static_library.sh +++ b/scripts/release_static_library.sh @@ -1,21 +1,28 @@ #!/bin/bash -GODOT_PLUGINS="gamecenter inappstore icloud camera arkit apn photo_picker" +if [[$1 == "tvos"]] then; + GODOT_PLUGINS="inappstore icloud" +elif [[$1 == "iphone"]] then; + GODOT_PLUGINS="gamecenter inappstore icloud camera arkit apn photo_picker" +fi -# Compile Plugin +rm -rf ./bin/$1 +mkdir ./bin/$1 + +# Compile Plugin for lib in $GODOT_PLUGINS; do - ./scripts/generate_static_library.sh $lib release $1 - ./scripts/generate_static_library.sh $lib release_debug $1 - mv ./bin/${lib}.release_debug.a ./bin/${lib}.debug.a + ./scripts/generate_static_library.sh $lib release $2 + ./scripts/generate_static_library.sh $lib release_debug $2 + mv ./bin/$1/${lib}.release_debug.a ./bin/$1/${lib}.debug.a done # Move to release folder -rm -rf ./bin/release -mkdir ./bin/release + +mkdir ./bin/$1/release # Move Plugin for lib in $GODOT_PLUGINS; do - mkdir ./bin/release/${lib} - mv ./bin/${lib}.{release,debug}.a ./bin/release/${lib} + mkdir ./bin/$1/release/${lib} + mv ./bin/$1/${lib}.{release,debug}.a ./bin/$1/release/${lib} done \ No newline at end of file diff --git a/scripts/release_xcframework.sh b/scripts/release_xcframework.sh old mode 100755 new mode 100644 index dfd4c7c..32f9191 --- a/scripts/release_xcframework.sh +++ b/scripts/release_xcframework.sh @@ -1,23 +1,35 @@ #!/bin/bash set -e -GODOT_PLUGINS="gamecenter inappstore icloud camera arkit apn photo_picker" +#call ./scripts/releasexcframework.sh iphone 3.x +#call ./scripts/releasexcframework.sh tvos 3.x +#call ./scripts/releasexcframework.sh iphone 4.0 +#call ./scripts/releasexcframework.sh tvos 4.0 -# Compile Plugin +if [[$1 == "tvos"]] then; + GODOT_PLUGINS="inappstore icloud" +elif [[$1 == "iphone"]] then; + GODOT_PLUGINS="gamecenter inappstore icloud camera arkit apn photo_picker" +fi + +rm -rf ./bin/$1 +mkdir ./bin/$1 + +# Compile Plugin for lib in $GODOT_PLUGINS; do - ./scripts/generate_xcframework.sh $lib release $1 - ./scripts/generate_xcframework.sh $lib release_debug $1 - mv ./bin/${lib}.release_debug.xcframework ./bin/${lib}.debug.xcframework + ./scripts/generate_xcframework.sh $lib release $2 $1 + ./scripts/generate_xcframework.sh $lib release_debug $2 $1 + mv ./bin/$1/${lib}.release_debug.xcframework ./bin/$1/${lib}.debug.xcframework done # Move to release folder -rm -rf ./bin/release -mkdir ./bin/release + +mkdir ./bin/$1/release # Move Plugin for lib in $GODOT_PLUGINS; do - mkdir ./bin/release/${lib} - mv ./bin/${lib}.{release,debug}.xcframework ./bin/release/${lib} - cp ./plugins/${lib}/${lib}.gdip ./bin/release/${lib} -done + mkdir ./bin/$1/release/${lib} + mv ./bin/$1/${lib}.{release,debug}.xcframework ./bin/$1/release/${lib} + cp ./plugins/${lib}/${lib}.gdip ./bin/$1/release/${lib}/${lib}.gdatvp +done \ No newline at end of file