void MainLoop() { var now = DateTime.Now; Dictionary <int, string> myTable = new Dictionary <int, string>(); Dictionary <int, string> myTable2 = new Dictionary <int, string>(); PreviousFrames.Add(now); PreviousFrames.RemoveAll(f => f.AddSeconds(1) < now); var dt = Math.Max(0, Math.Min(0.1, (now - PreviousFrame).TotalSeconds)); PreviousFrame = now; Seek += TimeSpan.FromSeconds(dt * PlaybackSpeed); if (Decoder != null) { Decoder.Seek(Seek); var frame = Decoder.CurrentFrame.Data; if (frame != null) { if (!generating) { generating = true; Array.Copy(frame, 0, savedFrame, 0, frame.Length); #if true ThreadPool.QueueUserWorkItem(o => { try { bmp = generator.GenerateImage(savedFrame); update2(bmp); generating = false; } catch (Exception ex) { Console.WriteLine(ex.Message); //generator.GenerateImage(savedFrame); generating = false; } }); #else //non threaded image generation (slow) generator.GenerateImage(savedFrame); generating = false; #endif } } } else { var text = new[] { " PLACEHOLDER CONTROLS" , "" , "Ctrl+C Reconfigure TtyRecMonkey" , "Ctrl+O Open a ttyrec" , "Escape Close ttyrec and return here" , "Alt+Enter Toggle fullscreen" , "" , "ZXC Play backwards at x100, x10, or x1 speed" , " V Play / Pause" , " BNM Play forwards at 1x, x10, or x100 speed" , "" , " F Decrease speed by 1" , " G Increase speed by 1" , "" , " Space Play / Pause" , "" , " A / S Zoom In/Out" }; } //Text = string.Format // ("TtyRecMonkey -- {0} FPS -- {1} @ {2} of {3} ({4} keyframes {5} packets) -- Speed {6} -- GC recognized memory: {7}" // , PreviousFrames.Count // , PrettyTimeSpan(Seek) // , Decoder == null ? "N/A" : PrettyTimeSpan(Decoder.CurrentFrame.SinceStart) // , Decoder == null ? "N/A" : PrettyTimeSpan(Decoder.Length) // , Decoder == null ? "N/A" : Decoder.Keyframes.ToString() // , Decoder == null ? "N/A" : Decoder.PacketCount.ToString() // , PlaybackSpeed // , PrettyByteCount(GC.GetTotalMemory(false)) // ); // Text = "Console"; }
void MainLoop() { var now = DateTime.Now; PreviousFrames.Add(now); PreviousFrames.RemoveAll(f => f.AddSeconds(1) < now); var dt = Math.Max(0, Math.Min(0.1, (now - PreviousFrame).TotalSeconds)); PreviousFrame = now; Seek += TimeSpan.FromSeconds(dt * PlaybackSpeed); var BufferW = Buffer.GetLength(0); var BufferH = Buffer.GetLength(1); if (Decoder != null) { Decoder.Seek(Seek); var frame = Decoder.CurrentFrame.Data; if (frame != null) { for (int y = 0; y < BufferH; ++y) { for (int x = 0; x < BufferW; ++x) { var ch = (x < frame.GetLength(0) && y < frame.GetLength(1)) ? frame[x, y] : default(TerminalCharacter); Buffer[x, y].Glyph = ch.Character; Buffer[x, y].Foreground = Palette.Default[ch.ForegroundPaletteIndex]; Buffer[x, y].Background = Palette.Default[ch.BackgroundPaletteIndex]; } } } } else { var text = new[] { " PLACEHOLDER CONTROLS" , "" , "Ctrl+C Reconfigure TtyRecMonkey" , "Ctrl+O Open a ttyrec" , "Escape Close ttyrec and return here" , "Alt+Enter Toggle fullscreen" , "" , "ZXC Play backwards at x100, x10, or x1 speed" , " V Pause (press a speed to unpause)" , " BNM Play forwards at 1x, x10, or x100 speed" , "" , " A / S Zoom In/Out" }; for (int y = 0; y < BufferH; ++y) { for (int x = 0; x < BufferW; ++x) { var ch = (y < text.Length && x < text[y].Length) ? text[y][x] : ' '; Buffer[x, y].Glyph = ch; Buffer[x, y].Foreground = 0xFFFFFFFFu; Buffer[x, y].Background = 0xFF000000u; Buffer[x, y].Font = Prototype.Font; } } } Text = string.Format ("TtyRecMonkey -- {0} FPS -- {1} @ {2} of {3} ({4} keyframes {5} packets) -- Speed {6} -- GC recognized memory: {7}" , PreviousFrames.Count , PrettyTimeSpan(Seek) , Decoder == null ? "N/A" : PrettyTimeSpan(Decoder.CurrentFrame.SinceStart) , Decoder == null ? "N/A" : PrettyTimeSpan(Decoder.Length) , Decoder == null ? "N/A" : Decoder.Keyframes.ToString() , Decoder == null ? "N/A" : Decoder.PacketCount.ToString() , PlaybackSpeed , PrettyByteCount(GC.GetTotalMemory(false)) ); Redraw(); }