Implement .NET 7 runtime support and bindings generation

This commit is contained in:
2022-11-17 19:49:39 +02:00
parent fe943ca010
commit 96dc279ebd
89 changed files with 6009 additions and 503 deletions

View File

@@ -6,13 +6,15 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
namespace FlaxEngine
{
/// <summary>
/// Class with helper functions.
/// </summary>
public static class Utils
public static partial class Utils
{
/// <summary>
/// Copies data from one memory location to another using an unmanaged memory pointers.
@@ -35,8 +37,8 @@ namespace FlaxEngine
/// <param name="source">The source location.</param>
/// <param name="destination">The destination location.</param>
/// <param name="length">The length (amount of bytes to copy).</param>
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern void MemoryCopy(IntPtr destination, IntPtr source, ulong length);
[LibraryImport("FlaxEngine", EntryPoint = "FlaxEngine.Utils::MemoryCopy")]
public static partial void MemoryCopy(IntPtr destination, IntPtr source, ulong length);
/// <summary>
/// Clears the memory region with zeros.
@@ -44,8 +46,8 @@ namespace FlaxEngine
/// <remarks>Uses low-level platform impl.</remarks>
/// <param name="dst">Destination memory address</param>
/// <param name="size">Size of the memory to clear in bytes</param>
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern void MemoryClear(IntPtr dst, ulong size);
[LibraryImport("FlaxEngine", EntryPoint = "FlaxEngine.Utils::MemoryClear")]
public static partial void MemoryClear(IntPtr dst, ulong size);
/// <summary>
/// Compares two blocks of the memory.
@@ -54,8 +56,8 @@ namespace FlaxEngine
/// <param name="buf1">The first buffer address.</param>
/// <param name="buf2">The second buffer address.</param>
/// <param name="size">Size of the memory to compare in bytes.</param>
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern int MemoryCompare(IntPtr buf1, IntPtr buf2, ulong size);
[LibraryImport("FlaxEngine", EntryPoint = "FlaxEngine.Utils::MemoryCompare")]
public static partial int MemoryCompare(IntPtr buf1, IntPtr buf2, ulong size);
/// <summary>
/// Rounds the floating point value up to 1 decimal place.
@@ -94,7 +96,11 @@ namespace FlaxEngine
/// <returns>The empty array object.</returns>
public static T[] GetEmptyArray<T>()
{
#if USE_NETCORE
return Array.Empty<T>();
#else
return Enumerable.Empty<T>() as T[];
#endif
}
/// <summary>
@@ -209,10 +215,50 @@ namespace FlaxEngine
return result;
}
/// <summary>
/// Gets the location of the assembly.
/// </summary>
/// <param name="assembly">The assembly.</param>
/// <returns>Path in the filesystem</returns>
public static string GetAssemblyLocation(Assembly assembly)
{
#if USE_NETCORE
if (!string.IsNullOrEmpty(assembly.Location))
return assembly.Location;
if (NativeInterop.AssemblyLocations.TryGetValue(assembly.FullName, out string assemblyLocation))
return assemblyLocation;
return null;
#else
return assembly.Location;
#endif
}
#if USE_MONO
internal static T[] ExtractArrayFromList<T>(List<T> list)
{
return list != null ? (T[])Internal_ExtractArrayFromList(list) : null;
}
#else
private class ExtractArrayFromListContext<T>
{
public static FieldInfo? itemsField;
}
internal static T[] ExtractArrayFromList<T>(List<T> list)
{
if (list == null)
return null;
if (ExtractArrayFromListContext<T>.itemsField == null)
{
Type listType = typeof(List<T>);
ExtractArrayFromListContext<T>.itemsField = listType.GetField("_items", BindingFlags.NonPublic | BindingFlags.Instance);
}
return (T[])ExtractArrayFromListContext<T>.itemsField.GetValue(list); // boxing is slower;
}
#endif
internal static Float2[] ConvertCollection(Vector2[] v)
{
@@ -295,8 +341,9 @@ namespace FlaxEngine
return result;
}
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern Array Internal_ExtractArrayFromList(object list);
[LibraryImport("FlaxEngine", EntryPoint = "FlaxEngine.Utils::Internal_ExtractArrayFromList")]
[return: MarshalUsing(typeof(FlaxEngine.SystemArrayMarshaller))]
internal static partial Array Internal_ExtractArrayFromList([MarshalUsing(typeof(FlaxEngine.GCHandleMarshaller))] object list);
/// <summary>
/// Reads the color from the binary stream.