Return container types as return parameters
This commit is contained in:
@@ -20,7 +20,7 @@ namespace FlaxEngine
|
||||
return;
|
||||
var temp = CollectionsMarshal.AsSpan(customActors).ToArray(); // FIXME
|
||||
var tempCount = temp.Length;
|
||||
Internal_DrawSceneDepth(FlaxEngine.Object.GetUnmanagedPtr(context), FlaxEngine.Object.GetUnmanagedPtr(task), FlaxEngine.Object.GetUnmanagedPtr(output), ref temp, ref tempCount);
|
||||
Internal_DrawSceneDepth(FlaxEngine.Object.GetUnmanagedPtr(context), FlaxEngine.Object.GetUnmanagedPtr(task), FlaxEngine.Object.GetUnmanagedPtr(output), temp, ref tempCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,11 +172,7 @@ namespace Flax.Build.Bindings
|
||||
|
||||
// Skip for collections
|
||||
if ((typeInfo.Type == "Array" || typeInfo.Type == "Span" || typeInfo.Type == "DataContainer" || typeInfo.Type == "Dictionary" || typeInfo.Type == "HashSet") && typeInfo.GenericArgs != null)
|
||||
#if !USE_NETCORE
|
||||
return false;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
|
||||
// Skip for special types
|
||||
if (typeInfo.GenericArgs == null)
|
||||
|
||||
@@ -478,6 +478,7 @@ namespace Flax.Build.Bindings
|
||||
}
|
||||
|
||||
#if USE_NETCORE
|
||||
var returnNativeType = GenerateCSharpManagedToNativeType(buildData, functionInfo.ReturnType, caller);
|
||||
string returnMarshalType = "";
|
||||
if (returnValueType == "bool")
|
||||
returnMarshalType = "MarshalAs(UnmanagedType.U1)";
|
||||
@@ -492,6 +493,12 @@ namespace Flax.Build.Bindings
|
||||
// Interfaces are not supported by NativeMarshallingAttribute, marshal the parameter
|
||||
returnMarshalType = $"MarshalUsing(typeof({returnValueType}Marshaller))";
|
||||
}
|
||||
else if (functionInfo.ReturnType.Type == "MonoArray")
|
||||
returnMarshalType = "MarshalUsing(typeof(FlaxEngine.SystemArrayMarshaller))";
|
||||
else if (functionInfo.ReturnType.Type == "Array" || functionInfo.ReturnType.Type == "Span" || functionInfo.ReturnType.Type == "DataContainer" || functionInfo.ReturnType.Type == "BytesContainer" || returnNativeType == "Array")
|
||||
returnMarshalType = $"MarshalUsing(typeof(FlaxEngine.ArrayMarshaller<,>), CountElementName = nameof(__returnCount))";
|
||||
else if (functionInfo.ReturnType.Type == "Dictionary")
|
||||
returnMarshalType = $"MarshalUsing(typeof(FlaxEngine.DictionaryMarshaller<,>), ConstantElementCount = 0)";
|
||||
else if (returnValueType == "byte[]")
|
||||
returnMarshalType = $"MarshalUsing(typeof(FlaxEngine.ArrayMarshaller<,>), CountElementName = \"__returnCount\")";
|
||||
else if (returnValueType == "bool[]")
|
||||
@@ -576,7 +583,7 @@ namespace Flax.Build.Bindings
|
||||
string parameterMarshalType = "";
|
||||
if (parameterInfo.IsOut && parameterInfo.DefaultValue == "var __resultAsRef")
|
||||
{
|
||||
if (functionInfo.Glue.UseResultReferenceCount)
|
||||
if (parameterInfo.Type.Type == "Array" || parameterInfo.Type.Type == "Span" || parameterInfo.Type.Type == "DataContainer" || parameterInfo.Type.Type == "BytesContainer")
|
||||
parameterMarshalType = $"MarshalUsing(typeof(FlaxEngine.ArrayMarshaller<,>), CountElementName = \"{parameterInfo.Name}Count\")";
|
||||
else if (parameterInfo.Type.Type == "Dictionary")
|
||||
parameterMarshalType = $"MarshalUsing(typeof(FlaxEngine.DictionaryMarshaller<,>), ConstantElementCount = 0)";
|
||||
@@ -819,7 +826,6 @@ namespace Flax.Build.Bindings
|
||||
{
|
||||
marshallerName = classInfo.Name + "Marshaller";
|
||||
contents.Append(indent).AppendLine($"[NativeMarshalling(typeof({marshallerName}))]");
|
||||
//contents.Append(indent).AppendLine($"[NativeMarshalling(typeof(FlaxEngine.GCHandleMarshaller2<{classInfo.Name}>.GCHandleMarshaller3<{classInfo.Name}>))]");
|
||||
}
|
||||
#endif
|
||||
contents.Append(indent);
|
||||
|
||||
@@ -879,6 +879,7 @@ namespace Flax.Build.Bindings
|
||||
CustomParameters = new List<FunctionInfo.ParameterInfo>(),
|
||||
};
|
||||
|
||||
bool returnTypeIsContainer = false;
|
||||
var returnValueConvert = GenerateCppWrapperNativeToManaged(buildData, functionInfo.ReturnType, caller, out var returnValueType, functionInfo);
|
||||
if (functionInfo.Glue.UseReferenceForResult)
|
||||
{
|
||||
@@ -894,26 +895,11 @@ namespace Flax.Build.Bindings
|
||||
},
|
||||
IsOut = true,
|
||||
});
|
||||
#if USE_NETCORE
|
||||
if (functionInfo.ReturnType.Type == "Array" || functionInfo.ReturnType.Type == "Span" || functionInfo.ReturnType.Type == "DataContainer")
|
||||
{
|
||||
functionInfo.Glue.UseResultReferenceCount = true;
|
||||
functionInfo.Glue.CustomParameters.Add(new FunctionInfo.ParameterInfo
|
||||
{
|
||||
Name = "__resultAsRefCount",
|
||||
DefaultValue = "var __resultAsRefCount",
|
||||
Type = new TypeInfo
|
||||
{
|
||||
Type = "int"
|
||||
},
|
||||
IsOut = true,
|
||||
});
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#if USE_NETCORE
|
||||
else if (functionInfo.ReturnType.Type == "BitArray" || functionInfo.ReturnType.Type == "BytesContainer")
|
||||
else if (functionInfo.ReturnType.Type == "Array" || functionInfo.ReturnType.Type == "Span" || functionInfo.ReturnType.Type == "DataContainer" || functionInfo.ReturnType.Type == "BitArray" || functionInfo.ReturnType.Type == "BytesContainer")
|
||||
{
|
||||
returnTypeIsContainer = true;
|
||||
functionInfo.Glue.CustomParameters.Add(new FunctionInfo.ParameterInfo
|
||||
{
|
||||
Name = "__returnCount",
|
||||
@@ -1048,22 +1034,14 @@ namespace Flax.Build.Bindings
|
||||
}
|
||||
|
||||
#if USE_NETCORE
|
||||
string callBegin2 = "";
|
||||
if (functionInfo.Glue.UseResultReferenceCount)
|
||||
string callReturnCount = "";
|
||||
if (returnTypeIsContainer)
|
||||
{
|
||||
callBegin2 = " ";
|
||||
callReturnCount = " ";
|
||||
if (functionInfo.ReturnType.Type == "Span" || functionInfo.ReturnType.Type == "BytesContainer")
|
||||
callBegin2 += "*__resultAsRefCount = {0}.Length();";
|
||||
callReturnCount += "*__returnCount = {0}.Length();";
|
||||
else
|
||||
callBegin2 += "*__resultAsRefCount = {0}.Count();";
|
||||
}
|
||||
else if (functionInfo.ReturnType.Type == "BitArray" || functionInfo.ReturnType.Type == "BytesContainer")
|
||||
{
|
||||
callBegin2 = " ";
|
||||
if (functionInfo.ReturnType.Type == "Span" || functionInfo.ReturnType.Type == "BytesContainer")
|
||||
callBegin2 += "*__returnCount = {0}.Length();";
|
||||
else
|
||||
callBegin2 += "*__returnCount = {0}.Count();";
|
||||
callReturnCount += "*__returnCount = {0}.Count();";
|
||||
}
|
||||
#endif
|
||||
string call;
|
||||
@@ -1102,16 +1080,6 @@ namespace Flax.Build.Bindings
|
||||
}
|
||||
else
|
||||
{
|
||||
#if USE_NETCORE
|
||||
// FIXME
|
||||
if (parameterInfo.Type.Type == "Span" ||
|
||||
parameterInfo.Type.Type == "Array" ||
|
||||
parameterInfo.Type.Type == "DataContainer" ||
|
||||
parameterInfo.Type.Type == "Dictionary")
|
||||
{
|
||||
name = '*' + name;
|
||||
}
|
||||
#endif
|
||||
// Convert value
|
||||
param += string.Format(CppParamsWrappersCache[i], name);
|
||||
}
|
||||
@@ -1155,11 +1123,11 @@ namespace Flax.Build.Bindings
|
||||
}
|
||||
|
||||
#if USE_NETCORE
|
||||
if (!string.IsNullOrEmpty(callBegin2))
|
||||
if (!string.IsNullOrEmpty(callReturnCount))
|
||||
{
|
||||
contents.Append(" ").Append("const auto& callTemp = ").Append(string.Format(callFormat, call, callParams)).Append(";").AppendLine();
|
||||
call = "callTemp";
|
||||
contents.Append(string.Format(callBegin2, call));
|
||||
contents.Append(string.Format(callReturnCount, call));
|
||||
contents.AppendLine();
|
||||
contents.Append(callBegin);
|
||||
}
|
||||
|
||||
@@ -60,7 +60,6 @@ namespace Flax.Build.Bindings
|
||||
public struct GlueInfo
|
||||
{
|
||||
public bool UseReferenceForResult;
|
||||
public bool UseResultReferenceCount;
|
||||
public List<ParameterInfo> CustomParameters;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user