Refactor autofire, remove the autofire adaptor. Added an autofire bool to IController and implemented it in the Controller object. Setting to true will turn the controller buttons into autofire buttons
This commit is contained in:
parent
fe33e75c1b
commit
0d01af5c7b
|
@ -2,124 +2,128 @@
|
|||
|
||||
namespace BizHawk
|
||||
{
|
||||
public class InputRecorder : IController
|
||||
{
|
||||
private IController baseController;
|
||||
private BinaryWriter writer;
|
||||
public class InputRecorder : IController
|
||||
{
|
||||
private IController baseController;
|
||||
private BinaryWriter writer;
|
||||
|
||||
public InputRecorder(IController baseController, BinaryWriter writer)
|
||||
{
|
||||
this.baseController = baseController;
|
||||
this.writer = writer;
|
||||
}
|
||||
public InputRecorder(IController baseController, BinaryWriter writer)
|
||||
{
|
||||
this.baseController = baseController;
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
public void CloseMovie()
|
||||
{
|
||||
writer.Close();
|
||||
}
|
||||
public void CloseMovie()
|
||||
{
|
||||
writer.Close();
|
||||
}
|
||||
|
||||
public ControllerDefinition Type
|
||||
{
|
||||
get { return baseController.Type; }
|
||||
}
|
||||
public ControllerDefinition Type
|
||||
{
|
||||
get { return baseController.Type; }
|
||||
}
|
||||
|
||||
public bool this[string button]
|
||||
{
|
||||
get { return baseController[button]; }
|
||||
}
|
||||
public bool this[string button]
|
||||
{
|
||||
get { return baseController[button]; }
|
||||
}
|
||||
|
||||
public bool IsPressed(string button)
|
||||
{
|
||||
return baseController[button];
|
||||
}
|
||||
public bool IsPressed(string button)
|
||||
{
|
||||
return baseController[button];
|
||||
}
|
||||
|
||||
public float GetFloat(string name)
|
||||
{
|
||||
return baseController.GetFloat(name);
|
||||
}
|
||||
|
||||
private int frame;
|
||||
public float GetFloat(string name)
|
||||
{
|
||||
return baseController.GetFloat(name);
|
||||
}
|
||||
|
||||
public void UpdateControls(int frame)
|
||||
{
|
||||
if (this.frame != frame)
|
||||
{
|
||||
this.frame = frame;
|
||||
baseController.UpdateControls(frame);
|
||||
RecordFrame();
|
||||
}
|
||||
}
|
||||
private int frame;
|
||||
|
||||
private void RecordFrame()
|
||||
{
|
||||
int encodedValue = 0;
|
||||
for (int i=0; i<Type.BoolButtons.Count; i++)
|
||||
{
|
||||
if (baseController[Type.BoolButtons[i]])
|
||||
{
|
||||
encodedValue |= (1 << i);
|
||||
}
|
||||
}
|
||||
writer.Seek(frame*2, SeekOrigin.Begin);
|
||||
writer.Write((ushort)encodedValue);
|
||||
}
|
||||
}
|
||||
public void UpdateControls(int frame)
|
||||
{
|
||||
if (this.frame != frame)
|
||||
{
|
||||
this.frame = frame;
|
||||
baseController.UpdateControls(frame);
|
||||
RecordFrame();
|
||||
}
|
||||
}
|
||||
|
||||
public class InputPlayback : IController
|
||||
{
|
||||
private ControllerDefinition def;
|
||||
private int[] input;
|
||||
private int frame;
|
||||
private void RecordFrame()
|
||||
{
|
||||
int encodedValue = 0;
|
||||
for (int i = 0; i < Type.BoolButtons.Count; i++)
|
||||
{
|
||||
if (baseController[Type.BoolButtons[i]])
|
||||
{
|
||||
encodedValue |= (1 << i);
|
||||
}
|
||||
}
|
||||
writer.Seek(frame * 2, SeekOrigin.Begin);
|
||||
writer.Write((ushort)encodedValue);
|
||||
}
|
||||
|
||||
public InputPlayback(ControllerDefinition controllerDefinition, BinaryReader reader)
|
||||
{
|
||||
def = controllerDefinition;
|
||||
int numFrames = (int) (reader.BaseStream.Length/2);
|
||||
input = new int[numFrames];
|
||||
for (int i=0; i<numFrames; i++)
|
||||
input[i] = reader.ReadUInt16();
|
||||
}
|
||||
public bool Autofire { get { return false; } set { } }
|
||||
}
|
||||
|
||||
public ControllerDefinition Type
|
||||
{
|
||||
get { return def; }
|
||||
}
|
||||
public class InputPlayback : IController
|
||||
{
|
||||
private ControllerDefinition def;
|
||||
private int[] input;
|
||||
private int frame;
|
||||
|
||||
public bool this[string button]
|
||||
{
|
||||
get { return IsPressed(button); }
|
||||
}
|
||||
public InputPlayback(ControllerDefinition controllerDefinition, BinaryReader reader)
|
||||
{
|
||||
def = controllerDefinition;
|
||||
int numFrames = (int)(reader.BaseStream.Length / 2);
|
||||
input = new int[numFrames];
|
||||
for (int i = 0; i < numFrames; i++)
|
||||
input[i] = reader.ReadUInt16();
|
||||
}
|
||||
|
||||
public bool IsPressed(string button)
|
||||
{
|
||||
if (frame >= input.Length)
|
||||
return false;
|
||||
public ControllerDefinition Type
|
||||
{
|
||||
get { return def; }
|
||||
}
|
||||
|
||||
for (int i = 0; i < def.BoolButtons.Count; i++)
|
||||
{
|
||||
if (def.BoolButtons[i] == button)
|
||||
{
|
||||
return (input[frame] & (1 << i)) != 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public bool this[string button]
|
||||
{
|
||||
get { return IsPressed(button); }
|
||||
}
|
||||
|
||||
public void UpdateControls(int frame)
|
||||
{
|
||||
this.frame = frame;
|
||||
}
|
||||
public bool IsPressed(string button)
|
||||
{
|
||||
if (frame >= input.Length)
|
||||
return false;
|
||||
|
||||
public float GetFloat(string name)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
for (int i = 0; i < def.BoolButtons.Count; i++)
|
||||
{
|
||||
if (def.BoolButtons[i] == button)
|
||||
{
|
||||
return (input[frame] & (1 << i)) != 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void UnpressButton(string name) {}
|
||||
public void ForceButton(string button) { }
|
||||
public void SetSticky(string button, bool sticky) { }
|
||||
public bool IsSticky(string button) { return false; }
|
||||
|
||||
public bool MovieEnded { get { return frame >= input.Length; } }
|
||||
}
|
||||
public void UpdateControls(int frame)
|
||||
{
|
||||
this.frame = frame;
|
||||
}
|
||||
|
||||
public float GetFloat(string name)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public void UnpressButton(string name) { }
|
||||
public void ForceButton(string button) { }
|
||||
public void SetSticky(string button, bool sticky) { }
|
||||
public bool IsSticky(string button) { return false; }
|
||||
|
||||
public bool MovieEnded { get { return frame >= input.Length; } }
|
||||
|
||||
public bool Autofire { get { return false; } set { } }
|
||||
}
|
||||
}
|
|
@ -1,19 +1,20 @@
|
|||
namespace BizHawk
|
||||
{
|
||||
public class NullController : IController
|
||||
{
|
||||
public ControllerDefinition Type { get { return null; } }
|
||||
public bool this[string button] { get { return false; } }
|
||||
public bool IsPressed(string button) { return false; }
|
||||
public float GetFloat(string name) { return 0f; }
|
||||
public void UpdateControls(int frame) { }
|
||||
public void UnpressButton(string button) { }
|
||||
public void ForceButton(string button) { }
|
||||
public class NullController : IController
|
||||
{
|
||||
public ControllerDefinition Type { get { return null; } }
|
||||
public bool this[string button] { get { return false; } }
|
||||
public bool IsPressed(string button) { return false; }
|
||||
public float GetFloat(string name) { return 0f; }
|
||||
public void UpdateControls(int frame) { }
|
||||
public void UnpressButton(string button) { }
|
||||
public void ForceButton(string button) { }
|
||||
|
||||
public void SetSticky(string button, bool sticky) { }
|
||||
public bool IsSticky(string button) { return false; }
|
||||
public void SetSticky(string button, bool sticky) { }
|
||||
public bool IsSticky(string button) { return false; }
|
||||
|
||||
private static NullController nullController = new NullController();
|
||||
public static NullController GetNullController() { return nullController; }
|
||||
}
|
||||
private static NullController nullController = new NullController();
|
||||
public static NullController GetNullController() { return nullController; }
|
||||
public bool Autofire { get { return false; } set { } }
|
||||
}
|
||||
}
|
|
@ -2,25 +2,28 @@
|
|||
|
||||
namespace BizHawk
|
||||
{
|
||||
public class ControllerDefinition
|
||||
{
|
||||
public string Name;
|
||||
public List<string> BoolButtons = new List<string>();
|
||||
public List<string> FloatControls = new List<string>();
|
||||
}
|
||||
public class ControllerDefinition
|
||||
{
|
||||
public string Name;
|
||||
public List<string> BoolButtons = new List<string>();
|
||||
public List<string> FloatControls = new List<string>();
|
||||
}
|
||||
|
||||
public interface IController
|
||||
{
|
||||
ControllerDefinition Type { get; }
|
||||
public interface IController
|
||||
{
|
||||
ControllerDefinition Type { get; }
|
||||
|
||||
//TODO - it is obnoxious for this to be here. must be removed.
|
||||
bool this[string button] { get; }
|
||||
bool this[string button] { get; }
|
||||
//TODO - this can stay but it needs to be changed to go through the float
|
||||
bool IsPressed(string button);
|
||||
bool IsPressed(string button);
|
||||
|
||||
float GetFloat(string name);
|
||||
|
||||
float GetFloat(string name);
|
||||
|
||||
//TODO - why does this have a frame argument. must be removed.
|
||||
void UpdateControls(int frame);
|
||||
}
|
||||
void UpdateControls(int frame);
|
||||
|
||||
//Flag for whether the controller will behave like a autofire (rapid fire) controller
|
||||
bool Autofire { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,11 +60,6 @@ namespace BizHawk.MultiClient
|
|||
/// </summary>
|
||||
public static StickyXORAdapter StickyXORAdapter = new StickyXORAdapter();
|
||||
|
||||
/// <summary>
|
||||
/// Auto-fire (Rapid fire) of controller buttons
|
||||
/// </summary>
|
||||
public static AutoFireAdapter AutoFireAdapter = new AutoFireAdapter();
|
||||
|
||||
/// <summary>
|
||||
/// fire off one-frame logical button clicks here. useful for things like ti-83 virtual pad and reset buttons
|
||||
/// </summary>
|
||||
|
|
|
@ -10,6 +10,9 @@ namespace BizHawk.MultiClient
|
|||
private WorkingDictionary<string, List<string>> bindings = new WorkingDictionary<string, List<string>>();
|
||||
private WorkingDictionary<string, bool> buttons = new WorkingDictionary<string, bool>();
|
||||
|
||||
private bool autofire = false;
|
||||
public bool Autofire { get { return false; } set { autofire = value; } }
|
||||
|
||||
public Controller(ControllerDefinition definition)
|
||||
{
|
||||
type = definition;
|
||||
|
@ -17,7 +20,21 @@ namespace BizHawk.MultiClient
|
|||
|
||||
public ControllerDefinition Type { get { return type; } }
|
||||
public bool this[string button] { get { return IsPressed(button); } }
|
||||
public bool IsPressed(string button) { return buttons[button]; }
|
||||
public bool IsPressed(string button)
|
||||
{
|
||||
if (autofire)
|
||||
{
|
||||
int a = Global.Emulator.Frame % 2;
|
||||
if (a == 1)
|
||||
return buttons[button];
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return buttons[button];
|
||||
}
|
||||
|
||||
|
||||
public float GetFloat(string name) { throw new NotImplementedException(); }
|
||||
public void UpdateControls(int frame) { }
|
||||
|
||||
|
|
|
@ -795,8 +795,8 @@ namespace BizHawk.MultiClient
|
|||
|
||||
Global.UD_LR_ControllerAdapter.Source = Global.ActiveController;
|
||||
Global.StickyXORAdapter.Source = Global.UD_LR_ControllerAdapter;
|
||||
Global.AutoFireAdapter.Source = Global.StickyXORAdapter;
|
||||
Global.MultitrackRewiringControllerAdapter.Source = Global.AutoFireAdapter;
|
||||
|
||||
Global.MultitrackRewiringControllerAdapter.Source = Global.StickyXORAdapter;
|
||||
Global.MovieInputSourceAdapter.Source = Global.MultitrackRewiringControllerAdapter;
|
||||
Global.ControllerOutput.Source = Global.MovieOutputAdapter;
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace BizHawk.MultiClient
|
|||
public class ClickyVirtualPadController : IController
|
||||
{
|
||||
public ControllerDefinition Type { get; set; }
|
||||
|
||||
public bool Autofire { get { return false; } set { } } //TODO: do we want virtualpad autofire pads?
|
||||
public bool this[string button] { get { return IsPressed(button); } }
|
||||
public float GetFloat(string name) { return 0.0f; } //TODO
|
||||
public void UpdateControls(int frame) { }
|
||||
|
@ -49,6 +49,7 @@ namespace BizHawk.MultiClient
|
|||
public bool this[string button] { get { return IsPressed(button); } }
|
||||
public float GetFloat(string name) { return 0.0f; } //TODO
|
||||
public void UpdateControls(int frame) { }
|
||||
public bool Autofire { get { return false; } set { } }
|
||||
public bool IsPressed(string button)
|
||||
{
|
||||
if (Global.Config.AllowUD_LR == true)
|
||||
|
@ -82,7 +83,7 @@ namespace BizHawk.MultiClient
|
|||
public virtual bool IsPressed(string button) { return this[button]; }
|
||||
public float GetFloat(string name) { return 0.0f; } //TODO
|
||||
public void UpdateControls(int frame) { }
|
||||
|
||||
public bool Autofire { get { return false; } set { } }
|
||||
public virtual void LatchFrom(IController source)
|
||||
{
|
||||
foreach (string button in source.Type.BoolButtons)
|
||||
|
@ -102,7 +103,7 @@ namespace BizHawk.MultiClient
|
|||
public bool IsPressed(string button) { return this[button]; }
|
||||
public float GetFloat(string name) { return 0.0f; } //TODO
|
||||
public void UpdateControls(int frame) { }
|
||||
|
||||
public bool Autofire { get { return false; } set { } } //TODO: sticky autofire buttons?
|
||||
public bool this[string button] {
|
||||
get
|
||||
{
|
||||
|
@ -130,53 +131,6 @@ namespace BizHawk.MultiClient
|
|||
}
|
||||
}
|
||||
|
||||
public class AutoFireAdapter : IController
|
||||
{
|
||||
private HashSet<string> autoFireSet = new HashSet<string>();
|
||||
public IController Source;
|
||||
|
||||
public ControllerDefinition Type { get { return Source.Type; } set { throw new InvalidOperationException(); } }
|
||||
|
||||
public bool IsPressed(string button) { return this[button]; }
|
||||
public float GetFloat(string name) { return 0.0f; } //TODO
|
||||
public void UpdateControls(int frame) { }
|
||||
|
||||
public bool this[string button]
|
||||
{
|
||||
get
|
||||
{
|
||||
bool source = Source[button];
|
||||
if (source)
|
||||
{
|
||||
}
|
||||
|
||||
if (autoFireSet.Contains(button))
|
||||
{
|
||||
int a = Global.Emulator.Frame % 2;
|
||||
if (a == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
set { throw new InvalidOperationException(); }
|
||||
}
|
||||
|
||||
|
||||
public void SetAutoFire(string button, bool isSticky)
|
||||
{
|
||||
if (isSticky)
|
||||
autoFireSet.Add(button);
|
||||
else autoFireSet.Remove(button);
|
||||
}
|
||||
|
||||
public bool IsAutoFire(string button)
|
||||
{
|
||||
return autoFireSet.Contains(button);
|
||||
}
|
||||
}
|
||||
|
||||
public class MnemonicsGenerator
|
||||
{
|
||||
IController Source;
|
||||
|
@ -353,7 +307,7 @@ namespace BizHawk.MultiClient
|
|||
else return Source;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Autofire { get { return false; } set { } }
|
||||
public ControllerDefinition Type { get { return Curr.Type; } }
|
||||
public bool this[string button] { get { return Curr[button]; } }
|
||||
public bool IsPressed(string button) { return Curr.IsPressed(button); }
|
||||
|
@ -404,7 +358,7 @@ namespace BizHawk.MultiClient
|
|||
public bool this[string button] { get { return this.IsPressed(button); } }
|
||||
public float GetFloat(string name) { return Source.GetFloat(name); }
|
||||
public void UpdateControls(int frame) { Source.UpdateControls(frame); }
|
||||
|
||||
public bool Autofire { get { return false; } set { } }
|
||||
public bool IsPressed(string button)
|
||||
{
|
||||
//do we even have a source?
|
||||
|
@ -437,6 +391,7 @@ namespace BizHawk.MultiClient
|
|||
public bool IsPressed(string button) { return MyBoolButtons[button]; }
|
||||
public float GetFloat(string name) { return 0; }
|
||||
public void UpdateControls(int frame) { }
|
||||
public bool Autofire { get { return false; } set { } }
|
||||
//--------
|
||||
|
||||
WorkingDictionary<string, bool> MyBoolButtons = new WorkingDictionary<string, bool>();
|
||||
|
|
Loading…
Reference in New Issue