diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b65a9eb8..d16f6ae0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,6 +41,16 @@ jobs: uses: actions/checkout@v4 with: submodules: recursive + - name: Cache vcpkg artifacts + uses: actions/cache@v4 + with: + path: "d:/.ezvcpkg" + key: vcpkg-windows-${{ hashFiles('native~/vcpkg/ports/**/vcpkg.json', 'native~/vcpkg/triplets/**/*', 'native~/extern/*toolchain.cmake') }}-${{ hashFiles('native~/extern/cesium-native/CMakeLists.txt', 'native~/CMakeLists.txt') }} + restore-keys: | + vcpkg-windows-${{ hashFiles('native~/vcpkg/ports/**/vcpkg.json', 'native~/vcpkg/triplets/**/*', 'native~/extern/*toolchain.cmake') }}- + - name: Install Ninja + run: | + choco install -y ninja - name: Install nasm uses: ilammy/setup-nasm@v1.5.1 - name: Install wget @@ -53,8 +63,8 @@ jobs: del ./UnityHubSetup.exe - name: Install Unity run: | - Start-Process -FilePath "C:/Program Files/Unity Hub/Unity Hub.exe" -Args "-- --headless install --version 2021.3.13f1 --changeset 9e7d58001ecf" -Wait - Start-Process -FilePath "C:/Program Files/Unity Hub/Unity Hub.exe" -Args "-- --headless install-modules --version 2021.3.13f1 --changeset 9e7d58001ecf --module android android-sdk-ndk-tools android-open-jdk-8u172-b11 universal-windows-platform uwp-il2cpp" -Wait + Start-Process -FilePath "C:/Program Files/Unity Hub/Unity Hub.exe" -Args "-- --headless install --version 2022.3.41f1 --changeset 0f988161febf" -Wait + Start-Process -FilePath "C:/Program Files/Unity Hub/Unity Hub.exe" -Args "-- --headless install-modules --version 2022.3.41f1 --changeset 0f988161febf --module android android-sdk-ndk-tools android-open-jdk-11.0.14.1+1 universal-windows-platform" -Wait - name: Create SSH tunnel to Unity License Server env: UNITY_LICENSE_SERVER_SSH_KEY: ${{ secrets.UNITY_LICENSE_SERVER_SSH_KEY }} @@ -93,6 +103,10 @@ jobs: run: | mkdir -p d:\cesium\CesiumForUnityBuildProject\Packages\com.cesium.unity mv $ENV:GITHUB_WORKSPACE/* d:\cesium\CesiumForUnityBuildProject\Packages\com.cesium.unity + # Disable Unity audio + mkdir -p d:\cesium\CesiumForUnityBuildProject\Packages\com.cesium.unity\ProjectSettings + $text="%YAML 1.1`n%TAG !u! tag:unity3d.com,2011:`n--- !u!11 &1`nAudioManager:`n m_DisableAudio: 1`n" + [IO.File]::WriteAllLines("d:/cesium/CesiumForUnityBuildProject/Packages/com.cesium.unity/ProjectSettings/AudioManager.asset",$text) - name: Build Reinterop run: | cd d:\cesium\CesiumForUnityBuildProject\Packages\com.cesium.unity @@ -103,9 +117,20 @@ jobs: mkdir -p d:\cesium\temp # Store temp files on the D drive, which is much faster than the EBS-backed C drive. $ENV:TEMP="d:\cesium\temp" + # We only need a release build of vcpkg dependencies + $ENV:CESIUM_VCPKG_RELEASE_ONLY="TRUE" + # Clear ANDROID_NDK_ROOT so that we use Unity's version + Remove-Item Env:ANDROID_NDK_ROOT + # Explicitly set the ezvcpkg path. Otherwise it will be `/.ezvcpkg` and the drive letter is ambiguous. + $ENV:EZVCPKG_BASEDIR="D:/.ezvcpkg" + # Run the build dotnet run --project Build~ - cat D:\cesium\CesiumForUnityBuildProject\Packages\com.cesium.unity\native~\build-WSA-x86_64\build.log - dir d:\cesium\CesiumForUnityBuildProject + - name: Publish Logs + if: success() || failure() # run this step even if previous step failed + uses: actions/upload-artifact@v4 + with: + name: Native Build Logs - Windows + path: d:/cesium/CesiumForUnityBuildProject/Packages/com.cesium.unity/native~/build-*/build.log - name: Publish package artifact if: ${{ success() }} uses: actions/upload-artifact@v4 @@ -114,7 +139,7 @@ jobs: path: d:\cesium\CesiumForUnityBuildProject\*.tgz - name: Run Tests run: | - start -FilePath "C:\Program Files\Unity\Hub\Editor\2021.3.13f1\Editor\Unity.exe" -ArgumentList "-runTests -batchmode -projectPath d:\cesium\CesiumForUnityBuildProject -testResults d:\cesium\temp\TestResults.xml -testPlatform PlayMode -logFile d:\cesium\temp\test-log.txt" -Wait + start -FilePath "C:\Program Files\Unity\Hub\Editor\2022.3.41f1\Editor\Unity.exe" -ArgumentList "-runTests -batchmode -projectPath d:\cesium\CesiumForUnityBuildProject -testResults d:\cesium\temp\TestResults.xml -testPlatform PlayMode -logFile d:\cesium\temp\test-log.txt" -Wait cat d:\cesium\temp\test-log.txt - name: Test Report uses: kring/test-reporter@v1.6.2-kring @@ -125,22 +150,23 @@ jobs: reporter: dotnet-nunit MacOS: needs: [QuickChecks] - runs-on: macos-12 + runs-on: macos-latest # Only allow a single macOS build at a time, for Unity licensing reasons concurrency: mac steps: - - name: Set XCode version - uses: maxim-lobanov/setup-xcode@v1 - with: - xcode-version: "14.1" - name: Check out repository code uses: actions/checkout@v4 with: submodules: recursive + - name: Cache vcpkg artifacts + uses: actions/cache@v4 + with: + path: "~/.ezvcpkg" + key: vcpkg-mac-${{ hashFiles('native~/vcpkg/ports/**/vcpkg.json', 'native~/vcpkg/triplets/**/*', 'native~/extern/*toolchain.cmake') }}-${{ hashFiles('native~/extern/cesium-native/CMakeLists.txt', 'native~/CMakeLists.txt') }} + restore-keys: | + vcpkg-mac-${{ hashFiles('native~/vcpkg/ports/**/vcpkg.json', 'native~/vcpkg/triplets/**/*', 'native~/extern/*toolchain.cmake') }}- - name: Install nasm uses: ilammy/setup-nasm@v1.5.1 - - name: Install jq - run: brew install jq - name: Install Unity Hub run: | wget --quiet https://public-cdn.cloud.unity3d.com/hub/prod/UnityHubSetup.dmg @@ -149,14 +175,14 @@ jobs: sudo cp -R "./UnityHubSetup/Unity Hub.app" /Applications hdiutil detach ./UnityHubSetup rm ./UnityHubSetup.dmg - - name: Install Unity 2021.3.13f1 + - name: Install Unity 2022.3.41f1 # This command sometimes returns exit code 130, despite actually succeeding. continue-on-error: true run: | - /Applications/Unity\ Hub.app/Contents/MacOS/Unity\ Hub -- --headless install --version 2021.3.13f1 --changeset 9e7d58001ecf --architecture x86_64 + /Applications/Unity\ Hub.app/Contents/MacOS/Unity\ Hub -- --headless install --version 2022.3.41f1 --changeset 0f988161febf --architecture arm64 - name: Install Unity iOS Support run: | - /Applications/Unity\ Hub.app/Contents/MacOS/Unity\ Hub -- --headless install-modules --version 2021.3.13f1 --changeset 9e7d58001ecf --module ios --architecture x86_64 + /Applications/Unity\ Hub.app/Contents/MacOS/Unity\ Hub -- --headless install-modules --version 2022.3.41f1 --changeset 0f988161febf --module ios --architecture arm64 - name: Configure Unity to Use the License Server run: | sudo mkdir -p "/Library/Application Support/Unity/config" @@ -196,19 +222,26 @@ jobs: run: | mkdir -p ~/cesium/CesiumForUnityBuildProject/Packages/com.cesium.unity mv $GITHUB_WORKSPACE/* ~/cesium/CesiumForUnityBuildProject/Packages/com.cesium.unity + # Disable Unity audio + mkdir -p ~/cesium/CesiumForUnityBuildProject/Packages/com.cesium.unity/ProjectSettings + echo '%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:\n--- !u!11 &1\nAudioManager:\n m_DisableAudio: 1\n' > ~/cesium/CesiumForUnityBuildProject/Packages/com.cesium.unity/ProjectSettings/AudioManager.asset - name: Build Reinterop run: | cd ~/cesium/CesiumForUnityBuildProject/Packages/com.cesium.unity dotnet publish Reinterop~ -o . - name: Build Package run: | + # We only need a release build of vcpkg dependencies + export CESIUM_VCPKG_RELEASE_ONLY="TRUE" cd ~/cesium/CesiumForUnityBuildProject/Packages/com.cesium.unity dotnet run --project Build~ ls -l ~/cesium/CesiumForUnityBuildProject - - name: Print log - if: ${{ failure() }} - run: | - cat /Users/runner/cesium/CesiumForUnityBuildProject/Packages/com.cesium.unity/native~/build-iOS/build.log + - name: Publish Logs + if: success() || failure() # run this step even if previous step failed + uses: actions/upload-artifact@v4 + with: + name: Native Build Logs - macOS + path: ~/cesium/CesiumForUnityBuildProject/Packages/com.cesium.unity/native~/build-*/build.log - name: Publish package artifact if: ${{ success() }} uses: actions/upload-artifact@v4 @@ -217,7 +250,7 @@ jobs: path: ~/cesium/CesiumForUnityBuildProject/*.tgz - name: Run Tests run: | - /Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/MacOS/Unity -runTests -batchmode -projectPath ~/cesium/CesiumForUnityBuildProject -testResults ~/cesium/CesiumForUnityBuildProject/TestResults.xml -testPlatform PlayMode -logFile ~/cesium/CesiumForUnityBuildProject/test-log.txt + /Applications/Unity/Hub/Editor/2022.3.41f1/Unity.app/Contents/MacOS/Unity -runTests -batchmode -projectPath ~/cesium/CesiumForUnityBuildProject -testResults ~/cesium/CesiumForUnityBuildProject/TestResults.xml -testPlatform PlayMode -logFile ~/cesium/CesiumForUnityBuildProject/test-log.txt cat ~/cesium/CesiumForUnityBuildProject/test-log.txt ls /Users/runner/cesium/CesiumForUnityBuildProject/TestResults.xml - name: Test Report diff --git a/.gitmodules b/.gitmodules index 2fab52ba..0a9976d6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,4 +6,8 @@ url = https://github.com/htacg/tidy-html5.git [submodule "native~/extern/enum-flags"] path = native~/extern/enum-flags - url = https://github.com/grisumbras/enum-flags.git + url = https://github.com/kring/enum-flags.git +[submodule "native~/extern/swl-variant"] + path = native~/extern/swl-variant + url = https://github.com/kring/swl-variant.git + branch = exception-public-inheritance diff --git a/Build~/Package.cs b/Build~/Package.cs index f009ae36..2225001b 100644 --- a/Build~/Package.cs +++ b/Build~/Package.cs @@ -36,13 +36,16 @@ public void Run() Directory.CreateDirectory(outputPackagePath); Console.WriteLine("**** Modifying the csc.rsp files to write generated files to disk"); - string generatedRuntimePath = Path.Combine(tempPath, "generated", "Runtime"); - Directory.CreateDirectory(generatedRuntimePath); - string generatedEditorPath = Path.Combine(tempPath, "generated", "Editor"); - Directory.CreateDirectory(generatedEditorPath); + string generatedRuntimeBasePath = Path.Combine(tempPath, "generated", "Runtime"); + Directory.CreateDirectory(generatedRuntimeBasePath); + string generatedEditorBasePath = Path.Combine(tempPath, "generated", "Editor"); + Directory.CreateDirectory(generatedEditorBasePath); - File.AppendAllText(runtimeCscRspPath, "-generatedfilesout:\"" + generatedRuntimePath + "\"" + Environment.NewLine, Encoding.UTF8); - File.AppendAllText(editorCscRspPath, "-generatedfilesout:\"" + generatedEditorPath + "\"" + Environment.NewLine, Encoding.UTF8); + File.AppendAllText(runtimeCscRspPath, "-generatedfilesout:\"" + generatedRuntimeBasePath + "\"" + Environment.NewLine, Encoding.UTF8); + File.AppendAllText(editorCscRspPath, "-generatedfilesout:\"" + generatedEditorBasePath + "\"" + Environment.NewLine, Encoding.UTF8); + + string generatedRuntimePath = Path.Combine(generatedRuntimeBasePath, "Reinterop"); + string generatedEditorPath = Path.Combine(generatedEditorBasePath, "Reinterop"); string sceneDirectory = Path.Combine(Utility.ProjectRoot, "Assets", "Scenes"); Directory.CreateDirectory(sceneDirectory); @@ -57,6 +60,24 @@ public void Run() } } + // Disable Unity audio, because we don't need it and because it seems to take 10-20 minutes + // to time out on macOS on GitHub Actions every time we start up Unity. + string projectSettingsDirectory = Path.Combine(Utility.ProjectRoot, "ProjectSettings"); + Directory.CreateDirectory(projectSettingsDirectory); + string audioManagerPath = Path.Combine(projectSettingsDirectory, "AudioManager.asset"); + if (!File.Exists(audioManagerPath)) + { + Console.WriteLine("**** Creating AudioManager.asset to disable Unity audio"); + using (StreamWriter audioManager = new StreamWriter(audioManagerPath)) + { + audioManager.WriteLine("%YAML 1.1"); + audioManager.WriteLine("%TAG !u! tag:unity3d.com,2011:"); + audioManager.WriteLine("--- !u!11 &1"); + audioManager.WriteLine("AudioManager:"); + audioManager.WriteLine(" m_DisableAudio: 1"); + } + } + Console.WriteLine("**** Compiling C# code for the Editor"); unity.Run(new[] { @@ -110,6 +131,11 @@ public void Run() if (OperatingSystem.IsMacOS()) { + configureArgs = configureArgs.Concat(new[] + { + "-DCMAKE_OSX_DEPLOYMENT_TARGET=10.15" + }).ToList(); + // On macOS, we must build the native code twice, once for x86_64 and once for arm64. // In theory we can build universal binaries, but some of our third party libraries don't // handle this well. @@ -161,6 +187,10 @@ public void Run() Console.WriteLine("**** Adding generated files (for the UWP Player) to the package"); AddGeneratedFiles("!UNITY_EDITOR && UNITY_WSA", generatedRuntimePath, Path.Combine(outputPackagePath, "Runtime", "generated")); + // Clean the generated code directory. + Directory.Delete(generatedRuntimePath, true); + Directory.CreateDirectory(generatedRuntimePath); + Console.WriteLine("**** Compiling for Windows Player"); unity.Run(new[] { diff --git a/CHANGES.md b/CHANGES.md index a5f7bc13..18b1dead 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,20 @@ # Change Log +## ? - ? + +##### Breaking Changes :mega: + +- Player builds for macOS now require macOS 10.15+. Previously, 10.13+ was supported. + +##### Additions :tada: + +- Editor builds for macOS now target macOS 10.15+. Previously, macOS 12.7+ was required. + +##### Fixes :wrench: + +- Fixed a bug that could cause a crash in `CesiumIonSession` when the object was garbage collected or the AppDomain was unloaded while network requests were in progress. +- Fixed a bug that could cause `CesiumFlyToController` to unexpectedly interrupt a flight. + ## v1.11.1 - 2024-08-01 ##### Fixes :wrench: diff --git a/Editor/BuildCesiumForUnity.cs b/Editor/BuildCesiumForUnity.cs index 8d8ed5f5..5b75633a 100644 --- a/Editor/BuildCesiumForUnity.cs +++ b/Editor/BuildCesiumForUnity.cs @@ -29,6 +29,8 @@ private static void OnEditorCompilationFinished(object o) public static void CompileForAndroidAndExit() { + CompileCesiumForUnityNative.ExitAfterCompile = true; + string buildPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(buildPath); try @@ -46,6 +48,8 @@ public static void CompileForAndroidAndExit() public static void CompileForUWPAndExit() { + CompileCesiumForUnityNative.ExitAfterCompile = true; + string buildPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(buildPath); try @@ -62,6 +66,8 @@ public static void CompileForUWPAndExit() public static void CompileForIOSAndExit() { + CompileCesiumForUnityNative.ExitAfterCompile = true; + string buildPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(buildPath); try @@ -85,6 +91,8 @@ public static void CompileForIOSAndExit() public static void CompileForWindowsAndExit() { + CompileCesiumForUnityNative.ExitAfterCompile = true; + string buildPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(buildPath); try @@ -100,6 +108,8 @@ public static void CompileForWindowsAndExit() public static void CompileForMacAndExit() { + CompileCesiumForUnityNative.ExitAfterCompile = true; + string buildPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(buildPath); try diff --git a/Editor/CompileCesiumForUnityNative.cs b/Editor/CompileCesiumForUnityNative.cs index 52de6f9f..1b8657ab 100644 --- a/Editor/CompileCesiumForUnityNative.cs +++ b/Editor/CompileCesiumForUnityNative.cs @@ -195,6 +195,16 @@ private static void OnPostprocessAllAssets( public int callbackOrder => 0; + /// + /// True if Unity should exit immediately after `OnPostBuildPlayerScriptDLLs` completes. + /// + public static bool ExitAfterCompile = false; + + /// + /// The exit code of the last step of the build process, such as cmake or lipo. + /// + private static int LastRunExitCode = 0; + /// /// Invoked after the managed script assemblies are compiled, including the CesiumForUnity /// managed code. Building the CesiumForUnity assembly will generate C++ code via Reinterop, @@ -225,13 +235,21 @@ public void OnPostBuildPlayerScriptDLLs(BuildReport report) Process p = Process.Start("lipo", string.Join(' ', args)); p.WaitForExit(); if (p.ExitCode != 0) - throw new Exception("lipo failed"); + { + UnityEngine.Debug.LogError($"Invocation of 'lipo' tool failed. The command-line was:{Environment.NewLine}lipo {string.Join(' ', args)}"); + LastRunExitCode = p.ExitCode; + } foreach (LibraryToBuild library in libraries) { Directory.Delete(library.InstallDirectory, true); } } + + if (ExitAfterCompile) + { + EditorApplication.Exit(LastRunExitCode); + } } /// @@ -338,6 +356,7 @@ public static LibraryToBuild GetLibraryToBuild(PlatformToBuild platform, Library library.ExtraConfigureArgs.Add("-DCMAKE_SYSTEM_NAME=iOS"); library.ExtraConfigureArgs.Add("-DCMAKE_SYSTEM_PROCESSOR=aarch64"); library.ExtraConfigureArgs.Add("-DCMAKE_OSX_ARCHITECTURES=arm64"); + library.ExtraConfigureArgs.Add("-DOSX_DEPLOYMENT_TARGET=12"); } if (platform.platform == BuildTarget.StandaloneOSX) @@ -345,7 +364,7 @@ public static LibraryToBuild GetLibraryToBuild(PlatformToBuild platform, Library if (cpu != null) library.ExtraConfigureArgs.Add("-DCMAKE_OSX_ARCHITECTURES=" + cpu.ToString().ToLowerInvariant()); - library.ExtraConfigureArgs.Add("-DCMAKE_OSX_DEPLOYMENT_TARGET=10.13"); + library.ExtraConfigureArgs.Add("-DCMAKE_OSX_DEPLOYMENT_TARGET=10.15"); } if (platform.platform == BuildTarget.WSAPlayer) @@ -400,6 +419,9 @@ private static string GetDirectoryNameForPlatform(BuildTargetGroup platformGroup return "Editor"; else if (IsIOS(platformGroup, platform)) return "iOS"; + // Make sure we use "WSA" and not "Metro" + else if (platformGroup == BuildTargetGroup.WSA) + return "WSA"; return platformGroup.ToString(); } @@ -422,7 +444,7 @@ internal static void BuildNativeLibrary(LibraryToBuild library) string projectPath = Path.Combine(Application.dataPath, ".."); string logDisplayName = Path.GetRelativePath(projectPath, logFilename); - EditorUtility.DisplayProgressBar($"Building CesiumForUnityNative", $"See {logDisplayName}.", 0.0f); + EditorUtility.DisplayProgressBar($"Building CesiumForUnityNative: {Path.GetFileName(library.BuildDirectory)}", $"See {logDisplayName}.", 0.0f); using (StreamWriter log = new StreamWriter(logFilename, false, Encoding.UTF8)) { @@ -510,6 +532,7 @@ private static void RunAndLog(ProcessStartInfo startInfo, StreamWriter log, stri if (configure.ExitCode != 0) { UnityEngine.Debug.LogError($"An error occurred while building CesiumForUnityNative. See {logFilename} for details. The command-line was:{Environment.NewLine}{startInfo.FileName} {startInfo.Arguments}"); + LastRunExitCode = configure.ExitCode; } } } @@ -531,12 +554,18 @@ private static void ConfigureEnvironmentVariables(IDictionary en // the default) won't work to build for Android. if (library.Platform == BuildTarget.Android && Environment.OSVersion.Platform == PlatformID.Win32NT) { - library.ExtraConfigureArgs.Add("-G \"Unix Makefiles\""); + library.ExtraConfigureArgs.Add("-G Ninja"); - if (!string.IsNullOrEmpty(ndkRoot)) + // If the NDK root has a space in it, this will confuse broken software like OpenSSL's build process. + // So map a drive letter and rewrite the path. + if (ndkRoot != null && ndkRoot.Contains(' ')) { - string make = Path.Combine(ndkRoot, "prebuilt", "windows-x86_64", "bin", "make.exe").Replace('\\', '/'); - library.ExtraConfigureArgs.Add($"-DCMAKE_MAKE_PROGRAM=\"{make}\""); + if (!Directory.Exists("N:\\")) + { + Process.Start("subst", "N: \"" + ndkRoot + "\"").WaitForExit(); + } + + ndkRoot = "N:\\"; } } diff --git a/Runtime/CesiumFlyToController.cs b/Runtime/CesiumFlyToController.cs index 51eb7c4d..740f7b25 100644 --- a/Runtime/CesiumFlyToController.cs +++ b/Runtime/CesiumFlyToController.cs @@ -219,8 +219,9 @@ private void Reset() private bool DetectMovementInput() { double3 currentPositionECEF = this._globeAnchor.positionGlobeFixed; - bool3 positionEquality = currentPositionECEF == this._previousPositionECEF; - return !positionEquality.x || !positionEquality.y || !positionEquality.z; + double distanceSquared = math.lengthsq(currentPositionECEF - this._previousPositionECEF); + const double distanceConsideredMovement = 1e-6; // 1/1000 of a millimeter + return distanceSquared >= (distanceConsideredMovement * distanceConsideredMovement); } /// diff --git a/Tests/TestCesiumFlyToController.cs b/Tests/TestCesiumFlyToController.cs index d2c6bd50..e7196ebe 100644 --- a/Tests/TestCesiumFlyToController.cs +++ b/Tests/TestCesiumFlyToController.cs @@ -74,4 +74,63 @@ public IEnumerator FlyToLocationLongitudeLatitudeHeight() Assert.That(goFlyer.transform.position.y, Is.EqualTo(0.0f).Using(FloatEqualityComparer.Instance)); Assert.That(goFlyer.transform.position.z, Is.EqualTo(0.0f).Using(FloatEqualityComparer.Instance)); } + + [UnityTest] + public IEnumerator FlyToLocationLongitudeLatitudeHeightInterrupted() + { + GameObject goGeoreference = new GameObject("Georeference"); + CesiumGeoreference georeference = goGeoreference.AddComponent(); + georeference.longitude = -55.0; + georeference.latitude = 55.0; + georeference.height = 1000.0; + + GameObject goFlyer = new GameObject("Flyer"); + goFlyer.transform.parent = goGeoreference.transform; + + CesiumGlobeAnchor anchor = goFlyer.AddComponent(); + goFlyer.AddComponent(); + CesiumFlyToController flyToController = goFlyer.AddComponent(); + + // Make the flight fast so the test doesn't take too long. + flyToController.flyToDuration = 0.25; + + anchor.adjustOrientationForGlobeWhenMoving = false; + anchor.longitudeLatitudeHeight = new double3(20.0, -25.0, 1000.0); + anchor.adjustOrientationForGlobeWhenMoving = true; + + yield return null; + + // The origin should have been shifted so the flyer is at the origin. + Assert.That(goFlyer.transform.position.x, Is.EqualTo(0.0f).Using(FloatEqualityComparer.Instance)); + Assert.That(goFlyer.transform.position.y, Is.EqualTo(0.0f).Using(FloatEqualityComparer.Instance)); + Assert.That(goFlyer.transform.position.z, Is.EqualTo(0.0f).Using(FloatEqualityComparer.Instance)); + + // Start a flight to elsewhere + bool flightComplete = false; + flyToController.OnFlightComplete += () => + { + flightComplete = true; + }; + + bool flightInterrupted = false; + flyToController.OnFlightInterrupted += () => + { + flightInterrupted = true; + }; + + flyToController.FlyToLocationLongitudeLatitudeHeight(new double3(100.0, 25.0, 800.0), 0.0f, 0.0f, true); + + yield return null; + + Assert.IsFalse(flightComplete); + Assert.IsFalse(flightInterrupted); + + // Give the object a new position, which should abort the flight. + goFlyer.transform.position = new Vector3(100.0f, 200.0f, 300.0f); + + yield return null; + + Assert.IsFalse(flightComplete); + Assert.IsTrue(flightInterrupted); + } } diff --git a/Tests/TestCesiumGeoreference.cs b/Tests/TestCesiumGeoreference.cs index efeca57f..4f67049d 100644 --- a/Tests/TestCesiumGeoreference.cs +++ b/Tests/TestCesiumGeoreference.cs @@ -24,21 +24,22 @@ public IEnumerator ChangingOriginAtRuntimeUpdatesGlobeAnchors() yield return null; - Assert.That(goAnchored.transform.localPosition.x, Is.EqualTo(0.0f)); - Assert.That(goAnchored.transform.localPosition.y, Is.EqualTo(0.0f)); - Assert.That(goAnchored.transform.localPosition.z, Is.EqualTo(0.0f)); + IEqualityComparer epsilon8f = new FloatEqualityComparer(1e-8f); + Assert.That(goAnchored.transform.localPosition.x, Is.EqualTo(0.0f).Using(epsilon8f)); + Assert.That(goAnchored.transform.localPosition.y, Is.EqualTo(0.0f).Using(epsilon8f)); + Assert.That(goAnchored.transform.localPosition.z, Is.EqualTo(0.0f).Using(epsilon8f)); georeference.SetOriginLongitudeLatitudeHeight(-55.1, 54.9, 1001.0); - Assert.That(goAnchored.transform.localPosition.x, Is.Not.EqualTo(0.0f)); - Assert.That(goAnchored.transform.localPosition.y, Is.Not.EqualTo(0.0f)); - Assert.That(goAnchored.transform.localPosition.z, Is.Not.EqualTo(0.0f)); + Assert.That(goAnchored.transform.localPosition.x, Is.Not.EqualTo(0.0f).Using(epsilon8f)); + Assert.That(goAnchored.transform.localPosition.y, Is.Not.EqualTo(0.0f).Using(epsilon8f)); + Assert.That(goAnchored.transform.localPosition.z, Is.Not.EqualTo(0.0f).Using(epsilon8f)); yield return null; - Assert.That(goAnchored.transform.localPosition.x, Is.Not.EqualTo(0.0f)); - Assert.That(goAnchored.transform.localPosition.y, Is.Not.EqualTo(0.0f)); - Assert.That(goAnchored.transform.localPosition.z, Is.Not.EqualTo(0.0f)); + Assert.That(goAnchored.transform.localPosition.x, Is.Not.EqualTo(0.0f).Using(epsilon8f)); + Assert.That(goAnchored.transform.localPosition.y, Is.Not.EqualTo(0.0f).Using(epsilon8f)); + Assert.That(goAnchored.transform.localPosition.z, Is.Not.EqualTo(0.0f).Using(epsilon8f)); } [UnityTest] @@ -56,9 +57,10 @@ public IEnumerator ChangingParentTransformAndGeoreferenceMaintainsCorrectGlobePo yield return null; - Assert.That(goAnchored.transform.localPosition.x, Is.EqualTo(0.0f)); - Assert.That(goAnchored.transform.localPosition.y, Is.EqualTo(0.0f)); - Assert.That(goAnchored.transform.localPosition.z, Is.EqualTo(0.0f)); + IEqualityComparer epsilon8f = new FloatEqualityComparer(1e-8f); + Assert.That(goAnchored.transform.localPosition.x, Is.EqualTo(0.0f).Using(epsilon8f)); + Assert.That(goAnchored.transform.localPosition.y, Is.EqualTo(0.0f).Using(epsilon8f)); + Assert.That(goAnchored.transform.localPosition.z, Is.EqualTo(0.0f).Using(epsilon8f)); // Change both the origin and the transform. georeference.transform.localPosition = new Vector3(100.0f, 200.0f, 300.0f); @@ -74,10 +76,10 @@ public IEnumerator ChangingParentTransformAndGeoreferenceMaintainsCorrectGlobePo // Its local local position should be affected by the georeference origin change // but not by the parent transform change. - IEqualityComparer epsilon4 = new FloatEqualityComparer(1e-3f); - Assert.That(goAnchored.transform.localPosition.x, Is.EqualTo(0.0f).Using(epsilon4)); - Assert.That(goAnchored.transform.localPosition.y, Is.EqualTo(-1000.0f).Using(epsilon4)); - Assert.That(goAnchored.transform.localPosition.z, Is.EqualTo(0.0f).Using(epsilon4)); + IEqualityComparer epsilon3 = new FloatEqualityComparer(1e-3f); + Assert.That(goAnchored.transform.localPosition.x, Is.EqualTo(0.0f).Using(epsilon3)); + Assert.That(goAnchored.transform.localPosition.y, Is.EqualTo(-1000.0f).Using(epsilon3)); + Assert.That(goAnchored.transform.localPosition.z, Is.EqualTo(0.0f).Using(epsilon3)); } [UnityTest] @@ -97,13 +99,14 @@ public IEnumerator GeoreferenceScaleAffectsGlobeAnchors() yield return null; - Assert.That(goAnchored.transform.localPosition.x, Is.EqualTo(1.0f)); - Assert.That(goAnchored.transform.localPosition.y, Is.EqualTo(2.0f)); - Assert.That(goAnchored.transform.localPosition.z, Is.EqualTo(3.0f)); + IEqualityComparer epsilon8f = new FloatEqualityComparer(1e-8f); + Assert.That(goAnchored.transform.localPosition.x, Is.EqualTo(1.0f).Using(epsilon8f)); + Assert.That(goAnchored.transform.localPosition.y, Is.EqualTo(2.0f).Using(epsilon8f)); + Assert.That(goAnchored.transform.localPosition.z, Is.EqualTo(3.0f).Using(epsilon8f)); - Assert.That(goAnchored.transform.localScale.x, Is.EqualTo(4.0f)); - Assert.That(goAnchored.transform.localScale.y, Is.EqualTo(5.0f)); - Assert.That(goAnchored.transform.localScale.z, Is.EqualTo(6.0f)); + Assert.That(goAnchored.transform.localScale.x, Is.EqualTo(4.0f).Using(epsilon8f)); + Assert.That(goAnchored.transform.localScale.y, Is.EqualTo(5.0f).Using(epsilon8f)); + Assert.That(goAnchored.transform.localScale.z, Is.EqualTo(6.0f).Using(epsilon8f)); // The globe anchor's scale initially matches the local scale. IEqualityComparer epsilon8 = Comparers.Double(1e-8); diff --git a/native~/CMakeLists.txt b/native~/CMakeLists.txt index f1e2b10c..77599343 100644 --- a/native~/CMakeLists.txt +++ b/native~/CMakeLists.txt @@ -6,6 +6,12 @@ project(CesiumForUnityNative LANGUAGES CXX C ) +# By default, vcpkg (or is it cmake?) will try to link against the Debug version +# of the vcpkg libraries when we build the RelWithDebInfo configuration. Tell it +# to prefer Release instead. vcpkg Release builds DO have debug symbols, just like +# RelWithDebInfo. +SET(CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO "RelWithDebInfo;Release;") + # When building for the Editor, both Runtime and Editor assemblies are # written to the Editor directory so that Unity won't load them in # a standalone build. @@ -57,7 +63,35 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Android") set(ANDROID_NDK ${CMAKE_ANDROID_NDK}) endif() -add_subdirectory(extern/cesium-native EXCLUDE_FROM_ALL) +# vcpkg setup +set(ENV{VCPKG_OVERLAY_PORTS} "${CMAKE_CURRENT_LIST_DIR}/vcpkg/ports") +set(ENV{VCPKG_OVERLAY_TRIPLETS} "${CMAKE_CURRENT_LIST_DIR}/vcpkg/triplets") + +include(${CMAKE_CURRENT_SOURCE_DIR}/extern/cesium-native/cmake/detect-vcpkg-triplet.cmake) + +if (NOT VCPKG_TRIPLET) + if (DEFINED ENV{VCPKG_TRIPLET}) + set(VCPKG_TRIPLET "$ENV{VCPKG_TRIPLET}") + elseif(DETECTED_VCPKG_TRIPLET_ERROR) + message(FATAL_ERROR "${DETECTED_VCPKG_TRIPLET_ERROR}") + else() + set(VCPKG_TRIPLET "${DETECTED_VCPKG_TRIPLET}-unity") + endif() +endif() + +# We never need any of cesium-native's header files to be installed. +set(CESIUM_INSTALL_HEADERS OFF) + +# We only need cesium-native's static lib files to be installed on iOS. +if (NOT IOS) + set(CESIUM_INSTALL_STATIC_LIBS OFF) +endif() + +add_subdirectory(extern/swl-variant) +add_subdirectory(extern/cesium-native) + +# Don't build the cesium-native tests by default. +set_target_properties(cesium-native-tests PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1) # Enum flags is a header-only library without a CMakeLists.txt file(GLOB ENUM_FLAGS_HEADERS ${CMAKE_CURRENT_LIST_DIR}/extern/enum-flags/include/*.hpp) @@ -73,70 +107,6 @@ set(LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}) # Specify all targets that need to compile bitcode if (${CMAKE_SYSTEM_NAME} STREQUAL "iOS") - set (ALL_TARGETS - CesiumForUnityNative-Runtime - Async++ - Cesium3DTilesContent - Cesium3DTilesReader - Cesium3DTilesSelection - CesiumAsync - CesiumGeometry - CesiumGeospatial - CesiumGltf - CesiumGltfContent - CesiumGltfReader - CesiumJsonReader - CesiumRasterOverlays - CesiumQuantizedMeshTerrain - CesiumUtility - draco_attributes - draco_compression_attributes_dec - draco_compression_bit_coders - draco_compression_entropy - draco_compression_decode - draco_compression_mesh_dec - draco_compression_point_cloud_dec - draco_core - draco_mesh - draco_metadata - draco_metadata_dec - draco_point_cloud - draco_points_dec - draco_static - expected-lite - GSL - httplib - ktx - meshoptimizer - modp_b64 - spdlog - sqlite3 - s2geometry - tinyxml2 - tidy-static - uriparser - webpdecode - webpdecoder - webpdspdecode - webputils - webputilsdecode - zlibstatic - ) - set(MESHOPT_BUILD_SHARED_LIBS OFF BOOL FORCE) install(TARGETS tidy-static) - install( - TARGETS ${ALL_TARGETS} - PUBLIC_HEADER - EXCLUDE_FROM_ALL - FRAMEWORK - DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) - set_target_properties(cesium-native-tests PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1) set_target_properties(tidy-static PROPERTIES EXCLUDE_FROM_ALL 0 EXCLUDE_FROM_DEFAULT_BUILD 0) - set_target_properties(${ALL_TARGETS} PROPERTIES XCODE_ATTRIBUTE_ENABLE_BITCODE "YES") - - # ktx tags itself as a FRAMEWORK on iOS, which causes linker errors. Undo that. - set_target_properties(ktx PROPERTIES FRAMEWORK FALSE) endif() - - diff --git a/native~/Editor/CMakeLists.txt b/native~/Editor/CMakeLists.txt index ba8183ba..5bd262f0 100644 --- a/native~/Editor/CMakeLists.txt +++ b/native~/Editor/CMakeLists.txt @@ -41,7 +41,7 @@ target_link_libraries( set_target_properties( CesiumForUnityNative-Editor PROPERTIES - CXX_STANDARD 17 + CXX_STANDARD 20 CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO ) diff --git a/native~/Editor/src/CesiumEditorWindowImpl.cpp b/native~/Editor/src/CesiumEditorWindowImpl.cpp index b4c31dcf..0b59e296 100644 --- a/native~/Editor/src/CesiumEditorWindowImpl.cpp +++ b/native~/Editor/src/CesiumEditorWindowImpl.cpp @@ -134,7 +134,7 @@ void CesiumEditorWindowImpl::AddAssetFromIon( } tileset.ionAssetID(tilesetID); - getNativeSession().getAssets(); + getNativeSession().getAssets(getSession()); if (overlayID > 0) { // TODO: Need to fix this when we support multiple overlays diff --git a/native~/Editor/src/CesiumIonSessionImpl.cpp b/native~/Editor/src/CesiumIonSessionImpl.cpp index 797e2a84..669c1c16 100644 --- a/native~/Editor/src/CesiumIonSessionImpl.cpp +++ b/native~/Editor/src/CesiumIonSessionImpl.cpp @@ -165,10 +165,13 @@ void CesiumIonSessionImpl::Connect( ionServerUrl); std::move(futureApiUrl) - .thenInMainThread([ionServerUrl, server, session, this]( + .thenInMainThread([ionServerUrl, + server, + session, + this, + asyncSystem = this->_asyncSystem]( std::optional&& ionApiUrl) { - CesiumAsync::Promise promise = - this->_asyncSystem.createPromise(); + CesiumAsync::Promise promise = asyncSystem.createPromise(); if (session == nullptr) { promise.reject( @@ -278,11 +281,15 @@ void CesiumIonSessionImpl::Resume( // Verify that the connection actually works. this->ensureAppDataLoaded(session) - .thenInMainThread([this, userAccessToken, server](bool loadedAppData) { - CesiumAsync::Promise promise = - this->_asyncSystem.createPromise(); - - if (!loadedAppData || !this->_appData.has_value()) { + .thenInMainThread([this, + session, + userAccessToken, + server, + asyncSystem = this->_asyncSystem](bool loadedAppData) { + CesiumAsync::Promise promise = asyncSystem.createPromise(); + + if (session == nullptr || !loadedAppData || + !this->_appData.has_value()) { promise.reject(std::runtime_error( "Failed to obtain _appData, can't resume connection")); return promise.getFuture(); @@ -290,8 +297,8 @@ void CesiumIonSessionImpl::Resume( if (this->_appData->needsOauthAuthentication() && System::String::IsNullOrEmpty(userAccessToken)) { - // No user access token was stored, so there's no existing session to - // resume. + // No user access token was stored, so there's no existing session + // to resume. promise.resolve(); this->_isResuming = false; return promise.getFuture(); @@ -306,9 +313,12 @@ void CesiumIonSessionImpl::Resume( server.apiUrl().ToStlString()); return pConnection->me().thenInMainThread( - [this, - pConnection](CesiumIonClient::Response&& - response) { + [this, session, pConnection]( + CesiumIonClient::Response&& + response) { + if (session == nullptr) + return; + logResponseErrors(response); if (response.value.has_value()) { this->_connection = std::move(*pConnection); @@ -317,10 +327,13 @@ void CesiumIonSessionImpl::Resume( this->_quickAddItems = nullptr; this->broadcastConnectionUpdate(); - this->startQueuedLoads(); + this->startQueuedLoads(session); }); }) - .catchInMainThread([this](std::exception&& e) { + .catchInMainThread([this, session](std::exception&& e) { + if (session == nullptr) + return; + logResponseErrors(e); this->_isResuming = false; }); @@ -356,7 +369,7 @@ void CesiumIonSessionImpl::Tick( System::String CesiumIonSessionImpl::GetProfileUsername( const DotNet::CesiumForUnity::CesiumIonSession& session) { - return System::String(this->getProfile().username); + return System::String(this->getProfile(session).username); } System::String CesiumIonSessionImpl::GetAuthorizeUrl( @@ -381,7 +394,7 @@ CesiumIonSessionImpl::GetQuickAddItems( DotNet::CesiumForUnity::QuickAddItem> result{}; - const CesiumIonClient::Defaults& defaults = this->getDefaults(); + const CesiumIonClient::Defaults& defaults = this->getDefaults(session); for (const CesiumIonClient::QuickAddAsset& asset : defaults.quickAddAssets) { if (asset.type == "3DTILES" || (asset.type == "TERRAIN" && !asset.rasterOverlays.empty())) { @@ -406,10 +419,11 @@ CesiumIonSessionImpl::GetQuickAddItems( void CesiumIonSessionImpl::RefreshProfile( const DotNet::CesiumForUnity::CesiumIonSession& session) { - this->refreshProfile(); + this->refreshProfile(session); } -void CesiumIonSessionImpl::refreshProfile() { +void CesiumIonSessionImpl::refreshProfile( + const DotNet::CesiumForUnity::CesiumIonSession& session) { if (!this->_connection || this->_isLoadingProfile) { this->_loadProfileQueued = true; return; @@ -420,29 +434,30 @@ void CesiumIonSessionImpl::refreshProfile() { this->_connection->me() .thenInMainThread( - [this]( + [this, session]( CesiumIonClient::Response&& profile) { this->_isLoadingProfile = false; this->_profile = std::move(profile.value); this->broadcastProfileUpdate(); if (this->_loadProfileQueued) - this->refreshProfile(); + this->refreshProfile(session); }) - .catchInMainThread([this](std::exception&& e) { + .catchInMainThread([this, session](std::exception&& e) { this->_isLoadingProfile = false; this->_profile = std::nullopt; this->broadcastProfileUpdate(); if (this->_loadProfileQueued) - this->refreshProfile(); + this->refreshProfile(session); }); } void CesiumIonSessionImpl::RefreshAssets( const DotNet::CesiumForUnity::CesiumIonSession& session) { - this->refreshAssets(); + this->refreshAssets(session); } -void CesiumIonSessionImpl::refreshAssets() { +void CesiumIonSessionImpl::refreshAssets( + const DotNet::CesiumForUnity::CesiumIonSession& session) { if (!this->_connection || this->_isLoadingAssets) { this->_loadAssetsQueued = true; return; @@ -453,33 +468,35 @@ void CesiumIonSessionImpl::refreshAssets() { this->_connection->assets() .thenInMainThread( - [this](CesiumIonClient::Response&& assets) { + [this, session]( + CesiumIonClient::Response&& assets) { this->_isLoadingAssets = false; this->_assets = std::move(assets.value); this->broadcastAssetsUpdate(); if (this->_loadAssetsQueued) - this->refreshAssets(); + this->refreshAssets(session); }) - .catchInMainThread([this](std::exception&& e) { + .catchInMainThread([this, session](std::exception&& e) { this->_isLoadingAssets = false; this->_assets = std::nullopt; this->broadcastAssetsUpdate(); if (this->_loadAssetsQueued) - this->refreshAssets(); + this->refreshAssets(session); }); } void CesiumIonSessionImpl::RefreshTokens( const DotNet::CesiumForUnity::CesiumIonSession& session) { - this->refreshTokens(); + this->refreshTokens(session); } void CesiumIonSessionImpl::RefreshDefaults( const DotNet::CesiumForUnity::CesiumIonSession& session) { - this->refreshDefaults(); + this->refreshDefaults(session); } -void CesiumIonSessionImpl::refreshTokens() { +void CesiumIonSessionImpl::refreshTokens( + const DotNet::CesiumForUnity::CesiumIonSession& session) { if (!this->_connection || this->_isLoadingTokens) { this->_loadTokensQueued = true; return; @@ -490,7 +507,7 @@ void CesiumIonSessionImpl::refreshTokens() { this->_connection->tokens() .thenInMainThread( - [this]( + [this, session]( CesiumIonClient::Response&& tokens) { this->_isLoadingTokens = false; this->_tokens = @@ -499,18 +516,19 @@ void CesiumIonSessionImpl::refreshTokens() { : std::nullopt; this->broadcastTokensUpdate(); if (this->_loadTokensQueued) - this->refreshTokens(); + this->refreshTokens(session); }) - .catchInMainThread([this](std::exception&& e) { + .catchInMainThread([this, session](std::exception&& e) { this->_isLoadingTokens = false; this->_tokens = std::nullopt; this->broadcastTokensUpdate(); if (this->_loadTokensQueued) - this->refreshTokens(); + this->refreshTokens(session); }); } -void CesiumIonSessionImpl::refreshDefaults() { +void CesiumIonSessionImpl::refreshDefaults( + const DotNet::CesiumForUnity::CesiumIonSession& session) { if (!this->_connection || this->_isLoadingDefaults) { this->_loadDefaultsQueued = true; return; @@ -521,7 +539,7 @@ void CesiumIonSessionImpl::refreshDefaults() { this->_connection->defaults() .thenInMainThread( - [this]( + [this, session]( CesiumIonClient::Response&& defaults) { logResponseErrors(defaults); this->_isLoadingDefaults = false; @@ -529,43 +547,47 @@ void CesiumIonSessionImpl::refreshDefaults() { this->_quickAddItems = nullptr; this->broadcastDefaultsUpdate(); if (this->_loadDefaultsQueued) - this->refreshDefaults(); + this->refreshDefaults(session); }) - .catchInMainThread([this](std::exception&& e) { + .catchInMainThread([this, session](std::exception&& e) { logResponseErrors(e); this->_isLoadingDefaults = false; this->_defaults = std::nullopt; this->_quickAddItems = nullptr; this->broadcastDefaultsUpdate(); if (this->_loadDefaultsQueued) - this->refreshDefaults(); + this->refreshDefaults(session); }); } -bool CesiumIonSessionImpl::refreshProfileIfNeeded() { +bool CesiumIonSessionImpl::refreshProfileIfNeeded( + const DotNet::CesiumForUnity::CesiumIonSession& session) { if (this->_loadProfileQueued || !this->_profile.has_value()) { - this->refreshProfile(); + this->refreshProfile(session); } return this->_profile.has_value(); } -bool CesiumIonSessionImpl::refreshAssetsIfNeeded() { +bool CesiumIonSessionImpl::refreshAssetsIfNeeded( + const DotNet::CesiumForUnity::CesiumIonSession& session) { if (this->_loadAssetsQueued || !this->_assets.has_value()) { - this->refreshAssets(); + this->refreshAssets(session); } return this->_assets.has_value(); } -bool CesiumIonSessionImpl::refreshTokensIfNeeded() { +bool CesiumIonSessionImpl::refreshTokensIfNeeded( + const DotNet::CesiumForUnity::CesiumIonSession& session) { if (this->_loadTokensQueued || !this->_tokens.has_value()) { - this->refreshTokens(); + this->refreshTokens(session); } return this->_tokens.has_value(); } -bool CesiumIonSessionImpl::refreshDefaultsIfNeeded() { +bool CesiumIonSessionImpl::refreshDefaultsIfNeeded( + const DotNet::CesiumForUnity::CesiumIonSession& session) { if (this->_loadDefaultsQueued || !this->_defaults.has_value()) { - this->refreshDefaults(); + this->refreshDefaults(session); } return this->_defaults.has_value(); } @@ -677,32 +699,35 @@ CesiumIonSessionImpl::getConnection() const { return this->_connection; } -const CesiumIonClient::Profile& CesiumIonSessionImpl::getProfile() { +const CesiumIonClient::Profile& CesiumIonSessionImpl::getProfile( + const DotNet::CesiumForUnity::CesiumIonSession& session) { static const CesiumIonClient::Profile empty{}; if (this->_profile) { return *this->_profile; } else { - this->refreshProfile(); + this->refreshProfile(session); return empty; } } -const CesiumIonClient::Assets& CesiumIonSessionImpl::getAssets() { +const CesiumIonClient::Assets& CesiumIonSessionImpl::getAssets( + const DotNet::CesiumForUnity::CesiumIonSession& session) { static const CesiumIonClient::Assets empty; if (this->_assets) { return *this->_assets; } else { - this->refreshAssets(); + this->refreshAssets(session); return empty; } } -const std::vector& CesiumIonSessionImpl::getTokens() { +const std::vector& CesiumIonSessionImpl::getTokens( + const DotNet::CesiumForUnity::CesiumIonSession& session) { static const std::vector empty; if (this->_tokens) { return *this->_tokens; } else { - this->refreshTokens(); + this->refreshTokens(session); return empty; } } @@ -715,12 +740,13 @@ const CesiumIonClient::ApplicationData& CesiumIonSessionImpl::getAppData() { return empty; } -const CesiumIonClient::Defaults& CesiumIonSessionImpl::getDefaults() { +const CesiumIonClient::Defaults& CesiumIonSessionImpl::getDefaults( + const DotNet::CesiumForUnity::CesiumIonSession& session) { static const CesiumIonClient::Defaults empty; if (this->_defaults) { return *this->_defaults; } else { - this->refreshDefaults(); + this->refreshDefaults(session); return empty; } } @@ -738,15 +764,16 @@ CesiumAsync::AsyncSystem& CesiumIonSessionImpl::getAsyncSystem() { return this->_asyncSystem; } -void CesiumIonSessionImpl::startQueuedLoads() { +void CesiumIonSessionImpl::startQueuedLoads( + const DotNet::CesiumForUnity::CesiumIonSession& session) { if (this->_loadProfileQueued) - this->refreshProfile(); + this->refreshProfile(session); if (this->_loadAssetsQueued) - this->refreshAssets(); + this->refreshAssets(session); if (this->_loadTokensQueued) - this->refreshTokens(); + this->refreshTokens(session); if (this->_loadDefaultsQueued) - this->refreshDefaults(); + this->refreshDefaults(session); } CesiumAsync::Future CesiumIonSessionImpl::ensureAppDataLoaded( @@ -758,11 +785,18 @@ CesiumAsync::Future CesiumIonSessionImpl::ensureAppDataLoaded( this->_pAssetAccessor, server.apiUrl().ToStlString()) .thenInMainThread( - [this, session]( + [this, session, asyncSystem = this->_asyncSystem]( CesiumIonClient::Response&& appData) { CesiumAsync::Promise promise = - this->_asyncSystem.createPromise(); + asyncSystem.createPromise(); + + if (session == nullptr) { + UnityEngine::Debug::LogError( + System::String("CesiumIonSession unexpectedly nullptr")); + promise.resolve(false); + return promise.getFuture(); + } this->_appData = appData.value; if (!appData.value.has_value()) { @@ -776,9 +810,10 @@ CesiumAsync::Future CesiumIonSessionImpl::ensureAppDataLoaded( return promise.getFuture(); }) - .catchInMainThread([this](std::exception&& e) { + .catchInMainThread([this, session, asyncSystem = this->_asyncSystem]( + std::exception&& e) { logResponseErrors(e); - return this->_asyncSystem.createResolvedFuture(false); + return asyncSystem.createResolvedFuture(false); }); } diff --git a/native~/Editor/src/CesiumIonSessionImpl.h b/native~/Editor/src/CesiumIonSessionImpl.h index 55559e2d..a17f9515 100644 --- a/native~/Editor/src/CesiumIonSessionImpl.h +++ b/native~/Editor/src/CesiumIonSessionImpl.h @@ -84,16 +84,6 @@ class CesiumIonSessionImpl { void RefreshTokens(const DotNet::CesiumForUnity::CesiumIonSession& session); void RefreshDefaults(const DotNet::CesiumForUnity::CesiumIonSession& session); - void refreshProfile(); - void refreshAssets(); - void refreshTokens(); - void refreshDefaults(); - - bool refreshProfileIfNeeded(); - bool refreshAssetsIfNeeded(); - bool refreshTokensIfNeeded(); - bool refreshDefaultsIfNeeded(); - CesiumAsync::Future> findToken(const std::string& token) const; @@ -104,18 +94,37 @@ class CesiumIonSessionImpl { void invalidateProjectDefaultTokenDetails(); const std::optional& getConnection() const; - const CesiumIonClient::Profile& getProfile(); - const CesiumIonClient::Assets& getAssets(); - const std::vector& getTokens(); + const CesiumIonClient::Profile& + getProfile(const DotNet::CesiumForUnity::CesiumIonSession& session); + const CesiumIonClient::Assets& + getAssets(const DotNet::CesiumForUnity::CesiumIonSession& session); + const std::vector& + getTokens(const DotNet::CesiumForUnity::CesiumIonSession& session); const CesiumIonClient::ApplicationData& getAppData(); - const CesiumIonClient::Defaults& getDefaults(); + const CesiumIonClient::Defaults& + getDefaults(const DotNet::CesiumForUnity::CesiumIonSession& session); const std::shared_ptr& getAssetAccessor() const; const CesiumAsync::AsyncSystem& getAsyncSystem() const; CesiumAsync::AsyncSystem& getAsyncSystem(); private: - void startQueuedLoads(); + void refreshProfile(const DotNet::CesiumForUnity::CesiumIonSession& session); + void refreshAssets(const DotNet::CesiumForUnity::CesiumIonSession& session); + void refreshTokens(const DotNet::CesiumForUnity::CesiumIonSession& session); + void refreshDefaults(const DotNet::CesiumForUnity::CesiumIonSession& session); + + bool refreshProfileIfNeeded( + const DotNet::CesiumForUnity::CesiumIonSession& session); + bool refreshAssetsIfNeeded( + const DotNet::CesiumForUnity::CesiumIonSession& session); + bool refreshTokensIfNeeded( + const DotNet::CesiumForUnity::CesiumIonSession& session); + bool refreshDefaultsIfNeeded( + const DotNet::CesiumForUnity::CesiumIonSession& session); + + void + startQueuedLoads(const DotNet::CesiumForUnity::CesiumIonSession& session); /** * If the {@link _appData} field has no value, this method will request the diff --git a/native~/Editor/src/IonAssetsTreeViewImpl.cpp b/native~/Editor/src/IonAssetsTreeViewImpl.cpp index c282e903..2545da79 100644 --- a/native~/Editor/src/IonAssetsTreeViewImpl.cpp +++ b/native~/Editor/src/IonAssetsTreeViewImpl.cpp @@ -117,7 +117,7 @@ void IonAssetsTreeViewImpl::CellGUI( void IonAssetsTreeViewImpl::Refresh( const DotNet::CesiumForUnity::IonAssetsTreeView& treeView) { CesiumIonSessionImpl& session = getNativeSession(); - const CesiumIonClient::Assets& assets = session.getAssets(); + const CesiumIonClient::Assets& assets = session.getAssets(getSession()); this->_assets.resize(assets.items.size()); diff --git a/native~/Editor/src/SelectIonTokenWindowImpl.cpp b/native~/Editor/src/SelectIonTokenWindowImpl.cpp index 39c7404a..7099beaf 100644 --- a/native~/Editor/src/SelectIonTokenWindowImpl.cpp +++ b/native~/Editor/src/SelectIonTokenWindowImpl.cpp @@ -214,8 +214,9 @@ SelectIonTokenWindowImpl::~SelectIonTokenWindowImpl() { void SelectIonTokenWindowImpl::RefreshTokens( const DotNet::CesiumForUnity::SelectIonTokenWindow& window) { + CesiumForUnity::CesiumIonSession session = getSession(window); const std::vector& tokens = - getSession(window).NativeImplementation().getTokens(); + session.NativeImplementation().getTokens(session); this->_tokens.resize(tokens.size()); System::Collections::Generic::List1 tokenNames = diff --git a/native~/Runtime/CMakeLists.txt b/native~/Runtime/CMakeLists.txt index 02038c76..92515530 100644 --- a/native~/Runtime/CMakeLists.txt +++ b/native~/Runtime/CMakeLists.txt @@ -44,12 +44,13 @@ target_link_libraries( PRIVATE tidy-static enum-flags + swl-variant ) set_target_properties( CesiumForUnityNative-Runtime PROPERTIES - CXX_STANDARD 17 + CXX_STANDARD 20 CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO ) @@ -66,6 +67,7 @@ target_compile_definitions( CesiumForUnityNative-Runtime PUBLIC TIDY_STATIC + SWL_VARIANT_NO_CONSTEXPR_EMPLACE ) # If we're building for the Unity Editor, set a #define accordingly. diff --git a/native~/Runtime/src/CesiumFeatureImpl.h b/native~/Runtime/src/CesiumFeatureImpl.h index 7c7c3b7c..7898788e 100644 --- a/native~/Runtime/src/CesiumFeatureImpl.h +++ b/native~/Runtime/src/CesiumFeatureImpl.h @@ -4,9 +4,9 @@ #include #include +#include #include -#include namespace DotNet::CesiumForUnity { class CesiumFeature; @@ -18,7 +18,7 @@ class String; namespace CesiumForUnityNative { -using ValueType = std::variant< +using ValueType = swl::variant< int8_t, uint8_t, int16_t, diff --git a/native~/Runtime/src/CesiumFeaturesMetadataUtility.h b/native~/Runtime/src/CesiumFeaturesMetadataUtility.h index 8dd836dc..a13738cf 100644 --- a/native~/Runtime/src/CesiumFeaturesMetadataUtility.h +++ b/native~/Runtime/src/CesiumFeaturesMetadataUtility.h @@ -59,6 +59,10 @@ class CesiumFeaturesMetadataUtility { static DotNet::CesiumForUnity::CesiumPropertyArray makePropertyArray(const CesiumGltf::PropertyArrayView& arrayView); + template + static DotNet::CesiumForUnity::CesiumPropertyArray + makePropertyArray(const CesiumGltf::PropertyArrayCopy& arrayCopy); + template static DotNet::CesiumForUnity::CesiumPropertyTableProperty makePropertyTableProperty( @@ -320,6 +324,13 @@ CesiumFeaturesMetadataUtility::makePropertyArray( return array; } +template +DotNet::CesiumForUnity::CesiumPropertyArray +CesiumFeaturesMetadataUtility::makePropertyArray( + const CesiumGltf::PropertyArrayCopy& arrayCopy) { + return makePropertyArray(arrayCopy.view()); +} + template DotNet::CesiumForUnity::CesiumPropertyTableProperty CesiumFeaturesMetadataUtility::makePropertyTableProperty( diff --git a/native~/Runtime/src/CesiumGlobeAnchorImpl.cpp b/native~/Runtime/src/CesiumGlobeAnchorImpl.cpp index 016d5ade..44c18ab4 100644 --- a/native~/Runtime/src/CesiumGlobeAnchorImpl.cpp +++ b/native~/Runtime/src/CesiumGlobeAnchorImpl.cpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include using namespace CesiumGeometry; using namespace CesiumGeospatial; diff --git a/native~/Runtime/src/CesiumMetadataValueImpl.cpp b/native~/Runtime/src/CesiumMetadataValueImpl.cpp index f0ba7adc..0a6a7362 100644 --- a/native~/Runtime/src/CesiumMetadataValueImpl.cpp +++ b/native~/Runtime/src/CesiumMetadataValueImpl.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include @@ -55,21 +56,22 @@ namespace CesiumForUnityNative { namespace { -CesiumMetadataValueImpl::ValueType getNativeBooleanValue( - const DotNet::CesiumForUnity::CesiumMetadataValue& value) { +template +auto getNativeBooleanValue( + const DotNet::CesiumForUnity::CesiumMetadataValue& value, + F&& callback) { std::optional maybeBoolean = CesiumForUnity::CesiumMetadataValue::GetObjectAsBoolean( value.objectValue()); if (maybeBoolean) { - return *maybeBoolean; + return callback(*maybeBoolean); } - return std::monostate(); + return callback(swl::monostate()); } -template -CesiumMetadataValueImpl::ValueType -getNativeScalarValue(const DotNet::System::Object& object) { +template +auto getNativeScalarValue(const DotNet::System::Object& object, F&& callback) { std::optional maybeValue; if constexpr (std::is_same_v) { maybeValue = CesiumMetadataValue::GetObjectAsSByte(object); @@ -94,45 +96,66 @@ getNativeScalarValue(const DotNet::System::Object& object) { } if (maybeValue) { - return *maybeValue; + return callback(*maybeValue); } - return std::monostate(); + return callback(swl::monostate()); } -CesiumMetadataValueImpl::ValueType -getNativeScalarValue(const DotNet::CesiumForUnity::CesiumMetadataValue& value) { +template +auto getNativeScalarValue( + const DotNet::CesiumForUnity::CesiumMetadataValue& value, + F&& callback) { CesiumMetadataValueType valueType = value.valueType(); assert(valueType.type == CesiumMetadataType::Scalar); switch (valueType.componentType) { case CesiumMetadataComponentType::Int8: - return getNativeScalarValue(value.objectValue()); + return getNativeScalarValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint8: - return getNativeScalarValue(value.objectValue()); + return getNativeScalarValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Int16: - return getNativeScalarValue(value.objectValue()); + return getNativeScalarValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint16: - return getNativeScalarValue(value.objectValue()); + return getNativeScalarValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Int32: - return getNativeScalarValue(value.objectValue()); + return getNativeScalarValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint32: - return getNativeScalarValue(value.objectValue()); + return getNativeScalarValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Int64: - return getNativeScalarValue(value.objectValue()); + return getNativeScalarValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint64: - return getNativeScalarValue(value.objectValue()); + return getNativeScalarValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Float32: - return getNativeScalarValue(value.objectValue()); + return getNativeScalarValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Float64: - return getNativeScalarValue(value.objectValue()); + return getNativeScalarValue( + value.objectValue(), + std::forward(callback)); default: - return std::monostate(); + return callback(swl::monostate()); } } -template -CesiumMetadataValueImpl::ValueType -getNativeVecValue(const DotNet::System::Object& object) { +template +auto getNativeVecValue(const DotNet::System::Object& object, F&& callback) { std::optional maybeValue; if constexpr (std::is_same_v) { maybeValue = CesiumMetadataValue::GetObjectAsCesiumIntVec2(object); @@ -161,7 +184,7 @@ getNativeVecValue(const DotNet::System::Object& object) { } if (!maybeValue) { - return std::monostate(); + return callback(swl::monostate()); } TTo result = TTo(); @@ -170,102 +193,167 @@ getNativeVecValue(const DotNet::System::Object& object) { result[i] = value[i]; } - return result; + return callback(std::move(result)); } -CesiumMetadataValueImpl::ValueType -getNativeVec2Value(const DotNet::CesiumForUnity::CesiumMetadataValue& value) { +template +auto getNativeVec2Value( + const DotNet::CesiumForUnity::CesiumMetadataValue& value, + F&& callback) { CesiumMetadataValueType valueType = value.valueType(); assert(valueType.type == CesiumMetadataType::Vec2); switch (valueType.componentType) { case CesiumMetadataComponentType::Int8: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint8: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Int16: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint16: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Int32: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint32: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Int64: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint64: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Float32: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Float64: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); default: - return std::monostate(); + return callback(swl::monostate()); } } -CesiumMetadataValueImpl::ValueType -getNativeVec3Value(const DotNet::CesiumForUnity::CesiumMetadataValue& value) { +template +auto getNativeVec3Value( + const DotNet::CesiumForUnity::CesiumMetadataValue& value, + F&& callback) { CesiumMetadataValueType valueType = value.valueType(); assert(valueType.type == CesiumMetadataType::Vec3); switch (valueType.componentType) { case CesiumMetadataComponentType::Int8: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint8: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Int16: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint16: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Int32: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint32: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Int64: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint64: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Float32: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Float64: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); default: - return std::monostate(); + return callback(swl::monostate()); } } -CesiumMetadataValueImpl::ValueType -getNativeVec4Value(const DotNet::CesiumForUnity::CesiumMetadataValue& value) { +template +auto getNativeVec4Value( + const DotNet::CesiumForUnity::CesiumMetadataValue& value, + F&& callback) { CesiumMetadataValueType valueType = value.valueType(); assert(valueType.type == CesiumMetadataType::Vec4); switch (valueType.componentType) { case CesiumMetadataComponentType::Int8: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint8: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Int16: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint16: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Int32: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint32: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Int64: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint64: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Float32: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Float64: - return getNativeVecValue(value.objectValue()); + return getNativeVecValue( + value.objectValue(), + std::forward(callback)); default: - return std::monostate(); + return callback(swl::monostate()); } } -template -CesiumMetadataValueImpl::ValueType -getNativeMatValue(const DotNet::System::Object& object) { +template +auto getNativeMatValue(const DotNet::System::Object& object, F&& callback) { std::optional maybeValue; if constexpr (std::is_same_v) { maybeValue = CesiumMetadataValue::GetObjectAsCesiumIntMat2x2(object); @@ -294,7 +382,7 @@ getNativeMatValue(const DotNet::System::Object& object) { } if (!maybeValue) { - return std::monostate(); + return callback(swl::monostate()); } TTo result = TTo(); @@ -305,824 +393,771 @@ getNativeMatValue(const DotNet::System::Object& object) { } } - return result; + return callback(std::move(result)); } -CesiumMetadataValueImpl::ValueType -getNativeMat2Value(const DotNet::CesiumForUnity::CesiumMetadataValue& value) { +template +auto getNativeMat2Value( + const DotNet::CesiumForUnity::CesiumMetadataValue& value, + F&& callback) { CesiumMetadataValueType valueType = value.valueType(); assert(valueType.type == CesiumMetadataType::Mat2); switch (valueType.componentType) { case CesiumMetadataComponentType::Int8: return getNativeMatValue( - value.objectValue()); + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint8: return getNativeMatValue( - value.objectValue()); + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Int16: return getNativeMatValue( - value.objectValue()); + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint16: return getNativeMatValue( - value.objectValue()); + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Int32: return getNativeMatValue( - value.objectValue()); + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint32: return getNativeMatValue( - value.objectValue()); + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Int64: return getNativeMatValue( - value.objectValue()); + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint64: return getNativeMatValue( - value.objectValue()); + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Float32: - return getNativeMatValue(value.objectValue()); + return getNativeMatValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Float64: - return getNativeMatValue(value.objectValue()); + return getNativeMatValue( + value.objectValue(), + std::forward(callback)); default: - return std::monostate(); + return callback(swl::monostate()); } } -CesiumMetadataValueImpl::ValueType -getNativeMat3Value(const DotNet::CesiumForUnity::CesiumMetadataValue& value) { +template +auto getNativeMat3Value( + const DotNet::CesiumForUnity::CesiumMetadataValue& value, + F&& callback) { CesiumMetadataValueType valueType = value.valueType(); assert(valueType.type == CesiumMetadataType::Mat3); switch (valueType.componentType) { case CesiumMetadataComponentType::Int8: return getNativeMatValue( - value.objectValue()); + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint8: return getNativeMatValue( - value.objectValue()); + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Int16: return getNativeMatValue( - value.objectValue()); + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint16: return getNativeMatValue( - value.objectValue()); + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Int32: return getNativeMatValue( - value.objectValue()); + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint32: return getNativeMatValue( - value.objectValue()); + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Int64: return getNativeMatValue( - value.objectValue()); + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint64: return getNativeMatValue( - value.objectValue()); + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Float32: - return getNativeMatValue(value.objectValue()); + return getNativeMatValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Float64: - return getNativeMatValue(value.objectValue()); + return getNativeMatValue( + value.objectValue(), + std::forward(callback)); default: - return std::monostate(); + return callback(swl::monostate()); } } -CesiumMetadataValueImpl::ValueType -getNativeMat4Value(const DotNet::CesiumForUnity::CesiumMetadataValue& value) { +template +auto getNativeMat4Value( + const DotNet::CesiumForUnity::CesiumMetadataValue& value, + F&& callback) { CesiumMetadataValueType valueType = value.valueType(); assert(valueType.type == CesiumMetadataType::Mat4); switch (valueType.componentType) { case CesiumMetadataComponentType::Int8: return getNativeMatValue( - value.objectValue()); + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint8: return getNativeMatValue( - value.objectValue()); + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Int16: return getNativeMatValue( - value.objectValue()); + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint16: return getNativeMatValue( - value.objectValue()); + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Int32: return getNativeMatValue( - value.objectValue()); + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint32: return getNativeMatValue( - value.objectValue()); + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Int64: return getNativeMatValue( - value.objectValue()); + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Uint64: return getNativeMatValue( - value.objectValue()); + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Float32: - return getNativeMatValue(value.objectValue()); + return getNativeMatValue( + value.objectValue(), + std::forward(callback)); case CesiumMetadataComponentType::Float64: - return getNativeMatValue(value.objectValue()); + return getNativeMatValue( + value.objectValue(), + std::forward(callback)); default: - return std::monostate(); + return callback(swl::monostate()); } } -CesiumMetadataValueImpl::ValueType -getNativeStringValue(const DotNet::CesiumForUnity::CesiumMetadataValue& value) { +template +auto getNativeStringValue( + const DotNet::CesiumForUnity::CesiumMetadataValue& value, + F&& callback) { DotNet::System::String string = CesiumForUnity::CesiumMetadataValue::GetObjectAsString( value.objectValue()); if (string == nullptr) { - return std::monostate(); + return callback(swl::monostate()); } - return string.ToStlString(); + return callback(string.ToStlString()); } -} // namespace - -/*static*/ CesiumMetadataValueImpl::ValueType -CesiumMetadataValueImpl::getNativeValue( - const DotNet::CesiumForUnity::CesiumMetadataValue& value) { +template +auto getNativeValue( + const DotNet::CesiumForUnity::CesiumMetadataValue& value, + F&& callback) { CesiumForUnity::CesiumMetadataValueType valueType = value.valueType(); switch (valueType.type) { case CesiumForUnity::CesiumMetadataType::Boolean: - return getNativeBooleanValue(value); + return getNativeBooleanValue(value, std::forward(callback)); case CesiumForUnity::CesiumMetadataType::Scalar: - return getNativeScalarValue(value); + return getNativeScalarValue(value, std::forward(callback)); case CesiumForUnity::CesiumMetadataType::Vec2: - return getNativeVec2Value(value); + return getNativeVec2Value(value, std::forward(callback)); case CesiumForUnity::CesiumMetadataType::Vec3: - return getNativeVec3Value(value); + return getNativeVec3Value(value, std::forward(callback)); case CesiumForUnity::CesiumMetadataType::Vec4: - return getNativeVec4Value(value); + return getNativeVec4Value(value, std::forward(callback)); case CesiumForUnity::CesiumMetadataType::Mat2: - return getNativeMat2Value(value); + return getNativeMat2Value(value, std::forward(callback)); case CesiumForUnity::CesiumMetadataType::Mat3: - return getNativeMat3Value(value); + return getNativeMat3Value(value, std::forward(callback)); case CesiumForUnity::CesiumMetadataType::Mat4: - return getNativeMat4Value(value); + return getNativeMat4Value(value, std::forward(callback)); case CesiumForUnity::CesiumMetadataType::String: - return getNativeStringValue(value); + return getNativeStringValue(value, std::forward(callback)); default: - return std::monostate(); + return callback(swl::monostate()); } } +} // namespace + /*static*/ bool CesiumMetadataValueImpl::ConvertToBoolean( const DotNet::CesiumForUnity::CesiumMetadataValue& value, bool defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> bool { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - return MetadataConversions::convert( - trueValue) - .value_or(defaultValue); - } - }, - nativeValue); + return getNativeValue(value, [defaultValue](auto&& trueValue) { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + return MetadataConversions::convert(trueValue).value_or( + defaultValue); + } + }); } /*static*/ int8_t CesiumMetadataValueImpl::ConvertToSByte( const DotNet::CesiumForUnity::CesiumMetadataValue& value, int8_t defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> int8_t { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - return MetadataConversions::convert( - trueValue) - .value_or(defaultValue); - } - }, - nativeValue); + return getNativeValue(value, [defaultValue](auto&& trueValue) -> int8_t { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + return MetadataConversions::convert(trueValue).value_or( + defaultValue); + } + }); } /*static*/ uint8_t CesiumMetadataValueImpl::ConvertToByte( const DotNet::CesiumForUnity::CesiumMetadataValue& value, uint8_t defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> uint8_t { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - return MetadataConversions::convert( - trueValue) - .value_or(defaultValue); - } - }, - nativeValue); + return getNativeValue(value, [defaultValue](auto&& trueValue) -> uint8_t { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + return MetadataConversions::convert(trueValue).value_or( + defaultValue); + } + }); } /*static*/ int16_t CesiumMetadataValueImpl::ConvertToInt16( const DotNet::CesiumForUnity::CesiumMetadataValue& value, int16_t defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> int16_t { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - return MetadataConversions::convert( - trueValue) - .value_or(defaultValue); - } - }, - nativeValue); + return getNativeValue(value, [defaultValue](auto&& trueValue) -> int16_t { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + return MetadataConversions::convert(trueValue).value_or( + defaultValue); + } + }); } /*static*/ uint16_t CesiumMetadataValueImpl::ConvertToUInt16( const DotNet::CesiumForUnity::CesiumMetadataValue& value, uint16_t defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> uint16_t { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - return MetadataConversions::convert( - trueValue) - .value_or(defaultValue); - } - }, - nativeValue); + return getNativeValue(value, [defaultValue](auto&& trueValue) -> uint16_t { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + return MetadataConversions::convert(trueValue).value_or( + defaultValue); + } + }); } /*static*/ int32_t CesiumMetadataValueImpl::ConvertToInt32( const DotNet::CesiumForUnity::CesiumMetadataValue& value, int32_t defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> int32_t { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - return MetadataConversions::convert( - trueValue) - .value_or(defaultValue); - } - }, - nativeValue); + return getNativeValue(value, [defaultValue](auto&& trueValue) -> int32_t { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + return MetadataConversions::convert(trueValue).value_or( + defaultValue); + } + }); } /*static*/ uint32_t CesiumMetadataValueImpl::ConvertToUInt32( const DotNet::CesiumForUnity::CesiumMetadataValue& value, uint32_t defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> uint32_t { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - return MetadataConversions::convert( - trueValue) - .value_or(defaultValue); - } - }, - nativeValue); + return getNativeValue(value, [defaultValue](auto&& trueValue) -> uint32_t { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + return MetadataConversions::convert(trueValue).value_or( + defaultValue); + } + }); } /*static*/ int64_t CesiumMetadataValueImpl::ConvertToInt64( const DotNet::CesiumForUnity::CesiumMetadataValue& value, int64_t defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> int64_t { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - return MetadataConversions::convert( - trueValue) - .value_or(defaultValue); - } - }, - nativeValue); + return getNativeValue(value, [defaultValue](auto&& trueValue) -> int64_t { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + return MetadataConversions::convert(trueValue).value_or( + defaultValue); + } + }); } /*static*/ uint64_t CesiumMetadataValueImpl::ConvertToUInt64( const DotNet::CesiumForUnity::CesiumMetadataValue& value, uint64_t defaultValue) { - ValueType nativeValue = getNativeValue(value); - std::optional test; - test = std::visit( - [&defaultValue, &test](auto trueValue) -> std::optional { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - return MetadataConversions::convert( - trueValue); - } - }, - nativeValue); - return test.value_or(defaultValue); + return getNativeValue(value, [defaultValue](auto&& trueValue) -> uint64_t { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + return MetadataConversions::convert(trueValue).value_or( + defaultValue); + } + }); } /*static*/ float CesiumMetadataValueImpl::ConvertToFloat( const DotNet::CesiumForUnity::CesiumMetadataValue& value, float defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> float { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - return MetadataConversions::convert( - trueValue) - .value_or(defaultValue); - } - }, - nativeValue); + return getNativeValue(value, [defaultValue](auto&& trueValue) -> float { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + return MetadataConversions::convert(trueValue).value_or( + defaultValue); + } + }); } /*static*/ double CesiumMetadataValueImpl::ConvertToDouble( const DotNet::CesiumForUnity::CesiumMetadataValue& value, double defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> double { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - return MetadataConversions::convert( - trueValue) - .value_or(defaultValue); - } - }, - nativeValue); + return getNativeValue(value, [defaultValue](auto&& trueValue) -> double { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + return MetadataConversions::convert(trueValue).value_or( + defaultValue); + } + }); } /*static*/ int2 CesiumMetadataValueImpl::ConvertToInt2( const DotNet::CesiumForUnity::CesiumMetadataValue& value, int2 defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> int2 { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - std::optional maybeVec2 = - MetadataConversions::convert( - trueValue); - return maybeVec2 ? UnityMetadataConversions::toInt2(*maybeVec2) - : defaultValue; - } - }, - nativeValue); + return getNativeValue(value, [&defaultValue](auto&& trueValue) -> int2 { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + std::optional maybeVec2 = + MetadataConversions::convert(trueValue); + return maybeVec2 ? UnityMetadataConversions::toInt2(*maybeVec2) + : defaultValue; + } + }); } /*static*/ uint2 CesiumMetadataValueImpl::ConvertToUInt2( const DotNet::CesiumForUnity::CesiumMetadataValue& value, uint2 defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> uint2 { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - std::optional maybeVec2 = - MetadataConversions::convert( - trueValue); - return maybeVec2 ? UnityMetadataConversions::toUint2(*maybeVec2) - : defaultValue; - } - }, - nativeValue); + return getNativeValue(value, [&defaultValue](auto&& trueValue) -> uint2 { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + std::optional maybeVec2 = + MetadataConversions::convert(trueValue); + return maybeVec2 ? UnityMetadataConversions::toUint2(*maybeVec2) + : defaultValue; + } + }); } /*static*/ float2 CesiumMetadataValueImpl::ConvertToFloat2( const DotNet::CesiumForUnity::CesiumMetadataValue& value, float2 defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> float2 { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - std::optional maybeVec2 = - MetadataConversions::convert( - trueValue); - return maybeVec2 ? UnityMetadataConversions::toFloat2(*maybeVec2) - : defaultValue; - } - }, - nativeValue); + return getNativeValue(value, [&defaultValue](auto&& trueValue) -> float2 { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + std::optional maybeVec2 = + MetadataConversions::convert(trueValue); + return maybeVec2 ? UnityMetadataConversions::toFloat2(*maybeVec2) + : defaultValue; + } + }); } /*static*/ double2 CesiumMetadataValueImpl::ConvertToDouble2( const DotNet::CesiumForUnity::CesiumMetadataValue& value, double2 defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> double2 { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - std::optional maybeVec2 = - MetadataConversions::convert( - trueValue); - return maybeVec2 ? UnityMetadataConversions::toDouble2(*maybeVec2) - : defaultValue; - } - }, - nativeValue); + return getNativeValue(value, [&defaultValue](auto&& trueValue) -> double2 { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + std::optional maybeVec2 = + MetadataConversions::convert(trueValue); + return maybeVec2 ? UnityMetadataConversions::toDouble2(*maybeVec2) + : defaultValue; + } + }); } /*static*/ int3 CesiumMetadataValueImpl::ConvertToInt3( const DotNet::CesiumForUnity::CesiumMetadataValue& value, int3 defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> int3 { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - std::optional maybeVec3 = - MetadataConversions::convert( - trueValue); - return maybeVec3 ? UnityMetadataConversions::toInt3(*maybeVec3) - : defaultValue; - } - }, - nativeValue); + return getNativeValue(value, [&defaultValue](auto&& trueValue) -> int3 { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + std::optional maybeVec3 = + MetadataConversions::convert(trueValue); + return maybeVec3 ? UnityMetadataConversions::toInt3(*maybeVec3) + : defaultValue; + } + }); } /*static*/ uint3 CesiumMetadataValueImpl::ConvertToUInt3( const DotNet::CesiumForUnity::CesiumMetadataValue& value, uint3 defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> uint3 { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - std::optional maybeVec3 = - MetadataConversions::convert( - trueValue); - return maybeVec3 ? UnityMetadataConversions::toUint3(*maybeVec3) - : defaultValue; - } - }, - nativeValue); + return getNativeValue(value, [&defaultValue](auto&& trueValue) -> uint3 { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + std::optional maybeVec3 = + MetadataConversions::convert(trueValue); + return maybeVec3 ? UnityMetadataConversions::toUint3(*maybeVec3) + : defaultValue; + } + }); } /*static*/ float3 CesiumMetadataValueImpl::ConvertToFloat3( const DotNet::CesiumForUnity::CesiumMetadataValue& value, float3 defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> float3 { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - std::optional maybeVec3 = - MetadataConversions::convert( - trueValue); - return maybeVec3 ? UnityMetadataConversions::toFloat3(*maybeVec3) - : defaultValue; - } - }, - nativeValue); + return getNativeValue(value, [&defaultValue](auto&& trueValue) -> float3 { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + std::optional maybeVec3 = + MetadataConversions::convert(trueValue); + return maybeVec3 ? UnityMetadataConversions::toFloat3(*maybeVec3) + : defaultValue; + } + }); } /*static*/ double3 CesiumMetadataValueImpl::ConvertToDouble3( const DotNet::CesiumForUnity::CesiumMetadataValue& value, double3 defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> double3 { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - std::optional maybeVec3 = - MetadataConversions::convert( - trueValue); - return maybeVec3 ? UnityMetadataConversions::toDouble3(*maybeVec3) - : defaultValue; - } - }, - nativeValue); + return getNativeValue(value, [&defaultValue](auto&& trueValue) -> double3 { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + std::optional maybeVec3 = + MetadataConversions::convert(trueValue); + return maybeVec3 ? UnityMetadataConversions::toDouble3(*maybeVec3) + : defaultValue; + } + }); } /*static*/ int4 CesiumMetadataValueImpl::ConvertToInt4( const DotNet::CesiumForUnity::CesiumMetadataValue& value, int4 defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> int4 { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - std::optional maybeVec4 = - MetadataConversions::convert( - trueValue); - return maybeVec4 ? UnityMetadataConversions::toInt4(*maybeVec4) - : defaultValue; - } - }, - nativeValue); + return getNativeValue(value, [&defaultValue](auto&& trueValue) -> int4 { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + std::optional maybeVec4 = + MetadataConversions::convert(trueValue); + return maybeVec4 ? UnityMetadataConversions::toInt4(*maybeVec4) + : defaultValue; + } + }); } /*static*/ uint4 CesiumMetadataValueImpl::ConvertToUInt4( const DotNet::CesiumForUnity::CesiumMetadataValue& value, uint4 defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> uint4 { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - std::optional maybeVec4 = - MetadataConversions::convert( - trueValue); - return maybeVec4 ? UnityMetadataConversions::toUint4(*maybeVec4) - : defaultValue; - } - }, - nativeValue); + return getNativeValue(value, [&defaultValue](auto&& trueValue) -> uint4 { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + std::optional maybeVec4 = + MetadataConversions::convert(trueValue); + return maybeVec4 ? UnityMetadataConversions::toUint4(*maybeVec4) + : defaultValue; + } + }); } /*static*/ float4 CesiumMetadataValueImpl::ConvertToFloat4( const DotNet::CesiumForUnity::CesiumMetadataValue& value, float4 defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> float4 { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - std::optional maybeVec4 = - MetadataConversions::convert( - trueValue); - return maybeVec4 ? UnityMetadataConversions::toFloat4(*maybeVec4) - : defaultValue; - } - }, - nativeValue); + return getNativeValue(value, [&defaultValue](auto&& trueValue) -> float4 { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + std::optional maybeVec4 = + MetadataConversions::convert(trueValue); + return maybeVec4 ? UnityMetadataConversions::toFloat4(*maybeVec4) + : defaultValue; + } + }); } /*static*/ double4 CesiumMetadataValueImpl::ConvertToDouble4( const DotNet::CesiumForUnity::CesiumMetadataValue& value, double4 defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> double4 { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - std::optional maybeVec4 = - MetadataConversions::convert( - trueValue); - return maybeVec4 ? UnityMetadataConversions::toDouble4(*maybeVec4) - : defaultValue; - } - }, - nativeValue); + return getNativeValue(value, [&defaultValue](auto&& trueValue) -> double4 { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + std::optional maybeVec4 = + MetadataConversions::convert(trueValue); + return maybeVec4 ? UnityMetadataConversions::toDouble4(*maybeVec4) + : defaultValue; + } + }); } /*static*/ int2x2 CesiumMetadataValueImpl::ConvertToInt2x2( const DotNet::CesiumForUnity::CesiumMetadataValue& value, int2x2 defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> int2x2 { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - std::optional maybeMat2 = - MetadataConversions::convert( - trueValue); - return maybeMat2 ? UnityMetadataConversions::toInt2x2(*maybeMat2) - : defaultValue; - } - }, - nativeValue); + return getNativeValue(value, [&defaultValue](auto&& trueValue) -> int2x2 { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + std::optional maybeMat2 = + MetadataConversions::convert(trueValue); + return maybeMat2 ? UnityMetadataConversions::toInt2x2(*maybeMat2) + : defaultValue; + } + }); } /*static*/ uint2x2 CesiumMetadataValueImpl::ConvertToUInt2x2( const DotNet::CesiumForUnity::CesiumMetadataValue& value, uint2x2 defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> uint2x2 { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - std::optional maybeMat2 = - MetadataConversions::convert( - trueValue); - return maybeMat2 ? UnityMetadataConversions::toUint2x2(*maybeMat2) - : defaultValue; - } - }, - nativeValue); + return getNativeValue(value, [&defaultValue](auto&& trueValue) -> uint2x2 { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + std::optional maybeMat2 = + MetadataConversions::convert(trueValue); + return maybeMat2 ? UnityMetadataConversions::toUint2x2(*maybeMat2) + : defaultValue; + } + }); } /*static*/ float2x2 CesiumMetadataValueImpl::ConvertToFloat2x2( const DotNet::CesiumForUnity::CesiumMetadataValue& value, float2x2 defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> float2x2 { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - std::optional maybeMat2 = - MetadataConversions::convert( - trueValue); - return maybeMat2 ? UnityMetadataConversions::toFloat2x2(*maybeMat2) - : defaultValue; - } - }, - nativeValue); + return getNativeValue(value, [&defaultValue](auto&& trueValue) -> float2x2 { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + std::optional maybeMat2 = + MetadataConversions::convert(trueValue); + return maybeMat2 ? UnityMetadataConversions::toFloat2x2(*maybeMat2) + : defaultValue; + } + }); } /*static*/ double2x2 CesiumMetadataValueImpl::ConvertToDouble2x2( const DotNet::CesiumForUnity::CesiumMetadataValue& value, double2x2 defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> double2x2 { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - std::optional maybeMat2 = - MetadataConversions::convert( - trueValue); - return maybeMat2 ? UnityMetadataConversions::toDouble2x2(*maybeMat2) - : defaultValue; - } - }, - nativeValue); + return getNativeValue(value, [&defaultValue](auto&& trueValue) -> double2x2 { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + std::optional maybeMat2 = + MetadataConversions::convert(trueValue); + return maybeMat2 ? UnityMetadataConversions::toDouble2x2(*maybeMat2) + : defaultValue; + } + }); } /*static*/ int3x3 CesiumMetadataValueImpl::ConvertToInt3x3( const DotNet::CesiumForUnity::CesiumMetadataValue& value, int3x3 defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> int3x3 { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - std::optional maybeMat3 = - MetadataConversions::convert( - trueValue); - return maybeMat3 ? UnityMetadataConversions::toInt3x3(*maybeMat3) - : defaultValue; - } - }, - nativeValue); + return getNativeValue(value, [&defaultValue](auto&& trueValue) -> int3x3 { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + std::optional maybeMat3 = + MetadataConversions::convert(trueValue); + return maybeMat3 ? UnityMetadataConversions::toInt3x3(*maybeMat3) + : defaultValue; + } + }); } /*static*/ uint3x3 CesiumMetadataValueImpl::ConvertToUInt3x3( const DotNet::CesiumForUnity::CesiumMetadataValue& value, uint3x3 defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> uint3x3 { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - std::optional maybeMat3 = - MetadataConversions::convert( - trueValue); - return maybeMat3 ? UnityMetadataConversions::toUint3x3(*maybeMat3) - : defaultValue; - } - }, - nativeValue); + return getNativeValue(value, [&defaultValue](auto&& trueValue) -> uint3x3 { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + std::optional maybeMat3 = + MetadataConversions::convert(trueValue); + return maybeMat3 ? UnityMetadataConversions::toUint3x3(*maybeMat3) + : defaultValue; + } + }); } /*static*/ float3x3 CesiumMetadataValueImpl::ConvertToFloat3x3( const DotNet::CesiumForUnity::CesiumMetadataValue& value, float3x3 defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> float3x3 { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - std::optional maybeMat3 = - MetadataConversions::convert( - trueValue); - return maybeMat3 ? UnityMetadataConversions::toFloat3x3(*maybeMat3) - : defaultValue; - } - }, - nativeValue); + return getNativeValue(value, [&defaultValue](auto&& trueValue) -> float3x3 { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + std::optional maybeMat3 = + MetadataConversions::convert(trueValue); + return maybeMat3 ? UnityMetadataConversions::toFloat3x3(*maybeMat3) + : defaultValue; + } + }); } /*static*/ double3x3 CesiumMetadataValueImpl::ConvertToDouble3x3( const DotNet::CesiumForUnity::CesiumMetadataValue& value, double3x3 defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> double3x3 { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - std::optional maybeMat3 = - MetadataConversions::convert( - trueValue); - return maybeMat3 ? UnityMetadataConversions::toDouble3x3(*maybeMat3) - : defaultValue; - } - }, - nativeValue); + return getNativeValue(value, [&defaultValue](auto&& trueValue) -> double3x3 { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + std::optional maybeMat3 = + MetadataConversions::convert(trueValue); + return maybeMat3 ? UnityMetadataConversions::toDouble3x3(*maybeMat3) + : defaultValue; + } + }); } /*static*/ int4x4 CesiumMetadataValueImpl::ConvertToInt4x4( const DotNet::CesiumForUnity::CesiumMetadataValue& value, int4x4 defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> int4x4 { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - std::optional maybeMat4 = - MetadataConversions::convert( - trueValue); - return maybeMat4 ? UnityMetadataConversions::toInt4x4(*maybeMat4) - : defaultValue; - } - }, - nativeValue); + return getNativeValue(value, [&defaultValue](auto&& trueValue) -> int4x4 { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + std::optional maybeMat4 = + MetadataConversions::convert(trueValue); + return maybeMat4 ? UnityMetadataConversions::toInt4x4(*maybeMat4) + : defaultValue; + } + }); } /*static*/ uint4x4 CesiumMetadataValueImpl::ConvertToUInt4x4( const DotNet::CesiumForUnity::CesiumMetadataValue& value, uint4x4 defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> uint4x4 { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - std::optional maybeMat4 = - MetadataConversions::convert( - trueValue); - return maybeMat4 ? UnityMetadataConversions::toUint4x4(*maybeMat4) - : defaultValue; - } - }, - nativeValue); + return getNativeValue(value, [&defaultValue](auto&& trueValue) -> uint4x4 { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return defaultValue; + } else { + std::optional maybeMat4 = + MetadataConversions::convert(trueValue); + return maybeMat4 ? UnityMetadataConversions::toUint4x4(*maybeMat4) + : defaultValue; + } + }); } /*static*/ float4x4 CesiumMetadataValueImpl::ConvertToFloat4x4( const DotNet::CesiumForUnity::CesiumMetadataValue& value, float4x4 defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> float4x4 { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - std::optional maybeMat4 = - MetadataConversions::convert( - trueValue); - return maybeMat4 ? UnityMetadataConversions::toFloat4x4(*maybeMat4) - : defaultValue; - } - }, - nativeValue); + return getNativeValue(value, [&defaultValue](auto&& trueValue) -> float4x4 { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v< + std::remove_cvref_t, + swl::monostate>) { + return defaultValue; + } else { + std::optional maybeMat4 = MetadataConversions< + glm::mat4, + std::remove_cvref_t>::convert(trueValue); + return maybeMat4 ? UnityMetadataConversions::toFloat4x4(*maybeMat4) + : defaultValue; + } + }); } /*static*/ double4x4 CesiumMetadataValueImpl::ConvertToDouble4x4( const DotNet::CesiumForUnity::CesiumMetadataValue& value, double4x4 defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> double4x4 { - if constexpr (std::is_same_v) { - return defaultValue; - } else { - std::optional maybeMat4 = - MetadataConversions::convert( - trueValue); - return maybeMat4 ? UnityMetadataConversions::toDouble4x4(*maybeMat4) - : defaultValue; - } - }, - nativeValue); + return getNativeValue(value, [&defaultValue](auto&& trueValue) -> double4x4 { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v< + std::remove_cvref_t, + swl::monostate>) { + return defaultValue; + } else { + std::optional maybeMat4 = MetadataConversions< + glm::dmat4, + std::remove_cvref_t>::convert(trueValue); + return maybeMat4 ? UnityMetadataConversions::toDouble4x4(*maybeMat4) + : defaultValue; + } + }); } /*static*/ DotNet::System::String CesiumMetadataValueImpl::ConvertToString( const DotNet::CesiumForUnity::CesiumMetadataValue& value, DotNet::System::String defaultValue) { - ValueType nativeValue = getNativeValue(value); - return std::visit( - [&defaultValue](auto trueValue) -> System::String { - if constexpr (std::is_same_v) { + return getNativeValue( + value, + [&defaultValue](auto&& trueValue) -> System::String { + using TValue = std::remove_cvref_t; + if constexpr (std::is_same_v< + std::remove_cvref_t, + swl::monostate>) { return defaultValue; } else { - auto maybeString = - MetadataConversions::convert( - trueValue); + auto maybeString = MetadataConversions< + std::string, + std::remove_cvref_t>::convert(trueValue); return maybeString ? System::String(*maybeString) : defaultValue; } - }, - nativeValue); + }); } } // namespace CesiumForUnityNative diff --git a/native~/Runtime/src/CesiumMetadataValueImpl.h b/native~/Runtime/src/CesiumMetadataValueImpl.h index f134c916..08f41250 100644 --- a/native~/Runtime/src/CesiumMetadataValueImpl.h +++ b/native~/Runtime/src/CesiumMetadataValueImpl.h @@ -3,8 +3,6 @@ #include #include -#include - namespace DotNet::CesiumForUnity { class CesiumMetadataValue; } // namespace DotNet::CesiumForUnity @@ -45,85 +43,6 @@ namespace CesiumForUnityNative { class CesiumMetadataValueImpl { public: -#pragma region ValueType declaration - // This definition excludes arrays because those are handled in C#. - using ValueType = std::variant< - std::monostate, - int8_t, - uint8_t, - int16_t, - uint16_t, - int32_t, - uint32_t, - int64_t, - uint64_t, - float, - double, - bool, - std::string, - glm::vec<2, int8_t>, - glm::vec<2, uint8_t>, - glm::vec<2, int16_t>, - glm::vec<2, uint16_t>, - glm::vec<2, int32_t>, - glm::vec<2, uint32_t>, - glm::vec<2, int64_t>, - glm::vec<2, uint64_t>, - glm::vec<2, float>, - glm::vec<2, double>, - glm::vec<3, int8_t>, - glm::vec<3, uint8_t>, - glm::vec<3, int16_t>, - glm::vec<3, uint16_t>, - glm::vec<3, int32_t>, - glm::vec<3, uint32_t>, - glm::vec<3, int64_t>, - glm::vec<3, uint64_t>, - glm::vec<3, float>, - glm::vec<3, double>, - glm::vec<4, int8_t>, - glm::vec<4, uint8_t>, - glm::vec<4, int16_t>, - glm::vec<4, uint16_t>, - glm::vec<4, int32_t>, - glm::vec<4, uint32_t>, - glm::vec<4, int64_t>, - glm::vec<4, uint64_t>, - glm::vec<4, float>, - glm::vec<4, double>, - glm::mat<2, 2, int8_t>, - glm::mat<2, 2, uint8_t>, - glm::mat<2, 2, int16_t>, - glm::mat<2, 2, uint16_t>, - glm::mat<2, 2, int32_t>, - glm::mat<2, 2, uint32_t>, - glm::mat<2, 2, int64_t>, - glm::mat<2, 2, uint64_t>, - glm::mat<2, 2, float>, - glm::mat<2, 2, double>, - glm::mat<3, 3, int8_t>, - glm::mat<3, 3, uint8_t>, - glm::mat<3, 3, int16_t>, - glm::mat<3, 3, uint16_t>, - glm::mat<3, 3, int32_t>, - glm::mat<3, 3, uint32_t>, - glm::mat<3, 3, int64_t>, - glm::mat<3, 3, uint64_t>, - glm::mat<3, 3, float>, - glm::mat<3, 3, double>, - glm::mat<4, 4, int8_t>, - glm::mat<4, 4, uint8_t>, - glm::mat<4, 4, int16_t>, - glm::mat<4, 4, uint16_t>, - glm::mat<4, 4, int32_t>, - glm::mat<4, 4, uint32_t>, - glm::mat<4, 4, int64_t>, - glm::mat<4, 4, uint64_t>, - glm::mat<4, 4, float>, - glm::mat<4, 4, double>>; -#pragma endregion - -#pragma region Partial function implementations static bool ConvertToBoolean( const DotNet::CesiumForUnity::CesiumMetadataValue& value, bool defaultValue); @@ -267,15 +186,5 @@ class CesiumMetadataValueImpl { static DotNet::System::String ConvertToString( const DotNet::CesiumForUnity::CesiumMetadataValue& value, DotNet::System::String defaultValue); -#pragma endregion - -private: - /** - * Retrieves the value from the System.Object in the C# - * class implementation as a C++-compatible type. std::monostate is used - * to indicate a null value. - */ - static ValueType - getNativeValue(const DotNet::CesiumForUnity::CesiumMetadataValue& value); }; } // namespace CesiumForUnityNative diff --git a/native~/extern/android-toolchain.cmake b/native~/extern/android-toolchain.cmake index e525187c..52be2c24 100644 --- a/native~/extern/android-toolchain.cmake +++ b/native~/extern/android-toolchain.cmake @@ -7,9 +7,9 @@ SET(CMAKE_ANDROID_STL_TYPE c++_static) # search for programs in the build host directories SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) # for libraries and headers in the target directories -SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) -SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) +SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH) +SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) +SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH) SET(HTTPLIB_USE_OPENSSL_IF_AVAILABLE OFF) diff --git a/native~/extern/cesium-native b/native~/extern/cesium-native index ca641c19..3b364351 160000 --- a/native~/extern/cesium-native +++ b/native~/extern/cesium-native @@ -1 +1 @@ -Subproject commit ca641c19ffabbf7a974bb11848de388f8fba2ac5 +Subproject commit 3b364351795b4c60d58f3ddba16526c56c317c9a diff --git a/native~/extern/enum-flags b/native~/extern/enum-flags index 48d25b47..dafc0265 160000 --- a/native~/extern/enum-flags +++ b/native~/extern/enum-flags @@ -1 +1 @@ -Subproject commit 48d25b470ee6971d0db15f020937abf6017ebf51 +Subproject commit dafc026588e98534a5898ebaef93a4eda1de6359 diff --git a/native~/extern/ios-toolchain.cmake b/native~/extern/ios-toolchain.cmake index 0929898b..d9cb19b2 100644 --- a/native~/extern/ios-toolchain.cmake +++ b/native~/extern/ios-toolchain.cmake @@ -1,3 +1,9 @@ +set(GENERATOR Xcode) set(CMAKE_SYSTEM_NAME iOS) set(CMAKE_OSX_ARCHITECTURES arm64) +set(CMAKE_SYSTEM_PROCESSOR arm64) +set(CMAKE_OSX_DEPLOYMENT_TARGET 12) set(CMAKE_POSITION_INDEPENDENT_CODE ON) +SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH) +SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) +SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH) diff --git a/native~/extern/swl-variant b/native~/extern/swl-variant new file mode 160000 index 00000000..8af20f43 --- /dev/null +++ b/native~/extern/swl-variant @@ -0,0 +1 @@ +Subproject commit 8af20f43129ec66159eecd62a48eafdb7a2f74ca diff --git a/native~/vcpkg/ports/asyncplusplus/portfile.cmake b/native~/vcpkg/ports/asyncplusplus/portfile.cmake new file mode 100644 index 00000000..54b343b2 --- /dev/null +++ b/native~/vcpkg/ports/asyncplusplus/portfile.cmake @@ -0,0 +1,21 @@ +vcpkg_check_linkage(ONLY_STATIC_LIBRARY) + +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO Amanieu/asyncplusplus + REF 4159da79e20ad6d0eb1f13baa0f10e989edd9fba + SHA512 a7b099ce24184aa56e843d4858228196f8220374585a375a9c0d944832bd68c8aabd6b2efde5aacbb9c73f9dd8e942e97262be04550205b3fbea44d8b972d78e + HEAD_REF master +) + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" +) + +vcpkg_cmake_install() + +vcpkg_cmake_config_fixup(CONFIG_PATH cmake PACKAGE_NAME async++) + +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include" "${CURRENT_PACKAGES_DIR}/debug/share") + +file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright) diff --git a/native~/vcpkg/ports/asyncplusplus/vcpkg.json b/native~/vcpkg/ports/asyncplusplus/vcpkg.json new file mode 100644 index 00000000..f70a5993 --- /dev/null +++ b/native~/vcpkg/ports/asyncplusplus/vcpkg.json @@ -0,0 +1,17 @@ +{ + "name": "asyncplusplus", + "version": "1.1", + "port-version": 2, + "description": "Async++ is a lightweight concurrency framework for C++11", + "license": "MIT", + "dependencies": [ + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ] +} diff --git a/native~/vcpkg/ports/ktx/0001-Use-vcpkg-zstd.patch b/native~/vcpkg/ports/ktx/0001-Use-vcpkg-zstd.patch new file mode 100644 index 00000000..71a587bd --- /dev/null +++ b/native~/vcpkg/ports/ktx/0001-Use-vcpkg-zstd.patch @@ -0,0 +1,122 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 9a56491..d7ca937 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -345,7 +345,6 @@ set(KTX_MAIN_SRC + lib/basisu/transcoder/basisu_transcoder.cpp + lib/basisu/transcoder/basisu_transcoder.h + lib/basisu/transcoder/basisu.h +- lib/basisu/zstd/zstd.c + lib/checkheader.c + lib/dfdutils/createdfd.c + lib/dfdutils/colourspaces.c +@@ -532,7 +531,6 @@ macro(common_libktx_settings target enable_write library_type) + $ + + $ +- $ + + $ + $ +@@ -627,6 +625,11 @@ macro(common_libktx_settings target enable_write library_type) + target_compile_definitions(${target} PUBLIC KTX_FEATURE_KTX2) + endif() + ++ # Use vcpkg zstd ++ find_package(zstd CONFIG REQUIRED) ++ set(ZSTD_LIBRARIES "$,zstd::libzstd_shared,zstd::libzstd_static>") ++ target_link_libraries(${target} PRIVATE ${ZSTD_LIBRARIES}) ++ + if(WIN32) + if(MINGW) + # Check if the Threads package is provided; if using Mingw it MIGHT be +diff --git a/cmake/KtxConfig.cmake b/cmake/KtxConfig.cmake +index 6386ba2..537bf4f 100644 +--- a/cmake/KtxConfig.cmake ++++ b/cmake/KtxConfig.cmake +@@ -1,7 +1,8 @@ + # Copyright 2015-2020 The Khronos Group Inc. + # SPDX-License-Identifier: Apache-2.0 + +-# include(CMakeFindDependencyMacro) +-# find_dependency() ++include(CMakeFindDependencyMacro) ++find_dependency(Threads) ++find_dependency(zstd CONFIG) + + include("${CMAKE_CURRENT_LIST_DIR}/KtxTargets.cmake") +diff --git a/lib/basisu/CMakeLists.txt b/lib/basisu/CMakeLists.txt +index 492233a..152ceb5 100644 +--- a/lib/basisu/CMakeLists.txt ++++ b/lib/basisu/CMakeLists.txt +@@ -145,9 +145,6 @@ set(BASISU_SRC_LIST ${COMMON_SRC_LIST} + transcoder/basisu_transcoder.cpp + ) + +-if (ZSTD) +- set(BASISU_SRC_LIST ${BASISU_SRC_LIST} zstd/zstd.c) +-endif() + + if (APPLE) + set(BIN_DIRECTORY "bin_osx") +@@ -165,6 +162,10 @@ else() + target_compile_definitions(basisu PRIVATE BASISD_SUPPORT_KTX2_ZSTD=0) + endif() + ++if(ZSTD_LIBRARIES) ++ target_link_libraries(basisu ${ZSTD_LIBRARIES}) ++endif() ++ + if (NOT MSVC) + # For Non-Windows builds, let cmake try and find the system OpenCL headers/libs for us. + if (OPENCL_FOUND) +diff --git a/lib/basisu/webgl/encoder/CMakeLists.txt b/lib/basisu/webgl/encoder/CMakeLists.txt +index 588d91b..a337b13 100644 +--- a/lib/basisu/webgl/encoder/CMakeLists.txt ++++ b/lib/basisu/webgl/encoder/CMakeLists.txt +@@ -34,9 +34,6 @@ if (EMSCRIPTEN) + ) + + if (KTX2_ZSTANDARD) +- set(SRC_LIST ${SRC_LIST} +- ../../zstd/zstd.c +- ) + set(ZSTD_DEFINITION BASISD_SUPPORT_KTX2_ZSTD=1) + else() + set(ZSTD_DEFINITION BASISD_SUPPORT_KTX2_ZSTD=0) +@@ -55,6 +52,10 @@ if (EMSCRIPTEN) + target_compile_options(basis_encoder.js PRIVATE -fno-strict-aliasing -O3) + + target_include_directories(basis_encoder.js PRIVATE ../../transcoder) ++ ++ if(ZSTD_LIBRARIES) ++ target_link_libraries(basis_encoder.js ${ZSTD_LIBRARIES}) ++ endif() + + set_target_properties(basis_encoder.js PROPERTIES + OUTPUT_NAME "basis_encoder" +diff --git a/lib/basisu/webgl/transcoder/CMakeLists.txt b/lib/basisu/webgl/transcoder/CMakeLists.txt +index 372653d..5ebc3cf 100644 +--- a/lib/basisu/webgl/transcoder/CMakeLists.txt ++++ b/lib/basisu/webgl/transcoder/CMakeLists.txt +@@ -28,9 +28,6 @@ if (EMSCRIPTEN) + endif() + + if (KTX2_ZSTANDARD) +- set(SRC_LIST ${SRC_LIST} +- ../../zstd/zstddeclib.c +- ) + set(ZSTD_DEFINITION BASISD_SUPPORT_KTX2_ZSTD=1) + else() + set(ZSTD_DEFINITION BASISD_SUPPORT_KTX2_ZSTD=0) +@@ -44,6 +41,10 @@ if (EMSCRIPTEN) + target_compile_definitions(basis_transcoder.js PRIVATE NDEBUG BASISD_SUPPORT_UASTC=1 BASISD_SUPPORT_BC7=1 BASISD_SUPPORT_ATC=0 BASISD_SUPPORT_ASTC_HIGHER_OPAQUE_QUALITY=0 BASISD_SUPPORT_PVRTC2=0 BASISD_SUPPORT_FXT1=0 BASISD_SUPPORT_ETC2_EAC_RG11=0 BASISU_SUPPORT_ENCODING=0 ${KTX2_DEFINITION} ${ZSTD_DEFINITION} ) + target_compile_options(basis_transcoder.js PRIVATE -O3 -fno-strict-aliasing) + target_include_directories(basis_transcoder.js PRIVATE ../../transcoder) ++ ++ if(ZSTD_LIBRARIES) ++ target_link_libraries(basis_transcoder.js ${ZSTD_LIBRARIES}) ++ endif() + + set_target_properties(basis_transcoder.js PROPERTIES + OUTPUT_NAME "basis_transcoder" diff --git a/native~/vcpkg/ports/ktx/0002-Fix-versioning.patch b/native~/vcpkg/ports/ktx/0002-Fix-versioning.patch new file mode 100644 index 00000000..1e509880 --- /dev/null +++ b/native~/vcpkg/ports/ktx/0002-Fix-versioning.patch @@ -0,0 +1,17 @@ +diff --git a/cmake/version.cmake b/cmake/version.cmake +index 4094df1a..3b2af3bb 100644 +--- a/cmake/version.cmake ++++ b/cmake/version.cmake +@@ -108,8 +108,10 @@ function(generate_version _var ) + set(${_var} "${KTX_VERSION}" PARENT_SCOPE) + endfunction() + +-# Get latest tag +-git_describe_raw(KTX_VERSION_FULL --abbrev=0 --match v[0-9]*) ++if (!KTX_VERSION_FULL) ++ # Get latest tag ++ git_describe_raw(KTX_VERSION_FULL --abbrev=0 --match v[0-9]*) ++endif() + #message("KTX full version: ${KTX_VERSION_FULL}") + + # generate_version(TOKTX_VERSION tools/toktx) diff --git a/native~/vcpkg/ports/ktx/0003-mkversion.patch b/native~/vcpkg/ports/ktx/0003-mkversion.patch new file mode 100644 index 00000000..ee8b3c4a --- /dev/null +++ b/native~/vcpkg/ports/ktx/0003-mkversion.patch @@ -0,0 +1,13 @@ +diff --git a/cmake/version.cmake b/cmake/version.cmake +index 9a90622..0fc3521 100644 +--- a/cmake/version.cmake ++++ b/cmake/version.cmake +@@ -176,7 +176,7 @@ function( create_version_header dest_path target ) + add_custom_command( + OUTPUT ${version_h_output} + # On Windows this command has to be invoked by a shell in order to work +- COMMAND ${BASH_EXECUTABLE} -c "\"./mkversion\" \"-o\" \"version.h\" \"${dest_path}\"" ++ COMMAND "${BASH_EXECUTABLE}" -- ./mkversion -o version.h "${dest_path}" + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + COMMENT "Generate ${version_h_output}" + VERBATIM diff --git a/native~/vcpkg/ports/ktx/0004-quirks.patch b/native~/vcpkg/ports/ktx/0004-quirks.patch new file mode 100644 index 00000000..afc34236 --- /dev/null +++ b/native~/vcpkg/ports/ktx/0004-quirks.patch @@ -0,0 +1,21 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 1500844..810914e 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -263,7 +263,7 @@ if(MSVC) + # ";" argument separator is problematic. Can't use a GenEx `$:/WX> ) +- add_compile_options( $,/Gz,/O2> ) ++ add_compile_options( $,,/O2> ) + # Enable UTF-8 support + add_compile_options( $<$:/utf-8> ) + add_compile_options( $<$:/utf-8> ) +@@ -946,6 +946,7 @@ if(EMSCRIPTEN) + endif() + + add_library( objUtil STATIC ++ EXCLUDE_FROM_ALL + utils/argparser.cpp + utils/argparser.h + utils/ktxapp.h diff --git a/native~/vcpkg/ports/ktx/0005-no-vendored-libs.patch b/native~/vcpkg/ports/ktx/0005-no-vendored-libs.patch new file mode 100644 index 00000000..77cdd851 --- /dev/null +++ b/native~/vcpkg/ports/ktx/0005-no-vendored-libs.patch @@ -0,0 +1,17 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index d7ca937..ffcbe95 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -1059,10 +1059,10 @@ endif() + # except for building the ktx library. + if((KTX_FEATURE_TOOLS OR KTX_FEATURE_TESTS) AND NOT TARGET fmt::fmt) + set(FMT_SYSTEM_HEADERS ON) +- add_subdirectory(other_projects/fmt) ++ find_package(fmt CONFIG REQUIRED) + endif() + if(KTX_FEATURE_TOOLS AND NOT TARGET cxxopts::cxxopts) +- add_subdirectory(other_projects/cxxopts) ++ find_package(cxxopts CONFIG REQUIRED) + endif() + + # Tools diff --git a/native~/vcpkg/ports/ktx/CESIUM-0001-do-not-define-_DEBUG.patch b/native~/vcpkg/ports/ktx/CESIUM-0001-do-not-define-_DEBUG.patch new file mode 100644 index 00000000..d3c38256 --- /dev/null +++ b/native~/vcpkg/ports/ktx/CESIUM-0001-do-not-define-_DEBUG.patch @@ -0,0 +1,13 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index ffcbe95..7b13753 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -490,7 +490,7 @@ macro(common_libktx_settings target enable_write library_type) + target_compile_definitions( + ${target} + PUBLIC +- "$<$:_DEBUG;DEBUG>" ++ #"$<$:_DEBUG;DEBUG>" + PRIVATE + LIBKTX + ) diff --git a/native~/vcpkg/ports/ktx/CESIUM-0002-not-a-framework.patch b/native~/vcpkg/ports/ktx/CESIUM-0002-not-a-framework.patch new file mode 100644 index 00000000..4458110f --- /dev/null +++ b/native~/vcpkg/ports/ktx/CESIUM-0002-not-a-framework.patch @@ -0,0 +1,17 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 7b13753..b62b849 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -474,9 +474,9 @@ macro(common_libktx_settings target enable_write library_type) + + ) + if(IOS) +- set_target_properties(${target} PROPERTIES +- FRAMEWORK TRUE +- ) ++# set_target_properties(${target} PROPERTIES ++# FRAMEWORK TRUE ++# ) + endif() + + if( NOT ${library_type} STREQUAL STATIC ) diff --git a/native~/vcpkg/ports/ktx/CESIUM-0003-ios-normal-header-path.patch b/native~/vcpkg/ports/ktx/CESIUM-0003-ios-normal-header-path.patch new file mode 100644 index 00000000..6ad9c977 --- /dev/null +++ b/native~/vcpkg/ports/ktx/CESIUM-0003-ios-normal-header-path.patch @@ -0,0 +1,30 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index b62b849..d8c4745 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -1133,18 +1133,18 @@ endif() + # Use of this to install KHR/khr_df.h is due to CMake's failure to + # preserve the include source folder hierarchy. + # See https://gitlab.kitware.com/cmake/cmake/-/issues/16739. +-if (IOS) +- set_source_files_properties( +- include/KHR/khr_df.h +- PROPERTIES MACOSX_PACKAGE_LOCATION Headers/KHR +- ) +-else() ++# if (IOS) ++# set_source_files_properties( ++# include/KHR/khr_df.h ++# PROPERTIES MACOSX_PACKAGE_LOCATION Headers/KHR ++# ) ++# else() + include(GNUInstallDirs) + install(FILES include/KHR/khr_df.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/KHR + COMPONENT dev + ) +-endif() ++# endif() + + install(EXPORT KTXTargets + FILE KtxTargets.cmake diff --git a/native~/vcpkg/ports/ktx/portfile.cmake b/native~/vcpkg/ports/ktx/portfile.cmake new file mode 100644 index 00000000..40c64bbf --- /dev/null +++ b/native~/vcpkg/ports/ktx/portfile.cmake @@ -0,0 +1,85 @@ +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO KhronosGroup/KTX-Software + REF "v${VERSION}" + SHA512 5a89f8986464705ec36ac1becaddd0ff335e4c3c235468aaef0e963fcfeda4c0d669a086b91e61c16a3ae9e1fa5bf456dccf12cc65720e1a22e7cc0f30552541 + HEAD_REF master + PATCHES + 0001-Use-vcpkg-zstd.patch + 0002-Fix-versioning.patch + 0003-mkversion.patch + 0004-quirks.patch + 0005-no-vendored-libs.patch + CESIUM-0001-do-not-define-_DEBUG.patch + CESIUM-0002-not-a-framework.patch + CESIUM-0003-ios-normal-header-path.patch +) +file(REMOVE "${SOURCE_PATH}/other_include/zstd_errors.h") + +vcpkg_list(SET OPTIONS) +# if(VCPKG_TARGET_IS_WINDOWS) +# vcpkg_acquire_msys(MSYS_ROOT +# PACKAGES +# bash +# DIRECT_PACKAGES +# # Required for "getopt" +# "https://repo.msys2.org/msys/x86_64/util-linux-2.35.2-3-x86_64.pkg.tar.zst" +# da26540881cd5734072717133307e5d1a27a60468d3656885507833b80f24088c5382eaa0234b30bdd9e8484a6638b4514623f5327f10b19eed36f12158e8edb +# # Required for "dos2unix" +# "https://mirror.msys2.org/msys/x86_64/dos2unix-7.5.1-1-x86_64.pkg.tar.zst" +# 83d85e6ccea746ef9e8153a0d605e774dbe7efc0ee952804acfee4ffd7e3b0386a353b45ff989dd99bc3ce75968209fea3d246ad2af88bbb5c4eca12fc5a8f92 +# ) +# vcpkg_add_to_path("${MSYS_ROOT}/usr/bin") +# vcpkg_list(APPEND OPTIONS "-DBASH_EXECUTABLE=${MSYS_ROOT}/usr/bin/bash.exe") +# endif() + +string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" ENABLE_STATIC) + +vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS + FEATURES + tools KTX_FEATURE_TOOLS + vulkan KTX_FEATURE_VK_UPLOAD +) + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" + OPTIONS + -DKTX_VERSION_FULL=v${VERSION} + -DKTX_FEATURE_TESTS=OFF + -DKTX_FEATURE_LOADTEST_APPS=OFF + -DKTX_FEATURE_STATIC_LIBRARY=${ENABLE_STATIC} + ${FEATURE_OPTIONS} + ${OPTIONS} + # Do not regenerate headers (needs more dependencies) + -DCMAKE_DISABLE_FIND_PACKAGE_Vulkan=1 + DISABLE_PARALLEL_CONFIGURE +) + +vcpkg_cmake_install() + +if(tools IN_LIST FEATURES) + vcpkg_copy_tools( + TOOL_NAMES + ktx + toktx + ktxsc + ktxinfo + ktx2ktx2 + ktx2check + AUTO_CLEAN + ) +else() + vcpkg_copy_pdbs() +endif() + +vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/ktx) + +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") + +if(VCPKG_LIBRARY_LINKAGE STREQUAL "static") + file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin" "${CURRENT_PACKAGES_DIR}/debug/bin") +endif() + +file(GLOB LICENSE_FILES "${SOURCE_PATH}/LICENSES/*") +file(COPY ${LICENSE_FILES} DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}/LICENSES") +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE.md") diff --git a/native~/vcpkg/ports/ktx/vcpkg.json b/native~/vcpkg/ports/ktx/vcpkg.json new file mode 100644 index 00000000..102e2813 --- /dev/null +++ b/native~/vcpkg/ports/ktx/vcpkg.json @@ -0,0 +1,37 @@ +{ + "name": "ktx", + "version-semver": "4.3.0-beta1", + "port-version": 1, + "description": [ + "The Khronos KTX library and tools.", + "Functions for writing and reading KTX files, and instantiating OpenGL®, OpenGL ES™️ and Vulkan® textures from them." + ], + "homepage": "https://github.com/KhronosGroup/KTX-Software", + "license": null, + "supports": "arm64 | x64 | !windows", + "dependencies": [ + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + }, + "zstd" + ], + "features": { + "tools": { + "description": "Build tools", + "supports": "!android", + "dependencies": [ + "cxxopts", + "fmt" + ] + }, + "vulkan": { + "description": "Build Vulkan support", + "supports": "!emscripten" + } + } +} diff --git a/native~/vcpkg/ports/zlib-ng/portfile.cmake b/native~/vcpkg/ports/zlib-ng/portfile.cmake new file mode 100644 index 00000000..bb837527 --- /dev/null +++ b/native~/vcpkg/ports/zlib-ng/portfile.cmake @@ -0,0 +1,64 @@ +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO zlib-ng/zlib-ng + REF "${VERSION}" + SHA512 59ef586c09b9a63788475abfd6dd59ed602316b38f543f801bea802ff8bec8b55a89bee90375b8bbffa3bdebc7d92a00903f4b7c94cdc1a53a36e2e1fd71d13a + HEAD_REF develop +) + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" + OPTIONS + "-DZLIB_FULL_VERSION=${ZLIB_FULL_VERSION}" + -DZLIB_ENABLE_TESTS=OFF + -DWITH_NEW_STRATEGIES=ON + # Disable ARMv6 instructions. We don't need this because we only run on 64-bit ARM (v8), + # which has better instructions. zlib-ng has a bug that makes it try to use these v6 + # instructions even though they're not available. An attempt to fix it was made in this + # PR: https://github.com/zlib-ng/zlib-ng/pull/1617 + # But it doesn't work in our Android builds because the dependent option + # "NOT ARCH STREQUAL \"aarch64\"" that is meant to set `WITH_ARMV6` to FALSE is not + # triggered because our ARCH is `aarch64-none-linux-android21`. It's not clear if this + # is something quirky about our environment or if the fix is just not robust. + # Either way, forcing WITH_ARMV6=OFF here fixes the problem and should be reasonable + # on all platforms that Cesium for Unity supports. + -DWITH_ARMV6=OFF + OPTIONS_RELEASE + -DWITH_OPTIM=ON +) +vcpkg_cmake_install() +vcpkg_copy_pdbs() + +# Condition in `WIN32`, from https://github.com/zlib-ng/zlib-ng/blob/2.1.5/CMakeLists.txt#L1081-L1100 +# (dynamic) for `zlib` or (static `MSVC) for `zlibstatic` or default `z` +# i.e. (windows) and not (static mingw) https://learn.microsoft.com/en-us/vcpkg/maintainers/variables#vcpkg_target_is_system +if(VCPKG_TARGET_IS_WINDOWS AND (NOT (VCPKG_LIBRARY_LINKAGE STREQUAL static AND VCPKG_TARGET_IS_MINGW))) + set(_port_suffix) + if(ZLIB_COMPAT) + set(_port_suffix "") + else() + set(_port_suffix "-ng") + endif() + + set(_port_output_name) + if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic") + set(_port_output_name "zlib${_port_suffix}") + else() + set(_port_output_name "zlibstatic${_port_suffix}") + endif() + + # CMAKE_DEBUG_POSTFIX from https://github.com/zlib-ng/zlib-ng/blob/2.1.5/CMakeLists.txt#L494 + if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release") + vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/lib/pkgconfig/zlib${_port_suffix}.pc" " -lz${_port_suffix}" " -l${_port_output_name}") + endif() + if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug") + vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/zlib${_port_suffix}.pc" " -lz${_port_suffix}" " -l${_port_output_name}d") + endif() +endif() + +vcpkg_fixup_pkgconfig() + +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share" + "${CURRENT_PACKAGES_DIR}/debug/include" +) +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE.md") diff --git a/native~/vcpkg/ports/zlib-ng/vcpkg.json b/native~/vcpkg/ports/zlib-ng/vcpkg.json new file mode 100644 index 00000000..a5ed45dd --- /dev/null +++ b/native~/vcpkg/ports/zlib-ng/vcpkg.json @@ -0,0 +1,14 @@ +{ + "name": "zlib-ng", + "version": "2.1.6", + "port-version": 1, + "description": "zlib replacement with optimizations for 'next generation' systems", + "homepage": "https://github.com/zlib-ng/zlib-ng", + "license": "Zlib", + "dependencies": [ + { + "name": "vcpkg-cmake", + "host": true + } + ] +} diff --git a/native~/vcpkg/triplets/arm64-android-unity.cmake b/native~/vcpkg/triplets/arm64-android-unity.cmake new file mode 100644 index 00000000..470d060d --- /dev/null +++ b/native~/vcpkg/triplets/arm64-android-unity.cmake @@ -0,0 +1,11 @@ +include("${CMAKE_CURRENT_LIST_DIR}/shared/common.cmake") + +set(VCPKG_TARGET_ARCHITECTURE arm64) +set(VCPKG_CRT_LINKAGE static) +set(VCPKG_LIBRARY_LINKAGE static) +set(VCPKG_CMAKE_SYSTEM_NAME Android) +set(VCPKG_CMAKE_SYSTEM_VERSION 21) +set(VCPKG_MAKE_BUILD_TRIPLET "--host=aarch64-linux-android") +set(VCPKG_CMAKE_CONFIGURE_OPTIONS -DANDROID_ABI=arm64-v8a) +set(VCPKG_ENV_PASSTHROUGH "ANDROID_NDK_ROOT") +set(ENV{ANDROID_NDK_HOME} "$ENV{ANDROID_NDK_ROOT}") diff --git a/native~/vcpkg/triplets/arm64-ios-unity.cmake b/native~/vcpkg/triplets/arm64-ios-unity.cmake new file mode 100644 index 00000000..7eede653 --- /dev/null +++ b/native~/vcpkg/triplets/arm64-ios-unity.cmake @@ -0,0 +1,7 @@ +include("${CMAKE_CURRENT_LIST_DIR}/shared/common.cmake") + +set(VCPKG_TARGET_ARCHITECTURE arm64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE static) +set(VCPKG_CMAKE_SYSTEM_NAME iOS) +set(VCPKG_OSX_DEPLOYMENT_TARGET 12) diff --git a/native~/vcpkg/triplets/arm64-osx-unity.cmake b/native~/vcpkg/triplets/arm64-osx-unity.cmake new file mode 100644 index 00000000..c6110068 --- /dev/null +++ b/native~/vcpkg/triplets/arm64-osx-unity.cmake @@ -0,0 +1,9 @@ +include("${CMAKE_CURRENT_LIST_DIR}/shared/common.cmake") + +set(VCPKG_TARGET_ARCHITECTURE arm64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE static) + +set(VCPKG_CMAKE_SYSTEM_NAME Darwin) +set(VCPKG_OSX_ARCHITECTURES arm64) +set(VCPKG_OSX_DEPLOYMENT_TARGET "10.15") diff --git a/native~/vcpkg/triplets/arm64-uwp-unity.cmake b/native~/vcpkg/triplets/arm64-uwp-unity.cmake new file mode 100644 index 00000000..c44215b1 --- /dev/null +++ b/native~/vcpkg/triplets/arm64-uwp-unity.cmake @@ -0,0 +1,8 @@ +include("${CMAKE_CURRENT_LIST_DIR}/shared/common.cmake") + +set(VCPKG_TARGET_ARCHITECTURE arm64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE static) + +set(VCPKG_CMAKE_SYSTEM_NAME WindowsStore) +set(VCPKG_CMAKE_SYSTEM_VERSION 10.0) diff --git a/native~/vcpkg/triplets/shared/common.cmake b/native~/vcpkg/triplets/shared/common.cmake new file mode 100644 index 00000000..18203f5b --- /dev/null +++ b/native~/vcpkg/triplets/shared/common.cmake @@ -0,0 +1,5 @@ +list(APPEND VCPKG_ENV_PASSTHROUGH "CESIUM_VCPKG_RELEASE_ONLY") + +if(DEFINED ENV{CESIUM_VCPKG_RELEASE_ONLY} AND "$ENV{CESIUM_VCPKG_RELEASE_ONLY}") + set(VCPKG_BUILD_TYPE "release") +endif() diff --git a/native~/vcpkg/triplets/x64-android-unity.cmake b/native~/vcpkg/triplets/x64-android-unity.cmake new file mode 100644 index 00000000..bba63abd --- /dev/null +++ b/native~/vcpkg/triplets/x64-android-unity.cmake @@ -0,0 +1,11 @@ +include("${CMAKE_CURRENT_LIST_DIR}/shared/common.cmake") + +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE static) +set(VCPKG_LIBRARY_LINKAGE static) +set(VCPKG_CMAKE_SYSTEM_NAME Android) +set(VCPKG_CMAKE_SYSTEM_VERSION 21) +set(VCPKG_MAKE_BUILD_TRIPLET "--host=x86_64-linux-android") +set(VCPKG_CMAKE_CONFIGURE_OPTIONS -DANDROID_ABI=x86_64) +set(VCPKG_ENV_PASSTHROUGH "ANDROID_NDK_ROOT") +set(ENV{ANDROID_NDK_HOME} "$ENV{ANDROID_NDK_ROOT}") diff --git a/native~/vcpkg/triplets/x64-osx-unity.cmake b/native~/vcpkg/triplets/x64-osx-unity.cmake new file mode 100644 index 00000000..cc04fd28 --- /dev/null +++ b/native~/vcpkg/triplets/x64-osx-unity.cmake @@ -0,0 +1,9 @@ +include("${CMAKE_CURRENT_LIST_DIR}/shared/common.cmake") + +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE static) + +set(VCPKG_CMAKE_SYSTEM_NAME Darwin) +set(VCPKG_OSX_ARCHITECTURES x86_64) +set(VCPKG_OSX_DEPLOYMENT_TARGET "10.15") diff --git a/native~/vcpkg/triplets/x64-uwp-unity.cmake b/native~/vcpkg/triplets/x64-uwp-unity.cmake new file mode 100644 index 00000000..0d16dec8 --- /dev/null +++ b/native~/vcpkg/triplets/x64-uwp-unity.cmake @@ -0,0 +1,8 @@ +include("${CMAKE_CURRENT_LIST_DIR}/shared/common.cmake") + +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE static) + +set(VCPKG_CMAKE_SYSTEM_NAME WindowsStore) +set(VCPKG_CMAKE_SYSTEM_VERSION 10.0) diff --git a/native~/vcpkg/triplets/x64-windows-unity.cmake b/native~/vcpkg/triplets/x64-windows-unity.cmake new file mode 100644 index 00000000..b16f3e88 --- /dev/null +++ b/native~/vcpkg/triplets/x64-windows-unity.cmake @@ -0,0 +1,5 @@ +include("${CMAKE_CURRENT_LIST_DIR}/shared/common.cmake") + +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE static) +set(VCPKG_LIBRARY_LINKAGE static)