2013-12-01 20:55:52 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2013-12-10 01:45:45 +00:00
|
|
|
|
using System.Text;
|
2014-06-11 21:14:13 +00:00
|
|
|
|
|
|
|
|
|
using BizHawk.Common;
|
2013-12-07 16:31:04 +00:00
|
|
|
|
using BizHawk.Emulation.Common;
|
|
|
|
|
|
2013-12-01 20:55:52 +00:00
|
|
|
|
namespace BizHawk.Client.Common
|
|
|
|
|
{
|
2014-07-07 18:00:25 +00:00
|
|
|
|
public sealed partial class TasMovie : Bk2Movie
|
2013-12-01 20:55:52 +00:00
|
|
|
|
{
|
2014-07-07 19:32:37 +00:00
|
|
|
|
private List<bool> LagLog = new List<bool>();
|
2014-07-07 18:40:42 +00:00
|
|
|
|
private readonly TasStateManager StateManager = new TasStateManager();
|
2013-12-08 18:44:41 +00:00
|
|
|
|
|
2014-07-13 14:26:40 +00:00
|
|
|
|
public TasMovie(string path) : base(path) { }
|
2013-12-01 22:29:38 +00:00
|
|
|
|
|
2014-06-14 20:17:07 +00:00
|
|
|
|
public TasMovie()
|
2014-06-14 21:09:14 +00:00
|
|
|
|
: base()
|
2013-12-01 22:29:38 +00:00
|
|
|
|
{
|
2014-07-13 14:26:40 +00:00
|
|
|
|
Header[HeaderKeys.MOVIEVERSION] = "BizHawk v2.0 Tasproj v1.0";
|
|
|
|
|
Markers = new TasMovieMarkerList();
|
2014-06-11 21:20:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-14 21:09:14 +00:00
|
|
|
|
public override string PreferredExtension
|
2014-06-11 21:20:23 +00:00
|
|
|
|
{
|
2014-07-07 18:00:25 +00:00
|
|
|
|
get { return Extension; }
|
2014-06-11 21:20:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-17 01:24:44 +00:00
|
|
|
|
public new const string Extension = "tasproj";
|
2013-12-01 20:55:52 +00:00
|
|
|
|
|
2014-07-13 14:13:20 +00:00
|
|
|
|
public TasMovieMarkerList Markers { get; set; }
|
|
|
|
|
|
2014-07-07 18:03:02 +00:00
|
|
|
|
public TasMovieRecord this[int index]
|
2013-12-02 21:57:48 +00:00
|
|
|
|
{
|
2013-12-03 01:43:02 +00:00
|
|
|
|
get
|
|
|
|
|
{
|
2014-07-13 20:51:19 +00:00
|
|
|
|
if (index == 9)
|
|
|
|
|
{
|
|
|
|
|
int zzz = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-07 18:40:42 +00:00
|
|
|
|
return new TasMovieRecord
|
2014-07-07 18:00:25 +00:00
|
|
|
|
{
|
2014-07-07 18:40:42 +00:00
|
|
|
|
State = StateManager[index],
|
|
|
|
|
LogEntry = GetInput(index),
|
2014-07-10 19:24:21 +00:00
|
|
|
|
Lagged = (index < LagLog.Count) ? LagLog[index] : (bool?)null
|
2014-07-07 18:00:25 +00:00
|
|
|
|
};
|
2013-12-03 01:43:02 +00:00
|
|
|
|
}
|
2013-12-02 21:57:48 +00:00
|
|
|
|
}
|
2014-07-08 13:33:01 +00:00
|
|
|
|
|
2014-07-11 18:06:18 +00:00
|
|
|
|
public void ClearChanges()
|
|
|
|
|
{
|
|
|
|
|
Changes = false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 13:33:01 +00:00
|
|
|
|
public override void StartNewRecording()
|
|
|
|
|
{
|
|
|
|
|
LagLog.Clear();
|
|
|
|
|
StateManager.Clear();
|
2014-07-09 16:35:39 +00:00
|
|
|
|
Markers.Clear();
|
2014-07-08 13:33:01 +00:00
|
|
|
|
base.StartNewRecording();
|
|
|
|
|
}
|
2014-07-09 16:35:39 +00:00
|
|
|
|
|
2014-07-11 19:58:24 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Removes lag log and greenzone after this frame
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void InvalidateAfter(int frame)
|
|
|
|
|
{
|
|
|
|
|
if (frame < LagLog.Count)
|
|
|
|
|
{
|
|
|
|
|
LagLog.RemoveRange(frame + 1, LagLog.Count - frame - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StateManager.Invalidate(frame + 1);
|
|
|
|
|
Changes = true; // TODO check if this actually removed anyting before flagging changes
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-10 02:45:56 +00:00
|
|
|
|
private readonly Bk2MnemonicConstants Mnemonics = new Bk2MnemonicConstants();
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the mnemonic value for boolean buttons, and actual value for floats,
|
|
|
|
|
/// for a given frame and button
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string DisplayValue(int frame, string buttonName)
|
|
|
|
|
{
|
|
|
|
|
var adapter = GetInputState(frame);
|
|
|
|
|
|
|
|
|
|
if (adapter.Type.BoolButtons.Contains(buttonName))
|
|
|
|
|
{
|
|
|
|
|
return adapter.IsPressed(buttonName) ?
|
|
|
|
|
Mnemonics[buttonName].ToString() :
|
|
|
|
|
string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (adapter.Type.FloatControls.Contains(buttonName))
|
|
|
|
|
{
|
2014-07-11 16:26:19 +00:00
|
|
|
|
return adapter.GetFloat(buttonName).ToString();
|
2014-07-10 02:45:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "!";
|
|
|
|
|
}
|
2014-07-10 20:40:50 +00:00
|
|
|
|
|
|
|
|
|
public void ToggleBoolState(int frame, string buttonName)
|
|
|
|
|
{
|
|
|
|
|
if (frame < _log.Count)
|
|
|
|
|
{
|
|
|
|
|
var adapter = GetInputState(frame) as Bk2ControllerAdapter;
|
|
|
|
|
adapter[buttonName] = !adapter.IsPressed(buttonName);
|
|
|
|
|
|
|
|
|
|
var lg = LogGeneratorInstance();
|
|
|
|
|
lg.SetSource(adapter);
|
|
|
|
|
_log[frame] = lg.GenerateLogEntry();
|
|
|
|
|
Changes = true;
|
2014-07-11 19:58:24 +00:00
|
|
|
|
InvalidateAfter(frame);
|
2014-07-10 20:40:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetBoolState(int frame, string buttonName, bool val)
|
|
|
|
|
{
|
|
|
|
|
if (frame < _log.Count)
|
|
|
|
|
{
|
|
|
|
|
var adapter = GetInputState(frame) as Bk2ControllerAdapter;
|
|
|
|
|
var old = adapter[buttonName];
|
|
|
|
|
adapter[buttonName] = val;
|
|
|
|
|
|
|
|
|
|
var lg = LogGeneratorInstance();
|
|
|
|
|
lg.SetSource(adapter);
|
|
|
|
|
_log[frame] = lg.GenerateLogEntry();
|
|
|
|
|
|
|
|
|
|
if (old != val)
|
|
|
|
|
{
|
2014-07-11 19:58:24 +00:00
|
|
|
|
InvalidateAfter(frame);
|
2014-07-10 20:40:50 +00:00
|
|
|
|
Changes = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-11 16:26:19 +00:00
|
|
|
|
public void SetFloatState(int frame, string buttonName, float val)
|
|
|
|
|
{
|
|
|
|
|
if (frame < _log.Count)
|
|
|
|
|
{
|
|
|
|
|
var adapter = GetInputState(frame) as Bk2ControllerAdapter;
|
|
|
|
|
var old = adapter.GetFloat(buttonName);
|
|
|
|
|
adapter.SetFloat(buttonName, val);
|
|
|
|
|
|
|
|
|
|
var lg = LogGeneratorInstance();
|
|
|
|
|
lg.SetSource(adapter);
|
|
|
|
|
_log[frame] = lg.GenerateLogEntry();
|
|
|
|
|
|
|
|
|
|
if (old != val)
|
|
|
|
|
{
|
2014-07-11 19:58:24 +00:00
|
|
|
|
InvalidateAfter(frame);
|
2014-07-11 16:26:19 +00:00
|
|
|
|
Changes = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-10 20:40:50 +00:00
|
|
|
|
public bool BoolIsPressed(int frame, string buttonName)
|
|
|
|
|
{
|
|
|
|
|
var adapter = GetInputState(frame) as Bk2ControllerAdapter;
|
|
|
|
|
return adapter.IsPressed(buttonName);
|
|
|
|
|
}
|
2014-07-10 20:48:43 +00:00
|
|
|
|
|
2014-07-11 16:26:19 +00:00
|
|
|
|
public float GetFloatValue(int frame, string buttonName)
|
|
|
|
|
{
|
|
|
|
|
var adapter = GetInputState(frame) as Bk2ControllerAdapter;
|
|
|
|
|
return adapter.GetFloat(buttonName);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-10 20:48:43 +00:00
|
|
|
|
public override string GetInput(int frame)
|
|
|
|
|
{
|
|
|
|
|
if (Global.Emulator.Frame == frame && !StateManager.HasState(frame))
|
|
|
|
|
{
|
|
|
|
|
StateManager.Capture();
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-13 20:51:19 +00:00
|
|
|
|
if (Global.Emulator.Frame == frame && frame >= LagLog.Count)
|
|
|
|
|
{
|
|
|
|
|
LagLog.Add(Global.Emulator.IsLagFrame);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-10 20:48:43 +00:00
|
|
|
|
return base.GetInput(frame);
|
|
|
|
|
}
|
2014-07-11 15:43:47 +00:00
|
|
|
|
|
|
|
|
|
public TasStateManager.ManagerSettings GreenzoneSettings
|
|
|
|
|
{
|
|
|
|
|
get { return StateManager.Settings; }
|
|
|
|
|
}
|
2014-07-13 15:26:50 +00:00
|
|
|
|
|
|
|
|
|
public int LastEmulatedFrame
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return StateManager.Last.Key;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-01 20:55:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|