private void AddImageToQueue(J2KImage image) { lock (m_syncRoot) try { m_queue.Enqueue(image, image.Priority); } catch (Exception) { } }
private J2KImage GetHighestPriorityImage() { J2KImage image = null; lock (m_syncRoot) { if (m_queue.Count > 0) { try { PriorityQueueItem<J2KImage, float> item; if (m_queue.TryDequeue(out item)) image = item.Value; } catch (Exception) { } } } return image; }
/// <summary> /// Handles an incoming texture request or update to an existing texture request /// </summary> /// <param name="newRequest"></param> public void EnqueueReq(TextureRequestArgs newRequest) { //Make sure we're not shutting down.. if (!m_shuttingdown) { // Do a linear search for this texture download J2KImage imgrequest = FindImage(newRequest); if (imgrequest != null) { if (newRequest.DiscardLevel == -1 && newRequest.Priority == 0f) { //MainConsole.Instance.Debug("[TEX]: (CAN) ID=" + newRequest.RequestedAssetID); try { lock (m_syncRoot) m_queue.Remove(imgrequest); } catch (Exception) { } } else { //MainConsole.Instance.DebugFormat("[TEX]: (UPD) ID={0}: D={1}, S={2}, P={3}", // newRequest.RequestedAssetID, newRequest.DiscardLevel, newRequest.PacketNumber, newRequest.Priority); //Check the packet sequence to make sure this isn't older than //one we've already received if (newRequest.requestSequence > imgrequest.LastSequence) { //Update the sequence number of the last RequestImage packet imgrequest.LastSequence = newRequest.requestSequence; //Update the requested discard level imgrequest.DiscardLevel = newRequest.DiscardLevel; //Update the requested packet number imgrequest.StartPacket = Math.Max(1, newRequest.PacketNumber); //Update the requested priority imgrequest.Priority = newRequest.Priority; lock (m_syncRoot) m_queue.Remove(imgrequest); AddImageToQueue(imgrequest); //Run an update imgrequest.RunUpdate(); } } } else { if (newRequest.DiscardLevel == -1 && newRequest.Priority == 0f) { //MainConsole.Instance.Debug("[TEX]: (CAN) ID=" + newRequest.RequestedAssetID); //MainConsole.Instance.DebugFormat("[TEX]: (IGN) ID={0}: D={1}, S={2}, P={3}", // newRequest.RequestedAssetID, newRequest.DiscardLevel, newRequest.PacketNumber, newRequest.Priority); } else { //MainConsole.Instance.DebugFormat("[TEX]: (NEW) ID={0}: D={1}, S={2}, P={3}", // newRequest.RequestedAssetID, newRequest.DiscardLevel, newRequest.PacketNumber, newRequest.Priority); imgrequest = new J2KImage() { J2KDecoder = m_j2kDecodeModule, AssetService = m_assetCache, AgentID = m_client.AgentId, InventoryAccessModule = m_client.Scene.RequestModuleInterface <IInventoryAccessModule>(), DiscardLevel = newRequest.DiscardLevel, StartPacket = Math.Max(1, newRequest.PacketNumber), Priority = newRequest.Priority, TextureID = newRequest.RequestedAssetID }; imgrequest.Priority = newRequest.Priority; //Add this download to the priority queue AddImageToQueue(imgrequest); //Run an update imgrequest.RunUpdate(); } } } }
public bool ProcessImageQueue(int packetsToSend) { int StartTime = Util.EnvironmentTickCount(); int packetsSent = 0; List <J2KImage> imagesToReAdd = new List <J2KImage>(); while (packetsSent < packetsToSend) { J2KImage image = GetHighestPriorityImage(); // If null was returned, the texture priority queue is currently empty if (image == null) { break; } //Break so that we add any images back that we might remove because they arn't finished decoding if (image.IsDecoded) { if (image.Layers == null) { //We don't have it, tell the client that it doesn't exist m_client.SendAssetUploadCompleteMessage((sbyte)AssetType.Texture, false, image.TextureID); packetsSent++; } else { int sent; bool imageDone = image.SendPackets(m_client, packetsToSend - packetsSent, out sent); packetsSent += sent; // If the send is complete, destroy any knowledge of this transfer if (!imageDone) { AddImageToQueue(image); } } } else { //Add it to the other queue and delete it from the top imagesToReAdd.Add(image); packetsSent++; //We tried to send one } } //Add all the ones we removed so that we wouldn't block the queue if (imagesToReAdd.Count != 0) { foreach (J2KImage image in imagesToReAdd) { AddImageToQueue(image); } } int EndTime = Util.EnvironmentTickCountSubtract(StartTime); IMonitorModule module = m_client.Scene.RequestModuleInterface <IMonitorModule>(); if (module != null) { IImageFrameTimeMonitor monitor = module.GetMonitor <IImageFrameTimeMonitor>(m_client.Scene); monitor.AddImageTime(EndTime); } lock (m_syncRoot) return(m_queue.Count > 0); }