Skip to content

Commit

Permalink
test: adding more profiler wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammin committed May 20, 2024
1 parent dbd0065 commit 6a16b88
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
11 changes: 10 additions & 1 deletion Assets/LDtkUnity/Editor/ScriptedImporter/LDtkJsonImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,25 @@ private LDtkTilesetImporter LoadAndCacheTilesetImporter(TilesetDefinition def)
return importer;
}

LDtkProfiler.BeginSample("TilesetImporterPath");
string path = TilesetImporterPath(assetPath, def.Identifier);
LDtkProfiler.EndSample();

if (!File.Exists(path))
LDtkProfiler.BeginSample("File.Exists");
bool exists = File.Exists(path);
LDtkProfiler.EndSample();

if (!exists)
{
Logger.LogError($"Failed to find the required tileset file at \"{path}\". Ensure that LDtk exported a tileset file through a custom command. If the command wasn't configured yet, check the project inspector for more info.");
_importersForDefs.Add(def, null);
return null;
}

LDtkProfiler.BeginSample("GetAtPath");
importer = (LDtkTilesetImporter)GetAtPath(path);
LDtkProfiler.EndSample();

if (importer == null)
{
Logger.LogError($"Failed to load the tileset importer at \"{path}\", but the file exists. The tileset file may have failed to import?");
Expand Down
14 changes: 14 additions & 0 deletions Assets/LDtkUnity/Editor/ScriptedImporter/LDtkProjectImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,15 @@ private void MakeDefObjects(LdtkJson json)
{
Dictionary<int, LDtkArtifactAssetsTileset> artifacts = MakeTilesetDict(this, json);

LDtkProfiler.BeginSample("InitializeFromProject");
DefinitionObjects.InitializeFromProject(json.Defs, artifacts);
LDtkProfiler.EndSample();

LDtkProfiler.BeginSample("Set _definitions");
_artifacts._definitions = DefinitionObjects.Defs;
LDtkProfiler.EndSample();

LDtkProfiler.BeginSample("AddAllObjectsToAsset");
foreach (var obj in DefinitionObjects.Defs)
{
if (obj is ILDtkUid uid)
Expand All @@ -197,6 +203,7 @@ private void MakeDefObjects(LdtkJson json)
}
Logger.LogError($"{obj.name} is not a uid! This should never happen", obj);
}
LDtkProfiler.EndSample();
}

private static void CheckDefaultEditorBehaviour()
Expand Down Expand Up @@ -247,12 +254,19 @@ private void BufferEditorCache()

private void MainBuild(LdtkJson json)
{
LDtkProfiler.BeginSample("SetupPreprocessors");
var preAction = new LDtkAssetProcessorActionCache();
LDtkAssetProcessorInvoker.AddPreProcessProject(preAction, json, AssetName);
LDtkProfiler.EndSample();

LDtkProfiler.BeginSample("RunPreprocessors");
preAction.Process();
LDtkProfiler.EndSample();

LDtkProfiler.BeginSample("ImportProject");
LDtkBuilderProjectFactory factory = new LDtkBuilderProjectFactory(this);
factory.Import(json);
LDtkProfiler.EndSample();
}

private void TryGenerateEnums(LdtkJson json)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ internal LDtkDefinitionObjectsCache(LDtkDebugInstance logger)

public void InitializeFromProject(Definitions defs, Dictionary<int, LDtkArtifactAssetsTileset> tilesets)
{
LDtkProfiler.BeginSample("InitializeTilesets");
InitializeTilesets(tilesets);
LDtkProfiler.EndSample();

LDtkProfiler.BeginSample("GenerateObjects");
GenerateObjects(defs);
Expand All @@ -52,8 +54,6 @@ public void InitializeFromProject(Definitions defs, Dictionary<int, LDtkArtifact
LDtkProfiler.EndSample();
}



public void InitializeFromLevel(List<LDtkDefinitionObject> defs, Dictionary<int, LDtkArtifactAssetsTileset> tilesets)
{
Profiler.BeginSample("InitializeTilesets");
Expand Down

0 comments on commit 6a16b88

Please sign in to comment.