Changeset 605
- Timestamp:
- 07/17/08 00:09:34 (4 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/tom-tweenlite/lib/com/modestmaps/core/TileGrid.as
r603 r605 164 164 165 165 this.tileQueue = new TileQueue(); 166 this.tileCache = new TileCache( );166 this.tileCache = new TileCache(map); 167 167 168 168 doubleClickEnabled = true; … … 233 233 234 234 if (debugField.parent) { 235 debugField.text = "tx: " + tx.toFixed(3) + " ty: " + tx.toFixed(3) + " sc: " + scale.toFixed(4) 235 debugField.text = "tx: " + tx.toFixed(3) 236 + "\nty: " + tx.toFixed(3) 237 + "\nsc: " + scale.toFixed(4) 236 238 + "\nfps: " + fps.toFixed(0) 237 239 + "\ncurrent child count: " + well.numChildren … … 242 244 + "\nfinished tiles: " + tileCache.size 243 245 + "\nrecently used tiles: " + recentlySeen.length 246 + "\nTiles created: " + map.tileCount 244 247 + "\nmemory: " + (System.totalMemory/1048576).toFixed(1) + "MB"; 245 248 debugField.width = debugField.textWidth+8; 246 249 debugField.height = debugField.textHeight+4; 250 debugField.x = mapWidth - debugField.width - 15; 251 debugField.y = mapHeight - debugField.height - 15; 247 252 } 248 253 … … 446 451 } 447 452 453 /* trace((maxCol - minCol + 1) * (maxRow - minRow + 1), "tiles visible at currentZoom"); 454 trace(visibleTiles.length, " tiles visible"); */ 455 448 456 // make absolutlely sure all our newly visible tiles are cached if they're done loading 449 457 // TODO: this should probably happen onLoadEnd when there are no URLs left? … … 466 474 well.removeChild(tile); 467 475 tile.hide(); 468 } 469 } 476 if (!tileCache.containsKey(tile.name)) { 477 //trace("destroying tile that was in the well but never cached"); 478 map.destroyTile(tile); 479 } 480 } 481 } 482 483 //trace(well.numChildren, " tiles in the well"); 470 484 471 485 // sort children by difference from current zoom level … … 491 505 var tileScale:Number = Math.pow(2, zoomLevel-tile.zoom); 492 506 tileScale = Math.ceil(tileScale * tileWidth) / tileWidth; // round up to the nearest pixel 493 tile.scaleX = tile.scaleY = tileScale; 494 495 if (tile.zoom != currentZoom && tile.alpha < 1) { 496 trace("showing now!"); 497 tile.showNow(); 498 } 507 tile.scaleX = tile.scaleY = tileScale; 499 508 } 500 509 501 510 // all the visible tiles will be at the end of recentlySeen 502 511 // let's make sure we keep them around: 503 var maxRecentlySeen:int = Math.max(visibleTiles.length,maxTilesToKeep); 512 var maxRecentlySeen:int = Math.max(visibleTiles.length, maxTilesToKeep); 513 514 /* trace("maxRecentlySeen is", maxRecentlySeen); 515 trace("recentlySeen.length is", recentlySeen.length); */ 504 516 505 517 // prune cache of already seen tiles if it's getting too big: 506 518 if (recentlySeen.length > maxRecentlySeen) { 519 //trace("... and that's too big"); 520 507 521 // throw away keys at the beginning of recentlySeen 508 recentlySeen = recentlySeen.slice(recentlySeen.length - maxTilesToKeep, recentlySeen.length); 522 recentlySeen = recentlySeen.slice(recentlySeen.length - maxRecentlySeen, recentlySeen.length); 523 524 /* trace("recentlySeen.length is now", recentlySeen.length); 525 526 trace("trimming cache from", tileCache.size); */ 527 509 528 // loop over our internal tile cache 510 529 // and throw out tiles not in recentlySeen 511 530 tileCache.retainKeys(recentlySeen); 531 532 // trace("to", tileCache.size); 512 533 } 513 534 … … 979 1000 980 1001 while (well.numChildren > 0) { 981 well.removeChildAt(0); 1002 var tile:Tile = well.removeChildAt(0) as Tile; 1003 if (!tileCache.containsKey(tile.name)) { 1004 map.destroyTile(tile); 1005 } 982 1006 } 983 1007 … … 1180 1204 1181 1205 import com.modestmaps.core.Tile; 1182 import flash.utils.Dictionary; 1206 import flash.utils.Dictionary; 1207 import com.modestmaps.Map; 1183 1208 1184 1209 class TileQueue … … 1232 1257 // Tiles we've already seen and fully loaded, by key (.name) 1233 1258 protected var alreadySeen:Dictionary; 1234 1235 public function TileCache() 1236 { 1259 protected var map:Map; // for handing tiles back! 1260 1261 public function TileCache(map:Map) 1262 { 1263 this.map = map; 1237 1264 alreadySeen = new Dictionary(); 1238 1265 } … … 1267 1294 for (var key:String in alreadySeen) { 1268 1295 if (keys.indexOf(key) < 0) { 1296 map.destroyTile(alreadySeen[key] as Tile); 1269 1297 delete alreadySeen[key]; 1270 1298 } … … 1275 1303 { 1276 1304 for (var key:String in alreadySeen) { 1305 map.destroyTile(alreadySeen[key] as Tile); 1277 1306 delete alreadySeen[key]; 1278 1307 } branches/tom-tweenlite/lib/com/modestmaps/Map.as
r600 r605 156 156 setExtent(extent); 157 157 } 158 159 //addChild(grid.debugField); 158 160 } 159 161 … … 841 843 } 842 844 845 protected var tilePool:Array = []; 846 public var tileCount:int = 0; 847 848 protected function getTileFromPool(column:int, row:int, zoom:int):Tile 849 { 850 if (tilePool.length > 0) { 851 var tile:Tile = tilePool.shift() as Tile; 852 tile.row = row; 853 tile.column = column; 854 tile.zoom = zoom; 855 tile.hide(); 856 return tile; 857 } 858 return null; 859 } 860 843 861 /** override this if you want to create your own tiles */ 844 862 public function createTile(column:int, row:int, zoom:int):Tile 845 863 { 864 var tile:Tile = getTileFromPool(column, row, zoom); 865 if (tile) { 866 return tile; 867 } 868 trace("made", tileCount++, "tiles"); 846 869 return new Tile(column, row, zoom); 870 } 871 872 /** once TileGrid is done with a tile, it will hand it back to you */ 873 public function destroyTile(tile:Tile):void 874 { 875 while (tile.numChildren > 0) { 876 tile.removeChildAt(0); 877 } 878 tilePool.push(tile); 847 879 } 848 880 branches/tom-tweenlite/lib/com/modestmaps/TweenMap.as
r599 r605 257 257 override public function createTile(column:int, row:int, zoom:int):Tile 258 258 { 259 var tile:Tile = getTileFromPool(column, row, zoom); 260 if (tile) { 261 return tile; 262 } 263 tileCount++; 259 264 return new TweenTile(column, row, zoom); 260 265 }
