Pass const ref parameters as in parameters in C# bindings

_amend in parameters
This commit is contained in:
2025-12-06 00:01:28 +02:00
parent dde07bac8d
commit d7eebb699c
14 changed files with 29 additions and 19 deletions

View File

@@ -525,7 +525,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
var restored = actor.AddScript(removed.PrefabObject.GetType());
var prefabId = actor.PrefabID;
var prefabObjectId = restored.PrefabObjectID;
Script.Internal_LinkPrefab(FlaxEngine.Object.GetUnmanagedPtr(restored), ref prefabId, ref prefabObjectId);
Script.Internal_LinkPrefab(FlaxEngine.Object.GetUnmanagedPtr(restored), prefabId, prefabObjectId);
string data = JsonSerializer.Serialize(removed.PrefabObject);
JsonSerializer.Deserialize(restored, data);
@@ -547,7 +547,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
string data = JsonSerializer.Serialize(removedActor.PrefabObject);
JsonSerializer.Deserialize(restored, data);
Presenter.Owner.SceneContext.Spawn(restored, parentActor, removedActor.OrderInParent);
Actor.Internal_LinkPrefab(FlaxEngine.Object.GetUnmanagedPtr(restored), ref prefabId, ref prefabObjectId);
Actor.Internal_LinkPrefab(FlaxEngine.Object.GetUnmanagedPtr(restored), prefabId, prefabObjectId);
return;
}

View File

@@ -56,7 +56,7 @@ namespace FlaxEditor.SceneGraph.Actors
return false;
}
return Camera.Internal_IntersectsItselfEditor(FlaxEngine.Object.GetUnmanagedPtr(_actor), ref ray.Ray, out distance);
return Camera.Internal_IntersectsItselfEditor(FlaxEngine.Object.GetUnmanagedPtr(_actor), ray.Ray, out distance);
}
/// <inheritdoc />

View File

@@ -191,7 +191,7 @@ namespace FlaxEditor.Actions
script.OrderInParent = _orderInParent;
_orderInParent = script.OrderInParent; // Ensure order is correct for script that want to use it later
if (_prefabObjectId != Guid.Empty)
SceneObject.Internal_LinkPrefab(Object.GetUnmanagedPtr(script), ref _prefabId, ref _prefabObjectId);
SceneObject.Internal_LinkPrefab(Object.GetUnmanagedPtr(script), _prefabId, _prefabObjectId);
Editor.Instance.Scene.MarkSceneEdited(parentActor.Scene);
}
}

View File

@@ -137,7 +137,7 @@ namespace FlaxEditor.Actions
var item = items[i];
var obj = Object.Find<Object>(ref item.ID);
if (obj != null)
SceneObject.Internal_LinkPrefab(Object.GetUnmanagedPtr(obj), ref item.PrefabID, ref item.PrefabObjectID);
SceneObject.Internal_LinkPrefab(Object.GetUnmanagedPtr(obj), item.PrefabID, item.PrefabObjectID);
}
}

View File

@@ -204,7 +204,7 @@ namespace FlaxEditor.Actions
Guid prefabId = _prefabIds[i];
if (prefabId != Guid.Empty)
{
Actor.Internal_LinkPrefab(FlaxEngine.Object.GetUnmanagedPtr(actors[i]), ref prefabId, ref _prefabObjectIds[i]);
Actor.Internal_LinkPrefab(FlaxEngine.Object.GetUnmanagedPtr(actors[i]), prefabId, _prefabObjectIds[i]);
}
}
}

View File

@@ -183,7 +183,7 @@ namespace FlaxEditor.Actions
{
var obj = Object.Find<SceneObject>(ref _idsForPrefab[i]);
if (obj != null && _prefabIds[i] != Guid.Empty)
SceneObject.Internal_LinkPrefab(Object.GetUnmanagedPtr(obj), ref _prefabIds[i], ref _prefabObjectIds[i]);
SceneObject.Internal_LinkPrefab(Object.GetUnmanagedPtr(obj), _prefabIds[i], _prefabObjectIds[i]);
}
}
}

View File

@@ -80,7 +80,7 @@ namespace FlaxEngine
set
{
Quaternion.Euler(ref value, out var orientation);
Internal_SetOrientation(__unmanagedPtr, ref orientation);
Internal_SetOrientation(__unmanagedPtr, orientation);
}
}
@@ -98,7 +98,7 @@ namespace FlaxEngine
set
{
Quaternion.Euler(ref value, out var orientation);
Internal_SetLocalOrientation(__unmanagedPtr, ref orientation);
Internal_SetLocalOrientation(__unmanagedPtr, orientation);
}
}

View File

@@ -12,7 +12,7 @@ namespace FlaxEngine
/// <param name="transform">The transformation to apply.</param>
public static void PushTransform(Matrix3x3 transform)
{
Internal_PushTransform(ref transform);
Internal_PushTransform(transform);
}
/// <summary>
@@ -21,7 +21,7 @@ namespace FlaxEngine
/// <param name="clipRect">The axis aligned clipping mask rectangle.</param>
public static void PushClip(Rectangle clipRect)
{
Internal_PushClip(ref clipRect);
Internal_PushClip(clipRect);
}
/// <summary>
@@ -32,7 +32,7 @@ namespace FlaxEngine
public static void DrawTexture(GPUTextureView rt, Rectangle rect)
{
var color = Color.White;
Internal_DrawTexture(FlaxEngine.Object.GetUnmanagedPtr(rt), ref rect, ref color);
Internal_DrawTexture(FlaxEngine.Object.GetUnmanagedPtr(rt), rect, color);
}
/// <summary>
@@ -43,7 +43,7 @@ namespace FlaxEngine
public static void DrawTexture(GPUTexture t, Rectangle rect)
{
var color = Color.White;
Internal_DrawTexture1(FlaxEngine.Object.GetUnmanagedPtr(t), ref rect, ref color);
Internal_DrawTexture1(FlaxEngine.Object.GetUnmanagedPtr(t), rect, color);
}
/// <summary>
@@ -54,7 +54,7 @@ namespace FlaxEngine
public static void DrawTexture(TextureBase t, Rectangle rect)
{
var color = Color.White;
Internal_DrawTexture2(FlaxEngine.Object.GetUnmanagedPtr(t), ref rect, ref color);
Internal_DrawTexture2(FlaxEngine.Object.GetUnmanagedPtr(t), rect, color);
}
/// <summary>
@@ -75,7 +75,7 @@ namespace FlaxEngine
public static void DrawTexturePoint(GPUTexture t, Rectangle rect)
{
var color = Color.White;
Internal_DrawTexturePoint(FlaxEngine.Object.GetUnmanagedPtr(t), ref rect, ref color);
Internal_DrawTexturePoint(FlaxEngine.Object.GetUnmanagedPtr(t), rect, color);
}
/// <summary>
@@ -96,7 +96,7 @@ namespace FlaxEngine
public static void DrawMaterial(MaterialBase material, Rectangle rect)
{
var color = Color.White;
Internal_DrawMaterial(FlaxEngine.Object.GetUnmanagedPtr(material), ref rect, ref color);
Internal_DrawMaterial(FlaxEngine.Object.GetUnmanagedPtr(material), rect, color);
}
/// <summary>

View File

@@ -111,7 +111,7 @@ void TextRender::SetFontSize(float value)
}
}
void TextRender::SetLayoutOptions(TextLayoutOptions& value)
void TextRender::SetLayoutOptions(const TextLayoutOptions& value)
{
if (_layoutOptions != value)
{

View File

@@ -126,7 +126,7 @@ public:
/// <summary>
/// Sets the layout options. Layout is defined in local space of the object (on XY plane).
/// </summary>
API_PROPERTY() void SetLayoutOptions(TextLayoutOptions& value);
API_PROPERTY() void SetLayoutOptions(const TextLayoutOptions& value);
/// <summary>
/// Gets the axis=aligned bounding box of the text vertices in the local-space of the actor.

View File

@@ -19,7 +19,7 @@ namespace Flax.Build.Bindings
partial class BindingsGenerator
{
private static readonly Dictionary<string, Type> TypeCache = new Dictionary<string, Type>();
private const int CacheVersion = 23;
private const int CacheVersion = 24;
internal static void Write(BinaryWriter writer, string e)
{

View File

@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
namespace Flax.Build.Bindings
{
@@ -1041,7 +1042,12 @@ namespace Flax.Build.Bindings
if (isGetter)
propertyInfo.Getter = functionInfo;
else
{
propertyInfo.Setter = functionInfo;
// Setter value parameter should always be const, forces bindings to pass value as "in" instead of "ref"
CollectionsMarshal.AsSpan(functionInfo.Parameters)[0].IsConst = true;
}
propertyInfo.DeprecatedMessage = functionInfo.DeprecatedMessage;
propertyInfo.IsHidden |= functionInfo.IsHidden;

View File

@@ -113,6 +113,7 @@ namespace Flax.Build.Bindings
{
Name = "value",
Type = fieldInfo.Type,
IsConst = true,
},
},
IsVirtual = false,

View File

@@ -17,6 +17,7 @@ namespace Flax.Build.Bindings
public string DefaultValue;
public string Attributes;
public bool IsRef;
public bool IsConst;
public bool IsOut;
public bool IsThis;
public bool IsParams;
@@ -36,6 +37,7 @@ namespace Flax.Build.Bindings
BindingsGenerator.Write(writer, Attributes);
// TODO: convert into flags
writer.Write(IsRef);
writer.Write(IsConst);
writer.Write(IsOut);
writer.Write(IsThis);
writer.Write(IsParams);
@@ -49,6 +51,7 @@ namespace Flax.Build.Bindings
Attributes = BindingsGenerator.Read(reader, Attributes);
// TODO: convert into flags
IsRef = reader.ReadBoolean();
IsConst = reader.ReadBoolean();
IsOut = reader.ReadBoolean();
IsThis = reader.ReadBoolean();
IsParams = reader.ReadBoolean();