Skip to content

Commit

Permalink
perf: Fixed a time consuming issue for users with large projects wher…
Browse files Browse the repository at this point in the history
…e all separate levels would unnessesarily reimport upon any project file change (like changing a definition or merely moving a level).

This was fixed (after some careful consideration) by removing the level's dependency registration upon it's project file. Additionally, removed separate levels registering a dependency upon level background images. These dependency changes shouln't pose any overall issues, but if levels are reimporting inconsistent results, feel free to report an issue!
  • Loading branch information
Cammin committed Sep 23, 2024
1 parent 5b1ccd1 commit 9460aa7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
5 changes: 3 additions & 2 deletions Assets/LDtkUnity/Editor/ScriptedImporter/LDtkJsonDigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ private static bool GetSeparateLevelDependenciesReader(ref JsonReader reader, re
}

//BACKGROUND
if (propName == "bgRelPath" && reader.ReadIsNameSeparator())
//don't need to make separate levels depend upon the background, but keep code just in case
/*if (propName == "bgRelPath" && reader.ReadIsNameSeparator())
{
string valueBackground = reader.ReadString();
if (!string.IsNullOrEmpty(valueBackground))
Expand All @@ -355,7 +356,7 @@ private static bool GetSeparateLevelDependenciesReader(ref JsonReader reader, re
return true;
}
continue;
}
}*/
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ namespace LDtkUnity.Editor
{
internal sealed class DugDependencyDataLevel
{
public string Background;
//public string Background;
public HashSet<string> Entities = new HashSet<string>();
public HashSet<string> IntGridValues = new HashSet<string>();

public override string ToString()
{
return $"Background: {Background}\n" +
return //$"Background: {Background}\n" +
$"Entities: {string.Join(", ", Entities)},\n" +
$"IntGridValues: {string.Join(", ", IntGridValues)},";
}
Expand Down Expand Up @@ -48,30 +48,34 @@ public static string[] GatherLevelDependencies(string levelPath)
}

HashSet<string> paths = new HashSet<string>();
paths.Add(projectPath);

//Don't depend on the base project, nor it's sub assets.
//paths.Add(projectPath);

//base project dependency is not required because many of the artifacts are reference-based anyway, so the levels only need to scoop up what the project makes.
//doesn't need to depend on tileset files either; the artifacts get loaded anyway due to the project importing before levels. Again, scooping up.
//We only need to depend on prefabs because those absolutely need to be updated in the level's result.
//in this case, it's:
//- LDtkIntGridValue assets (so tilemaps tile references are updated properly),
//- Entity prefabs, and level prefab (so that prefabs in the import result are updated, because normally they aren't after editing a prefab)

//Within the above types of assets we want to depend on, we only want to depend on assets that are used in a particular level as to further prevent unnecessary reimports.
DugDependencyDataLevel depends = new DugDependencyDataLevel();
LDtkJsonDigger.GetSeparateLevelDependencies(levelPath, ref depends);

string relLvlBackgroundPath = depends.Background;
HashSet<string> entities = depends.Entities;
HashSet<string> intGridValues = depends.IntGridValues;

if (relLvlBackgroundPath != null)
{
if (!string.IsNullOrEmpty(relLvlBackgroundPath))
{
LDtkRelativeGetterLevelBackground levelGetter = new LDtkRelativeGetterLevelBackground();
string levelBgPath = levelGetter.GetPathRelativeToPath(projectPath, relLvlBackgroundPath);
paths.Add(levelBgPath);
}
}
//As things stand, dependency on level background is not required, because the reference to the background is a sprite, and even if it was missing, there'd be bigger errors to solve anyways.
//DependOnLevelBackground(depends, projectPath, paths);

//we get all possible assets that is possibly available as the serialized information.
string[] projectLines = LDtkDependencyUtil.LoadMetaLinesAtPath(projectPath);
List<ParsedMetaData> allSerializedAssets = LDtkDependencyUtil.GetMetaDatasForDependencies(projectLines);

foreach (ParsedMetaData data in allSerializedAssets)
{
//DEPEND ON CUSTOM LEVEL PREFAB
if (data.Name == "_customLevelPrefab")
{
AddThisData();
Expand Down Expand Up @@ -118,5 +122,21 @@ void AddThisData()

return paths.ToArray();
}

private static void DependOnLevelBackground(DugDependencyDataLevel depends, string projectPath, HashSet<string> paths)
{
string relLvlBackgroundPath = "";//depends.Background;
if (relLvlBackgroundPath != null)
{
if (!string.IsNullOrEmpty(relLvlBackgroundPath))
{
LDtkRelativeGetterLevelBackground levelGetter = new LDtkRelativeGetterLevelBackground();
string levelBgPath = levelGetter.GetPathRelativeToPath(projectPath, relLvlBackgroundPath);

//DEPEND ON LEVEL BACKGROUND
paths.Add(levelBgPath);
}
}
}
}
}

0 comments on commit 9460aa7

Please sign in to comment.