Пример #1
0
        /// <summary>
        ///     Sends packets for this texture to a client until packetsToSend is
        ///     hit or the transfer completes
        /// </summary>
        /// <param name="client">Reference to the client that the packets are destined for</param>
        /// <param name="packetsToSend">Maximum number of packets to send during this call</param>
        /// <param name="packetsSent">Number of packets sent during this call</param>
        /// <returns>True if the transfer completes at the current discard level, otherwise false</returns>
        public bool SendPackets(LLClientView client, int packetsToSend, out int packetsSent)
        {
            packetsSent = 0;

            if (m_currentPacket <= m_stopPacket)
            {
                bool sendMore = true;

                if (!m_sentInfo || (m_currentPacket == 0))
                {
                    sendMore = !SendFirstPacket(client);

                    m_sentInfo = true;
                    ++m_currentPacket;
                    ++packetsSent;
                }
                if (m_currentPacket < 2)
                {
                    m_currentPacket = 2;
                }

                while (sendMore && packetsSent < packetsToSend && m_currentPacket <= m_stopPacket)
                {
                    sendMore = SendPacket(client);
                    ++m_currentPacket;
                    ++packetsSent;
                }
            }

            return(m_currentPacket > m_stopPacket);
        }
Пример #2
0
        bool SendPacket(LLClientView client)
        {
            if (client == null || m_asset == null)
            {
                return(false);
            }

            bool complete        = false;
            int  imagePacketSize = ((int)m_currentPacket == (TexturePacketCount()))
                                      ? LastPacketSize()
                                      : IMAGE_PACKET_SIZE;

            try
            {
                if ((CurrentBytePosition() + IMAGE_PACKET_SIZE) > m_asset.Length)
                {
                    imagePacketSize = LastPacketSize();
                    complete        = true;
                    if ((CurrentBytePosition() + imagePacketSize) > m_asset.Length)
                    {
                        imagePacketSize = m_asset.Length - CurrentBytePosition();
                        complete        = true;
                    }
                }

                // It's concievable that the client might request packet one
                // from a one packet image, which is really packet 0,
                // which would leave us with a negative imagePacketSize..
                if (imagePacketSize > 0)
                {
                    byte[] imageData       = new byte[imagePacketSize];
                    int    currentPosition = CurrentBytePosition();

                    try
                    {
                        Buffer.BlockCopy(m_asset, currentPosition, imageData, 0, imagePacketSize);
                    }
                    catch (Exception e)
                    {
                        MainConsole.Instance.ErrorFormat(
                            "[J2K Image]: Texture block copy for the first packet failed. textureid={0}, assetlength={1}, currentposition={2}, imagepacketsize={3}, exception={4}",
                            TextureID, m_asset.Length, currentPosition, imagePacketSize, e.Message);
                        return(false);
                    }

                    //Send the packet
                    client.SendImageNextPart((ushort)(m_currentPacket - 1), TextureID, imageData);
                }

                return(!complete);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Пример #3
0
        public LLImageManager(LLClientView client, IAssetService pAssetCache, IJ2KDecoder pJ2kDecodeModule)
        {
            m_client     = client;
            m_assetCache = pAssetCache;

            if (pAssetCache != null && m_missingImage == null)
            {
                m_missingImage = pAssetCache.Get("5748decc-f629-461c-9a36-a35a221fe21f");
            }

            if (m_missingImage == null)
            {
                MainConsole.Instance.Error(
                    "[ClientView] - Couldn't set missing image asset, falling back to missing image packet. This is known to crash the client");
            }

            m_j2kDecodeModule = pJ2kDecodeModule;
        }
Пример #4
0
        public LLImageManager(LLClientView client, IAssetService pAssetCache, IJ2KDecoder pJ2kDecodeModule)
        {
            m_client     = client;
            m_assetCache = pAssetCache;

            if (pAssetCache != null && m_missingImage == null)
            {
                //m_missingImage = pAssetCache.Get("5748decc-f629-461c-9a36-a35a221fe21f"); // this is just a blank texture. Not very useful -greythane-
                m_missingImage = pAssetCache.Get(Constants.MISSING_TEXTURE_ID);
            }
            if (m_missingImage == null)
            {
                MainConsole.Instance.Error(
                    "[ClientView] - Couldn't set missing image asset, falling back to missing image packet. This is known to crash the client");
            }

            m_j2kDecodeModule = pJ2kDecodeModule;
        }
Пример #5
0
        bool SendFirstPacket(LLClientView client)
        {
            if (client == null)
            {
                return(false);
            }

            if (m_asset == null)
            {
                MainConsole.Instance.Warn("[J2K Image]: Sending ImageNotInDatabase for texture " + TextureID);
                client.SendImageNotFound(TextureID);
                return(true);
            }
            if (m_asset.Length <= FIRST_PACKET_SIZE)
            {
                // We have less then one packet's worth of data
                client.SendImageFirstPart(1, TextureID, (uint)m_asset.Length, m_asset, 2);
                m_stopPacket = 0;
                return(true);
            }
            // This is going to be a multi-packet texture download
            byte[] firstImageData = new byte[FIRST_PACKET_SIZE];

            try
            {
                Buffer.BlockCopy(m_asset, 0, firstImageData, 0, FIRST_PACKET_SIZE);
            }
            catch (Exception)
            {
                MainConsole.Instance.ErrorFormat(
                    "[J2K Image]: Texture block copy for the first packet failed. textureid={0}, assetlength={1}",
                    TextureID, m_asset.Length);
                return(true);
            }

            client.SendImageFirstPart(TexturePacketCount(), TextureID, (uint)m_asset.Length, firstImageData,
                                      (byte)ImageCodec.J2C);
            return(false);
        }
 public AsyncPacketProcess(LLClientView pClientview, PacketMethod pMethod, Packet pPack)
 {
     ClientView = pClientview;
     Method     = pMethod;
     Pack       = pPack;
 }