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
This commit is contained in:
Michael Bayne
2004-10-28 17:49:02 +00:00
parent 69e3f857c2
commit a70efc3ffb
10 changed files with 52 additions and 110 deletions
@@ -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 // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // 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.image.ImageManager;
import com.threerings.media.tile.IMImageProvider; import com.threerings.media.tile.IMImageProvider;
import com.threerings.media.tile.NoSuchTileException;
import com.threerings.media.tile.Tile; import com.threerings.media.tile.Tile;
import com.threerings.media.tile.TileSet; import com.threerings.media.tile.TileSet;
import com.threerings.media.tile.TrimmedTile; import com.threerings.media.tile.TrimmedTile;
@@ -479,13 +478,7 @@ public class BundledComponentRepository
protected Tile getTile (int orient, int index) protected Tile getTile (int orient, int index)
{ {
int tileIndex = _orients.get(orient) * _fcount + index; int tileIndex = _orients.get(orient) * _fcount + index;
try { return _set.getTile(tileIndex);
return _set.getTile(tileIndex);
} catch (NoSuchTileException nste) {
Log.warning("Can't extract action frame [set=" + _set +
", orient=" + orient + ", index=" + index + "].");
return null;
}
} }
/** The tileset from which we obtain our frame images. */ /** The tileset from which we obtain our frame images. */
@@ -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 // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // 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.LRUHashMap;
import com.samskivert.util.StringUtil; import com.samskivert.util.StringUtil;
import com.threerings.media.tile.NoSuchTileException;
import com.threerings.media.tile.TileIcon; import com.threerings.media.tile.TileIcon;
import com.threerings.media.tile.TileManager; import com.threerings.media.tile.TileManager;
import com.threerings.media.tile.TileSet; import com.threerings.media.tile.TileSet;
@@ -146,10 +145,6 @@ public class IconManager
// fetch the appropriate image and create an image icon // fetch the appropriate image and create an image icon
return new TileIcon(set.getTile(index)); 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) { } catch (Exception e) {
Log.warning("Unable to load icon [iconSet=" + iconSet + Log.warning("Unable to load icon [iconSet=" + iconSet +
", index=" + index + ", error=" + e + "]."); ", index=" + index + ", error=" + e + "].");
@@ -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 // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // 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 java.awt.image.BufferedImage;
import com.threerings.media.image.Colorization; import com.threerings.media.image.Colorization;
import com.threerings.media.image.ImageManager;
import com.threerings.media.image.Mirage; import com.threerings.media.image.Mirage;
/** /**
@@ -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;
}
@@ -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 // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -194,7 +194,7 @@ public class TileManager
* @see TileUtil#getFQTileId * @see TileUtil#getFQTileId
*/ */
public Tile getTile (int fqTileId) public Tile getTile (int fqTileId)
throws NoSuchTileSetException, NoSuchTileException throws NoSuchTileSetException
{ {
return getTile(TileUtil.getTileSetId(fqTileId), return getTile(TileUtil.getTileSetId(fqTileId),
TileUtil.getTileIndex(fqTileId), null); TileUtil.getTileIndex(fqTileId), null);
@@ -207,7 +207,7 @@ public class TileManager
* @see TileUtil#getFQTileId * @see TileUtil#getFQTileId
*/ */
public Tile getTile (int fqTileId, TileSet.Colorizer rizer) public Tile getTile (int fqTileId, TileSet.Colorizer rizer)
throws NoSuchTileSetException, NoSuchTileException throws NoSuchTileSetException
{ {
return getTile(TileUtil.getTileSetId(fqTileId), return getTile(TileUtil.getTileSetId(fqTileId),
TileUtil.getTileIndex(fqTileId), rizer); TileUtil.getTileIndex(fqTileId), rizer);
@@ -223,7 +223,7 @@ public class TileManager
* @return the tile object. * @return the tile object.
*/ */
public Tile getTile (int tileSetId, int tileIndex, TileSet.Colorizer rizer) public Tile getTile (int tileSetId, int tileIndex, TileSet.Colorizer rizer)
throws NoSuchTileSetException, NoSuchTileException throws NoSuchTileSetException
{ {
TileSet set = getTileSet(tileSetId); TileSet set = getTileSet(tileSetId);
return set.getTile(tileIndex, rizer); return set.getTile(tileIndex, rizer);
+37 -30
View File
@@ -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 // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // 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.Log;
import com.threerings.media.image.Colorization; import com.threerings.media.image.Colorization;
import com.threerings.media.image.Mirage; 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 * A tileset stores information on a single logical set of tiles. It
@@ -154,7 +156,6 @@ public abstract class TileSet
* <code>Colorizer</code> argument. * <code>Colorizer</code> argument.
*/ */
public Tile getTile (int tileIndex) public Tile getTile (int tileIndex)
throws NoSuchTileException
{ {
return getTile(tileIndex, _zations); return getTile(tileIndex, _zations);
} }
@@ -173,14 +174,9 @@ public abstract class TileSet
* known not to be recolorizable is valid. * known not to be recolorizable is valid.
* *
* @return the tile object. * @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) public Tile getTile (int tileIndex, Colorizer rizer)
throws NoSuchTileException
{ {
checkTileIndex(tileIndex);
return getTile(tileIndex, getColorizations(tileIndex, rizer)); return getTile(tileIndex, getColorizations(tileIndex, rizer));
} }
@@ -197,9 +193,6 @@ public abstract class TileSet
* to returning it. These may be null for uncolorized images. * to returning it. These may be null for uncolorized images.
* *
* @return the tile object. * @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) public Tile getTile (int tileIndex, Colorization[] zations)
{ {
@@ -241,7 +234,6 @@ public abstract class TileSet
* that is desired is access to the underlying image. * that is desired is access to the underlying image.
*/ */
public Mirage getTileMirage (int tileIndex) public Mirage getTileMirage (int tileIndex)
throws NoSuchTileException
{ {
return getTileMirage(tileIndex, getColorizations(tileIndex, null)); return getTileMirage(tileIndex, getColorizations(tileIndex, null));
} }
@@ -254,15 +246,22 @@ public abstract class TileSet
* that is desired is access to the underlying image. * that is desired is access to the underlying image.
*/ */
public Mirage getTileMirage (int tileIndex, Colorization[] zations) public Mirage getTileMirage (int tileIndex, Colorization[] zations)
throws NoSuchTileException
{ {
checkTileIndex(tileIndex);
Rectangle bounds = computeTileBounds(tileIndex); Rectangle bounds = computeTileBounds(tileIndex);
if (_improv == null) { Mirage mirage = null;
Log.warning("Aiya! Tile set missing image provider " + if (checkTileIndex(tileIndex)) {
"[path=" + _imagePath + "]."); 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. * processing and prepare the subsequent image for display onscreen.
*/ */
public BufferedImage getRawTileImage (int tileIndex) public BufferedImage getRawTileImage (int tileIndex)
throws NoSuchTileException
{ {
checkTileIndex(tileIndex);
Rectangle bounds = computeTileBounds(tileIndex); Rectangle bounds = computeTileBounds(tileIndex);
BufferedImage timg = getRawTileSetImage(); BufferedImage img = null;
if (timg == null) { if (checkTileIndex(tileIndex)) {
throw new IllegalStateException("Missing source image " + this); 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, if (img == null) {
bounds.width, bounds.height); 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. * Used to ensure that the specified tile index is valid.
*/ */
protected void checkTileIndex (int tileIndex) protected boolean checkTileIndex (int tileIndex)
throws NoSuchTileException
{ {
// bail if there's no such tile
int tcount = getTileCount(); int tcount = getTileCount();
if (tileIndex < 0 || tileIndex >= tcount) { if (tileIndex >= 0 && tileIndex < tcount) {
throw new NoSuchTileException(this, tileIndex); return true;
} } else {
Log.warning("Requested invalid tile [tset=" + this +
", index=" + tileIndex + "].");
return false;
}
} }
/** /**
@@ -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 // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // 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.samskivert.util.StringUtil;
import com.threerings.geom.GeomUtil; import com.threerings.geom.GeomUtil;
import com.threerings.media.tile.NoSuchTileException;
import com.threerings.media.tile.NoSuchTileSetException; import com.threerings.media.tile.NoSuchTileSetException;
import com.threerings.media.tile.ObjectTile; import com.threerings.media.tile.ObjectTile;
import com.threerings.media.tile.TileSet; import com.threerings.media.tile.TileSet;
@@ -301,8 +300,6 @@ public class SceneBlock
errmsg = "Scene contains non-base tile in base layer"; errmsg = "Scene contains non-base tile in base layer";
} catch (NoSuchTileSetException nste) { } catch (NoSuchTileSetException nste) {
errmsg = "Scene contains non-existent tileset"; errmsg = "Scene contains non-existent tileset";
} catch (NoSuchTileException nste) {
errmsg = "Scene contains non-existent tile";
} }
if (errmsg != null) { if (errmsg != null) {
@@ -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 // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // 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.RuntimeAdjust;
import com.samskivert.util.StringUtil; import com.samskivert.util.StringUtil;
import com.threerings.media.tile.NoSuchTileException;
import com.threerings.media.tile.NoSuchTileSetException; import com.threerings.media.tile.NoSuchTileSetException;
import com.threerings.media.tile.ObjectTile; import com.threerings.media.tile.ObjectTile;
import com.threerings.media.tile.TileUtil; import com.threerings.media.tile.TileUtil;
@@ -256,9 +255,6 @@ public class SceneObject
tsid, tidx, panel.getColorizer(info)); tsid, tidx, panel.getColorizer(info));
computeInfo(panel.getSceneMetrics()); computeInfo(panel.getSceneMetrics());
} catch (NoSuchTileException nste) {
Log.warning("Scene contains non-existent object tile " +
"[info=" + info + "].");
} catch (NoSuchTileSetException te) { } catch (NoSuchTileSetException te) {
Log.warning("Scene contains non-existent object tileset " + Log.warning("Scene contains non-existent object tileset " +
"[info=" + info + "]."); "[info=" + info + "].");
@@ -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 // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // 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.ImageManager;
import com.threerings.media.image.ImageUtil; import com.threerings.media.image.ImageUtil;
import com.threerings.media.tile.NoSuchTileException;
import com.threerings.media.tile.NoSuchTileSetException; import com.threerings.media.tile.NoSuchTileSetException;
import com.threerings.media.tile.Tile; import com.threerings.media.tile.Tile;
import com.threerings.media.tile.TileManager; import com.threerings.media.tile.TileManager;
@@ -157,9 +156,6 @@ public class AutoFringer
try { try {
ftimg = getTileImage(ftimg, fringers[ii].baseset, ftimg = getTileImage(ftimg, fringers[ii].baseset,
indexes[jj], masks, hashValue); indexes[jj], masks, hashValue);
} catch (NoSuchTileException nste) {
Log.warning("Autofringer couldn't find a needed tile " +
"[error=" + nste + "].");
} catch (NoSuchTileSetException nstse) { } catch (NoSuchTileSetException nstse) {
Log.warning("Autofringer couldn't find a needed tileset " + Log.warning("Autofringer couldn't find a needed tileset " +
"[error=" + nstse + "]."); "[error=" + nstse + "].");
@@ -176,7 +172,7 @@ public class AutoFringer
protected BufferedImage getTileImage ( protected BufferedImage getTileImage (
BufferedImage ftimg, int baseset, int index, BufferedImage ftimg, int baseset, int index,
HashMap masks, int hashValue) HashMap masks, int hashValue)
throws NoSuchTileException, NoSuchTileSetException throws NoSuchTileSetException
{ {
FringeConfiguration.FringeTileSetRecord tsr = FringeConfiguration.FringeTileSetRecord tsr =
_fringeconf.getFringe(baseset, hashValue); _fringeconf.getFringe(baseset, hashValue);
@@ -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 // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // 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.samskivert.io.PersistenceException;
import com.threerings.media.tile.NoSuchTileException;
import com.threerings.media.tile.NoSuchTileSetException; import com.threerings.media.tile.NoSuchTileSetException;
import com.threerings.media.tile.TileSet; import com.threerings.media.tile.TileSet;
import com.threerings.media.tile.TileSetRepository; import com.threerings.media.tile.TileSetRepository;
@@ -46,7 +45,7 @@ import com.threerings.miso.data.ObjectInfo;
public class ScrollingScene extends MisoSceneModel public class ScrollingScene extends MisoSceneModel
{ {
public ScrollingScene (MisoContext ctx) public ScrollingScene (MisoContext ctx)
throws NoSuchTileSetException, NoSuchTileException, PersistenceException throws NoSuchTileSetException, PersistenceException
{ {
// locate the water tileset // locate the water tileset
TileSetRepository tsrepo = ctx.getTileManager().getTileSetRepository(); TileSetRepository tsrepo = ctx.getTileManager().getTileSetRepository();