コード例 #1
0
ファイル: TileSet.java プロジェクト: dosage/nenya
  /**
   * Creates a {@link Tile} object from this tileset corresponding to the specified tile id and
   * returns that tile. A null tile will never be returned, but one with an error image may be
   * returned if a problem occurs loading the underlying tileset image.
   *
   * @param tileIndex the index of the tile in the tileset. Tile indexes start with zero as the
   *     upper left tile and increase by one as the tiles move left to right and top to bottom over
   *     the source image.
   * @param zations colorizations to be applied to the tile image prior to returning it. These may
   *     be null for uncolorized images.
   * @return the tile object.
   */
  public Tile getTile(int tileIndex, Colorization[] zations) {
    Tile tile = null;

    // first look in the active set; if it's in use by anyone or in the cache, it will be in
    // the active set
    synchronized (_atiles) {
      _key.tileSet = this;
      _key.tileIndex = tileIndex;
      _key.zations = zations;
      SoftReference<Tile> sref = _atiles.get(_key);
      if (sref != null) {
        tile = sref.get();
      }
    }

    // if it's not in the active set, it's not in memory; so load it
    if (tile == null) {
      tile = createTile();
      tile.key = new Tile.Key(this, tileIndex, zations);
      initTile(tile, tileIndex, zations);
      synchronized (_atiles) {
        _atiles.put(tile.key, new SoftReference<Tile>(tile));
      }
    }

    // periodically report our image cache performance
    reportCachePerformance();

    return tile;
  }