Merge branch 'FlaxEngine:master' into flax-msdf-font

This commit is contained in:
fibref
2026-02-16 22:48:19 +08:00
committed by GitHub
185 changed files with 3363 additions and 1242 deletions

View File

@@ -1892,13 +1892,13 @@ namespace Flax.Build.Bindings
CppAutoSerializeProperties.Clear();
CppIncludeFiles.Add("Engine/Serialization/Serialization.h");
// Serialize
contents.AppendLine();
contents.Append($"void {typeNameNative}::Serialize(SerializeStream& stream, const void* otherObj)").AppendLine();
contents.Append('{').AppendLine();
if (baseType != null)
contents.Append($" {baseType.FullNameNative}::Serialize(stream, otherObj);").AppendLine();
contents.Append($" SERIALIZE_GET_OTHER_OBJ({typeNameNative});").AppendLine();
if (classInfo != null)
{
foreach (var fieldInfo in classInfo.Fields)
@@ -1910,7 +1910,6 @@ namespace Flax.Build.Bindings
contents.Append($" SERIALIZE{typeHint}({fieldInfo.Name});").AppendLine();
CppAutoSerializeFields.Add(fieldInfo);
}
foreach (var propertyInfo in classInfo.Properties)
{
if (propertyInfo.Getter == null || propertyInfo.Setter == null)
@@ -1952,21 +1951,19 @@ namespace Flax.Build.Bindings
CppAutoSerializeFields.Add(fieldInfo);
}
}
contents.Append('}').AppendLine();
// Deserialize
contents.AppendLine();
contents.Append($"void {typeNameNative}::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)").AppendLine();
contents.Append('{').AppendLine();
if (baseType != null)
contents.Append($" {baseType.FullNameNative}::Deserialize(stream, modifier);").AppendLine();
foreach (var fieldInfo in CppAutoSerializeFields)
{
var typeHint = GenerateCppAutoSerializationDefineType(buildData, contents, moduleInfo, typeInfo, fieldInfo.Type, fieldInfo);
contents.Append($" DESERIALIZE{typeHint}({fieldInfo.Name});").AppendLine();
}
foreach (var propertyInfo in CppAutoSerializeProperties)
{
contents.AppendLine(" {");
@@ -1978,7 +1975,43 @@ namespace Flax.Build.Bindings
contents.AppendLine(" }");
contents.AppendLine(" }");
}
contents.Append('}').AppendLine();
// ShouldSerialize
contents.AppendLine();
contents.Append($"bool {typeNameNative}::ShouldSerialize(const void* otherObj) const").AppendLine();
contents.Append('{').AppendLine();
if (!typeInfo.IsScriptingObject)
{
contents.Append($" SERIALIZE_GET_OTHER_OBJ({typeNameNative});").AppendLine();
contents.AppendLine(" bool result = false;");
if (baseType != null)
contents.Append($" result |= {baseType.FullNameNative}::ShouldSerialize(otherObj);").AppendLine();
foreach (var fieldInfo in CppAutoSerializeFields)
{
contents.Append($" result |= Serialization::ShouldSerialize({fieldInfo.Name}, &other->{fieldInfo.Name});").AppendLine();
}
foreach (var propertyInfo in CppAutoSerializeProperties)
{
contents.Append(" {");
contents.Append(" const auto");
if (propertyInfo.Getter.ReturnType.IsConstRef)
contents.Append('&');
contents.Append($" value = {propertyInfo.Getter.Name}();");
contents.Append(" const auto");
if (propertyInfo.Getter.ReturnType.IsConstRef)
contents.Append('&');
contents.Append($" otherValue = other->{propertyInfo.Getter.Name}();");
contents.Append(" result |= Serialization::ShouldSerialize(value, &otherValue);").AppendLine();
contents.Append('}').AppendLine();
}
contents.AppendLine(" return result;");
}
else
{
// Not needed to generate
contents.AppendLine(" return true;");
}
contents.Append('}').AppendLine();
}

View File

@@ -4,6 +4,7 @@ using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace Flax.Build
@@ -166,6 +167,7 @@ namespace Flax.Build
/// </summary>
public string CSharpLanguageVersion => Version.Major switch
{
_ when Version.Major >= 10 => "14.0",
_ when Version.Major >= 9 => "13.0",
_ when Version.Major >= 8 => "12.0",
_ when Version.Major >= 7 => "11.0",
@@ -186,7 +188,7 @@ namespace Flax.Build
// Find system-installed SDK
string dotnetPath = Environment.GetEnvironmentVariable("DOTNET_ROOT");
string rid, ridFallback, arch;
string arch;
IEnumerable<string> dotnetSdkVersions = null, dotnetRuntimeVersions = null;
switch (architecture)
{
@@ -208,8 +210,6 @@ namespace Flax.Build
{
case TargetPlatform.Windows:
{
rid = $"win-{arch}";
ridFallback = "";
#pragma warning disable CA1416
if (string.IsNullOrEmpty(dotnetPath))
{
@@ -234,16 +234,12 @@ namespace Flax.Build
}
case TargetPlatform.Linux:
{
rid = $"linux-{arch}";
ridFallback = Utilities.ReadProcessOutput("dotnet", "--info").Split('\n').FirstOrDefault(x => x.StartsWith(" RID:"), "").Replace("RID:", "").Trim();
if (string.IsNullOrEmpty(dotnetPath))
dotnetPath ??= SearchForDotnetLocationLinux();
break;
}
case TargetPlatform.Mac:
{
rid = $"osx-{arch}";
ridFallback = "";
if (string.IsNullOrEmpty(dotnetPath))
{
dotnetPath = "/usr/local/share/dotnet/"; // Officially recommended dotnet location
@@ -257,7 +253,6 @@ namespace Flax.Build
}
if (Flax.Build.Platforms.MacPlatform.BuildingForx64)
{
rid = "osx-x64";
dotnetPath = Path.Combine(dotnetPath, "x64");
architecture = TargetArchitecture.x64;
}
@@ -282,7 +277,7 @@ namespace Flax.Build
dotnetRuntimeVersions = MergeVersions(dotnetRuntimeVersions, GetVersions(Path.Combine(dotnetPath, "shared", "Microsoft.NETCore.App")));
dotnetSdkVersions = dotnetSdkVersions.Where(x => File.Exists(Path.Combine(dotnetPath, "sdk", x, ".version")));
dotnetRuntimeVersions = dotnetRuntimeVersions.Where(x => File.Exists(Path.Combine(dotnetPath, "shared", "Microsoft.NETCore.App", x, ".version")));
dotnetRuntimeVersions = dotnetRuntimeVersions.Where(x => File.Exists(Path.Combine(dotnetPath, "shared", "Microsoft.NETCore.App", x, "System.dll")));
dotnetRuntimeVersions = dotnetRuntimeVersions.Where(x => Directory.Exists(Path.Combine(dotnetPath, "packs", "Microsoft.NETCore.App.Ref", x)));
dotnetSdkVersions = dotnetSdkVersions.OrderByDescending(ParseVersion);
@@ -331,6 +326,20 @@ namespace Flax.Build
VersionName = dotnetSdkVersion;
RuntimeVersionName = dotnetRuntimeVersion;
string rid, ridFallback = "";
switch (platform)
{
case TargetPlatform.Windows: rid = $"win-{arch}"; break;
case TargetPlatform.Linux:
{
rid = RuntimeInformation.RuntimeIdentifier;
ridFallback = $"linux-{arch}";
break;
}
case TargetPlatform.Mac: rid = Flax.Build.Platforms.MacPlatform.BuildingForx64 ? "osx-x64" : $"osx-{arch}"; break;
default: throw new InvalidPlatformException(platform);
}
// Pick SDK runtime
if (!TryAddHostRuntime(platform, architecture, rid) && !TryAddHostRuntime(platform, architecture, ridFallback))
{