Various fixes for scripting runtime
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
Custom fork: [https://github.com/FlaxEngine/mono](https://github.com/FlaxEngine/mono) with custom features for C# assemblies hot-reloading at runtime without domain unload (more: [https://flaxengine.com/blog/flax-facts-16-scripts-hot-reload/](https://flaxengine.com/blog/flax-facts-16-scripts-hot-reload/)).
|
Custom fork: [https://github.com/FlaxEngine/mono](https://github.com/FlaxEngine/mono) with custom features for C# assemblies hot-reloading at runtime without domain unload (more: [https://flaxengine.com/blog/flax-facts-16-scripts-hot-reload/](https://flaxengine.com/blog/flax-facts-16-scripts-hot-reload/)).
|
||||||
|
|
||||||
|
Startup docs about building mono: [https://www.mono-project.com/docs/compiling-mono/](https://www.mono-project.com/docs/compiling-mono/)
|
||||||
|
|
||||||
### Notes
|
### Notes
|
||||||
|
|
||||||
Some useful notes and tips for devs:
|
Some useful notes and tips for devs:
|
||||||
|
|||||||
@@ -281,9 +281,10 @@ bool JsonAsset::CreateInstance()
|
|||||||
|
|
||||||
void JsonAsset::DeleteInstance()
|
void JsonAsset::DeleteInstance()
|
||||||
{
|
{
|
||||||
ASSERT_LOW_LAYER(Instance && _dtor);
|
if (!Instance || !_dtor)
|
||||||
InstanceType = ScriptingTypeHandle();
|
return;
|
||||||
_dtor(Instance);
|
_dtor(Instance);
|
||||||
|
InstanceType = ScriptingTypeHandle();
|
||||||
Allocator::Free(Instance);
|
Allocator::Free(Instance);
|
||||||
Instance = nullptr;
|
Instance = nullptr;
|
||||||
_dtor = nullptr;
|
_dtor = nullptr;
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
int32 _firstManagedTypeIndex;
|
int32 _firstManagedTypeIndex = 0;
|
||||||
Array<void*> _managedMemoryBlocks;
|
Array<void*> _managedMemoryBlocks;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -352,6 +352,7 @@ bool MAssembly::LoadWithImage(const String& assemblyPath)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: load pdbs for custom third-party libs referenced by game assemblies for debugging
|
||||||
#if 0
|
#if 0
|
||||||
// Hack to load debug information for Newtonsoft.Json (enable it to debug C# code of json lib)
|
// Hack to load debug information for Newtonsoft.Json (enable it to debug C# code of json lib)
|
||||||
if (assemblyPath.EndsWith(TEXT("FlaxEngine.CSharp.dll")))
|
if (assemblyPath.EndsWith(TEXT("FlaxEngine.CSharp.dll")))
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#include "MCore.h"
|
#include "MCore.h"
|
||||||
#include "MDomain.h"
|
#include "MDomain.h"
|
||||||
#include "MClass.h"
|
|
||||||
#include "Engine/Core/Log.h"
|
#include "Engine/Core/Log.h"
|
||||||
#include "Engine/Core/Types/String.h"
|
#include "Engine/Core/Types/String.h"
|
||||||
#include "Engine/Core/Types/DateTime.h"
|
#include "Engine/Core/Types/DateTime.h"
|
||||||
@@ -353,6 +352,9 @@ bool MCore::LoadEngine()
|
|||||||
PROFILE_CPU();
|
PROFILE_CPU();
|
||||||
ASSERT(Globals::MonoPath.IsANSI());
|
ASSERT(Globals::MonoPath.IsANSI());
|
||||||
|
|
||||||
|
// Debugging Mono GC
|
||||||
|
//Platform::SetEnvironmentVariable(TEXT("MONO_GC_DEBUG"), TEXT("6:gc-log.txt,check-remset-consistency,nursery-canaries"));
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
// Override memory allocation callback
|
// Override memory allocation callback
|
||||||
// TODO: use ENABLE_OVERRIDABLE_ALLOCATORS when building Mono to support memory callbacks or use counters for memory profiling
|
// TODO: use ENABLE_OVERRIDABLE_ALLOCATORS when building Mono to support memory callbacks or use counters for memory profiling
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ MonoString* MUtils::ToString(const String& str)
|
|||||||
MonoString* MUtils::ToString(const String& str, MonoDomain* domain)
|
MonoString* MUtils::ToString(const String& str, MonoDomain* domain)
|
||||||
{
|
{
|
||||||
if (str.IsEmpty())
|
if (str.IsEmpty())
|
||||||
return mono_string_empty(mono_domain_get());
|
return mono_string_empty(domain);
|
||||||
return mono_string_new_utf16(domain, (const mono_unichar2*)*str, str.Length());
|
return mono_string_new_utf16(domain, (const mono_unichar2*)*str, str.Length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#include "ManagedCLR/MMethod.h"
|
#include "ManagedCLR/MMethod.h"
|
||||||
#include <ThirdParty/mono-2.0/mono/metadata/mono-debug.h>
|
#include <ThirdParty/mono-2.0/mono/metadata/mono-debug.h>
|
||||||
|
|
||||||
void ManagedSerialization::Serialize(ISerializable::SerializeStream& stream, MonoObject* object)
|
void ManagedSerialization::Serialize(ISerializable::SerializeStream& stream, MObject* object)
|
||||||
{
|
{
|
||||||
if (!object)
|
if (!object)
|
||||||
{
|
{
|
||||||
@@ -47,7 +47,7 @@ void ManagedSerialization::Serialize(ISerializable::SerializeStream& stream, Mon
|
|||||||
mono_free(invokeResultChars);
|
mono_free(invokeResultChars);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ManagedSerialization::SerializeDiff(ISerializable::SerializeStream& stream, MonoObject* object, MonoObject* other)
|
void ManagedSerialization::SerializeDiff(ISerializable::SerializeStream& stream, MObject* object, MObject* other)
|
||||||
{
|
{
|
||||||
if (!object || !other)
|
if (!object || !other)
|
||||||
{
|
{
|
||||||
@@ -85,7 +85,7 @@ void ManagedSerialization::SerializeDiff(ISerializable::SerializeStream& stream,
|
|||||||
mono_free(invokeResultChars);
|
mono_free(invokeResultChars);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ManagedSerialization::Deserialize(ISerializable::DeserializeStream& stream, MonoObject* object)
|
void ManagedSerialization::Deserialize(ISerializable::DeserializeStream& stream, MObject* object)
|
||||||
{
|
{
|
||||||
if (!object)
|
if (!object)
|
||||||
return;
|
return;
|
||||||
@@ -98,7 +98,7 @@ void ManagedSerialization::Deserialize(ISerializable::DeserializeStream& stream,
|
|||||||
Deserialize(StringAnsiView(buffer.GetString(), (int32)buffer.GetSize()), object);
|
Deserialize(StringAnsiView(buffer.GetString(), (int32)buffer.GetSize()), object);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ManagedSerialization::Deserialize(const StringAnsiView& data, MonoObject* object)
|
void ManagedSerialization::Deserialize(const StringAnsiView& data, MObject* object)
|
||||||
{
|
{
|
||||||
const char* str = data.Get();
|
const char* str = data.Get();
|
||||||
const int32 len = data.Length();
|
const int32 len = data.Length();
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public:
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="stream">The output stream.</param>
|
/// <param name="stream">The output stream.</param>
|
||||||
/// <param name="object">The object to serialize.</param>
|
/// <param name="object">The object to serialize.</param>
|
||||||
static void Serialize(ISerializable::SerializeStream& stream, MonoObject* object);
|
static void Serialize(ISerializable::SerializeStream& stream, MObject* object);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Serializes managed object difference to JSON.
|
/// Serializes managed object difference to JSON.
|
||||||
@@ -26,20 +26,20 @@ public:
|
|||||||
/// <param name="stream">The output stream.</param>
|
/// <param name="stream">The output stream.</param>
|
||||||
/// <param name="object">The object to serialize.</param>
|
/// <param name="object">The object to serialize.</param>
|
||||||
/// <param name="other">The reference object to serialize diff compared to it.</param>
|
/// <param name="other">The reference object to serialize diff compared to it.</param>
|
||||||
static void SerializeDiff(ISerializable::SerializeStream& stream, MonoObject* object, MonoObject* other);
|
static void SerializeDiff(ISerializable::SerializeStream& stream, MObject* object, MObject* other);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deserializes managed object from the JSON.
|
/// Deserializes managed object from the JSON.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="stream">The input stream.</param>
|
/// <param name="stream">The input stream.</param>
|
||||||
/// <param name="object">The object to deserialize.</param>
|
/// <param name="object">The object to deserialize.</param>
|
||||||
static void Deserialize(ISerializable::DeserializeStream& stream, MonoObject* object);
|
static void Deserialize(ISerializable::DeserializeStream& stream, MObject* object);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deserializes managed object from the JSON.
|
/// Deserializes managed object from the JSON.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="data">The input data.</param>
|
/// <param name="data">The input data.</param>
|
||||||
/// <param name="object">The object to deserialize.</param>
|
/// <param name="object">The object to deserialize.</param>
|
||||||
static void Deserialize(const StringAnsiView& data, MonoObject* object);
|
static void Deserialize(const StringAnsiView& data, MObject* object);
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ namespace Flax.Build
|
|||||||
|
|
||||||
// Prefer installed Roslyn C# compiler over Mono one
|
// Prefer installed Roslyn C# compiler over Mono one
|
||||||
monoPath = null;
|
monoPath = null;
|
||||||
cscPath = Path.Combine(Path.GetDirectoryName(Deploy.VCEnvironment.MSBuildPath), "Roslyn", "csc.exe");
|
cscPath = Path.Combine(Path.GetDirectoryName(VCEnvironment.MSBuildPath), "Roslyn", "csc.exe");
|
||||||
|
|
||||||
if (!File.Exists(cscPath))
|
if (!File.Exists(cscPath))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -244,6 +244,26 @@ namespace Flax.Build
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes the directories inside a directory.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="directoryPath">The directory path.</param>
|
||||||
|
/// <param name="searchPattern">The custom filter for the directories to delete. Can be used to select files to delete. Null if unused.</param>
|
||||||
|
/// <param name="withSubdirs">if set to <c>true</c> with sub-directories (recursive delete operation).</param>
|
||||||
|
public static void DirectoriesDelete(string directoryPath, string searchPattern = null, bool withSubdirs = true)
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(directoryPath))
|
||||||
|
return;
|
||||||
|
if (searchPattern == null)
|
||||||
|
searchPattern = "*";
|
||||||
|
|
||||||
|
var directories = Directory.GetDirectories(directoryPath, searchPattern, withSubdirs ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
|
||||||
|
for (int i = 0; i < directories.Length; i++)
|
||||||
|
{
|
||||||
|
DirectoryDelete(directories[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The process run options.
|
/// The process run options.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user