2014-06-13 00:15:55 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
using BizHawk.Emulation.Common;
|
|
|
|
|
|
|
|
|
|
namespace BizHawk.Client.Common
|
|
|
|
|
{
|
|
|
|
|
public partial class Bk2Movie : IMovie
|
|
|
|
|
{
|
2014-11-15 21:49:58 +00:00
|
|
|
|
protected 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
|
|
|
|
{
|
|
|
|
|
Rerecords = 0;
|
|
|
|
|
Filename = filename;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-14 20:17:07 +00:00
|
|
|
|
public Bk2Movie()
|
2014-06-13 00:15:55 +00:00
|
|
|
|
{
|
2014-07-06 22:13:12 +00:00
|
|
|
|
Subtitles = new SubtitleList();
|
|
|
|
|
Comments = new List<string>();
|
|
|
|
|
|
2014-06-13 00:15:55 +00:00
|
|
|
|
Filename = string.Empty;
|
|
|
|
|
IsCountingRerecords = true;
|
|
|
|
|
_mode = Moviemode.Inactive;
|
2014-11-15 21:49:58 +00:00
|
|
|
|
MakeBackup = true;
|
2014-06-14 20:17:07 +00:00
|
|
|
|
|
|
|
|
|
Header[HeaderKeys.MOVIEVERSION] = "BizHawk v2.0.0";
|
2015-11-15 08:27:48 +00:00
|
|
|
|
|
|
|
|
|
_log = StringLogUtil.MakeStringLog();
|
2014-06-13 00:15:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-22 02:56:27 +00:00
|
|
|
|
private string _filename;
|
|
|
|
|
|
|
|
|
|
public string Filename
|
|
|
|
|
{
|
|
|
|
|
get { return _filename; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_filename = value;
|
|
|
|
|
int index = Filename.LastIndexOf("\\");
|
|
|
|
|
Name = Filename.Substring(index + 1, Filename.Length - index - 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name { get; private set; }
|
2014-06-14 20:17:07 +00:00
|
|
|
|
|
2014-06-17 01:24:44 +00:00
|
|
|
|
public virtual string PreferredExtension { get { return Extension; } }
|
|
|
|
|
public const string Extension = "bk2";
|
2014-06-14 20:17:07 +00:00
|
|
|
|
|
2014-08-23 18:02:02 +00:00
|
|
|
|
public virtual bool Changes { get; protected set; }
|
2014-06-14 14:04:54 +00:00
|
|
|
|
public bool IsCountingRerecords { get; set; }
|
2014-06-13 00:15:55 +00:00
|
|
|
|
|
2014-06-14 22:36:32 +00:00
|
|
|
|
public ILogEntryGenerator LogGeneratorInstance()
|
|
|
|
|
{
|
2014-11-15 21:49:58 +00:00
|
|
|
|
return new Bk2LogEntryGenerator(LogKey);
|
2014-06-14 22:36:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
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 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-15 12:17:28 +00:00
|
|
|
|
var lg = LogGeneratorInstance();
|
|
|
|
|
lg.SetSource(source);
|
|
|
|
|
_log.Add(lg.GenerateLogEntry());
|
2014-06-14 14:04:54 +00:00
|
|
|
|
Changes = true;
|
2014-06-13 00:15:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-07 18:40:42 +00:00
|
|
|
|
public virtual void RecordFrame(int frame, IController source)
|
2014-06-13 00:15:55 +00:00
|
|
|
|
{
|
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-15 02:23:28 +00:00
|
|
|
|
Truncate(Global.Emulator.Frame);
|
2014-06-14 14:04:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-14 22:36:32 +00:00
|
|
|
|
var lg = LogGeneratorInstance();
|
|
|
|
|
lg.SetSource(source);
|
2014-06-15 02:23:28 +00:00
|
|
|
|
SetFrameAt(frame, lg.GenerateLogEntry());
|
2014-06-14 14:04:54 +00:00
|
|
|
|
|
|
|
|
|
Changes = true;
|
2014-06-13 00:15:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-07 18:40:42 +00:00
|
|
|
|
public virtual void Truncate(int frame)
|
2014-06-13 00:15:55 +00:00
|
|
|
|
{
|
2014-08-10 02:21:08 +00:00
|
|
|
|
// This is a bad way to do multitrack logic, pass the info in instead of going to the global
|
2014-08-21 18:45:14 +00:00
|
|
|
|
// and it is weird for Truncate to possibly not truncate
|
2014-08-10 02:21:08 +00:00
|
|
|
|
if (!Global.MovieSession.MultiTrack.IsActive)
|
2014-06-15 02:23:28 +00:00
|
|
|
|
{
|
2014-08-10 02:21:08 +00:00
|
|
|
|
if (frame < _log.Count)
|
|
|
|
|
{
|
|
|
|
|
_log.RemoveRange(frame, _log.Count - frame);
|
|
|
|
|
Changes = true;
|
2015-03-01 05:47:32 +00:00
|
|
|
|
|
|
|
|
|
|
2014-08-10 02:21:08 +00:00
|
|
|
|
}
|
2014-06-15 02:23:28 +00:00
|
|
|
|
}
|
2014-06-13 00:15:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-16 23:05:59 +00:00
|
|
|
|
public virtual IController GetInputState(int frame)
|
2014-06-18 02:26:22 +00:00
|
|
|
|
{
|
|
|
|
|
if (frame < FrameCount && frame >= 0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
int getframe;
|
|
|
|
|
|
|
|
|
|
if (LoopOffset.HasValue)
|
|
|
|
|
{
|
|
|
|
|
if (frame < _log.Count)
|
|
|
|
|
{
|
|
|
|
|
getframe = frame;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
getframe = ((frame - LoopOffset.Value) % (_log.Count - LoopOffset.Value)) + LoopOffset.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
getframe = frame;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-21 17:27:35 +00:00
|
|
|
|
var adapter = new Bk2ControllerAdapter
|
|
|
|
|
{
|
2016-12-12 18:30:32 +00:00
|
|
|
|
Definition = Global.MovieSession.MovieControllerAdapter.Definition
|
2014-06-21 17:27:35 +00:00
|
|
|
|
};
|
|
|
|
|
|
2014-06-18 02:26:22 +00:00
|
|
|
|
adapter.SetControllersAsMnemonic(_log[getframe]);
|
|
|
|
|
return adapter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-07 18:40:42 +00:00
|
|
|
|
public virtual void PokeFrame(int frame, IController source)
|
2014-06-14 22:36:32 +00:00
|
|
|
|
{
|
2014-07-04 00:24:41 +00:00
|
|
|
|
var lg = LogGeneratorInstance();
|
|
|
|
|
lg.SetSource(source);
|
|
|
|
|
|
|
|
|
|
Changes = true;
|
|
|
|
|
SetFrameAt(frame, lg.GenerateLogEntry());
|
2014-06-14 22:36:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-07 18:40:42 +00:00
|
|
|
|
public virtual void ClearFrame(int frame)
|
2014-06-14 22:36:32 +00:00
|
|
|
|
{
|
2014-07-11 19:58:24 +00:00
|
|
|
|
var lg = LogGeneratorInstance();
|
|
|
|
|
lg.SetSource(Global.MovieSession.MovieControllerInstance());
|
|
|
|
|
SetFrameAt(frame, lg.EmptyEntry);
|
2014-07-07 18:40:42 +00:00
|
|
|
|
Changes = true;
|
2014-06-14 22:36:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-14 14:04:54 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2014-11-15 21:49:58 +00:00
|
|
|
|
protected void SetFrameAt(int frameNum, string frame)
|
2014-06-15 02:23:28 +00:00
|
|
|
|
{
|
|
|
|
|
if (_log.Count > frameNum)
|
|
|
|
|
{
|
|
|
|
|
_log[frameNum] = frame;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_log.Add(frame);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-13 00:15:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|