2014-06-13 00:15:55 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
using BizHawk.Common;
|
|
|
|
|
using BizHawk.Emulation.Common;
|
|
|
|
|
|
|
|
|
|
namespace BizHawk.Client.Common
|
|
|
|
|
{
|
|
|
|
|
public partial class Bk2Movie : IMovie
|
|
|
|
|
{
|
|
|
|
|
private readonly PlatformFrameRates _frameRates = new PlatformFrameRates();
|
2014-06-13 00:43:55 +00:00
|
|
|
|
private bool _makeBackup = true;
|
2014-06-13 00:15:55 +00:00
|
|
|
|
|
2014-06-14 20:17:07 +00:00
|
|
|
|
public Bk2Movie(string filename)
|
|
|
|
|
: this()
|
2014-06-13 00:15:55 +00:00
|
|
|
|
{
|
2014-06-13 00:43:55 +00:00
|
|
|
|
Subtitles = new SubtitleList();
|
|
|
|
|
Comments = new List<string>();
|
|
|
|
|
|
2014-06-13 00:15:55 +00:00
|
|
|
|
Rerecords = 0;
|
|
|
|
|
Filename = filename;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-14 20:17:07 +00:00
|
|
|
|
public Bk2Movie()
|
2014-06-13 00:15:55 +00:00
|
|
|
|
{
|
|
|
|
|
Filename = string.Empty;
|
|
|
|
|
IsCountingRerecords = true;
|
|
|
|
|
_mode = Moviemode.Inactive;
|
2014-06-13 00:43:55 +00:00
|
|
|
|
_makeBackup = true;
|
2014-06-14 20:17:07 +00:00
|
|
|
|
|
|
|
|
|
Header[HeaderKeys.MOVIEVERSION] = "BizHawk v2.0.0";
|
2014-06-13 00:15:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-14 14:04:54 +00:00
|
|
|
|
public string Filename { get; set; }
|
2014-06-14 20:17:07 +00:00
|
|
|
|
|
2014-06-14 21:09:14 +00:00
|
|
|
|
public virtual string PreferredExtension { get { return "bk2"; } }
|
2014-06-14 20:17:07 +00:00
|
|
|
|
|
2014-06-13 00:43:55 +00:00
|
|
|
|
public bool Changes { get; private set; }
|
2014-06-14 14:04:54 +00:00
|
|
|
|
public bool IsCountingRerecords { get; set; }
|
2014-06-13 00:15:55 +00:00
|
|
|
|
|
|
|
|
|
public double FrameCount
|
|
|
|
|
{
|
2014-06-14 14:04:54 +00:00
|
|
|
|
get
|
|
|
|
|
{
|
2014-06-14 18:52:00 +00:00
|
|
|
|
if (LoopOffset.HasValue)
|
2014-06-14 14:04:54 +00:00
|
|
|
|
{
|
|
|
|
|
return double.PositiveInfinity;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-14 21:37:51 +00:00
|
|
|
|
return _log.Count;
|
2014-06-14 14:04:54 +00:00
|
|
|
|
}
|
2014-06-13 00:15:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double Fps
|
|
|
|
|
{
|
2014-06-14 14:04:54 +00:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var system = Header[HeaderKeys.PLATFORM];
|
|
|
|
|
var pal = Header.ContainsKey(HeaderKeys.PAL) &&
|
|
|
|
|
Header[HeaderKeys.PAL] == "1";
|
|
|
|
|
|
|
|
|
|
return _frameRates[system, pal];
|
|
|
|
|
}
|
2014-06-13 00:15:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TimeSpan Time
|
|
|
|
|
{
|
2014-06-14 14:04:54 +00:00
|
|
|
|
get
|
|
|
|
|
{
|
2014-06-14 21:37:51 +00:00
|
|
|
|
var dblseconds = GetSeconds(_log.Count);
|
2014-06-14 14:04:54 +00:00
|
|
|
|
var seconds = (int)(dblseconds % 60);
|
|
|
|
|
var days = seconds / 86400;
|
|
|
|
|
var hours = seconds / 3600;
|
|
|
|
|
var minutes = (seconds / 60) % 60;
|
|
|
|
|
var milliseconds = (int)((dblseconds - seconds) * 1000);
|
|
|
|
|
return new TimeSpan(days, hours, minutes, seconds, milliseconds);
|
|
|
|
|
}
|
2014-06-13 00:15:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int InputLogLength
|
|
|
|
|
{
|
2014-06-14 21:37:51 +00:00
|
|
|
|
get { return _log.Count; }
|
2014-06-13 00:15:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-14 14:04:54 +00:00
|
|
|
|
#region Log Editing
|
2014-06-13 00:15:55 +00:00
|
|
|
|
|
|
|
|
|
public void AppendFrame(IController source)
|
|
|
|
|
{
|
2014-06-14 14:04:54 +00:00
|
|
|
|
var mg = new MnemonicsGenerator();
|
|
|
|
|
mg.SetSource(source);
|
2014-06-14 21:37:51 +00:00
|
|
|
|
_log.Add(mg.GetControllersAsMnemonic());
|
2014-06-14 14:04:54 +00:00
|
|
|
|
Changes = true;
|
2014-06-13 00:15:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RecordFrame(int frame, IController source)
|
|
|
|
|
{
|
2014-06-14 14:04:54 +00:00
|
|
|
|
if (Global.Config.VBAStyleMovieLoadState)
|
|
|
|
|
{
|
2014-06-14 21:37:51 +00:00
|
|
|
|
if (Global.Emulator.Frame < _log.Count)
|
2014-06-14 14:04:54 +00:00
|
|
|
|
{
|
2014-06-14 21:41:11 +00:00
|
|
|
|
_log.Truncate(Global.Emulator.Frame);
|
2014-06-14 14:04:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var mg = new MnemonicsGenerator();
|
|
|
|
|
mg.SetSource(source);
|
|
|
|
|
|
|
|
|
|
Changes = true;
|
|
|
|
|
_log.SetFrameAt(frame, mg.GetControllersAsMnemonic());
|
2014-06-13 00:15:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Truncate(int frame)
|
|
|
|
|
{
|
2014-06-14 21:41:11 +00:00
|
|
|
|
_log.Truncate(frame);
|
2014-06-14 14:04:54 +00:00
|
|
|
|
Changes = true;
|
2014-06-13 00:15:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetInput(int frame)
|
|
|
|
|
{
|
2014-06-14 14:04:54 +00:00
|
|
|
|
if (frame < FrameCount && frame >= 0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
int getframe;
|
|
|
|
|
|
2014-06-14 18:52:00 +00:00
|
|
|
|
if (LoopOffset.HasValue)
|
2014-06-14 14:04:54 +00:00
|
|
|
|
{
|
2014-06-14 21:37:51 +00:00
|
|
|
|
if (frame < _log.Count)
|
2014-06-14 14:04:54 +00:00
|
|
|
|
{
|
|
|
|
|
getframe = frame;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-06-14 21:37:51 +00:00
|
|
|
|
getframe = ((frame - LoopOffset.Value) % (_log.Count - LoopOffset.Value)) + LoopOffset.Value;
|
2014-06-14 14:04:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
getframe = frame;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _log[getframe];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Finish();
|
|
|
|
|
return string.Empty;
|
2014-06-13 00:15:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-14 14:04:54 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
private double GetSeconds(int frameCount)
|
|
|
|
|
{
|
|
|
|
|
double frames = frameCount;
|
|
|
|
|
|
|
|
|
|
if (frames < 1)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return frames / Fps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Probably won't support
|
|
|
|
|
|
2014-06-13 00:15:55 +00:00
|
|
|
|
public void PokeFrame(int frame, IController source)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ClearFrame(int frame)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|