BizHawk/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs

180 lines
3.5 KiB
C#
Raw Normal View History

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
{
// Movies 2.0 TODO: save and load loopOffset, put in header object
2014-06-13 00:15:55 +00:00
private readonly PlatformFrameRates _frameRates = new PlatformFrameRates();
2014-06-13 00:43:55 +00:00
private bool _makeBackup = true;
2014-06-14 14:04:54 +00:00
private int? _loopOffset;
2014-06-13 00:15:55 +00:00
public Bk2Movie(string filename, bool startsFromSavestate = false)
: this(startsFromSavestate)
{
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;
}
public Bk2Movie(bool startsFromSavestate = false)
{
Filename = string.Empty;
StartsFromSavestate = startsFromSavestate;
IsCountingRerecords = true;
_mode = Moviemode.Inactive;
2014-06-13 00:43:55 +00:00
_makeBackup = true;
2014-06-13 00:15:55 +00:00
}
2014-06-14 14:04:54 +00:00
public string Filename { get; set; }
2014-06-13 00:15:55 +00:00
public string PreferredExtension { get { return "bk2"; } }
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
{
if (_loopOffset.HasValue)
{
return double.PositiveInfinity;
}
return _log.Length;
}
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
{
var dblseconds = GetSeconds(_log.Length);
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 14:04:54 +00:00
get { return _log.Length; }
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);
_log.AppendFrame(mg.GetControllersAsMnemonic());
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)
{
if (Global.Emulator.Frame < _log.Length)
{
_log.TruncateMovie(Global.Emulator.Frame);
}
}
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 14:04:54 +00:00
_log.TruncateMovie(frame);
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;
if (_loopOffset.HasValue)
{
if (frame < _log.Length)
{
getframe = frame;
}
else
{
getframe = ((frame - _loopOffset.Value) % (_log.Length - _loopOffset.Value)) + _loopOffset.Value;
}
}
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
}
}