Optimize VariantType to use static type name in game or from non-reloadable assemblies
This avoids many dynamic memory allocations in Visual Scripts and Anim Graph. #
This commit is contained in:
@@ -683,6 +683,8 @@ BinaryModule* BinaryModule::GetModule(const StringAnsiView& name)
|
||||
|
||||
BinaryModule::BinaryModule()
|
||||
{
|
||||
CanReload = USE_EDITOR;
|
||||
|
||||
// Register
|
||||
GetModules().Add(this);
|
||||
}
|
||||
|
||||
@@ -91,6 +91,11 @@ public:
|
||||
/// </summary>
|
||||
Dictionary<StringAnsi, int32> TypeNameToTypeIndex;
|
||||
|
||||
/// <summary>
|
||||
/// Determinates whether module can be hot-reloaded at runtime. For example, in Editor after scripts recompilation. Some modules such as engine and class library modules are static.
|
||||
/// </summary>
|
||||
bool CanReload;
|
||||
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -34,6 +34,7 @@ private:
|
||||
|
||||
int32 _isLoaded : 1;
|
||||
int32 _isLoading : 1;
|
||||
int32 _canReload : 1;
|
||||
mutable int32 _hasCachedClasses : 1;
|
||||
|
||||
mutable ClassesDictionary _classes;
|
||||
@@ -125,6 +126,14 @@ public:
|
||||
return _isLoaded != 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if assembly can be hot-reloaded at runtime. For example, in Editor after scripts recompilation. Some assemblies such as engine and class library modules are static.
|
||||
/// </summary>
|
||||
FORCE_INLINE bool CanReload() const
|
||||
{
|
||||
return USE_EDITOR && _canReload;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the assembly name.
|
||||
/// </summary>
|
||||
|
||||
@@ -45,6 +45,7 @@ MAssembly::MAssembly(MDomain* domain, const StringAnsiView& name)
|
||||
: _domain(domain)
|
||||
, _isLoaded(false)
|
||||
, _isLoading(false)
|
||||
, _canReload(true)
|
||||
, _hasCachedClasses(false)
|
||||
, _reloadCount(0)
|
||||
, _name(name)
|
||||
@@ -59,6 +60,7 @@ MAssembly::MAssembly(MDomain* domain, const StringAnsiView& name, const StringAn
|
||||
, _domain(domain)
|
||||
, _isLoaded(false)
|
||||
, _isLoading(false)
|
||||
, _canReload(true)
|
||||
, _hasCachedClasses(false)
|
||||
, _reloadCount(0)
|
||||
, _name(name)
|
||||
|
||||
@@ -874,6 +874,7 @@ bool MAssembly::LoadCorlib()
|
||||
return true;
|
||||
}
|
||||
_hasCachedClasses = false;
|
||||
_canReload = false;
|
||||
CachedAssemblyHandles.Add(_handle, this);
|
||||
|
||||
// End
|
||||
|
||||
@@ -502,6 +502,7 @@ bool Scripting::LoadBinaryModules(const String& path, const String& projectFolde
|
||||
// C#
|
||||
if (managedPath.HasChars() && !((ManagedBinaryModule*)module)->Assembly->IsLoaded())
|
||||
{
|
||||
(((ManagedBinaryModule*)module)->Assembly)->_canReload = module->CanReload;
|
||||
if (((ManagedBinaryModule*)module)->Assembly->Load(managedPath, nativePath))
|
||||
{
|
||||
LOG(Error, "Failed to load C# assembly '{0}' for binary module {1}.", managedPath, name);
|
||||
@@ -528,6 +529,7 @@ bool Scripting::Load()
|
||||
#if USE_CSHARP
|
||||
// Load C# core assembly
|
||||
ManagedBinaryModule* corlib = GetBinaryModuleCorlib();
|
||||
corlib->CanReload = false;
|
||||
if (corlib->Assembly->LoadCorlib())
|
||||
{
|
||||
LOG(Error, "Failed to load corlib C# assembly.");
|
||||
@@ -581,6 +583,8 @@ bool Scripting::Load()
|
||||
LOG(Error, "Failed to load FlaxEngine C# assembly.");
|
||||
return true;
|
||||
}
|
||||
flaxEngineModule->CanReload = false;
|
||||
flaxEngineModule->Assembly->_canReload = false;
|
||||
onEngineLoaded(flaxEngineModule->Assembly);
|
||||
|
||||
// Insert type aliases for vector types that don't exist in C++ but are just typedef (properly redirect them to actual types)
|
||||
|
||||
Reference in New Issue
Block a user