From 266c53cea8f58ab7d16e94fe804669b9e3f2cd68 Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 16 Jul 2024 13:49:26 -0700 Subject: [PATCH] perf: Slight optimize to the tile building, where the flip bits is calculated in the job execution instead of the job construction --- Assets/LDtkUnity/Editor/Builders/TileBuildingJob.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Assets/LDtkUnity/Editor/Builders/TileBuildingJob.cs b/Assets/LDtkUnity/Editor/Builders/TileBuildingJob.cs index c27d825b..cfc663ec 100644 --- a/Assets/LDtkUnity/Editor/Builders/TileBuildingJob.cs +++ b/Assets/LDtkUnity/Editor/Builders/TileBuildingJob.cs @@ -11,8 +11,7 @@ public struct InputData public int CoordId; public int PxX; public int PxY; - public bool FlipX; - public bool FlipY; + public int Flip; } public struct OutputData @@ -49,8 +48,7 @@ public TileBuildingJob(TileInstance[] tiles, LayerInstance layer, float layerSca CoordId = isAutoLayer ? tile.D[1] : tile.D[0], PxX = tile.Px[0], PxY = tile.Px[1], - FlipX = tile.FlipX, - FlipY = tile.FlipY, + Flip = tile.F, }; } } @@ -69,9 +67,12 @@ public void Execute(int i) offset.x = pxOffsetX / (float)LayerGridSize; offset.y = -pxOffsetY / (float)LayerGridSize; + bool flipX = (input.Flip & 1) == 1; + bool flipY = (input.Flip & 2) == 2; + Vector3 scale = new Vector3(ScaleFactor, ScaleFactor, 1); - scale.x *= input.FlipX ? -1 : 1; - scale.y *= input.FlipY ? -1 : 1; + scale.x *= flipX ? -1 : 1; + scale.y *= flipY ? -1 : 1; //convert y into unity tilemap coordinate space cY = -cY + LayerCHei - 1;