Skip to content
This repository has been archived by the owner on Oct 30, 2019. It is now read-only.

Commit

Permalink
Moar Input cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
flibitijibibo committed Mar 31, 2014
1 parent d42d412 commit 6d87b6d
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 88 deletions.
1 change: 1 addition & 0 deletions MonoGame.Framework/Input/AccelerometerCapabilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public float AccelerationResolution
return 1.0f;
}
}

#endregion
}
}
18 changes: 2 additions & 16 deletions MonoGame.Framework/Input/AccelerometerState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
*/
#endregion

using System;

namespace Microsoft.Xna.Framework.Input
{
public struct AccelerometerState
Expand All @@ -17,14 +15,8 @@ public struct AccelerometerState

public Vector3 Acceleration
{
get
{
return acceleration;
}
internal set
{
acceleration = value;
}
get;
internal set;
}

/*
Expand All @@ -43,11 +35,5 @@ public bool IsConnected
}

#endregion

#region Private Variables

private Vector3 acceleration;

#endregion
}
}
2 changes: 0 additions & 2 deletions MonoGame.Framework/Input/ButtonState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
*/
#endregion

using System;

namespace Microsoft.Xna.Framework.Input
{
public enum ButtonState
Expand Down
2 changes: 2 additions & 0 deletions MonoGame.Framework/Input/Buttons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/
#endregion

#region Using Statements
using System;
#endregion

namespace Microsoft.Xna.Framework.Input
{
Expand Down
6 changes: 1 addition & 5 deletions MonoGame.Framework/Input/GamePadButtons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
*/
#endregion

using System;

namespace Microsoft.Xna.Framework.Input
{
public struct GamePadButtons
Expand Down Expand Up @@ -144,8 +142,7 @@ public GamePadButtons(Buttons buttons)

#region Internal Constructor

internal GamePadButtons(params Buttons[] buttons)
: this()
internal GamePadButtons(params Buttons[] buttons) : this()
{
foreach (Buttons b in buttons)
{
Expand Down Expand Up @@ -197,4 +194,3 @@ public override int GetHashCode()
#endregion
}
}

2 changes: 2 additions & 0 deletions MonoGame.Framework/Input/GamePadCapabilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/
#endregion

#region Using Statements
using System;
#endregion

namespace Microsoft.Xna.Framework.Input
{
Expand Down
24 changes: 13 additions & 11 deletions MonoGame.Framework/Input/GamePadDPad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/
#endregion

#region Using Statements
using System;
#endregion

namespace Microsoft.Xna.Framework.Input
{
Expand Down Expand Up @@ -48,8 +50,7 @@ public ButtonState Up
ButtonState downValue,
ButtonState leftValue,
ButtonState rightValue
) : this()
{
) : this() {
Up = upValue;
Down = downValue;
Left = leftValue;
Expand All @@ -60,8 +61,7 @@ ButtonState rightValue

#region Internal Constructor

internal GamePadDPad(Buttons b)
: this()
internal GamePadDPad(Buttons b) : this()
{
if ((b & Buttons.DPadDown) == Buttons.DPadDown)
{
Expand Down Expand Up @@ -93,10 +93,10 @@ internal GamePadDPad(Buttons b)
/// <returns>true if <paramref name="left"/> and <paramref name="right"/> are equal; otherwise, false.</returns>
public static bool operator ==(GamePadDPad left, GamePadDPad right)
{
return (left.Down == right.Down) &&
return ( (left.Down == right.Down) &&
(left.Left == right.Left) &&
(left.Right == right.Right) &&
(left.Up == right.Up);
(left.Right == right.Right) &&
(left.Up == right.Up) );
}

/// <summary>
Expand All @@ -122,10 +122,12 @@ public override bool Equals(object obj)

public override int GetHashCode ()
{
return (this.Down == ButtonState.Pressed ? 1 : 0) +
(this.Left == ButtonState.Pressed ? 2 : 0) +
(this.Right == ButtonState.Pressed ? 4 : 0) +
(this.Up == ButtonState.Pressed ? 8 : 0);
return (
(Down == ButtonState.Pressed ? 1 : 0) +
(Left == ButtonState.Pressed ? 2 : 0) +
(Right == ButtonState.Pressed ? 4 : 0) +
(Up == ButtonState.Pressed ? 8 : 0)
);
}

#endregion
Expand Down
6 changes: 2 additions & 4 deletions MonoGame.Framework/Input/GamePadDeadZone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
*/
#endregion

using System;

namespace Microsoft.Xna.Framework.Input
{
/// <summary>
Expand All @@ -32,5 +30,5 @@ public enum GamePadDeadZone
None,
IndependentAxes,
Circular
};
}
}
}
7 changes: 1 addition & 6 deletions MonoGame.Framework/Input/GamePadState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
*/
#endregion

#region Using Statements
using Microsoft.Xna.Framework;
using System;
#endregion

namespace Microsoft.Xna.Framework.Input
{
/// <summary>
Expand Down Expand Up @@ -173,7 +168,7 @@ GamePadDPad dPad
/// </param>
public bool IsButtonDown(Buttons button)
{
return (GetVirtualButtons() & button) == button;
return (GetVirtualButtons() & button) == button;
}

/// <summary>
Expand Down
12 changes: 5 additions & 7 deletions MonoGame.Framework/Input/GamePadThumbSticks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#endregion

#region Using Statements
using Microsoft.Xna.Framework;
using System;
#endregion

Expand Down Expand Up @@ -98,22 +97,22 @@ public enum GateType
None,
Round,
Square
};
}

public static GateType Gate = GateType.Round;

#endregion

#region Private Variables

Vector2 left;
Vector2 right;
private Vector2 left;
private Vector2 right;

#endregion

#region Public Constructor

public GamePadThumbSticks(Vector2 leftPosition, Vector2 rightPosition):this()
public GamePadThumbSticks(Vector2 leftPosition, Vector2 rightPosition) : this()
{
Left = leftPosition;
Right = rightPosition;
Expand Down Expand Up @@ -172,8 +171,7 @@ internal void ApplyDeadZone(GamePadDeadZone dz, float size)
/// <returns>true if <paramref name="left"/> and <paramref name="right"/> are equal; otherwise, false.</returns>
public static bool operator ==(GamePadThumbSticks left, GamePadThumbSticks right)
{
return (left.left == right.left)
&& (left.right == right.right);
return (left.left == right.left) && (left.right == right.right);
}

/// <summary>
Expand Down
8 changes: 3 additions & 5 deletions MonoGame.Framework/Input/GamePadTriggers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
*/
#endregion

using System;

namespace Microsoft.Xna.Framework.Input
{
public struct GamePadTriggers
Expand Down Expand Up @@ -42,7 +40,8 @@ internal set

#region Private Variables

float left, right;
private float left
private float right;

#endregion

Expand All @@ -66,8 +65,7 @@ public GamePadTriggers(float leftTrigger, float rightTrigger):this()
/// <returns>true if <paramref name="left"/> and <paramref name="right"/> are equal; otherwise, false.</returns>
public static bool operator ==(GamePadTriggers left, GamePadTriggers right)
{
return (left.left == right.left) &&
(left.right == right.right);
return (left.left == right.left) && (left.right == right.right);
}

/// <summary>
Expand Down
2 changes: 0 additions & 2 deletions MonoGame.Framework/Input/GamePadType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
*/
#endregion

using System;

namespace Microsoft.Xna.Framework.Input
{
public enum GamePadType
Expand Down
8 changes: 4 additions & 4 deletions MonoGame.Framework/Input/Keyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static class Keyboard
{
#region Private Static Variables

static List<Keys> _keys;
static List<Keys> keys;

#endregion

Expand All @@ -33,7 +33,7 @@ public static class Keyboard
/// <returns>Current keyboard state.</returns>
public static KeyboardState GetState()
{
return new KeyboardState(_keys);
return new KeyboardState(keys);
}

#endregion
Expand All @@ -48,7 +48,7 @@ public static KeyboardState GetState()
[Obsolete("Use GetState() instead. In future versions this method can be removed.")]
public static KeyboardState GetState(PlayerIndex playerIndex)
{
return new KeyboardState(_keys);
return new KeyboardState(keys);
}

#endregion
Expand All @@ -57,7 +57,7 @@ public static KeyboardState GetState(PlayerIndex playerIndex)

internal static void SetKeys(List<Keys> keys)
{
_keys = keys;
this.keys = keys;
}

#endregion
Expand Down
27 changes: 15 additions & 12 deletions MonoGame.Framework/Input/KeyboardState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/
#endregion

#region Using Statements
using System.Collections.Generic;
#endregion

namespace Microsoft.Xna.Framework.Input
{
Expand Down Expand Up @@ -131,15 +133,16 @@ public bool IsKeyUp(Keys key)
/// <returns>The keys that are currently being pressed.</returns>
public Keys[] GetPressedKeys()
{
uint count =
uint count = (
CountBits(keys0) +
CountBits(keys1) +
CountBits(keys2) +
CountBits(keys3) +
CountBits(keys4) +
CountBits(keys5) +
CountBits(keys6) +
CountBits(keys7);
CountBits(keys7)
);

if (count == 0)
{
Expand Down Expand Up @@ -275,14 +278,14 @@ public override int GetHashCode()
/// <returns>true if the instances are equal; false otherwise.</returns>
public static bool operator ==(KeyboardState a, KeyboardState b)
{
return a.keys0 == b.keys0
&& a.keys1 == b.keys1
&& a.keys2 == b.keys2
&& a.keys3 == b.keys3
&& a.keys4 == b.keys4
&& a.keys5 == b.keys5
&& a.keys6 == b.keys6
&& a.keys7 == b.keys7;
return ( a.keys0 == b.keys0 &&
a.keys1 == b.keys1 &&
a.keys2 == b.keys2 &&
a.keys3 == b.keys3 &&
a.keys4 == b.keys4 &&
a.keys5 == b.keys5 &&
a.keys6 == b.keys6 &&
a.keys7 == b.keys7 );
}

/// <summary>
Expand Down Expand Up @@ -313,8 +316,8 @@ public override bool Equals(object obj)
private static uint CountBits(uint v)
{
// http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
v = v - ((v >> 1) & 0x55555555); // reuse input as temporary
v = (v & 0x33333333) + ((v >> 2) & 0x33333333); // temp
v = v - ((v >> 1) & 0x55555555); // reuse input as temporary
v = (v & 0x33333333) + ((v >> 2) & 0x33333333); // temp
return ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; // count
}

Expand Down
4 changes: 0 additions & 4 deletions MonoGame.Framework/Input/Keys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
*/
#endregion

#region Using Statements
using System;
#endregion Using Statements

namespace Microsoft.Xna.Framework.Input
{
/// <summary>
Expand Down
Loading

0 comments on commit 6d87b6d

Please sign in to comment.