Skip to content

Commit

Permalink
Remove IsExisting info from nodes and rather get rid of removed file…
Browse files Browse the repository at this point in the history
…s in the asset and file caches themself
  • Loading branch information
pak762 committed Nov 16, 2022
1 parent 2efe354 commit 2e2bd7f
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ public void AddExistingNodes(List<IDependencyMappingNode> nodes)
{
foreach (AssetNode assetNode in fileToAssetNode.AssetNodes)
{
if (assetNode.Existing)
{
nodes.Add(assetNode);
}
nodes.Add(assetNode);
}
}
}
Expand Down Expand Up @@ -172,11 +169,7 @@ private bool CheckNeedsUpdateForResolver(IAssetDependencyResolver resolver, stri
if (list.ContainsKey(guid))
{
FileToAssetNode fileToAssetNode = list[guid];
foreach (AssetNode assetNode in fileToAssetNode.AssetNodes)
{
assetNode.Existing = true;
}


if (fileToAssetNode.GetResolverTimeStamp(id).TimeStamp != timestamps[i])
{
return true;
Expand Down Expand Up @@ -227,7 +220,8 @@ private HashSet<string> GetChangedAssetIdsForResolver(IAssetDependencyResolver r
FileToAssetNode fileToAssetNode = list[guid];
foreach (AssetNode assetNode in fileToAssetNode.AssetNodes)
{
assetNode.Existing = true;
// TODO
//assetNode.Existing = true;
}

if (fileToAssetNode.GetResolverTimeStamp(id).TimeStamp != timestamps[i])
Expand All @@ -246,13 +240,14 @@ private HashSet<string> GetChangedAssetIdsForResolver(IAssetDependencyResolver r

public void Update()
{
_fileToAssetNodes = GetDependenciesForAssets(_fileToAssetNodes, _createdDependencyCache);
string[] pathes = NodeDependencyLookupUtility.GetAllAssetPathes(true);

NodeDependencyLookupUtility.RemoveNonExistingFilesFromIdentifyableList(pathes, ref _fileToAssetNodes);
GetDependenciesForAssets(pathes, _createdDependencyCache);
}

private FileToAssetNode[] GetDependenciesForAssets(FileToAssetNode[] fileToAssetNodes,
CreatedDependencyCache createdDependencyCache)
private void GetDependenciesForAssets(string[] pathes, CreatedDependencyCache createdDependencyCache)
{
string[] pathes = NodeDependencyLookupUtility.GetAllAssetPathes(false);
long[] timestamps = NodeDependencyLookupUtility.GetTimeStampsForFiles(pathes);

List<AssetResolverData> data = new List<AssetResolverData>();
Expand All @@ -276,14 +271,14 @@ private FileToAssetNode[] GetDependenciesForAssets(FileToAssetNode[] fileToAsset
_hierarchyTraverser.Initialize();
_hierarchyTraverser.Search();

Dictionary<string, FileToAssetNode> nodeDict = RelationLookup.RelationLookupBuilder.ConvertToDictionary(fileToAssetNodes);
Dictionary<string, FileToAssetNode> nodeDict = RelationLookup.RelationLookupBuilder.ConvertToDictionary(_fileToAssetNodes);

foreach (AssetResolverData resolverData in data)
{
GetDependenciesForAssetsInResolver(resolverData.ChangedAssets, resolverData.Resolver as IAssetDependencyResolver, nodeDict);
}

return nodeDict.Values.ToArray();
_fileToAssetNodes = nodeDict.Values.ToArray();
}

private void GetDependenciesForAssetsInResolver(HashSet<string> changedAssets, IAssetDependencyResolver resolver, Dictionary<string, FileToAssetNode> resultList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public AssetNode GetAssetNode(string id)
}
}

AssetNode newAssetNode = new AssetNode(id){Existing = true};
AssetNode newAssetNode = new AssetNode(id);
AssetNodes.Add(newAssetNode);
return newAssetNode;
}
Expand Down Expand Up @@ -65,8 +65,7 @@ public class ResolverData

public string Id{get { return AssetId; }}
public string Type{get { return AssetNodeType.Name; }}
public bool Existing { get; set; }


public List<ResolverData> ResolverDatas = new List<ResolverData>();

public AssetNode(string assetId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private bool GetNeedsUpdate(string[] pathes, long[] timestamps)

return false;
}

private HashSet<string> GetChangedAssetIds(string[] pathes, long[] timestamps, FileToAssetsMapping[] fileToAssetMappings)
{
HashSet<string> result = new HashSet<string>();
Expand Down Expand Up @@ -103,8 +103,6 @@ private HashSet<string> GetChangedAssetIds(string[] pathes, long[] timestamps, F
if (list.ContainsKey(guid))
{
FileToAssetsMapping fileToAssetsMapping = list[guid];
fileToAssetsMapping.SetExisting();

long timeStamp = timestamps[i];

if (fileToAssetsMapping.Timestamp != timeStamp)
Expand Down Expand Up @@ -136,6 +134,7 @@ private FileToAssetsMapping[] GetDependenciesForAssets(FileToAssetsMapping[] fil
{
string[] pathes = NodeDependencyLookupUtility.GetAllAssetPathes(true);
long[] timestamps = NodeDependencyLookupUtility.GetTimeStampsForFiles(pathes);
NodeDependencyLookupUtility.RemoveNonExistingFilesFromIdentifyableList(pathes, ref fileToAssetsMappings);

List<AssetResolverData> data = new List<AssetResolverData>();

Expand Down Expand Up @@ -191,10 +190,7 @@ public void AddExistingNodes(List<IDependencyMappingNode> nodes)
{
foreach (GenericDependencyMappingNode fileNode in fileToAssetsMapping.FileNodes)
{
if (fileNode.Existing)
{
nodes.Add(fileNode);
}
nodes.Add(fileNode);
}
}
}
Expand Down Expand Up @@ -284,14 +280,6 @@ public GenericDependencyMappingNode GetFileNode(string id)

return newGenericDependencyMappingNode;
}

public void SetExisting()
{
foreach (GenericDependencyMappingNode fileNode in FileNodes)
{
fileNode.IsExisting = true;
}
}
}

public interface IAssetToFileDependencyResolver : IDependencyResolver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ public class GenericDependencyMappingNode : IDependencyMappingNode
{
public string NodeId;
public List<Dependency> Dependencies = new List<Dependency>();
public bool IsExisting = true;
public string NodeType = String.Empty;
public string Id => NodeId;
public string Type => NodeType;
public bool Existing => IsExisting;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ public void AddExistingNodes(List<IDependencyMappingNode> nodes)
{
foreach (IDependencyMappingNode node in Nodes)
{
if (node.Existing)
{
nodes.Add(node);
}
nodes.Add(node);
}
}

Expand Down
6 changes: 0 additions & 6 deletions NodeDependencyLookup/Editor/Lookup/IDependencyMappingNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,5 @@ public interface IIdentifyable
public interface IDependencyMappingNode : IIdentifyable
{
string Type { get; }

/**
* It can be that a node got cached as being a dependency but is no longer existing anymore.
* This would be the case if an asset got deleted which was used by another one.
*/
bool Existing { get; }
}
}
32 changes: 24 additions & 8 deletions NodeDependencyLookup/Editor/Utility/NodeDependencyLookupUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ namespace Com.Innogames.Core.Frontend.NodeDependencyLookup
/// </summary>
public static class NodeDependencyLookupUtility
{
public class CachedNodeSize
public struct NodeSize
{
public int Size;
public HashSet<Node> FlattenedSubTree;
public bool ContributesToTreeSize;
}

public const string DEFAULT_CACHE_SAVE_PATH = "NodeDependencyCache";
Expand Down Expand Up @@ -299,12 +299,6 @@ public static bool IsNodePackedToApp(string id, string type, NodeDependencyLooku
return false;
}

public struct NodeSize
{
public int Size;
public bool ContributesToTreeSize;
}

public static int GetOwnNodeSize(string id, string type, string key,
NodeDependencyLookupContext stateContext, Dictionary<string, NodeSize> ownSizeCache)
{
Expand Down Expand Up @@ -520,6 +514,28 @@ public static string GetNodeKey(string id, string type)
return $"{id}@{type}";
}

public static void RemoveNonExistingFilesFromIdentifyableList<T>(string[] pathes, ref T[] list) where T : IIdentifyable
{
HashSet<string> pathesLookup = new HashSet<string>(pathes);
HashSet<T> deletedNodes = new HashSet<T>();

foreach (T listItem in list)
{
string filePath = AssetDatabase.GUIDToAssetPath(listItem.Id);
if (!pathesLookup.Contains(filePath))
{
deletedNodes.Add(listItem);
}
}

if (deletedNodes.Count > 0)
{
List<T> fileToAssetNodesLists = list.ToList();
fileToAssetNodesLists.RemoveAll(deletedNodes.Contains);
list = fileToAssetNodesLists.ToArray();
}
}

public static RelationType InvertRelationType(RelationType relationType)
{
switch (relationType)
Expand Down

0 comments on commit 2e2bd7f

Please sign in to comment.