Automatic script assembly reloading

This commit is contained in:
Simon Lübeß
2023-07-20 22:11:11 +02:00
parent 0cbb8a4966
commit 5f27b8001a
4 changed files with 73 additions and 197 deletions
+34 -1
View File
@@ -5,6 +5,8 @@ using GlitchyEngine.Renderer;
using GlitchyEngine.Debug;
using GlitchyEngine.Content;
using GlitchyEngine.Scripting;
using System.Collections;
using System.Threading;
namespace GlitchyEngine
{
@@ -28,6 +30,9 @@ namespace GlitchyEngine
private IContentManager _contentManager;
private append List<delegate void()> _jobQueue = .() ~ ClearAndDeleteItems!(_);
private append Monitor _jobQueueMutex = .();
public bool IsRunning => _running;
public Window Window => _window;
@@ -37,9 +42,11 @@ namespace GlitchyEngine
public GameTime GameTime => _gameTime;
[Inline]
[Inline, Obsolete("Use Application.Instance instead.", false)]
public static Application Get() => s_Instance;
public static Application Instance => s_Instance;
public Settings Settings {get; private set;} = new .() ~ delete _;
public this()
@@ -157,6 +164,8 @@ namespace GlitchyEngine
}
#endif
RunJobs();
if(allowFrame && !_isMinimized)
{
Debug.Profiler.ProfileScope!("Update Layers");
@@ -218,5 +227,29 @@ namespace GlitchyEngine
return false;
}
/// Executes the given Job on the main thread. Takes ownership of the delegate.
public void InvokeOnMainThread(delegate void() ownJob)
{
using (_jobQueueMutex.Enter())
{
_jobQueue.Add(ownJob);
}
}
private void RunJobs()
{
Debug.Profiler.ProfileFunction!();
using (_jobQueueMutex.Enter())
{
for (let job in _jobQueue)
{
job();
}
ClearAndDeleteItems!(_jobQueue);
}
}
}
}