Exemplo n.º 1
0
        public void RunUpdate()
        {
            //This is where we decide what we need to update
            //and assign the real discardLevel and packetNumber
            //assuming of course that the connected client might be bonkers

            if (!m_hasasset)
            {
                if (!m_asset_requested)
                {
                    m_asset_requested = true;
                    m_assetCache.Get(m_requestedUUID.ToString(), this, AssetReceived);
                }
            }
            else
            {
                if (!m_decoded)
                {
                    //We need to decode the requested image first
                    if (!m_decoderequested)
                    {
                        //Request decode
                        m_decoderequested = true;
                        // Do we have a jpeg decoder?
                        if (m_j2kDecodeModule != null)
                        {
                            if (Data == null)
                            {
                                J2KDecodedCallback(m_requestedUUID, new OpenJPEG.J2KLayerInfo[0]);
                            }
                            // Send it off to the jpeg decoder
                            m_j2kDecodeModule.decode(m_requestedUUID, Data, J2KDecodedCallback);
                        }
                        else
                        {
                            J2KDecodedCallback(m_requestedUUID, new OpenJPEG.J2KLayerInfo[0]);
                        }
                    }
                }
                else
                {
                    //discardLevel of -1 means just update the priority
                    if (m_requestedDiscardLevel != -1)
                    {
                        //Evaluate the discard level
                        //First, is it positive?
                        if (m_requestedDiscardLevel >= 0)
                        {
                            if (m_requestedDiscardLevel > Layers.Length - 1)
                            {
                                m_discardLevel = (sbyte)(Layers.Length - 1);
                            }
                            else
                            {
                                m_discardLevel = m_requestedDiscardLevel;
                            }

                            //Calculate the m_stopPacket
                            if (Layers.Length > 0)
                            {
                                m_stopPacket = (uint)GetPacketForBytePosition(Layers[(Layers.Length - 1) - m_discardLevel].End);
                                //I don't know why, but the viewer seems to expect the final packet if the file
                                //is just one packet bigger.
                                if (TexturePacketCount() == m_stopPacket + 1)
                                {
                                    m_stopPacket = TexturePacketCount();
                                }
                            }
                            else
                            {
                                m_stopPacket = TexturePacketCount();
                            }
                            //Don't reset packet number unless we're waiting or it's ahead of us
                            if (m_completedSendAtCurrentDiscardLevel || m_requestedPacketNumber > m_packetNumber)
                            {
                                m_packetNumber = m_requestedPacketNumber;
                            }

                            if (m_packetNumber <= m_stopPacket)
                            {
                                m_completedSendAtCurrentDiscardLevel = false;
                            }
                        }
                    }
                    else
                    {
                        m_packetNumber = m_stopPacket;
                    }
                }
            }
        }