From a69a3812c2c3d3dcb236afa3853d014536f7ded8 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Tue, 20 Aug 2024 18:30:02 -0500 Subject: [PATCH 1/2] Add Bindings for handling MAX c++ defines and converting them to c#. --- .../Bindings/BindingsGenerator.CSharp.cs | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs index a437a4158..b0f4ab48f 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs @@ -2042,13 +2042,18 @@ namespace Flax.Build.Bindings GenerateCSharpAttributes(buildData, contents, indent, enumInfo, true); contents.Append(indent).Append(GenerateCSharpAccessLevel(enumInfo.Access)); contents.Append("enum ").Append(enumInfo.Name); + string managedType = string.Empty; if (enumInfo.UnderlyingType != null) - contents.Append(" : ").Append(GenerateCSharpNativeToManaged(buildData, enumInfo.UnderlyingType, enumInfo)); + { + managedType = GenerateCSharpNativeToManaged(buildData, enumInfo.UnderlyingType, enumInfo); + contents.Append(" : ").Append(managedType); + } contents.AppendLine(); contents.Append(indent + "{"); indent += " "; // Entries + bool usedMax = false; foreach (var entryInfo in enumInfo.Entries) { contents.AppendLine(); @@ -2056,7 +2061,25 @@ namespace Flax.Build.Bindings GenerateCSharpAttributes(buildData, contents, indent, enumInfo, entryInfo.Attributes, entryInfo.Comment, true, false); contents.Append(indent).Append(entryInfo.Name); if (!string.IsNullOrEmpty(entryInfo.Value)) - contents.Append(" = ").Append(entryInfo.Value); + { + string value; + if (enumInfo.UnderlyingType != null) + { + value = GenerateCSharpDefaultValueNativeToManaged(buildData, entryInfo.Value, enumInfo, enumInfo.UnderlyingType, false, managedType); + if (value.Contains($"{managedType}.MaxValue", StringComparison.Ordinal)) + usedMax = true; + } + else + { + value = entryInfo.Value; + } + contents.Append(" = ").Append(value); + } + else if (string.IsNullOrEmpty(entryInfo.Value) && usedMax) + { + contents.Append(" = ").Append('0'); + usedMax = false; + } contents.Append(','); contents.AppendLine(); } From b7b23dce5f65ab40d74108e8a39472f16b68dbb3 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Wed, 21 Aug 2024 08:48:35 -0500 Subject: [PATCH 2/2] Fix bug with usedMax not only setting zero after max. --- Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs index b0f4ab48f..a972f1b78 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs @@ -2062,6 +2062,9 @@ namespace Flax.Build.Bindings contents.Append(indent).Append(entryInfo.Name); if (!string.IsNullOrEmpty(entryInfo.Value)) { + if (usedMax) + usedMax = false; + string value; if (enumInfo.UnderlyingType != null) { @@ -2075,6 +2078,7 @@ namespace Flax.Build.Bindings } contents.Append(" = ").Append(value); } + // Handle case of next value after Max value being zero if a value is not defined. else if (string.IsNullOrEmpty(entryInfo.Value) && usedMax) { contents.Append(" = ").Append('0');