Autofire is smarter now and keeps track of when a button was pressed and then uses that for the basis of the autofire pattern

This commit is contained in:
andres.delikat 2011-08-10 00:34:33 +00:00
parent 4b65d9e9cf
commit 6f3bc27c59
1 changed files with 16 additions and 7 deletions

View File

@ -95,17 +95,20 @@ namespace BizHawk.MultiClient
private ControllerDefinition type; private ControllerDefinition type;
private WorkingDictionary<string, List<string>> bindings = new WorkingDictionary<string, List<string>>(); private WorkingDictionary<string, List<string>> bindings = new WorkingDictionary<string, List<string>>();
private WorkingDictionary<string, bool> buttons = new WorkingDictionary<string, bool>(); private WorkingDictionary<string, bool> buttons = new WorkingDictionary<string, bool>();
private WorkingDictionary<string, int> buttonStarts = new WorkingDictionary<string, int>();
private bool autofire = true; private bool autofire = true;
public bool Autofire { get { return false; } set { autofire = value; } } public bool Autofire { get { return false; } set { autofire = value; } }
public int On { get; set; } public int On { get; set; }
public int Off { get; set; } public int Off { get; set; }
//public int StartFrame { get; set; }
public AutofireController(ControllerDefinition definition) public AutofireController(ControllerDefinition definition)
{ {
On = Global.Config.AutofireOn < 1 ? 0 : Global.Config.AutofireOn; On = Global.Config.AutofireOn < 1 ? 0 : Global.Config.AutofireOn;
Off = Global.Config.AutofireOff < 1 ? 0 : Global.Config.AutofireOff; Off = Global.Config.AutofireOff < 1 ? 0 : Global.Config.AutofireOff;
//StartFrame = 0;
type = definition; type = definition;
} }
@ -115,7 +118,7 @@ namespace BizHawk.MultiClient
{ {
if (autofire) if (autofire)
{ {
int a = Global.Emulator.Frame % (On + Off); int a = (Global.Emulator.Frame - buttonStarts[button]) % (On + Off);
if (a < On) if (a < On)
return buttons[button]; return buttons[button];
else else
@ -144,29 +147,35 @@ namespace BizHawk.MultiClient
return ret; return ret;
} }
int frameStarted = 0;
/// <summary> /// <summary>
/// uses the bindings to latch our own logical button state from the source controller's button state (which are assumed to be the physical side of the binding). /// uses the bindings to latch our own logical button state from the source controller's button state (which are assumed to be the physical side of the binding).
/// this will clobber any existing data (use OR_* or other functions to layer in additional input sources) /// this will clobber any existing data (use OR_* or other functions to layer in additional input sources)
/// </summary> /// </summary>
public void LatchFromPhysical(IController controller) public void LatchFromPhysical(IController controller)
{ {
foreach (var kvp in bindings)
{
foreach (var bound_button in kvp.Value)
{
if (buttons[kvp.Key] == false && controller[bound_button] == true)
buttonStarts[kvp.Key] = Global.Emulator.Frame;
}
}
buttons.Clear(); buttons.Clear();
foreach (var kvp in bindings) foreach (var kvp in bindings)
{ {
buttons[kvp.Key] = false; buttons[kvp.Key] = false;
foreach (var bound_button in kvp.Value) foreach (var bound_button in kvp.Value)
{ {
if (buttons[kvp.Key] == false && controller[bound_button] == true)
frameStarted = Global.Emulator.Frame;
else
frameStarted = 0;
if (controller[bound_button]) if (controller[bound_button])
{
buttons[kvp.Key] = true; buttons[kvp.Key] = true;
} }
} }
} }
}
/// <summary> /// <summary>
/// merges pressed logical buttons from the supplied controller, effectively ORing it with the current state /// merges pressed logical buttons from the supplied controller, effectively ORing it with the current state