From 9733142d354f621aa11cd2048372179fdc78e7ca Mon Sep 17 00:00:00 2001 From: Dave Hoover Date: Thu, 10 Jan 2008 19:51:24 +0000 Subject: [PATCH] It's not a perfect solution, but make it so we can call the tile trimming task and not actually write out new image to a file if we don't need to. This cuts my tileset building from 42 seconds to 22 when no files have changed (as opposed to 4 when it was skipping it altogether, but winding up with a hosed tsbundles.dat), so it's at least a decent bit better. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@391 ed5b42cb-e716-0410-a449-f6a68f950b19 --- .../bundle/tools/DirectoryTileSetBundler.java | 27 ++++++++++--------- .../media/tile/util/TileSetTrimmer.java | 12 +++++---- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/java/com/threerings/media/tile/bundle/tools/DirectoryTileSetBundler.java b/src/java/com/threerings/media/tile/bundle/tools/DirectoryTileSetBundler.java index 85ee7621..f3f898bb 100644 --- a/src/java/com/threerings/media/tile/bundle/tools/DirectoryTileSetBundler.java +++ b/src/java/com/threerings/media/tile/bundle/tools/DirectoryTileSetBundler.java @@ -87,25 +87,28 @@ public class DirectoryTileSetBundler extends TileSetBundler try { // create a trimmed object tileset, which will - // write the trimmed tileset image to the destination - // output stream + // write the trimmed tileset image to the destination output stream File outFile = new File(target, imagePath); + FileOutputStream fout = null; + if (outFile.lastModified() > newestMod) { // Our file's newer than the newest bundle mod - up to date. + // So don't actually do anything - // FIXME: We can't just skip it, since we would've normally trimmed it, - // so we need to get an appropriate TrimmedObjectTileSet added to our - // bundle in place of this old ObjectTileSet. - //continue; + // TODO: Ideally, we'd like to skip re-trimming altogether, since that's + // expensive, but for the moment, we're at least doing half as much by + // not writing out the trimmed image. + + } else { + // It's changed, so let's open the file & do all that jazz + outFile.getParentFile().mkdirs(); + fout = new FileOutputStream(outFile); } - outFile.getParentFile().mkdirs(); - FileOutputStream fout = new FileOutputStream(outFile); + TrimmedObjectTileSet tset = - TrimmedObjectTileSet.trimObjectTileSet( - (ObjectTileSet)set, fout, "png"); + TrimmedObjectTileSet.trimObjectTileSet((ObjectTileSet)set, fout, "png"); tset.setImagePath(imagePath); - // replace the original set with the trimmed - // tileset in the tileset bundle + // replace the original set with the trimmed tileset in the tileset bundle bundle.addTileSet(tileSetId, tset); } catch (Exception e) { diff --git a/src/java/com/threerings/media/tile/util/TileSetTrimmer.java b/src/java/com/threerings/media/tile/util/TileSetTrimmer.java index b4d84648..1546c8f8 100644 --- a/src/java/com/threerings/media/tile/util/TileSetTrimmer.java +++ b/src/java/com/threerings/media/tile/util/TileSetTrimmer.java @@ -151,11 +151,13 @@ public class TileSetTrimmer xoff += tb.width; } - // write out trimmed image - if (imgFormat == null || FastImageIO.FILE_SUFFIX.equals(imgFormat)) { - FastImageIO.write(image, destImage); - } else { - ImageIO.write(image, imgFormat, destImage); + if (destImage != null) { + // write out trimmed image + if (imgFormat == null || FastImageIO.FILE_SUFFIX.equals(imgFormat)) { + FastImageIO.write(image, destImage); + } else { + ImageIO.write(image, imgFormat, destImage); + } } } }