public class GamePad
{
internal const int MaxAxisCount = 10;
- internal const int MaxButtonCount = 16; // if this grows over 32 then GamePadState.buttons must be modified
internal const int MaxDPadCount = 2;
static readonly IGamePadDriver driver =
internal void SetButton(Buttons button, bool pressed)
{
- if (IsButtonValid(button))
+ if (pressed)
{
- int index = (int)button;
-
- Buttons mask = (Buttons)(1 << index);
- if (pressed)
- {
- buttons |= mask;
- }
- else
- {
- buttons &= ~mask;
- }
+ buttons |= button;
}
else
{
- throw new ArgumentOutOfRangeException("button");
+ buttons &= ~button;
}
}
return index >= 0 && index < GamePad.MaxAxisCount;
}
- bool IsButtonValid(Buttons button)
- {
- int index = (int)button;
- return index >= 0 && index < GamePad.MaxButtonCount;
- }
-
bool IsDPadValid(int index)
{
return index >= 0 && index < GamePad.MaxDPadCount;