private void ApplyNewData(Context context, RasterDataDetails details) { // This is the start of a new frame, so the next request goes at the end details.RequestInsertionPoint = null; #if SingleThreaded details.RequestQueue.ProcessQueue(); #endif List <TileLoadRequest> tiles = new List <TileLoadRequest>(); EventHandler <MessageQueueEventArgs> handler = delegate(object sender, MessageQueueEventArgs e) { TileLoadRequest tile = (TileLoadRequest)e.Message; details.LoadedTiles[tile.Tile.Identifier] = tile.Texture; details.LoadingTiles.Remove(tile.Tile.Identifier); tiles.Add(tile); }; details.DoneQueue.MessageReceived += handler; details.DoneQueue.ProcessQueue(); details.DoneQueue.MessageReceived -= handler; foreach (TileLoadRequest tile in tiles) { ApplyNewTile(context, details, tile.Level, tile.Tile); } }
private void RequestTileLoad(RasterDataDetails details, ClipmapLevel level, RasterTile tile) { LinkedListNode <TileLoadRequest> requestNode; bool exists = details.LoadingTiles.TryGetValue(tile.Identifier, out requestNode); if (!exists) { // Create a new request. TileLoadRequest request = new TileLoadRequest(); request.Level = level; request.Tile = tile; requestNode = new LinkedListNode <TileLoadRequest>(request); } lock (details.RequestList) { if (exists) { // Remove the existing request from the queue so we can re-insert it // in its new location. if (requestNode.List == null) { // Request was in the queue at one point, but it's not anymore. // That means it's been loaded, so we don't need to do anything. return; } details.RequestList.Remove(requestNode); } if (details.RequestInsertionPoint == null || details.RequestInsertionPoint.List == null) { details.RequestList.AddLast(requestNode); } else { details.RequestList.AddBefore(details.RequestInsertionPoint, requestNode); } details.RequestInsertionPoint = requestNode; // If the request list has too many entries, delete from the beginning const int MaxRequests = 500; while (details.RequestList.Count > MaxRequests) { LinkedListNode <TileLoadRequest> nodeToRemove = details.RequestList.First; details.RequestList.RemoveFirst(); details.LoadingTiles.Remove(nodeToRemove.Value.Tile.Identifier); } Monitor.Pulse(details.RequestList); } details.LoadingTiles[tile.Identifier] = requestNode; }
private void RequestThreadEntryPoint(object state) { RasterDataDetails details = (RasterDataDetails)state; details.WorkerWindow.Context.MakeCurrent(); while (true) { TileLoadRequest request = null; lock (details.RequestList) { LinkedListNode <TileLoadRequest> lastNode = details.RequestList.Last; if (lastNode != null) { request = lastNode.Value; details.RequestList.RemoveLast(); } else { Monitor.Wait(details.RequestList); lastNode = details.RequestList.Last; if (lastNode != null) { request = lastNode.Value; details.RequestList.RemoveLast(); } } } if (request != null) { RasterTile tile = request.Tile; request.Texture = tile.LoadTexture(); Fence fence = Device.CreateFence(); fence.ClientWait(); details.DoneQueue.Post(request); } } }
private void RequestTileLoad(RasterDataDetails details, ClipmapLevel level, RasterTile tile) { LinkedListNode<TileLoadRequest> requestNode; bool exists = details.LoadingTiles.TryGetValue(tile.Identifier, out requestNode); if (!exists) { // Create a new request. TileLoadRequest request = new TileLoadRequest(); request.Level = level; request.Tile = tile; requestNode = new LinkedListNode<TileLoadRequest>(request); } lock (details.RequestList) { if (exists) { // Remove the existing request from the queue so we can re-insert it // in its new location. if (requestNode.List == null) { // Request was in the queue at one point, but it's not anymore. // That means it's been loaded, so we don't need to do anything. return; } details.RequestList.Remove(requestNode); } if (details.RequestInsertionPoint == null || details.RequestInsertionPoint.List == null) { details.RequestList.AddLast(requestNode); } else { details.RequestList.AddBefore(details.RequestInsertionPoint, requestNode); } details.RequestInsertionPoint = requestNode; // If the request list has too many entries, delete from the beginning const int MaxRequests = 500; while (details.RequestList.Count > MaxRequests) { LinkedListNode<TileLoadRequest> nodeToRemove = details.RequestList.First; details.RequestList.RemoveFirst(); details.LoadingTiles.Remove(nodeToRemove.Value.Tile.Identifier); } Monitor.Pulse(details.RequestList); } details.LoadingTiles[tile.Identifier] = requestNode; }