Some fixes to nJoy. No more trying to read non-existing buttons (dunno about axes, but i got warnings about the buttons),
Also some code standard cleanup. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1488 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
6384f9b420
commit
ff776ce7cf
|
@ -61,7 +61,7 @@ DWORD g_dwNumForceFeedbackAxis = 0;
|
||||||
INT g_nXForce = 0;
|
INT g_nXForce = 0;
|
||||||
INT g_nYForce = 0;
|
INT g_nYForce = 0;
|
||||||
|
|
||||||
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
|
#define SAFE_RELEASE(p) { if (p) { (p)->Release(); (p)=NULL; } }
|
||||||
|
|
||||||
HRESULT InitDirectInput(HWND hDlg);
|
HRESULT InitDirectInput(HWND hDlg);
|
||||||
VOID FreeDirectInput();
|
VOID FreeDirectInput();
|
||||||
|
@ -109,7 +109,7 @@ BOOL APIENTRY DllMain( HINSTANCE hinstDLL, // DLL module handle
|
||||||
char **argv = NULL;
|
char **argv = NULL;
|
||||||
wxEntryStart(argc, argv);
|
wxEntryStart(argc, argv);
|
||||||
|
|
||||||
if ( !wxTheApp || !wxTheApp->CallOnInit() )
|
if (!wxTheApp || !wxTheApp->CallOnInit() )
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -154,7 +154,7 @@ void GetDllInfo(PLUGIN_INFO* _PluginInfo)
|
||||||
void DllConfig(HWND _hParent)
|
void DllConfig(HWND _hParent)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if(SDL_Init(SDL_INIT_JOYSTICK ) < 0)
|
if (SDL_Init(SDL_INIT_JOYSTICK ) < 0)
|
||||||
{
|
{
|
||||||
MessageBox(NULL, SDL_GetError(), "Could not initialize SDL!", MB_ICONERROR);
|
MessageBox(NULL, SDL_GetError(), "Could not initialize SDL!", MB_ICONERROR);
|
||||||
return;
|
return;
|
||||||
|
@ -169,7 +169,7 @@ void DllConfig(HWND _hParent)
|
||||||
win.SetHWND(0);
|
win.SetHWND(0);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
if(SDL_Init(SDL_INIT_JOYSTICK ) < 0)
|
if (SDL_Init(SDL_INIT_JOYSTICK ) < 0)
|
||||||
{
|
{
|
||||||
printf("Could not initialize SDL! (%s)\n", SDL_GetError());
|
printf("Could not initialize SDL! (%s)\n", SDL_GetError());
|
||||||
return;
|
return;
|
||||||
|
@ -191,7 +191,7 @@ void PAD_Initialize(SPADInitialize _PADInitialize)
|
||||||
DEBUG_INIT();
|
DEBUG_INIT();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(SDL_Init(SDL_INIT_JOYSTICK ) < 0)
|
if (SDL_Init(SDL_INIT_JOYSTICK ) < 0)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
MessageBox(NULL, SDL_GetError(), "Could not initialize SDL!", MB_ICONERROR);
|
MessageBox(NULL, SDL_GetError(), "Could not initialize SDL!", MB_ICONERROR);
|
||||||
|
@ -207,13 +207,13 @@ void PAD_Initialize(SPADInitialize _PADInitialize)
|
||||||
|
|
||||||
LoadConfig(); // Load joystick mapping
|
LoadConfig(); // Load joystick mapping
|
||||||
|
|
||||||
if(joysticks[0].enabled)
|
if (joysticks[0].enabled)
|
||||||
joystate[0].joy = SDL_JoystickOpen(joysticks[0].ID);
|
joystate[0].joy = SDL_JoystickOpen(joysticks[0].ID);
|
||||||
if(joysticks[1].enabled)
|
if (joysticks[1].enabled)
|
||||||
joystate[1].joy = SDL_JoystickOpen(joysticks[1].ID);
|
joystate[1].joy = SDL_JoystickOpen(joysticks[1].ID);
|
||||||
if(joysticks[2].enabled)
|
if (joysticks[2].enabled)
|
||||||
joystate[2].joy = SDL_JoystickOpen(joysticks[2].ID);
|
joystate[2].joy = SDL_JoystickOpen(joysticks[2].ID);
|
||||||
if(joysticks[3].enabled)
|
if (joysticks[3].enabled)
|
||||||
joystate[3].joy = SDL_JoystickOpen(joysticks[3].ID);
|
joystate[3].joy = SDL_JoystickOpen(joysticks[3].ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,13 +221,13 @@ void PAD_Initialize(SPADInitialize _PADInitialize)
|
||||||
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
||||||
void PAD_Shutdown()
|
void PAD_Shutdown()
|
||||||
{
|
{
|
||||||
if(joysticks[0].enabled)
|
if (joysticks[0].enabled)
|
||||||
SDL_JoystickClose(joystate[0].joy);
|
SDL_JoystickClose(joystate[0].joy);
|
||||||
if(joysticks[1].enabled)
|
if (joysticks[1].enabled)
|
||||||
SDL_JoystickClose(joystate[1].joy);
|
SDL_JoystickClose(joystate[1].joy);
|
||||||
if(joysticks[2].enabled)
|
if (joysticks[2].enabled)
|
||||||
SDL_JoystickClose(joystate[2].joy);
|
SDL_JoystickClose(joystate[2].joy);
|
||||||
if(joysticks[3].enabled)
|
if (joysticks[3].enabled)
|
||||||
SDL_JoystickClose(joystate[3].joy);
|
SDL_JoystickClose(joystate[3].joy);
|
||||||
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
@ -253,7 +253,7 @@ void PAD_Shutdown()
|
||||||
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
||||||
void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
|
void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
|
||||||
{
|
{
|
||||||
if(!joysticks[_numPAD].enabled)
|
if (!joysticks[_numPAD].enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// clear pad status
|
// clear pad status
|
||||||
|
@ -284,22 +284,22 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
|
||||||
int sub_stick_y = -(joystate[_numPAD].axis[CTL_SUB_Y]>>8);
|
int sub_stick_y = -(joystate[_numPAD].axis[CTL_SUB_Y]>>8);
|
||||||
|
|
||||||
// Quick fix
|
// Quick fix
|
||||||
if(main_stick_x > 127)
|
if (main_stick_x > 127)
|
||||||
main_stick_x = 127;
|
main_stick_x = 127;
|
||||||
if(main_stick_y > 127)
|
if (main_stick_y > 127)
|
||||||
main_stick_y = 127;
|
main_stick_y = 127;
|
||||||
if(sub_stick_x > 127)
|
if (sub_stick_x > 127)
|
||||||
sub_stick_x = 127;
|
sub_stick_x = 127;
|
||||||
if(sub_stick_y > 127)
|
if (sub_stick_y > 127)
|
||||||
sub_stick_y = 127;
|
sub_stick_y = 127;
|
||||||
|
|
||||||
if(main_stick_x < -128)
|
if (main_stick_x < -128)
|
||||||
main_stick_x = -128;
|
main_stick_x = -128;
|
||||||
if(main_stick_y < -128)
|
if (main_stick_y < -128)
|
||||||
main_stick_y = -128;
|
main_stick_y = -128;
|
||||||
if(sub_stick_x < -128)
|
if (sub_stick_x < -128)
|
||||||
sub_stick_x = -128;
|
sub_stick_x = -128;
|
||||||
if(sub_stick_y < -128)
|
if (sub_stick_y < -128)
|
||||||
sub_stick_y = -128;
|
sub_stick_y = -128;
|
||||||
|
|
||||||
// Send values to Dolpin
|
// Send values to Dolpin
|
||||||
|
@ -340,22 +340,22 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
|
||||||
if (joystate[_numPAD].buttons[CTL_START]) _pPADStatus->button|=PAD_BUTTON_START;
|
if (joystate[_numPAD].buttons[CTL_START]) _pPADStatus->button|=PAD_BUTTON_START;
|
||||||
|
|
||||||
// Set D-pad
|
// Set D-pad
|
||||||
if(joysticks[_numPAD].controllertype == CTL_TYPE_JOYSTICK)
|
if (joysticks[_numPAD].controllertype == CTL_TYPE_JOYSTICK)
|
||||||
{
|
{
|
||||||
if(joystate[_numPAD].dpad == SDL_HAT_LEFTUP || joystate[_numPAD].dpad == SDL_HAT_UP || joystate[_numPAD].dpad == SDL_HAT_RIGHTUP ) _pPADStatus->button|=PAD_BUTTON_UP;
|
if (joystate[_numPAD].dpad == SDL_HAT_LEFTUP || joystate[_numPAD].dpad == SDL_HAT_UP || joystate[_numPAD].dpad == SDL_HAT_RIGHTUP ) _pPADStatus->button|=PAD_BUTTON_UP;
|
||||||
if(joystate[_numPAD].dpad == SDL_HAT_LEFTUP || joystate[_numPAD].dpad == SDL_HAT_LEFT || joystate[_numPAD].dpad == SDL_HAT_LEFTDOWN ) _pPADStatus->button|=PAD_BUTTON_LEFT;
|
if (joystate[_numPAD].dpad == SDL_HAT_LEFTUP || joystate[_numPAD].dpad == SDL_HAT_LEFT || joystate[_numPAD].dpad == SDL_HAT_LEFTDOWN ) _pPADStatus->button|=PAD_BUTTON_LEFT;
|
||||||
if(joystate[_numPAD].dpad == SDL_HAT_LEFTDOWN || joystate[_numPAD].dpad == SDL_HAT_DOWN || joystate[_numPAD].dpad == SDL_HAT_RIGHTDOWN ) _pPADStatus->button|=PAD_BUTTON_DOWN;
|
if (joystate[_numPAD].dpad == SDL_HAT_LEFTDOWN || joystate[_numPAD].dpad == SDL_HAT_DOWN || joystate[_numPAD].dpad == SDL_HAT_RIGHTDOWN ) _pPADStatus->button|=PAD_BUTTON_DOWN;
|
||||||
if(joystate[_numPAD].dpad == SDL_HAT_RIGHTUP || joystate[_numPAD].dpad == SDL_HAT_RIGHT || joystate[_numPAD].dpad == SDL_HAT_RIGHTDOWN ) _pPADStatus->button|=PAD_BUTTON_RIGHT;
|
if (joystate[_numPAD].dpad == SDL_HAT_RIGHTUP || joystate[_numPAD].dpad == SDL_HAT_RIGHT || joystate[_numPAD].dpad == SDL_HAT_RIGHTDOWN ) _pPADStatus->button|=PAD_BUTTON_RIGHT;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(joystate[_numPAD].dpad2[CTL_D_PAD_UP])
|
if (joystate[_numPAD].dpad2[CTL_D_PAD_UP])
|
||||||
_pPADStatus->button|=PAD_BUTTON_UP;
|
_pPADStatus->button|=PAD_BUTTON_UP;
|
||||||
if(joystate[_numPAD].dpad2[CTL_D_PAD_DOWN])
|
if (joystate[_numPAD].dpad2[CTL_D_PAD_DOWN])
|
||||||
_pPADStatus->button|=PAD_BUTTON_DOWN;
|
_pPADStatus->button|=PAD_BUTTON_DOWN;
|
||||||
if(joystate[_numPAD].dpad2[CTL_D_PAD_LEFT])
|
if (joystate[_numPAD].dpad2[CTL_D_PAD_LEFT])
|
||||||
_pPADStatus->button|=PAD_BUTTON_LEFT;
|
_pPADStatus->button|=PAD_BUTTON_LEFT;
|
||||||
if(joystate[_numPAD].dpad2[CTL_D_PAD_RIGHT])
|
if (joystate[_numPAD].dpad2[CTL_D_PAD_RIGHT])
|
||||||
_pPADStatus->button|=PAD_BUTTON_RIGHT;
|
_pPADStatus->button|=PAD_BUTTON_RIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,9 +364,9 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#ifdef USE_RUMBLE_DINPUT_HACK
|
#ifdef USE_RUMBLE_DINPUT_HACK
|
||||||
if(joystate[_numPAD].halfpress)
|
if (joystate[_numPAD].halfpress)
|
||||||
if(!g_pDI)
|
if (!g_pDI)
|
||||||
if(FAILED(InitDirectInput(m_hWnd)))
|
if (FAILED(InitDirectInput(m_hWnd)))
|
||||||
{
|
{
|
||||||
MessageBox(NULL, SDL_GetError(), "Could not initialize DirectInput!", MB_ICONERROR);
|
MessageBox(NULL, SDL_GetError(), "Could not initialize DirectInput!", MB_ICONERROR);
|
||||||
g_rumbleEnable = FALSE;
|
g_rumbleEnable = FALSE;
|
||||||
|
@ -379,12 +379,12 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
|
||||||
{
|
{
|
||||||
g_pDevice->Acquire();
|
g_pDevice->Acquire();
|
||||||
|
|
||||||
if(g_pEffect)
|
if (g_pEffect)
|
||||||
g_pEffect->Start(1, 0);
|
g_pEffect->Start(1, 0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
if(!fd)
|
if (!fd)
|
||||||
{
|
{
|
||||||
sprintf(device_file_name, "/dev/input/event%d", joysticks[_numPAD].eventnum); //TODO: Make dynamic //
|
sprintf(device_file_name, "/dev/input/event%d", joysticks[_numPAD].eventnum); //TODO: Make dynamic //
|
||||||
|
|
||||||
|
@ -399,7 +399,7 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
|
||||||
if (ioctl(fd, EVIOCGEFFECTS, &n_effects) == -1) {
|
if (ioctl(fd, EVIOCGEFFECTS, &n_effects) == -1) {
|
||||||
perror("Ioctl number of effects");
|
perror("Ioctl number of effects");
|
||||||
}
|
}
|
||||||
if(n_effects > 0)
|
if (n_effects > 0)
|
||||||
CanRumble = true;
|
CanRumble = true;
|
||||||
else
|
else
|
||||||
return; // Return since we can't do any effects
|
return; // Return since we can't do any effects
|
||||||
|
@ -423,7 +423,7 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
|
||||||
// (Stop=0, Rumble=1)
|
// (Stop=0, Rumble=1)
|
||||||
void PAD_Rumble(u8 _numPAD, unsigned int _uType, unsigned int _uStrength)
|
void PAD_Rumble(u8 _numPAD, unsigned int _uType, unsigned int _uStrength)
|
||||||
{
|
{
|
||||||
//if(_numPAD > 0)
|
//if (_numPAD > 0)
|
||||||
// return;
|
// return;
|
||||||
|
|
||||||
// not supported by SDL
|
// not supported by SDL
|
||||||
|
@ -455,7 +455,7 @@ void PAD_Rumble(u8 _numPAD, unsigned int _uType, unsigned int _uStrength)
|
||||||
#endif
|
#endif
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
struct input_event event;
|
struct input_event event;
|
||||||
if(CanRumble)
|
if (CanRumble)
|
||||||
{
|
{
|
||||||
if (_uType == 1)
|
if (_uType == 1)
|
||||||
{
|
{
|
||||||
|
@ -489,13 +489,13 @@ unsigned int PAD_GetAttachedPads()
|
||||||
|
|
||||||
LoadConfig();
|
LoadConfig();
|
||||||
|
|
||||||
if(joysticks[0].enabled)
|
if (joysticks[0].enabled)
|
||||||
connected |= 1;
|
connected |= 1;
|
||||||
if(joysticks[1].enabled)
|
if (joysticks[1].enabled)
|
||||||
connected |= 2;
|
connected |= 2;
|
||||||
if(joysticks[2].enabled)
|
if (joysticks[2].enabled)
|
||||||
connected |= 4;
|
connected |= 4;
|
||||||
if(joysticks[3].enabled)
|
if (joysticks[3].enabled)
|
||||||
connected |= 8;
|
connected |= 8;
|
||||||
|
|
||||||
return connected;
|
return connected;
|
||||||
|
@ -513,6 +513,13 @@ unsigned int SaveLoadState(char *ptr, BOOL save)
|
||||||
// Custom Functions
|
// Custom Functions
|
||||||
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
||||||
|
|
||||||
|
void ReadButton(int controller, int button) {
|
||||||
|
int ctl_button = joysticks[controller].buttons[button];
|
||||||
|
if (ctl_button < joyinfo[controller].NumButtons) {
|
||||||
|
joystate[controller].buttons[button] = SDL_JoystickGetButton(joystate[controller].joy, ctl_button);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Request joystick state
|
// Request joystick state
|
||||||
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
||||||
void GetJoyState(int controller)
|
void GetJoyState(int controller)
|
||||||
|
@ -524,19 +531,22 @@ void GetJoyState(int controller)
|
||||||
joystate[controller].axis[CTL_SUB_X] = SDL_JoystickGetAxis(joystate[controller].joy, joysticks[controller].axis[CTL_SUB_X]);
|
joystate[controller].axis[CTL_SUB_X] = SDL_JoystickGetAxis(joystate[controller].joy, joysticks[controller].axis[CTL_SUB_X]);
|
||||||
joystate[controller].axis[CTL_SUB_Y] = SDL_JoystickGetAxis(joystate[controller].joy, joysticks[controller].axis[CTL_SUB_Y]);
|
joystate[controller].axis[CTL_SUB_Y] = SDL_JoystickGetAxis(joystate[controller].joy, joysticks[controller].axis[CTL_SUB_Y]);
|
||||||
|
|
||||||
joystate[controller].buttons[CTL_L_SHOULDER] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].buttons[CTL_L_SHOULDER]);
|
ReadButton(controller, CTL_L_SHOULDER);
|
||||||
joystate[controller].buttons[CTL_R_SHOULDER] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].buttons[CTL_R_SHOULDER]);
|
ReadButton(controller, CTL_R_SHOULDER);
|
||||||
joystate[controller].buttons[CTL_A_BUTTON] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].buttons[CTL_A_BUTTON]);
|
ReadButton(controller, CTL_A_BUTTON);
|
||||||
joystate[controller].buttons[CTL_B_BUTTON] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].buttons[CTL_B_BUTTON]);
|
ReadButton(controller, CTL_B_BUTTON);
|
||||||
joystate[controller].buttons[CTL_X_BUTTON] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].buttons[CTL_X_BUTTON]);
|
ReadButton(controller, CTL_X_BUTTON);
|
||||||
joystate[controller].buttons[CTL_Y_BUTTON] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].buttons[CTL_Y_BUTTON]);
|
ReadButton(controller, CTL_Y_BUTTON);
|
||||||
joystate[controller].buttons[CTL_Z_TRIGGER] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].buttons[CTL_Z_TRIGGER]);
|
ReadButton(controller, CTL_Z_TRIGGER);
|
||||||
joystate[controller].buttons[CTL_START] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].buttons[CTL_START]);
|
ReadButton(controller, CTL_START);
|
||||||
|
|
||||||
joystate[controller].halfpress = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].halfpress);
|
if (joysticks[controller].halfpress < joyinfo[controller].NumButtons)
|
||||||
|
joystate[controller].halfpress = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].halfpress);
|
||||||
|
|
||||||
if(joysticks[controller].controllertype == CTL_TYPE_JOYSTICK)
|
if (joysticks[controller].controllertype == CTL_TYPE_JOYSTICK)
|
||||||
|
{
|
||||||
joystate[controller].dpad = SDL_JoystickGetHat(joystate[controller].joy, joysticks[controller].dpad);
|
joystate[controller].dpad = SDL_JoystickGetHat(joystate[controller].joy, joysticks[controller].dpad);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
joystate[controller].dpad2[CTL_D_PAD_UP] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].dpad2[CTL_D_PAD_UP]);
|
joystate[controller].dpad2[CTL_D_PAD_UP] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].dpad2[CTL_D_PAD_UP]);
|
||||||
|
@ -557,7 +567,7 @@ int Search_Devices()
|
||||||
|
|
||||||
int numjoy = SDL_NumJoysticks();
|
int numjoy = SDL_NumJoysticks();
|
||||||
|
|
||||||
if(numjoy == 0)
|
if (numjoy == 0)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
MessageBox(NULL, "No Joystick detected!", NULL, MB_ICONWARNING);
|
MessageBox(NULL, "No Joystick detected!", NULL, MB_ICONWARNING);
|
||||||
|
@ -567,7 +577,7 @@ int Search_Devices()
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(joyinfo)
|
if (joyinfo)
|
||||||
{
|
{
|
||||||
delete [] joyinfo;
|
delete [] joyinfo;
|
||||||
joyinfo = new CONTROLLER_INFO [numjoy];
|
joyinfo = new CONTROLLER_INFO [numjoy];
|
||||||
|
@ -602,7 +612,7 @@ int Search_Devices()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Close if opened
|
// Close if opened
|
||||||
if(SDL_JoystickOpened(i))
|
if (SDL_JoystickOpened(i))
|
||||||
SDL_JoystickClose(joyinfo[i].joy);
|
SDL_JoystickClose(joyinfo[i].joy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -613,7 +623,7 @@ int Search_Devices()
|
||||||
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
||||||
void DEBUG_INIT()
|
void DEBUG_INIT()
|
||||||
{
|
{
|
||||||
if(pFile)
|
if (pFile)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -635,7 +645,7 @@ void DEBUG_INIT()
|
||||||
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
|
||||||
void DEBUG_QUIT()
|
void DEBUG_QUIT()
|
||||||
{
|
{
|
||||||
if(!pFile)
|
if (!pFile)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -655,7 +665,7 @@ void SaveConfig()
|
||||||
IniFile file;
|
IniFile file;
|
||||||
file.Load("nJoy.ini");
|
file.Load("nJoy.ini");
|
||||||
|
|
||||||
for (int i=0; i<4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
char SectionName[32];
|
char SectionName[32];
|
||||||
sprintf(SectionName, "PAD%i", i+1);
|
sprintf(SectionName, "PAD%i", i+1);
|
||||||
|
@ -695,7 +705,7 @@ void LoadConfig()
|
||||||
IniFile file;
|
IniFile file;
|
||||||
file.Load("nJoy.ini");
|
file.Load("nJoy.ini");
|
||||||
|
|
||||||
for (int i=0; i<4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
char SectionName[32];
|
char SectionName[32];
|
||||||
sprintf(SectionName, "PAD%i", i+1);
|
sprintf(SectionName, "PAD%i", i+1);
|
||||||
|
@ -739,18 +749,18 @@ HRESULT InitDirectInput( HWND hDlg )
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
|
||||||
// Register with the DirectInput subsystem and get a pointer to a IDirectInput interface we can use.
|
// Register with the DirectInput subsystem and get a pointer to a IDirectInput interface we can use.
|
||||||
if(FAILED(hr = DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&g_pDI, NULL)))
|
if (FAILED(hr = DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&g_pDI, NULL)))
|
||||||
{
|
{
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look for a force feedback device we can use
|
// Look for a force feedback device we can use
|
||||||
if(FAILED(hr = g_pDI->EnumDevices( DI8DEVCLASS_GAMECTRL, EnumFFDevicesCallback, NULL, DIEDFL_ATTACHEDONLY | DIEDFL_FORCEFEEDBACK)))
|
if (FAILED(hr = g_pDI->EnumDevices( DI8DEVCLASS_GAMECTRL, EnumFFDevicesCallback, NULL, DIEDFL_ATTACHEDONLY | DIEDFL_FORCEFEEDBACK)))
|
||||||
{
|
{
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NULL == g_pDevice)
|
if (NULL == g_pDevice)
|
||||||
{
|
{
|
||||||
MessageBox(NULL, "Force feedback device not found. nJoy will now disable rumble." ,"FFConst" , MB_ICONERROR | MB_OK);
|
MessageBox(NULL, "Force feedback device not found. nJoy will now disable rumble." ,"FFConst" , MB_ICONERROR | MB_OK);
|
||||||
g_rumbleEnable = FALSE;
|
g_rumbleEnable = FALSE;
|
||||||
|
@ -766,15 +776,15 @@ HRESULT InitDirectInput( HWND hDlg )
|
||||||
// IDirectInputDevice8::GetDeviceState(). Even though we won't actually do
|
// IDirectInputDevice8::GetDeviceState(). Even though we won't actually do
|
||||||
// it in this sample. But setting the data format is important so that the
|
// it in this sample. But setting the data format is important so that the
|
||||||
// DIJOFS_* values work properly.
|
// DIJOFS_* values work properly.
|
||||||
if(FAILED(hr = g_pDevice->SetDataFormat(&c_dfDIJoystick)))
|
if (FAILED(hr = g_pDevice->SetDataFormat(&c_dfDIJoystick)))
|
||||||
return hr;
|
return hr;
|
||||||
|
|
||||||
// Set the cooperative level to let DInput know how this device should
|
// Set the cooperative level to let DInput know how this device should
|
||||||
// interact with the system and with other DInput applications.
|
// interact with the system and with other DInput applications.
|
||||||
// Exclusive access is required in order to perform force feedback.
|
// Exclusive access is required in order to perform force feedback.
|
||||||
//if(FAILED(hr = g_pDevice->SetCooperativeLevel(hDlg, DISCL_EXCLUSIVE | DISCL_FOREGROUND)))
|
//if (FAILED(hr = g_pDevice->SetCooperativeLevel(hDlg, DISCL_EXCLUSIVE | DISCL_FOREGROUND)))
|
||||||
|
|
||||||
if(FAILED(hr = g_pDevice->SetCooperativeLevel(hDlg, DISCL_EXCLUSIVE | DISCL_FOREGROUND)))
|
if (FAILED(hr = g_pDevice->SetCooperativeLevel(hDlg, DISCL_EXCLUSIVE | DISCL_FOREGROUND)))
|
||||||
{
|
{
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
@ -787,15 +797,15 @@ HRESULT InitDirectInput( HWND hDlg )
|
||||||
dipdw.diph.dwHow = DIPH_DEVICE;
|
dipdw.diph.dwHow = DIPH_DEVICE;
|
||||||
dipdw.dwData = FALSE;
|
dipdw.dwData = FALSE;
|
||||||
|
|
||||||
if(FAILED(hr = g_pDevice->SetProperty(DIPROP_AUTOCENTER, &dipdw.diph)))
|
if (FAILED(hr = g_pDevice->SetProperty(DIPROP_AUTOCENTER, &dipdw.diph)))
|
||||||
return hr;
|
return hr;
|
||||||
|
|
||||||
// Enumerate and count the axes of the joystick
|
// Enumerate and count the axes of the joystick
|
||||||
if(FAILED(hr = g_pDevice->EnumObjects(EnumAxesCallback, (VOID*)&g_dwNumForceFeedbackAxis, DIDFT_AXIS)))
|
if (FAILED(hr = g_pDevice->EnumObjects(EnumAxesCallback, (VOID*)&g_dwNumForceFeedbackAxis, DIDFT_AXIS)))
|
||||||
return hr;
|
return hr;
|
||||||
|
|
||||||
// This simple sample only supports one or two axis joysticks
|
// This simple sample only supports one or two axis joysticks
|
||||||
if(g_dwNumForceFeedbackAxis > 2)
|
if (g_dwNumForceFeedbackAxis > 2)
|
||||||
g_dwNumForceFeedbackAxis = 2;
|
g_dwNumForceFeedbackAxis = 2;
|
||||||
|
|
||||||
// This application needs only one effect: Applying raw forces.
|
// This application needs only one effect: Applying raw forces.
|
||||||
|
@ -821,12 +831,12 @@ HRESULT InitDirectInput( HWND hDlg )
|
||||||
eff.dwStartDelay = 0;
|
eff.dwStartDelay = 0;
|
||||||
|
|
||||||
// Create the prepared effect
|
// Create the prepared effect
|
||||||
if(FAILED(hr = g_pDevice->CreateEffect(GUID_ConstantForce, &eff, &g_pEffect, NULL)))
|
if (FAILED(hr = g_pDevice->CreateEffect(GUID_ConstantForce, &eff, &g_pEffect, NULL)))
|
||||||
{
|
{
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NULL == g_pEffect)
|
if (NULL == g_pEffect)
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
|
@ -836,7 +846,7 @@ VOID FreeDirectInput()
|
||||||
{
|
{
|
||||||
// Unacquire the device one last time just in case
|
// Unacquire the device one last time just in case
|
||||||
// the app tried to exit while the device is still acquired.
|
// the app tried to exit while the device is still acquired.
|
||||||
if(g_pDevice)
|
if (g_pDevice)
|
||||||
g_pDevice->Unacquire();
|
g_pDevice->Unacquire();
|
||||||
|
|
||||||
// Release any DirectInput objects.
|
// Release any DirectInput objects.
|
||||||
|
@ -855,7 +865,7 @@ BOOL CALLBACK EnumFFDevicesCallback( const DIDEVICEINSTANCE* pInst, VOID* pConte
|
||||||
|
|
||||||
// If it failed, then we can't use this device for some bizarre reason.
|
// If it failed, then we can't use this device for some bizarre reason.
|
||||||
// (Maybe the user unplugged it while we were in the middle of enumerating it.) So continue enumerating
|
// (Maybe the user unplugged it while we were in the middle of enumerating it.) So continue enumerating
|
||||||
if( FAILED(hr))
|
if (FAILED(hr))
|
||||||
return DIENUM_CONTINUE;
|
return DIENUM_CONTINUE;
|
||||||
|
|
||||||
// We successfully created an IDirectInputDevice8. So stop looking for another one.
|
// We successfully created an IDirectInputDevice8. So stop looking for another one.
|
||||||
|
@ -867,7 +877,7 @@ BOOL CALLBACK EnumFFDevicesCallback( const DIDEVICEINSTANCE* pInst, VOID* pConte
|
||||||
BOOL CALLBACK EnumAxesCallback(const DIDEVICEOBJECTINSTANCE* pdidoi, VOID* pContext)
|
BOOL CALLBACK EnumAxesCallback(const DIDEVICEOBJECTINSTANCE* pdidoi, VOID* pContext)
|
||||||
{
|
{
|
||||||
DWORD* pdwNumForceFeedbackAxis = (DWORD*)pContext;
|
DWORD* pdwNumForceFeedbackAxis = (DWORD*)pContext;
|
||||||
if((pdidoi->dwFlags & DIDOI_FFACTUATOR) != 0)
|
if ((pdidoi->dwFlags & DIDOI_FFACTUATOR) != 0)
|
||||||
(*pdwNumForceFeedbackAxis)++;
|
(*pdwNumForceFeedbackAxis)++;
|
||||||
|
|
||||||
return DIENUM_CONTINUE;
|
return DIENUM_CONTINUE;
|
||||||
|
@ -880,7 +890,7 @@ HRESULT SetDeviceForcesXY()
|
||||||
|
|
||||||
DICONSTANTFORCE cf;
|
DICONSTANTFORCE cf;
|
||||||
|
|
||||||
if( g_dwNumForceFeedbackAxis == 1 )
|
if (g_dwNumForceFeedbackAxis == 1)
|
||||||
{
|
{
|
||||||
// If only one force feedback axis, then apply only one direction and keep the direction at zero
|
// If only one force feedback axis, then apply only one direction and keep the direction at zero
|
||||||
cf.lMagnitude = g_nXForce;
|
cf.lMagnitude = g_nXForce;
|
||||||
|
|
Loading…
Reference in New Issue