Permalink
Browse files

Refactored the GamePad code for Windows , Linux and Mac to not rely o…

…n the thirdParty Gamepad dlls.

This means there is not GamePad config screen at the moment, only AutoConfig is working, but it will allow MonoGame to be included in the next debian release.
  • Loading branch information...
1 parent 6f3ff3f commit 101caae21373bdd37e7cd91f58329f7224097c69 @dellis1972 committed Jun 6, 2012
@@ -0,0 +1,75 @@
+#region License
+/*
+Microsoft Public License (Ms-PL)
+MonoGame - Copyright © 2009 The MonoGame Team
+
+All rights reserved.
+
+This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
+accept the license, do not use the software.
+
+1. Definitions
+The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
+U.S. copyright law.
+
+A "contribution" is the original software, or any additions or changes to the software.
+A "contributor" is any person that distributes its contribution under this license.
+"Licensed patents" are a contributor's patent claims that read directly on its contribution.
+
+2. Grant of Rights
+(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
+(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
+
+3. Conditions and Limitations
+(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
+(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
+your patent license from such contributor to the software ends automatically.
+(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
+notices that are present in the software.
+(D) If you distribute any portion of the software in source code form, you may do so only under this license by including
+a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
+code form, you may only do so under a license that complies with this license.
+(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
+or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
+permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
+purpose and non-infringement.
+*/
+#endregion License
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Microsoft.Xna.Framework.Input
+{
+ public class Axis
+ {
+ public Axis()
+ {
+ this.Negative = new Input();
+ this.Positive = new Input();
+ }
+
+ public Input Negative { get; set; }
+ public Input Positive { get; set; }
+ public InputType Type { get; set; }
+
+ public float ReadAxis(IntPtr device)
+ {
+ return (this.Positive.ReadFloat(device) - this.Negative.ReadFloat(device));
+ }
+
+
+ internal void AssignAxis(int id, bool negative)
+ {
+ this.Negative.ID = id;
+ this.Negative.Negative = !negative;
+ this.Negative.Type = InputType.Axis;
+ this.Positive.ID = id;
+ this.Positive.Negative = negative;
+ this.Positive.Type = InputType.Axis;
+ }
+ }
+}
@@ -0,0 +1,63 @@
+#region License
+/*
+Microsoft Public License (Ms-PL)
+MonoGame - Copyright © 2009 The MonoGame Team
+
+All rights reserved.
+
+This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
+accept the license, do not use the software.
+
+1. Definitions
+The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
+U.S. copyright law.
+
+A "contribution" is the original software, or any additions or changes to the software.
+A "contributor" is any person that distributes its contribution under this license.
+"Licensed patents" are a contributor's patent claims that read directly on its contribution.
+
+2. Grant of Rights
+(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
+(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
+
+3. Conditions and Limitations
+(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
+(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
+your patent license from such contributor to the software ends automatically.
+(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
+notices that are present in the software.
+(D) If you distribute any portion of the software in source code form, you may do so only under this license by including
+a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
+code form, you may only do so under a license that complies with this license.
+(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
+or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
+permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
+purpose and non-infringement.
+*/
+#endregion License
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Microsoft.Xna.Framework.Input
+{
+ public class Capabilities
+ {
+ public Capabilities(IntPtr device)
+ {
+ // TODO: Complete member initialization
+ this.NumberOfAxis = Tao.Sdl.Sdl.SDL_JoystickNumAxes(device);
+ this.NumberOfButtons = Tao.Sdl.Sdl.SDL_JoystickNumButtons(device);
+ this.NumberOfPovHats = Tao.Sdl.Sdl.SDL_JoystickNumHats(device);
+ }
+
+
+ public int NumberOfAxis { get; private set; }
+ public int NumberOfButtons { get; private set; }
+ public int NumberOfPovHats { get; private set; }
+
+ }
+}
@@ -0,0 +1,79 @@
+#region License
+/*
+Microsoft Public License (Ms-PL)
+MonoGame - Copyright © 2009 The MonoGame Team
+
+All rights reserved.
+
+This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
+accept the license, do not use the software.
+
+1. Definitions
+The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
+U.S. copyright law.
+
+A "contribution" is the original software, or any additions or changes to the software.
+A "contributor" is any person that distributes its contribution under this license.
+"Licensed patents" are a contributor's patent claims that read directly on its contribution.
+
+2. Grant of Rights
+(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
+(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
+
+3. Conditions and Limitations
+(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
+(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
+your patent license from such contributor to the software ends automatically.
+(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
+notices that are present in the software.
+(D) If you distribute any portion of the software in source code form, you may do so only under this license by including
+a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
+code form, you may only do so under a license that complies with this license.
+(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
+or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
+permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
+purpose and non-infringement.
+*/
+#endregion License
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Microsoft.Xna.Framework.Input
+{
+ public class DPad
+ {
+ public DPad()
+ {
+ this.Up = new Input();
+ this.Down = new Input();
+ this.Left = new Input();
+ this.Right = new Input();
+ }
+
+ public Input Up { get; set; }
+ public Input Down { get; set; }
+ public Input Left { get; set; }
+ public Input Right { get; set; }
+
+ internal void AssignPovHat(int id)
+ {
+ this.Up.ID = id;
+ this.Up.Negative = false;
+ this.Up.Type = InputType.PovUp;
+ this.Down.ID = id;
+ this.Down.Negative = false;
+ this.Down.Type = InputType.PovDown;
+ this.Left.ID = id;
+ this.Left.Negative = false;
+ this.Left.Type = InputType.PovLeft;
+ this.Right.ID = id;
+ this.Right.Negative = false;
+ this.Right.Type = InputType.PovRight;
+
+ }
+ }
+}
@@ -1,9 +1,47 @@
-using System;
+#region License
+/*
+Microsoft Public License (Ms-PL)
+MonoGame - Copyright © 2009 The MonoGame Team
+
+All rights reserved.
+
+This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
+accept the license, do not use the software.
+
+1. Definitions
+The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
+U.S. copyright law.
+
+A "contribution" is the original software, or any additions or changes to the software.
+A "contributor" is any person that distributes its contribution under this license.
+"Licensed patents" are a contributor's patent claims that read directly on its contribution.
+
+2. Grant of Rights
+(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
+(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
+
+3. Conditions and Limitations
+(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
+(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
+your patent license from such contributor to the software ends automatically.
+(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
+notices that are present in the software.
+(D) If you distribute any portion of the software in source code form, you may do so only under this license by including
+a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
+code form, you may only do so under a license that complies with this license.
+(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
+or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
+permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
+purpose and non-infringement.
+*/
+#endregion License
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
-using GamepadConfigLib;
using Tao.Sdl;
using System.Xml.Serialization;
@@ -16,8 +54,9 @@ namespace Microsoft.Xna.Framework.Input
// code samples.
public static class GamePad
{
- static bool running;
- static bool sdl;
+ static bool running;
+ static bool sdl;
+
static Settings settings;
static Settings Settings
{
@@ -27,16 +66,16 @@ static Settings Settings
}
}
- static void AutoConfig () {
- Init();
- if (!sdl)
- return;
+ static void AutoConfig ()
+ {
+ Init();
+ if (!sdl) return;
Console.WriteLine("Number of joysticks: " + Sdl.SDL_NumJoysticks());
int numSticks = Sdl.SDL_NumJoysticks();
for (int x = 0; x < numSticks; x++) {
PadConfig pc = new PadConfig(Sdl.SDL_JoystickName(x), 0);
- devices[x] = Sdl.SDL_JoystickOpen (pc.ID);
+ devices[x] = Sdl.SDL_JoystickOpen (pc.Index);
int numbuttons = Sdl.SDL_JoystickNumButtons(devices[x]);
Console.WriteLine("Number of buttons for joystick: " + x + " - " + numbuttons);
@@ -225,11 +264,8 @@ static Settings PrepSettings()
{
if (settings == null)
{
- settings = LoadConfigs("Settings.xml");
- if (settings == null) {
settings = new Settings();
- AutoConfig();
- }
+ AutoConfig();
}
else if (!running)
{
@@ -240,48 +276,30 @@ static Settings PrepSettings()
Init();
return settings;
}
- static Settings LoadConfigs(string filename)
- {
- Settings e;
- try
- {
- using (Stream s = File.OpenRead(filename))
- {
- XmlSerializer x = new XmlSerializer(typeof(Settings));
- e = (Settings)x.Deserialize(s);
- }
- }
- catch
- {
- return null;
- }
- //for (int i = 0; i < 4; i++)
- // if (e[i] == null)
- // e[i] = new PadConfig(true);
- return e;
- }
+
static IntPtr[] devices = new IntPtr[4];
//Inits SDL and grabs the sticks
static void Init ()
{
running = true;
- try {
- Joystick.Init ();
+ try
+ {
+ Joystick.Init ();
sdl = true;
}
- catch (Exception exc) {
+ catch (Exception)
+ {
}
-
for (int i = 0; i < 4; i++)
- {
+ {
PadConfig pc = settings[i];
if (pc != null)
- {
- devices[i] = Sdl.SDL_JoystickOpen (pc.ID);
- }
- }
+ {
+ devices[i] = Sdl.SDL_JoystickOpen (pc.Index);
+ }
+ }
}
@@ -317,6 +335,7 @@ static Buttons StickToButtons(Vector2 stick, float DeadZoneSize)
return b;
}
+
static Buttons ReadButtons(IntPtr device, PadConfig c, float deadZoneSize)
{
short DeadZone = (short)(deadZoneSize * short.MaxValue);
@@ -366,7 +385,6 @@ static Buttons ReadButtons(IntPtr device, PadConfig c, float deadZoneSize, Vecto
return b;
}
-
static GamePadState ReadState(PlayerIndex index, GamePadDeadZone deadZone)
{
const float DeadZoneSize = 0.27f;
Oops, something went wrong.

0 comments on commit 101caae

Please sign in to comment.