A round of code cleanup on movie code

This commit is contained in:
adelikat 2014-06-29 03:03:27 +00:00
parent 9fd640ff4b
commit 9e73db3daa
24 changed files with 179 additions and 201 deletions

View File

@ -6,7 +6,6 @@ using System.IO;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Nintendo.SNES;
using BizHawk.Client.Common.MovieConversionExtensions;
namespace BizHawk.Client.Common
@ -135,7 +134,7 @@ namespace BizHawk.Client.Common
// Return whether or not the type of file provided can currently be imported.
public static bool IsValidMovieExtension(string extension)
{
string[] extensions = new[]
string[] extensions =
{
"FCM", "FM2", "FMV", "GMV", "MCM", "MC2", "MMV", "NMV", "LSMV", "SMV", "VBM", "VMV", "YMV", "ZMV"
};
@ -163,9 +162,9 @@ namespace BizHawk.Client.Common
private static BkmMovie ImportTextFrame(string line, int lineNum, BkmMovie m, string path, string platform,
ref string warningMsg)
{
string[] buttons = new string[] { };
string controller = "";
string ext = path != null ? Path.GetExtension(path).ToUpper() : "";
string[] buttons = { };
var controller = string.Empty;
var ext = path != null ? Path.GetExtension(path).ToUpper() : "";
switch (ext)
{
case ".FM2":
@ -192,7 +191,7 @@ namespace BizHawk.Client.Common
controller = "Saturn Controller";
break;
}
SimpleController controllers = new SimpleController {Type = new ControllerDefinition {Name = controller}};
var controllers = new SimpleController {Type = new ControllerDefinition {Name = controller}};
// Split up the sections of the frame.
string[] sections = line.Split('|');
if (ext == ".FM2" && sections.Length >= 2 && sections[1].Length != 0)
@ -269,7 +268,7 @@ namespace BizHawk.Client.Common
{
// The player number is one less than the section number for the reasons explained above.
int player = section + player_offset;
string prefix = "P" + (player).ToString() + " ";
string prefix = "P" + (player) + " ";
// Gameboy doesn't currently have a prefix saying which player the input is for.
if (controllers.Type.Name == "Gameboy Controller")
{
@ -327,11 +326,11 @@ namespace BizHawk.Client.Common
private static BkmMovie ImportText(string path, out string errorMsg, out string warningMsg)
{
errorMsg = warningMsg = string.Empty;
BkmMovie m = new BkmMovie(path);
FileInfo file = new FileInfo(path);
StreamReader sr = file.OpenText();
string emulator = string.Empty;
string platform = string.Empty;
var m = new BkmMovie(path);
var file = new FileInfo(path);
var sr = file.OpenText();
var emulator = string.Empty;
var platform = string.Empty;
switch (Path.GetExtension(path).ToUpper())
{
case ".FM2":
@ -573,7 +572,7 @@ namespace BizHawk.Client.Common
m.Header[HeaderKeys.PAL] = pal.ToString();
// other: reserved, set to 0
bool syncHack = (((flags >> 4) & 0x1) != 0);
m.Comments.Add(SYNCHACK + " " + syncHack.ToString());
m.Comments.Add(SYNCHACK + " " + syncHack);
// 009 1-byte flags: reserved, set to 0
r.ReadByte();
// 00A 1-byte flags: reserved, set to 0
@ -599,7 +598,7 @@ namespace BizHawk.Client.Common
m.Header[MD5] = Util.BytesToHexString(md5).ToLower();
// 030 4-byte little-endian unsigned int: version of the emulator used
uint emuVersion = r.ReadUInt32();
m.Comments.Add(EMULATIONORIGIN + " FCEU " + emuVersion.ToString());
m.Comments.Add(EMULATIONORIGIN + " FCEU " + emuVersion);
// 034 name of the ROM used - UTF8 encoded nul-terminated string.
List<byte> gameBytes = new List<byte>();
while (r.PeekChar() != 0)
@ -623,7 +622,7 @@ namespace BizHawk.Client.Common
// Advance to first byte of input data.
r.BaseStream.Position = firstFrameOffset;
SimpleController controllers = new SimpleController {Type = new ControllerDefinition {Name = "NES Controller"}};
string[] buttons = new[] { "A", "B", "Select", "Start", "Up", "Down", "Left", "Right" };
string[] buttons = { "A", "B", "Select", "Start", "Up", "Down", "Left", "Right" };
bool fds = false;
bool fourscore = false;
int frame = 1;
@ -864,8 +863,8 @@ namespace BizHawk.Client.Common
* 40 Select
* 80 Start
*/
string[] buttons = new[] { "Right", "Left", "Up", "Down", "B", "A", "Select", "Start" };
bool[] masks = new[] { controller1, controller2, FDS };
string[] buttons = { "Right", "Left", "Up", "Down", "B", "A", "Select", "Start" };
bool[] masks = { controller1, controller2, FDS };
/*
The file has no terminator byte or frame count. The number of frames is the <filesize minus 144> divided by
<number of bytes per frame>.
@ -986,7 +985,7 @@ namespace BizHawk.Client.Common
* 0x40 C
* 0x80 Start
*/
string[] buttons = new[] { "Up", "Down", "Left", "Right", "A", "B", "C", "Start" };
string[] buttons = { "Up", "Down", "Left", "Right", "A", "B", "C", "Start" };
/*
For XYZ-mode, each value is determined by OR-ing together values for whichever of the following are left
unpressed:
@ -999,7 +998,7 @@ namespace BizHawk.Client.Common
* 0x40 Controller 2 Z
* 0x80 Controller 2 Mode
*/
string[] other = new[] { "X", "Y", "Z", "Mode" };
string[] other = { "X", "Y", "Z", "Mode" };
// The file has no terminator byte or frame count. The number of frames is the <filesize minus 64> divided by 3.
long frameCount = (fs.Length - 64) / 3;
for (long frame = 1; frame <= frameCount; frame++)
@ -1040,8 +1039,8 @@ namespace BizHawk.Client.Common
private static BkmMovie ImportLSMV(string path, out string errorMsg, out string warningMsg)
{
errorMsg = warningMsg = string.Empty;
BkmMovie m = new BkmMovie(path);
HawkFile hf = new HawkFile(path);
var m = new BkmMovie(path);
var hf = new HawkFile(path);
// .LSMV movies are .zip files containing data files.
if (!hf.IsArchive)
{
@ -1276,7 +1275,7 @@ namespace BizHawk.Client.Common
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
BinaryReader r = new BinaryReader(fs);
// 000 8-byte "MDFNMOVI" signature
string signature = r.ReadStringFixedAscii(8);
var signature = r.ReadStringFixedAscii(8);
if (signature != "MDFNMOVI")
{
errorMsg = "This is not a valid .MCM file.";
@ -1286,7 +1285,7 @@ namespace BizHawk.Client.Common
}
// 008 uint32 Mednafen Version (Current is 0A 08)
uint emuVersion = r.ReadUInt32();
m.Comments.Add(EMULATIONORIGIN + " Mednafen " + emuVersion.ToString());
m.Comments.Add(EMULATIONORIGIN + " Mednafen " + emuVersion);
// 00C uint32 Movie Format Version (Current is 01)
uint version = r.ReadUInt32();
m.Comments.Add(MOVIEORIGIN + " .MCM version " + version);
@ -1407,7 +1406,7 @@ namespace BizHawk.Client.Common
}
// 0004: 4-byte little endian unsigned int: dega version
uint emuVersion = r.ReadUInt32();
m.Comments.Add(EMULATIONORIGIN + " Dega version " + emuVersion.ToString());
m.Comments.Add(EMULATIONORIGIN + " Dega version " + emuVersion);
m.Comments.Add(MOVIEORIGIN + " .MMV");
// 0008: 4-byte little endian unsigned int: frame count
uint frameCount = r.ReadUInt32();
@ -1461,7 +1460,7 @@ namespace BizHawk.Client.Common
// 00e4-00f3: binary: rom MD5 digest
byte[] md5 = r.ReadBytes(16);
m.Header[MD5] = string.Format("{0:x8}", Util.BytesToHexString(md5).ToLower());
SimpleController controllers = new SimpleController {Type = new ControllerDefinition {Name = "SMS Controller"}};
var controllers = new SimpleController { Type = new ControllerDefinition { Name = "SMS Controller" }};
/*
76543210
* bit 0 (0x01): up
@ -1473,7 +1472,7 @@ namespace BizHawk.Client.Common
* bit 6 (0x40): start (Master System)
* bit 7 (0x80): start (Game Gear)
*/
string[] buttons = new[] { "Up", "Down", "Left", "Right", "B1", "B2" };
string[] buttons = { "Up", "Down", "Left", "Right", "B1", "B2" };
for (int frame = 1; frame <= frameCount; frame++)
{
/*
@ -1902,7 +1901,7 @@ namespace BizHawk.Client.Common
00 40 Y
00 80 B
*/
string[] buttons = new[]
string[] buttons =
{
"Right", "Left", "Down", "Up", "Start", "Select", "Y", "B", "R", "L", "X", "A"
};
@ -1937,7 +1936,7 @@ namespace BizHawk.Client.Common
*/
if (version != "1.43" && player <= controllerTypes.Length)
{
string peripheral = "";
var peripheral = string.Empty;
switch (controllerTypes[player - 1])
{
// NONE
@ -2216,7 +2215,7 @@ namespace BizHawk.Client.Common
* 00 01 R
* 00 02 L
*/
string[] buttons = new[] { "A", "B", "Select", "Start", "Right", "Left", "Up", "Down", "R", "L" };
string[] buttons = { "A", "B", "Select", "Start", "Right", "Left", "Up", "Down", "R", "L" };
/*
* 00 04 Reset (old timing)
* 00 08 Reset (new timing since version 1.1)
@ -2225,7 +2224,8 @@ namespace BizHawk.Client.Common
* 00 40 Down motion sensor
* 00 80 Up motion sensor
*/
string[] other = new[] {
string[] other =
{
"Reset (old timing)" , "Reset (new timing since version 1.1)", "Left motion sensor",
"Right motion sensor", "Down motion sensor", "Up motion sensor"
};
@ -2624,7 +2624,7 @@ namespace BizHawk.Client.Common
* bit 1: Left
* bit 0: Right
*/
string[] buttons = new[]
string[] buttons =
{
"Right", "Left", "Down", "Up", "Start", "Select", "Y", "B", "R", "L", "X", "A"
};
@ -2787,7 +2787,7 @@ namespace BizHawk.Client.Common
}
r.BaseStream.Position = r.BaseStream.Length - authorSize;
// Last in the file comes the author name field, which is an UTF-8 encoded text string.
string author = Encoding.UTF8.GetString(r.ReadBytes(authorSize));
var author = Encoding.UTF8.GetString(r.ReadBytes(authorSize));
m.Header[HeaderKeys.AUTHOR] = author;
return m;
}

View File

@ -1,11 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using BizHawk.Common;
using BizHawk.Client.Common.MovieConversionExtensions;
namespace BizHawk.Client.Common
@ -14,31 +10,26 @@ namespace BizHawk.Client.Common
{
public static IMovie Get(string path)
{
// TODO: open the file and determine the format, and instantiate the appropriate implementation
// Currently we just use the file extension
// TODO: change IMovies to take HawkFiles only and not path
if (Path.GetExtension(path).EndsWith("bk2"))
{
return new Bk2Movie(path);
}
else if (Path.GetExtension(path).EndsWith("tasproj"))
if (Path.GetExtension(path).EndsWith("tasproj"))
{
return new TasMovie(path);
}
else
{
var movie = new BkmMovie(path);
if (VersionInfo.DeveloperBuild)
{
movie.Load();
return movie.ToBk2();
}
else
{
return movie;
}
var movie = new BkmMovie(path);
if (VersionInfo.DeveloperBuild)
{
movie.Load();
return movie.ToBk2();
}
return movie;
}
/// <summary>

View File

@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using BizHawk.Emulation.Common;

View File

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BizHawk.Common;
using BizHawk.Emulation.Common;
@ -10,7 +9,7 @@ namespace BizHawk.Client.Common
{
public class Bk2ControllerAdapter : IMovieController
{
private string _logKey = string.Empty;
private readonly string _logKey = string.Empty;
public Bk2ControllerAdapter()
{
@ -27,14 +26,10 @@ namespace BizHawk.Client.Common
{
if (!string.IsNullOrEmpty(_logKey))
{
// TODO: this could be cleaned up into a LINQ select
List<List<string>> controls = new List<List<string>>();
var groups = _logKey.Split(new[] { "#" }, StringSplitOptions.RemoveEmptyEntries);
foreach (var group in groups)
{
var buttons = group.Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries).ToList();
controls.Add(buttons);
}
var controls = groups
.Select(@group => @group.Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries).ToList())
.ToList();
_type.ControlsFromLog = controls;
}
@ -82,7 +77,7 @@ namespace BizHawk.Client.Common
/// </summary>
public void LatchPlayerFromSource(IController playerSource, int playerNum)
{
foreach (string button in playerSource.Type.BoolButtons)
foreach (var button in playerSource.Type.BoolButtons)
{
var bnp = ButtonNameParser.Parse(button);
if (bnp == null)
@ -95,7 +90,7 @@ namespace BizHawk.Client.Common
continue;
}
bool val = playerSource[button];
var val = playerSource[button];
MyBoolButtons[button] = val;
}
}
@ -105,12 +100,12 @@ namespace BizHawk.Client.Common
/// </summary>
public void LatchFromSource(IController source)
{
foreach (string button in Type.BoolButtons)
foreach (var button in Type.BoolButtons)
{
MyBoolButtons[button] = source[button];
}
foreach (string name in Type.FloatControls)
foreach (var name in Type.FloatControls)
{
MyFloatControls[name] = source.GetFloat(name);
}
@ -127,26 +122,21 @@ namespace BizHawk.Client.Common
var trimmed = mnemonic.Replace("|", "");
var buttons = Type.ControlsOrdered.SelectMany(x => x).ToList();
var iterator = 0;
var boolIt = 0;
var floatIt = 0;
for (int i = 0; i < buttons.Count; i++)
foreach (var key in buttons)
{
var b = buttons[i];
if (def.BoolButtons.Contains(buttons[i]))
if (def.BoolButtons.Contains(key))
{
MyBoolButtons[buttons[i]] = trimmed[iterator] == '.' ? false : true;
this.MyBoolButtons[key] = trimmed[iterator] != '.';
iterator++;
boolIt++;
}
else if (def.FloatControls.Contains(buttons[i]))
else if (def.FloatControls.Contains(key))
{
string temp = trimmed.Substring(iterator, 4);
var temp = trimmed.Substring(iterator, 4);
var val = int.Parse(temp.Trim());
MyFloatControls[buttons[i]] = val;
this.MyFloatControls[key] = val;
iterator += 5;
floatIt++;
}
}
}
@ -157,7 +147,6 @@ namespace BizHawk.Client.Common
public class Bk2ControllerDefinition : ControllerDefinition
{
public Bk2ControllerDefinition()
: base()
{
}

View File

@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Generic;
using System.Text;
namespace BizHawk.Client.Common

View File

@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq;
using System.Text;
using BizHawk.Emulation.Common;
@ -11,7 +9,7 @@ namespace BizHawk.Client.Common
{
private readonly Bk2MnemonicConstants Mnemonics = new Bk2MnemonicConstants();
private IController _source;
private string _logKey = string.Empty;
private readonly string _logKey = string.Empty;
public Bk2LogEntryGenerator(string logKey)
{

View File

@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Generic;
namespace BizHawk.Client.Common
{
@ -23,11 +20,13 @@ namespace BizHawk.Client.Common
{
return SystemOverrides[Global.Emulator.SystemId][key];
}
else if (BaseMnemonicLookupTable.ContainsKey(key))
if (BaseMnemonicLookupTable.ContainsKey(key))
{
return BaseMnemonicLookupTable[key];
}
else if (key.Length == 1)
if (key.Length == 1)
{
return key[0];
}

View File

@ -1,11 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Generic;
using System.Text;
namespace BizHawk.Client.Common
{
public partial class Bk2Movie : IMovie
public partial class Bk2Movie
{
protected readonly Bk2Header Header = new Bk2Header();
private string _syncSettingsJson = string.Empty;
@ -173,7 +171,7 @@ namespace BizHawk.Client.Common
private string CommentsString()
{
StringBuilder sb = new StringBuilder();
var sb = new StringBuilder();
foreach(var comment in Comments)
{

View File

@ -1,14 +1,11 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using BizHawk.Common;
namespace BizHawk.Client.Common
{
public partial class Bk2Movie : IMovie
public partial class Bk2Movie
{
public void Save()
{
@ -43,7 +40,7 @@ namespace BizHawk.Client.Common
return false;
}
using (BinaryStateLoader bl = BinaryStateLoader.LoadAndDetect(Filename, true))
using (var bl = BinaryStateLoader.LoadAndDetect(Filename, true))
{
if (bl == null)
{
@ -59,7 +56,7 @@ namespace BizHawk.Client.Common
{
if (!string.IsNullOrWhiteSpace(line))
{
var pair = line.Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
var pair = line.Split(new[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
if (pair.Length > 1)
{
@ -107,7 +104,7 @@ namespace BizHawk.Client.Common
bl.GetLump(BinaryStateLump.Input, true, delegate(TextReader tr)
{
string errorMessage = string.Empty;
var errorMessage = string.Empty;
ExtractInputLog(tr, out errorMessage);
});
@ -142,15 +139,15 @@ namespace BizHawk.Client.Common
private void Write(string fn)
{
using (FileStream fs = new FileStream(Filename, FileMode.Create, FileAccess.Write))
using (BinaryStateSaver bs = new BinaryStateSaver(fs, false))
using (var fs = new FileStream(fn, FileMode.Create, FileAccess.Write))
using (var bs = new BinaryStateSaver(fs, false))
{
bs.PutLump(BinaryStateLump.Movieheader, (tw) => tw.WriteLine(Header.ToString()));
bs.PutLump(BinaryStateLump.Comments, (tw) => tw.WriteLine(CommentsString()));
bs.PutLump(BinaryStateLump.Subtitles, (tw) => tw.WriteLine(Subtitles.ToString()));
bs.PutLump(BinaryStateLump.SyncSettings, (tw) => tw.WriteLine(_syncSettingsJson));
bs.PutLump(BinaryStateLump.Movieheader, tw => tw.WriteLine(Header.ToString()));
bs.PutLump(BinaryStateLump.Comments, tw => tw.WriteLine(CommentsString()));
bs.PutLump(BinaryStateLump.Subtitles, tw => tw.WriteLine(Subtitles.ToString()));
bs.PutLump(BinaryStateLump.SyncSettings, tw => tw.WriteLine(_syncSettingsJson));
bs.PutLump(BinaryStateLump.Input, (tw) => tw.WriteLine(RawInputLog()));
bs.PutLump(BinaryStateLump.Input, tw => tw.WriteLine(RawInputLog()));
if (StartsFromSavestate)
{

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
@ -7,7 +6,7 @@ using System.Text;
namespace BizHawk.Client.Common
{
public partial class Bk2Movie : IMovie
public partial class Bk2Movie
{
private readonly List<string> _log = new List<string>();
private string _logKey = string.Empty;

View File

@ -1,11 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq;
namespace BizHawk.Client.Common
{
public partial class Bk2Movie : IMovie
public partial class Bk2Movie
{
private enum Moviemode { Inactive, Play, Record, Finished }
private Moviemode _mode = Moviemode.Inactive;

View File

@ -1,17 +1,12 @@
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();
private bool _makeBackup = true;
public Bk2Movie(string filename)

View File

@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using BizHawk.Common;
using BizHawk.Emulation.Common;
@ -37,7 +35,7 @@ namespace BizHawk.Client.Common
/// </summary>
public void LatchPlayerFromSource(IController playerSource, int playerNum)
{
foreach (string button in playerSource.Type.BoolButtons)
foreach (var button in playerSource.Type.BoolButtons)
{
var bnp = ButtonNameParser.Parse(button);
if (bnp == null)
@ -50,7 +48,7 @@ namespace BizHawk.Client.Common
continue;
}
bool val = playerSource[button];
var val = playerSource[button];
MyBoolButtons[button] = val;
}
}
@ -60,12 +58,12 @@ namespace BizHawk.Client.Common
/// </summary>
public void LatchFromSource(IController source)
{
foreach (string button in Type.BoolButtons)
foreach (var button in Type.BoolButtons)
{
MyBoolButtons[button] = source[button];
}
foreach (string name in Type.FloatControls)
foreach (var name in Type.FloatControls)
{
MyFloatControls[name] = source.GetFloat(name);
}
@ -80,58 +78,68 @@ namespace BizHawk.Client.Common
{
return;
}
else if (ControlType == "SNES Controller")
if (ControlType == "SNES Controller")
{
SetSNESControllersAsMnemonic(mnemonic);
return;
}
else if (ControlType == "Commodore 64 Controller")
if (ControlType == "Commodore 64 Controller")
{
SetC64ControllersAsMnemonic(mnemonic);
return;
}
else if (ControlType == "GBA Controller")
if (ControlType == "GBA Controller")
{
SetGBAControllersAsMnemonic(mnemonic);
return;
}
else if (ControlType == "Atari 7800 ProLine Joystick Controller")
if (ControlType == "Atari 7800 ProLine Joystick Controller")
{
SetAtari7800AsMnemonic(mnemonic);
return;
}
else if (ControlType == "Dual Gameboy Controller")
if (ControlType == "Dual Gameboy Controller")
{
SetDualGameBoyControllerAsMnemonic(mnemonic);
return;
}
else if (ControlType == "WonderSwan Controller")
if (ControlType == "WonderSwan Controller")
{
SetWonderSwanControllerAsMnemonic(mnemonic);
return;
}
else if (ControlType == "Nintento 64 Controller")
if (ControlType == "Nintento 64 Controller")
{
SetN64ControllersAsMnemonic(mnemonic);
return;
}
else if (ControlType == "Saturn Controller")
if (ControlType == "Saturn Controller")
{
SetSaturnControllersAsMnemonic(mnemonic);
return;
}
else if (ControlType == "PSP Controller")
if (ControlType == "PSP Controller")
{
// TODO
return;
}
else if (ControlType == "GPGX Genesis Controller")
if (ControlType == "GPGX Genesis Controller")
{
SetGensis6ControllersAsMnemonic(mnemonic);
return;
}
MnemonicChecker c = new MnemonicChecker(mnemonic);
var c = new MnemonicChecker(mnemonic);
MyBoolButtons.Clear();
@ -222,7 +230,7 @@ namespace BizHawk.Client.Common
{
int srcindex = BkmMnemonicConstants.PLAYERS[ControlType] * (BkmMnemonicConstants.BUTTONS[ControlType].Count + 1);
int ctr = start;
foreach (string command in BkmMnemonicConstants.COMMANDS[ControlType].Keys)
foreach (var command in BkmMnemonicConstants.COMMANDS[ControlType].Keys)
{
Force(command, c[srcindex + ctr++]);
}
@ -308,7 +316,7 @@ namespace BizHawk.Client.Common
private void SetSNESControllersAsMnemonic(string mnemonic)
{
MnemonicChecker c = new MnemonicChecker(mnemonic);
var c = new MnemonicChecker(mnemonic);
MyBoolButtons.Clear();
if (mnemonic.Length < 2)
@ -335,7 +343,7 @@ namespace BizHawk.Client.Common
}
int start = 3;
foreach (string button in BkmMnemonicConstants.BUTTONS[ControlType].Keys)
foreach (var button in BkmMnemonicConstants.BUTTONS[ControlType].Keys)
{
Force("P" + player + " " + button, c[srcindex + start++]);
}
@ -492,7 +500,7 @@ namespace BizHawk.Client.Common
private void SetC64ControllersAsMnemonic(string mnemonic)
{
MnemonicChecker c = new MnemonicChecker(mnemonic);
var c = new MnemonicChecker(mnemonic);
MyBoolButtons.Clear();
@ -506,7 +514,7 @@ namespace BizHawk.Client.Common
}
int start = 1;
foreach (string button in BkmMnemonicConstants.BUTTONS[ControlType].Keys)
foreach (var button in BkmMnemonicConstants.BUTTONS[ControlType].Keys)
{
Force("P" + player + " " + button, c[srcindex + start++]);
}
@ -519,7 +527,7 @@ namespace BizHawk.Client.Common
}
}
private class MnemonicChecker
private sealed class MnemonicChecker
{
private readonly string _mnemonic;

View File

@ -22,13 +22,26 @@ namespace BizHawk.Client.Common
public string SavestateBinaryBase64Blob
{
get {
if (ContainsKey(HeaderKeys.SAVESTATEBINARYBASE64BLOB)) return this[HeaderKeys.SAVESTATEBINARYBASE64BLOB];
else return null;
get
{
if (ContainsKey(HeaderKeys.SAVESTATEBINARYBASE64BLOB))
{
return this[HeaderKeys.SAVESTATEBINARYBASE64BLOB];
}
return null;
}
set {
if (value == null) Remove(HeaderKeys.SAVESTATEBINARYBASE64BLOB);
else Add(HeaderKeys.SAVESTATEBINARYBASE64BLOB, value);
set
{
if (value == null)
{
Remove(HeaderKeys.SAVESTATEBINARYBASE64BLOB);
}
else
{
Add(HeaderKeys.SAVESTATEBINARYBASE64BLOB, value);
}
}
}

View File

@ -21,43 +21,53 @@ namespace BizHawk.Client.Common
{
return "|.|";
}
else if (_controlType == "Atari 7800 ProLine Joystick Controller")
if (_controlType == "Atari 7800 ProLine Joystick Controller")
{
return GetA78ControllersAsMnemonic();
}
else if (_controlType == "SNES Controller")
if (_controlType == "SNES Controller")
{
return GetSNESControllersAsMnemonic();
}
else if (_controlType == "Commodore 64 Controller")
if (_controlType == "Commodore 64 Controller")
{
return GetC64ControllersAsMnemonic();
}
else if (_controlType == "GBA Controller")
if (_controlType == "GBA Controller")
{
return GetGBAControllersAsMnemonic();
}
else if (_controlType == "Dual Gameboy Controller")
if (_controlType == "Dual Gameboy Controller")
{
return GetDualGameBoyControllerAsMnemonic();
}
else if (_controlType == "WonderSwan Controller")
if (_controlType == "WonderSwan Controller")
{
return GetWonderSwanControllerAsMnemonic();
}
else if (_controlType == "Nintento 64 Controller")
if (_controlType == "Nintento 64 Controller")
{
return GetN64ControllersAsMnemonic();
}
else if (_controlType == "Saturn Controller")
if (_controlType == "Saturn Controller")
{
return GetSaturnControllersAsMnemonic();
}
else if (_controlType == "PSP Controller")
if (_controlType == "PSP Controller")
{
return "|.|"; // TODO
}
else if (_controlType == "GPGX Genesis Controller")
if (_controlType == "GPGX Genesis Controller")
{
return GetGeneis6ButtonControllersAsMnemonic();
}

View File

@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
using BizHawk.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common
{
@ -165,7 +161,7 @@ namespace BizHawk.Client.Common
// just experimenting with different possibly more painful ways to handle mnemonics
// |P|UDLRsSBA|
public static Tuple<string, char>[] DGBMnemonic = new[]
public static Tuple<string, char>[] DGBMnemonic =
{
new Tuple<string, char>(null, '|'),
new Tuple<string, char>("P1 Power", 'P'),
@ -192,7 +188,7 @@ namespace BizHawk.Client.Common
new Tuple<string, char>(null, '|')
};
public static Tuple<string, char>[] WSMnemonic = new[]
public static Tuple<string, char>[] WSMnemonic =
{
new Tuple<string, char>(null, '|'),
new Tuple<string, char>("P1 X1", '1'),
@ -221,7 +217,7 @@ namespace BizHawk.Client.Common
new Tuple<string, char>(null, '|'),
new Tuple<string, char>("Power", 'P'),
new Tuple<string, char>("Rotate", 'R'),
new Tuple<string, char>(null, '|'),
new Tuple<string, char>(null, '|')
};
}
}

View File

@ -2,7 +2,7 @@
namespace BizHawk.Client.Common
{
public partial class BkmMovie : IMovie
public partial class BkmMovie
{
public IDictionary<string, string> HeaderEntries
{

View File

@ -6,7 +6,7 @@ using BizHawk.Common;
namespace BizHawk.Client.Common
{
public partial class BkmMovie : IMovie
public partial class BkmMovie
{
private int _preloadFramecount; // Not a a reliable number, used for preloading (when no log has yet been loaded), this is only for quick stat compilation for dialogs such as play movie
@ -142,11 +142,15 @@ namespace BizHawk.Client.Common
//read to first space (key/value delimeter), or pipe, or EOF
int first = sr.Read();
if (first == -1) break; //EOF
else if (first == '|') //pipe: begin input log
if (first == -1)
{
break;
} // EOF
if (first == '|') //pipe: begin input log
{
//NOTE - this code is a bit convoluted due to its predating the basic outline of the parser which was upgraded in may 2014
string line = '|' + sr.ReadLine();
var line = '|' + sr.ReadLine();
//how many bytes are left, total?
long remain = sr.BaseStream.Length - sr.BaseStream.Position;
@ -178,7 +182,7 @@ namespace BizHawk.Client.Common
else
{
//a header line. finish reading key token, to make sure it isn't one of the FORBIDDEN keys
StringBuilder sbLine = new StringBuilder();
var sbLine = new StringBuilder();
sbLine.Append((char)first);
for (; ; )
{
@ -210,7 +214,7 @@ namespace BizHawk.Client.Common
}
string remainder = sr.ReadLine();
var remainder = sr.ReadLine();
sbLine.Append(' ');
sbLine.Append(remainder);
line = sbLine.ToString();

View File

@ -6,7 +6,7 @@ using System.Text;
namespace BizHawk.Client.Common
{
public partial class BkmMovie : IMovie
public partial class BkmMovie
{
private readonly List<string> _log = new List<string>();

View File

@ -2,7 +2,7 @@
namespace BizHawk.Client.Common
{
public partial class BkmMovie : IMovie
public partial class BkmMovie
{
private enum Moviemode { Inactive, Play, Record, Finished }

View File

@ -1,11 +1,9 @@
using System;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common
{
public partial class BkmMovie : IMovie
{
private readonly PlatformFrameRates _frameRates = new PlatformFrameRates();
private bool _makeBackup = true;
private bool _changes;
private int? _loopOffset;
@ -130,14 +128,16 @@ namespace BizHawk.Client.Common
getframe = frame;
}
var adapter = new BkmControllerAdapter();
adapter.Type = Global.MovieSession.MovieControllerAdapter.Type;
var adapter = new BkmControllerAdapter
{
Type = Global.MovieSession.MovieControllerAdapter.Type
};
adapter.SetControllersAsMnemonic(_log[getframe]);
return adapter;
}
Finish();
return null; ;
return null;
}
public void ClearFrame(int frame)

View File

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace BizHawk.Client.Common.MovieConversionExtensions
namespace BizHawk.Client.Common.MovieConversionExtensions
{
public static class MovieConversionExtensions
{
@ -35,7 +29,7 @@ namespace BizHawk.Client.Common.MovieConversionExtensions
bk2.TextSavestate = bkm.TextSavestate;
bk2.BinarySavestate = bkm.BinarySavestate;
for (int i = 0; i < bkm.InputLogLength; i++)
for (var i = 0; i < bkm.InputLogLength; i++)
{
var input = bkm.GetInputState(i);
bk2.AppendFrame(input);

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using BizHawk.Common;

View File

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common
{