diff --git a/Assets/LDtkUnity/Editor/Builders/LDtkBuilderTileset.cs b/Assets/LDtkUnity/Editor/Builders/LDtkBuilderTileset.cs index 417b279f..4d46b22b 100644 --- a/Assets/LDtkUnity/Editor/Builders/LDtkBuilderTileset.cs +++ b/Assets/LDtkUnity/Editor/Builders/LDtkBuilderTileset.cs @@ -54,6 +54,25 @@ public void BuildTileset(TileInstance[] tiles) { _tiles = tiles; + LDtkProfiler.BeginSample("EvaluateTilesetDefinition"); + TilesetDefinition tilesetDef = EvaluateTilesetDefinition(); + LDtkProfiler.EndSample(); + if (tilesetDef == null) + { + //It is possible that a layer has no tileset definition assigned. In this case, it's fine to not build any tiles. + return; + } + + LDtkProfiler.BeginSample("LoadTilesetArtifacts"); + LDtkArtifactAssetsTileset artifacts = Importer.LoadTilesetArtifacts(Project, tilesetDef); + LDtkProfiler.EndSample(); + + if (artifacts == null) + { + //failure to load should not spend time calculating tiles + return; + } + LDtkProfiler.BeginSample("construct TileBuildingJob"); TileBuildingJob job = new TileBuildingJob(_tiles, Layer, LayerScale); LDtkProfiler.EndSample(); @@ -63,6 +82,7 @@ public void BuildTileset(TileInstance[] tiles) int tilesLength = _tiles.Length; int innerLoopBatchCount = Mathf.Max(1, (tilesLength / System.Environment.ProcessorCount) + 1); JobHandle handle = job.ScheduleParallel(tilesLength, innerLoopBatchCount, default); + JobHandle.ScheduleBatchedJobs(); LDtkProfiler.EndSample(); LDtkProfiler.BeginSample("ConstructNewTilemap"); @@ -85,31 +105,6 @@ public void BuildTileset(TileInstance[] tiles) Map.SetOpacity(Layer); LDtkProfiler.EndSample(); - LDtkProfiler.BeginSample("EvaluateTilesetDefinition"); - TilesetDefinition tilesetDef = EvaluateTilesetDefinition(); - LDtkProfiler.EndSample(); - if (tilesetDef == null) - { - //It is possible that a layer has no tileset definition assigned. In this case, it's fine to not build any tiles. - handle.Complete(); - job.Input.Dispose(); - job.Output.Dispose(); - return; - } - - LDtkProfiler.BeginSample("LoadTilesetArtifacts"); - LDtkArtifactAssetsTileset artifacts = Importer.LoadTilesetArtifacts(Project, tilesetDef); - LDtkProfiler.EndSample(); - - if (artifacts == null) - { - //failure to load should not spend time calculating tiles - handle.Complete(); - job.Input.Dispose(); - job.Output.Dispose(); - return; - } - LDtkProfiler.BeginSample("CacheNeededTilesArtifacts"); TileBase[] tileAssets = new TileBase[tilesLength]; for (int i = 0; i < tilesLength; i++) @@ -127,7 +122,10 @@ public void BuildTileset(TileInstance[] tiles) LDtkProfiler.EndSample(); handle.Complete(); + + LDtkProfiler.BeginSample("Input.Dispose"); job.Input.Dispose(); + LDtkProfiler.EndSample(); LDtkProfiler.BeginSample("AddTiles"); Vector3Int[] cells = new Vector3Int[tilesLength]; @@ -151,7 +149,13 @@ public void BuildTileset(TileInstance[] tiles) } LDtkProfiler.EndSample(); + LDtkProfiler.BeginSample("Output.Dispose"); job.Output.Dispose(); + LDtkProfiler.EndSample(); + + LDtkProfiler.BeginSample("ApplyExtraData"); + _tilesetProvider.ApplyExtraData(); + LDtkProfiler.EndSample(); LDtkProfiler.BeginSample("CompressBounds"); Map.CompressBounds(); @@ -162,7 +166,5 @@ private TilesetDefinition EvaluateTilesetDefinition() { return Layer.OverrideTilesetUid != null ? Layer.OverrideTilesetDefinition : Layer.TilesetDefinition; } - - } } diff --git a/Assets/LDtkUnity/Editor/Builders/TilemapTilesBuilder.cs b/Assets/LDtkUnity/Editor/Builders/TilemapTilesBuilder.cs index d503f1f4..d5c2b417 100644 --- a/Assets/LDtkUnity/Editor/Builders/TilemapTilesBuilder.cs +++ b/Assets/LDtkUnity/Editor/Builders/TilemapTilesBuilder.cs @@ -84,12 +84,9 @@ public void ApplyPendingTiles(bool isIntGrid) LDtkProfiler.EndSample(); LDtkProfiler.BeginSample("ApplyExtraData"); - foreach (KeyValuePair pair in _extraData) - { - pair.Value.ApplyExtraValues(Map, pair.Key); - } + ApplyExtraData(); LDtkProfiler.EndSample(); - + if (!isIntGrid) { return; @@ -108,6 +105,14 @@ public void ApplyPendingTiles(bool isIntGrid) LDtkProfiler.EndSample(); } + public void ApplyExtraData() + { + foreach (KeyValuePair pair in _extraData) + { + pair.Value.ApplyExtraValues(Map, pair.Key); + } + } + public void SetColor(Vector3Int cell, Color color) { if (!_extraData.ContainsKey(cell)) @@ -128,17 +133,9 @@ public void SetTransformMatrix(Vector3Int cell, Matrix4x4 matrix) public void SetColorAndMatrix(Vector3Int cell, ref Color color, ref Matrix4x4 matrix) { - if (!_extraData.ContainsKey(cell)) - { - _extraData.Add(cell, new ExtraData()); - } + _extraData.Add(cell, new ExtraData()); _extraData[cell].color = color; _extraData[cell].matrix = matrix; } - - public void SetAllTiles(Vector3Int[] cells, TileBase[] tiles) - { - - } } } \ No newline at end of file