/// <summary> /// Finds the "best" tile from queue /// </summary> public virtual GeoSpatialDownloadRequest GetClosestDownloadRequest() { GeoSpatialDownloadRequest closestRequest = null; float largestArea = float.MinValue; lock (m_downloadRequests.SyncRoot) { foreach (GeoSpatialDownloadRequest curRequest in m_downloadRequests.Values) { if (curRequest.IsDownloading) { continue; } QuadTile qt = curRequest.QuadTile; if (!m_camera.ViewFrustum.Intersects(qt.BoundingBox)) { continue; } float screenArea = qt.BoundingBox.CalcRelativeScreenArea(m_camera); if (screenArea > largestArea) { largestArea = screenArea; closestRequest = curRequest; } } } return(closestRequest); }
/// <summary> /// Removes a request from the download queue. /// </summary> public virtual void RemoveFromDownloadQueue(GeoSpatialDownloadRequest removeRequest) { lock (m_downloadRequests.SyncRoot) { QuadTile key = removeRequest.QuadTile; GeoSpatialDownloadRequest request = (GeoSpatialDownloadRequest)m_downloadRequests[key]; if (request != null) { m_downloadRequests.Remove(key); request.QuadTile.DownloadRequest = null; } } }
public void RenderDownloadProgress(DrawArgs drawArgs, GeoSpatialDownloadRequest request, int offset) { int halfIconHeight = 24; int halfIconWidth = 24; Vector3 projectedPoint = new Vector3(DrawArgs.ParentControl.Width - halfIconWidth - 10, DrawArgs.ParentControl.Height - 34 - 4 * offset, 0.5f); // Render progress bar if (progressBar == null) { progressBar = new ProgressBar(40, 4); } progressBar.Draw(drawArgs, projectedPoint.X, projectedPoint.Y + 24, request.ProgressPercent, World.Settings.DownloadProgressColor.ToArgb()); DrawArgs.Device.RenderState.ZBufferEnable = true; // Render server logo if (ServerLogoFilePath == null) { return; } if (m_iconTexture == null) { m_iconTexture = ImageHelper.LoadIconTexture(ServerLogoFilePath); } if (sprite == null) { using (Surface s = m_iconTexture.GetSurfaceLevel(0)) { SurfaceDescription desc = s.Description; m_spriteSize = new Rectangle(0, 0, desc.Width, desc.Height); } this.sprite = new Sprite(DrawArgs.Device); } float scaleWidth = (float)2.0f * halfIconWidth / m_spriteSize.Width; float scaleHeight = (float)2.0f * halfIconHeight / m_spriteSize.Height; this.sprite.Begin(SpriteFlags.AlphaBlend); this.sprite.Transform = Matrix.Transformation2D(new Vector2(0.0f, 0.0f), 0.0f, new Vector2(scaleWidth, scaleHeight), new Vector2(0, 0), 0.0f, new Vector2(projectedPoint.X, projectedPoint.Y)); this.sprite.Draw(m_iconTexture, m_spriteSize, new Vector3(1.32f * 48, 1.32f * 48, 0), new Vector3(0, 0, 0), World.Settings.DownloadLogoColor); this.sprite.End(); }
/// <summary> /// Render one of the 4 quadrants with optional download indicator /// </summary> private void Render(Device device, CustomVertex.PositionTextured[] verts, QuadTile child) { bool isMultitexturing = false; if (World.Settings.ShowDownloadIndicator && child != null) { // Check/display download activity GeoSpatialDownloadRequest request = child.DownloadRequest; if (child.isDownloadingTerrain) { device.SetTexture(1, QuadTileSet.DownloadTerrainTexture); isMultitexturing = true; } //else if (request != null) else if (child.WaitingForDownload) { if (child.IsDownloadingImage) { device.SetTexture(1, QuadTileSet.DownloadInProgressTexture); } else { device.SetTexture(1, QuadTileSet.DownloadQueuedTexture); } isMultitexturing = true; } } if (isMultitexturing) { device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.BlendTextureAlpha); } if (verts != null && vertexIndexes != null) { device.DrawIndexedUserPrimitives(PrimitiveType.TriangleList, 0, verts.Length, vertexIndexes.Length / 3, vertexIndexes, true, verts); } if (isMultitexturing) { device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.Disable); } }
public virtual void AddToDownloadQueue(CameraBase camera, GeoSpatialDownloadRequest newRequest) { QuadTile key = newRequest.QuadTile; key.WaitingForDownload = true; lock (m_downloadRequests.SyncRoot) { if (m_downloadRequests.Contains(key)) { return; } m_downloadRequests.Add(key, newRequest); if (m_downloadRequests.Count >= m_maxQueueSize) { //remove spatially farthest request GeoSpatialDownloadRequest farthestRequest = null; Angle curDistance = Angle.Zero; Angle farthestDistance = Angle.Zero; foreach (GeoSpatialDownloadRequest curRequest in m_downloadRequests.Values) { curDistance = MathEngine.SphericalDistance( curRequest.QuadTile.CenterLatitude, curRequest.QuadTile.CenterLongitude, camera.Latitude, camera.Longitude); if (curDistance > farthestDistance) { farthestRequest = curRequest; farthestDistance = curDistance; } } farthestRequest.Dispose(); farthestRequest.QuadTile.DownloadRequest = null; m_downloadRequests.Remove(farthestRequest.QuadTile); } } ServiceDownloadQueue(); }
public virtual void Dispose() { try { isInitialized = false; if (texture != null && !texture.Disposed) { texture.Dispose(); texture = null; } if (northWestChild != null) { northWestChild.Dispose(); northWestChild = null; } if (southWestChild != null) { southWestChild.Dispose(); southWestChild = null; } if (northEastChild != null) { northEastChild.Dispose(); northEastChild = null; } if (southEastChild != null) { southEastChild.Dispose(); southEastChild = null; } if (DownloadRequest != null) { QuadTileSet.RemoveFromDownloadQueue(DownloadRequest); DownloadRequest.Dispose(); DownloadRequest = null; } } catch {} }
public void RenderDownloadProgress(DrawArgs drawArgs, GeoSpatialDownloadRequest request) { int halfIconHeight = 24; int halfIconWidth = 24; Vector3 projectedPoint = new Vector3(DrawArgs.StaticParentControl.Width - halfIconWidth - 10, DrawArgs.StaticParentControl.Height - 34, 0.5f); // Render progress bar if (progressBar == null) { progressBar = new ProgressBar(40, 4); } progressBar.Draw(drawArgs, projectedPoint.X, projectedPoint.Y + 24, request.ProgressPercent, World.Settings.DownloadProgressColor.ToArgb()); DrawArgs.StaticDevice.RenderState.ZBufferEnable = true; // Render server logo if (ServerLogoFilePath == null) { return; } if (m_iconTexture == null) { m_iconTexture = ImageHelper.LoadIconTexture(ServerLogoFilePath); } if (sprite == null) { using (Surface s = m_iconTexture.GetSurfaceLevel(0)) { SurfaceDescription desc = s.Description; m_spriteSize = new Rectangle(0, 0, desc.Width, desc.Height); } this.sprite = new Sprite(DrawArgs.StaticDevice); } float scaleWidth = (float) 2.0f*halfIconWidth/m_spriteSize.Width; float scaleHeight = (float) 2.0f*halfIconHeight/m_spriteSize.Height; this.sprite.Begin(SpriteFlags.AlphaBlend); this.sprite.Transform = Matrix.Transformation2D(new Vector2(0.0f, 0.0f), 0.0f, new Vector2(scaleWidth, scaleHeight), new Vector2(0, 0), 0.0f, new Vector2(projectedPoint.X, projectedPoint.Y)); this.sprite.Draw(m_iconTexture, m_spriteSize, new Vector3(1.32f*48, 1.32f*48, 0), new Vector3(0, 0, 0), World.Settings.DownloadLogoColor); this.sprite.End(); }
/// <summary> /// Removes a request from the download queue. /// </summary> public virtual void RemoveFromDownloadQueue(GeoSpatialDownloadRequest removeRequest) { lock (m_downloadRequests.SyncRoot) { QuadTile key = removeRequest.QuadTile; GeoSpatialDownloadRequest request = (GeoSpatialDownloadRequest) m_downloadRequests[key]; if (request != null) { m_downloadRequests.Remove(key); request.QuadTile.DownloadRequest = null; } } }
public virtual void AddToDownloadQueue(CameraBase camera, GeoSpatialDownloadRequest newRequest) { QuadTile key = newRequest.QuadTile; key.WaitingForDownload = true; lock (m_downloadRequests.SyncRoot) { if (m_downloadRequests.Contains(key)) { return; } m_downloadRequests.Add(key, newRequest); if (m_downloadRequests.Count >= m_maxQueueSize) { //remove spatially farthest request GeoSpatialDownloadRequest farthestRequest = null; Angle curDistance = Angle.Zero; Angle farthestDistance = Angle.Zero; foreach (GeoSpatialDownloadRequest curRequest in m_downloadRequests.Values) { curDistance = MathEngine.SphericalDistance(curRequest.QuadTile.CenterLatitude, curRequest.QuadTile.CenterLongitude, camera.Latitude, camera.Longitude); if (curDistance > farthestDistance) { farthestRequest = curRequest; farthestDistance = curDistance; } } farthestRequest.Dispose(); farthestRequest.QuadTile.DownloadRequest = null; m_downloadRequests.Remove(farthestRequest.QuadTile); } } ServiceDownloadQueue(); }