From 7dfc37f65276eae7f9889c454055b59db3b8cd79 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sun, 12 Oct 2025 23:24:34 +0200 Subject: [PATCH] Adjustments for #3338 --- Source/Engine/Audio/AudioBackend.h | 5 +-- Source/Engine/Audio/AudioListener.cpp | 4 +-- .../Flax.Build/Deps/Dependencies/NvCloth.cs | 2 +- .../Flax.Build/Deps/Dependencies/OpenAL.cs | 35 ++++++++++++------- Source/Tools/Flax.Build/Deps/Dependency.cs | 15 ++++++++ Source/Tools/Flax.Build/Deps/Downloader.cs | 18 ++++++++-- 6 files changed, 58 insertions(+), 21 deletions(-) diff --git a/Source/Engine/Audio/AudioBackend.h b/Source/Engine/Audio/AudioBackend.h index d0cf42fb1..7d3d087a7 100644 --- a/Source/Engine/Audio/AudioBackend.h +++ b/Source/Engine/Audio/AudioBackend.h @@ -4,8 +4,6 @@ #include "Config.h" #include "Types.h" - -#include "Engine/Core/Math/Vector3.h" #include "Engine/Core/Types/BaseTypes.h" /// @@ -85,8 +83,7 @@ public: FORCE_INLINE static void VelocityChanged(const Vector3& velocity) { - if (!velocity.IsNanOrInfinity()) - Instance->Listener_VelocityChanged(velocity); + Instance->Listener_VelocityChanged(velocity); } FORCE_INLINE static void TransformChanged(const Vector3& position, const Quaternion& orientation) diff --git a/Source/Engine/Audio/AudioListener.cpp b/Source/Engine/Audio/AudioListener.cpp index 1921bd373..9c5898b4a 100644 --- a/Source/Engine/Audio/AudioListener.cpp +++ b/Source/Engine/Audio/AudioListener.cpp @@ -23,11 +23,11 @@ void AudioListener::Update() { // Update the velocity const Vector3 pos = GetPosition(); - const float dt = Time::Update.UnscaledDeltaTime.GetTotalSeconds(); + const float dt = Math::Max(Time::Update.UnscaledDeltaTime.GetTotalSeconds(), 0.00001f); const auto prevVelocity = _velocity; _velocity = (pos - _prevPos) / dt; _prevPos = pos; - if (_velocity != prevVelocity) + if (_velocity != prevVelocity && !_velocity.IsNanOrInfinity()) { AudioBackend::Listener::VelocityChanged(_velocity); } diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/NvCloth.cs b/Source/Tools/Flax.Build/Deps/Dependencies/NvCloth.cs index 545ef7169..699e40f72 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/NvCloth.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/NvCloth.cs @@ -195,7 +195,7 @@ namespace Flax.Deps.Dependencies RunCmake(cmakeFolder, platform, architecture, " -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF " + cmakeArgs, envVars); // Run build - BuildCmake(cmakeFolder, envVars: envVars); + BuildCmake(cmakeFolder, envVars); // Deploy binaries var libs = new[] diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs b/Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs index 0f1140583..447b91498 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs @@ -50,8 +50,7 @@ namespace Flax.Deps.Dependencies { var root = options.IntermediateFolder; var version = "1.24.3"; - string configuration = "Release"; - int concurrency = Math.Min(Math.Max(1, (int)(Environment.ProcessorCount * Configuration.ConcurrencyProcessorScale)), Configuration.MaxConcurrency); + var configuration = "Release"; var dstIncludePath = Path.Combine(options.ThirdPartyFolder, "OpenAL"); foreach (var platform in options.Platforms) @@ -123,7 +122,7 @@ namespace Flax.Deps.Dependencies { { "CC", "clang-" + Configuration.LinuxClangMinVer }, { "CC_FOR_BUILD", "clang-" + Configuration.LinuxClangMinVer }, - { "CMAKE_BUILD_PARALLEL_LEVEL", concurrency.ToString() }, + { "CMAKE_BUILD_PARALLEL_LEVEL", CmakeBuildParallel }, }; var config = $"-DALSOFT_REQUIRE_ALSA=ON " + $"-DALSOFT_REQUIRE_OSS=ON " + @@ -158,7 +157,11 @@ namespace Flax.Deps.Dependencies { "libopenal.a", }; - var config = "-DALSOFT_REQUIRE_OBOE=OFF -DALSOFT_REQUIRE_OPENSL=ON -DALSOFT_EMBED_HRTF_DATA=YES"; + var envVars = new Dictionary + { + { "CMAKE_BUILD_PARALLEL_LEVEL", CmakeBuildParallel }, + }; + var config = " -DALSOFT_REQUIRE_OBOE=OFF -DALSOFT_REQUIRE_OPENSL=ON -DALSOFT_EMBED_HRTF_DATA=YES"; // Get the source var packagePath = Path.Combine(root, "package.zip"); @@ -181,8 +184,8 @@ namespace Flax.Deps.Dependencies SetupDirectory(buildDir, true); // Build - RunCmake(buildDir, platform, TargetArchitecture.ARM64, ".. -DLIBTYPE=STATIC -DCMAKE_BUILD_TYPE=Release " + config); - BuildCmake(buildDir); + RunCmake(buildDir, platform, TargetArchitecture.ARM64, ".. -DLIBTYPE=STATIC -DCMAKE_BUILD_TYPE=" + configuration + config, envVars); + BuildCmake(buildDir, envVars); var depsFolder = GetThirdPartyFolder(options, platform, TargetArchitecture.ARM64); foreach (var file in binariesToCopy) Utilities.FileCopy(Path.Combine(buildDir, file), Path.Combine(depsFolder, file)); @@ -194,7 +197,11 @@ namespace Flax.Deps.Dependencies { "libopenal.a", }; - var config = "-DALSOFT_REQUIRE_COREAUDIO=ON -DALSOFT_EMBED_HRTF_DATA=YES"; + var envVars = new Dictionary + { + { "CMAKE_BUILD_PARALLEL_LEVEL", CmakeBuildParallel }, + }; + var config = " -DALSOFT_REQUIRE_COREAUDIO=ON -DALSOFT_EMBED_HRTF_DATA=YES"; // Get the source var packagePath = Path.Combine(root, "package.zip"); @@ -210,8 +217,8 @@ namespace Flax.Deps.Dependencies foreach (var architecture in new[] { TargetArchitecture.x64, TargetArchitecture.ARM64 }) { SetupDirectory(buildDir, true); - RunCmake(buildDir, platform, architecture, ".. -DLIBTYPE=STATIC -DCMAKE_BUILD_TYPE=Release " + config); - BuildCmake(buildDir); + RunCmake(buildDir, platform, architecture, ".. -DLIBTYPE=STATIC -DCMAKE_BUILD_TYPE=" + configuration + config, envVars); + BuildCmake(buildDir, envVars); var depsFolder = GetThirdPartyFolder(options, platform, architecture); foreach (var file in binariesToCopy) Utilities.FileCopy(Path.Combine(buildDir, file), Path.Combine(depsFolder, file)); @@ -224,7 +231,11 @@ namespace Flax.Deps.Dependencies { "libopenal.a", }; - var config = "-DALSOFT_REQUIRE_COREAUDIO=ON -DALSOFT_EMBED_HRTF_DATA=YES"; + var envVars = new Dictionary + { + { "CMAKE_BUILD_PARALLEL_LEVEL", CmakeBuildParallel }, + }; + var config = " -DALSOFT_REQUIRE_COREAUDIO=ON -DALSOFT_EMBED_HRTF_DATA=YES"; // Get the source var packagePath = Path.Combine(root, "package.zip"); @@ -240,8 +251,8 @@ namespace Flax.Deps.Dependencies // Build for iOS SetupDirectory(buildDir, true); - RunCmake(buildDir, platform, TargetArchitecture.ARM64, ".. -DCMAKE_SYSTEM_NAME=iOS -DALSOFT_OSX_FRAMEWORK=ON -DLIBTYPE=STATIC -DCMAKE_BUILD_TYPE=Release " + config); - BuildCmake(buildDir); + RunCmake(buildDir, platform, TargetArchitecture.ARM64, ".. -DCMAKE_SYSTEM_NAME=iOS -DALSOFT_OSX_FRAMEWORK=ON -DLIBTYPE=STATIC -DCMAKE_BUILD_TYPE=" + configuration + config, envVars); + BuildCmake(buildDir, envVars); var depsFolder = GetThirdPartyFolder(options, platform, TargetArchitecture.ARM64); foreach (var file in binariesToCopy) Utilities.FileCopy(Path.Combine(buildDir, file), Path.Combine(depsFolder, file)); diff --git a/Source/Tools/Flax.Build/Deps/Dependency.cs b/Source/Tools/Flax.Build/Deps/Dependency.cs index 79d39f2a6..a79a968a3 100644 --- a/Source/Tools/Flax.Build/Deps/Dependency.cs +++ b/Source/Tools/Flax.Build/Deps/Dependency.cs @@ -248,6 +248,21 @@ namespace Flax.Deps Utilities.Run("git", "reset --hard", null, path, Utilities.RunOptions.DefaultTool); } + /// + /// Gets the maximum concurrency level for a cmake command. See CMAKE_BUILD_PARALLEL_LEVEL or -j docs. + /// + public static string CmakeBuildParallel => Math.Min(Math.Max(1, (int)(Environment.ProcessorCount * Configuration.ConcurrencyProcessorScale)), Configuration.MaxConcurrency).ToString(); + + /// + /// Builds the cmake project. + /// + /// The path. + /// Custom environment variables to pass to the child process. + public static void BuildCmake(string path, Dictionary envVars) + { + BuildCmake(path, "Release", envVars); + } + /// /// Builds the cmake project. /// diff --git a/Source/Tools/Flax.Build/Deps/Downloader.cs b/Source/Tools/Flax.Build/Deps/Downloader.cs index 4b8c77da0..57da4a2ee 100644 --- a/Source/Tools/Flax.Build/Deps/Downloader.cs +++ b/Source/Tools/Flax.Build/Deps/Downloader.cs @@ -14,6 +14,7 @@ namespace Flax.Deps /// static class Downloader { + private static bool IgnoreSSL = false; private const string GoogleDriveDomain = "drive.google.com"; private const string GoogleDriveDomain2 = "https://drive.google.com"; @@ -54,7 +55,7 @@ namespace Flax.Deps { if (httpClient == null) { - using (httpClient = new HttpClient()) + using (httpClient = GetHttpClient()) { return DownloadFileFromUrlToPathRaw(url, path, httpClient); } @@ -130,7 +131,7 @@ namespace Flax.Deps // You can comment the statement below if the provided url is guaranteed to be in the following format: // https://drive.google.com/uc?id=FILEID&export=download url = GetGoogleDriveDownloadLinkFromUrl(url); - using (var httpClient = new HttpClient()) + using (var httpClient = GetHttpClient()) { FileInfo downloadedFile; @@ -209,5 +210,18 @@ namespace Flax.Deps return string.Format("https://drive.google.com/uc?id={0}&export=download", url.Substring(index, closingIndex - index)); } + + private static HttpClient GetHttpClient() + { + if (IgnoreSSL) + { + Log.Warning("Accessing HTTP with SSL certificate validation disabled!"); + var handler = new HttpClientHandler(); + handler.ClientCertificateOptions = ClientCertificateOption.Manual; + handler.ServerCertificateCustomValidationCallback = (httpRequestMessage, cert, cetChain, policyErrors) => true; + return new HttpClient(handler); + } + return new HttpClient(); + } } }