Changeset 618

Show
Ignore:
Timestamp:
07/18/08 11:35:03 (1 month ago)
Author:
tom
Message:

fixed some bugs in the tweenlite branch where (rarely) a tile could end up on the stage with no children

Files:

Legend:

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

    r616 r618  
    7373                // they are free to check the bounds of their overlays and don't have to serve 
    7474                // millions of 404s 
    75                 protected var layersNeeded:Dictionary = new Dictionary(true)
     75                protected var layersNeeded:Object = {}
    7676 
    7777                // keys we've recently seen 
     
    233233                        fps = (0.9 * fps) + (0.1 * (1000.0/frameDuration)); 
    234234 
    235                         // report stats: 
    236                          
    237235                        if (debugField.parent) { 
     236                                // report stats: 
     237                                var tileChildren:int = 0; 
     238                                for (var i:int = 0; i < well.numChildren; i++) { 
     239                                        tileChildren += Tile(well.getChildAt(i)).numChildren; 
     240                                }   
     241/*                              debugField.text = "fps: " + fps.toFixed(0) 
     242                                                + "\nmemory: " + (System.totalMemory/1048576).toFixed(1) + "MB"; */ 
     243  
    238244                                debugField.text = "tx: " + tx.toFixed(3) 
    239245                                                + "\nty: " + tx.toFixed(3) 
     
    241247                                                + "\nfps: " + fps.toFixed(0) 
    242248                                                + "\ncurrent child count: " + well.numChildren 
     249                                                + "\ncurrent child of tile count: " + tileChildren 
    243250                                                + "\nvisible tile count: " + visibleTiles.length 
    244251                                                + "\nqueue length: " + tileQueue.length 
     
    248255                                                + "\nrecently used tiles: " + recentlySeen.length 
    249256                                                + "\nTiles created: " + map.tileCount 
    250                                                 + "\nmemory: " + (System.totalMemory/1048576).toFixed(1) + "MB"; 
     257                                                + "\nmemory: " + (System.totalMemory/1048576).toFixed(1) + "MB";  
    251258                                debugField.width = debugField.textWidth+8; 
    252259                                debugField.height = debugField.textHeight+4; 
     
    340347                        for each (var visibleTile:Tile in visibleTiles) { 
    341348                                // if we're done loading this one, add/move it to the end of recently seen: 
    342                                 if (!layersNeeded[visibleTile]) { 
     349                                if (!layersNeeded[visibleTile.name]) { 
    343350                                        var ri:int = recentlySeen.indexOf(visibleTile.name);  
    344351                                        if (ri >= 0) { 
     
    358365                                        if (!tileCache.containsKey(wellTile.name)) { 
    359366                                                //trace("destroying tile that was in the well but never cached"); 
     367                                                delete layersNeeded[wellTile.name]; 
     368                                                if (tileQueue.contains(wellTile)) { 
     369                                                        tileQueue.remove(wellTile); 
     370                                                } 
    360371                                                map.destroyTile(wellTile); 
    361372                                        } 
     
    424435                                                        if (urls && urls.length > 0) { 
    425436                                                                // keep a local copy of the URLs so we don't have to call this twice: 
    426                                                                 layersNeeded[tile] = urls; 
     437                                                                layersNeeded[tile.name] = urls; 
    427438                                                                tileQueue.push(tile); 
    428439                                                        } 
     
    439450                                        visibleTiles.push(tile); 
    440451 
    441                                         var tileReady:Boolean = tile.isShowing() && (layersNeeded[tile] == null); 
     452                                        var tileReady:Boolean = tile.isShowing() && (layersNeeded[tile.name] == null); 
    442453                                         
    443454                                        // 
     
    551562 
    552563                                // prune queue for tiles that aren't visible 
    553                                 tileQueue.retainAll(visibleTiles); 
     564                                var removedTiles:Array = tileQueue.retainAll(visibleTiles); 
     565                                 
     566                                for each (var removedTile:Tile in removedTiles) { 
     567                                        delete layersNeeded[removedTile.name]; 
     568                                } 
    554569                                 
    555570                                // note that queue is not the same as visible tiles, because things  
     
    585600                { 
    586601                        // TODO: add urls to Tile? 
    587                         var urls:Array = layersNeeded[tile] as Array; 
     602                        var urls:Array = layersNeeded[tile.name] as Array; 
    588603                        if (urls && urls.length > 0) { 
    589604                                var url:* = urls.shift(); 
     
    608623                                } 
    609624                                tileCache.putTile(tile);                                         
    610                                 delete layersNeeded[tile]; 
     625                                delete layersNeeded[tile.name]; 
    611626                        }                        
    612627                } 
     
    688703                        } 
    689704                        else { 
    690                                 var urls:Array = layersNeeded[tile] as Array; 
    691                                 if (urls && urls.length == 0) { 
    692                                         tileCache.putTile(tile);                                         
    693                                         delete layersNeeded[tile]; 
    694                                 } 
     705                                // we've loaded an image, but its parent tile has been removed 
     706                                // so we'll have to throw it away 
    695707                        } 
    696708                        var index:int = openRequests.indexOf(loader); 
     
    709721                                        var tile:Tile = well.getChildByName(loader.name) as Tile; 
    710722                                        if (tile) { 
    711                                                 delete layersNeeded[tile]; 
     723                                                delete layersNeeded[tile.name]; 
    712724                                                tile.paintError(tileWidth, tileHeight); 
    713725                                                if (tile.zoom == currentZoom) { 
     
    764776                        return _invertedMatrix; 
    765777                } 
    766 /*              protected function set invertedMatrix(m:Matrix):void 
    767                 { 
    768                         throw new Error("invertedMatrix is read only"); 
    769                 } */ 
    770778 
    771779                /** derived from map provider by calculateBounds(), read-only here for convenience */ 
     
    806814                        return _topLeftCoordinate; 
    807815                } 
    808 /*              public function set topLeftCoordinate(c:Coordinate):void 
    809                 { 
    810                         throw new Error("topLeftCoordinate is read only"); 
    811                 } */ 
    812816 
    813817                public function get bottomRightCoordinate():Coordinate 
     
    819823                        return _bottomRightCoordinate; 
    820824                } 
    821 /*              public function set bottomRightCoordinate(c:Coordinate):void 
    822                 { 
    823                         throw new Error("bottomRightCoordinate is read only"); 
    824                 } */ 
    825825                                                 
    826826                // for backward compatibility: 
     
    10101010                                var tile:Tile = well.removeChildAt(0) as Tile; 
    10111011                                if (!tileCache.containsKey(tile.name)) { 
     1012                                        delete layersNeeded[tile.name]; 
    10121013                                        map.destroyTile(tile); 
    10131014                                } 
     
    10271028                        openRequests = []; 
    10281029                         
    1029                         for (var key:* in layersNeeded) { 
     1030                        for (var key:String in layersNeeded) { 
    10301031                                delete layersNeeded[key]; 
    10311032                        } 
    1032                         layersNeeded = new Dictionary(true);  
     1033                        layersNeeded = {};  
    10331034 
    10341035                        recentlySeen = []; 
     
    12301231                return queue.length; 
    12311232        } 
     1233 
     1234        public function contains(tile:Tile):Boolean 
     1235        { 
     1236                return queue.indexOf(tile) >= 0; 
     1237        } 
     1238 
     1239        public function remove(tile:Tile):void 
     1240        { 
     1241                var index:int = queue.indexOf(tile);  
     1242                if (index >= 0) {  
     1243                        queue.splice(index, 1); 
     1244                } 
     1245        } 
    12321246         
    12331247        public function push(tile:Tile):void 
    12341248        { 
     1249/*              if (contains(tile)) { 
     1250                        throw new Error("that tile is already on the queue!"); 
     1251                } */ 
    12351252                queue.push(tile); 
    12361253        } 
     
    12461263        } 
    12471264         
    1248         public function retainAll(tiles:Array):void 
    1249         { 
    1250                 var tilesToKeep:Array = tiles;  
    1251                 queue = queue.filter(function(tile:Tile, i:int, a:Array):Boolean { 
    1252                         return tilesToKeep.indexOf(tile) >= 0; 
    1253                 });              
    1254                 tilesToKeep = null; 
     1265        public function retainAll(tiles:Array):Array 
     1266        { 
     1267                var removed:Array = []; 
     1268                for (var i:int = queue.length-1; i >= 0; i--) { 
     1269                        var tile:Tile = queue[i] as Tile; 
     1270                        if (tiles.indexOf(tile) < 0) { 
     1271                                removed.push(tile); 
     1272                                queue.splice(i,1); 
     1273                        }  
     1274                } 
     1275                return removed; 
    12551276        } 
    12561277         
     
    12861307        { 
    12871308                alreadySeen[tile.name] = tile; 
     1309/*              if (tile.numChildren == 0) { 
     1310                        throw new Error("tile added to cache has no children!"); 
     1311                } */ 
    12881312                // TODO is a collision here an error? 
    12891313        } 
  • branches/tom-tweenlite/lib/com/modestmaps/Map.as

    r612 r618  
    905905                        } 
    906906                } 
     907                tile.graphics.clear(); 
    907908                tilePool.push(tile); 
    908909            }