protected FringeTile composeFringeTile ( FringerRec [ ] fringers , Map < FringeTile , WeakReference < FringeTile > > fringes , int hashValue , boolean passable , Map < Long , BufferedImage > masks ) { // sort the array so that higher priority fringers get drawn first QuickSort . sort ( fringers ) ; // Generate an identifier for the fringe tile being created as an array of the keys of its // component tiles in the order they'll be drawn in the fringe tile. List < Long > keys = Lists . newArrayList ( ) ; for ( FringerRec fringer : fringers ) { int [ ] indexes = getFringeIndexes ( fringer . bits ) ; FringeConfiguration . FringeTileSetRecord tsr = _fringeconf . getFringe ( fringer . baseset , hashValue ) ; int fringeset = tsr . fringe_tsid ; for ( int index : indexes ) { // Add a key for this tile as a long containing its base tile, the fringe set it's // working with and the index used in that set. keys . add ( ( ( ( long ) fringer . baseset ) << 32 ) + ( fringeset << 16 ) + index ) ; } } long [ ] fringeId = new long [ keys . size ( ) ] ; for ( int ii = 0 ; ii < fringeId . length ; ii ++ ) { fringeId [ ii ] = keys . get ( ii ) ; } FringeTile frTile = new FringeTile ( fringeId , passable ) ; // If the fringes map contains something with the same fringe identifier, this will pull // it out and we can use it instead. WeakReference < FringeTile > result = fringes . get ( frTile ) ; if ( result != null ) { FringeTile fringe = result . get ( ) ; if ( fringe != null ) { return fringe ; } } // There's no fringe with he same identifier, so we need to create the tile. BufferedImage img = null ; for ( FringerRec fringer : fringers ) { int [ ] indexes = getFringeIndexes ( fringer . bits ) ; FringeConfiguration . FringeTileSetRecord tsr = _fringeconf . getFringe ( fringer . baseset , hashValue ) ; for ( int index : indexes ) { try { img = getTileImage ( img , tsr , fringer . baseset , index , hashValue , masks ) ; } catch ( NoSuchTileSetException nstse ) { log . warning ( "Autofringer couldn't find a needed tileset" , nstse ) ; } } } frTile . setImage ( new BufferedMirage ( img ) ) ; fringes . put ( frTile , new WeakReference < FringeTile > ( frTile ) ) ; return frTile ; }
Compose a FringeTile out of the various fringe images needed .