mirror of
https://github.com/godotengine/godot.git
synced 2024-11-27 09:16:35 +08:00
Merge pull request #44107 from neikeq/fix-slow-build-log-update
C#: Fix very slow build log update in the editor
This commit is contained in:
commit
af61ad5e36
@ -2,6 +2,7 @@ using Godot;
|
||||
using System;
|
||||
using Godot.Collections;
|
||||
using GodotTools.Internals;
|
||||
using JetBrains.Annotations;
|
||||
using File = GodotTools.Utils.File;
|
||||
using Path = System.IO.Path;
|
||||
|
||||
@ -26,6 +27,9 @@ namespace GodotTools.Build
|
||||
private TextEdit buildLog;
|
||||
private PopupMenu issuesListContextMenu;
|
||||
|
||||
private readonly object pendingBuildLogTextLock = new object();
|
||||
[NotNull] private string pendingBuildLogText = string.Empty;
|
||||
|
||||
[Signal] public event Action BuildStateChanged;
|
||||
|
||||
public bool HasBuildExited { get; private set; } = false;
|
||||
@ -240,16 +244,34 @@ namespace GodotTools.Build
|
||||
EmitSignal(nameof(BuildStateChanged));
|
||||
}
|
||||
|
||||
private void UpdateBuildLogText()
|
||||
{
|
||||
lock (pendingBuildLogTextLock)
|
||||
{
|
||||
buildLog.Text += pendingBuildLogText;
|
||||
pendingBuildLogText = string.Empty;
|
||||
ScrollToLastNonEmptyLogLine();
|
||||
}
|
||||
}
|
||||
|
||||
private void StdOutputReceived(string text)
|
||||
{
|
||||
buildLog.Text += text + "\n";
|
||||
ScrollToLastNonEmptyLogLine();
|
||||
lock (pendingBuildLogTextLock)
|
||||
{
|
||||
if (pendingBuildLogText.Length == 0)
|
||||
CallDeferred(nameof(UpdateBuildLogText));
|
||||
pendingBuildLogText += text + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
private void StdErrorReceived(string text)
|
||||
{
|
||||
buildLog.Text += text + "\n";
|
||||
ScrollToLastNonEmptyLogLine();
|
||||
lock (pendingBuildLogTextLock)
|
||||
{
|
||||
if (pendingBuildLogText.Length == 0)
|
||||
CallDeferred(nameof(UpdateBuildLogText));
|
||||
pendingBuildLogText += text + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
private void ScrollToLastNonEmptyLogLine()
|
||||
@ -377,12 +399,14 @@ namespace GodotTools.Build
|
||||
BuildManager.BuildStarted += BuildStarted;
|
||||
BuildManager.BuildFinished += BuildFinished;
|
||||
// StdOutput/Error can be received from different threads, so we need to use CallDeferred
|
||||
BuildManager.StdOutputReceived += line => CallDeferred(nameof(StdOutputReceived), line);
|
||||
BuildManager.StdErrorReceived += line => CallDeferred(nameof(StdErrorReceived), line);
|
||||
BuildManager.StdOutputReceived += StdOutputReceived;
|
||||
BuildManager.StdErrorReceived += StdErrorReceived;
|
||||
}
|
||||
|
||||
public void OnBeforeSerialize()
|
||||
{
|
||||
// In case it didn't update yet. We don't want to have to serialize any pending output.
|
||||
UpdateBuildLogText();
|
||||
}
|
||||
|
||||
public void OnAfterDeserialize()
|
||||
|
Loading…
Reference in New Issue
Block a user