Tweaks and improvements

This commit is contained in:
Wojtek Figat
2021-07-29 15:41:58 +02:00
parent 92b1e067b1
commit f42d2b8a18
6 changed files with 22 additions and 32 deletions

View File

@@ -25,12 +25,12 @@ namespace FlaxEditor.Modules.SourceCodeEditing
{
}
private static bool CheckFunc(ScriptType type)
private static bool CheckFunc(ScriptType scriptType)
{
if (!type.IsPublic)
if (scriptType.IsStatic || scriptType.IsGenericType || !scriptType.IsPublic || scriptType.HasAttribute(typeof(HideInEditorAttribute), true))
return false;
var objectType = new ScriptType(typeof(FlaxEngine.Object));
return type.IsEnum || type == objectType || objectType.IsAssignableFrom(type);
return scriptType.IsEnum || objectType.IsAssignableFrom(scriptType);
}
/// <inheritdoc />

View File

@@ -288,12 +288,12 @@ namespace FlaxEditor.Surface
/// <remarks>
/// Don't call it too often. It does memory allocation and iterates over the surface controls to find comments in the graph.
/// </remarks>
public List<SurfaceComment> Comments => _context.Comments;
public List<SurfaceComment> Comments => _context?.Comments;
/// <summary>
/// The current surface context nodes collection. Read-only.
/// </summary>
public List<SurfaceNode> Nodes => _context.Nodes;
public List<SurfaceNode> Nodes => _context?.Nodes;
/// <summary>
/// The surface node descriptors collection.

View File

@@ -188,12 +188,13 @@ namespace FlaxEditor.Utilities
public static void DirectoryCopy(string srcDirectoryPath, string dstDirectoryPath, bool copySubDirs = true, bool overrideFiles = false)
{
var dir = new DirectoryInfo(srcDirectoryPath);
if (!dir.Exists)
{
throw new DirectoryNotFoundException("Missing source directory to copy. " + srcDirectoryPath);
}
DirectoryCopy(dir, dstDirectoryPath, copySubDirs, overrideFiles);
}
private static void DirectoryCopy(DirectoryInfo dir, string dstDirectoryPath, bool copySubDirs = true, bool overrideFiles = false)
{
if (!Directory.Exists(dstDirectoryPath))
{
Directory.CreateDirectory(dstDirectoryPath);
@@ -212,7 +213,7 @@ namespace FlaxEditor.Utilities
for (int i = 0; i < dirs.Length; i++)
{
string tmp = Path.Combine(dstDirectoryPath, dirs[i].Name);
DirectoryCopy(dirs[i].FullName, tmp, true, overrideFiles);
DirectoryCopy(dirs[i], tmp, true, overrideFiles);
}
}
}
@@ -225,11 +226,7 @@ namespace FlaxEditor.Utilities
/// <returns>The structure.</returns>
public static T ByteArrayToStructure<T>(byte[] bytes) where T : struct
{
// #stupid c#
GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
T stuff = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T));
handle.Free();
return stuff;
return (T)ByteArrayToStructure(bytes, typeof(T));
}
/// <summary>
@@ -255,10 +252,7 @@ namespace FlaxEditor.Utilities
/// <param name="result">The result.</param>
public static void ByteArrayToStructure<T>(byte[] bytes, out T result) where T : struct
{
// #stupid c#
GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
result = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T));
handle.Free();
result = (T)ByteArrayToStructure(bytes, typeof(T));
}
/// <summary>
@@ -269,14 +263,7 @@ namespace FlaxEditor.Utilities
/// <returns>The bytes array that contains a structure data.</returns>
public static byte[] StructureToByteArray<T>(ref T value) where T : struct
{
// #stupid c#
int size = Marshal.SizeOf(typeof(T));
byte[] arr = new byte[size];
IntPtr ptr = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(value, ptr, true);
Marshal.Copy(ptr, arr, 0, size);
Marshal.FreeHGlobal(ptr);
return arr;
return StructureToByteArray(value, typeof(void));
}
/// <summary>

View File

@@ -418,6 +418,8 @@ namespace FlaxEditor.Utilities
{
if (type == null)
throw new Exception("Missing structure type of the Variant.");
if (!type.IsStructure())
throw new Exception($"Invalid type {type.FullName} used as a structure.");
var data = stream.ReadBytes(stream.ReadInt32());
return Utils.ByteArrayToStructure(data, type);
}

View File

@@ -338,9 +338,12 @@ namespace FlaxEditor.Windows
FlaxEngine.Scripting.RunOnUpdate(() =>
{
vsWindow.Surface.NodeBreakpointEdited += OnSurfaceNodeBreakpointEdited;
foreach (var node in vsWindow.Surface.Nodes)
if (node.Breakpoint.Set)
OnSurfaceNodeBreakpointEdited(node);
if (vsWindow.Surface.Nodes != null)
{
foreach (var node in vsWindow.Surface.Nodes)
if (node.Breakpoint.Set)
OnSurfaceNodeBreakpointEdited(node);
}
});
}
}

View File

@@ -348,9 +348,7 @@ void ReadStream::ReadVariant(Variant* data)
LOG(Error, "Invalid Variant {2} data length {0}. Expected {1} bytes from stream.", data->AsBlob.Length, length, data->Type.ToString());
// Skip those bytes
void* ptr = Allocator::Allocate(length);
ReadBytes(ptr, length);
Allocator::Free(ptr);
SetPosition(GetPosition() + length);
}
break;
}