public void computeMemoryUsage ( Map < Tile . Key , BaseTile > bases , Set < BaseTile > fringes , Map < Tile . Key , ObjectTile > objects , long [ ] usage ) { // account for our base tiles for ( int yy = 0 ; yy < _bounds . height ; yy ++ ) { for ( int xx = 0 ; xx < _bounds . width ; xx ++ ) { int x = _bounds . x + xx , y = _bounds . y + yy ; int tidx = index ( x , y ) ; BaseTile base = _base [ tidx ] ; if ( base == null ) { continue ; } BaseTile sbase = bases . get ( base . key ) ; if ( sbase == null ) { bases . put ( base . key , base ) ; usage [ 0 ] += base . getEstimatedMemoryUsage ( ) ; } else if ( base != _base [ tidx ] ) { log . warning ( "Multiple instances of same base tile " + "[base=" + base + ", x=" + xx + ", y=" + yy + "]." ) ; usage [ 0 ] += base . getEstimatedMemoryUsage ( ) ; } // now account for the fringe if ( _fringe [ tidx ] == null ) { continue ; } else if ( ! fringes . contains ( _fringe [ tidx ] ) ) { fringes . add ( _fringe [ tidx ] ) ; usage [ 1 ] += _fringe [ tidx ] . getEstimatedMemoryUsage ( ) ; } } } // now get the object tiles int ocount = ( _objects == null ) ? 0 : _objects . length ; for ( int ii = 0 ; ii < ocount ; ii ++ ) { SceneObject scobj = _objects [ ii ] ; ObjectTile tile = objects . get ( scobj . tile . key ) ; if ( tile == null ) { objects . put ( scobj . tile . key , scobj . tile ) ; usage [ 2 ] += scobj . tile . getEstimatedMemoryUsage ( ) ; } else if ( tile != scobj . tile ) { log . warning ( "Multiple instances of same object tile: " + scobj . info + "." ) ; usage [ 2 ] += scobj . tile . getEstimatedMemoryUsage ( ) ; } } }
Computes the memory usage of the base and object tiles in this scene block ; registering counted tiles in the hash map so that other blocks can be sure not to double count them . Base tile usage is placed into the zeroth array element fringe tile usage into the first and object tile usage into the second .