ae1052a371
things compile and most things run so this is a good time to checkpoint. Let me recall: - Refactored the whole scene deal. - Revamped the XML parser stuff (now uses Digester). - Rethought the tile management. - Started tile bundle stuff. - Wrote some tests. - Did a bit of Mike-ification. Onward and moreward. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@621 542714f4-19e9-0310-aa3c-eee0fc999fb1
81 lines
2.2 KiB
Java
81 lines
2.2 KiB
Java
//
|
|
// $Id: TileLayer.java,v 1.1 2001/11/18 04:09:21 mdb Exp $
|
|
|
|
package com.threerings.media.tile;
|
|
|
|
/**
|
|
* The tile layer class is a convenience class provided to simplify the
|
|
* management of a two-dimensional array of tiles. It takes care of
|
|
* dereferencing the tile array efficiently with methods that the Java
|
|
* compiler should inline, and prevents the caller from having to do the
|
|
* indexing multiplication by hand every time.
|
|
*/
|
|
public final class TileLayer
|
|
{
|
|
/**
|
|
* Constructs a tile layer instance with the supplied tiles, width and
|
|
* height. The tiles should exist in row-major format (the first row
|
|
* of tiles followed by the second and so on).
|
|
*
|
|
* @exception IllegalArgumentException thrown if the size of the tiles
|
|
* array does not match the specified width and height.
|
|
*/
|
|
public TileLayer (Tile[] tiles, int width, int height)
|
|
{
|
|
// sanity check
|
|
if (tiles.length != width*height) {
|
|
String errmsg = "tiles.length != width*height";
|
|
throw new IllegalArgumentException(errmsg);
|
|
}
|
|
|
|
_tiles = tiles;
|
|
_width = width;
|
|
_height = height;
|
|
}
|
|
|
|
/**
|
|
* Returns the width of the layer in tiles.
|
|
*/
|
|
public int getWidth ()
|
|
{
|
|
return _width;
|
|
}
|
|
|
|
/**
|
|
* Returns the height of the layer in tiles.
|
|
*/
|
|
public int getHeight ()
|
|
{
|
|
return _height;
|
|
}
|
|
|
|
/**
|
|
* Fetches the tile at the specified row and column. Bounds checking
|
|
* is not done. Note that the parameters are column first, followed by
|
|
* row (x, y order rather than row, column order).
|
|
*/
|
|
public Tile getTile (int column, int row)
|
|
{
|
|
return _tiles[row*_width+column];
|
|
}
|
|
|
|
/**
|
|
* Sets the tile at the specified row and column. Bounds checking is
|
|
* not done. Note that the parameters are column first, followed by
|
|
* row (x, y order rather than row, column order).
|
|
*/
|
|
public void setTile (int column, int row, Tile tile)
|
|
{
|
|
_tiles[row*_width+column] = tile;
|
|
}
|
|
|
|
/** Our tiles array. */
|
|
private Tile[] _tiles;
|
|
|
|
/** The number of tiles in a row. */
|
|
private int _width;
|
|
|
|
/** The number of rows. */
|
|
private int _height;
|
|
}
|