AVI cleanup - gray of menu items when appropriate, use default filename, and AVI Path config, add on screen messages, fix crash on Null emulator capture (snow is awesome yo), other misc things

This commit is contained in:
andres.delikat 2011-07-11 23:26:20 +00:00
parent e6202bdea1
commit bd71909f38
4 changed files with 138 additions and 98 deletions

View File

@ -4,62 +4,64 @@ using System.IO;
namespace BizHawk
{
public class NullEmulator : IEmulator, IVideoProvider, ISoundProvider
{
public string SystemId { get { return "NULL"; } }
public static readonly ControllerDefinition NullController = new ControllerDefinition { Name = "Null Controller" };
public class NullEmulator : IEmulator, IVideoProvider, ISoundProvider
{
public string SystemId { get { return "NULL"; } }
public static readonly ControllerDefinition NullController = new ControllerDefinition { Name = "Null Controller" };
private int[] frameBuffer = new int[256 * 192];
private Random rand = new Random();
private int[] frameBuffer = new int[256 * 192];
private Random rand = new Random();
public CoreInputComm CoreInputComm { get; set; }
public CoreOutputComm CoreOutputComm { get; private set; }
public IVideoProvider VideoProvider { get { return this; } }
public ISoundProvider SoundProvider { get { return this; } }
public NullEmulator()
{
var domains = new List<MemoryDomain>(1);
domains.Add(new MemoryDomain("Main RAM", 1, Endian.Little, addr=>0, (a,v)=> { }));
memoryDomains = domains.AsReadOnly();
}
public void LoadGame(IGame game) { }
public void FrameAdvance(bool render)
{
if (render == false) return;
for (int i = 0; i < 256 * 192; i++)
frameBuffer[i] = Colors.Luminosity((byte)rand.Next());
}
public ControllerDefinition ControllerDefinition { get { return NullController; } }
public IController Controller { get; set; }
public IVideoProvider VideoProvider { get { return this; } }
public ISoundProvider SoundProvider { get { return this; } }
public NullEmulator()
{
var domains = new List<MemoryDomain>(1);
domains.Add(new MemoryDomain("Main RAM", 1, Endian.Little, addr => 0, (a, v) => { }));
memoryDomains = domains.AsReadOnly();
CoreOutputComm = new CoreOutputComm();
CoreInputComm = new CoreInputComm();
}
public void LoadGame(IGame game) { }
public void FrameAdvance(bool render)
{
if (render == false) return;
for (int i = 0; i < 256 * 192; i++)
frameBuffer[i] = Colors.Luminosity((byte)rand.Next());
}
public ControllerDefinition ControllerDefinition { get { return NullController; } }
public IController Controller { get; set; }
public int Frame { get; set; }
public int LagCount { get { return 0; } set { return; } }
public bool IsLagFrame { get { return false; } }
public int Frame { get; set; }
public int LagCount { get { return 0; } set { return; } }
public bool IsLagFrame { get { return false; } }
public byte[] SaveRam { get { return new byte[0]; } }
public bool DeterministicEmulation { get; set; }
public bool SaveRamModified { get; set; }
public void SaveStateText(TextWriter writer) { }
public void LoadStateText(TextReader reader) { }
public void SaveStateBinary(BinaryWriter writer) { }
public void LoadStateBinary(BinaryReader reader) { }
public byte[] SaveStateBinary() { return new byte[1]; }
public int[] GetVideoBuffer() { return frameBuffer; }
public int BufferWidth { get { return 256; } }
public int BufferHeight { get { return 192; } }
public int BackgroundColor { get { return 0; } }
public void GetSamples(short[] samples) { }
public byte[] SaveRam { get { return new byte[0]; } }
public bool DeterministicEmulation { get; set; }
public bool SaveRamModified { get; set; }
public void SaveStateText(TextWriter writer) { }
public void LoadStateText(TextReader reader) { }
public void SaveStateBinary(BinaryWriter writer) { }
public void LoadStateBinary(BinaryReader reader) { }
public byte[] SaveStateBinary() { return new byte[1]; }
public int[] GetVideoBuffer() { return frameBuffer; }
public int BufferWidth { get { return 256; } }
public int BufferHeight { get { return 192; } }
public int BackgroundColor { get { return 0; } }
public void GetSamples(short[] samples) { }
public void DiscardSamples() { }
private IList<MemoryDomain> memoryDomains;
public IList<MemoryDomain> MemoryDomains { get { return memoryDomains; } }
public MemoryDomain MainMemory { get { return memoryDomains[0]; } }
public void Dispose() { }
}
private IList<MemoryDomain> memoryDomains;
public IList<MemoryDomain> MemoryDomains { get { return memoryDomains; } }
public MemoryDomain MainMemory { get { return memoryDomains[0]; } }
public void Dispose() { }
}
public class NullSound : ISoundProvider
{
public static readonly NullSound SilenceProvider = new NullSound();
public class NullSound : ISoundProvider
{
public static readonly NullSound SilenceProvider = new NullSound();
public void GetSamples(short[] samples) { }
public void DiscardSamples() { }
}
public void GetSamples(short[] samples) { }
public void DiscardSamples() { }
}
}

View File

@ -258,7 +258,7 @@
this.menuStrip1.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.Flow;
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(470, 40);
this.menuStrip1.Size = new System.Drawing.Size(470, 21);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
this.menuStrip1.MenuDeactivate += new System.EventHandler(this.menuStrip1_MenuDeactivate);
@ -805,9 +805,11 @@
this.aVIWAVToolStripMenuItem.Name = "aVIWAVToolStripMenuItem";
this.aVIWAVToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.aVIWAVToolStripMenuItem.Text = "AVI/WAV";
this.aVIWAVToolStripMenuItem.DropDownOpened += new System.EventHandler(this.aVIWAVToolStripMenuItem_DropDownOpened);
//
// recordAVIToolStripMenuItem
//
this.recordAVIToolStripMenuItem.Image = global::BizHawk.MultiClient.Properties.Resources.RecordHS;
this.recordAVIToolStripMenuItem.Name = "recordAVIToolStripMenuItem";
this.recordAVIToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.recordAVIToolStripMenuItem.Text = "Record AVI";
@ -815,6 +817,7 @@
//
// stopAVIToolStripMenuItem
//
this.stopAVIToolStripMenuItem.Image = global::BizHawk.MultiClient.Properties.Resources.Stop;
this.stopAVIToolStripMenuItem.Name = "stopAVIToolStripMenuItem";
this.stopAVIToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.stopAVIToolStripMenuItem.Text = "Stop AVI";

View File

@ -10,39 +10,12 @@ namespace BizHawk.MultiClient
{
private void recordAVIToolStripMenuItem_Click(object sender, EventArgs e)
{
var sfd = new SaveFileDialog();
//TODO adelikat (dunno how to do the paths correctly)
sfd.FileName = Path.Combine(Global.Config.AVIPath, "game.avi");
if (sfd.ShowDialog() == DialogResult.Cancel)
return;
//TODO - cores should be able to specify exact values for these instead of relying on this to calculate them
int fps = (int)(Global.Emulator.CoreOutputComm.VsyncRate * 0x01000000);
AviWriter aw = new AviWriter();
try
{
aw.SetMovieParameters(fps, 0x01000000);
aw.SetVideoParameters(Global.Emulator.VideoProvider.BufferWidth, Global.Emulator.VideoProvider.BufferHeight);
aw.SetAudioParameters(44100, 2, 16);
aw.OpenFile(sfd.FileName);
var token = aw.AcquireVideoCodecToken(Global.MainForm.Handle);
aw.SetVideoCodecToken(token);
aw.OpenStreams();
//commit the avi writing last, in case there were any errors earlier
CurrAviWriter = aw;
}
catch
{
aw.Dispose();
throw;
}
RecordAVI();
}
private void stopAVIToolStripMenuItem_Click(object sender, EventArgs e)
{
CurrAviWriter.CloseFile();
CurrAviWriter = null;
StopAVI();
}
private void DumpStatus_Click(object sender, EventArgs e)
@ -952,14 +925,38 @@ namespace BizHawk.MultiClient
StopUserMovie();
}
private void displayLogWindowToolStripMenuItem_Click(object sender, EventArgs e)
{
Global.Config.ShowLogWindow ^= true;
displayLogWindowToolStripMenuItem.Checked = Global.Config.ShowLogWindow;
if (Global.Config.ShowLogWindow)
LogConsole.ShowConsole();
else
LogConsole.HideConsole();
}
private void displayLogWindowToolStripMenuItem_Click(object sender, EventArgs e)
{
Global.Config.ShowLogWindow ^= true;
displayLogWindowToolStripMenuItem.Checked = Global.Config.ShowLogWindow;
if (Global.Config.ShowLogWindow)
LogConsole.ShowConsole();
else
LogConsole.HideConsole();
}
private void PauseStrip_Click(object sender, EventArgs e)
{
TogglePause();
}
private void displaySubtitlesToolStripMenuItem_Click(object sender, EventArgs e)
{
Global.Config.DisplaySubtitles ^= true;
}
private void aVIWAVToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
{
if (CurrAviWriter == null)
{
recordAVIToolStripMenuItem.Enabled = true;
stopAVIToolStripMenuItem.Enabled = false;
}
else
{
recordAVIToolStripMenuItem.Enabled = false;
stopAVIToolStripMenuItem.Enabled = true;
}
}
}
}

View File

@ -2550,19 +2550,57 @@ namespace BizHawk.MultiClient
c.ShowDialog();
}
private void PauseStrip_Click(object sender, EventArgs e)
public void RecordAVI()
{
TogglePause();
var sfd = new SaveFileDialog();
if (!(Global.Emulator is NullEmulator))
{
sfd.FileName = Global.Game.FilesystemSafeName;
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.AVIPath, "");
}
else
{
sfd.FileName = "NULL";
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.AVIPath, "");
}
sfd.Filter = "AVI (*.avi)|*.avi|All Files|*.*";
Global.Sound.StopSound();
var result = sfd.ShowDialog();
Global.Sound.StartSound();
if (result == DialogResult.Cancel)
return;
//TODO - cores should be able to specify exact values for these instead of relying on this to calculate them
int fps = (int)(Global.Emulator.CoreOutputComm.VsyncRate * 0x01000000);
AviWriter aw = new AviWriter();
try
{
aw.SetMovieParameters(fps, 0x01000000);
aw.SetVideoParameters(Global.Emulator.VideoProvider.BufferWidth, Global.Emulator.VideoProvider.BufferHeight);
aw.SetAudioParameters(44100, 2, 16);
aw.OpenFile(sfd.FileName);
var token = aw.AcquireVideoCodecToken(Global.MainForm.Handle);
aw.SetVideoCodecToken(token);
aw.OpenStreams();
//commit the avi writing last, in case there were any errors earlier
CurrAviWriter = aw;
Global.RenderPanel.AddMessage("AVI capture started");
}
catch
{
Global.RenderPanel.AddMessage("AVI capture failed!");
aw.Dispose();
throw;
}
}
private void displaySubtitlesToolStripMenuItem_Click(object sender, EventArgs e)
public void StopAVI()
{
Global.Config.DisplaySubtitles ^= true;
CurrAviWriter.CloseFile();
CurrAviWriter = null;
Global.RenderPanel.AddMessage("AVI capture stopped");
}
}
}