diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index da056c33..d16f6ae0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -63,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 }} @@ -103,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 @@ -121,7 +125,12 @@ jobs: $ENV:EZVCPKG_BASEDIR="D:/.ezvcpkg" # Run the build dotnet run --project Build~ - cat D:\cesium\CesiumForUnityBuildProject\Packages\com.cesium.unity\native~\build-Android-arm64\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 - Windows + path: d:/cesium/CesiumForUnityBuildProject/Packages/com.cesium.unity/native~/build-*/build.log - name: Publish package artifact if: ${{ success() }} uses: actions/upload-artifact@v4 @@ -130,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 @@ -166,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" @@ -213,6 +222,9 @@ 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 @@ -224,12 +236,12 @@ jobs: 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-Standalone-x86_64/build.log - cat /Users/runner/cesium/CesiumForUnityBuildProject/Packages/com.cesium.unity/native~/build-Standalone-arm64/build.log - 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 @@ -238,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 12fc7218..baf37af8 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[] { diff --git a/Editor/CompileCesiumForUnityNative.cs b/Editor/CompileCesiumForUnityNative.cs index f0189fc5..1aa3ff30 100644 --- a/Editor/CompileCesiumForUnityNative.cs +++ b/Editor/CompileCesiumForUnityNative.cs @@ -418,6 +418,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(); } @@ -440,7 +443,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)) { 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 e1425e07..77599343 100644 --- a/native~/CMakeLists.txt +++ b/native~/CMakeLists.txt @@ -87,6 +87,7 @@ 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. @@ -106,69 +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(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..0c92a2db 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/CesiumMetadataValueImpl.cpp b/native~/Runtime/src/CesiumMetadataValueImpl.cpp index f0ba7adc..48571d94 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(std::move(*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/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/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