some mostly useless code reformatting in client.common

This commit is contained in:
adelikat 2014-02-04 03:08:20 +00:00
parent 255eb5adbf
commit 993845fe72
6 changed files with 167 additions and 231 deletions

View File

@ -6,6 +6,16 @@ using ICSharpCode.SharpZipLib.Zip;
namespace BizHawk.Client.Common
{
public enum BinaryStateLump
{
Versiontag,
Corestate,
Framebuffer,
Input,
CorestateText,
Movieheader
}
public class BinaryStateFileNames
{
/*
@ -36,22 +46,19 @@ namespace BizHawk.Client.Common
}
}
public enum BinaryStateLump
{
Versiontag,
Corestate,
Framebuffer,
Input,
CorestateText,
Movieheader
}
/// <summary>
/// more accurately should be called ZipStateLoader, as it supports both text and binary core data
/// </summary>
public class BinaryStateLoader : IDisposable
{
private ZipFile _zip;
private Version _ver;
private bool _isDisposed;
private BinaryStateLoader()
{
}
public void Dispose()
{
Dispose(true);
@ -71,13 +78,6 @@ namespace BizHawk.Client.Common
}
}
private ZipFile _zip;
private Version _ver;
private BinaryStateLoader()
{
}
private void ReadVersion(Stream s)
{
// the "BizState 1.0" tag contains an integer in it describing the sub version.
@ -139,8 +139,8 @@ namespace BizHawk.Client.Common
/// <returns>true if callback was called and stream was loaded</returns>
public bool GetLump(BinaryStateLump lump, bool abort, Action<Stream> callback)
{
string Name = BinaryStateFileNames.Get(lump);
var e = _zip.GetEntry(Name);
var name = BinaryStateFileNames.Get(lump);
var e = _zip.GetEntry(name);
if (e != null)
{
using (var zs = _zip.GetInputStream(e))
@ -150,15 +150,14 @@ namespace BizHawk.Client.Common
return true;
}
else if (abort)
if (abort)
{
throw new Exception("Essential zip section not found: " + Name);
throw new Exception("Essential zip section not found: " + name);
}
else
{
return false;
}
}
public bool GetLump(BinaryStateLump lump, bool abort, Action<BinaryReader> callback)
{
@ -198,28 +197,12 @@ namespace BizHawk.Client.Common
throw new Exception("Couldn't find Binary or Text savestate");
}
}
/*
public bool GetFrameBuffer(Action<Stream> callback)
{
return GetFileByName(BinaryStateFileNames.Framebuffer, false, callback);
}
public void GetInputLogRequired(Action<Stream> callback)
{
GetFileByName(BinaryStateFileNames.Input, true, callback);
}
public void GetMovieHeaderRequired(Action<Stream> callback)
{
GetFileByName(BinaryStateFileNames.Movieheader, true, callback);
}
*/
}
public class BinaryStateSaver : IDisposable
{
private readonly ZipOutputStream zip;
private readonly ZipOutputStream _zip;
private bool _isDisposed;
private static void WriteVersion(Stream s)
{
@ -234,23 +217,23 @@ namespace BizHawk.Client.Common
/// <param name="s">not closed when finished!</param>
public BinaryStateSaver(Stream s)
{
zip = new ZipOutputStream(s)
_zip = new ZipOutputStream(s)
{
IsStreamOwner = false,
UseZip64 = UseZip64.Off
};
zip.SetLevel(0);
_zip.SetLevel(0);
PutLump(BinaryStateLump.Versiontag, WriteVersion);
}
public void PutLump(BinaryStateLump lump, Action<Stream> callback)
{
string Name = BinaryStateFileNames.Get(lump);
var e = new ZipEntry(Name) {CompressionMethod = CompressionMethod.Stored};
zip.PutNextEntry(e);
callback(zip);
zip.CloseEntry();
var name = BinaryStateFileNames.Get(lump);
var e = new ZipEntry(name) {CompressionMethod = CompressionMethod.Stored};
_zip.PutNextEntry(e);
callback(_zip);
_zip.CloseEntry();
}
public void PutLump(BinaryStateLump lump, Action<BinaryWriter> callback)
@ -273,35 +256,6 @@ namespace BizHawk.Client.Common
});
}
/*
public void PutCoreStateBinary(Action<Stream> callback)
{
PutFileByName(BinaryStateFileNames.Corestate, callback);
}
public void PutCoreStateText(Action<Stream> callback)
{
PutFileByName(BinaryStateFileNames.CorestateText, callback);
}
public void PutFrameBuffer(Action<Stream> callback)
{
PutFileByName(BinaryStateFileNames.Framebuffer, callback);
}
public void PutInputLog(Action<Stream> callback)
{
PutFileByName(BinaryStateFileNames.Input, callback);
}
public void PutMovieHeader(Action<Stream> callback)
{
PutFileByName(BinaryStateFileNames.Movieheader, callback);
}
*/
private bool _isDisposed;
public void Dispose()
{
Dispose(true);
@ -316,7 +270,7 @@ namespace BizHawk.Client.Common
if (disposing)
{
zip.Close();
_zip.Close();
}
}
}

View File

@ -1,17 +1,10 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Text;
namespace BizHawk.Client.Common
{
using System.Linq;
public class MovieHeader : Dictionary<string, string>, IMovieHeader
{
public List<string> Comments { get; private set; }
public Dictionary<string, string> BoardProperties { get; private set; }
public SubtitleList Subtitles { get; private set; }
public MovieHeader()
{
Comments = new List<string>();
@ -20,17 +13,100 @@ namespace BizHawk.Client.Common
this[HeaderKeys.EMULATIONVERSION] = VersionInfo.GetEmuVersion();
this[HeaderKeys.MOVIEVERSION] = HeaderKeys.MovieVersion1;
this[HeaderKeys.PLATFORM] = Global.Emulator != null ? Global.Emulator.SystemId : String.Empty;
this[HeaderKeys.GAMENAME] = String.Empty;
this[HeaderKeys.AUTHOR] = String.Empty;
this[HeaderKeys.PLATFORM] = Global.Emulator != null ? Global.Emulator.SystemId : string.Empty;
this[HeaderKeys.GAMENAME] = string.Empty;
this[HeaderKeys.AUTHOR] = string.Empty;
this[HeaderKeys.RERECORDS] = "0";
}
public List<string> Comments { get; private set; }
public Dictionary<string, string> BoardProperties { get; private set; }
public SubtitleList Subtitles { get; private set; }
public ulong Rerecords
{
get
{
if (!ContainsKey(HeaderKeys.RERECORDS))
{
this[HeaderKeys.RERECORDS] = "0";
}
return ulong.Parse(this[HeaderKeys.RERECORDS]);
}
set
{
this[HeaderKeys.RERECORDS] = value.ToString();
}
}
public bool StartsFromSavestate
{
get
{
if (ContainsKey(HeaderKeys.STARTSFROMSAVESTATE))
{
return bool.Parse(this[HeaderKeys.STARTSFROMSAVESTATE]);
}
return false;
}
set
{
if (value)
{
Add(HeaderKeys.STARTSFROMSAVESTATE, "True");
}
else
{
Remove(HeaderKeys.STARTSFROMSAVESTATE);
}
}
}
public string GameName
{
get
{
if (ContainsKey(HeaderKeys.GAMENAME))
{
return this[HeaderKeys.GAMENAME];
}
return string.Empty;
}
set
{
this[HeaderKeys.GAMENAME] = value;
}
}
public string SystemID
{
get
{
if (ContainsKey(HeaderKeys.PLATFORM))
{
return this[HeaderKeys.PLATFORM];
}
return string.Empty;
}
set
{
this[HeaderKeys.PLATFORM] = value;
}
}
public new string this[string key]
{
get
{
return this.ContainsKey(key) ? base[key] : String.Empty;
return this.ContainsKey(key) ? base[key] : string.Empty;
}
set
@ -84,94 +160,9 @@ namespace BizHawk.Client.Common
return sb.ToString();
}
public ulong Rerecords
{
get
{
if (!ContainsKey(HeaderKeys.RERECORDS))
{
this[HeaderKeys.RERECORDS] = "0";
}
return ulong.Parse(this[HeaderKeys.RERECORDS]);
}
set
{
this[HeaderKeys.RERECORDS] = value.ToString();
}
}
public bool StartsFromSavestate
{
get
{
if (ContainsKey(HeaderKeys.STARTSFROMSAVESTATE))
{
return bool.Parse(this[HeaderKeys.STARTSFROMSAVESTATE]);
}
else
{
return false;
}
}
set
{
if (value)
{
Add(HeaderKeys.STARTSFROMSAVESTATE, "True");
}
else
{
Remove(HeaderKeys.STARTSFROMSAVESTATE);
}
}
}
public string GameName
{
get
{
if (ContainsKey(HeaderKeys.GAMENAME))
{
return this[HeaderKeys.GAMENAME];
}
else
{
return String.Empty;
}
}
set
{
this[HeaderKeys.GAMENAME] = value;
}
}
public string SystemID
{
get
{
if (ContainsKey(HeaderKeys.PLATFORM))
{
return this[HeaderKeys.PLATFORM];
}
else
{
return String.Empty;
}
}
set
{
this[HeaderKeys.PLATFORM] = value;
}
}
public bool ParseLineFromFile(string line)
{
if (!String.IsNullOrWhiteSpace(line))
if (!string.IsNullOrWhiteSpace(line))
{
var splitLine = line.Split(new[] { ' ' }, 2);

View File

@ -1,30 +1,13 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
namespace BizHawk.Client.Common
{
public class PlatformFrameRates
{
public double this[string systemId, bool pal]
{
get
{
var key = systemId + (pal ? "_PAL" : String.Empty);
if (_rates.ContainsKey(key))
{
return _rates[key];
}
else
{
return 60.0;
}
}
}
// these are political numbers, designed to be in accord with tasvideos.org tradition. theyre not necessarily mathematical factualities (although they may be in some cases)
// it would be nice if we could turn this into a rational expression natively, and also, to write some comments about the derivation and ideal valees (since this seems to be where theyre all collected)
// are we collecting them anywhere else? for avi-writing code perhaps?
private static Dictionary<string, double> _rates = new Dictionary<string, double>
private static readonly Dictionary<string, double> _rates = new Dictionary<string, double>
{
{ "NES", 60.098813897440515532 }, // discussion here: http://forums.nesdev.com/viewtopic.php?t=492 ; a rational expression would be (19687500 / 11) / ((341*262-0.529780.5)/3) -> (118125000 / 1965513) -> 60.098813897440515529533511098629 (so our chosen number is very close)
{ "NES_PAL", 50.006977968268290849 },
@ -53,5 +36,19 @@ namespace BizHawk.Client.Common
{ "A78", 59.9227510135505 },
{ "Coleco", 59.9227510135505 }
};
public double this[string systemId, bool pal]
{
get
{
var key = systemId + (pal ? "_PAL" : string.Empty);
if (_rates.ContainsKey(key))
{
return _rates[key];
}
return 60.0;
}
}
}
}

View File

@ -1,20 +1,12 @@
using System;
using System.Text;
using System.Text;
namespace BizHawk.Client.Common
{
public class Subtitle
{
public string Message { get; set; }
public int Frame { get; set; }
public int X { get; set; }
public int Y { get; set; }
public int Duration { get; set; }
public uint Color { get; set; }
public Subtitle()
{
Message = String.Empty;
Message = string.Empty;
X = 0;
Y = 0;
Duration = 120;
@ -32,6 +24,13 @@ namespace BizHawk.Client.Common
Color = s.Color;
}
public string Message { get; set; }
public int Frame { get; set; }
public int X { get; set; }
public int Y { get; set; }
public int Duration { get; set; }
public uint Color { get; set; }
public override string ToString()
{
var sb = new StringBuilder("subtitle ");
@ -40,7 +39,7 @@ namespace BizHawk.Client.Common
.Append(X).Append(" ")
.Append(Y).Append(" ")
.Append(Duration).Append(" ")
.Append(String.Format("{0:X8}", Color)).Append(" ")
.Append(string.Format("{0:X8}", Color)).Append(" ")
.Append(Message);
return sb.ToString();

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
@ -22,14 +21,14 @@ namespace BizHawk.Client.Common
public bool AddFromString(string subtitleStr)
{
if (!String.IsNullOrWhiteSpace(subtitleStr))
if (!string.IsNullOrWhiteSpace(subtitleStr))
{
try
{
var subparts = subtitleStr.Split(' ');
// Unfortunately I made the file format space delminated so this hack is necessary to get the message
var message = String.Empty;
var message = string.Empty;
for (var i = 6; i < subparts.Length; i++)
{
message += subparts[i] + ' ';
@ -52,10 +51,8 @@ namespace BizHawk.Client.Common
return false;
}
}
else
{
return false;
}
}
}
}

View File

@ -5,11 +5,6 @@ namespace BizHawk.Client.Common
{
public class Rewinder
{
public Rewinder()
{
RewindActive = true;
}
private StreamBlobDatabase _rewindBuffer;
private RewindThreader _rewindThread;
private byte[] _lastState;
@ -19,6 +14,11 @@ namespace BizHawk.Client.Common
private byte[] _rewindFellationBuf;
private byte[] _tempBuf = new byte[0];
public Rewinder()
{
RewindActive = true;
}
public Action<string> MessageCallback { get; set; }
public bool RewindActive { get; set; }
@ -220,12 +220,10 @@ namespace BizHawk.Client.Common
// otherwise, allocate it
return new byte[size];
}
else
{
_rewindFellationBuf = inbuf;
return null;
}
}
private void CaptureRewindStateNonDelta(byte[] currentState)
{