Skip to content

Commit

Permalink
Optimization of assembly reloading after build
Browse files Browse the repository at this point in the history
  • Loading branch information
Hilderin committed Jan 21, 2024
1 parent 0bcc0e9 commit fc48e91
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -295,6 +296,8 @@ internal static void SetGodotObjectPtr(IntPtr gcHandlePtr, IntPtr newPtr)
return wrapperType;
}

private static ConcurrentDictionary<string, DateTime> _cacheLastWriteTimeCSharpScripts = new ConcurrentDictionary<string, DateTime>();

// Called from GodotPlugins
// ReSharper disable once UnusedMember.Local
public static void LookupScriptsInAssembly(Assembly assembly)
Expand All @@ -310,11 +313,20 @@ static void LookupScriptForClass(Type type)

_pathTypeBiMap.Add(scriptPathAttr.Path, type);


// This method may be called before initialization.
if (NativeFuncs.godotsharp_dotnet_module_is_initialized().ToBool() && Engine.IsEditorHint())
{
using godot_string scriptPath = Marshaling.ConvertStringToNative(scriptPathAttr.Path);
NativeFuncs.godotsharp_internal_editor_file_system_update_file(scriptPath);
DateTime lastWriteTime = DateTime.MinValue;
if (File.Exists(scriptPathAttr.Path))
lastWriteTime = File.GetLastWriteTime(scriptPathAttr.Path);

if (!_cacheLastWriteTimeCSharpScripts.TryGetValue(scriptPathAttr.Path, out var oldLastWriteTime) || oldLastWriteTime != lastWriteTime)
{
using godot_string scriptPath = Marshaling.ConvertStringToNative(scriptPathAttr.Path);
NativeFuncs.godotsharp_internal_editor_file_system_update_file(scriptPath);
_cacheLastWriteTimeCSharpScripts[scriptPathAttr.Path] = lastWriteTime;
}
}

if (AlcReloadCfg.IsAlcReloadingEnabled)
Expand Down

0 comments on commit fc48e91

Please sign in to comment.