Merge branch 'dotnet7' of https://github.com/GoaLitiuM/FlaxEngine into GoaLitiuM-dotnet7
This commit is contained in:
@@ -183,7 +183,11 @@ void OnAssemblyUnloading(MAssembly* assembly)
|
||||
// Remove entries with user classes
|
||||
for (auto i = Cache.Begin(); i.IsNotEnd(); ++i)
|
||||
{
|
||||
#if USE_NETCORE
|
||||
MonoClass* monoClass = mono_type_get_class(i->Key);
|
||||
#else
|
||||
MonoClass* monoClass = (MonoClass*)(void*)i->Key;
|
||||
#endif
|
||||
|
||||
if (assembly->GetClass(monoClass))
|
||||
{
|
||||
|
||||
@@ -1554,7 +1554,7 @@ namespace FlaxEditor
|
||||
internal static partial bool Internal_CookMeshCollision(string path, CollisionDataType type, IntPtr model, int modelLodIndex, uint materialSlotsMask, ConvexMeshGenerationFlags convexFlags, int convexVertexLimit);
|
||||
|
||||
[LibraryImport("FlaxEngine", EntryPoint = "FlaxEditor.Editor::Internal_GetCollisionWires", StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(FlaxEngine.StringMarshaller))]
|
||||
internal static partial void Internal_GetCollisionWires(IntPtr collisionData, [MarshalUsing(typeof(FlaxEngine.ArrayMarshaller<,>), ConstantElementCount = 1)] out Float3[] triangles, [MarshalUsing(typeof(FlaxEngine.ArrayMarshaller<,>), ConstantElementCount = 1)] out int[] indices);
|
||||
internal static partial void Internal_GetCollisionWires(IntPtr collisionData, [MarshalUsing(typeof(FlaxEngine.ArrayMarshaller<,>), CountElementName = "trianglesCount")] out Float3[] triangles, [MarshalUsing(typeof(FlaxEngine.ArrayMarshaller<,>), CountElementName = "indicesCount")] out int[] indices, out int trianglesCount, out int indicesCount);
|
||||
|
||||
[LibraryImport("FlaxEngine", EntryPoint = "FlaxEditor.Editor::Internal_GetEditorBoxWithChildren", StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(FlaxEngine.StringMarshaller))]
|
||||
internal static partial void Internal_GetEditorBoxWithChildren(IntPtr obj, out BoundingBox resultAsRef);
|
||||
@@ -1602,12 +1602,12 @@ namespace FlaxEditor
|
||||
internal static partial void Internal_RunVisualScriptBreakpointLoopTick(float deltaTime);
|
||||
|
||||
[LibraryImport("FlaxEngine", EntryPoint = "FlaxEditor.Editor::Internal_GetVisualScriptLocals", StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(FlaxEngine.StringMarshaller))]
|
||||
[return: MarshalUsing(typeof(FlaxEngine.ArrayMarshaller<,>), ConstantElementCount = 1)]
|
||||
internal static partial VisualScriptLocal[] Internal_GetVisualScriptLocals();
|
||||
[return: MarshalUsing(typeof(FlaxEngine.ArrayMarshaller<,>), CountElementName = "localsCount")]
|
||||
internal static partial VisualScriptLocal[] Internal_GetVisualScriptLocals(out int localsCount);
|
||||
|
||||
[LibraryImport("FlaxEngine", EntryPoint = "FlaxEditor.Editor::Internal_GetVisualScriptStackFrames", StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(FlaxEngine.StringMarshaller))]
|
||||
[return: MarshalUsing(typeof(FlaxEngine.ArrayMarshaller<,>), ConstantElementCount = 1)]
|
||||
internal static partial VisualScriptStackFrame[] Internal_GetVisualScriptStackFrames();
|
||||
[return: MarshalUsing(typeof(FlaxEngine.ArrayMarshaller<,>), CountElementName = "stackFrameCount")]
|
||||
internal static partial VisualScriptStackFrame[] Internal_GetVisualScriptStackFrames(out int stackFrameCount);
|
||||
|
||||
[LibraryImport("FlaxEngine", EntryPoint = "FlaxEditor.Editor::Internal_GetVisualScriptPreviousScopeFrame", StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(FlaxEngine.StringMarshaller))]
|
||||
internal static partial VisualScriptStackFrame Internal_GetVisualScriptPreviousScopeFrame();
|
||||
|
||||
@@ -419,7 +419,7 @@ public:
|
||||
return 0;
|
||||
|
||||
int32 count = 0;
|
||||
const int32 maxCount = outArraySize;//(int32)mono_array_length(*outMessages);
|
||||
const int32 maxCount = outArraySize;
|
||||
|
||||
byte* ptr = CachedLogData.Get();
|
||||
byte* end = ptr + CachedLogData.Count();
|
||||
@@ -798,7 +798,7 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
static void GetCollisionWires(CollisionData* collisionData, MonoArray** triangles, MonoArray** indices)
|
||||
static void GetCollisionWires(CollisionData* collisionData, MonoArray** triangles, MonoArray** indices, int* trianglesCount, int* indicesCount)
|
||||
{
|
||||
SCRIPTING_EXPORT("FlaxEditor.Editor::Internal_GetCollisionWires")
|
||||
if (!collisionData || collisionData->WaitForLoaded() || collisionData->GetOptions().Type == CollisionDataType::None)
|
||||
@@ -822,6 +822,8 @@ public:
|
||||
mono_array_set(*indices, int32, iI++, i + 1);
|
||||
mono_array_set(*indices, int32, iI++, i);
|
||||
}
|
||||
*trianglesCount = debugLines.Count();
|
||||
*indicesCount = linesCount * 3;
|
||||
}
|
||||
|
||||
static void GetEditorBoxWithChildren(Actor* obj, BoundingBox* result)
|
||||
@@ -960,10 +962,11 @@ public:
|
||||
int32 BoxId;
|
||||
};
|
||||
|
||||
static MonoArray* GetVisualScriptLocals()
|
||||
static MonoArray* GetVisualScriptLocals(int* localsCount)
|
||||
{
|
||||
SCRIPTING_EXPORT("FlaxEditor.Editor::Internal_GetVisualScriptLocals")
|
||||
MonoArray* result = nullptr;
|
||||
*localsCount = 0;
|
||||
const auto stack = VisualScripting::GetThreadStackTop();
|
||||
if (stack && stack->Scope)
|
||||
{
|
||||
@@ -998,6 +1001,7 @@ public:
|
||||
local.ValueTypeName = MUtils::ToString(v.Value.Type.GetTypeName());
|
||||
mono_array_set(result, VisualScriptLocalManaged, stack->Scope->Parameters.Length() + i, local);
|
||||
}
|
||||
*localsCount = count;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1009,10 +1013,11 @@ public:
|
||||
int32 BoxId;
|
||||
};
|
||||
|
||||
static MonoArray* GetVisualScriptStackFrames()
|
||||
static MonoArray* GetVisualScriptStackFrames(int* stackFramesCount)
|
||||
{
|
||||
SCRIPTING_EXPORT("FlaxEditor.Editor::Internal_GetVisualScriptStackFrames")
|
||||
MonoArray* result = nullptr;
|
||||
*stackFramesCount = 0;
|
||||
const auto stack = VisualScripting::GetThreadStackTop();
|
||||
if (stack)
|
||||
{
|
||||
@@ -1038,6 +1043,7 @@ public:
|
||||
s = s->PreviousFrame;
|
||||
count++;
|
||||
}
|
||||
*stackFramesCount = count;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -236,7 +236,7 @@ namespace FlaxEditor.Windows.Assets
|
||||
_collisionWiresModel = FlaxEngine.Content.CreateVirtualAsset<Model>();
|
||||
_collisionWiresModel.SetupLODs(new[] { 1 });
|
||||
}
|
||||
Editor.Internal_GetCollisionWires(FlaxEngine.Object.GetUnmanagedPtr(Asset), out var triangles, out var indices);
|
||||
Editor.Internal_GetCollisionWires(FlaxEngine.Object.GetUnmanagedPtr(Asset), out var triangles, out var indices, out var _, out var _);
|
||||
if (triangles != null && indices != null)
|
||||
_collisionWiresModel.LODs[0].Meshes[0].UpdateMesh(triangles, indices);
|
||||
else
|
||||
|
||||
@@ -818,7 +818,7 @@ namespace FlaxEditor.Windows.Assets
|
||||
var state = (BreakpointHangState)Editor.Instance.Simulation.BreakpointHangTag;
|
||||
if (state.Locals == null)
|
||||
{
|
||||
state.Locals = Editor.Internal_GetVisualScriptLocals();
|
||||
state.Locals = Editor.Internal_GetVisualScriptLocals(out var _);
|
||||
Editor.Instance.Simulation.BreakpointHangTag = state;
|
||||
}
|
||||
return state;
|
||||
@@ -829,7 +829,7 @@ namespace FlaxEditor.Windows.Assets
|
||||
var state = (BreakpointHangState)Editor.Instance.Simulation.BreakpointHangTag;
|
||||
if (state.StackFrames == null)
|
||||
{
|
||||
state.StackFrames = Editor.Internal_GetVisualScriptStackFrames();
|
||||
state.StackFrames = Editor.Internal_GetVisualScriptStackFrames(out var _);
|
||||
Editor.Instance.Simulation.BreakpointHangTag = state;
|
||||
}
|
||||
return state;
|
||||
|
||||
@@ -797,6 +797,12 @@ namespace FlaxEngine
|
||||
hostExecutable = Marshal.PtrToStringUni(hostExecutableName);
|
||||
NativeLibrary.SetDllImportResolver(Assembly.GetExecutingAssembly(), InternalDllResolver);
|
||||
|
||||
// Change default culture to match with Mono runtime default culture
|
||||
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
|
||||
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;
|
||||
System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
|
||||
System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
|
||||
|
||||
// TODO: benchmark collectible setting performance, maybe enable it only in editor builds?
|
||||
scriptingAssemblyLoadContext = new AssemblyLoadContext(null, true);
|
||||
|
||||
@@ -1359,6 +1365,18 @@ namespace FlaxEngine
|
||||
*classAttributesCount = attributeTypes.Length;
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
internal static IntPtr GetCustomAttribute(IntPtr typeHandle, IntPtr attribHandle)
|
||||
{
|
||||
Type type = (Type)GCHandle.FromIntPtr(typeHandle).Target;
|
||||
Type attribType = (Type)GCHandle.FromIntPtr(attribHandle).Target;
|
||||
object attrib = type.GetCustomAttributes(false).FirstOrDefault(x => x.GetType() == attribType);
|
||||
|
||||
if (attrib != null)
|
||||
return GCHandle.ToIntPtr(GCHandle.Alloc(attrib, GCHandleType.Weak));
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
internal static void GetClassInterfaces(IntPtr typeHandle, IntPtr* classInterfaces, int* classInterfacesCount)
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <ThirdParty/mono-2.0/mono/metadata/blob.h>
|
||||
|
||||
#include "Engine/Core/Types/String.h"
|
||||
#include "Engine/Core/Collections/Array.h"
|
||||
#include "Engine/Scripting/Types.h"
|
||||
|
||||
#if defined(_WIN32)
|
||||
@@ -46,4 +47,9 @@ public:
|
||||
static gchandle NewGCHandleWeakref(void* obj, bool track_resurrection);
|
||||
static void* GetGCHandleTarget(const gchandle& gchandle);
|
||||
static void FreeGCHandle(const gchandle& gchandle);
|
||||
|
||||
static bool HasCustomAttribute(void* klass, void* attribClass);
|
||||
static bool HasCustomAttribute(void* klass);
|
||||
static void* GetCustomAttribute(void* klass, void* attribClass);
|
||||
static Array<void*> GetCustomAttributes(void* klass);
|
||||
};
|
||||
|
||||
@@ -587,6 +587,30 @@ const char* CoreCLR::GetClassFullname(void* klass)
|
||||
return ((CoreCLRClass*)klass)->GetFullname().Get();
|
||||
}
|
||||
|
||||
bool CoreCLR::HasCustomAttribute(void* klass, void* attribClass)
|
||||
{
|
||||
return CoreCLR::GetCustomAttribute(klass, attribClass) != nullptr;
|
||||
}
|
||||
bool CoreCLR::HasCustomAttribute(void* klass)
|
||||
{
|
||||
return CoreCLR::GetCustomAttribute(klass, nullptr) != nullptr;
|
||||
}
|
||||
void* CoreCLR::GetCustomAttribute(void* klass, void* attribClass)
|
||||
{
|
||||
return CoreCLR::CallStaticMethodInternal<void*, void*, void*>(TEXT("GetCustomAttribute"), ((CoreCLRClass*)klass)->GetTypeHandle(), ((CoreCLRClass*)attribClass)->GetTypeHandle());
|
||||
}
|
||||
Array<void*> CoreCLR::GetCustomAttributes(void* klass)
|
||||
{
|
||||
Array<CoreCLRCustomAttribute*> attrib = ((CoreCLRClass*)klass)->GetCustomAttributes();
|
||||
|
||||
Array<void*> attributes;
|
||||
attributes.Resize(attrib.Count(), false);
|
||||
for (int i = 0; i < attrib.Count(); i++)
|
||||
attributes.Add(attrib[i]->GetHandle());
|
||||
|
||||
return attributes;
|
||||
}
|
||||
|
||||
/*
|
||||
* loader.h
|
||||
*/
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
#include <ThirdParty/mono-2.0/mono/metadata/attrdefs.h>
|
||||
#define GET_CUSTOM_ATTR() (MonoCustomAttrInfo*)(_attrInfo ? _attrInfo : _attrInfo = mono_custom_attrs_from_class(_monoClass))
|
||||
#endif
|
||||
#if USE_NETCORE
|
||||
#include "Engine/Scripting/DotNet/CoreCLR.h"
|
||||
#endif
|
||||
|
||||
#if USE_MONO
|
||||
MClass::MClass(const MAssembly* parentAssembly, MonoClass* monoClass, const MString& fullname)
|
||||
@@ -375,7 +378,9 @@ MObject* MClass::CreateInstance(void** params, uint32 numParams)
|
||||
|
||||
bool MClass::HasAttribute(const MClass* monoClass) const
|
||||
{
|
||||
#if USE_MONO
|
||||
#if USE_NETCORE
|
||||
return CoreCLR::HasCustomAttribute(_monoClass, monoClass->GetNative());
|
||||
#elif USE_MONO
|
||||
MonoCustomAttrInfo* attrInfo = GET_CUSTOM_ATTR();
|
||||
return attrInfo != nullptr && mono_custom_attrs_has_attr(attrInfo, monoClass->GetNative()) != 0;
|
||||
#else
|
||||
@@ -385,7 +390,9 @@ bool MClass::HasAttribute(const MClass* monoClass) const
|
||||
|
||||
bool MClass::HasAttribute() const
|
||||
{
|
||||
#if USE_MONO
|
||||
#if USE_NETCORE
|
||||
return CoreCLR::HasCustomAttribute(_monoClass);
|
||||
#elif USE_MONO
|
||||
MonoCustomAttrInfo* attrInfo = GET_CUSTOM_ATTR();
|
||||
return attrInfo && attrInfo->num_attrs > 0;
|
||||
#else
|
||||
@@ -395,7 +402,9 @@ bool MClass::HasAttribute() const
|
||||
|
||||
MObject* MClass::GetAttribute(const MClass* monoClass) const
|
||||
{
|
||||
#if USE_MONO
|
||||
#if USE_NETCORE
|
||||
return (MObject*)CoreCLR::GetCustomAttribute(_monoClass, monoClass->GetNative());
|
||||
#elif USE_MONO
|
||||
MonoCustomAttrInfo* attrInfo = GET_CUSTOM_ATTR();
|
||||
return attrInfo ? mono_custom_attrs_get_attr(attrInfo, monoClass->GetNative()) : nullptr;
|
||||
#else
|
||||
@@ -409,7 +418,9 @@ const Array<MObject*>& MClass::GetAttributes()
|
||||
return _attributes;
|
||||
|
||||
_hasCachedAttributes = true;
|
||||
#if USE_MONO
|
||||
#if USE_NETCORE
|
||||
_attributes = *(Array<MObject*>*)(&CoreCLR::GetCustomAttributes(_monoClass));
|
||||
#elif USE_MONO
|
||||
MonoCustomAttrInfo* attrInfo = GET_CUSTOM_ATTR();
|
||||
if (attrInfo == nullptr)
|
||||
return _attributes;
|
||||
|
||||
Reference in New Issue
Block a user