From 3f866f6d7f1da05c1dbcd741f37511b5ee072e8f Mon Sep 17 00:00:00 2001
From: adelikat <adelikat@tasvideos.org>
Date: Wed, 19 Apr 2017 12:44:02 -0500
Subject: [PATCH] Rename SnesSaveController to SaveController and move it to
 Emulation.Common since it is used by multiple cores and is general in design

---
 .../BizHawk.Emulation.Common.csproj           |   1 +
 BizHawk.Emulation.Common/SaveController.cs    | 100 +++++++++++++++++
 .../Consoles/Nintendo/Gameboy/GambatteLink.cs |   4 +-
 .../Nintendo/SNES/LibsnesCore.IEmulator.cs    |   2 +-
 .../Nintendo/SNES/LibsnesCore.IStatable.cs    |   2 +-
 .../Consoles/Nintendo/SNES/LibsnesCore.cs     | 104 ------------------
 6 files changed, 105 insertions(+), 108 deletions(-)
 create mode 100644 BizHawk.Emulation.Common/SaveController.cs

diff --git a/BizHawk.Emulation.Common/BizHawk.Emulation.Common.csproj b/BizHawk.Emulation.Common/BizHawk.Emulation.Common.csproj
index 81770041f7..f59446d021 100644
--- a/BizHawk.Emulation.Common/BizHawk.Emulation.Common.csproj
+++ b/BizHawk.Emulation.Common/BizHawk.Emulation.Common.csproj
@@ -141,6 +141,7 @@
     <Compile Include="Interfaces\Services\ITraceable.cs" />
     <Compile Include="Interfaces\Services\IVideoProvider.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="SaveController.cs" />
     <Compile Include="ServiceAttributes.cs" />
     <Compile Include="ServiceInjector.cs" />
     <Compile Include="Sound\Utilities\BlipBuffer.cs" />
diff --git a/BizHawk.Emulation.Common/SaveController.cs b/BizHawk.Emulation.Common/SaveController.cs
new file mode 100644
index 0000000000..d54e99f62c
--- /dev/null
+++ b/BizHawk.Emulation.Common/SaveController.cs
@@ -0,0 +1,100 @@
+using System;
+using System.IO;
+using System.Linq;
+
+using BizHawk.Common;
+
+namespace BizHawk.Emulation.Common
+{
+	/// <summary>
+	/// Can freeze a copy of a controller input set and serialize\deserialize it
+	/// </summary>
+	public class SaveController : IController
+	{
+		private readonly WorkingDictionary<string, float> _buttons = new WorkingDictionary<string, float>();
+
+		public SaveController()
+		{
+			Definition = null;
+		}
+
+		public SaveController(ControllerDefinition def)
+		{
+			Definition = def;
+		}
+
+		/// <summary>
+		/// Gets the current definition.
+		/// Invalid until CopyFrom has been called
+		/// </summary>
+		public ControllerDefinition Definition { get; private set; }
+
+		public void Serialize(BinaryWriter b)
+		{
+			b.Write(_buttons.Keys.Count);
+			foreach (var k in _buttons.Keys)
+			{
+				b.Write(k);
+				b.Write(_buttons[k]);
+			}
+		}
+
+		/// <summary>
+		/// No checking to see if the deserialized controls match any definition
+		/// </summary>
+		public void DeSerialize(BinaryReader b)
+		{
+			_buttons.Clear();
+			int numbuttons = b.ReadInt32();
+			for (int i = 0; i < numbuttons; i++)
+			{
+				string k = b.ReadString();
+				float v = b.ReadSingle();
+				_buttons.Add(k, v);
+			}
+		}
+
+		/// <summary>
+		/// This controller's definition changes to that of source
+		/// </summary>
+		public void CopyFrom(IController source)
+		{
+			Definition = source.Definition;
+			_buttons.Clear();
+			foreach (var k in Definition.BoolButtons)
+			{
+				_buttons.Add(k, source.IsPressed(k) ? 1.0f : 0);
+			}
+
+			foreach (var k in Definition.FloatControls)
+			{
+				if (_buttons.Keys.Contains(k))
+				{
+					throw new Exception("name collision between bool and float lists!");
+				}
+
+				_buttons.Add(k, source.GetFloat(k));
+			}
+		}
+
+		public void Clear()
+		{
+			_buttons.Clear();
+		}
+
+		public void Set(string button)
+		{
+			_buttons[button] = 1.0f;
+		}
+
+		public bool IsPressed(string button)
+		{
+			return _buttons[button] != 0;
+		}
+
+		public float GetFloat(string name)
+		{
+			return _buttons[name];
+		}
+	}
+}
diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs
index ee2c510cc7..06bfcfe30b 100644
--- a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs
+++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs
@@ -73,8 +73,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
 
 		const int SampPerFrame = 35112;
 
-		LibsnesCore.SnesSaveController LCont = new LibsnesCore.SnesSaveController(Gameboy.GbController);
-		LibsnesCore.SnesSaveController RCont = new LibsnesCore.SnesSaveController(Gameboy.GbController);
+		SaveController LCont = new SaveController(Gameboy.GbController);
+		SaveController RCont = new SaveController(Gameboy.GbController);
 
 		public bool IsCGBMode(bool right)
 		{
diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.IEmulator.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.IEmulator.cs
index 0ebc11b1fb..549fe06788 100644
--- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.IEmulator.cs
+++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.IEmulator.cs
@@ -39,7 +39,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
 				var bw = new BinaryWriter(ms);
 				bw.Write(CoreSaveState());
 				bw.Write(false); // not framezero
-				var ssc = new SnesSaveController();
+				var ssc = new SaveController();
 				ssc.CopyFrom(Controller);
 				ssc.Serialize(bw);
 				bw.Close();
diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.IStatable.cs
index 594854bceb..de565bf3d7 100644
--- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.IStatable.cs
+++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.IStatable.cs
@@ -58,7 +58,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
 				bw.Write(framezero);
 				if (!framezero)
 				{
-					var ssc = new SnesSaveController(ControllerDefinition);
+					var ssc = new SaveController(ControllerDefinition);
 					ssc.DeSerialize(reader);
 					IController tmp = Controller;
 					Controller = ssc;
diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs
index 5e9ce8c735..79f9c3e666 100644
--- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs
+++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs
@@ -3,7 +3,6 @@ using System.Linq;
 using System.Xml;
 using System.IO;
 
-using BizHawk.Common;
 using BizHawk.Common.BufferExtensions;
 using BizHawk.Emulation.Common;
 using BizHawk.Emulation.Cores.Components.W65816;
@@ -557,108 +556,5 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
 		{
 			SetPalette((SnesColors.ColorType)Enum.Parse(typeof(SnesColors.ColorType), _settings.Palette, false));
 		}
-
-		/// <summary>
-		/// can freeze a copy of a controller input set and serialize\deserialize it
-		/// </summary>
-		public class SnesSaveController : IController
-		{
-			// this is all rather general, so perhaps should be moved out of LibsnesCore
-			ControllerDefinition _def;
-
-			public SnesSaveController()
-			{
-				_def = null;
-			}
-
-			public SnesSaveController(ControllerDefinition def)
-			{
-				_def = def;
-			}
-
-			private readonly WorkingDictionary<string, float> buttons = new WorkingDictionary<string, float>();
-
-			/// <summary>
-			/// invalid until CopyFrom has been called
-			/// </summary>
-			public ControllerDefinition Definition
-			{
-				get { return _def; }
-			}
-
-			public void Serialize(BinaryWriter b)
-			{
-				b.Write(buttons.Keys.Count);
-				foreach (var k in buttons.Keys)
-				{
-					b.Write(k);
-					b.Write(buttons[k]);
-				}
-			}
-
-			/// <summary>
-			/// no checking to see if the deserialized controls match any definition
-			/// </summary>
-			/// <param name="b"></param>
-			public void DeSerialize(BinaryReader b)
-			{
-				buttons.Clear();
-				int numbuttons = b.ReadInt32();
-				for (int i = 0; i < numbuttons; i++)
-				{
-					string k = b.ReadString();
-					float v = b.ReadSingle();
-					buttons.Add(k, v);
-				}
-			}
-
-			/// <summary>
-			/// this controller's definition changes to that of source
-			/// </summary>
-			public void CopyFrom(IController source)
-			{
-				this._def = source.Definition;
-				buttons.Clear();
-				foreach (var k in _def.BoolButtons)
-				{
-					buttons.Add(k, source.IsPressed(k) ? 1.0f : 0);
-				}
-
-				foreach (var k in _def.FloatControls)
-				{
-					if (buttons.Keys.Contains(k))
-					{
-						throw new Exception("name collision between bool and float lists!");
-					}
-
-					buttons.Add(k, source.GetFloat(k));
-				}
-			}
-
-			public void Clear()
-			{
-				buttons.Clear();
-			}
-
-			public void Set(string button)
-			{
-				buttons[button] = 1.0f;
-			}
-
-			public bool this[string button]
-			{
-				get { return buttons[button] != 0; }
-			}
-
-			public bool IsPressed(string button)
-			{
-				return buttons[button] != 0;
-			}
-
-			public float GetFloat(string name)
-			{
-				return buttons[name];
-			}
-		}
 	}
 }