Skip to content

Commit

Permalink
Merged r9212, 9201, 9198, 9193, 9190, 9189 to branches/release
Browse files Browse the repository at this point in the history
  • Loading branch information
hegyak committed Mar 10, 2015
1 parent eae0575 commit d34d00f
Show file tree
Hide file tree
Showing 47 changed files with 1,279 additions and 432 deletions.
1 change: 1 addition & 0 deletions BizHawk.Client.Common/BizHawk.Client.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="Global.cs" />
<Compile Include="inputAdapters\AutoPattern.cs" />
<Compile Include="inputAdapters\BitwiseAdapters.cs" />
<Compile Include="inputAdapters\InputAdapterExtensions.cs" />
<Compile Include="inputAdapters\InputAdapters.cs" />
Expand Down
119 changes: 119 additions & 0 deletions BizHawk.Client.Common/inputAdapters/AutoPattern.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BizHawk.Client.Common
{
public class AutoPatternBool
{
public bool SkipsLag = true;
private bool[] _pattern;
private int _index;

/// <summary>
/// Autohold.
/// </summary>
public AutoPatternBool()
{
SkipsLag = true;
_index = 0;
_pattern = new bool[] { true };
}
/// <summary>
/// Simple on/off pattern.
/// </summary>
/// <param name="on"></param>
/// <param name="off"></param>
public AutoPatternBool(int on, int off, bool skip_lag = true, int offset = 0)
{
SkipsLag = skip_lag;
_index = offset;
_pattern = new bool[on + off];
for (int i = 0; i < on; i++)
_pattern[i] = true;
}
public AutoPatternBool(bool[] pattern, bool skip_lag = true, int offset = 0)
{
SkipsLag = skip_lag;
_pattern = pattern;
_index = offset;
}

/// <summary>
/// Gets the next value and increments index.
/// </summary>
/// <returns></returns>
public bool GetNextValue()
{
bool ret = _pattern[_index];
_index++;
_index = _index % _pattern.Length;

return ret;
}

/// <summary>
/// Gets the next value without incrementing index.
/// </summary>
/// <returns></returns>
public bool PeekNextValue()
{ return _pattern[_index]; }
}

public class AutoPatternFloat
{
public bool SkipsLag = true;
private float[] _pattern;
private int _index;

/// <summary>
/// Defaults to 0.
/// </summary>
public AutoPatternFloat()
{
SkipsLag = true;
_pattern = new float[] { 0f };
_index = 0;
}
/// <summary>
/// Sinple on/off pattern, using the given values as on/off.
/// </summary>
public AutoPatternFloat(float valueOn, int on, float valueOff, int off, bool skip_lag = true, int offset = 0)
{
SkipsLag = skip_lag;
_index = offset;
_pattern = new float[on + off];
for (int i = 0; i < on; i++)
_pattern[i] = valueOn;
for (int i = on; i < _pattern.Length; i++)
_pattern[i] = valueOff;
}
public AutoPatternFloat(float[] pattern, bool skip_lag = true, int offset = 0)
{
SkipsLag = skip_lag;
_pattern = pattern;
_index = offset;
}

/// <summary>
/// Gets the next value and increments index.
/// </summary>
/// <returns></returns>
public float GetNextValue()
{
float ret = _pattern[_index];
_index++;
_index = _index % _pattern.Length;

return ret;
}

/// <summary>
/// Gets the next value without incrementing index.
/// </summary>
/// <returns></returns>
public float PeekNextValue()
{ return _pattern[_index]; }
}
}
Loading

0 comments on commit d34d00f

Please sign in to comment.