TasMovie - round 1 of replacing mnemonic system with an IMnemonicGenerator system, this breaks stuff, but nothing anyone should have been using.
This commit is contained in:
parent
2f28317f92
commit
15d0e1adb6
|
@ -123,6 +123,7 @@
|
||||||
<Compile Include="lua\LuaFunctionList.cs" />
|
<Compile Include="lua\LuaFunctionList.cs" />
|
||||||
<Compile Include="lua\LuaLibraryBase.cs" />
|
<Compile Include="lua\LuaLibraryBase.cs" />
|
||||||
<Compile Include="lua\NamedLuaFunction.cs" />
|
<Compile Include="lua\NamedLuaFunction.cs" />
|
||||||
|
<Compile Include="movie\ControllerLookups\MnemonicGeneratorFactory.cs" />
|
||||||
<Compile Include="movie\ControllerLookups\MnemonicGenerators.cs" />
|
<Compile Include="movie\ControllerLookups\MnemonicGenerators.cs" />
|
||||||
<Compile Include="movie\ControllerLookups\NesMnemonicGenerator.cs" />
|
<Compile Include="movie\ControllerLookups\NesMnemonicGenerator.cs" />
|
||||||
<Compile Include="movie\HeaderKeys.cs" />
|
<Compile Include="movie\HeaderKeys.cs" />
|
||||||
|
|
|
@ -31,11 +31,17 @@ namespace BizHawk.Client.Common
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string EmptyMnemonicString { get; }
|
string EmptyMnemonicString { get; }
|
||||||
|
|
||||||
|
// Analog TODO: this assumes the Generator is boolean
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parses a segment of a full mnemonic string (the content between pipes)
|
/// Parses a segment of a full mnemonic string (the content between pipes)
|
||||||
/// Note: this assume the pipes are not being passed in!
|
/// Note: this assume the pipes are not being passed in!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
IDictionary<string, bool> ParseMnemonicSegment(string mnemonicSegment);
|
IDictionary<string, bool> ParseMnemonicSegment(string mnemonicSegment);
|
||||||
|
|
||||||
|
// Analog Support TODO: this assume the Generator is boolean
|
||||||
|
//Dictionary<string, bool> GetBoolButtons();
|
||||||
|
|
||||||
|
Dictionary<string, char> AvailableMnemonics { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -49,6 +55,11 @@ namespace BizHawk.Client.Common
|
||||||
/// </summary>
|
/// </summary>
|
||||||
int Count { get; }
|
int Count { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Source controller to read input state from
|
||||||
|
/// </summary>
|
||||||
|
IController Source { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the given port with an IMnemonicGenerator implementation
|
/// Gets or sets the given port with an IMnemonicGenerator implementation
|
||||||
/// Ports are zero based
|
/// Ports are zero based
|
||||||
|
@ -61,6 +72,18 @@ namespace BizHawk.Client.Common
|
||||||
/// Gets an IMnemonicGenerator implementation that represents the buttons and controls on the console itself (Reset, Power, etc)
|
/// Gets an IMnemonicGenerator implementation that represents the buttons and controls on the console itself (Reset, Power, etc)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
IMnemonicGenerator ConsoleControls { get; }
|
IMnemonicGenerator ConsoleControls { get; }
|
||||||
|
|
||||||
|
Dictionary<string, bool> ParseMnemonicString(string mnemonicStr);
|
||||||
|
|
||||||
|
// Analog TODO: this assume the generators are boolean
|
||||||
|
Dictionary<string, bool> GetBoolButtons();
|
||||||
|
|
||||||
|
// TODO: this shouldn't be required, refactor MovieRecord
|
||||||
|
string GenerateMnemonicString(Dictionary<string, bool> buttons);
|
||||||
|
|
||||||
|
string EmptyMnemonic { get; }
|
||||||
|
|
||||||
|
Dictionary<string, char> AvailableMnemonics { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BooleanControllerMnemonicGenerator : IMnemonicGenerator
|
public class BooleanControllerMnemonicGenerator : IMnemonicGenerator
|
||||||
|
@ -77,6 +100,14 @@ namespace BizHawk.Client.Common
|
||||||
_controllerMnemonics.Add(key, value);
|
_controllerMnemonics.Add(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Dictionary<string, char> AvailableMnemonics
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _controllerMnemonics.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public IController Source { get; set; }
|
public IController Source { get; set; }
|
||||||
public string ControllerPrefix { get; set; }
|
public string ControllerPrefix { get; set; }
|
||||||
public string Name
|
public string Name
|
||||||
|
|
|
@ -2,15 +2,21 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using BizHawk.Emulation.Common;
|
||||||
|
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
public class NesMnemonicGenerator : IMnemonicPorts
|
public class NesMnemonicGenerator : IMnemonicPorts
|
||||||
{
|
{
|
||||||
public NesMnemonicGenerator(bool fds = false, bool isFourscore = false)
|
public NesMnemonicGenerator(IController source, bool fds = false, bool isFourscore = false)
|
||||||
{
|
{
|
||||||
|
Source = source;
|
||||||
_isFds = fds;
|
_isFds = fds;
|
||||||
_isFourscore = isFourscore;
|
_isFourscore = isFourscore;
|
||||||
|
|
||||||
|
_nesConsoleControls.Source = source;
|
||||||
|
_fdsConsoleControls.Source = source;
|
||||||
|
_controllerPorts.ForEach(x => x.Source = source);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool FourScoreEnabled
|
public bool FourScoreEnabled
|
||||||
|
@ -32,6 +38,8 @@ namespace BizHawk.Client.Common
|
||||||
get { return _isFourscore ? 4 : 2; }
|
get { return _isFourscore ? 4 : 2; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IController Source { get; set; }
|
||||||
|
|
||||||
// This is probably not necessary, but let's see how things go
|
// This is probably not necessary, but let's see how things go
|
||||||
public IEnumerable<IMnemonicGenerator> AvailableGenerators
|
public IEnumerable<IMnemonicGenerator> AvailableGenerators
|
||||||
{
|
{
|
||||||
|
@ -86,6 +94,86 @@ namespace BizHawk.Client.Common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region TODO: nothing specific to this object here, this could be done in a base class
|
||||||
|
|
||||||
|
public Dictionary<string, bool> ParseMnemonicString(string mnemonicStr)
|
||||||
|
{
|
||||||
|
var segments = mnemonicStr.Split('|');
|
||||||
|
var kvps = new List<KeyValuePair<string,bool>>();
|
||||||
|
var generators = AvailableGenerators.ToList();
|
||||||
|
for(int i = 0; i < mnemonicStr.Length; i++)
|
||||||
|
{
|
||||||
|
kvps.AddRange(generators[i].ParseMnemonicSegment(segments[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return kvps.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dictionary<string, bool> GetBoolButtons()
|
||||||
|
{
|
||||||
|
List<IMnemonicGenerator> generators = AvailableGenerators.ToList();
|
||||||
|
|
||||||
|
return generators
|
||||||
|
.SelectMany(mc => mc.AvailableMnemonics)
|
||||||
|
.ToDictionary(kvp => kvp.Key, kvp => this.Source.IsPressed(kvp.Key));
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: this shouldn't be required, refactor MovieRecord
|
||||||
|
public string GenerateMnemonicString(Dictionary<string, bool> buttons)
|
||||||
|
{
|
||||||
|
var mnemonics = AvailableMnemonics;
|
||||||
|
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
sb.Append('|');
|
||||||
|
|
||||||
|
foreach (var generator in AvailableGenerators)
|
||||||
|
{
|
||||||
|
foreach (var blah in generator.AvailableMnemonics)
|
||||||
|
{
|
||||||
|
if (buttons.ContainsKey(blah.Key))
|
||||||
|
{
|
||||||
|
sb.Append(buttons[blah.Key] ? blah.Value : '.');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sb.Append('.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Append('|');
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string EmptyMnemonic
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var blah = AvailableGenerators.Select(x => x.EmptyMnemonicString);
|
||||||
|
return "|" + String.Join("|", blah) + "|";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: refactor me!
|
||||||
|
public Dictionary<string, char> AvailableMnemonics
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var kvps = new List<KeyValuePair<string, char>>();
|
||||||
|
foreach (var blah in AvailableGenerators)
|
||||||
|
{
|
||||||
|
foreach (var blah2 in blah.AvailableMnemonics)
|
||||||
|
{
|
||||||
|
kvps.Add(blah2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return kvps.ToDictionary(x => x.Key, x => x.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Privates
|
#region Privates
|
||||||
|
@ -114,7 +202,6 @@ namespace BizHawk.Client.Common
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Source = Global.MovieOutputHardpoint,
|
|
||||||
ControllerPrefix = String.Empty
|
ControllerPrefix = String.Empty
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -130,7 +217,6 @@ namespace BizHawk.Client.Common
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Source = Global.MovieOutputHardpoint,
|
|
||||||
ControllerPrefix = String.Empty
|
ControllerPrefix = String.Empty
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -139,22 +225,18 @@ namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
new BooleanControllerMnemonicGenerator("Player 1", _basicController)
|
new BooleanControllerMnemonicGenerator("Player 1", _basicController)
|
||||||
{
|
{
|
||||||
Source = Global.MovieOutputHardpoint,
|
|
||||||
ControllerPrefix = "P1"
|
ControllerPrefix = "P1"
|
||||||
},
|
},
|
||||||
new BooleanControllerMnemonicGenerator("Player 2", _basicController)
|
new BooleanControllerMnemonicGenerator("Player 2", _basicController)
|
||||||
{
|
{
|
||||||
Source = Global.MovieOutputHardpoint,
|
|
||||||
ControllerPrefix = "P2"
|
ControllerPrefix = "P2"
|
||||||
},
|
},
|
||||||
new BooleanControllerMnemonicGenerator("Player 3", _basicController)
|
new BooleanControllerMnemonicGenerator("Player 3", _basicController)
|
||||||
{
|
{
|
||||||
Source = Global.MovieOutputHardpoint,
|
|
||||||
ControllerPrefix = "P3"
|
ControllerPrefix = "P3"
|
||||||
},
|
},
|
||||||
new BooleanControllerMnemonicGenerator("Player 4", _basicController)
|
new BooleanControllerMnemonicGenerator("Player 4", _basicController)
|
||||||
{
|
{
|
||||||
Source = Global.MovieOutputHardpoint,
|
|
||||||
ControllerPrefix = "P4"
|
ControllerPrefix = "P4"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,6 +8,7 @@ using BizHawk.Emulation.Common;
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
// Used with the version 2 movie implementation (TasMovie.cs)
|
// Used with the version 2 movie implementation (TasMovie.cs)
|
||||||
|
/*
|
||||||
public class NewMnemonicsGenerator
|
public class NewMnemonicsGenerator
|
||||||
{
|
{
|
||||||
public MnemonicLookupTable MnemonicLookup { get; private set; }
|
public MnemonicLookupTable MnemonicLookup { get; private set; }
|
||||||
|
@ -157,4 +158,5 @@ namespace BizHawk.Client.Common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace BizHawk.Client.Common
|
||||||
// TODO: preloading, or benchmark and see how much of a performaance gain it really is
|
// TODO: preloading, or benchmark and see how much of a performaance gain it really is
|
||||||
// TODO: support loop Offset
|
// TODO: support loop Offset
|
||||||
// TODO: consider the fileformat of binary and lagged data
|
// TODO: consider the fileformat of binary and lagged data
|
||||||
private readonly NewMnemonicsGenerator _mg;
|
private readonly IMnemonicPorts _mg;
|
||||||
private readonly IController _source = Global.MovieOutputHardpoint;
|
private readonly IController _source = Global.MovieOutputHardpoint;
|
||||||
|
|
||||||
public MovieRecord this[int index]
|
public MovieRecord this[int index]
|
||||||
|
@ -27,8 +27,7 @@ namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var mg = new NewMnemonicsGenerator(_source) { ActivePlayers = this.ActivePlayers };
|
return _mg.AvailableMnemonics;
|
||||||
return mg.AvailableMnemonics;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,14 +88,13 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
public TasMovie(bool startsFromSavestate = false)
|
public TasMovie(bool startsFromSavestate = false)
|
||||||
{
|
{
|
||||||
|
_mg = MnemonicGeneratorFactory.Generate();
|
||||||
Filename = String.Empty;
|
Filename = String.Empty;
|
||||||
Header = new MovieHeader { StartsFromSavestate = startsFromSavestate };
|
Header = new MovieHeader { StartsFromSavestate = startsFromSavestate };
|
||||||
Header[HeaderKeys.MOVIEVERSION] = HeaderKeys.MovieVersion2;
|
Header[HeaderKeys.MOVIEVERSION] = HeaderKeys.MovieVersion2;
|
||||||
_records = new MovieRecordList();
|
_records = new MovieRecordList();
|
||||||
_mode = Moviemode.Inactive;
|
_mode = Moviemode.Inactive;
|
||||||
IsCountingRerecords = true;
|
IsCountingRerecords = true;
|
||||||
|
|
||||||
_mg = new NewMnemonicsGenerator(_source);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Filename { get; set; }
|
public string Filename { get; set; }
|
||||||
|
|
Loading…
Reference in New Issue