/// <summary> /// 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 /// </summary> public void RunUpdate() { if (!HasAsset) { if (!m_assetRequested || DateTime.UtcNow.Ticks > AssetRequestTime + ASSET_REQUEST_TIMEOUT) { // m_log.DebugFormat( // "[J2KIMAGE]: Requesting asset {0} from request in packet {1}, already requested? {2}, due to timeout? {3}", // TextureID, LastSequence, m_assetRequested, DateTime.UtcNow.Ticks > AssetRequestTime + ASSET_REQUEST_TIMEOUT); m_assetRequested = true; AssetRequestTime = DateTime.UtcNow.Ticks; AssetService.Get(TextureID.ToString(), this, AssetReceived); } } else { if (!IsDecoded) { //We need to decode the requested image first if (!m_decodeRequested) { //Request decode m_decodeRequested = true; // m_log.DebugFormat("[J2KIMAGE]: Requesting decode of asset {0}", TextureID); // Do we have a jpeg decoder? if (J2KDecoder != null) { if (m_asset == null) { J2KDecodedCallback(TextureID, new OpenJPEG.J2KLayerInfo[0]); } else { // Send it off to the jpeg decoder J2KDecoder.BeginDecode(TextureID, m_asset, J2KDecodedCallback); } } else { J2KDecodedCallback(TextureID, new OpenJPEG.J2KLayerInfo[0]); } } } else { // Check for missing image asset data if (m_asset == null) { //m_log.Warn("[J2KIMAGE]: RunUpdate() called with missing asset data (no missing image texture?). Canceling texture transfer"); m_currentPacket = m_stopPacket; return; } if (DiscardLevel >= 0 || m_stopPacket == 0) { // This shouldn't happen, but if it does, we really can't proceed if (m_layers == null) { m_log.Warn("[J2KIMAGE]: RunUpdate() called with missing Layers. Canceling texture transfer"); m_currentPacket = m_stopPacket; return; } int maxDiscardLevel = Math.Max(0, m_layers.Length - 1); // Treat initial texture downloads with a DiscardLevel of -1 a request for the highest DiscardLevel if (DiscardLevel < 0 && m_stopPacket == 0) { DiscardLevel = (sbyte)maxDiscardLevel; } // Clamp at the highest discard level DiscardLevel = (sbyte)Math.Min(DiscardLevel, maxDiscardLevel); //Calculate the m_stopPacket if (m_layers.Length > 0) { m_stopPacket = (uint)GetPacketForBytePosition(m_layers[(m_layers.Length - 1) - 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(); } //Give them at least two packets, to play nice with some broken viewers (SL also behaves this way) if (m_stopPacket == 1 && m_layers[0].End > FIRST_PACKET_SIZE) { m_stopPacket++; } m_currentPacket = StartPacket; } } } }
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 (!HasAsset) { if (!m_assetRequested) { m_assetRequested = true; AssetService.Get(TextureID.ToString(), this, AssetReceived); } } else { if (!IsDecoded) { //We need to decode the requested image first if (!m_decodeRequested) { //Request decode m_decodeRequested = true; // Do we have a jpeg decoder? if (J2KDecoder != null) { if (m_asset == null) { J2KDecodedCallback(TextureID, new OpenJPEG.J2KLayerInfo[0]); } else { // Send it off to the jpeg decoder J2KDecoder.BeginDecode(TextureID, m_asset, J2KDecodedCallback); } } else { J2KDecodedCallback(TextureID, new OpenJPEG.J2KLayerInfo[0]); } } } else { // Check for missing image asset data if (m_asset == null) { MainConsole.Instance.Debug( "[J2KIMAGE]: RunUpdate() called with missing asset data (no missing image texture?). Canceling texture transfer"); m_currentPacket = m_stopPacket; return; } if (DiscardLevel >= 0 || m_stopPacket == 0) { // This shouldn't happen, but if it does, we really can't proceed if (Layers == null) { MainConsole.Instance.Warn( "[J2KIMAGE]: RunUpdate() called with missing Layers. Canceling texture transfer"); m_currentPacket = m_stopPacket; return; } int maxDiscardLevel = Math.Max(0, Layers.Length - 1); // Treat initial texture downloads with a DiscardLevel of -1 a request for the highest DiscardLevel if (DiscardLevel < 0 && m_stopPacket == 0) { DiscardLevel = (sbyte)maxDiscardLevel; } // Clamp at the highest discard level DiscardLevel = (sbyte)Math.Min(DiscardLevel, maxDiscardLevel); //Calculate the m_stopPacket if (Layers.Length > 0) { m_stopPacket = (uint)GetPacketForBytePosition(Layers[(Layers.Length - 1) - 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(); } m_currentPacket = StartPacket; } } } }