Changeset 601

Show
Ignore:
Timestamp:
07/16/08 13:56:25 (2 months ago)
Author:
tom
Message:

slowly refactoring load queue in TileGrid in tween branch

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/tom-tweenlite/lib/com/modestmaps/core/TileGrid.as

    r600 r601  
    6060                protected var provider:IMapProvider; 
    6161 
    62                 // Tiles we want to load: 
    63                 protected var queue:Array = []; 
     62                protected var tileQueue:TileQueue; 
    6463                 
    6564                // per-tile, the number of images we're expecting to load 
     
    8382                // currently visible tiles 
    8483                protected var visibleTiles:Array = []; 
    85                  
    86                 // TODO: move to MapConfig 
    87                 public static var MAX_OPEN_REQUESTS:int = 4; 
    88                  
     84                                 
    8985                // number of tiles we're failing to show 
    9086                protected var blankCount:int = 0; 
     
    119115                protected static const DEFAULT_TILE_BUFFER:int = 0; 
    120116                protected static const DEFAULT_ENFORCE_BOUNDS:Boolean = true; 
     117                protected static const DEFAULT_MAX_OPEN_REQUESTS:int = 4; 
    121118 
    122119                /** if we don't have a tile at currentZoom, onRender will look for tiles up to 5 levels out. 
     
    135132                // 0 or 1, really: 2 will load *lots* of extra tiles 
    136133                public var tileBuffer:int = DEFAULT_TILE_BUFFER; 
     134                 
     135                // how many Loaders are allowed to be open at once? 
     136                public var maxOpenRequests:int = DEFAULT_MAX_OPEN_REQUESTS; 
    137137 
    138138                // set this to true to enable enforcing of map bounds from the map provider's limits 
     
    158158                        this.draggable = draggable; 
    159159                        this.provider = provider; 
     160 
     161                        this.tileQueue = new TileQueue(); 
    160162 
    161163                        doubleClickEnabled = true; 
     
    235237                                                + "\ncurrent child count: " + well.numChildren 
    236238                                                + "\nvisible tile count: " + visibleTiles.length 
    237                                                 + "\nqueue length: " + queue.length 
     239                                                + "\nqueue length: " + tileQueue.length 
    238240                                                + "\nblank count: " + blankCount 
    239241                                                + "\nrequests: " + openRequests.length 
     
    352354                                                        // keep a local copy of the URLs so we don't have to call this twice:  
    353355                                                        layersNeeded[tile] = provider.getTileUrls(coord); 
    354                                                         queue.push(tile); 
     356                                                        tileQueue.push(tile); 
    355357                                                } 
    356358                                                else { 
     
    527529                { 
    528530                        // prepare the queue 
    529                         if (openRequests.length < MAX_OPEN_REQUESTS && queue.length > 0) { 
     531                        if (openRequests.length < maxOpenRequests && tileQueue.length > 0) { 
    530532 
    531533                                // prune queue for tiles that aren't visible 
    532                                 queue = queue.filter(function(tile:Tile, i:int, a:Array):Boolean { 
    533                                         return visibleTiles.indexOf(tile) >= 0; 
    534                                 }); 
     534                                tileQueue.retainAll(visibleTiles); 
    535535                                 
    536536                                // note that queue is not the same as visible tiles, because things  
     
    539539         
    540540                                // sort queue by distance from 'center' 
    541                                 queue = queue.sort(centerDistanceCompare);                             
     541                                tileQueue.sortTiles(centerDistanceCompare);                            
    542542                        } 
    543543                         
    544544                        // process the queue 
    545                         while (openRequests.length < MAX_OPEN_REQUESTS && queue.length > 0) { 
    546                                 var tile:Tile = queue.shift() as Tile
     545                        while (openRequests.length < maxOpenRequests && tileQueue.length > 0) { 
     546                                var tile:Tile = tileQueue.shift()
    547547                                // if it's still on the stage: 
    548548                                if (tile.parent) { 
     
    598598                { 
    599599                        if (t1.zoom == t2.zoom && t1.zoom == currentZoom && t2.zoom == currentZoom) { 
    600                                 var d1:int = Math.pow(t1.row-centerRow,2) + Math.pow(t1.column-centerColumn,2);  
    601                                 var d2:int = Math.pow(t2.row-centerRow,2) + Math.pow(t2.column-centerColumn,2);  
     600                                var d1:int = Math.pow(t1.row+0.5-centerRow,2) + Math.pow(t1.column+0.5-centerColumn,2);  
     601                                var d2:int = Math.pow(t2.row+0.5-centerRow,2) + Math.pow(t2.column+0.5-centerColumn,2);  
    602602                                return d1 < d2 ? -1 : d1 > d2 ? 1 : 0;  
    603603                        } 
     
    982982                        openRequests = []; 
    983983                        recentlySeen = []; 
    984                         queue = [];                    
     984                        tileQueue.clear();                     
    985985                         
    986986                        dirty = true; 
     
    11541154} 
    11551155 
     1156import com.modestmaps.core.Tile;         
     1157 
     1158class TileQueue 
     1159{ 
     1160        // Tiles we want to load: 
     1161        protected var queue:Array; 
     1162         
     1163        public function TileQueue() 
     1164        { 
     1165                queue = []; 
     1166        } 
     1167         
     1168        public function get length():Number  
     1169        { 
     1170                return queue.length; 
     1171        } 
     1172         
     1173        public function push(tile:Tile):void 
     1174        { 
     1175                queue.push(tile); 
     1176        } 
     1177         
     1178        public function shift():Tile 
     1179        { 
     1180                return queue.shift() as Tile; 
     1181        } 
     1182         
     1183        public function sortTiles(callback:Function):void 
     1184        { 
     1185                queue = queue.sort(callback); 
     1186        } 
     1187         
     1188        public function retainAll(tiles:Array):void 
     1189        { 
     1190                var tilesToKeep:Array = tiles;  
     1191                queue = queue.filter(function(tile:Tile, i:int, a:Array):Boolean { 
     1192                        return tilesToKeep.indexOf(tile) >= 0; 
     1193                });              
     1194                tilesToKeep = null; 
     1195        } 
     1196         
     1197        public function clear():void 
     1198        { 
     1199                queue = []; 
     1200        } 
     1201         
     1202} 
     1203