BizHawk/BizHawk.Client.EmuHawk/MainForm.Movie.cs

217 lines
6.7 KiB
C#
Raw Normal View History

using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES;
2014-05-18 16:28:56 +00:00
using BizHawk.Emulation.Cores.Nintendo.NES;
using BizHawk.Emulation.Cores.Nintendo.SNES;
namespace BizHawk.Client.EmuHawk
{
partial class MainForm
{
public void StartNewMovie(IMovie movie, bool record, bool fromTastudio = false) //TasStudio flag is a hack for now
{
//If a movie is already loaded, save it before starting a new movie
if (!fromTastudio && Global.MovieSession.Movie.IsActive)
{
Global.MovieSession.Movie.Save();
}
2012-10-13 21:30:19 +00:00
Global.MovieSession = new MovieSession
{
Movie = movie,
2014-06-19 01:47:22 +00:00
MovieControllerAdapter = movie.LogGeneratorInstance().MovieControllerAdapter,
MessageCallback = GlobalWin.OSD.AddMessage,
AskYesNoCallback = StateErrorAskUser
};
InputManager.RewireInputChain();
if (!record)
2012-09-03 19:42:53 +00:00
{
Global.MovieSession.Movie.Load();
2012-09-03 19:42:53 +00:00
}
2013-12-24 23:32:43 +00:00
try
{
2014-05-18 16:28:56 +00:00
var quicknesName = ((CoreAttributes)Attribute.GetCustomAttribute(typeof(QuickNES), typeof(CoreAttributes))).CoreName;
var neshawkName = ((CoreAttributes)Attribute.GetCustomAttribute(typeof(NES), typeof(CoreAttributes))).CoreName;
2014-05-18 16:28:56 +00:00
if (!record && Global.Emulator.SystemId == "NES") // For NES we need special logic since the movie will drive which core to load
2013-12-24 23:32:43 +00:00
{
// If either is specified use that, else use whatever is currently set
if (Global.MovieSession.Movie.Core == quicknesName)
{
Global.Config.NES_InQuickNES = true;
}
else if (Global.MovieSession.Movie.Core == neshawkName)
{
2014-05-18 16:28:56 +00:00
Global.Config.NES_InQuickNES = false;
}
}
string s = Global.MovieSession.Movie.SyncSettingsJson;
if (!string.IsNullOrWhiteSpace(s))
{
2014-05-18 17:19:38 +00:00
_syncSettingsHack = ConfigService.LoadWithType(s);
}
if (record) // This is a hack really, the movie isn't active yet unless I do this, and LoadRom wants to know if it is
{
Global.MovieSession.Movie.SwitchToRecord();
}
LoadRom(GlobalWin.MainForm.CurrentlyOpenRom);
2013-12-24 23:32:43 +00:00
}
finally
{
// ensure subsequent calls to LoadRom won't get the settings object created here
2013-12-29 23:35:42 +00:00
this._syncSettingsHack = null;
2013-12-24 23:32:43 +00:00
}
if (!fromTastudio)
{
Global.Config.RecentMovies.Add(movie.Filename);
}
if (Global.MovieSession.Movie.StartsFromSavestate)
{
var state = Convert.FromBase64String(Global.MovieSession.Movie.SavestateBinaryBase64Blob);
Global.Emulator.LoadStateBinary(new BinaryReader(new MemoryStream(state)));
Global.Emulator.ResetCounters();
}
if (!fromTastudio)
{
if (record)
{
Global.MovieSession.Movie.StartNewRecording();
Global.MovieSession.ReadOnly = false;
}
else
{
Global.MovieSession.Movie.StartNewPlayback();
}
}
SetMainformMovieInfo();
if (!fromTastudio)
{
GlobalWin.Tools.Restart<TAStudio>();
}
GlobalWin.Tools.Restart<VirtualPadForm>();
GlobalWin.DisplayManager.NeedsToPaint = true;
}
public void SetMainformMovieInfo()
{
2013-10-24 22:26:28 +00:00
if (Global.MovieSession.Movie.IsPlaying)
{
Text = DisplayNameForSystem(Global.Game.System) + " - " + Global.Game.Name + " - " + Path.GetFileName(Global.MovieSession.Movie.Filename);
2013-10-27 15:53:37 +00:00
PlayRecordStatusButton.Image = Properties.Resources.Play;
PlayRecordStatusButton.ToolTipText = "Movie is in playback mode";
PlayRecordStatusButton.Visible = true;
}
2013-10-24 22:26:28 +00:00
else if (Global.MovieSession.Movie.IsRecording)
{
Text = DisplayNameForSystem(Global.Game.System) + " - " + Global.Game.Name + " - " + Path.GetFileName(Global.MovieSession.Movie.Filename);
2013-10-27 15:53:37 +00:00
PlayRecordStatusButton.Image = Properties.Resources.RecordHS;
PlayRecordStatusButton.ToolTipText = "Movie is in record mode";
PlayRecordStatusButton.Visible = true;
}
2013-10-24 22:26:28 +00:00
else if (!Global.MovieSession.Movie.IsActive)
{
Text = DisplayNameForSystem(Global.Game.System) + " - " + Global.Game.Name;
2013-10-27 15:53:37 +00:00
PlayRecordStatusButton.Image = Properties.Resources.Blank;
PlayRecordStatusButton.ToolTipText = "No movie is active";
PlayRecordStatusButton.Visible = false;
}
}
public void LoadPlayMovieDialog()
{
new PlayMovie().ShowDialog();
}
public void LoadRecordMovieDialog()
{
if (!Global.Emulator.Attributes().Released)
{
var result = MessageBox.Show
(this, "Thanks for using Bizhawk! The emulation core you have selected " +
"is currently BETA-status. We appreciate your help in testing Bizhawk. " +
"You can record a movie on this core if you'd like to, but expect to " +
"encounter bugs and sync problems. Continue?", "BizHawk", MessageBoxButtons.YesNo);
if (result != DialogResult.Yes)
{
return;
}
}
else if (Global.Emulator is LibsnesCore)
{
var ss = (LibsnesCore.SnesSyncSettings)Global.Emulator.GetSyncSettings();
if (ss.Profile == "Performance" && !Global.Config.DontAskPerformanceCoreRecordingNag)
{
var box = new MsgBox(
"While the performance core is faster, it is recommended that you use the Compatibility profile when recording movies for better accuracy and stability\n\nSwitch to Compatibility?",
"Stability Warning",
MessageBoxIcon.Warning);
box.SetButtons(
new [] {"Switch", "Continue", "Cancel" },
new DialogResult[] { DialogResult.Yes, DialogResult.No, DialogResult.Cancel });
box.SetCheckbox("Don't ask me again");
box.MaximumSize = new Size(450, 350);
box.SetMessageToAutoSize();
var result = box.ShowDialog();
Global.Config.DontAskPerformanceCoreRecordingNag = box.CheckboxChecked;
if (result == DialogResult.Yes)
{
ss.Profile = "Compatibility";
Global.Emulator.PutSyncSettings(ss);
}
else if (result == DialogResult.Cancel)
{
return;
}
}
}
new RecordMovie().ShowDialog();
}
public void RestartMovie()
{
2013-10-24 22:26:28 +00:00
if (Global.MovieSession.Movie.IsActive)
{
LoadRom(CurrentlyOpenRom);
if (Global.MovieSession.Movie.StartsFromSavestate)
{
var state = Convert.FromBase64String(Global.MovieSession.Movie.SavestateBinaryBase64Blob);
Global.Emulator.LoadStateBinary(new BinaryReader(new MemoryStream(state)));
Global.Emulator.ResetCounters();
}
Global.MovieSession.Movie.StartNewPlayback();
SetMainformMovieInfo();
GlobalWin.OSD.AddMessage("Replaying movie file in read-only mode");
Global.MovieSession.ReadOnly = true;
}
}
public void StopMovie(bool saveChanges = true)
{
Global.MovieSession.StopMovie(saveChanges);
SetMainformMovieInfo();
}
}
}