Skip to content

Commit

Permalink
Merge pull request #425 from bid-soft/dev
Browse files Browse the repository at this point in the history
RenderManager: parse dependencies of subtype
  • Loading branch information
MSchmoecker authored Mar 28, 2024
2 parents 8dd2357 + 4ecd3d4 commit 4a3f1f0
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions JotunnLib/Managers/RenderManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,15 @@ private static List<Type> GetTopolocialSort(Transform tranform)
private static bool TopologicalSortUtil(Type node, HashSet<Type> visited, HashSet<Type> recursionStack, List<Type> result)
{
// Type already processed
if (visited.Contains(node) || visited.Any(node.IsSubclassOf))
if (visited.Contains(node)) return true;
List<Type> tailList = null;

//check if supertype is already in list, split list to insert dependencies of sub type before super type
int splitIndex = result.FindIndex(node.IsSubclassOf);
if (splitIndex != -1)
{
return true;
tailList = result.Skip(splitIndex).ToList();
result.RemoveRange(splitIndex, result.Count - splitIndex);
}

// Cycle detected
Expand All @@ -487,9 +493,12 @@ private static bool TopologicalSortUtil(Type node, HashSet<Type> visited, HashSe
}
}

// if super type was in list, concat tail of list back without adding subtype to result
if (tailList != null) result.AddRange(tailList);
else result.Add(node);

recursionStack.Remove(node);
visited.Add(node);
result.Add(node);
visited.Add(node);

return true;
}
Expand Down

0 comments on commit 4a3f1f0

Please sign in to comment.