General updating per initial code review. Created EditableSceneView

to separate scene display from editing functionality.  Load and
initialize managers in a fashion that more appropriately hides the
implementation details.  Tidied comments up a bit.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@103 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-07-23 18:52:51 +00:00
parent 00388caaa5
commit 2572535f95
19 changed files with 210 additions and 252 deletions
@@ -1,5 +1,5 @@
//
// $Id: ImageManager.java,v 1.2 2001/07/18 22:45:34 shaper Exp $
// $Id: ImageManager.java,v 1.3 2001/07/23 18:52:51 shaper Exp $
package com.threerings.media;
@@ -15,15 +15,12 @@ import java.util.Hashtable;
* The ImageManager class provides a single point of access for image
* retrieval and caching.
*
* <p> <b>Note:</b> The ImageManager must be initialized with a root
* AWT component before images can be retrieved, in the interest of
* allowing for proper preparation of images for optimal storage and
* eventual display.
* <p> <b>Note:</b> The ImageManager must be constructed with a root
* AWT component, in the interest of allowing for proper preparation
* of images for optimal storage and eventual display.
*/
public class ImageManager
{
public Toolkit tk = Toolkit.getDefaultToolkit();
/**
* Construct an ImageManager object with the ResourceManager from
* which it will obtain its data, and a root component to which
@@ -33,7 +30,7 @@ public class ImageManager
{
_rmgr = rmgr;
_root = root;
tk = root.getToolkit();
_tk = root.getToolkit();
}
/**
@@ -57,7 +54,7 @@ public class ImageManager
try {
byte[] data = _rmgr.getResourceAsBytes(fname);
img = tk.createImage(data);
img = _tk.createImage(data);
MediaTracker tracker = new MediaTracker(_root);
tracker.addImage(img, 0);
@@ -99,4 +96,5 @@ public class ImageManager
protected ResourceManager _rmgr;
protected Component _root;
protected Hashtable _imgs = new Hashtable();
protected Toolkit _tk = Toolkit.getDefaultToolkit();
}
+16 -8
View File
@@ -1,5 +1,5 @@
//
// $Id: Tile.java,v 1.6 2001/07/20 08:17:10 shaper Exp $
// $Id: Tile.java,v 1.7 2001/07/23 18:52:51 shaper Exp $
package com.threerings.miso.tile;
@@ -10,25 +10,33 @@ import java.awt.Image;
*/
public class Tile
{
public Image img; // the tile image
public short tsid; // the tile set identifier
public short tid; // the tile identifier within the set
/** The tile image. */
public Image img;
/** The tile set identifier. */
public short tsid;
/** The tile identifier within the set. */
public short tid;
/** The tile height in pixels. */
public short height; // the tile height in pixels
// height and width of a tile image in pixels
/** The height and width of a tile image in pixels. */
public static final int HEIGHT = 16;
public static final int WIDTH = 32;
// halved values of tile width/height in pixels for use in common
// tile-dimension-related calculations
/** Halved tile width in pixels for use in common calculations. */
public static final int HALF_HEIGHT = HEIGHT / 2;
/** Halved tile height in pixels for use in common calculations. */
public static final int HALF_WIDTH = WIDTH / 2;
/**
* Construct a new tile with the specified identifiers. Intended
* only for use by the TileManager. Do not use this method.
*
* @see com.threerings.miso.TileManager#getTile
* @see TileManager#getTile
*/
public Tile (int tsid, int tid)
{
@@ -1,16 +1,14 @@
//
// $Id: TileManager.java,v 1.9 2001/07/21 01:51:10 shaper Exp $
// $Id: TileManager.java,v 1.10 2001/07/23 18:52:51 shaper Exp $
package com.threerings.miso.tile;
import com.threerings.miso.Log;
import com.samskivert.util.ConfigUtil;
import com.samskivert.util.IntMap;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.ArrayList;
/**
@@ -33,7 +31,7 @@ public class TileManager
public Tile getTile (int tsid, int tid)
{
// the fully unique tile id is the conjoined tile set and tile id
int utid = tsid << 16 | tid;
int utid = (tsid << 16) | tid;
// look the tile up in our hash
Tile tile = (Tile) _tiles.get(utid);
@@ -65,30 +63,9 @@ public class TileManager
return _tsmgr;
}
/**
* Load all tileset objects described in the specified file into
* the set of available tilesets.
*/
public void loadTileSets (String fname)
{
try {
InputStream tis = ConfigUtil.getStream(fname);
if (tis == null) {
Log.warning("Couldn't find file [fname=" + fname + "].");
return;
}
_tsmgr.loadTileSets(tis);
} catch (IOException ioe) {
Log.warning("Exception loading tileset [fname=" + fname +
", ioe=" + ioe + "].");
}
}
// mapping from (tsid << 16 | tid) to tile objects
/** Cache of tiles that have been requested thus far. */
protected IntMap _tiles = new IntMap();
// our tile set manager
/** Our tileset manager. */
protected TileSetManager _tsmgr;
}
+31 -25
View File
@@ -1,24 +1,24 @@
//
// $Id: TileSet.java,v 1.9 2001/07/20 08:17:10 shaper Exp $
// $Id: TileSet.java,v 1.10 2001/07/23 18:52:51 shaper Exp $
package com.threerings.miso.tile;
import java.awt.Image;
import java.awt.image.*;
import com.samskivert.util.StringUtil;
import com.threerings.miso.Log;
import com.threerings.media.ImageManager;
import java.awt.Image;
import java.awt.Graphics2D;
import java.awt.image.*;
/**
* A tileset stores information on a single logical set of tiles. It
* provides a clean interface for the TileManager to retrieve
* individual tile images from a particular tile in the tileset.
*
* <p> The width of each tile in every tileset is a constant
* Tile.WIDTH in pixels. The tile count in each row can vary. The
* height of the tiles in each row can also vary. This information is
* obtained from the config object.
* <code>Tile.WIDTH</code> in pixels. The tile count in each row can
* vary. The height of the tiles in each row can also vary. This
* information is obtained from the config object.
*
* <p> Tiles are retrieved from the tile set by the TileManager, and
* are referenced by their tile id (essentially the tile number,
@@ -116,27 +116,33 @@ public class TileSet
buf.append(", tsid=").append(_tsid);
buf.append(", numtiles=").append(_numTiles);
buf.append(", rowheight={");
for (int ii = 0; ii < _rowHeight.length; ii++) {
if (ii > 0) buf.append(",");
buf.append(_rowHeight[ii]);
}
buf.append(", rowheight=");
StringUtil.toString(buf, _rowHeight);
buf.append("}, tilecount={");
for (int ii = 0; ii < _tileCount.length; ii++) {
if (ii > 0) buf.append(",");
buf.append(_tileCount[ii]);
}
buf.append(", tilecount=");
StringUtil.toString(buf, _tileCount);
return buf.append("}]").toString();
return buf.append("]").toString();
}
protected String _name; // the tileset name
protected String _imgFile; // the file containing the tile images
protected int _tsid; // the tileset unique identifier
protected int _rowHeight[]; // the height of each row in pixels
protected int _tileCount[]; // the number of tiles in each row
protected int _numTiles; // the total number of tiles
/** The tileset name. */
protected String _name;
/** The file containing the tile images. */
protected String _imgFile;
/** The tileset unique identifier. */
protected int _tsid;
/** The height of each row in pixels. */
protected int _rowHeight[];
/** The number of tiles in each row. */
protected int _tileCount[];
/** The total number of tiles. */
protected int _numTiles;
/** The image containing all tile images for this set. */
protected Image _imgTiles;
}
@@ -1,22 +1,15 @@
//
// $Id: TileSetManager.java,v 1.7 2001/07/21 01:51:10 shaper Exp $
// $Id: TileSetManager.java,v 1.8 2001/07/23 18:52:51 shaper Exp $
package com.threerings.miso.tile;
import com.threerings.media.ImageManager;
import java.awt.Image;
import java.io.InputStream;
import java.io.IOException;
import java.util.ArrayList;
public interface TileSetManager
{
/**
* Initialize the TileSetManager with the given ImageManager.
*/
public void init (ImageManager imgmgr);
/**
* Return the total number of tiles in the specified tileset.
*/
@@ -41,10 +34,4 @@ public interface TileSetManager
* Return the total number of tilesets.
*/
public int getNumTileSets ();
/**
* Load the tilesets described in the specified input stream into
* the set of available tilesets.
*/
public void loadTileSets (InputStream tis) throws IOException;
}
@@ -1,21 +1,27 @@
//
// $Id: TileSetManagerImpl.java,v 1.6 2001/07/21 01:51:10 shaper Exp $
// $Id: TileSetManagerImpl.java,v 1.7 2001/07/23 18:52:51 shaper Exp $
package com.threerings.miso.tile;
import com.threerings.media.ImageManager;
import com.samskivert.util.IntMap;
import java.awt.Image;
import java.io.*;
import java.util.ArrayList;
import java.util.Enumeration;
import com.samskivert.util.*;
import com.threerings.media.ImageManager;
public abstract class TileSetManagerImpl implements TileSetManager
{
public void init (ImageManager imgr)
/**
* Initialize the TileSetManager with a Config object to obtain
* configuration information and an ImageManager object for use in
* retrieving tile images.
*/
public void init (Config config, ImageManager imgmgr)
{
_imgr = imgr;
_imgmgr = imgmgr;
_config = config;
}
public int getNumTilesInSet (int tsid)
@@ -32,7 +38,7 @@ public abstract class TileSetManagerImpl implements TileSetManager
public Image getTileImage (int tsid, int tid)
{
TileSet tset = getTileSet(tsid);
return (tset != null) ? tset.getTileImage(_imgr, tid) : null;
return (tset != null) ? tset.getTileImage(_imgmgr, tid) : null;
}
public ArrayList getAllTileSets ()
@@ -41,12 +47,7 @@ public abstract class TileSetManagerImpl implements TileSetManager
if (size == 0) return null;
ArrayList list = new ArrayList();
Enumeration sets = _tilesets.elements();
for (int ii = 0; ii < size; ii++) {
list.add(sets.nextElement());
}
CollectionUtil.addAll(list, _tilesets.elements());
return list;
}
@@ -55,6 +56,7 @@ public abstract class TileSetManagerImpl implements TileSetManager
return _tilesets.size();
}
protected ImageManager _imgr;
protected Config _config;
protected ImageManager _imgmgr;
protected IntMap _tilesets = new IntMap();
}
@@ -1,5 +1,5 @@
//
// $Id: TileSetParser.java,v 1.2 2001/07/18 21:45:42 shaper Exp $
// $Id: TileSetParser.java,v 1.3 2001/07/23 18:52:51 shaper Exp $
package com.threerings.miso.tile;
@@ -15,16 +15,10 @@ import java.util.ArrayList;
public interface TileSetParser
{
/**
* Return all tileset objects constructed from any previous
* parsing activity.
* Read tileset description data from the given input stream and
* construct TileSet objects to suit. Return an ArrayList of all
* TileSet objects constructed, or a zero-length array if no
* tileset descriptions were fully parsed.
*/
public ArrayList getTileSets ();
/**
* Construct tileset objects from the tileset description data on
* the given input stream. Classes that implement this method
* should store the tileset objects for later retrieval via the
* <code>getTileSets()</code> method.
*/
public void loadTileSets (InputStream tis) throws IOException;
public ArrayList loadTileSets (InputStream tis) throws IOException;
}
@@ -1,5 +1,5 @@
//
// $Id: XMLTileSetParser.java,v 1.4 2001/07/20 23:41:12 shaper Exp $
// $Id: XMLTileSetParser.java,v 1.5 2001/07/23 18:52:51 shaper Exp $
package com.threerings.miso.tile;
@@ -75,10 +75,11 @@ public class XMLTileSetParser extends DefaultHandler
}
}
public void loadTileSets (InputStream tis) throws IOException
public ArrayList loadTileSets (InputStream tis) throws IOException
{
try {
XMLUtil.parse(this, tis);
return _tilesets;
} catch (ParserConfigurationException pce) {
throw new IOException(pce.toString());
@@ -88,13 +89,10 @@ public class XMLTileSetParser extends DefaultHandler
}
}
public ArrayList getTileSets ()
{
if (_tilesets.size() == 0) return null;
return _tilesets;
}
/** The XML element tag currently being processed. */
protected String _tag;
/** The tilesets constructed thus far. */
protected ArrayList _tilesets = new ArrayList();
// temporary storage of tileset object values