Merge remote-tracking branch 'origin/master' into 1.6

# Conflicts:
#	Source/Editor/Scripting/CodeEditors/VisualStudioCodeEditor.cpp
#	Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs
This commit is contained in:
Wojtek Figat
2023-04-22 18:59:41 +02:00
51 changed files with 1397 additions and 673 deletions

View File

@@ -37,6 +37,7 @@ namespace FlaxEditor.Viewport.Previews
private readonly object _locker = new object();
private AudioClip _asset;
private int _pcmSequence = 0;
private float[] _pcmData;
private AudioDataInfo _pcmInfo;
@@ -79,6 +80,20 @@ namespace FlaxEditor.Viewport.Previews
}
}
/// <summary>
/// Gets the cached audio data info.
/// </summary>
public AudioDataInfo DataInfo
{
get
{
lock (_locker)
{
return _pcmInfo;
}
}
}
/// <summary>
/// The draw mode.
/// </summary>
@@ -104,6 +119,28 @@ namespace FlaxEditor.Viewport.Previews
/// </summary>
public static readonly float UnitsPerSecond = 100.0f;
/// <summary>
/// Invalidates the cached audio PCM data and fetches it again from the asset.
/// </summary>
public void RefreshPreview()
{
lock (_locker)
{
if (_asset != null)
{
// Release any cached data
_pcmData = null;
// Invalidate any in-flight data download to reject cached data due to refresh
if (_pcmSequence != 0)
_pcmSequence++;
// Use async task to gather PCM data (engine loads it from the asset)
Task.Run(DownloadData);
}
}
}
/// <inheritdoc />
public override void Draw()
{
@@ -220,7 +257,13 @@ namespace FlaxEditor.Viewport.Previews
/// </summary>
private void DownloadData()
{
var asset = _asset;
AudioClip asset;
int sequence;
lock (_locker)
{
asset = _asset;
sequence = _pcmSequence;
}
if (!asset)
return;
@@ -245,8 +288,9 @@ namespace FlaxEditor.Viewport.Previews
lock (_locker)
{
// If asset has been modified during data fetching, ignore it
if (_asset == asset)
if (_asset == asset && _pcmSequence == sequence)
{
_pcmSequence++;
_pcmData = data;
_pcmInfo = dataInfo;
}