diff options
| author | John Peterson <jpeterson57@gmail.com> | 2009-02-08 14:34:23 +0000 |
|---|---|---|
| committer | John Peterson <jpeterson57@gmail.com> | 2009-02-08 14:34:23 +0000 |
| commit | c6b4f5c8191ca52c6f366e1e07baec557d032504 (patch) | |
| tree | 61acc9d2d3964af6beb4fcfe24c29e6a13eef1dd /Source/Plugins | |
| parent | 44370518a37d2c28811d5ad5fb76df060a6ff482 (diff) | |
InputCommon and nJoy: Moved functions to InputCommon, to be shared with the Wiimote plugin
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2147 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Plugins')
| -rw-r--r-- | Source/Plugins/Plugin_nJoy_SDL/Plugin_nJoy_SDL.vcproj | 8 | ||||
| -rw-r--r-- | Source/Plugins/Plugin_nJoy_SDL/Src/Config.cpp | 64 | ||||
| -rw-r--r-- | Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigAdvanced.cpp | 22 | ||||
| -rw-r--r-- | Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.cpp | 10 | ||||
| -rw-r--r-- | Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigJoypad.cpp | 88 | ||||
| -rw-r--r-- | Source/Plugins/Plugin_nJoy_SDL/Src/XInput.cpp | 136 | ||||
| -rw-r--r-- | Source/Plugins/Plugin_nJoy_SDL/Src/XInput.h | 45 | ||||
| -rw-r--r-- | Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.cpp | 250 | ||||
| -rw-r--r-- | Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.h | 126 |
9 files changed, 139 insertions, 610 deletions
diff --git a/Source/Plugins/Plugin_nJoy_SDL/Plugin_nJoy_SDL.vcproj b/Source/Plugins/Plugin_nJoy_SDL/Plugin_nJoy_SDL.vcproj index b20c24766c..94adefdb65 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Plugin_nJoy_SDL.vcproj +++ b/Source/Plugins/Plugin_nJoy_SDL/Plugin_nJoy_SDL.vcproj @@ -522,14 +522,6 @@ RelativePath=".\Src\Rumble.cpp"
>
</File>
- <File
- RelativePath=".\Src\XInput.cpp"
- >
- </File>
- <File
- RelativePath=".\Src\XInput.h"
- >
- </File>
</Filter>
<Filter
Name="GUI"
diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/Config.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/Config.cpp index 6d2057b645..2a4e26045f 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/Config.cpp +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/Config.cpp @@ -141,23 +141,23 @@ void Config::Save(int Slot) SectionName = joyinfo[PadMapping[i].ID].Name;
}
- file.Set(SectionName.c_str(), "l_shoulder", PadMapping[i].buttons[CTL_L_SHOULDER]);
- file.Set(SectionName.c_str(), "r_shoulder", PadMapping[i].buttons[CTL_R_SHOULDER]);
- file.Set(SectionName.c_str(), "a_button", PadMapping[i].buttons[CTL_A_BUTTON]);
- file.Set(SectionName.c_str(), "b_button", PadMapping[i].buttons[CTL_B_BUTTON]);
- file.Set(SectionName.c_str(), "x_button", PadMapping[i].buttons[CTL_X_BUTTON]);
- file.Set(SectionName.c_str(), "y_button", PadMapping[i].buttons[CTL_Y_BUTTON]);
- file.Set(SectionName.c_str(), "z_trigger", PadMapping[i].buttons[CTL_Z_TRIGGER]);
- file.Set(SectionName.c_str(), "start_button", PadMapping[i].buttons[CTL_START]);
+ file.Set(SectionName.c_str(), "l_shoulder", PadMapping[i].buttons[InputCommon::CTL_L_SHOULDER]);
+ file.Set(SectionName.c_str(), "r_shoulder", PadMapping[i].buttons[InputCommon::CTL_R_SHOULDER]);
+ file.Set(SectionName.c_str(), "a_button", PadMapping[i].buttons[InputCommon::CTL_A_BUTTON]);
+ file.Set(SectionName.c_str(), "b_button", PadMapping[i].buttons[InputCommon::CTL_B_BUTTON]);
+ file.Set(SectionName.c_str(), "x_button", PadMapping[i].buttons[InputCommon::CTL_X_BUTTON]);
+ file.Set(SectionName.c_str(), "y_button", PadMapping[i].buttons[InputCommon::CTL_Y_BUTTON]);
+ file.Set(SectionName.c_str(), "z_trigger", PadMapping[i].buttons[InputCommon::CTL_Z_TRIGGER]);
+ file.Set(SectionName.c_str(), "start_button", PadMapping[i].buttons[InputCommon::CTL_START]);
file.Set(SectionName.c_str(), "dpad", PadMapping[i].dpad);
- file.Set(SectionName.c_str(), "dpad_up", PadMapping[i].dpad2[CTL_D_PAD_UP]);
- file.Set(SectionName.c_str(), "dpad_down", PadMapping[i].dpad2[CTL_D_PAD_DOWN]);
- file.Set(SectionName.c_str(), "dpad_left", PadMapping[i].dpad2[CTL_D_PAD_LEFT]);
- file.Set(SectionName.c_str(), "dpad_right", PadMapping[i].dpad2[CTL_D_PAD_RIGHT]);
- file.Set(SectionName.c_str(), "main_x", PadMapping[i].axis[CTL_MAIN_X]);
- file.Set(SectionName.c_str(), "main_y", PadMapping[i].axis[CTL_MAIN_Y]);
- file.Set(SectionName.c_str(), "sub_x", PadMapping[i].axis[CTL_SUB_X]);
- file.Set(SectionName.c_str(), "sub_y", PadMapping[i].axis[CTL_SUB_Y]);
+ file.Set(SectionName.c_str(), "dpad_up", PadMapping[i].dpad2[InputCommon::CTL_D_PAD_UP]);
+ file.Set(SectionName.c_str(), "dpad_down", PadMapping[i].dpad2[InputCommon::CTL_D_PAD_DOWN]);
+ file.Set(SectionName.c_str(), "dpad_left", PadMapping[i].dpad2[InputCommon::CTL_D_PAD_LEFT]);
+ file.Set(SectionName.c_str(), "dpad_right", PadMapping[i].dpad2[InputCommon::CTL_D_PAD_RIGHT]);
+ file.Set(SectionName.c_str(), "main_x", PadMapping[i].axis[InputCommon::CTL_MAIN_X]);
+ file.Set(SectionName.c_str(), "main_y", PadMapping[i].axis[InputCommon::CTL_MAIN_Y]);
+ file.Set(SectionName.c_str(), "sub_x", PadMapping[i].axis[InputCommon::CTL_SUB_X]);
+ file.Set(SectionName.c_str(), "sub_y", PadMapping[i].axis[InputCommon::CTL_SUB_Y]);
file.Set(SectionName.c_str(), "deadzone", PadMapping[i].deadzone);
file.Set(SectionName.c_str(), "halfpress", PadMapping[i].halfpress);
@@ -228,23 +228,23 @@ void Config::Load(bool ChangePad, bool ChangeSaveByID) SectionName = joyinfo[PadMapping[i].ID].Name;
}
- file.Get(SectionName.c_str(), "l_shoulder", &PadMapping[i].buttons[CTL_L_SHOULDER], 4);
- file.Get(SectionName.c_str(), "r_shoulder", &PadMapping[i].buttons[CTL_R_SHOULDER], 5);
- file.Get(SectionName.c_str(), "a_button", &PadMapping[i].buttons[CTL_A_BUTTON], 0);
- file.Get(SectionName.c_str(), "b_button", &PadMapping[i].buttons[CTL_B_BUTTON], 1);
- file.Get(SectionName.c_str(), "x_button", &PadMapping[i].buttons[CTL_X_BUTTON], 3);
- file.Get(SectionName.c_str(), "y_button", &PadMapping[i].buttons[CTL_Y_BUTTON], 2);
- file.Get(SectionName.c_str(), "z_trigger", &PadMapping[i].buttons[CTL_Z_TRIGGER], 7);
- file.Get(SectionName.c_str(), "start_button", &PadMapping[i].buttons[CTL_START], 9);
+ file.Get(SectionName.c_str(), "l_shoulder", &PadMapping[i].buttons[InputCommon::CTL_L_SHOULDER], 4);
+ file.Get(SectionName.c_str(), "r_shoulder", &PadMapping[i].buttons[InputCommon::CTL_R_SHOULDER], 5);
+ file.Get(SectionName.c_str(), "a_button", &PadMapping[i].buttons[InputCommon::CTL_A_BUTTON], 0);
+ file.Get(SectionName.c_str(), "b_button", &PadMapping[i].buttons[InputCommon::CTL_B_BUTTON], 1);
+ file.Get(SectionName.c_str(), "x_button", &PadMapping[i].buttons[InputCommon::CTL_X_BUTTON], 3);
+ file.Get(SectionName.c_str(), "y_button", &PadMapping[i].buttons[InputCommon::CTL_Y_BUTTON], 2);
+ file.Get(SectionName.c_str(), "z_trigger", &PadMapping[i].buttons[InputCommon::CTL_Z_TRIGGER], 7);
+ file.Get(SectionName.c_str(), "start_button", &PadMapping[i].buttons[InputCommon::CTL_START], 9);
file.Get(SectionName.c_str(), "dpad", &PadMapping[i].dpad, 0);
- file.Get(SectionName.c_str(), "dpad_up", &PadMapping[i].dpad2[CTL_D_PAD_UP], 0);
- file.Get(SectionName.c_str(), "dpad_down", &PadMapping[i].dpad2[CTL_D_PAD_DOWN], 0);
- file.Get(SectionName.c_str(), "dpad_left", &PadMapping[i].dpad2[CTL_D_PAD_LEFT], 0);
- file.Get(SectionName.c_str(), "dpad_right", &PadMapping[i].dpad2[CTL_D_PAD_RIGHT], 0);
- file.Get(SectionName.c_str(), "main_x", &PadMapping[i].axis[CTL_MAIN_X], 0);
- file.Get(SectionName.c_str(), "main_y", &PadMapping[i].axis[CTL_MAIN_Y], 1);
- file.Get(SectionName.c_str(), "sub_x", &PadMapping[i].axis[CTL_SUB_X], 2);
- file.Get(SectionName.c_str(), "sub_y", &PadMapping[i].axis[CTL_SUB_Y], 3);
+ file.Get(SectionName.c_str(), "dpad_up", &PadMapping[i].dpad2[InputCommon::CTL_D_PAD_UP], 0);
+ file.Get(SectionName.c_str(), "dpad_down", &PadMapping[i].dpad2[InputCommon::CTL_D_PAD_DOWN], 0);
+ file.Get(SectionName.c_str(), "dpad_left", &PadMapping[i].dpad2[InputCommon::CTL_D_PAD_LEFT], 0);
+ file.Get(SectionName.c_str(), "dpad_right", &PadMapping[i].dpad2[InputCommon::CTL_D_PAD_RIGHT], 0);
+ file.Get(SectionName.c_str(), "main_x", &PadMapping[i].axis[InputCommon::CTL_MAIN_X], 0);
+ file.Get(SectionName.c_str(), "main_y", &PadMapping[i].axis[InputCommon::CTL_MAIN_Y], 1);
+ file.Get(SectionName.c_str(), "sub_x", &PadMapping[i].axis[InputCommon::CTL_SUB_X], 2);
+ file.Get(SectionName.c_str(), "sub_y", &PadMapping[i].axis[InputCommon::CTL_SUB_Y], 3);
file.Get(SectionName.c_str(), "deadzone", &PadMapping[i].deadzone, 9);
file.Get(SectionName.c_str(), "halfpress", &PadMapping[i].halfpress, -1);
diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigAdvanced.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigAdvanced.cpp index fa06351219..b2f2d8bdb6 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigAdvanced.cpp +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigAdvanced.cpp @@ -70,8 +70,10 @@ void ConfigBox::PadGetStatus() int PhysicalDevice = PadMapping[notebookpage].ID;
int TriggerType = PadMapping[notebookpage].triggertype;
- // Get pad status
- GetJoyState(notebookpage);
+ // Check that Dolphin is in focus, otherwise don't update the pad status
+ if (!g_Config.bCheckFocus && IsFocus())
+ InputCommon::GetJoyState(PadState[notebookpage], PadMapping[notebookpage], notebookpage, joyinfo[PadMapping[notebookpage].ID].NumButtons);
+
//////////////////////////////////////
// Analog stick
@@ -81,8 +83,8 @@ void ConfigBox::PadGetStatus() //int deadzone2 = (int)(((float)(-128.00/100.00)) * (float)(PadMapping[_numPAD].deadzone+1));
// Get original values
- int main_x = PadState[notebookpage].axis[CTL_MAIN_X];
- int main_y = PadState[notebookpage].axis[CTL_MAIN_Y];
+ int main_x = PadState[notebookpage].axis[InputCommon::CTL_MAIN_X];
+ int main_y = PadState[notebookpage].axis[InputCommon::CTL_MAIN_Y];
//int sub_x = (PadState[_numPAD].axis[CTL_SUB_X];
//int sub_y = -(PadState[_numPAD].axis[CTL_SUB_Y];
@@ -138,11 +140,11 @@ void ConfigBox::PadGetStatus() m_JoyShoulderR[notebookpage]->GetValue().ToLong(&Right);
// Get the trigger values
- int TriggerLeft = PadState[notebookpage].axis[CTL_L_SHOULDER];
- int TriggerRight = PadState[notebookpage].axis[CTL_R_SHOULDER];
+ int TriggerLeft = PadState[notebookpage].axis[InputCommon::CTL_L_SHOULDER];
+ int TriggerRight = PadState[notebookpage].axis[InputCommon::CTL_R_SHOULDER];
// Convert the triggers values
- if (PadMapping[notebookpage].triggertype == CTL_TRIGGER_SDL)
+ if (PadMapping[notebookpage].triggertype == InputCommon::CTL_TRIGGER_SDL)
{
TriggerLeft = Pad_Convert(TriggerLeft);
TriggerRight = Pad_Convert(TriggerRight);
@@ -153,8 +155,8 @@ void ConfigBox::PadGetStatus() if(Right < 1000) TriggerRight = 0;
// Get the digital values
- if(Left < 1000 && PadState[notebookpage].buttons[CTL_L_SHOULDER]) TriggerLeft = TriggerValue;
- if(Right < 1000 && PadState[notebookpage].buttons[CTL_R_SHOULDER]) TriggerRight = TriggerValue;
+ if(Left < 1000 && PadState[notebookpage].buttons[InputCommon::CTL_L_SHOULDER]) TriggerLeft = TriggerValue;
+ if(Right < 1000 && PadState[notebookpage].buttons[InputCommon::CTL_R_SHOULDER]) TriggerRight = TriggerValue;
m_TStatusTriggers[notebookpage]->SetLabel(wxString::Format(
wxT("Left:%03i Right:%03i"),
@@ -233,7 +235,7 @@ std::string ShowStatus(int VirtualController) //PadState[PadMapping[0].ID].joy, PadState[PadMapping[1].ID].joy, PadState[PadMapping[2].ID].joy, PadState[PadMapping[3].ID].joy,
#ifdef _WIN32
- XInput::IsConnected(0), XInput::GetXI(0, XI_TRIGGER_L), XInput::GetXI(0, XI_TRIGGER_R),
+ XInput::IsConnected(0), XInput::GetXI(0, InputCommon::XI_TRIGGER_L), XInput::GetXI(0, InputCommon::XI_TRIGGER_R),
#endif
StrAxes.c_str(), StrHats.c_str(), StrBut.c_str(),
Axes, Balls, Hats, Buttons
diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.cpp index b1a2d48e53..2590546990 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.cpp +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.cpp @@ -475,7 +475,7 @@ void ConfigBox::UpdateGUI(int _notebookpage) UpdateGUIKeys(_notebookpage); // Collect status - bool Hat = (PadMapping[_notebookpage].controllertype == CTL_DPAD_HAT); + bool Hat = (PadMapping[_notebookpage].controllertype == InputCommon::CTL_DPAD_HAT); long Left, Right; m_JoyShoulderL[_notebookpage]->GetValue().ToLong(&Left); m_JoyShoulderR[_notebookpage]->GetValue().ToLong(&Right); @@ -619,12 +619,12 @@ void ConfigBox::CreateGUIControls() // Populate the DPad type and Trigger type list // ----------------------------- wxArrayString wxAS_DPadType; - wxAS_DPadType.Add(wxString::FromAscii(DPadType[CTL_DPAD_HAT])); - wxAS_DPadType.Add(wxString::FromAscii(DPadType[CTL_DPAD_CUSTOM])); + wxAS_DPadType.Add(wxString::FromAscii(DPadType[InputCommon::CTL_DPAD_HAT])); + wxAS_DPadType.Add(wxString::FromAscii(DPadType[InputCommon::CTL_DPAD_CUSTOM])); wxArrayString wxAS_TriggerType; - wxAS_TriggerType.Add(wxString::FromAscii(TriggerType[CTL_TRIGGER_SDL])); - wxAS_TriggerType.Add(wxString::FromAscii(TriggerType[CTL_TRIGGER_XINPUT])); + wxAS_TriggerType.Add(wxString::FromAscii(TriggerType[InputCommon::CTL_TRIGGER_SDL])); + wxAS_TriggerType.Add(wxString::FromAscii(TriggerType[InputCommon::CTL_TRIGGER_XINPUT])); // -------------------------------------------------------------------- // Populate the deadzone list diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigJoypad.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigJoypad.cpp index faeadff75b..c42d7b2654 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigJoypad.cpp +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigJoypad.cpp @@ -56,22 +56,22 @@ void ConfigBox::UpdateGUIKeys(int controller) // Update the enabled checkbox
m_Joyattach[controller]->SetValue(PadMapping[controller].enabled == 1 ? true : false);
- tmp << PadMapping[controller].buttons[CTL_L_SHOULDER]; m_JoyShoulderL[controller]->SetValue(tmp); tmp.clear();
- tmp << PadMapping[controller].buttons[CTL_R_SHOULDER]; m_JoyShoulderR[controller]->SetValue(tmp); tmp.clear();
+ tmp << PadMapping[controller].buttons[InputCommon::CTL_L_SHOULDER]; m_JoyShoulderL[controller]->SetValue(tmp); tmp.clear();
+ tmp << PadMapping[controller].buttons[InputCommon::CTL_R_SHOULDER]; m_JoyShoulderR[controller]->SetValue(tmp); tmp.clear();
- tmp << PadMapping[controller].buttons[CTL_A_BUTTON]; m_JoyButtonA[controller]->SetValue(tmp); tmp.clear();
- tmp << PadMapping[controller].buttons[CTL_B_BUTTON]; m_JoyButtonB[controller]->SetValue(tmp); tmp.clear();
- tmp << PadMapping[controller].buttons[CTL_X_BUTTON]; m_JoyButtonX[controller]->SetValue(tmp); tmp.clear();
- tmp << PadMapping[controller].buttons[CTL_Y_BUTTON]; m_JoyButtonY[controller]->SetValue(tmp); tmp.clear();
- tmp << PadMapping[controller].buttons[CTL_Z_TRIGGER]; m_JoyButtonZ[controller]->SetValue(tmp); tmp.clear();
+ tmp << PadMapping[controller].buttons[InputCommon::CTL_A_BUTTON]; m_JoyButtonA[controller]->SetValue(tmp); tmp.clear();
+ tmp << PadMapping[controller].buttons[InputCommon::CTL_B_BUTTON]; m_JoyButtonB[controller]->SetValue(tmp); tmp.clear();
+ tmp << PadMapping[controller].buttons[InputCommon::CTL_X_BUTTON]; m_JoyButtonX[controller]->SetValue(tmp); tmp.clear();
+ tmp << PadMapping[controller].buttons[InputCommon::CTL_Y_BUTTON]; m_JoyButtonY[controller]->SetValue(tmp); tmp.clear();
+ tmp << PadMapping[controller].buttons[InputCommon::CTL_Z_TRIGGER]; m_JoyButtonZ[controller]->SetValue(tmp); tmp.clear();
- tmp << PadMapping[controller].buttons[CTL_START]; m_JoyButtonStart[controller]->SetValue(tmp); tmp.clear();
+ tmp << PadMapping[controller].buttons[InputCommon::CTL_START]; m_JoyButtonStart[controller]->SetValue(tmp); tmp.clear();
tmp << PadMapping[controller].halfpress; m_JoyButtonHalfpress[controller]->SetValue(tmp); tmp.clear();
- tmp << PadMapping[controller].axis[CTL_MAIN_X]; m_JoyAnalogMainX[controller]->SetValue(tmp); tmp.clear();
- tmp << PadMapping[controller].axis[CTL_MAIN_Y]; m_JoyAnalogMainY[controller]->SetValue(tmp); tmp.clear();
- tmp << PadMapping[controller].axis[CTL_SUB_X]; m_JoyAnalogSubX[controller]->SetValue(tmp); tmp.clear();
- tmp << PadMapping[controller].axis[CTL_SUB_Y]; m_JoyAnalogSubY[controller]->SetValue(tmp); tmp.clear();
+ tmp << PadMapping[controller].axis[InputCommon::CTL_MAIN_X]; m_JoyAnalogMainX[controller]->SetValue(tmp); tmp.clear();
+ tmp << PadMapping[controller].axis[InputCommon::CTL_MAIN_Y]; m_JoyAnalogMainY[controller]->SetValue(tmp); tmp.clear();
+ tmp << PadMapping[controller].axis[InputCommon::CTL_SUB_X]; m_JoyAnalogSubX[controller]->SetValue(tmp); tmp.clear();
+ tmp << PadMapping[controller].axis[InputCommon::CTL_SUB_Y]; m_JoyAnalogSubY[controller]->SetValue(tmp); tmp.clear();
// Update the deadzone and controller type controls
m_ControlType[controller]->SetSelection(PadMapping[controller].controllertype);
@@ -83,16 +83,16 @@ void ConfigBox::UpdateGUIKeys(int controller) //LogMsg("m_TriggerType[%i] = %i\n", controller, PadMapping[controller].triggertype);
// Update D-Pad
- if(PadMapping[controller].controllertype == CTL_DPAD_HAT)
+ if(PadMapping[controller].controllertype == InputCommon::CTL_DPAD_HAT)
{
tmp << PadMapping[controller].dpad; m_JoyDpadUp[controller]->SetValue(tmp); tmp.clear();
}
else
{
- tmp << PadMapping[controller].dpad2[CTL_D_PAD_UP]; m_JoyDpadUp[controller]->SetValue(tmp); tmp.clear();
- tmp << PadMapping[controller].dpad2[CTL_D_PAD_DOWN]; m_JoyDpadDown[controller]->SetValue(tmp); tmp.clear();
- tmp << PadMapping[controller].dpad2[CTL_D_PAD_LEFT]; m_JoyDpadLeft[controller]->SetValue(tmp); tmp.clear();
- tmp << PadMapping[controller].dpad2[CTL_D_PAD_RIGHT]; m_JoyDpadRight[controller]->SetValue(tmp); tmp.clear();
+ tmp << PadMapping[controller].dpad2[InputCommon::CTL_D_PAD_UP]; m_JoyDpadUp[controller]->SetValue(tmp); tmp.clear();
+ tmp << PadMapping[controller].dpad2[InputCommon::CTL_D_PAD_DOWN]; m_JoyDpadDown[controller]->SetValue(tmp); tmp.clear();
+ tmp << PadMapping[controller].dpad2[InputCommon::CTL_D_PAD_LEFT]; m_JoyDpadLeft[controller]->SetValue(tmp); tmp.clear();
+ tmp << PadMapping[controller].dpad2[InputCommon::CTL_D_PAD_RIGHT]; m_JoyDpadRight[controller]->SetValue(tmp); tmp.clear();
}
// Replace "-1" with "" in the GUI controls
@@ -124,22 +124,22 @@ void ConfigBox::SaveButtonMapping(int controller, bool DontChangeId, int FromSlo PadMapping[controller].bSquareToCircle = m_CBS_to_C[FromSlot]->IsChecked();
// The analog buttons
- m_JoyAnalogMainX[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].axis[CTL_MAIN_X] = value; tmp.clear();
- m_JoyAnalogMainY[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].axis[CTL_MAIN_Y] = value; tmp.clear();
- m_JoyAnalogSubX[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].axis[CTL_SUB_X] = value; tmp.clear();
- m_JoyAnalogSubY[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].axis[CTL_SUB_Y] = value; tmp.clear();
+ m_JoyAnalogMainX[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].axis[InputCommon::CTL_MAIN_X] = value; tmp.clear();
+ m_JoyAnalogMainY[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].axis[InputCommon::CTL_MAIN_Y] = value; tmp.clear();
+ m_JoyAnalogSubX[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].axis[InputCommon::CTL_SUB_X] = value; tmp.clear();
+ m_JoyAnalogSubY[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].axis[InputCommon::CTL_SUB_Y] = value; tmp.clear();
// The shoulder buttons
- m_JoyShoulderL[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].buttons[CTL_L_SHOULDER] = value;
- m_JoyShoulderR[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].buttons[CTL_R_SHOULDER] = value;
+ m_JoyShoulderL[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].buttons[InputCommon::CTL_L_SHOULDER] = value;
+ m_JoyShoulderR[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].buttons[InputCommon::CTL_R_SHOULDER] = value;
// The digital buttons
- m_JoyButtonA[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].buttons[CTL_A_BUTTON] = value; tmp.clear();
- m_JoyButtonB[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].buttons[CTL_B_BUTTON] = value; tmp.clear();
- m_JoyButtonX[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].buttons[CTL_X_BUTTON] = value; tmp.clear();
- m_JoyButtonY[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].buttons[CTL_Y_BUTTON] = value; tmp.clear();
- m_JoyButtonZ[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].buttons[CTL_Z_TRIGGER] = value; tmp.clear();
- m_JoyButtonStart[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].buttons[CTL_START] = value; tmp.clear();
+ m_JoyButtonA[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].buttons[InputCommon::CTL_A_BUTTON] = value; tmp.clear();
+ m_JoyButtonB[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].buttons[InputCommon::CTL_B_BUTTON] = value; tmp.clear();
+ m_JoyButtonX[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].buttons[InputCommon::CTL_X_BUTTON] = value; tmp.clear();
+ m_JoyButtonY[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].buttons[InputCommon::CTL_Y_BUTTON] = value; tmp.clear();
+ m_JoyButtonZ[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].buttons[InputCommon::CTL_Z_TRIGGER] = value; tmp.clear();
+ m_JoyButtonStart[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].buttons[InputCommon::CTL_START] = value; tmp.clear();
//LogMsg("PadMapping[%i].triggertype = %i, m_TriggerType[%i]->GetSelection() = %i\n",
// controller, PadMapping[controller].triggertype, FromSlot, m_TriggerType[FromSlot]->GetSelection());
@@ -148,16 +148,16 @@ void ConfigBox::SaveButtonMapping(int controller, bool DontChangeId, int FromSlo m_JoyButtonHalfpress[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].halfpress = value; tmp.clear();
// The digital pad
- if(PadMapping[controller].controllertype == CTL_DPAD_HAT)
+ if(PadMapping[controller].controllertype == InputCommon::CTL_DPAD_HAT)
{
m_JoyDpadUp[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].dpad = value; tmp.clear();
}
else
{
- m_JoyDpadUp[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].dpad2[CTL_D_PAD_UP] = value; tmp.clear();
- m_JoyDpadDown[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].dpad2[CTL_D_PAD_DOWN] = value; tmp.clear();
- m_JoyDpadLeft[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].dpad2[CTL_D_PAD_LEFT] = value; tmp.clear();
- m_JoyDpadRight[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].dpad2[CTL_D_PAD_RIGHT] = value; tmp.clear();
+ m_JoyDpadUp[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].dpad2[InputCommon::CTL_D_PAD_UP] = value; tmp.clear();
+ m_JoyDpadDown[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].dpad2[InputCommon::CTL_D_PAD_DOWN] = value; tmp.clear();
+ m_JoyDpadLeft[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].dpad2[InputCommon::CTL_D_PAD_LEFT] = value; tmp.clear();
+ m_JoyDpadRight[FromSlot]->GetValue().ToLong(&value); PadMapping[controller].dpad2[InputCommon::CTL_D_PAD_RIGHT] = value; tmp.clear();
}
// Replace "-1" with ""
@@ -288,16 +288,16 @@ void ConfigBox::DoGetButtons(int GetId) bool LeftRight = (GetId == IDB_SHOULDER_L || GetId == IDB_SHOULDER_R);
bool Axis = (GetId >= IDB_ANALOG_MAIN_X && GetId <= IDB_SHOULDER_R)
- && !(TriggerType == CTL_TRIGGER_XINPUT && (GetId == IDB_SHOULDER_L || GetId == IDB_SHOULDER_R) ); // Don't allow SDL here
+ && !(TriggerType == InputCommon::CTL_TRIGGER_XINPUT && (GetId == IDB_SHOULDER_L || GetId == IDB_SHOULDER_R) ); // Don't allow SDL here
- bool XInput = (TriggerType == CTL_TRIGGER_XINPUT);
+ bool XInput = (TriggerType == InputCommon::CTL_TRIGGER_XINPUT);
bool Button = (GetId >= IDB_BUTTON_A && GetId <= IDB_BUTTONHALFPRESS) // All digital buttons
|| (GetId == IDB_SHOULDER_L || GetId == IDB_SHOULDER_R) // both shoulder buttons
- || (GetId >= IDB_DPAD_UP && GetId <= IDB_DPAD_RIGHT && ControllerType == CTL_DPAD_CUSTOM); // Or the custom hat mode
+ || (GetId >= IDB_DPAD_UP && GetId <= IDB_DPAD_RIGHT && ControllerType == InputCommon::CTL_DPAD_CUSTOM); // Or the custom hat mode
bool Hat = (GetId >= IDB_DPAD_UP && GetId <= IDB_DPAD_RIGHT) // All DPads
- && (PadMapping[Controller].controllertype == CTL_DPAD_HAT); // Not with the hat option defined
+ && (PadMapping[Controller].controllertype == InputCommon::CTL_DPAD_HAT); // Not with the hat option defined
/* Open a new joystick. Joysticks[controller].GetId is the system GetId of the physical joystick
that is mapped to controller, for example 0, 1, 2, 3 for the first four PadMapping */
@@ -370,7 +370,7 @@ void ConfigBox::DoGetButtons(int GetId) if(AvoidValues(value)) continue; // Avoid values
pressed = i + (LeftRight ? 1000 : 0); // Identify the analog triggers
- type = CTL_AXIS;
+ type = InputCommon::CTL_AXIS;
Succeed = true;
}
}
@@ -383,7 +383,7 @@ void ConfigBox::DoGetButtons(int GetId) if(SDL_JoystickGetHat(joy, i))
{
pressed = i;
- type = CTL_HAT;
+ type = InputCommon::CTL_HAT;
Succeed = true;
}
}
@@ -400,7 +400,7 @@ void ConfigBox::DoGetButtons(int GetId) if(SDL_JoystickGetButton(joy, i))
{
pressed = i;
- type = CTL_BUTTON;
+ type = InputCommon::CTL_BUTTON;
Succeed = true;
}
}
@@ -410,12 +410,12 @@ void ConfigBox::DoGetButtons(int GetId) #ifdef _WIN32
if(XInput)
{
- for(int i = 0; i <= XI_TRIGGER_R; i++)
+ for(int i = 0; i <= InputCommon::XI_TRIGGER_R; i++)
{
if(XInput::GetXI(0, i))
{
pressed = i + 1000;
- type = CTL_AXIS;
+ type = InputCommon::CTL_AXIS;
Succeed = true;
}
}
@@ -429,7 +429,7 @@ void ConfigBox::DoGetButtons(int GetId) if(g_Pressed >= buttons)
{
pressed = g_Pressed;
- type = CTL_BUTTON;
+ type = InputCommon::CTL_BUTTON;
Succeed = true;
g_Pressed = 0;
if(pressed == WXK_ESCAPE) pressed = -1; // Check for the exape key
diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/XInput.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/XInput.cpp deleted file mode 100644 index 33a63e9edb..0000000000 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/XInput.cpp +++ /dev/null @@ -1,136 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////////////////
-//
-// 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 "nJoy.h" // Local
-///////////////////////////////////////////////
-
-
-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 XI_TRIGGER_L:
- return g_Controllers[0].state.Gamepad.bLeftTrigger;
-
- case XI_TRIGGER_R:
- return g_Controllers[0].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
\ No newline at end of file diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/XInput.h b/Source/Plugins/Plugin_nJoy_SDL/Src/XInput.h deleted file mode 100644 index 943d6ef9ea..0000000000 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/XInput.h +++ /dev/null @@ -1,45 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////////////////
-//
-// 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
\ No newline at end of file diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.cpp index c5d9b1191e..185df15abc 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.cpp +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.cpp @@ -81,12 +81,12 @@ // ŻŻŻŻŻŻŻŻŻ // Rumble in windows -#define _CONTROLLER_STATE_H // Avoid certain declarations in nJoy.h +#define _EXCLUDE_MAIN_ // Avoid certain declarations in nJoy.h FILE *pFile; HINSTANCE nJoy_hInst = NULL; -std::vector<CONTROLLER_INFO> joyinfo; -CONTROLLER_STATE PadState[4]; -CONTROLLER_MAPPING PadMapping[4]; +std::vector<InputCommon::CONTROLLER_INFO> joyinfo; +InputCommon::CONTROLLER_STATE PadState[4]; +InputCommon::CONTROLLER_MAPPING PadMapping[4]; bool emulator_running = false; int NumPads = 0, NumGoodPads = 0; HWND m_hWnd; // Handle to window @@ -193,7 +193,7 @@ void DllConfig(HWND _hParent) // Start the pads so we can use them in the configuration and advanced controls if(!emulator_running) { - NumPads = Search_Devices(); // Populate joyinfo for all attached devices + Search_Devices(joyinfo, NumPads, NumGoodPads); // Populate joyinfo for all attached devices } m_frame = new ConfigBox(NULL); @@ -251,7 +251,7 @@ void Initialize(void *init) m_hWnd = (HWND)g_PADInitialize->hWnd; #endif - NumPads = Search_Devices(); // Populate joyinfo for all attached devices + Search_Devices(joyinfo, NumPads, NumGoodPads); // Populate joyinfo for all attached devices /* Check if any of the pads failed to open. In Windows there is a strange "IDirectInputDevice2:: SetDataFormat() DirectX error -2147024809" after a few Open and Close */ @@ -265,79 +265,15 @@ void Initialize(void *init) } } - -// Search attached devices. Populate joyinfo for all attached physical devices. -// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ -int Search_Devices() +bool Search_Devices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads, int &_NumGoodPads) { - // Load config - #ifdef _DEBUG - DEBUG_INIT(); - #endif - - /* SDL 1.3 use DirectInput instead of the old Microsoft Multimeda API, and with this we need - the SDL_INIT_VIDEO flag to */ - if (!SDL_WasInit(0)) - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) - { - PanicAlert("Could not initialize SDL: %s", SDL_GetError()); - return 0; - } - - #ifdef _DEBUG - fprintf(pFile, "Scanning for devices\n"); - fprintf(pFile, "ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ\n"); - #endif - - // 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); - - #ifdef _DEBUG - fprintf(pFile, "ID: %d\n", i); - fprintf(pFile, "Name: %s\n", joyinfo[i].Name); - fprintf(pFile, "Buttons: %d\n", joyinfo[i].NumButtons); - fprintf(pFile, "Axes: %d\n", joyinfo[i].NumAxes); - fprintf(pFile, "Hats: %d\n", joyinfo[i].NumHats); - fprintf(pFile, "Balls: %d\n\n", joyinfo[i].NumBalls); - #endif - - // We have now read the values we need so we close the device - if (SDL_JoystickOpened(i)) SDL_JoystickClose(joyinfo[i].joy); - } + bool Success = InputCommon::SearchDevices(_joyinfo, _NumPads, _NumGoodPads); // Warn the user if no gamepads are detected - if (NumGoodPads == 0 && emulator_running) + if (_NumGoodPads == 0 && emulator_running) { PanicAlert("nJoy: No Gamepad Detected"); - return joyinfo.size(); + return false; } // Load PadMapping[] etc @@ -351,7 +287,7 @@ int Search_Devices() PadState[i].joy = SDL_JoystickOpen(PadMapping[i].ID); } - return joyinfo.size(); + return Success; } // Shutdown PAD (stop emulation) @@ -405,13 +341,13 @@ void PAD_Input(u16 _Key, u8 _UpDown) // Check if the keys are interesting, and then update it for(int i = 0; i < 4; i++) { - for(int j = CTL_L_SHOULDER; j <= CTL_START; j++) + for(int j = InputCommon::CTL_L_SHOULDER; j <= InputCommon::CTL_START; j++) { if (PadMapping[i].buttons[j] == _Key) { PadState[i].buttons[j] = _UpDown; break; } } - for(int j = CTL_D_PAD_UP; j <= CTL_D_PAD_RIGHT; j++) + for(int j = InputCommon::CTL_D_PAD_UP; j <= InputCommon::CTL_D_PAD_RIGHT; j++) { if (PadMapping[i].dpad2[j] == _Key) { PadState[i].dpad2[j] = _UpDown; break; } @@ -461,8 +397,9 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus) // Clear pad status memset(_pPADStatus, 0, sizeof(SPADStatus)); - // Update the pad status - GetJoyState(_numPAD); + // Check that Dolphin is in focus, otherwise don't update the pad status + if (!g_Config.bCheckFocus && IsFocus()) + GetJoyState(PadState[_numPAD], PadMapping[_numPAD], _numPAD, joyinfo[PadMapping[_numPAD].ID].NumButtons); // Get type int TriggerType = PadMapping[_numPAD].triggertype; @@ -472,12 +409,12 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus) // ----------- // Read axis values - int i_main_stick_x = PadState[_numPAD].axis[CTL_MAIN_X]; - int i_main_stick_y = -PadState[_numPAD].axis[CTL_MAIN_Y]; - int i_sub_stick_x = PadState[_numPAD].axis[CTL_SUB_X]; - int i_sub_stick_y = -PadState[_numPAD].axis[CTL_SUB_Y]; - int TriggerLeft = PadState[_numPAD].axis[CTL_L_SHOULDER]; - int TriggerRight = PadState[_numPAD].axis[CTL_R_SHOULDER]; + int i_main_stick_x = PadState[_numPAD].axis[InputCommon::CTL_MAIN_X]; + int i_main_stick_y = -PadState[_numPAD].axis[InputCommon::CTL_MAIN_Y]; + int i_sub_stick_x = PadState[_numPAD].axis[InputCommon::CTL_SUB_X]; + int i_sub_stick_y = -PadState[_numPAD].axis[InputCommon::CTL_SUB_Y]; + int TriggerLeft = PadState[_numPAD].axis[InputCommon::CTL_L_SHOULDER]; + int TriggerRight = PadState[_numPAD].axis[InputCommon::CTL_R_SHOULDER]; // Check if we should make adjustments if(PadMapping[_numPAD].bSquareToCircle) @@ -494,10 +431,10 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus) u8 sub_stick_y = Pad_Convert(i_sub_stick_y); // Convert the triggers values, if we are using analog triggers at all - if(PadMapping[_numPAD].triggertype == CTL_TRIGGER_SDL) + if(PadMapping[_numPAD].triggertype == InputCommon::CTL_TRIGGER_SDL) { - if(PadMapping[_numPAD].buttons[CTL_L_SHOULDER] >= 1000) TriggerLeft = Pad_Convert(TriggerLeft); - if(PadMapping[_numPAD].buttons[CTL_R_SHOULDER] >= 1000) TriggerRight = Pad_Convert(TriggerRight); + if(PadMapping[_numPAD].buttons[InputCommon::CTL_L_SHOULDER] >= 1000) TriggerLeft = Pad_Convert(TriggerLeft); + if(PadMapping[_numPAD].buttons[InputCommon::CTL_R_SHOULDER] >= 1000) TriggerRight = Pad_Convert(TriggerRight); } // Set Deadzones (perhaps out of function?) @@ -520,7 +457,7 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus) _pPADStatus->button |= PAD_USE_ORIGIN; // Neutral value, no button pressed // Check if the digital L button is pressed - if (PadState[_numPAD].buttons[CTL_L_SHOULDER]) + if (PadState[_numPAD].buttons[InputCommon::CTL_L_SHOULDER]) { _pPADStatus->button |= PAD_TRIGGER_L; _pPADStatus->triggerLeft = TriggerValue; @@ -529,7 +466,7 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus) _pPADStatus->triggerLeft = TriggerLeft; // Check if the digital R button is pressed - if (PadState[_numPAD].buttons[CTL_R_SHOULDER]) + if (PadState[_numPAD].buttons[InputCommon::CTL_R_SHOULDER]) { _pPADStatus->button |= PAD_TRIGGER_R; _pPADStatus->triggerRight = TriggerValue; @@ -545,26 +482,26 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus) /////////////////////////////////////////////////// // The digital buttons // ----------- - if (PadState[_numPAD].buttons[CTL_A_BUTTON]) + if (PadState[_numPAD].buttons[InputCommon::CTL_A_BUTTON]) { _pPADStatus->button |= PAD_BUTTON_A; _pPADStatus->analogA = 255; // Perhaps support pressure? } - if (PadState[_numPAD].buttons[CTL_B_BUTTON]) + if (PadState[_numPAD].buttons[InputCommon::CTL_B_BUTTON]) { _pPADStatus->button |= PAD_BUTTON_B; _pPADStatus->analogB = 255; // Perhaps support pressure? } - if (PadState[_numPAD].buttons[CTL_X_BUTTON]) _pPADStatus->button|=PAD_BUTTON_X; - if (PadState[_numPAD].buttons[CTL_Y_BUTTON]) _pPADStatus->button|=PAD_BUTTON_Y; - if (PadState[_numPAD].buttons[CTL_Z_TRIGGER]) _pPADStatus->button|=PAD_TRIGGER_Z; - if (PadState[_numPAD].buttons[CTL_START]) _pPADStatus->button|=PAD_BUTTON_START; + if (PadState[_numPAD].buttons[InputCommon::CTL_X_BUTTON]) _pPADStatus->button|=PAD_BUTTON_X; + if (PadState[_numPAD].buttons[InputCommon::CTL_Y_BUTTON]) _pPADStatus->button|=PAD_BUTTON_Y; + if (PadState[_numPAD].buttons[InputCommon::CTL_Z_TRIGGER]) _pPADStatus->button|=PAD_TRIGGER_Z; + if (PadState[_numPAD].buttons[InputCommon::CTL_START]) _pPADStatus->button|=PAD_BUTTON_START; /////////////////////////////////////////////////// // The D-pad // ----------- - if (PadMapping[_numPAD].controllertype == CTL_DPAD_HAT) + if (PadMapping[_numPAD].controllertype == InputCommon::CTL_DPAD_HAT) { if (PadState[_numPAD].dpad == SDL_HAT_LEFTUP || PadState[_numPAD].dpad == SDL_HAT_UP || PadState[_numPAD].dpad == SDL_HAT_RIGHTUP ) _pPADStatus->button|=PAD_BUTTON_UP; if (PadState[_numPAD].dpad == SDL_HAT_LEFTUP || PadState[_numPAD].dpad == SDL_HAT_LEFT || PadState[_numPAD].dpad == SDL_HAT_LEFTDOWN ) _pPADStatus->button|=PAD_BUTTON_LEFT; @@ -573,13 +510,13 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus) } else { - if (PadState[_numPAD].dpad2[CTL_D_PAD_UP]) + if (PadState[_numPAD].dpad2[InputCommon::CTL_D_PAD_UP]) _pPADStatus->button |= PAD_BUTTON_UP; - if (PadState[_numPAD].dpad2[CTL_D_PAD_DOWN]) + if (PadState[_numPAD].dpad2[InputCommon::CTL_D_PAD_DOWN]) _pPADStatus->button |= PAD_BUTTON_DOWN; - if (PadState[_numPAD].dpad2[CTL_D_PAD_LEFT]) + if (PadState[_numPAD].dpad2[InputCommon::CTL_D_PAD_LEFT]) _pPADStatus->button |= PAD_BUTTON_LEFT; - if (PadState[_numPAD].dpad2[CTL_D_PAD_RIGHT]) + if (PadState[_numPAD].dpad2[InputCommon::CTL_D_PAD_RIGHT]) _pPADStatus->button |= PAD_BUTTON_RIGHT; } @@ -757,114 +694,3 @@ std::vector<int> Pad_Square_to_Circle(int _x, int _y, int _pad) -////////////////////////////////////////////////////////////////////////////////////////// -// Supporting functions -// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ - -// Read current joystick status -/* ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ - The value PadMapping[].buttons[] is the number of the assigned joypad button, - PadState[].buttons[] is the status of the button, it becomes 0 (no pressed) or 1 (pressed) */ - - -// Read buttons status. Called from GetJoyState(). -// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ -void ReadButton(int controller, int button) -{ - int ctl_button = PadMapping[controller].buttons[button]; - if (ctl_button < joyinfo[PadMapping[controller].ID].NumButtons) - { - PadState[controller].buttons[button] = SDL_JoystickGetButton(PadState[controller].joy, ctl_button); - } -} - -// Request joystick state. -// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ -/* Called from: PAD_GetStatus() - Input: The virtual device 0, 1, 2 or 3 - Function: Updates the PadState struct with the current pad status. The input value "controller" is - for a virtual controller 0 to 3. */ -void GetJoyState(int controller) -{ - // Check that Dolphin is in focus, otherwise don't update the pad status - if (!g_Config.bCheckFocus && !IsFocus()) return; - - // Update the gamepad status - SDL_JoystickUpdate(); - - // Save the number of buttons - int Buttons = joyinfo[PadMapping[controller].ID].NumButtons; - - // Update axis states. It doesn't hurt much if we happen to ask for nonexisting axises here. - PadState[controller].axis[CTL_MAIN_X] = SDL_JoystickGetAxis(PadState[controller].joy, PadMapping[controller].axis[CTL_MAIN_X]); - PadState[controller].axis[CTL_MAIN_Y] = SDL_JoystickGetAxis(PadState[controller].joy, PadMapping[controller].axis[CTL_MAIN_Y]); - PadState[controller].axis[CTL_SUB_X] = SDL_JoystickGetAxis(PadState[controller].joy, PadMapping[controller].axis[CTL_SUB_X]); - PadState[controller].axis[CTL_SUB_Y] = SDL_JoystickGetAxis(PadState[controller].joy, PadMapping[controller].axis[CTL_SUB_Y]); - - // Update the analog trigger axis values -#ifdef _WIN32 - if (PadMapping[controller].triggertype == CTL_TRIGGER_SDL) - { -#endif - // If we are using SDL analog triggers the buttons have to be mapped as 1000 or up, otherwise they are not used - if(PadMapping[controller].buttons[CTL_L_SHOULDER] >= 1000) PadState[controller].axis[CTL_L_SHOULDER] = SDL_JoystickGetAxis(PadState[controller].joy, PadMapping[controller].buttons[CTL_L_SHOULDER] - 1000); else PadState[controller].axis[CTL_L_SHOULDER] = 0; - if(PadMapping[controller].buttons[CTL_R_SHOULDER] >= 1000) PadState[controller].axis[CTL_R_SHOULDER] = SDL_JoystickGetAxis(PadState[controller].joy, PadMapping[controller].buttons[CTL_R_SHOULDER] - 1000); else PadState[controller].axis[CTL_R_SHOULDER] = 0; -#ifdef _WIN32 - } - else - { - PadState[controller].axis[CTL_L_SHOULDER] = XInput::GetXI(0, PadMapping[controller].buttons[CTL_L_SHOULDER] - 1000); - PadState[controller].axis[CTL_R_SHOULDER] = XInput::GetXI(0, PadMapping[controller].buttons[CTL_R_SHOULDER] - 1000); - } -#endif - - // Update button states to on or off - ReadButton(controller, CTL_L_SHOULDER); - ReadButton(controller, CTL_R_SHOULDER); - ReadButton(controller, CTL_A_BUTTON); - ReadButton(controller, CTL_B_BUTTON); - ReadButton(controller, CTL_X_BUTTON); - ReadButton(controller, CTL_Y_BUTTON); - ReadButton(controller, CTL_Z_TRIGGER); - ReadButton(controller, CTL_START); - - // - if (PadMapping[controller].halfpress < joyinfo[controller].NumButtons) - PadState[controller].halfpress = SDL_JoystickGetButton(PadState[controller].joy, PadMapping[controller].halfpress); - - // Check if we have an analog or digital joypad - if (PadMapping[controller].controllertype == CTL_DPAD_HAT) - { - PadState[controller].dpad = SDL_JoystickGetHat(PadState[controller].joy, PadMapping[controller].dpad); - } - else - { - /* Only do this if the assigned button is in range (to allow for the current way of saving keyboard - keys in the same array) */ - if(PadMapping[controller].dpad2[CTL_D_PAD_UP] <= Buttons) - PadState[controller].dpad2[CTL_D_PAD_UP] = SDL_JoystickGetButton(PadState[controller].joy, PadMapping[controller].dpad2[CTL_D_PAD_UP]); - if(PadMapping[controller].dpad2[CTL_D_PAD_DOWN] <= Buttons) - PadState[controller].dpad2[CTL_D_PAD_DOWN] = SDL_JoystickGetButton(PadState[controller].joy, PadMapping[controller].dpad2[CTL_D_PAD_DOWN]); - if(PadMapping[controller].dpad2[CTL_D_PAD_LEFT] <= Buttons) - PadState[controller].dpad2[CTL_D_PAD_LEFT] = SDL_JoystickGetButton(PadState[controller].joy, PadMapping[controller].dpad2[CTL_D_PAD_LEFT]); - if(PadMapping[controller].dpad2[CTL_D_PAD_RIGHT] <= Buttons) - PadState[controller].dpad2[CTL_D_PAD_RIGHT] = SDL_JoystickGetButton(PadState[controller].joy, PadMapping[controller].dpad2[CTL_D_PAD_RIGHT]); - } - - /* Debugging - Console::ClearScreen(); - Console::Print( - "Controller and handle: %i %i\n" - - "Triggers:%i %i %i %i %i | HalfPress: %i Mapping: %i\n", - - controller, (int)PadState[controller].joy, - - PadMapping[controller].triggertype, - PadMapping[controller].buttons[CTL_L_SHOULDER], PadMapping[controller].buttons[CTL_R_SHOULDER], - PadState[controller].axis[CTL_L_SHOULDER], PadState[controller].axis[CTL_R_SHOULDER], - - PadState[controller].halfpress, PadMapping[controller].halfpress - ); */ -} -////////////////////////////////////////////////////////////////////////////////////////// diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.h b/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.h index 9295304e7e..556bfc6f28 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.h +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.h @@ -45,7 +45,9 @@ #include <cstdio> #include <ctime> #include <cmath> -#include <SDL.h> + +#include "../../../Core/InputCommon/Src/SDL.h" // Core +#include "../../../Core/InputCommon/Src/XInput.h" #include "Common.h" // Common #include "pluginspecs_pad.h" @@ -54,7 +56,6 @@ //#include "Timer.h" #include "Config.h" // Local -#include "XInput.h" #if defined(HAVE_WX) && HAVE_WX #include "GUI/AboutBox.h" @@ -103,115 +104,6 @@ ////////////////////////////////////////////////////////////////////////////////////////// -// Structures -/* ŻŻŻŻŻŻŻŻŻŻ - CONTROLLER_STATE buttons (PadState) = 0 or 1 - CONTROLLER_MAPPING buttons (joystick) = 0 or 1, 2, 3, 4, a certain joypad button - - Please remember: The axis limit is hardcoded here, if you allow more axises (for - example for analog A and B buttons) you must first incrase the size of the axis array - size here - */ -struct CONTROLLER_STATE // GC PAD INFO/STATE -{ - int buttons[8]; // Amount of buttons (A B X Y Z, L-Trigger R-Trigger Start) might need to change the triggers buttons - int dpad; // Automatic SDL D-Pad (8 directions + neutral) - int dpad2[4]; // D-pad using buttons - int axis[6]; // 2 x 2 Axes (Main & Sub) - int halfpress; // Halfpress... you know, like not fully pressed ;)... - SDL_Joystick *joy; // SDL joystick device -}; - -struct CONTROLLER_MAPPING // GC PAD MAPPING -{ - int buttons[8]; // (See above) - int dpad; // (See above) - int dpad2[4]; // (See above) - int axis[6]; // (See above) - int halfpress; // (See above) - int enabled; // Pad attached? - int deadzone; // Deadzone... what else? - int ID; // SDL joystick device ID - int controllertype; // Hat: Hat or custom buttons - int triggertype; // Triggers range - std::string SDiagonal; - bool bSquareToCircle; - int eventnum; // Linux Event Number, Can't be found dynamically yet -}; - -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; - SDL_Joystick *joy; // SDL joystick device -}; - -enum -{ - // CTL_L_SHOULDER and CTL_R_SHOULDER = 0 and 1 - CTL_MAIN_X = 2, - CTL_MAIN_Y, - CTL_SUB_X, - CTL_SUB_Y -}; - -enum -{ - CTL_L_SHOULDER = 0, - CTL_R_SHOULDER, - CTL_A_BUTTON, - CTL_B_BUTTON, - CTL_X_BUTTON, - CTL_Y_BUTTON, - CTL_Z_TRIGGER, - CTL_START -}; - -// DPad Type -enum -{ - CTL_DPAD_HAT = 0, // Automatically use the first hat that SDL finds - CTL_DPAD_CUSTOM // Custom directional pad settings -}; - -// Trigger Type -enum -{ - CTL_TRIGGER_SDL = 0, // - CTL_TRIGGER_XINPUT // The XBox 360 pad -}; - -enum -{ - CTL_D_PAD_UP = 0, - CTL_D_PAD_DOWN, - CTL_D_PAD_LEFT, - CTL_D_PAD_RIGHT -}; - -// Button type for the configuration -enum -{ - CTL_AXIS = 0, - CTL_HAT, - CTL_BUTTON, - CTL_KEY -}; - -// XInput buttons -enum -{ - XI_TRIGGER_L = 0, - XI_TRIGGER_R -}; - - -////////////////////////////////////////////////////////////////////////////////////////// // Input vector. Todo: Save the configured keys here instead of in joystick // ŻŻŻŻŻŻŻŻŻ /* @@ -225,11 +117,11 @@ extern std::vector<u8> Keys; ////////////////////////////////////////////////////////////////////////////////////////// // Variables // ŻŻŻŻŻŻŻŻŻ -#ifndef _CONTROLLER_STATE_H +#ifndef _EXCLUDE_MAIN_ extern FILE *pFile; - extern std::vector<CONTROLLER_INFO> joyinfo; - extern CONTROLLER_STATE PadState[4]; - extern CONTROLLER_MAPPING PadMapping[4]; + extern std::vector<InputCommon::CONTROLLER_INFO> joyinfo; + extern InputCommon::CONTROLLER_STATE PadState[4]; + extern InputCommon::CONTROLLER_MAPPING PadMapping[4]; extern HWND m_hWnd; // Handle to window extern int NumPads, NumGoodPads; // Number of goods pads #endif @@ -238,9 +130,7 @@ extern std::vector<u8> Keys; ////////////////////////////////////////////////////////////////////////////////////////// // Custom Functions // ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ - -void GetJoyState(int controller); -int Search_Devices(); +bool Search_Devices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads, int &_NumGoodPads); void DEBUG_INIT(); void DEBUG_QUIT(); bool IsFocus(); |
