Merge remote-tracking branch 'origin/master' into 1.7

This commit is contained in:
Wojtek Figat
2023-09-27 17:32:47 +02:00
40 changed files with 710 additions and 164 deletions

View File

@@ -968,7 +968,7 @@ namespace Flax.Build.Bindings
CppParamsWrappersCache[i] = result;
}
string eventSignature;
string eventType;
if (useCustomDelegateSignature)
{
contents.Append(indent).Append($"/// <summary>The delegate for event {eventInfo.Name}.</summary>").AppendLine();
@@ -983,24 +983,25 @@ namespace Flax.Build.Bindings
contents.Append(CppParamsWrappersCache[i]).Append(" arg").Append(i);
}
contents.Append(");").AppendLine().AppendLine();
eventSignature = "event " + eventInfo.Name + "Delegate";
eventType = eventInfo.Name + "Delegate";
}
else
{
eventSignature = "event Action";
eventType = "Action";
if (paramsCount != 0)
{
eventSignature += '<';
eventType += '<';
for (var i = 0; i < paramsCount; i++)
{
if (i != 0)
eventSignature += ", ";
eventType += ", ";
CppParamsWrappersCache[i] = GenerateCSharpNativeToManaged(buildData, eventInfo.Type.GenericArgs[i], classInfo);
eventSignature += CppParamsWrappersCache[i];
eventType += CppParamsWrappersCache[i];
}
eventSignature += '>';
eventType += '>';
}
}
string eventSignature = "event " + eventType;
GenerateCSharpComment(contents, indent, eventInfo.Comment, true);
GenerateCSharpAttributes(buildData, contents, indent, classInfo, eventInfo, useUnmanaged);
@@ -1013,11 +1014,7 @@ namespace Flax.Build.Bindings
indent += " ";
var eventInstance = eventInfo.IsStatic ? string.Empty : "__unmanagedPtr, ";
contents.Append(indent).Append($"add {{ Internal_{eventInfo.Name} += value; if (Internal_{eventInfo.Name}_Count++ == 0) Internal_{eventInfo.Name}_Bind({eventInstance}true); }}").AppendLine();
contents.Append(indent).Append("remove { ").AppendLine();
contents.Append("#if FLAX_EDITOR || BUILD_DEBUG").AppendLine();
contents.Append(indent).Append($"if (Internal_{eventInfo.Name} != null) {{ bool invalid = true; foreach (Delegate e in Internal_{eventInfo.Name}.GetInvocationList()) {{ if (e == (Delegate)value) {{ invalid = false; break; }} }} if (invalid) throw new Exception(\"Cannot unregister from event if not registered before.\"); }}").AppendLine();
contents.Append("#endif").AppendLine();
contents.Append(indent).Append($"Internal_{eventInfo.Name} -= value; if (--Internal_{eventInfo.Name}_Count == 0) Internal_{eventInfo.Name}_Bind({eventInstance}false); }}").AppendLine();
contents.Append(indent).Append($"remove {{ var __delegate = ({eventType})Delegate.Remove(Internal_{eventInfo.Name}, value); if (__delegate != Internal_{eventInfo.Name}) {{ Internal_{eventInfo.Name} = __delegate; if (--Internal_{eventInfo.Name}_Count == 0) Internal_{eventInfo.Name}_Bind({eventInstance}false); }} }}").AppendLine();
indent = indent.Substring(0, indent.Length - 4);
contents.Append(indent).Append('}').AppendLine();
@@ -1034,6 +1031,7 @@ namespace Flax.Build.Bindings
contents.Append("static ");
contents.Append($"{eventSignature} Internal_{eventInfo.Name};");
contents.AppendLine();
contents.Append("#pragma warning restore 67").AppendLine();
contents.AppendLine();
contents.Append(indent).Append("internal ");
@@ -1515,8 +1513,8 @@ namespace Flax.Build.Bindings
type = "IntPtr";
else if (type == "bool")
type = "byte";
else if (type == "object")
type = "NativeVariant";
else if (fieldInfo.Type.Type == "Variant")
type = "IntPtr";
else if (internalType)
{
internalTypeMarshaller = type + "Marshaller";
@@ -1533,9 +1531,6 @@ namespace Flax.Build.Bindings
if (fieldInfo.NoArray && fieldInfo.Type.IsArray)
continue;
if (type == "NativeVariant")
continue; // TODO: FIXME
if (useSeparator)
{
toManagedContent.Append(", ");
@@ -1637,6 +1632,12 @@ namespace Flax.Build.Bindings
toManagedContent.Append($"managed.{fieldInfo.Name} != 0");
toNativeContent.Append($"managed.{fieldInfo.Name} ? (byte)1 : (byte)0");
}
else if (fieldInfo.Type.Type == "Variant")
{
// Variant passed as boxed object handle
toManagedContent.Append($"ManagedHandleMarshaller.NativeToManaged.ConvertToManaged(managed.{fieldInfo.Name})");
toNativeContent.Append($"ManagedHandleMarshaller.NativeToManaged.ConvertToUnmanaged(managed.{fieldInfo.Name})");
}
else if (internalType)
{
toManagedContent.Append($"{internalTypeMarshaller}.ToManaged(managed.{fieldInfo.Name})");
@@ -1770,6 +1771,10 @@ namespace Flax.Build.Bindings
// char's are not blittable, store as short instead
contents.Append($"fixed short {fieldInfo.Name}0[{fieldInfo.Type.ArraySize}]; // {managedType}*").AppendLine();
}
else if (managedType == "byte")
{
contents.Append($"fixed byte {fieldInfo.Name}0[{fieldInfo.Type.ArraySize}]; // {managedType}*").AppendLine();
}
else
#endif
{