diff options
| author | John Peterson <jpeterson57@gmail.com> | 2009-02-09 13:10:29 +0000 |
|---|---|---|
| committer | John Peterson <jpeterson57@gmail.com> | 2009-02-09 13:10:29 +0000 |
| commit | 1fbebb4ce15b04872a698c8fd6c7f1335ac978b0 (patch) | |
| tree | 22d908dc44f4e88aa5d4655b310e7dee5d8e7513 /Source/Core | |
| parent | e8925e43febb2f95b1d4ec09f4804861bab37282 (diff) | |
Wiimote: Configure gamepad in Wiimote plugin
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2172 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core')
| -rw-r--r-- | Source/Core/Core/Src/Core.cpp | 2 | ||||
| -rw-r--r-- | Source/Core/Core/Src/PluginManager.cpp | 16 | ||||
| -rw-r--r-- | Source/Core/Core/Src/PluginManager.h | 3 | ||||
| -rw-r--r-- | Source/Core/InputCommon/Src/SDL.cpp | 130 | ||||
| -rw-r--r-- | Source/Core/InputCommon/Src/SDL.h | 30 |
5 files changed, 176 insertions, 5 deletions
diff --git a/Source/Core/Core/Src/Core.cpp b/Source/Core/Core/Src/Core.cpp index c6d45b1844..b34f6f6f4e 100644 --- a/Source/Core/Core/Src/Core.cpp +++ b/Source/Core/Core/Src/Core.cpp @@ -353,6 +353,8 @@ THREAD_RETURN EmuThread(void *pArg) PADInitialize.hWnd = g_pWindowHandle; PADInitialize.pLog = Callback_PADLog; PADInitialize.padNumber = i; + // This is may be needed to avoid a SDL problem + //Plugins.FreeWiimote(); // Check if we should init the plugin if (Plugins.OkayToInitPlugin(i)) { diff --git a/Source/Core/Core/Src/PluginManager.cpp b/Source/Core/Core/Src/PluginManager.cpp index 6dfd67e1c0..c81cbac080 100644 --- a/Source/Core/Core/Src/PluginManager.cpp +++ b/Source/Core/Core/Src/PluginManager.cpp @@ -457,11 +457,19 @@ void CPluginManager::FreeDSP() delete m_dsp; m_dsp = NULL; } -void CPluginManager::FreePad(u32 pad) +void CPluginManager::FreePad(u32 Pad) { - if (pad < MAXPADS) { - delete m_pad[pad]; - m_pad[pad] = NULL; + if (Pad < MAXPADS) { + delete m_pad[Pad]; + m_pad[Pad] = NULL; + } +} +void CPluginManager::FreeWiimote(u32 Wiimote) +{ + if (Wiimote < MAXWIIMOTES) + { + delete m_wiimote[Wiimote]; + m_wiimote[Wiimote] = NULL; } } /////////////////////////////////////////// diff --git a/Source/Core/Core/Src/PluginManager.h b/Source/Core/Core/Src/PluginManager.h index d20ac9b076..e3b4aebbeb 100644 --- a/Source/Core/Core/Src/PluginManager.h +++ b/Source/Core/Core/Src/PluginManager.h @@ -54,7 +54,8 @@ public: void FreeVideo(); void FreeDSP(); - void FreePad(u32 pad); + void FreePad(u32 Pad); + void FreeWiimote(u32 Wiimote); bool InitPlugins(); void ShutdownPlugins(); diff --git a/Source/Core/InputCommon/Src/SDL.cpp b/Source/Core/InputCommon/Src/SDL.cpp index 286ccf0fc1..67c4b97b31 100644 --- a/Source/Core/InputCommon/Src/SDL.cpp +++ b/Source/Core/InputCommon/Src/SDL.cpp @@ -231,4 +231,134 @@ void GetJoyState(CONTROLLER_STATE &_PadState, CONTROLLER_MAPPING _PadMapping, in +
+//////////////////////////////////////////////////////////////////////////////////////////
+// Configure button mapping
+// ŻŻŻŻŻŻŻŻŻŻ
+
+// Avoid extreme axis values
+// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
+/* Function: We have to avoid very big values to becuse some triggers are -0x8000 in the
+ unpressed state (and then go from -0x8000 to 0x8000 as they are fully pressed) */
+bool AvoidValues(int value)
+{
+ // Avoid detecting very small or very big (for triggers) values
+ if( (value > -0x2000 && value < 0x2000) // Small values
+ || (value < -0x6000 || value > 0x6000)) // 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)
+{
+ // 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)) continue; // Avoid values
+
+ pressed = i + (LeftRight ? 1000 : 0); // Identify the analog triggers
+ type = InputCommon::CTL_AXIS;
+ Succeed = true;
+ }
+ Console::Print("Id: %i\n", joy);
+ }
+
+ // Check for a hat
+ if(Hat)
+ {
+ for(int i = 0; i < hats; i++)
+ {
+ if(SDL_JoystickGetHat(joy, i))
+ {
+ 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)
+ {
+ for(int i = 0; i <= InputCommon::XI_TRIGGER_R; i++)
+ {
+ if(XInput::GetXI(0, 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
+ {
+ Succeed = true;
+ KeyboardKey = 0;
+ pressed = -1;
+ }
+ }
+}
+/////////////////////////////////////////////////////////// Configure button mapping
+
+
+
} // InputCommon
\ No newline at end of file diff --git a/Source/Core/InputCommon/Src/SDL.h b/Source/Core/InputCommon/Src/SDL.h index 02305df771..3fb9d8b06d 100644 --- a/Source/Core/InputCommon/Src/SDL.h +++ b/Source/Core/InputCommon/Src/SDL.h @@ -41,6 +41,7 @@ #include <SDL.h> // Externals
#include "Common.h" // Common
+#include "ConsoleWindow.h"
////////////////////////////
@@ -148,6 +149,34 @@ enum XI_TRIGGER_L = 0,
XI_TRIGGER_R
};
+
+
+struct PadAxis
+{
+ int Lx;
+ int Ly;
+ int Rx;
+ int Ry;
+ int Tl; // Triggers
+ int Tr;
+};
+struct CONTROLLER_STATE_NEW // GC PAD INFO/STATE
+{
+ PadAxis Axis; // 6 Axes (Main, Sub, Triggers)
+ SDL_Joystick *joy; // SDL joystick device
+};
+
+struct CONTROLLER_MAPPING_NEW // GC PAD MAPPING
+{
+ PadAxis Axis; // (See above)
+ bool enabled; // Pad attached?
+ int deadzone; // Deadzone... what else?
+ int ID; // SDL joystick device ID
+ int controllertype; // D-Pad type: Hat or custom buttons
+ int triggertype; // SDL or XInput trigger
+ std::string SDiagonal;
+ bool bSquareToCircle;
+};
////////////////////////////
@@ -158,6 +187,7 @@ enum // General functions
bool SearchDevices(std::vector<CONTROLLER_INFO> &_joyinfo, int &NumPads, int &NumGoodPads);
void GetJoyState(CONTROLLER_STATE &_PadState, CONTROLLER_MAPPING _PadMapping, int controller, int NumButtons);
+void GetButton(SDL_Joystick*, int,int,int,int, int&,int&,int&,int&,bool&,bool&, bool,bool,bool,bool,bool);
// Value conversion
int Pad_Convert(int _val);
|
