support multiple game devices.
This commit is contained in:
parent
a248e403d6
commit
67a9a34dfa
|
@ -19,7 +19,7 @@
|
|||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//*/
|
||||
|
||||
|
||||
//TODO - rumble is broken. hopefully nobody will notice
|
||||
|
||||
#ifdef __MINGW32__
|
||||
#define _WIN32_IE 0x0501
|
||||
|
@ -276,19 +276,20 @@ typedef char TcDIBuf[512];
|
|||
|
||||
TcDIBuf cDIBuf;
|
||||
LPDIRECTINPUT8 pDI;
|
||||
LPDIRECTINPUTDEVICE8 pJoystick;
|
||||
DIDEVCAPS DIJoycap;
|
||||
LPDIRECTINPUTEFFECT pEffect;
|
||||
char JoystickName[255];
|
||||
BOOL Feedback;
|
||||
|
||||
|
||||
static LPDIRECTINPUT8 tmp_pDI = NULL;
|
||||
static BOOL tmp_Feedback = FALSE;
|
||||
static char tmp_device_name[255] = { 0 };
|
||||
static LPDIRECTINPUTDEVICE8 tmp_Device = 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)
|
||||
{
|
||||
if ( FAILED( tmp_pDI->CreateDevice(lpddi->guidInstance, &tmp_Device, NULL) ) )
|
||||
|
@ -297,25 +298,21 @@ BOOL CALLBACK EnumCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef)
|
|||
return DIENUM_CONTINUE;
|
||||
}
|
||||
|
||||
strcpy(tmp_device_name, lpddi->tszProductName);
|
||||
if (lpddi->guidFFDriver.Data1) tmp_Feedback = TRUE;
|
||||
return DIENUM_STOP;
|
||||
joyDevices.push_back(tmp_Device);
|
||||
joyDeviceNames.push_back(lpddi->tszProductName);
|
||||
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_Feedback = FALSE;
|
||||
memset(tmp_device_name, 0, 255);
|
||||
if( FAILED( pDI->EnumDevices(DI8DEVCLASS_GAMECTRL,
|
||||
pDI->EnumDevices(DI8DEVCLASS_GAMECTRL,
|
||||
EnumCallback,
|
||||
NULL,
|
||||
DIEDFL_ATTACHEDONLY) ) )
|
||||
return NULL;
|
||||
Feedback = tmp_Feedback;
|
||||
strcpy(JoystickName, tmp_device_name);
|
||||
return tmp_Device;
|
||||
DIEDFL_ATTACHEDONLY);
|
||||
}
|
||||
|
||||
BOOL CALLBACK EnumObjects(const DIDEVICEOBJECTINSTANCE* pdidoi,VOID* pContext)
|
||||
|
@ -439,19 +436,24 @@ static void SaveInputConfig()
|
|||
|
||||
BOOL di_init()
|
||||
{
|
||||
Feedback = FALSE;
|
||||
HWND hParentWnd = MainWindow->getHWnd();
|
||||
|
||||
pDI = NULL;
|
||||
pJoystick = NULL;
|
||||
Feedback = FALSE;
|
||||
memset(cDIBuf, 0, sizeof(cDIBuf));
|
||||
memset(JoystickName, 0, sizeof(JoystickName));
|
||||
|
||||
if(FAILED(DirectInput8Create(GetModuleHandle(NULL),DIRECTINPUT_VERSION,IID_IDirectInput8,(void**)&pDI,NULL)))
|
||||
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)
|
||||
{
|
||||
|
@ -473,6 +475,8 @@ BOOL di_init()
|
|||
}
|
||||
else
|
||||
{
|
||||
JoystickF[i].Attached = false;
|
||||
JoystickF[i].Device = NULL;
|
||||
pJoystick->Release();
|
||||
pJoystick = NULL;
|
||||
}
|
||||
|
@ -511,18 +515,20 @@ BOOL di_init()
|
|||
eff.lpvTypeSpecificParams = &cf;
|
||||
eff.dwStartDelay = 0;
|
||||
|
||||
if( FAILED( pJoystick->CreateEffect(GUID_ConstantForce, &eff, &pEffect, NULL) ) )
|
||||
Feedback = FALSE;
|
||||
//if( FAILED( pJoystick->CreateEffect(GUID_ConstantForce, &eff, &pEffect, NULL) ) )
|
||||
// Feedback = FALSE;
|
||||
}
|
||||
else
|
||||
Feedback = FALSE;
|
||||
//Feedback = FALSE;
|
||||
{}
|
||||
}
|
||||
|
||||
INFO("DirectX Input: \n");
|
||||
if (pJoystick != NULL)
|
||||
{
|
||||
INFO(" - gamecontrol successfully inited: %s\n", JoystickName);
|
||||
if (Feedback) INFO("\t\t\t\t (with FeedBack support)\n");
|
||||
INFO(" - gamecontrol successfully inited: %s\n", joyDeviceNames[i].c_str());
|
||||
if (joyDeviceFeedback[i]) INFO("\t\t\t\t (with FeedBack support)\n");
|
||||
}
|
||||
}
|
||||
|
||||
paused = FALSE;
|
||||
|
@ -530,10 +536,10 @@ BOOL di_init()
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL JoystickEnabled()
|
||||
{
|
||||
return (pJoystick==NULL?FALSE:TRUE);
|
||||
}
|
||||
//BOOL JoystickEnabled()
|
||||
//{
|
||||
// return (pJoystick==NULL?FALSE:TRUE);
|
||||
//}
|
||||
|
||||
|
||||
HWND funky;
|
||||
|
@ -643,7 +649,10 @@ void S9xUpdateJoyState()
|
|||
{
|
||||
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)
|
||||
{
|
||||
DIJOYSTATE2 JoyStatus;
|
||||
|
@ -710,10 +719,15 @@ void S9xUpdateJoyState()
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
DIJOYSTATE2 JoyStatus;
|
||||
|
@ -727,8 +741,8 @@ void di_poll_scan()
|
|||
if (FAILED(hr)) hr=pJoystick->Acquire();
|
||||
else
|
||||
{
|
||||
CheckAxis(0,0,JoyStatus.lX,-10000,10000,Joystick[0].Left,Joystick[0].Right);
|
||||
CheckAxis(0,2,JoyStatus.lY,-10000,10000,Joystick[0].Down,Joystick[0].Up);
|
||||
CheckAxis(0,0,JoyStatus.lX,-10000,10000,Joystick[C].Left,Joystick[C].Right);
|
||||
CheckAxis(0,2,JoyStatus.lY,-10000,10000,Joystick[C].Down,Joystick[C].Up);
|
||||
|
||||
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 ++)
|
||||
// JoystickF[C].Attached = joyGetDevCaps( JOYSTICKID1+C, &JoystickF[C].Caps, sizeof( JOYCAPS)) == JOYERR_NOERROR;
|
||||
|
||||
memset(&JoystickF[0],0,sizeof(JoystickF[0]));
|
||||
JoystickF[0].Attached = pJoystick != NULL;
|
||||
//memset(&JoystickF[0],0,sizeof(JoystickF[0]));
|
||||
//JoystickF[0].Attached = pJoystick != NULL;
|
||||
|
||||
|
||||
//for(i=1;i<6;i++)
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#define INPUTDX_INCLUDED
|
||||
|
||||
#include <mmsystem.h>
|
||||
#define DIRECTINPUT_VERSION 0x0800
|
||||
#include "directx/dinput.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
@ -79,6 +81,7 @@ struct SJoypad {
|
|||
|
||||
|
||||
struct SJoyState{
|
||||
LPDIRECTINPUTDEVICE8 Device;
|
||||
bool Attached;
|
||||
JOYCAPS Caps;
|
||||
int Threshold;
|
||||
|
@ -102,7 +105,7 @@ struct SJoyState{
|
|||
bool VDown;
|
||||
bool ZUp;
|
||||
bool ZDown;
|
||||
bool Button[32];
|
||||
bool Button[128];
|
||||
};
|
||||
|
||||
extern SJoypad Joypad[16];
|
||||
|
|
Loading…
Reference in New Issue