Add support for passing back value via reference to C# scripting event
This commit is contained in:
@@ -428,7 +428,7 @@ namespace FlaxEditor.Viewport
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCollectDrawCalls(RenderContext renderContext)
|
private void OnCollectDrawCalls(ref RenderContext renderContext)
|
||||||
{
|
{
|
||||||
if (_previewStaticModel)
|
if (_previewStaticModel)
|
||||||
{
|
{
|
||||||
@@ -471,7 +471,7 @@ namespace FlaxEditor.Viewport
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPostRender(GPUContext context, RenderContext renderContext)
|
private void OnPostRender(GPUContext context, ref RenderContext renderContext)
|
||||||
{
|
{
|
||||||
bool renderPostFx = true;
|
bool renderPostFx = true;
|
||||||
switch (renderContext.View.Mode)
|
switch (renderContext.View.Mode)
|
||||||
|
|||||||
@@ -258,12 +258,12 @@ namespace FlaxEditor.Viewport
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCollectDrawCalls(RenderContext renderContext)
|
private void OnCollectDrawCalls(ref RenderContext renderContext)
|
||||||
{
|
{
|
||||||
_debugDrawData.OnDraw(ref renderContext);
|
_debugDrawData.OnDraw(ref renderContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPostRender(GPUContext context, RenderContext renderContext)
|
private void OnPostRender(GPUContext context, ref RenderContext renderContext)
|
||||||
{
|
{
|
||||||
if (renderContext.View.Mode != ViewMode.Default)
|
if (renderContext.View.Mode != ViewMode.Default)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ namespace FlaxEditor.Viewport.Previews
|
|||||||
Task.AddCustomActor(PostFxVolume);
|
Task.AddCustomActor(PostFxVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPostRender(GPUContext context, RenderContext renderContext)
|
private void OnPostRender(GPUContext context, ref RenderContext renderContext)
|
||||||
{
|
{
|
||||||
if (renderContext.View.Mode != ViewMode.Default && _editorPrimitives && _editorPrimitives.CanRender)
|
if (renderContext.View.Mode != ViewMode.Default && _editorPrimitives && _editorPrimitives.CanRender)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -520,7 +520,7 @@ namespace FlaxEditor.Windows.Assets
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPostRender(GPUContext context, RenderContext renderContext)
|
private void OnPostRender(GPUContext context, ref RenderContext renderContext)
|
||||||
{
|
{
|
||||||
var task = _gameWindow.Viewport.Task;
|
var task = _gameWindow.Viewport.Task;
|
||||||
var taskFrame = task.FrameCount;
|
var taskFrame = task.FrameCount;
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ namespace FlaxEditor.Windows
|
|||||||
InputActions.Add(options => options.StepFrame, Editor.Simulation.RequestPlayOneFrame);
|
InputActions.Add(options => options.StepFrame, Editor.Simulation.RequestPlayOneFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPostRender(GPUContext context, RenderContext renderContext)
|
private void OnPostRender(GPUContext context, ref RenderContext renderContext)
|
||||||
{
|
{
|
||||||
// Debug Draw shapes
|
// Debug Draw shapes
|
||||||
if (_showDebugDraw)
|
if (_showDebugDraw)
|
||||||
|
|||||||
@@ -37,10 +37,8 @@ namespace FlaxEngine
|
|||||||
/// <param name="projection">The projection.</param>
|
/// <param name="projection">The projection.</param>
|
||||||
public void SetUp(ref Matrix view, ref Matrix projection)
|
public void SetUp(ref Matrix view, ref Matrix projection)
|
||||||
{
|
{
|
||||||
Position = view.TranslationVector;
|
|
||||||
Projection = projection;
|
Projection = projection;
|
||||||
NonJitteredProjection = projection;
|
NonJitteredProjection = projection;
|
||||||
TemporalAAJitter = Vector4.Zero;
|
|
||||||
View = view;
|
View = view;
|
||||||
|
|
||||||
UpdateCachedData();
|
UpdateCachedData();
|
||||||
|
|||||||
@@ -185,6 +185,7 @@ namespace Flax.Build.Bindings
|
|||||||
sb.Append('}');
|
sb.Append('}');
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special case for value constructors
|
// Special case for value constructors
|
||||||
if (value.Contains('(') && value.Contains(')'))
|
if (value.Contains('(') && value.Contains(')'))
|
||||||
return "new " + value;
|
return "new " + value;
|
||||||
@@ -680,7 +681,7 @@ namespace Flax.Build.Bindings
|
|||||||
{
|
{
|
||||||
var paramType = eventInfo.Type.GenericArgs[i];
|
var paramType = eventInfo.Type.GenericArgs[i];
|
||||||
var result = GenerateCSharpNativeToManaged(buildData, paramType, classInfo);
|
var result = GenerateCSharpNativeToManaged(buildData, paramType, classInfo);
|
||||||
if ((paramType.IsRef && !paramType.IsConst && paramType.IsPod(buildData, classInfo)) || result[result.Length - 1] == '*')
|
if ((paramType.IsRef && !paramType.IsConst) || result[result.Length - 1] == '*')
|
||||||
useCustomDelegateSignature = true;
|
useCustomDelegateSignature = true;
|
||||||
CppParamsWrappersCache[i] = result;
|
CppParamsWrappersCache[i] = result;
|
||||||
}
|
}
|
||||||
@@ -695,7 +696,7 @@ namespace Flax.Build.Bindings
|
|||||||
var paramType = eventInfo.Type.GenericArgs[i];
|
var paramType = eventInfo.Type.GenericArgs[i];
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
contents.Append(", ");
|
contents.Append(", ");
|
||||||
if (paramType.IsRef && !paramType.IsConst && paramType.IsPod(buildData, classInfo))
|
if (paramType.IsRef && !paramType.IsConst)
|
||||||
contents.Append("ref ");
|
contents.Append("ref ");
|
||||||
contents.Append(CppParamsWrappersCache[i]).Append(" arg").Append(i);
|
contents.Append(CppParamsWrappersCache[i]).Append(" arg").Append(i);
|
||||||
}
|
}
|
||||||
@@ -774,9 +775,9 @@ namespace Flax.Build.Bindings
|
|||||||
var paramType = eventInfo.Type.GenericArgs[i];
|
var paramType = eventInfo.Type.GenericArgs[i];
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
contents.Append(", ");
|
contents.Append(", ");
|
||||||
|
if (paramType.IsRef && !paramType.IsConst)
|
||||||
|
contents.Append("ref ");
|
||||||
contents.Append(CppParamsWrappersCache[i]);
|
contents.Append(CppParamsWrappersCache[i]);
|
||||||
if (paramType.IsRef && !paramType.IsConst && paramType.IsPod(buildData, classInfo))
|
|
||||||
contents.Append("*");
|
|
||||||
contents.Append(" arg").Append(i);
|
contents.Append(" arg").Append(i);
|
||||||
}
|
}
|
||||||
contents.Append(')').AppendLine();
|
contents.Append(')').AppendLine();
|
||||||
@@ -788,8 +789,8 @@ namespace Flax.Build.Bindings
|
|||||||
var paramType = eventInfo.Type.GenericArgs[i];
|
var paramType = eventInfo.Type.GenericArgs[i];
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
contents.Append(", ");
|
contents.Append(", ");
|
||||||
if (paramType.IsRef && !paramType.IsConst && paramType.IsPod(buildData, classInfo))
|
if (paramType.IsRef && !paramType.IsConst)
|
||||||
contents.Append("ref *");
|
contents.Append("ref ");
|
||||||
contents.Append("arg").Append(i);
|
contents.Append("arg").Append(i);
|
||||||
}
|
}
|
||||||
contents.Append(");").AppendLine();
|
contents.Append(");").AppendLine();
|
||||||
|
|||||||
@@ -695,6 +695,14 @@ namespace Flax.Build.Bindings
|
|||||||
return "MConverter<" + apiType.Name + ">::Unbox({0})";
|
return "MConverter<" + apiType.Name + ">::Unbox({0})";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Scripting Object
|
||||||
|
if (functionInfo == null && apiType.IsScriptingObject)
|
||||||
|
{
|
||||||
|
// Inside bindings function the managed runtime passes raw unamanged pointer
|
||||||
|
type = "MonoObject*";
|
||||||
|
return "(" + typeInfo.Type + "*)ScriptingObject::ToNative({0})";
|
||||||
|
}
|
||||||
|
|
||||||
// Nested type (namespace prefix is required)
|
// Nested type (namespace prefix is required)
|
||||||
if (!(apiType.Parent is FileInfo))
|
if (!(apiType.Parent is FileInfo))
|
||||||
{
|
{
|
||||||
@@ -1494,6 +1502,28 @@ namespace Flax.Build.Bindings
|
|||||||
contents.Append(" mono_runtime_invoke(mmethod->GetNative(), instance, params, &exception);").AppendLine();
|
contents.Append(" mono_runtime_invoke(mmethod->GetNative(), instance, params, &exception);").AppendLine();
|
||||||
contents.Append(" if (exception)").AppendLine();
|
contents.Append(" if (exception)").AppendLine();
|
||||||
contents.Append(" DebugLog::LogException(exception);").AppendLine();
|
contents.Append(" DebugLog::LogException(exception);").AppendLine();
|
||||||
|
for (var i = 0; i < paramsCount; i++)
|
||||||
|
{
|
||||||
|
var paramType = eventInfo.Type.GenericArgs[i];
|
||||||
|
if (paramType.IsRef && !paramType.IsConst)
|
||||||
|
{
|
||||||
|
// Convert value back from managed to native (could be modified there)
|
||||||
|
paramType.IsRef = false;
|
||||||
|
var managedToNative = GenerateCppWrapperManagedToNative(buildData, paramType, classInfo, out var managedType, null, out var _);
|
||||||
|
var passAsParamPtr = managedType.EndsWith("*");
|
||||||
|
var paramValue = $"({managedType}{(passAsParamPtr ? "" : "*")})params[{i}]";
|
||||||
|
if (!string.IsNullOrEmpty(managedToNative))
|
||||||
|
{
|
||||||
|
if (!passAsParamPtr)
|
||||||
|
paramValue = '*' + paramValue;
|
||||||
|
paramValue = string.Format(managedToNative, paramValue);
|
||||||
|
}
|
||||||
|
else if (!passAsParamPtr)
|
||||||
|
paramValue = '*' + paramValue;
|
||||||
|
contents.Append($" arg{i} = {paramValue};").AppendLine();
|
||||||
|
paramType.IsRef = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
contents.Append(" }").AppendLine().AppendLine();
|
contents.Append(" }").AppendLine().AppendLine();
|
||||||
|
|
||||||
// C# event wrapper binding method (binds/unbinds C# wrapper to C++ delegate)
|
// C# event wrapper binding method (binds/unbinds C# wrapper to C++ delegate)
|
||||||
|
|||||||
Reference in New Issue
Block a user