コード例 #1
0
ファイル: Textures.cs プロジェクト: jhurliman/simian
        private bool ProcessImageQueue(int packetsToSend)
        {
            int packetsSent = 0;

            while (packetsSent < packetsToSend)
            {
                J2KImage image = GetHighestPriorityImage();

                // If null was returned, the texture priority queue is currently empty
                if (image == null)
                {
                    return(false);
                }

                int  sent;
                bool imageDone = image.SendPackets(packetsToSend - packetsSent, out sent);
                packetsSent += sent;

                // If the send is complete, destroy any knowledge of this transfer
                if (imageDone)
                {
                    RemoveImageFromQueue(image);
                }
            }

            return(m_priorityQueue.Count > 0);
        }
コード例 #2
0
ファイル: Textures.cs プロジェクト: jhurliman/simian
 private void RemoveImageFromQueue(J2KImage image)
 {
     lock (m_priorityQueue)
     {
         if (m_priorityQueue.Find(image.PriorityQueueHandle, out image))
         {
             try { m_priorityQueue.Delete(image.PriorityQueueHandle); }
             catch (Exception) { }
             m_queuedTextures.Remove(image.TextureID);
         }
     }
 }
コード例 #3
0
ファイル: Textures.cs プロジェクト: jhurliman/simian
        private J2KImage GetHighestPriorityImage()
        {
            J2KImage image = null;

            lock (m_priorityQueue)
            {
                if (!m_priorityQueue.IsEmpty)
                {
                    try { image = m_priorityQueue.FindMax(); }
                    catch (Exception) { }
                }
            }

            return(image);
        }
コード例 #4
0
ファイル: Textures.cs プロジェクト: jhurliman/simian
        private void UpdateImageInQueue(J2KImage image)
        {
            lock (m_priorityQueue)
            {
                J2KImage existingImage;
                if (m_priorityQueue.Find(image.PriorityQueueHandle, out existingImage))
                {
                    try
                    {
                        m_priorityQueue.Replace(image.PriorityQueueHandle, image);
                        return;
                    }
                    catch { }
                }

                image.PriorityQueueHandle = null;
                m_priorityQueue.Add(ref image.PriorityQueueHandle, image);
                m_queuedTextures[image.TextureID] = image;
            }
        }
コード例 #5
0
ファイル: Textures.cs プロジェクト: jhurliman/simian
        private void EnqueueRequest(LLAgent agent, UUID textureID, sbyte discardLevel, float priority, uint packetNumber, uint sequenceNumber)
        {
            J2KImage image;

            // Look up this texture download
            lock (m_priorityQueue)
                m_queuedTextures.TryGetValue(textureID, out image);

            if (image != null)
            {
                // Update for an existing texture request
                if (discardLevel == -1 && priority == 0f)
                {
                    //m_log.Debug("[TEX]: (CAN) ID=" + textureID);

                    try
                    {
                        lock (m_priorityQueue)
                        {
                            m_priorityQueue.Delete(image.PriorityQueueHandle);
                            m_queuedTextures.Remove(textureID);
                        }
                    }
                    catch (Exception) { }
                }
                else
                {
                    //m_log.DebugFormat("[TEX]: (UPD) ID={0}: D={1}, S={2}, P={3}", textureID, discardLevel, packetNumber, priority);

                    // Check the packet sequence to make sure this update isn't older than
                    // one we've already received
                    if (sequenceNumber > image.LastSequence)
                    {
                        // Update the sequence number of the last RequestImage packet
                        image.LastSequence = sequenceNumber;

                        //Update the requested discard level
                        image.DiscardLevel = discardLevel;

                        //Update the requested packet number
                        image.StartPacket = Math.Max(1, packetNumber);

                        //Update the requested priority
                        image.Priority = priority;

                        // Update the start/end offsets for this request
                        image.UpdateOffsets();

                        UpdateImageInQueue(image);
                    }
                }
            }
            else
            {
                // New texture request
                if (discardLevel == -1 && priority == 0f)
                {
                    //m_log.DebugFormat("[TEX]: (IGN) ID={0}", textureID);
                }
                else
                {
                    //m_log.DebugFormat("[TEX]: (NEW) ID={0}: D={1}, S={2}, P={3}", textureID, discardLevel, packetNumber, priority);

                    Asset asset;
                    if (m_assetClient.TryGetAsset(textureID, "image/x-j2c", out asset))
                    {
                        image = new J2KImage(m_udp, asset, agent, discardLevel, Math.Max(1, packetNumber), priority);

                        // Update the start/end offsets for this request
                        image.UpdateOffsets();

                        // Add this download to the priority queue
                        UpdateImageInQueue(image);
                    }
                    else
                    {
                        ImageNotInDatabasePacket missing = new ImageNotInDatabasePacket();
                        missing.ImageID.ID = textureID;
                        m_udp.SendPacket(agent, missing, ThrottleCategory.Asset, true);
                    }
                }
            }
        }