From a70efc3ffba2068ef070b6e3626bf087c22ec961 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 28 Oct 2004 17:49:02 +0000 Subject: [PATCH] NoLongerAnySuchNoSuchTileException. Instead we just log a warning and return a tile with an error image so that the caller doesn't freak out and we achieve maximal "continue to work as much as possible." git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3177 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../bundle/BundledComponentRepository.java | 11 +-- .../com/threerings/media/IconManager.java | 7 +- .../threerings/media/tile/ImageProvider.java | 3 +- .../media/tile/NoSuchTileException.java | 42 ------------ .../threerings/media/tile/TileManager.java | 8 +-- .../com/threerings/media/tile/TileSet.java | 67 ++++++++++--------- .../threerings/miso/client/SceneBlock.java | 5 +- .../threerings/miso/client/SceneObject.java | 6 +- .../com/threerings/miso/tile/AutoFringer.java | 8 +-- .../miso/client/ScrollingScene.java | 5 +- 10 files changed, 52 insertions(+), 110 deletions(-) delete mode 100644 src/java/com/threerings/media/tile/NoSuchTileException.java diff --git a/src/java/com/threerings/cast/bundle/BundledComponentRepository.java b/src/java/com/threerings/cast/bundle/BundledComponentRepository.java index 50a51ccf6..a2b2f2d2a 100644 --- a/src/java/com/threerings/cast/bundle/BundledComponentRepository.java +++ b/src/java/com/threerings/cast/bundle/BundledComponentRepository.java @@ -1,5 +1,5 @@ // -// $Id: BundledComponentRepository.java,v 1.35 2004/10/18 21:39:18 mdb Exp $ +// $Id: BundledComponentRepository.java,v 1.36 2004/10/28 17:49:01 mdb Exp $ // // Narya library - tools for developing networked games // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved @@ -48,7 +48,6 @@ import com.threerings.media.image.ImageDataProvider; import com.threerings.media.image.ImageManager; import com.threerings.media.tile.IMImageProvider; -import com.threerings.media.tile.NoSuchTileException; import com.threerings.media.tile.Tile; import com.threerings.media.tile.TileSet; import com.threerings.media.tile.TrimmedTile; @@ -479,13 +478,7 @@ public class BundledComponentRepository protected Tile getTile (int orient, int index) { int tileIndex = _orients.get(orient) * _fcount + index; - try { - return _set.getTile(tileIndex); - } catch (NoSuchTileException nste) { - Log.warning("Can't extract action frame [set=" + _set + - ", orient=" + orient + ", index=" + index + "]."); - return null; - } + return _set.getTile(tileIndex); } /** The tileset from which we obtain our frame images. */ diff --git a/src/java/com/threerings/media/IconManager.java b/src/java/com/threerings/media/IconManager.java index db11e4087..d1df12362 100644 --- a/src/java/com/threerings/media/IconManager.java +++ b/src/java/com/threerings/media/IconManager.java @@ -1,5 +1,5 @@ // -// $Id: IconManager.java,v 1.7 2004/08/27 02:12:37 mdb Exp $ +// $Id: IconManager.java,v 1.8 2004/10/28 17:49:02 mdb Exp $ // // Narya library - tools for developing networked games // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved @@ -34,7 +34,6 @@ import com.samskivert.util.ConfigUtil; import com.samskivert.util.LRUHashMap; import com.samskivert.util.StringUtil; -import com.threerings.media.tile.NoSuchTileException; import com.threerings.media.tile.TileIcon; import com.threerings.media.tile.TileManager; import com.threerings.media.tile.TileSet; @@ -146,10 +145,6 @@ public class IconManager // fetch the appropriate image and create an image icon return new TileIcon(set.getTile(index)); - } catch (NoSuchTileException nste) { - Log.warning("Unable to load icon [iconSet=" + iconSet + - ", index=" + index + "]. Image index out of bounds."); - } catch (Exception e) { Log.warning("Unable to load icon [iconSet=" + iconSet + ", index=" + index + ", error=" + e + "]."); diff --git a/src/java/com/threerings/media/tile/ImageProvider.java b/src/java/com/threerings/media/tile/ImageProvider.java index 270152245..517f3825a 100644 --- a/src/java/com/threerings/media/tile/ImageProvider.java +++ b/src/java/com/threerings/media/tile/ImageProvider.java @@ -1,5 +1,5 @@ // -// $Id: ImageProvider.java,v 1.4 2004/08/27 02:12:41 mdb Exp $ +// $Id: ImageProvider.java,v 1.5 2004/10/28 17:49:02 mdb Exp $ // // Narya library - tools for developing networked games // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved @@ -25,6 +25,7 @@ import java.awt.Rectangle; import java.awt.image.BufferedImage; import com.threerings.media.image.Colorization; +import com.threerings.media.image.ImageManager; import com.threerings.media.image.Mirage; /** diff --git a/src/java/com/threerings/media/tile/NoSuchTileException.java b/src/java/com/threerings/media/tile/NoSuchTileException.java deleted file mode 100644 index 3d150a014..000000000 --- a/src/java/com/threerings/media/tile/NoSuchTileException.java +++ /dev/null @@ -1,42 +0,0 @@ -// -// $Id: NoSuchTileException.java,v 1.4 2004/08/27 02:12:41 mdb Exp $ -// -// Narya library - tools for developing networked games -// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved -// http://www.threerings.net/code/narya/ -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.threerings.media.tile; - -/** - * Thrown when an attempt is made to retrieve a non-existent tile from the - * tile manager. - */ -public class NoSuchTileException extends RuntimeException -{ - public NoSuchTileException (TileSet set, int tid) - { - super("No such tile [set=" + set + ", tid=" + tid + "]"); - _tid = tid; - } - - public int getTileId () - { - return _tid; - } - - protected int _tid; -} diff --git a/src/java/com/threerings/media/tile/TileManager.java b/src/java/com/threerings/media/tile/TileManager.java index ced9a09dc..cae7fb805 100644 --- a/src/java/com/threerings/media/tile/TileManager.java +++ b/src/java/com/threerings/media/tile/TileManager.java @@ -1,5 +1,5 @@ // -// $Id: TileManager.java,v 1.36 2004/08/27 02:12:41 mdb Exp $ +// $Id: TileManager.java,v 1.37 2004/10/28 17:49:02 mdb Exp $ // // Narya library - tools for developing networked games // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved @@ -194,7 +194,7 @@ public class TileManager * @see TileUtil#getFQTileId */ public Tile getTile (int fqTileId) - throws NoSuchTileSetException, NoSuchTileException + throws NoSuchTileSetException { return getTile(TileUtil.getTileSetId(fqTileId), TileUtil.getTileIndex(fqTileId), null); @@ -207,7 +207,7 @@ public class TileManager * @see TileUtil#getFQTileId */ public Tile getTile (int fqTileId, TileSet.Colorizer rizer) - throws NoSuchTileSetException, NoSuchTileException + throws NoSuchTileSetException { return getTile(TileUtil.getTileSetId(fqTileId), TileUtil.getTileIndex(fqTileId), rizer); @@ -223,7 +223,7 @@ public class TileManager * @return the tile object. */ public Tile getTile (int tileSetId, int tileIndex, TileSet.Colorizer rizer) - throws NoSuchTileSetException, NoSuchTileException + throws NoSuchTileSetException { TileSet set = getTileSet(tileSetId); return set.getTile(tileIndex, rizer); diff --git a/src/java/com/threerings/media/tile/TileSet.java b/src/java/com/threerings/media/tile/TileSet.java index 6db158657..e91084d7d 100644 --- a/src/java/com/threerings/media/tile/TileSet.java +++ b/src/java/com/threerings/media/tile/TileSet.java @@ -1,5 +1,5 @@ // -// $Id: TileSet.java,v 1.61 2004/08/27 02:12:41 mdb Exp $ +// $Id: TileSet.java,v 1.62 2004/10/28 17:49:02 mdb Exp $ // // Narya library - tools for developing networked games // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved @@ -34,6 +34,8 @@ import com.samskivert.util.Throttle; import com.threerings.media.Log; import com.threerings.media.image.Colorization; import com.threerings.media.image.Mirage; +import com.threerings.media.image.ImageUtil; +import com.threerings.media.image.BufferedMirage; /** * A tileset stores information on a single logical set of tiles. It @@ -154,7 +156,6 @@ public abstract class TileSet * Colorizer argument. */ public Tile getTile (int tileIndex) - throws NoSuchTileException { return getTile(tileIndex, _zations); } @@ -173,14 +174,9 @@ public abstract class TileSet * known not to be recolorizable is valid. * * @return the tile object. - * - * @exception NoSuchTileException thrown if the specified tile index - * is out of range for this tileset. */ public Tile getTile (int tileIndex, Colorizer rizer) - throws NoSuchTileException { - checkTileIndex(tileIndex); return getTile(tileIndex, getColorizations(tileIndex, rizer)); } @@ -197,9 +193,6 @@ public abstract class TileSet * to returning it. These may be null for uncolorized images. * * @return the tile object. - * - * @exception NoSuchTileException thrown if the specified tile index - * is out of range for this tileset. */ public Tile getTile (int tileIndex, Colorization[] zations) { @@ -241,7 +234,6 @@ public abstract class TileSet * that is desired is access to the underlying image. */ public Mirage getTileMirage (int tileIndex) - throws NoSuchTileException { return getTileMirage(tileIndex, getColorizations(tileIndex, null)); } @@ -254,15 +246,22 @@ public abstract class TileSet * that is desired is access to the underlying image. */ public Mirage getTileMirage (int tileIndex, Colorization[] zations) - throws NoSuchTileException { - checkTileIndex(tileIndex); Rectangle bounds = computeTileBounds(tileIndex); - if (_improv == null) { - Log.warning("Aiya! Tile set missing image provider " + - "[path=" + _imagePath + "]."); + Mirage mirage = null; + if (checkTileIndex(tileIndex)) { + if (_improv == null) { + Log.warning("Aiya! Tile set missing image provider " + + "[path=" + _imagePath + "]."); + } else { + mirage = _improv.getTileImage(_imagePath, bounds, zations); + } } - return _improv.getTileImage(_imagePath, bounds, zations); + if (mirage == null) { + mirage = new BufferedMirage( + ImageUtil.createErrorImage(bounds.width, bounds.height)); + } + return mirage; } /** @@ -285,16 +284,22 @@ public abstract class TileSet * processing and prepare the subsequent image for display onscreen. */ public BufferedImage getRawTileImage (int tileIndex) - throws NoSuchTileException { - checkTileIndex(tileIndex); Rectangle bounds = computeTileBounds(tileIndex); - BufferedImage timg = getRawTileSetImage(); - if (timg == null) { - throw new IllegalStateException("Missing source image " + this); + BufferedImage img = null; + if (checkTileIndex(tileIndex)) { + BufferedImage timg = getRawTileSetImage(); + if (timg != null) { + img = timg.getSubimage(bounds.x, bounds.y, + bounds.width, bounds.height); + } else { + Log.warning("Missing source image " + this); + } } - return timg.getSubimage(bounds.x, bounds.y, - bounds.width, bounds.height); + if (img == null) { + img = ImageUtil.createErrorImage(bounds.width, bounds.height); + } + return img; } /** @@ -312,14 +317,16 @@ public abstract class TileSet /** * Used to ensure that the specified tile index is valid. */ - protected void checkTileIndex (int tileIndex) - throws NoSuchTileException + protected boolean checkTileIndex (int tileIndex) { - // bail if there's no such tile int tcount = getTileCount(); - if (tileIndex < 0 || tileIndex >= tcount) { - throw new NoSuchTileException(this, tileIndex); - } + if (tileIndex >= 0 && tileIndex < tcount) { + return true; + } else { + Log.warning("Requested invalid tile [tset=" + this + + ", index=" + tileIndex + "]."); + return false; + } } /** diff --git a/src/java/com/threerings/miso/client/SceneBlock.java b/src/java/com/threerings/miso/client/SceneBlock.java index 694d91d0e..f0f4c3125 100644 --- a/src/java/com/threerings/miso/client/SceneBlock.java +++ b/src/java/com/threerings/miso/client/SceneBlock.java @@ -1,5 +1,5 @@ // -// $Id: SceneBlock.java,v 1.25 2004/08/27 02:20:06 mdb Exp $ +// $Id: SceneBlock.java,v 1.26 2004/10/28 17:49:02 mdb Exp $ // // Narya library - tools for developing networked games // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved @@ -33,7 +33,6 @@ import com.samskivert.util.HashIntMap; import com.samskivert.util.StringUtil; import com.threerings.geom.GeomUtil; -import com.threerings.media.tile.NoSuchTileException; import com.threerings.media.tile.NoSuchTileSetException; import com.threerings.media.tile.ObjectTile; import com.threerings.media.tile.TileSet; @@ -301,8 +300,6 @@ public class SceneBlock errmsg = "Scene contains non-base tile in base layer"; } catch (NoSuchTileSetException nste) { errmsg = "Scene contains non-existent tileset"; - } catch (NoSuchTileException nste) { - errmsg = "Scene contains non-existent tile"; } if (errmsg != null) { diff --git a/src/java/com/threerings/miso/client/SceneObject.java b/src/java/com/threerings/miso/client/SceneObject.java index 6513b5ed6..fcab84fdd 100644 --- a/src/java/com/threerings/miso/client/SceneObject.java +++ b/src/java/com/threerings/miso/client/SceneObject.java @@ -1,5 +1,5 @@ // -// $Id: SceneObject.java,v 1.11 2004/08/27 02:20:06 mdb Exp $ +// $Id: SceneObject.java,v 1.12 2004/10/28 17:49:02 mdb Exp $ // // Narya library - tools for developing networked games // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved @@ -32,7 +32,6 @@ import java.awt.Rectangle; import com.samskivert.util.RuntimeAdjust; import com.samskivert.util.StringUtil; -import com.threerings.media.tile.NoSuchTileException; import com.threerings.media.tile.NoSuchTileSetException; import com.threerings.media.tile.ObjectTile; import com.threerings.media.tile.TileUtil; @@ -256,9 +255,6 @@ public class SceneObject tsid, tidx, panel.getColorizer(info)); computeInfo(panel.getSceneMetrics()); - } catch (NoSuchTileException nste) { - Log.warning("Scene contains non-existent object tile " + - "[info=" + info + "]."); } catch (NoSuchTileSetException te) { Log.warning("Scene contains non-existent object tileset " + "[info=" + info + "]."); diff --git a/src/java/com/threerings/miso/tile/AutoFringer.java b/src/java/com/threerings/miso/tile/AutoFringer.java index 8fd5d1745..22c4858af 100644 --- a/src/java/com/threerings/miso/tile/AutoFringer.java +++ b/src/java/com/threerings/miso/tile/AutoFringer.java @@ -1,5 +1,5 @@ // -// $Id: AutoFringer.java,v 1.29 2004/08/27 02:20:07 mdb Exp $ +// $Id: AutoFringer.java,v 1.30 2004/10/28 17:49:02 mdb Exp $ // // Narya library - tools for developing networked games // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved @@ -34,7 +34,6 @@ import com.threerings.media.image.BufferedMirage; import com.threerings.media.image.ImageManager; import com.threerings.media.image.ImageUtil; -import com.threerings.media.tile.NoSuchTileException; import com.threerings.media.tile.NoSuchTileSetException; import com.threerings.media.tile.Tile; import com.threerings.media.tile.TileManager; @@ -157,9 +156,6 @@ public class AutoFringer try { ftimg = getTileImage(ftimg, fringers[ii].baseset, indexes[jj], masks, hashValue); - } catch (NoSuchTileException nste) { - Log.warning("Autofringer couldn't find a needed tile " + - "[error=" + nste + "]."); } catch (NoSuchTileSetException nstse) { Log.warning("Autofringer couldn't find a needed tileset " + "[error=" + nstse + "]."); @@ -176,7 +172,7 @@ public class AutoFringer protected BufferedImage getTileImage ( BufferedImage ftimg, int baseset, int index, HashMap masks, int hashValue) - throws NoSuchTileException, NoSuchTileSetException + throws NoSuchTileSetException { FringeConfiguration.FringeTileSetRecord tsr = _fringeconf.getFringe(baseset, hashValue); diff --git a/tests/src/java/com/threerings/miso/client/ScrollingScene.java b/tests/src/java/com/threerings/miso/client/ScrollingScene.java index be2b6b8cc..7a036f75c 100644 --- a/tests/src/java/com/threerings/miso/client/ScrollingScene.java +++ b/tests/src/java/com/threerings/miso/client/ScrollingScene.java @@ -1,5 +1,5 @@ // -// $Id: ScrollingScene.java,v 1.15 2004/08/27 02:21:01 mdb Exp $ +// $Id: ScrollingScene.java,v 1.16 2004/10/28 17:49:02 mdb Exp $ // // Narya library - tools for developing networked games // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved @@ -28,7 +28,6 @@ import java.util.Random; import com.samskivert.io.PersistenceException; -import com.threerings.media.tile.NoSuchTileException; import com.threerings.media.tile.NoSuchTileSetException; import com.threerings.media.tile.TileSet; import com.threerings.media.tile.TileSetRepository; @@ -46,7 +45,7 @@ import com.threerings.miso.data.ObjectInfo; public class ScrollingScene extends MisoSceneModel { public ScrollingScene (MisoContext ctx) - throws NoSuchTileSetException, NoSuchTileException, PersistenceException + throws NoSuchTileSetException, PersistenceException { // locate the water tileset TileSetRepository tsrepo = ctx.getTileManager().getTileSetRepository();