public static Tile GetTileNow(int level, int x, int y, IImageSet dataset, Tile parent) { if (level < dataset.BaseLevel) { return(null); } Tile retTile = null; long tileKey = ImageSetHelper.GetTileKey(dataset, level, x, y); try { if (!tiles.ContainsKey(tileKey)) { retTile = ImageSetHelper.GetNewTile(dataset, level, x, y, parent); tileMutex.WaitOne(); tiles.Add(tileKey, retTile); tileMutex.ReleaseMutex(); } else { retTile = tiles[tileKey]; } } catch { if (Earth3d.Logging) { Earth3d.WriteLogMessage("GetTile: Exception"); } } finally { //todoperf get rid of this write for GC retTile.AccessCount = AccessID++; } // Create if not ready to render if (!retTile.ReadyToRender) { TileCache.GetTileFromWeb(retTile, false); retTile.CreateGeometry(Earth3d.MainWindow.RenderContext11, false); } return(retTile); }
public static void QueueThread() { System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US", false); bool fileOnly = fileOnlyThreadID == Thread.CurrentThread.ManagedThreadId; while (running) { if (queue.Count < 1) { System.Threading.Thread.Sleep(50); } else { System.Threading.Thread.Sleep(1); } double minDistance = 1000000000000000000; bool overlayTile = false; long maxKey = 0; int level = 1000; queueMutex.WaitOne(); foreach (Tile t in queue.Values) { if (!t.RequestPending) // && t.InViewFrustum) { Vector3d vectTemp = new Vector3d(t.SphereCenter); vectTemp.TransformCoordinate(Earth3d.WorldMatrix); if (Earth3d.MainWindow.Space) { vectTemp.Subtract(new Vector3d(0.0f, 0.0f, -1.0f)); } else { vectTemp.Subtract(Earth3d.MainWindow.RenderContext11.CameraPosition); } double distTemp = Math.Max(0, vectTemp.Length() - t.SphereRadius); bool thisIsOverlay = (t.Dataset.Projection == ProjectionType.Tangent) || (t.Dataset.Projection == ProjectionType.SkyImage); if (distTemp < minDistance && (!overlayTile || thisIsOverlay)) { Tile test = (Tile)queue[t.Key]; if (!test.FileChecked) { test.FileExists = File.Exists(test.FileName); test.FileChecked = true; if (test.Volitile) { test.FileExists = false; } } if (test.FileExists || (!test.FileExists && !fileOnly)) { minDistance = distTemp; maxKey = t.Key; level = t.Level; overlayTile = thisIsOverlay; } } } } if (maxKey != 0) { Tile workTile = (Tile)queue[maxKey]; workTile.RequestPending = true; TileCache.RequestCount++; queueMutex.ReleaseMutex(); TileCache.GetTileFromWeb(workTile, true); queueMutex.WaitOne(); TileCache.RequestCount--; workTile.RequestPending = false; queue.Remove(workTile.Key); } queueMutex.ReleaseMutex(); } return; }