Skip to content

Commit

Permalink
Various performance improvements and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pak762 committed Feb 28, 2023
1 parent 6aca95a commit 99e1ee3
Show file tree
Hide file tree
Showing 12 changed files with 342 additions and 228 deletions.
301 changes: 149 additions & 152 deletions AssetRelationsViewer/Editor/AssetRelationsViewerWindow.cs

Large diffs are not rendered by default.

56 changes: 56 additions & 0 deletions AssetRelationsViewer/Editor/NodeSizeThread.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Collections.Generic;
using System.Threading;
using Com.Innogames.Core.Frontend.NodeDependencyLookup;

namespace Com.Innogames.Core.Frontend.AssetRelationsViewer
{
/// <summary>
/// Thread to calculate the hierarchy size of nodes in the background
/// </summary>
public class NodeSizeThread
{
private readonly Stack<VisualizationNodeData> _stack = new Stack<VisualizationNodeData>();
private readonly HashSet<string> _traversedNodes = new HashSet<string>();
private Thread _thread;
private NodeDependencyLookupContext _context;

public NodeSizeThread(NodeDependencyLookupContext context)
{
_context = context;
}

public void Start()
{
_thread = new Thread(ThreadProc);
_thread.Name = "HierarchySizeThread";
_thread.Start();
}

public void Kill()
{
_thread?.Abort();
_stack.Clear();
}

public void EnqueueNodeData(VisualizationNodeData nodeData)
{
_stack.Push(nodeData);
}

private void ThreadProc()
{
HashSet<Node> flattedHierarchy = new HashSet<Node>();

while(true)
{
while (_stack.Count > 0)
{
VisualizationNodeData visualizationNodeData = _stack.Pop();
visualizationNodeData.HierarchySize = NodeDependencyLookupUtility.GetTreeSize(visualizationNodeData.Node, _context, flattedHierarchy);
}

Thread.Sleep(5);
}
}
}
}
3 changes: 3 additions & 0 deletions AssetRelationsViewer/Editor/NodeSizeThread.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public class PathVisualizationNode : VisualizationNodeBase
public PathNode PathNode;
public HashSet<PathNode> TargetNodes = new HashSet<PathNode>();

public override string GetSortingKey(RelationType relationType)
public override string GetSortingKey(RelationType relationType, bool sortBySize)
{
string sortingKey = GetRelationArray(relationType)[0].VNode.GetSortingKey(relationType);
string sortingKey = GetRelationArray(relationType)[0].VNode.GetSortingKey(relationType, sortBySize);
return sortingKey;
}

Expand All @@ -39,6 +39,16 @@ public override void CalculateCachedDataInternal()
PathNode.CalculatePositionData(0, 0, TargetNodes);
}

public override bool HasNoneFilteredChildren(RelationType relationType)
{
return GetRelationArray(relationType)[0].VNode.HasNoneFilteredChildren(relationType);
}

public override bool IsFiltered(RelationType relationType)
{
return GetRelationArray(relationType)[0].VNode.IsFiltered(relationType);
}

private void DrawPathNodeConnections(PathNode rootNode, HashSet<PathNode> targetNodes, INodeDisplayDataProvider colorProvider, float yOffset)
{
foreach (PathNode tn in targetNodes)
Expand All @@ -65,22 +75,22 @@ private int GetPathNodeCount()
}
}
}

return pathCount;
}

private void GeneratePathNodeTree()
{
PathNode = new PathNode(string.Empty, PathSegmentType.GameObject, "Root");

foreach (VisualizationConnection connection in GetRelations(RelationType.DEPENDENCY, true, true))
{
foreach (VisualizationConnection.Data data in connection.Datas)
{
PathNode.AddPath(PathNode, data.PathSegments.Reverse().ToArray(), data.Type);
}
}

PathNode.CalculateNodeHeight(PathNode);
}
}
Expand Down
49 changes: 35 additions & 14 deletions AssetRelationsViewer/Editor/VisualizationNode/VisualizationNode.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.IO;
using Com.Innogames.Core.Frontend.NodeDependencyLookup;
using UnityEditor;
using UnityEngine;
using UnityEngine.Profiling;

namespace Com.Innogames.Core.Frontend.AssetRelationsViewer
{
Expand All @@ -12,36 +12,45 @@ public class VisualizationNode : VisualizationNodeBase
public string Key;
public int Hash;

public bool HasNonFilteredChildren = false;
public bool Filtered;

public void SetKey(string value)
{
Key = value;
Hash = value.GetHashCode();
}

public override string GetSortingKey(RelationType relationType)
public override string GetSortingKey(RelationType relationType, bool sortBySize)
{
if (sortBySize)
{
return NodeData.Node.OwnSize.Size.ToString("000000000000000000000");
}

return NodeData.GetSortingKey();
}

public override EnclosedBounds GetBoundsOwn(NodeDisplayData displayData)
{
float height = displayData.AssetPreviewSize;

if (displayData.ShowAdditionalInformation)
{
height = Math.Max(48, height);
}

float width = displayData.AssetPreviewSize + displayData.NodeWidth;
height = displayData.NodeSpaceY + Math.Max(height, PathNode.NodeHeight);
return new EnclosedBounds(0, 0, (int)width, (int)height);
}

public override void Draw(int depth, RelationType relationType, INodeDisplayDataProvider displayDataProvider,
public override void Draw(int depth, RelationType relationType, INodeDisplayDataProvider displayDataProvider,
ISelectionChanger selectionChanger, NodeDisplayData displayData, ViewAreaData viewAreaData)
{
Profiler.BeginSample("VisualizationNode::Draw()");
Vector2 position = GetPosition(viewAreaData);

Color rectColor = (depth == 0) ? ARVStyles.NodeBackGroundColorOwn : ARVStyles.NodeBackGroundColor;

bool isMissing = NodeData.IsMissing;
Expand All @@ -68,13 +77,13 @@ public override void Draw(int depth, RelationType relationType, INodeDisplayData

GUIStyle style = new GUIStyle();
Color textColor = Color.white;

if (depth > 0)
{
string typeId = GetRelations(NodeDependencyLookupUtility.InvertRelationType(relationType))[0].Datas[0].Type;
textColor = displayDataProvider.GetConnectionColorForType(typeId);
}

textColor *= ARVStyles.TextColorMod;

style.normal.textColor = textColor;
Expand Down Expand Up @@ -109,7 +118,7 @@ public override void Draw(int depth, RelationType relationType, INodeDisplayData
{
float x = relationType == RelationType.DEPENDENCY ? Bounds.Rect.xMax : Bounds.Rect.xMin - 16;
string cutTooltip = "Connections hidden due to reasons:";

foreach (CutData.Entry entry in cutData.Entries)
{
cutTooltip += $"\n{entry.CutReason} : {entry.Count}";
Expand All @@ -121,7 +130,7 @@ public override void Draw(int depth, RelationType relationType, INodeDisplayData
}

DrawIsFilteredOverlay(position, displayData);

if (GUI.Button(new Rect(position.x + displayData.NodeWidth + assetPreviewSize - 16, position.y, 16, 16), ">"))
{
selectionChanger.ChangeSelection(NodeData.Node.Id, NodeData.Node.Type);
Expand All @@ -131,6 +140,18 @@ public override void Draw(int depth, RelationType relationType, INodeDisplayData
{
NodeData.TypeHandler.SelectInEditor(NodeData.Node.Id);
}

Profiler.EndSample();
}

public override bool HasNoneFilteredChildren(RelationType relationType)
{
return HasNonFilteredChildren;
}

public override bool IsFiltered(RelationType relationType)
{
return Filtered;
}

private string GetNameFromFullName(string fullName)
Expand All @@ -145,17 +166,17 @@ private string GetNameFromFullName(string fullName)
return fullName;
}

public void DrawIsFilteredOverlay(Vector2 position, NodeDisplayData displayData)
private void DrawIsFilteredOverlay(Vector2 position, NodeDisplayData displayData)
{
if (IsFiltered)
if (Filtered)
{
Rect b = GetBoundsOwn(displayData).Rect;
Rect rect = new Rect(b.x + position.x, b.y + position.y, b.width, b.height);

EditorGUI.DrawRect(rect, ARVStyles.NodeFilteredOverlayColor);
}
}

/// <summary>
/// Draws the preview texture for the asset. Tries to use the actual Previewtexture but uses the Thumbnail if no preview could be rendered
/// </summary>
Expand Down
Loading

0 comments on commit 99e1ee3

Please sign in to comment.