diff options
| author | Shawn Hoffman <godisgovernment@gmail.com> | 2010-06-09 01:37:08 +0000 |
|---|---|---|
| committer | Shawn Hoffman <godisgovernment@gmail.com> | 2010-06-09 01:37:08 +0000 |
| commit | 4a0c8fc0c9b6666e7933683260e2befbc81917ff (patch) | |
| tree | eb83de83f60b3de6f631bcf5da9c18a07a0f263a /Source/Core/InputCommon | |
| parent | dacd557f57c73043155c06c060370df9789eb98c (diff) | |
Hg:
enable newline normalization
get revision number via `hg svn info` for svnrev.h
ignore incremental/generated binary files (windows/VS at least)
leave a comment if some files need native eol set in svnprops
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5637 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core/InputCommon')
| -rw-r--r-- | Source/Core/InputCommon/Src/SDL_Util.cpp | 444 | ||||
| -rw-r--r-- | Source/Core/InputCommon/Src/SDL_Util.h | 156 | ||||
| -rw-r--r-- | Source/Core/InputCommon/Src/XInput_Util.cpp | 246 | ||||
| -rw-r--r-- | Source/Core/InputCommon/Src/XInput_Util.h | 84 |
4 files changed, 465 insertions, 465 deletions
diff --git a/Source/Core/InputCommon/Src/SDL_Util.cpp b/Source/Core/InputCommon/Src/SDL_Util.cpp index 0ae94ad95e..c9a51e1e9b 100644 --- a/Source/Core/InputCommon/Src/SDL_Util.cpp +++ b/Source/Core/InputCommon/Src/SDL_Util.cpp @@ -1,222 +1,222 @@ -
-// Project description
-// -------------------
-// Name: SDL Input
-// Description: Common SDL Input Functions
-//
-// Author: Falcon4ever (nJoy@falcon4ever.com, www.multigesture.net), JPeterson etc
-// Copyright (C) 2003 Dolphin Project.
-//
-
-//
-// Licensetype: GNU General Public License (GPL)
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, version 2.0.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License 2.0 for more details.
-//
-// A copy of the GPL 2.0 should have been included with the program.
-// If not, see http://www.gnu.org/licenses/
-//
-// Official SVN repository and contact information can be found at
-// http://code.google.com/p/dolphin-emu/
-//
-
-
-#define _SDL_MAIN_ // Avoid certain declarations in SDL.h
-#include "InputCommon.h"
-#include "SDL_Util.h" // Local
-#ifdef _WIN32
-#include "XInput_Util.h"
-#endif
-
-namespace InputCommon
-{
-
-
-// Search attached devices. Populate joyinfo for all attached physical devices.
-// -----------------------
-bool SearchDevices(std::vector<CONTROLLER_INFO> &_joyinfo, int &_NumPads, int &_NumGoodPads)
-{
- if (!SDL_WasInit(0))
-#if SDL_VERSION_ATLEAST(1, 3, 0)
- if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC) < 0)
-#else
- if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
-#endif
- {
- PanicAlert("Could not initialize SDL: %s", SDL_GetError());
- return false;
- }
-
- // Get device status
- int numjoy = SDL_NumJoysticks();
- for (int i = 0; i < numjoy; i++)
- {
- CONTROLLER_INFO Tmp;
-
- Tmp.joy = SDL_JoystickOpen(i);
- Tmp.ID = i;
- Tmp.NumAxes = SDL_JoystickNumAxes(Tmp.joy);
- Tmp.NumButtons = SDL_JoystickNumButtons(Tmp.joy);
- Tmp.NumBalls = SDL_JoystickNumBalls(Tmp.joy);
- Tmp.NumHats = SDL_JoystickNumHats(Tmp.joy);
- Tmp.Name = SDL_JoystickName(i);
-
- // Check if the device is okay
- if ( Tmp.NumAxes == 0
- && Tmp.NumBalls == 0
- && Tmp.NumButtons == 0
- && Tmp.NumHats == 0
- )
- {
- Tmp.Good = false;
- }
- else
- {
- _NumGoodPads++;
- Tmp.Good = true;
- }
-
- _joyinfo.push_back(Tmp);
-
- // We have now read the values we need so we close the device
-// if (SDL_JoystickOpened(i)) SDL_JoystickClose(_joyinfo[i].joy);
- }
-
- _NumPads = (int)_joyinfo.size();
-
- return true;
-}
-
-
-// Avoid extreme axis values
-// ---------------------
-/* Function: We have to avoid very big values because some triggers are -0x8000 in the
- unpressed state (and then go from -0x8000 to 0x8000 as they are fully pressed) */
-bool AvoidValues(int value, bool NoTriggerFilter)
-{
- // Avoid detecting very small or very big (for triggers) values
- if((value > -0x1000 && value < 0x1000) // Small values
- || ((value < -0x7000 || value > 0x7000) && !NoTriggerFilter)) // Big values
- return true; // Avoid
- else
- return false; // Keep
-}
-
-
-// Detect a pressed button
-// ---------------------
-void GetButton(SDL_Joystick *joy, int ControllerID, int buttons, int axes, int hats,
- int &KeyboardKey, int &value, int &type, int &pressed, bool &Succeed, bool &Stop,
- bool LeftRight, bool Axis, bool XInput, bool Button, bool Hat, bool NoTriggerFilter)
-{
- // It needs the wxWidgets excape keycode
- static const int WXK_ESCAPE = 27;
-
- // Update the internal status
- SDL_JoystickUpdate();
-
- // For the triggers we accept both a digital or an analog button
- if(Axis)
- {
- for(int i = 0; i < axes; i++)
- {
- value = SDL_JoystickGetAxis(joy, i);
-
- if(AvoidValues(value, NoTriggerFilter)) continue; // Avoid values
-
- pressed = i + (LeftRight ? 1000 : 0); // Identify the analog triggers
- type = InputCommon::CTL_AXIS;
- Succeed = true;
- }
- }
-
- // Check for a hat
- if(Hat)
- {
- for(int i = 0; i < hats; i++)
- {
- value = SDL_JoystickGetHat(joy, i);
- if(value)
- {
- pressed = i;
- type = InputCommon::CTL_HAT;
- Succeed = true;
- }
- }
- }
-
- // Check for a button
- if(Button)
- {
- for(int i = 0; i < buttons; i++)
- {
- // Some kind of bug in SDL 1.3 would give button 9 and 10 (nonexistent) the value 48 on the 360 pad
- if (SDL_JoystickGetButton(joy, i) > 1) continue;
-
- if(SDL_JoystickGetButton(joy, i))
- {
- pressed = i;
- type = InputCommon::CTL_BUTTON;
- Succeed = true;
- }
- }
- }
-
- // Check for a XInput trigger
- #ifdef _WIN32
- if(XInput && LeftRight)
- {
- for(int i = 0; i <= InputCommon::XI_TRIGGER_R; i++)
- {
- if(XInput::GetXI(ControllerID, i))
- {
- pressed = i + 1000;
- type = InputCommon::CTL_AXIS;
- Succeed = true;
- }
- }
- }
- #endif
-
- // Check for keyboard action
- if (KeyboardKey)
- {
- if(Button)
- {
- // Todo: Add a separate keyboard vector to remove this restriction
- if(KeyboardKey >= buttons)
- {
- pressed = KeyboardKey;
- type = InputCommon::CTL_BUTTON;
- Succeed = true;
- KeyboardKey = 0;
- if(pressed == WXK_ESCAPE) pressed = -1; // Check for the escape key
- }
- // Else show the error message
- else
- {
- pressed = KeyboardKey;
- KeyboardKey = -1;
- Stop = true;
- }
- }
- // Only accept the escape key
- else if (KeyboardKey == WXK_ESCAPE)
- {
- Succeed = true;
- KeyboardKey = 0;
- pressed = -1;
- }
- }
-}
-
-
-} // InputCommon
-
+ +// Project description +// ------------------- +// Name: SDL Input +// Description: Common SDL Input Functions +// +// Author: Falcon4ever (nJoy@falcon4ever.com, www.multigesture.net), JPeterson etc +// Copyright (C) 2003 Dolphin Project. +// + +// +// Licensetype: GNU General Public License (GPL) +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. +// +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ +// +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ +// + + +#define _SDL_MAIN_ // Avoid certain declarations in SDL.h +#include "InputCommon.h" +#include "SDL_Util.h" // Local +#ifdef _WIN32 +#include "XInput_Util.h" +#endif + +namespace InputCommon +{ + + +// Search attached devices. Populate joyinfo for all attached physical devices. +// ----------------------- +bool SearchDevices(std::vector<CONTROLLER_INFO> &_joyinfo, int &_NumPads, int &_NumGoodPads) +{ + if (!SDL_WasInit(0)) +#if SDL_VERSION_ATLEAST(1, 3, 0) + if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC) < 0) +#else + if (SDL_Init(SDL_INIT_JOYSTICK) < 0) +#endif + { + PanicAlert("Could not initialize SDL: %s", SDL_GetError()); + return false; + } + + // Get device status + int numjoy = SDL_NumJoysticks(); + for (int i = 0; i < numjoy; i++) + { + CONTROLLER_INFO Tmp; + + Tmp.joy = SDL_JoystickOpen(i); + Tmp.ID = i; + Tmp.NumAxes = SDL_JoystickNumAxes(Tmp.joy); + Tmp.NumButtons = SDL_JoystickNumButtons(Tmp.joy); + Tmp.NumBalls = SDL_JoystickNumBalls(Tmp.joy); + Tmp.NumHats = SDL_JoystickNumHats(Tmp.joy); + Tmp.Name = SDL_JoystickName(i); + + // Check if the device is okay + if ( Tmp.NumAxes == 0 + && Tmp.NumBalls == 0 + && Tmp.NumButtons == 0 + && Tmp.NumHats == 0 + ) + { + Tmp.Good = false; + } + else + { + _NumGoodPads++; + Tmp.Good = true; + } + + _joyinfo.push_back(Tmp); + + // We have now read the values we need so we close the device +// if (SDL_JoystickOpened(i)) SDL_JoystickClose(_joyinfo[i].joy); + } + + _NumPads = (int)_joyinfo.size(); + + return true; +} + + +// Avoid extreme axis values +// --------------------- +/* Function: We have to avoid very big values because some triggers are -0x8000 in the + unpressed state (and then go from -0x8000 to 0x8000 as they are fully pressed) */ +bool AvoidValues(int value, bool NoTriggerFilter) +{ + // Avoid detecting very small or very big (for triggers) values + if((value > -0x1000 && value < 0x1000) // Small values + || ((value < -0x7000 || value > 0x7000) && !NoTriggerFilter)) // Big values + return true; // Avoid + else + return false; // Keep +} + + +// Detect a pressed button +// --------------------- +void GetButton(SDL_Joystick *joy, int ControllerID, int buttons, int axes, int hats, + int &KeyboardKey, int &value, int &type, int &pressed, bool &Succeed, bool &Stop, + bool LeftRight, bool Axis, bool XInput, bool Button, bool Hat, bool NoTriggerFilter) +{ + // It needs the wxWidgets excape keycode + static const int WXK_ESCAPE = 27; + + // Update the internal status + SDL_JoystickUpdate(); + + // For the triggers we accept both a digital or an analog button + if(Axis) + { + for(int i = 0; i < axes; i++) + { + value = SDL_JoystickGetAxis(joy, i); + + if(AvoidValues(value, NoTriggerFilter)) continue; // Avoid values + + pressed = i + (LeftRight ? 1000 : 0); // Identify the analog triggers + type = InputCommon::CTL_AXIS; + Succeed = true; + } + } + + // Check for a hat + if(Hat) + { + for(int i = 0; i < hats; i++) + { + value = SDL_JoystickGetHat(joy, i); + if(value) + { + pressed = i; + type = InputCommon::CTL_HAT; + Succeed = true; + } + } + } + + // Check for a button + if(Button) + { + for(int i = 0; i < buttons; i++) + { + // Some kind of bug in SDL 1.3 would give button 9 and 10 (nonexistent) the value 48 on the 360 pad + if (SDL_JoystickGetButton(joy, i) > 1) continue; + + if(SDL_JoystickGetButton(joy, i)) + { + pressed = i; + type = InputCommon::CTL_BUTTON; + Succeed = true; + } + } + } + + // Check for a XInput trigger + #ifdef _WIN32 + if(XInput && LeftRight) + { + for(int i = 0; i <= InputCommon::XI_TRIGGER_R; i++) + { + if(XInput::GetXI(ControllerID, i)) + { + pressed = i + 1000; + type = InputCommon::CTL_AXIS; + Succeed = true; + } + } + } + #endif + + // Check for keyboard action + if (KeyboardKey) + { + if(Button) + { + // Todo: Add a separate keyboard vector to remove this restriction + if(KeyboardKey >= buttons) + { + pressed = KeyboardKey; + type = InputCommon::CTL_BUTTON; + Succeed = true; + KeyboardKey = 0; + if(pressed == WXK_ESCAPE) pressed = -1; // Check for the escape key + } + // Else show the error message + else + { + pressed = KeyboardKey; + KeyboardKey = -1; + Stop = true; + } + } + // Only accept the escape key + else if (KeyboardKey == WXK_ESCAPE) + { + Succeed = true; + KeyboardKey = 0; + pressed = -1; + } + } +} + + +} // InputCommon + diff --git a/Source/Core/InputCommon/Src/SDL_Util.h b/Source/Core/InputCommon/Src/SDL_Util.h index 1dcebb8186..d7fba95da7 100644 --- a/Source/Core/InputCommon/Src/SDL_Util.h +++ b/Source/Core/InputCommon/Src/SDL_Util.h @@ -1,78 +1,78 @@ -// Copyright (C) 2003 Dolphin Project.
-
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, version 2.0.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License 2.0 for more details.
-
-// A copy of the GPL 2.0 should have been included with the program.
-// If not, see http://www.gnu.org/licenses/
-
-// Official SVN repository and contact information can be found at
-// http://code.google.com/p/dolphin-emu/
-
-#ifndef _SDL_h
-#define _SDL_h
-
-
-#include <iostream> // System
-#include <vector>
-#include <cmath>
-
-#ifdef _WIN32
-#include <SDL.h> // Externals
-#include <SDL_version.h>
-#if SDL_VERSION_ATLEAST(1, 3, 0)
- #include <SDL_haptic.h>
-#endif
-#else
-#include <SDL/SDL.h>
-#include <SDL/SDL_version.h>
-#if SDL_VERSION_ATLEAST(1, 3, 0)
- #include <SDL/SDL_haptic.h>
-#endif
-#endif
-
-#include "Common.h" // Common
-
-
-namespace InputCommon
-{
-
-struct CONTROLLER_INFO // CONNECTED WINDOWS DEVICES INFO
-{
- int NumAxes; // Amount of Axes
- int NumButtons; // Amount of Buttons
- int NumBalls; // Amount of Balls
- int NumHats; // Amount of Hats (POV)
- std::string Name; // Joypad/stickname
- int ID; // SDL joystick device ID
- bool Good; // Pad is good (it has at least one button or axis)
- SDL_Joystick *joy; // SDL joystick device
-};
-
-
-// General functions
-bool SearchDevices(std::vector<CONTROLLER_INFO> &_joyinfo, int &NumPads, int &NumGoodPads);
-void GetButton(SDL_Joystick*, int,int,int,int, int&,int&,int&,int&,bool&,bool&, bool,bool,bool,bool,bool,bool);
-
-// Value conversion
-float Deg2Rad(float Deg);
-float Rad2Deg(float Rad);
-int Pad_Convert(int _val);
-float SquareDistance(float deg);
-bool IsDeadZone(float DeadZone, int x, int y);
-void Square2Circle(int &_x, int &_y, int _Diagonal, bool Circle2Square = false);
-void RadiusAdjustment(s8 &_x, s8 &_y, int _Radius);
-// Input configuration
-std::string VKToString(int keycode);
-
-
-} // InputCommon
-
-
-#endif // _SDL_h
+// Copyright (C) 2003 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + +#ifndef _SDL_h +#define _SDL_h + + +#include <iostream> // System +#include <vector> +#include <cmath> + +#ifdef _WIN32 +#include <SDL.h> // Externals +#include <SDL_version.h> +#if SDL_VERSION_ATLEAST(1, 3, 0) + #include <SDL_haptic.h> +#endif +#else +#include <SDL/SDL.h> +#include <SDL/SDL_version.h> +#if SDL_VERSION_ATLEAST(1, 3, 0) + #include <SDL/SDL_haptic.h> +#endif +#endif + +#include "Common.h" // Common + + +namespace InputCommon +{ + +struct CONTROLLER_INFO // CONNECTED WINDOWS DEVICES INFO +{ + int NumAxes; // Amount of Axes + int NumButtons; // Amount of Buttons + int NumBalls; // Amount of Balls + int NumHats; // Amount of Hats (POV) + std::string Name; // Joypad/stickname + int ID; // SDL joystick device ID + bool Good; // Pad is good (it has at least one button or axis) + SDL_Joystick *joy; // SDL joystick device +}; + + +// General functions +bool SearchDevices(std::vector<CONTROLLER_INFO> &_joyinfo, int &NumPads, int &NumGoodPads); +void GetButton(SDL_Joystick*, int,int,int,int, int&,int&,int&,int&,bool&,bool&, bool,bool,bool,bool,bool,bool); + +// Value conversion +float Deg2Rad(float Deg); +float Rad2Deg(float Rad); +int Pad_Convert(int _val); +float SquareDistance(float deg); +bool IsDeadZone(float DeadZone, int x, int y); +void Square2Circle(int &_x, int &_y, int _Diagonal, bool Circle2Square = false); +void RadiusAdjustment(s8 &_x, s8 &_y, int _Radius); +// Input configuration +std::string VKToString(int keycode); + + +} // InputCommon + + +#endif // _SDL_h diff --git a/Source/Core/InputCommon/Src/XInput_Util.cpp b/Source/Core/InputCommon/Src/XInput_Util.cpp index 88e0d0e54c..de255ec074 100644 --- a/Source/Core/InputCommon/Src/XInput_Util.cpp +++ b/Source/Core/InputCommon/Src/XInput_Util.cpp @@ -1,123 +1,123 @@ -
-//
-// Licensetype: GNU General Public License (GPL)
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, version 2.0.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License 2.0 for more details.
-//
-// A copy of the GPL 2.0 should have been included with the program.
-// If not, see http://www.gnu.org/licenses/
-//
-// Official SVN repository and contact information can be found at
-// http://code.google.com/p/dolphin-emu/
-//
-
-
-
-
-// File description
-/* -------------------
- Function: This file will get the status of the analog triggers of any connected XInput device.
- This code was made with the help of SimpleController.cpp in the June 2008 Microsoft DirectX SDK
- Samples.
-
-///////////////////////////////////////////////////// */
-
-#ifdef _WIN32
-
-
-// Includes
-// -------------------
-#include <windows.h>
-#include <XInput.h> // XInput API
-#include "InputCommon.h"
-
-namespace XInput
-{
-
-// Declarations
-// -------------------
-
-#define MAX_CONTROLLERS 4 // XInput handles up to 4 controllers
-
-struct CONTROLER_STATE
-{
- XINPUT_STATE state;
- bool bConnected;
-};
-
-CONTROLER_STATE g_Controllers[MAX_CONTROLLERS];
-
-
-// Init
-// -------------------
-/* Function: Calculate the number of connected XInput devices
- Todo: Implement this to figure out if there are multiple XInput controllers connected,
- we currently only try to connect to XInput device 0 */
-void Init()
-{
- // Init state
- //ZeroMemory( g_Controllers, sizeof( CONTROLER_STATE ) * MAX_CONTROLLERS );
-
- // Declaration
- DWORD dwResult;
-
- // Calculate the number of connected XInput devices
- for( DWORD i = 0; i < MAX_CONTROLLERS; i++ )
- {
- // Simply get the state of the controller from XInput.
- dwResult = XInputGetState( i, &g_Controllers[i].state );
-
- if( dwResult == ERROR_SUCCESS )
- g_Controllers[i].bConnected = true;
- else
- g_Controllers[i].bConnected = false;
- }
-
-}
-
-// Get the trigger status
-// -------------------
-int GetXI(int Controller, int Button)
-{
- // Update the internal status
- DWORD dwResult;
- dwResult = XInputGetState(Controller, &g_Controllers[Controller].state);
-
- if (dwResult != ERROR_SUCCESS) return -1;
-
- switch (Button)
- {
- case InputCommon::XI_TRIGGER_L:
- return g_Controllers[Controller].state.Gamepad.bLeftTrigger;
-
- case InputCommon::XI_TRIGGER_R:
- return g_Controllers[Controller].state.Gamepad.bRightTrigger;
-
- default:
- return 0;
- }
-}
-
-// Check if a certain controller is connected
-// -------------------
-bool IsConnected(int Controller)
-{
- DWORD dwResult = XInputGetState( Controller, &g_Controllers[Controller].state );
-
- // Update the connected status
- if( dwResult == ERROR_SUCCESS )
- return true;
- else
- return false;
-}
-
-} // XInput
-
-#endif
+ +// +// Licensetype: GNU General Public License (GPL) +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. +// +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ +// +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ +// + + + + +// File description +/* ------------------- + Function: This file will get the status of the analog triggers of any connected XInput device. + This code was made with the help of SimpleController.cpp in the June 2008 Microsoft DirectX SDK + Samples. + +///////////////////////////////////////////////////// */ + +#ifdef _WIN32 + + +// Includes +// ------------------- +#include <windows.h> +#include <XInput.h> // XInput API +#include "InputCommon.h" + +namespace XInput +{ + +// Declarations +// ------------------- + +#define MAX_CONTROLLERS 4 // XInput handles up to 4 controllers + +struct CONTROLER_STATE +{ + XINPUT_STATE state; + bool bConnected; +}; + +CONTROLER_STATE g_Controllers[MAX_CONTROLLERS]; + + +// Init +// ------------------- +/* Function: Calculate the number of connected XInput devices + Todo: Implement this to figure out if there are multiple XInput controllers connected, + we currently only try to connect to XInput device 0 */ +void Init() +{ + // Init state + //ZeroMemory( g_Controllers, sizeof( CONTROLER_STATE ) * MAX_CONTROLLERS ); + + // Declaration + DWORD dwResult; + + // Calculate the number of connected XInput devices + for( DWORD i = 0; i < MAX_CONTROLLERS; i++ ) + { + // Simply get the state of the controller from XInput. + dwResult = XInputGetState( i, &g_Controllers[i].state ); + + if( dwResult == ERROR_SUCCESS ) + g_Controllers[i].bConnected = true; + else + g_Controllers[i].bConnected = false; + } + +} + +// Get the trigger status +// ------------------- +int GetXI(int Controller, int Button) +{ + // Update the internal status + DWORD dwResult; + dwResult = XInputGetState(Controller, &g_Controllers[Controller].state); + + if (dwResult != ERROR_SUCCESS) return -1; + + switch (Button) + { + case InputCommon::XI_TRIGGER_L: + return g_Controllers[Controller].state.Gamepad.bLeftTrigger; + + case InputCommon::XI_TRIGGER_R: + return g_Controllers[Controller].state.Gamepad.bRightTrigger; + + default: + return 0; + } +} + +// Check if a certain controller is connected +// ------------------- +bool IsConnected(int Controller) +{ + DWORD dwResult = XInputGetState( Controller, &g_Controllers[Controller].state ); + + // Update the connected status + if( dwResult == ERROR_SUCCESS ) + return true; + else + return false; +} + +} // XInput + +#endif diff --git a/Source/Core/InputCommon/Src/XInput_Util.h b/Source/Core/InputCommon/Src/XInput_Util.h index 411e1958a0..24b653c808 100644 --- a/Source/Core/InputCommon/Src/XInput_Util.h +++ b/Source/Core/InputCommon/Src/XInput_Util.h @@ -1,42 +1,42 @@ -
-//
-// Licensetype: GNU General Public License (GPL)
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, version 2.0.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License 2.0 for more details.
-//
-// A copy of the GPL 2.0 should have been included with the program.
-// If not, see http://www.gnu.org/licenses/
-//
-// Official SVN repository and contact information can be found at
-// http://code.google.com/p/dolphin-emu/
-//
-
-
-#ifdef _WIN32
-
-
-// Includes
-// ----------
-#include <iostream>
-
-
-namespace XInput
-{
-
-// Declarations
-// ----------
-void Init();
-int GetXI(int Controller, int Button);
-bool IsConnected(int Controller);
-
-} // XInput
-
-#endif
-
+ +// +// Licensetype: GNU General Public License (GPL) +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. +// +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ +// +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ +// + + +#ifdef _WIN32 + + +// Includes +// ---------- +#include <iostream> + + +namespace XInput +{ + +// Declarations +// ---------- +void Init(); +int GetXI(int Controller, int Button); +bool IsConnected(int Controller); + +} // XInput + +#endif + |
