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

This commit is contained in:
Wojtek Figat
2023-05-10 12:13:45 +02:00
12 changed files with 105 additions and 58 deletions

View File

@@ -1,8 +1,6 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. // Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using System; using System;
using System.IO;
using System.Text;
using FlaxEngine; using FlaxEngine;
using FlaxEngine.GUI; using FlaxEngine.GUI;
@@ -38,14 +36,6 @@ namespace FlaxEditor.Content
ID = id; ID = id;
} }
/// <inheritdoc />
public override void UpdateTooltipText()
{
var sb = new StringBuilder();
OnBuildTooltipText(sb);
TooltipText = sb.ToString();
}
private sealed class TooltipDoubleClickHook : Control private sealed class TooltipDoubleClickHook : Control
{ {
public AssetItem Item; public AssetItem Item;
@@ -74,20 +64,25 @@ namespace FlaxEditor.Content
hook.Item = this; hook.Item = this;
} }
/// <summary>
/// Called when building tooltip text.
/// </summary>
/// <param name="sb">The String Builder.</param>
protected virtual void OnBuildTooltipText(StringBuilder sb)
{
sb.Append("Type: ").Append(TypeName).AppendLine();
sb.Append("Size: ").Append(Utilities.Utils.FormatBytesCount((int)new FileInfo(Path).Length)).AppendLine();
sb.Append("Path: ").Append(Path).AppendLine();
}
/// <inheritdoc /> /// <inheritdoc />
public override ContentItemType ItemType => ContentItemType.Asset; public override ContentItemType ItemType => ContentItemType.Asset;
/// <inheritdoc />
public override string TypeDescription
{
get
{
// Translate asset type name
var typeName = TypeName;
string[] typeNamespaces = typeName.Split('.');
if (typeNamespaces.Length != 0 && typeNamespaces.Length != 0)
{
typeName = Utilities.Utils.GetPropertyNameUI(typeNamespaces[typeNamespaces.Length - 1]);
}
return typeName;
}
}
/// <summary> /// <summary>
/// Loads the asset. /// Loads the asset.
/// </summary> /// </summary>

View File

@@ -19,6 +19,9 @@ namespace FlaxEditor.Content
{ {
} }
/// <inheritdoc />
public override string TypeDescription => "C# Source Code";
/// <inheritdoc /> /// <inheritdoc />
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.CSharpScript128; public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.CSharpScript128;
} }

View File

@@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text;
using FlaxEditor.GUI.Drag; using FlaxEditor.GUI.Drag;
using FlaxEngine; using FlaxEngine;
using FlaxEngine.GUI; using FlaxEngine.GUI;
@@ -120,6 +121,9 @@ namespace FlaxEditor.Content
/// <inheritdoc /> /// <inheritdoc />
public override bool Exists => Directory.Exists(Path); public override bool Exists => Directory.Exists(Path);
/// <inheritdoc />
public override string TypeDescription => "Folder";
/// <inheritdoc /> /// <inheritdoc />
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Folder128; public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Folder128;
@@ -135,9 +139,10 @@ namespace FlaxEditor.Content
} }
/// <inheritdoc /> /// <inheritdoc />
public override void UpdateTooltipText() protected override void OnBuildTooltipText(StringBuilder sb)
{ {
TooltipText = Path; sb.Append("Type: ").Append(TypeDescription).AppendLine();
sb.Append("Path: ").Append(Utilities.Utils.GetAssetNamePathWithExt(Path)).AppendLine();
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@@ -2,6 +2,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Text;
using FlaxEditor.Content.GUI; using FlaxEditor.Content.GUI;
using FlaxEditor.GUI.Drag; using FlaxEditor.GUI.Drag;
using FlaxEngine; using FlaxEngine;
@@ -273,6 +275,11 @@ namespace FlaxEditor.Content
/// </summary> /// </summary>
public string NamePath => FlaxEditor.Utilities.Utils.GetAssetNamePath(Path); public string NamePath => FlaxEditor.Utilities.Utils.GetAssetNamePath(Path);
/// <summary>
/// Gets the content item type description (for UI).
/// </summary>
public abstract string TypeDescription { get; }
/// <summary> /// <summary>
/// Gets the default name of the content item thumbnail. Returns null if not used. /// Gets the default name of the content item thumbnail. Returns null if not used.
/// </summary> /// </summary>
@@ -353,11 +360,32 @@ namespace FlaxEditor.Content
} }
/// <summary> /// <summary>
/// Updates the tooltip text text. /// Updates the tooltip text.
/// </summary> /// </summary>
public virtual void UpdateTooltipText() public virtual void UpdateTooltipText()
{ {
TooltipText = "Path: " + Path; var sb = new StringBuilder();
OnBuildTooltipText(sb);
if (sb.Length != 0 && sb[sb.Length - 1] == '\n')
{
// Remove new-line from end
int sub = 1;
if (sb.Length != 1 && sb[sb.Length - 2] == '\r')
sub = 2;
sb.Length -= sub;
}
TooltipText = sb.ToString();
}
/// <summary>
/// Called when building tooltip text.
/// </summary>
/// <param name="sb">The output string builder.</param>
protected virtual void OnBuildTooltipText(StringBuilder sb)
{
sb.Append("Type: ").Append(TypeDescription).AppendLine();
sb.Append("Size: ").Append(Utilities.Utils.FormatBytesCount((int)new FileInfo(Path).Length)).AppendLine();
sb.Append("Path: ").Append(Utilities.Utils.GetAssetNamePathWithExt(Path)).AppendLine();
} }
/// <summary> /// <summary>

View File

@@ -19,6 +19,9 @@ namespace FlaxEditor.Content
{ {
} }
/// <inheritdoc />
public override string TypeDescription => Path.EndsWith(".h") ? "C++ Header File" : "C++ Source Code";
/// <inheritdoc /> /// <inheritdoc />
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.CPPScript128; public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.CPPScript128;
} }

View File

@@ -25,6 +25,9 @@ namespace FlaxEditor.Content
/// <inheritdoc /> /// <inheritdoc />
public override ContentItemSearchFilter SearchFilter => ContentItemSearchFilter.Other; public override ContentItemSearchFilter SearchFilter => ContentItemSearchFilter.Other;
/// <inheritdoc />
public override string TypeDescription => "File";
/// <inheritdoc /> /// <inheritdoc />
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Document128; public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Document128;
} }

View File

@@ -39,6 +39,9 @@ namespace FlaxEditor.Content
/// <inheritdoc /> /// <inheritdoc />
public override ContentItemSearchFilter SearchFilter => ContentItemSearchFilter.Other; public override ContentItemSearchFilter SearchFilter => ContentItemSearchFilter.Other;
/// <inheritdoc />
public override string TypeDescription => "New";
/// <inheritdoc /> /// <inheritdoc />
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Document128; public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Document128;

View File

@@ -27,6 +27,9 @@ namespace FlaxEditor.Content
/// <inheritdoc /> /// <inheritdoc />
public override ContentItemSearchFilter SearchFilter => ContentItemSearchFilter.Scene; public override ContentItemSearchFilter SearchFilter => ContentItemSearchFilter.Scene;
/// <inheritdoc />
public override string TypeDescription => "Scene";
/// <inheritdoc /> /// <inheritdoc />
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Scene128; public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Scene128;

View File

@@ -26,6 +26,9 @@ namespace FlaxEditor.Content
/// <inheritdoc /> /// <inheritdoc />
public override ContentItemSearchFilter SearchFilter => ContentItemSearchFilter.Shader; public override ContentItemSearchFilter SearchFilter => ContentItemSearchFilter.Shader;
/// <inheritdoc />
public override string TypeDescription => "Shader Source Code";
/// <inheritdoc /> /// <inheritdoc />
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Document128; public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Document128;
} }

View File

@@ -1081,7 +1081,7 @@ namespace FlaxEditor.Utilities
} }
/// <summary> /// <summary>
/// Updates (recursivly) search popup tree structures based on the filter text. /// Updates (recursively) search popup tree structures based on the filter text.
/// </summary> /// </summary>
public static void UpdateSearchPopupFilter(TreeNode node, string filterText) public static void UpdateSearchPopupFilter(TreeNode node, string filterText)
{ {
@@ -1107,6 +1107,19 @@ namespace FlaxEditor.Utilities
node.Visible = isThisVisible | isAnyChildVisible; node.Visible = isThisVisible | isAnyChildVisible;
} }
/// <summary>
/// Gets the asset name relative to the project root folder (with asset file extension)
/// </summary>
/// <param name="path">The asset path.</param>
/// <returns>The processed name path.</returns>
public static string GetAssetNamePathWithExt(string path)
{
var projectFolder = Globals.ProjectFolder;
if (path.StartsWith(projectFolder))
path = path.Substring(projectFolder.Length + 1);
return path;
}
/// <summary> /// <summary>
/// Gets the asset name relative to the project root folder (without asset file extension) /// Gets the asset name relative to the project root folder (without asset file extension)
/// </summary> /// </summary>
@@ -1114,9 +1127,7 @@ namespace FlaxEditor.Utilities
/// <returns>The processed name path.</returns> /// <returns>The processed name path.</returns>
public static string GetAssetNamePath(string path) public static string GetAssetNamePath(string path)
{ {
var projectFolder = Globals.ProjectFolder; path = GetAssetNamePathWithExt(path);
if (path.StartsWith(projectFolder))
path = path.Substring(projectFolder.Length + 1);
return StringUtils.GetPathWithoutExtension(path); return StringUtils.GetPathWithoutExtension(path);
} }

View File

@@ -8,6 +8,7 @@ using FlaxEngine;
using FlaxEngine.Json; using FlaxEngine.Json;
using FlaxEngine.GUI; using FlaxEngine.GUI;
using FlaxEditor.GUI.ContextMenu; using FlaxEditor.GUI.ContextMenu;
using System.Linq;
namespace FlaxEditor.Windows.Profiler namespace FlaxEditor.Windows.Profiler
{ {
@@ -17,7 +18,7 @@ namespace FlaxEditor.Windows.Profiler
/// <seealso cref="FlaxEditor.Windows.Profiler.ProfilerMode" /> /// <seealso cref="FlaxEditor.Windows.Profiler.ProfilerMode" />
internal sealed class Assets : ProfilerMode internal sealed class Assets : ProfilerMode
{ {
private struct Resource private class Resource
{ {
public string Name; public string Name;
public string TypeName; public string TypeName;
@@ -120,19 +121,18 @@ namespace FlaxEditor.Windows.Profiler
// Capture current assets usage info // Capture current assets usage info
var assets = FlaxEngine.Content.Assets; var assets = FlaxEngine.Content.Assets;
var sb = _stringBuilder;
var resources = new Resource[assets.Length]; var resources = new Resource[assets.Length];
var contentDatabase = Editor.Instance.ContentDatabase;
ulong totalMemoryUsage = 0; ulong totalMemoryUsage = 0;
for (int i = 0; i < resources.Length; i++) for (int i = 0; i < resources.Length; i++)
{ {
var asset = assets[i]; var asset = assets[i];
ref var resource = ref resources[i];
if (!asset) if (!asset)
continue; continue;
// Try to reuse cached resource info // Try to reuse cached resource info
var assetId = asset.ID; var assetId = asset.ID;
if (!_resourceCache.TryGetValue(assetId, out var resource)) if (!_resourceCache.TryGetValue(assetId, out resource))
{ {
resource = new Resource resource = new Resource
{ {
@@ -154,12 +154,10 @@ namespace FlaxEditor.Windows.Profiler
} }
resource.MemoryUsage = asset.MemoryUsage; resource.MemoryUsage = asset.MemoryUsage;
totalMemoryUsage += resource.MemoryUsage;
resource.ReferencesCount = asset.ReferencesCount; resource.ReferencesCount = asset.ReferencesCount;
resources[i] = resource; totalMemoryUsage += resource.MemoryUsage;
} }
_memoryUsageChart.AddSample((float)totalMemoryUsage); _memoryUsageChart.AddSample((float)totalMemoryUsage);
Array.Sort(resources, SortResources);
if (_resources == null) if (_resources == null)
_resources = new SamplesBuffer<Resource[]>(); _resources = new SamplesBuffer<Resource[]>();
_resources.Add(resources); _resources.Add(resources);
@@ -188,11 +186,6 @@ namespace FlaxEditor.Windows.Profiler
base.OnDestroy(); base.OnDestroy();
} }
private static int SortResources(Resource a, Resource b)
{
return (int)(b.MemoryUsage - a.MemoryUsage);
}
private void UpdateTable() private void UpdateTable()
{ {
_table.IsLayoutLocked = true; _table.IsLayoutLocked = true;
@@ -225,13 +218,13 @@ namespace FlaxEditor.Windows.Profiler
var resources = _resources.Get(_memoryUsageChart.SelectedSampleIndex); var resources = _resources.Get(_memoryUsageChart.SelectedSampleIndex);
if (resources == null || resources.Length == 0) if (resources == null || resources.Length == 0)
return; return;
var resourcesOrdered = resources.OrderByDescending(x => x.MemoryUsage);
// Add rows // Add rows
var rowColor2 = Style.Current.Background * 1.4f; var rowColor2 = Style.Current.Background * 1.4f;
for (int i = 0; i < resources.Length; i++) int rowIndex = 0;
foreach (var e in resourcesOrdered)
{ {
ref var e = ref resources[i];
ClickableRow row; ClickableRow row;
if (_tableRowsCache.Count != 0) if (_tableRowsCache.Count != 0)
{ {
@@ -257,8 +250,9 @@ namespace FlaxEditor.Windows.Profiler
// Add row to the table // Add row to the table
row.Width = _table.Width; row.Width = _table.Width;
row.BackgroundColor = i % 2 == 0 ? rowColor2 : Color.Transparent; row.BackgroundColor = rowIndex % 2 == 0 ? rowColor2 : Color.Transparent;
row.Parent = _table; row.Parent = _table;
rowIndex++;
} }
} }

View File

@@ -2,6 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text; using System.Text;
using FlaxEditor.GUI; using FlaxEditor.GUI;
using FlaxEngine; using FlaxEngine;
@@ -15,7 +16,7 @@ namespace FlaxEditor.Windows.Profiler
/// <seealso cref="FlaxEditor.Windows.Profiler.ProfilerMode" /> /// <seealso cref="FlaxEditor.Windows.Profiler.ProfilerMode" />
internal sealed class MemoryGPU : ProfilerMode internal sealed class MemoryGPU : ProfilerMode
{ {
private struct Resource private class Resource
{ {
public string Name; public string Name;
public string Tooltip; public string Tooltip;
@@ -126,10 +127,11 @@ namespace FlaxEditor.Windows.Profiler
for (int i = 0; i < resources.Length; i++) for (int i = 0; i < resources.Length; i++)
{ {
var gpuResource = gpuResources[i]; var gpuResource = gpuResources[i];
ref var resource = ref resources[i];
// Try to reuse cached resource info // Try to reuse cached resource info
var gpuResourceId = gpuResource.ID; var gpuResourceId = gpuResource.ID;
if (!_resourceCache.TryGetValue(gpuResourceId, out var resource)) if (!_resourceCache.TryGetValue(gpuResourceId, out resource))
{ {
resource = new Resource resource = new Resource
{ {
@@ -194,9 +196,7 @@ namespace FlaxEditor.Windows.Profiler
resource.MemoryUsage = gpuResource.MemoryUsage; resource.MemoryUsage = gpuResource.MemoryUsage;
if (resource.MemoryUsage == 1) if (resource.MemoryUsage == 1)
resource.MemoryUsage = 0; // Sometimes GPU backend fakes memory usage as 1 to mark as allocated but not resided in actual GPU memory resource.MemoryUsage = 0; // Sometimes GPU backend fakes memory usage as 1 to mark as allocated but not resided in actual GPU memory
resources[i] = resource;
} }
Array.Sort(resources, SortResources);
if (_resources == null) if (_resources == null)
_resources = new SamplesBuffer<Resource[]>(); _resources = new SamplesBuffer<Resource[]>();
_resources.Add(resources); _resources.Add(resources);
@@ -240,11 +240,6 @@ namespace FlaxEditor.Windows.Profiler
base.OnDestroy(); base.OnDestroy();
} }
private static int SortResources(Resource a, Resource b)
{
return (int)(b.MemoryUsage - a.MemoryUsage);
}
private void UpdateTable() private void UpdateTable()
{ {
_table.IsLayoutLocked = true; _table.IsLayoutLocked = true;
@@ -277,13 +272,13 @@ namespace FlaxEditor.Windows.Profiler
var resources = _resources.Get(_memoryUsageChart.SelectedSampleIndex); var resources = _resources.Get(_memoryUsageChart.SelectedSampleIndex);
if (resources == null || resources.Length == 0) if (resources == null || resources.Length == 0)
return; return;
var resourcesOrdered = resources.OrderByDescending(x => x.MemoryUsage);
// Add rows // Add rows
var rowColor2 = Style.Current.Background * 1.4f; var rowColor2 = Style.Current.Background * 1.4f;
for (int i = 0; i < resources.Length; i++) int rowIndex = 0;
foreach (var e in resourcesOrdered)
{ {
ref var e = ref resources[i];
ClickableRow row; ClickableRow row;
if (_tableRowsCache.Count != 0) if (_tableRowsCache.Count != 0)
{ {
@@ -314,8 +309,9 @@ namespace FlaxEditor.Windows.Profiler
// Add row to the table // Add row to the table
row.Width = _table.Width; row.Width = _table.Width;
row.BackgroundColor = i % 2 == 0 ? rowColor2 : Color.Transparent; row.BackgroundColor = rowIndex % 2 == 0 ? rowColor2 : Color.Transparent;
row.Parent = _table; row.Parent = _table;
rowIndex++;
} }
} }