support multiple game devices.

This commit is contained in:
zeromus 2009-10-30 06:05:43 +00:00
parent a248e403d6
commit 67a9a34dfa
2 changed files with 290 additions and 272 deletions

View File

@ -19,7 +19,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//*/ //*/
//TODO - rumble is broken. hopefully nobody will notice
#ifdef __MINGW32__ #ifdef __MINGW32__
#define _WIN32_IE 0x0501 #define _WIN32_IE 0x0501
@ -276,19 +276,20 @@ typedef char TcDIBuf[512];
TcDIBuf cDIBuf; TcDIBuf cDIBuf;
LPDIRECTINPUT8 pDI; LPDIRECTINPUT8 pDI;
LPDIRECTINPUTDEVICE8 pJoystick;
DIDEVCAPS DIJoycap; DIDEVCAPS DIJoycap;
LPDIRECTINPUTEFFECT pEffect; LPDIRECTINPUTEFFECT pEffect;
char JoystickName[255];
BOOL Feedback; BOOL Feedback;
static LPDIRECTINPUT8 tmp_pDI = NULL; static LPDIRECTINPUT8 tmp_pDI = NULL;
static BOOL tmp_Feedback = FALSE;
static char tmp_device_name[255] = { 0 }; static char tmp_device_name[255] = { 0 };
static LPDIRECTINPUTDEVICE8 tmp_Device = NULL; static LPDIRECTINPUTDEVICE8 tmp_Device = NULL;
static LPDIRECTINPUTDEVICE8 tmp_Joystick = NULL; static LPDIRECTINPUTDEVICE8 tmp_Joystick = NULL;
std::vector<LPDIRECTINPUTDEVICE8> joyDevices;
std::vector<std::string> joyDeviceNames;
std::vector<bool> joyDeviceFeedback;
BOOL CALLBACK EnumCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef) BOOL CALLBACK EnumCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef)
{ {
if ( FAILED( tmp_pDI->CreateDevice(lpddi->guidInstance, &tmp_Device, NULL) ) ) if ( FAILED( tmp_pDI->CreateDevice(lpddi->guidInstance, &tmp_Device, NULL) ) )
@ -297,25 +298,21 @@ BOOL CALLBACK EnumCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef)
return DIENUM_CONTINUE; return DIENUM_CONTINUE;
} }
strcpy(tmp_device_name, lpddi->tszProductName); joyDevices.push_back(tmp_Device);
if (lpddi->guidFFDriver.Data1) tmp_Feedback = TRUE; joyDeviceNames.push_back(lpddi->tszProductName);
return DIENUM_STOP; if (lpddi->guidFFDriver.Data1) joyDeviceFeedback.push_back(true);
else joyDeviceFeedback.push_back(false);
return DIENUM_CONTINUE;
} }
LPDIRECTINPUTDEVICE8 EnumDevices(LPDIRECTINPUT8 pDI) static void EnumDevices(LPDIRECTINPUT8 pDI)
{ {
tmp_pDI = pDI; tmp_pDI = pDI;
tmp_Feedback = FALSE; pDI->EnumDevices(DI8DEVCLASS_GAMECTRL,
memset(tmp_device_name, 0, 255);
if( FAILED( pDI->EnumDevices(DI8DEVCLASS_GAMECTRL,
EnumCallback, EnumCallback,
NULL, NULL,
DIEDFL_ATTACHEDONLY) ) ) DIEDFL_ATTACHEDONLY);
return NULL;
Feedback = tmp_Feedback;
strcpy(JoystickName, tmp_device_name);
return tmp_Device;
} }
BOOL CALLBACK EnumObjects(const DIDEVICEOBJECTINSTANCE* pdidoi,VOID* pContext) BOOL CALLBACK EnumObjects(const DIDEVICEOBJECTINSTANCE* pdidoi,VOID* pContext)
@ -439,19 +436,24 @@ static void SaveInputConfig()
BOOL di_init() BOOL di_init()
{ {
Feedback = FALSE;
HWND hParentWnd = MainWindow->getHWnd(); HWND hParentWnd = MainWindow->getHWnd();
pDI = NULL; pDI = NULL;
pJoystick = NULL;
Feedback = FALSE;
memset(cDIBuf, 0, sizeof(cDIBuf)); memset(cDIBuf, 0, sizeof(cDIBuf));
memset(JoystickName, 0, sizeof(JoystickName));
if(FAILED(DirectInput8Create(GetModuleHandle(NULL),DIRECTINPUT_VERSION,IID_IDirectInput8,(void**)&pDI,NULL))) if(FAILED(DirectInput8Create(GetModuleHandle(NULL),DIRECTINPUT_VERSION,IID_IDirectInput8,(void**)&pDI,NULL)))
return FALSE; return FALSE;
memset(&JoystickF,0,sizeof(JoystickF));
pJoystick = EnumDevices(pDI); EnumDevices(pDI);
for(int i=0;i<(int)joyDevices.size();i++) {
JoystickF[i].Attached = true;
JoystickF[i].Device = joyDevices[i];
LPDIRECTINPUTDEVICE8 pJoystick = joyDevices[i];
if (pJoystick) if (pJoystick)
{ {
@ -473,6 +475,8 @@ BOOL di_init()
} }
else else
{ {
JoystickF[i].Attached = false;
JoystickF[i].Device = NULL;
pJoystick->Release(); pJoystick->Release();
pJoystick = NULL; pJoystick = NULL;
} }
@ -511,18 +515,20 @@ BOOL di_init()
eff.lpvTypeSpecificParams = &cf; eff.lpvTypeSpecificParams = &cf;
eff.dwStartDelay = 0; eff.dwStartDelay = 0;
if( FAILED( pJoystick->CreateEffect(GUID_ConstantForce, &eff, &pEffect, NULL) ) ) //if( FAILED( pJoystick->CreateEffect(GUID_ConstantForce, &eff, &pEffect, NULL) ) )
Feedback = FALSE; // Feedback = FALSE;
} }
else else
Feedback = FALSE; //Feedback = FALSE;
{}
} }
INFO("DirectX Input: \n"); INFO("DirectX Input: \n");
if (pJoystick != NULL) if (pJoystick != NULL)
{ {
INFO(" - gamecontrol successfully inited: %s\n", JoystickName); INFO(" - gamecontrol successfully inited: %s\n", joyDeviceNames[i].c_str());
if (Feedback) INFO("\t\t\t\t (with FeedBack support)\n"); if (joyDeviceFeedback[i]) INFO("\t\t\t\t (with FeedBack support)\n");
}
} }
paused = FALSE; paused = FALSE;
@ -530,10 +536,10 @@ BOOL di_init()
return TRUE; return TRUE;
} }
BOOL JoystickEnabled() //BOOL JoystickEnabled()
{ //{
return (pJoystick==NULL?FALSE:TRUE); // return (pJoystick==NULL?FALSE:TRUE);
} //}
HWND funky; HWND funky;
@ -643,7 +649,10 @@ void S9xUpdateJoyState()
{ {
memset(&Joystick[0],0,sizeof(Joystick[0])); memset(&Joystick[0],0,sizeof(Joystick[0]));
int C = 0; for(int C=0;C<16;C++)
{
if(!JoystickF[C].Attached) continue;
LPDIRECTINPUTDEVICE8 pJoystick = JoystickF[C].Device;
if (pJoystick) if (pJoystick)
{ {
DIJOYSTATE2 JoyStatus; DIJOYSTATE2 JoyStatus;
@ -709,11 +718,16 @@ void S9xUpdateJoyState()
} }
} }
} }
}
} }
void di_poll_scan() void di_poll_scan()
{ {
int C = 0; for(int C=0;C<16;C++)
{
//if(!JoystickF[C].Attached) continue;
LPDIRECTINPUTDEVICE8 pJoystick = JoystickF[C].Device;
if(!pJoystick) continue;
if (pJoystick) if (pJoystick)
{ {
DIJOYSTATE2 JoyStatus; DIJOYSTATE2 JoyStatus;
@ -727,8 +741,8 @@ void di_poll_scan()
if (FAILED(hr)) hr=pJoystick->Acquire(); if (FAILED(hr)) hr=pJoystick->Acquire();
else else
{ {
CheckAxis(0,0,JoyStatus.lX,-10000,10000,Joystick[0].Left,Joystick[0].Right); CheckAxis(0,0,JoyStatus.lX,-10000,10000,Joystick[C].Left,Joystick[C].Right);
CheckAxis(0,2,JoyStatus.lY,-10000,10000,Joystick[0].Down,Joystick[0].Up); CheckAxis(0,2,JoyStatus.lY,-10000,10000,Joystick[C].Down,Joystick[C].Up);
switch (JoyStatus.rgdwPOV[0]) switch (JoyStatus.rgdwPOV[0])
{ {
@ -864,6 +878,7 @@ void di_poll_scan()
} }
} }
} }
} // C loop
} }
@ -1941,8 +1956,8 @@ switch(msg)
//for( C = 0; C != 16; C ++) //for( C = 0; C != 16; C ++)
// JoystickF[C].Attached = joyGetDevCaps( JOYSTICKID1+C, &JoystickF[C].Caps, sizeof( JOYCAPS)) == JOYERR_NOERROR; // JoystickF[C].Attached = joyGetDevCaps( JOYSTICKID1+C, &JoystickF[C].Caps, sizeof( JOYCAPS)) == JOYERR_NOERROR;
memset(&JoystickF[0],0,sizeof(JoystickF[0])); //memset(&JoystickF[0],0,sizeof(JoystickF[0]));
JoystickF[0].Attached = pJoystick != NULL; //JoystickF[0].Attached = pJoystick != NULL;
//for(i=1;i<6;i++) //for(i=1;i<6;i++)

View File

@ -24,6 +24,8 @@
#define INPUTDX_INCLUDED #define INPUTDX_INCLUDED
#include <mmsystem.h> #include <mmsystem.h>
#define DIRECTINPUT_VERSION 0x0800
#include "directx/dinput.h"
typedef struct typedef struct
{ {
@ -79,6 +81,7 @@ struct SJoypad {
struct SJoyState{ struct SJoyState{
LPDIRECTINPUTDEVICE8 Device;
bool Attached; bool Attached;
JOYCAPS Caps; JOYCAPS Caps;
int Threshold; int Threshold;
@ -102,7 +105,7 @@ struct SJoyState{
bool VDown; bool VDown;
bool ZUp; bool ZUp;
bool ZDown; bool ZDown;
bool Button[32]; bool Button[128];
}; };
extern SJoypad Joypad[16]; extern SJoypad Joypad[16];