Skip to content

Commit

Permalink
perf: Slight optimize to the tile building, where the flip bits is ca…
Browse files Browse the repository at this point in the history
…lculated in the job execution instead of the job construction
  • Loading branch information
Cammin committed Jul 16, 2024
1 parent efbd4d0 commit 266c53c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Assets/LDtkUnity/Editor/Builders/TileBuildingJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
};
}
}
Expand All @@ -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;
Expand Down

0 comments on commit 266c53c

Please sign in to comment.