private static void SendNextPacket() { if (!Playing) { return; } if (World.Player == null) { btnPlay.Text = "Play"; tbPos.Enabled = btnClose.Enabled = btnPlay.Enabled = btnStop.Enabled = btnRec.Enabled = true; tbPos.Value = tbPos.Minimum; if (m_PlayTimer != null && m_PlayTimer.Running) { m_PlayTimer.Stop(); } if (m_ScrollTimer != null && m_ScrollTimer.Running) { m_ScrollTimer.Stop(); } return; } int delay = 0; int totalDelay = 0; do { // peek ahead 1 byte... and no, BinaryReader does not have a peek function. if (m_GZIn.Compressed.ReadByte() == 0xFF) { break; } m_GZIn.Seek(-1, SeekOrigin.Current); ClientCommunication.ProcessPlaybackData(m_GZIn.Compressed); if (!m_GZIn.EndOfFile) { totalDelay += (delay = m_GZIn.Compressed.ReadInt32()); } } while ((totalDelay * SpeedScalar() < 2 || delay * SpeedScalar() < 2) && !m_GZIn.EndOfFile); m_Elapsed += TimeSpan.FromMilliseconds(totalDelay); UpdateTimeText(); //tbPos.Value = (int)m_Elapsed.TotalSeconds; if (!m_GZIn.EndOfFile) { m_PlayTimer = Timer.DelayedCallback(TimeSpan.FromMilliseconds(delay * SpeedScalar() * 0.75), m_SendNext); m_PlayTimer.Start(); } else { Stop(); } }
public static void OnScroll() { bool wasRunning = m_PlayTimer.Running; TimeSpan delay = TimeSpan.Zero; TimeSpan target = TimeSpan.FromSeconds(tbPos.Value); try { if (!Playing) { tbPos.Value = tbPos.Minimum; return; } else if (target <= m_Elapsed) { tbPos.Value = (int)m_Elapsed.TotalSeconds; return; } } catch { return; } if (wasRunning) { m_PlayTimer.Stop(); } PlayerData.ExternalZ = false; int sleepCount = 0; while (m_Elapsed < target && !m_GZIn.EndOfFile) { // peek ahead 1 byte... and no, BinaryReader doesnt have a peek function. byte peek = m_GZIn.Compressed.ReadByte(); if (peek == 0xFF) { break; } m_GZIn.Seek(-1, SeekOrigin.Current); ClientCommunication.ProcessPlaybackData(m_GZIn.Compressed); if (!m_GZIn.EndOfFile) { delay = TimeSpan.FromMilliseconds(m_GZIn.Compressed.ReadInt32()); m_Elapsed += delay; if (((++sleepCount) % 5) == 0) { tbPos.Value = (int)m_Elapsed.TotalSeconds; Application.DoEvents(); System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(1)); } } } try { tbPos.Value = (int)m_Elapsed.TotalSeconds; } catch { } UpdateTimeText(); ClientCommunication.ForceSendToClient(new MobileUpdate(World.Player)); ClientCommunication.ForceSendToClient(new MobileIncoming(World.Player)); if (wasRunning) // paused? { if (!m_GZIn.EndOfFile) { m_PlayTimer = Timer.DelayedCallback(delay, m_SendNext); m_PlayTimer.Start(); } else { Stop(); } } ClientCommunication.BeginCalibratePosition(); }