From 993845fe7281d79bf7815cf146fea15d6ce95ccc Mon Sep 17 00:00:00 2001 From: adelikat Date: Tue, 4 Feb 2014 03:08:20 +0000 Subject: [PATCH] some mostly useless code reformatting in client.common --- BizHawk.Client.Common/BinarySaveStates.cs | 114 ++++------- BizHawk.Client.Common/movie/MovieHeader.cs | 187 +++++++++--------- .../movie/PlatformFrameRates.cs | 43 ++-- BizHawk.Client.Common/movie/Subtitle.cs | 21 +- BizHawk.Client.Common/movie/SubtitleList.cs | 13 +- BizHawk.Client.Common/rewind/Rewinder.cs | 20 +- 6 files changed, 167 insertions(+), 231 deletions(-) diff --git a/BizHawk.Client.Common/BinarySaveStates.cs b/BizHawk.Client.Common/BinarySaveStates.cs index 0081a7ba94..1ad3a3f110 100644 --- a/BizHawk.Client.Common/BinarySaveStates.cs +++ b/BizHawk.Client.Common/BinarySaveStates.cs @@ -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 - } - /// /// more accurately should be called ZipStateLoader, as it supports both text and binary core data /// 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 /// true if callback was called and stream was loaded public bool GetLump(BinaryStateLump lump, bool abort, Action 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,14 +150,13 @@ namespace BizHawk.Client.Common return true; } - else if (abort) + + if (abort) { - throw new Exception("Essential zip section not found: " + Name); - } - else - { - return false; + throw new Exception("Essential zip section not found: " + name); } + + return false; } public bool GetLump(BinaryStateLump lump, bool abort, Action callback) @@ -198,28 +197,12 @@ namespace BizHawk.Client.Common throw new Exception("Couldn't find Binary or Text savestate"); } } - - /* - public bool GetFrameBuffer(Action callback) - { - return GetFileByName(BinaryStateFileNames.Framebuffer, false, callback); - } - - public void GetInputLogRequired(Action callback) - { - GetFileByName(BinaryStateFileNames.Input, true, callback); - } - - public void GetMovieHeaderRequired(Action 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 /// not closed when finished! 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 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 callback) @@ -273,35 +256,6 @@ namespace BizHawk.Client.Common }); } - /* - public void PutCoreStateBinary(Action callback) - { - PutFileByName(BinaryStateFileNames.Corestate, callback); - } - - public void PutCoreStateText(Action callback) - { - PutFileByName(BinaryStateFileNames.CorestateText, callback); - } - - public void PutFrameBuffer(Action callback) - { - PutFileByName(BinaryStateFileNames.Framebuffer, callback); - } - - public void PutInputLog(Action callback) - { - PutFileByName(BinaryStateFileNames.Input, callback); - } - - public void PutMovieHeader(Action 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(); } } } diff --git a/BizHawk.Client.Common/movie/MovieHeader.cs b/BizHawk.Client.Common/movie/MovieHeader.cs index 4d28c7f247..395bc1540e 100644 --- a/BizHawk.Client.Common/movie/MovieHeader.cs +++ b/BizHawk.Client.Common/movie/MovieHeader.cs @@ -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, IMovieHeader { - public List Comments { get; private set; } - public Dictionary BoardProperties { get; private set; } - public SubtitleList Subtitles { get; private set; } - public MovieHeader() { Comments = new List(); @@ -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 Comments { get; private set; } + public Dictionary 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); diff --git a/BizHawk.Client.Common/movie/PlatformFrameRates.cs b/BizHawk.Client.Common/movie/PlatformFrameRates.cs index 5c436ea415..de61493213 100644 --- a/BizHawk.Client.Common/movie/PlatformFrameRates.cs +++ b/BizHawk.Client.Common/movie/PlatformFrameRates.cs @@ -1,32 +1,15 @@ -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 + // 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 readonly Dictionary _rates = new Dictionary { - 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 _rates = new Dictionary - { - { "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", 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 }, { "FDS", 60.098813897440515532 }, { "FDS_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; + } + } } } diff --git a/BizHawk.Client.Common/movie/Subtitle.cs b/BizHawk.Client.Common/movie/Subtitle.cs index 356d994b5c..dbc7cff4d2 100644 --- a/BizHawk.Client.Common/movie/Subtitle.cs +++ b/BizHawk.Client.Common/movie/Subtitle.cs @@ -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(); diff --git a/BizHawk.Client.Common/movie/SubtitleList.cs b/BizHawk.Client.Common/movie/SubtitleList.cs index 4bee48622f..738904f617 100644 --- a/BizHawk.Client.Common/movie/SubtitleList.cs +++ b/BizHawk.Client.Common/movie/SubtitleList.cs @@ -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; - } + + return false; } } } \ No newline at end of file diff --git a/BizHawk.Client.Common/rewind/Rewinder.cs b/BizHawk.Client.Common/rewind/Rewinder.cs index a2c3d63632..740881fe48 100644 --- a/BizHawk.Client.Common/rewind/Rewinder.cs +++ b/BizHawk.Client.Common/rewind/Rewinder.cs @@ -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 MessageCallback { get; set; } public bool RewindActive { get; set; } @@ -220,11 +220,9 @@ namespace BizHawk.Client.Common // otherwise, allocate it return new byte[size]; } - else - { - _rewindFellationBuf = inbuf; - return null; - } + + _rewindFellationBuf = inbuf; + return null; } private void CaptureRewindStateNonDelta(byte[] currentState) @@ -251,7 +249,7 @@ namespace BizHawk.Client.Common var inChangeSequence = false; // try to set up the buffer in advance so we dont ever have exceptions in here - //zeromus says: this sets off red flags for me. vecna got an exception that might be related to this inflating to 2x the input size. we should add an emergency check, or analyze how much it could inflate by (perhaps 3x would be adequate in every case?) + // zeromus says: this sets off red flags for me. vecna got an exception that might be related to this inflating to 2x the input size. we should add an emergency check, or analyze how much it could inflate by (perhaps 3x would be adequate in every case?) if (_tempBuf.Length < currentState.Length) { _tempBuf = new byte[currentState.Length * 2];