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:
andres.delikat 2011-08-08 23:35:13 +00:00
parent fe33e75c1b
commit 0d01af5c7b
7 changed files with 167 additions and 192 deletions

View File

@ -53,16 +53,18 @@ namespace BizHawk
private void RecordFrame()
{
int encodedValue = 0;
for (int i=0; i<Type.BoolButtons.Count; i++)
for (int i = 0; i < Type.BoolButtons.Count; i++)
{
if (baseController[Type.BoolButtons[i]])
{
encodedValue |= (1 << i);
}
}
writer.Seek(frame*2, SeekOrigin.Begin);
writer.Seek(frame * 2, SeekOrigin.Begin);
writer.Write((ushort)encodedValue);
}
public bool Autofire { get { return false; } set { } }
}
public class InputPlayback : IController
@ -74,9 +76,9 @@ namespace BizHawk
public InputPlayback(ControllerDefinition controllerDefinition, BinaryReader reader)
{
def = controllerDefinition;
int numFrames = (int) (reader.BaseStream.Length/2);
int numFrames = (int)(reader.BaseStream.Length / 2);
input = new int[numFrames];
for (int i=0; i<numFrames; i++)
for (int i = 0; i < numFrames; i++)
input[i] = reader.ReadUInt16();
}
@ -115,11 +117,13 @@ namespace BizHawk
throw new System.NotImplementedException();
}
public void UnpressButton(string name) {}
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 { } }
}
}

View File

@ -15,5 +15,6 @@
private static NullController nullController = new NullController();
public static NullController GetNullController() { return nullController; }
public bool Autofire { get { return false; } set { } }
}
}

View File

@ -22,5 +22,8 @@ namespace BizHawk
//TODO - why does this have a frame argument. must be removed.
void UpdateControls(int frame);
//Flag for whether the controller will behave like a autofire (rapid fire) controller
bool Autofire { get; set; }
}
}

View File

@ -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>

View File

@ -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) { }

View File

@ -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;

View File

@ -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>();