From 2a9710b63cdb604334a46ab80dd54a09ff9d77df Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 18 Apr 2020 10:49:15 -0500 Subject: [PATCH] movie some video provider movie logic into an extension method --- BizHawk.Client.EmuHawk/MainForm.Movie.cs | 8 +------ .../Interfaces/Services/IVideoProvider.cs | 24 ++++++++++++++++++- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/BizHawk.Client.EmuHawk/MainForm.Movie.cs b/BizHawk.Client.EmuHawk/MainForm.Movie.cs index 3eaf65f1ba..145dd11652 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Movie.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Movie.cs @@ -44,13 +44,7 @@ namespace BizHawk.Client.EmuHawk if (movie.SavestateFramebuffer != null && Emulator.HasVideoProvider()) { - var b1 = movie.SavestateFramebuffer; - var b2 = Emulator.AsVideoProvider().GetVideoBuffer(); - int len = Math.Min(b1.Length, b2.Length); - for (int i = 0; i < len; i++) - { - b2[i] = b1[i]; - } + Emulator.AsVideoProvider().PopulateFromBuffer(movie.SavestateFramebuffer); } Emulator.ResetCounters(); diff --git a/BizHawk.Emulation.Common/Interfaces/Services/IVideoProvider.cs b/BizHawk.Emulation.Common/Interfaces/Services/IVideoProvider.cs index fa25a414f9..d6ecba85e6 100644 --- a/BizHawk.Emulation.Common/Interfaces/Services/IVideoProvider.cs +++ b/BizHawk.Emulation.Common/Interfaces/Services/IVideoProvider.cs @@ -1,4 +1,6 @@ -namespace BizHawk.Emulation.Common +using System; + +namespace BizHawk.Emulation.Common { /// /// This service provides the ability to pass video output to the client @@ -62,4 +64,24 @@ /// int BackgroundColor { get; } } + + public static class VideoProviderExtensions + { + /// + /// Sets the frame buffer to the given frame buffer + /// Note: This sets the value returned by + /// which relies on the core to send a reference to the frame buffer instead of a copy, + /// in order to work + /// + public static void PopulateFromBuffer(this IVideoProvider videoProvider, int[] frameBuffer) + { + var b1 = frameBuffer; + var b2 = videoProvider.GetVideoBuffer(); + int len = Math.Min(b1.Length, b2.Length); + for (int i = 0; i < len; i++) + { + b2[i] = b1[i]; + } + } + } }