mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-22 22:00:39 -06:00
Fix crazy svn changing trunk on last commit
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2206 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
@ -81,13 +81,13 @@
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
// 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];
|
||||
bool emulator_running = false;
|
||||
std::vector<InputCommon::CONTROLLER_INFO> joyinfo;
|
||||
InputCommon::CONTROLLER_STATE PadState[4];
|
||||
InputCommon::CONTROLLER_MAPPING PadMapping[4];
|
||||
bool g_EmulatorRunning = false;
|
||||
int NumPads = 0, NumGoodPads = 0;
|
||||
HWND m_hWnd; // Handle to window
|
||||
SPADInitialize *g_PADInitialize = NULL;
|
||||
@ -191,9 +191,9 @@ void DllConfig(HWND _hParent)
|
||||
|
||||
#ifdef _WIN32
|
||||
// Start the pads so we can use them in the configuration and advanced controls
|
||||
if(!emulator_running)
|
||||
if(!g_EmulatorRunning)
|
||||
{
|
||||
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);
|
||||
@ -232,7 +232,7 @@ void DllDebugger(HWND _hParent, bool Show) {}
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/* Information: This function can not be run twice without a Shutdown in between. If
|
||||
it's run twice the SDL_Init() will cause a crash. One solution to this is to keep a
|
||||
global function that remembers the SDL_Init() and SDL_Quit() (emulator_running does
|
||||
global function that remembers the SDL_Init() and SDL_Quit() (g_EmulatorRunning does
|
||||
not do that since we can open and close this without any game running). But I would
|
||||
suggest that avoiding to run this twice from the Core is better. */
|
||||
void Initialize(void *init)
|
||||
@ -241,7 +241,7 @@ void Initialize(void *init)
|
||||
//Console::Open();
|
||||
Console::Print("Initialize: %i\n", SDL_WasInit(0));
|
||||
g_PADInitialize = (SPADInitialize*)init;
|
||||
emulator_running = true;
|
||||
g_EmulatorRunning = true;
|
||||
|
||||
#ifdef _DEBUG
|
||||
DEBUG_INIT();
|
||||
@ -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.
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
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, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\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 && g_EmulatorRunning)
|
||||
{
|
||||
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)
|
||||
@ -372,18 +308,17 @@ void Shutdown()
|
||||
if(SDL_JoystickOpened(PadMapping[i].ID)) SDL_JoystickClose(PadState[i].joy);
|
||||
}
|
||||
|
||||
SDL_Quit();
|
||||
// Clear the physical device info
|
||||
joyinfo.clear();
|
||||
|
||||
// Finally close SDL
|
||||
if (SDL_WasInit(0)) SDL_Quit();
|
||||
|
||||
#ifdef _DEBUG
|
||||
DEBUG_QUIT();
|
||||
#endif
|
||||
|
||||
// Clear the physical device info
|
||||
//delete [] joyinfo;
|
||||
//joyinfo = NULL;
|
||||
joyinfo.clear();
|
||||
|
||||
emulator_running = false;
|
||||
g_EmulatorRunning = false;
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef USE_RUMBLE_DINPUT_HACK
|
||||
@ -405,13 +340,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 +396,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,32 +408,32 @@ 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)
|
||||
{
|
||||
std::vector<int> main_xy = Pad_Square_to_Circle(i_main_stick_x, i_main_stick_y, _numPAD);
|
||||
std::vector<int> main_xy = InputCommon::Pad_Square_to_Circle(i_main_stick_x, i_main_stick_y, _numPAD, PadMapping[_numPAD]);
|
||||
i_main_stick_x = main_xy.at(0);
|
||||
i_main_stick_y = main_xy.at(1);
|
||||
}
|
||||
|
||||
// Convert axis values
|
||||
u8 main_stick_x = Pad_Convert(i_main_stick_x);
|
||||
u8 main_stick_y = Pad_Convert(i_main_stick_y);
|
||||
u8 sub_stick_x = Pad_Convert(i_sub_stick_x);
|
||||
u8 sub_stick_y = Pad_Convert(i_sub_stick_y);
|
||||
u8 main_stick_x = InputCommon::Pad_Convert(i_main_stick_x);
|
||||
u8 main_stick_y = InputCommon::Pad_Convert(i_main_stick_y);
|
||||
u8 sub_stick_x = InputCommon::Pad_Convert(i_sub_stick_x);
|
||||
u8 sub_stick_y = InputCommon::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 = InputCommon::Pad_Convert(TriggerLeft);
|
||||
if(PadMapping[_numPAD].buttons[InputCommon::CTL_R_SHOULDER] >= 1000) TriggerRight = InputCommon::Pad_Convert(TriggerRight);
|
||||
}
|
||||
|
||||
// Set Deadzones (perhaps out of function?)
|
||||
@ -520,7 +456,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 +465,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 +481,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 +509,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;
|
||||
}
|
||||
|
||||
@ -645,226 +581,7 @@ bool IsFocus()
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Convert stick values
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
/* Convert stick values.
|
||||
|
||||
The value returned by SDL_JoystickGetAxis is a signed integer s16
|
||||
(-32768 to 32767). The value used for the gamecube controller is an unsigned
|
||||
char u8 (0 to 255) with neutral at 0x80 (128), so that it's equivalent to a signed
|
||||
-128 to 127.
|
||||
*/
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int Pad_Convert(int _val)
|
||||
{
|
||||
/* If the limits on PadState[].axis[] actually is a u16 then we don't need this
|
||||
but if it's not actually limited to that we need to apply these limits */
|
||||
if(_val > 32767) _val = 32767; // upper limit
|
||||
if(_val < -32768) _val = -32768; // lower limit
|
||||
|
||||
// Convert the range (-0x8000 to 0x7fff) to (0 to 0xffff)
|
||||
_val = 0x8000 +_val;
|
||||
|
||||
// Convert the range (-32768 to 32767) to (-128 to 127)
|
||||
_val = _val >> 8;
|
||||
|
||||
//Console::Print("0x%04x %06i\n\n", _val, _val);
|
||||
|
||||
return _val;
|
||||
}
|
||||
|
||||
|
||||
/* Convert the stick raidus from a circular to a square. I don't know what input values
|
||||
the actual GC controller produce for the GC, it may be a square, a circle or something
|
||||
in between. But one thing that is certain is that PC pads differ in their output (as
|
||||
shown in the list below), so it may be beneficiary to convert whatever radius they
|
||||
produce to the radius the GC games expect. This is the first implementation of this
|
||||
that convert a square radius to a circual radius. Use the advanced settings to enable
|
||||
and calibrate it.
|
||||
|
||||
Observed diagonals:
|
||||
Perfect circle: 71% = sin(45)
|
||||
Logitech Dual Action: 100%
|
||||
Dual Shock 2 (Original) with Super Dual Box Pro: 90%
|
||||
XBox 360 Wireless: 85%
|
||||
GameCube Controller (Third Party) with EMS TrioLinker Plus II: 60%
|
||||
*/
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
float SquareDistance(float deg)
|
||||
{
|
||||
// See if we have to adjust the angle
|
||||
deg = abs(deg);
|
||||
if( (deg > 45 && deg < 135) ) deg = deg - 90;
|
||||
|
||||
float rad = deg * M_PI / 180;
|
||||
|
||||
float val = abs(cos(rad));
|
||||
float dist = 1 / val; // Calculate distance from center
|
||||
|
||||
//m_frame->m_pStatusBar2->SetLabel(wxString::Format("Deg:%f Val:%f Dist:%f", deg, val, dist));
|
||||
|
||||
return dist;
|
||||
}
|
||||
std::vector<int> Pad_Square_to_Circle(int _x, int _y, int _pad)
|
||||
{
|
||||
/* Do we need this? */
|
||||
if(_x > 32767) _x = 32767; if(_y > 32767) _y = 32767; // upper limit
|
||||
if(_x < -32768) _x = -32768; if(_y > 32767) _y = 32767; // lower limit
|
||||
|
||||
// ====================================
|
||||
// Convert to circle
|
||||
// -----------
|
||||
int Tmp = atoi (PadMapping[_pad].SDiagonal.substr(0, PadMapping[_pad].SDiagonal.length() - 1).c_str());
|
||||
float Diagonal = Tmp / 100.0;
|
||||
|
||||
// First make a perfect square in case we don't have one already
|
||||
float OrigDist = sqrt( pow((float)_y, 2) + pow((float)_x, 2) ); // Get current distance
|
||||
float rad = atan2((float)_y, (float)_x); // Get current angle
|
||||
float deg = rad * 180 / M_PI;
|
||||
|
||||
// A diagonal of 85% means a distance of 1.20
|
||||
float corner_circle_dist = ( Diagonal / sin(45 * M_PI / 180) );
|
||||
float SquareDist = SquareDistance(deg);
|
||||
float adj_ratio1; // The original-to-square distance adjustment
|
||||
float adj_ratio2 = SquareDist; // The circle-to-square distance adjustment
|
||||
// float final_ratio; // The final adjustment to the current distance //TODO: This is not used
|
||||
float result_dist; // The resulting distance
|
||||
|
||||
// Calculate the corner-to-square adjustment ratio
|
||||
if(corner_circle_dist < SquareDist) adj_ratio1 = SquareDist / corner_circle_dist;
|
||||
else adj_ratio1 = 1;
|
||||
|
||||
// Calculate the resulting distance
|
||||
result_dist = OrigDist * adj_ratio1 / adj_ratio2;
|
||||
|
||||
float x = result_dist * cos(rad); // calculate x
|
||||
float y = result_dist * sin(rad); // calculate y
|
||||
|
||||
int int_x = (int)floor(x);
|
||||
int int_y = (int)floor(y);
|
||||
|
||||
// Debugging
|
||||
//m_frame->m_pStatusBar2->SetLabel(wxString::Format("%f %f %i", corner_circle_dist, Diagonal, Tmp));
|
||||
|
||||
std::vector<int> vec;
|
||||
vec.push_back(int_x);
|
||||
vec.push_back(int_y);
|
||||
return vec;
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////// Convert stick values
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Supporting functions
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
// Read current joystick status
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
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().
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
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.
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/* 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
|
||||
); */
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
Reference in New Issue
Block a user