Xbox handler now functions correctly.

This commit is contained in:
Ryan Dortmans
2004-09-28 05:06:47 +00:00
parent 3296336486
commit 8696eafc0e
2 changed files with 18 additions and 13 deletions
@@ -33,10 +33,6 @@ byte buttonMasks[] = { XINPUT_GAMEPAD_DPAD_LEFT,
* A, B, X, Y, BLACK, WHITE, Left trigger, right trigger * A, B, X, Y, BLACK, WHITE, Left trigger, right trigger
*/ */
/* XXX: For some reason, with this input handler the input isn't handled on the gameplay screen!
* All other menus work, and the screen itself sees the input and bounces the arrow, but no step
* is actually registered. */
InputHandler_Xbox::InputHandler_Xbox() InputHandler_Xbox::InputHandler_Xbox()
{ {
// //
@@ -44,13 +40,14 @@ InputHandler_Xbox::InputHandler_Xbox()
// //
XDEVICE_PREALLOC_TYPE xdpt[] = {{XDEVICE_TYPE_GAMEPAD, 4}}; XDEVICE_PREALLOC_TYPE xdpt[] = {{XDEVICE_TYPE_GAMEPAD, 4}};
XInitDevices( sizeof(xdpt) / sizeof(XDEVICE_PREALLOC_TYPE), xdpt ); XInitDevices( sizeof(xdpt) / sizeof(XDEVICE_PREALLOC_TYPE), xdpt );
ZeroMemory( joysticks, sizeof(joysticks) );
getHandles(); getHandles();
} }
InputHandler_Xbox::~InputHandler_Xbox() InputHandler_Xbox::~InputHandler_Xbox()
{ {
for(unsigned i = 0; i < NUM_PLAYERS; i++) for(unsigned i = 0; i < NUM_JOYSTICKS; i++)
{ {
if(joysticks[i] != 0) if(joysticks[i] != 0)
XInputClose(joysticks[i]); XInputClose(joysticks[i]);
@@ -88,7 +85,7 @@ void InputHandler_Xbox::Update(float fDeltaTime)
return; return;
} }
for(unsigned i = 0; i < NUM_PLAYERS; i++) for(unsigned i = 0; i < NUM_JOYSTICKS; i++)
{ {
if(joysticks[i] == 0) if(joysticks[i] == 0)
{ {
@@ -159,11 +156,13 @@ void InputHandler_Xbox::Update(float fDeltaTime)
memcpy(&lastState[i], &xis.Gamepad, sizeof(XINPUT_GAMEPAD)); memcpy(&lastState[i], &xis.Gamepad, sizeof(XINPUT_GAMEPAD));
} }
InputHandler::UpdateTimer();
} }
void InputHandler_Xbox::GetDevicesAndDescriptions(vector<InputDevice>& vDevicesOut, vector<CString>& vDescriptionsOut) void InputHandler_Xbox::GetDevicesAndDescriptions(vector<InputDevice>& vDevicesOut, vector<CString>& vDescriptionsOut)
{ {
for( int i=0; i<NUM_PLAYERS; i++ ) for( int i=0; i<NUM_JOYSTICKS; i++ )
{ {
if( joysticks[i] != 0 ) if( joysticks[i] != 0 )
{ {
@@ -175,6 +174,12 @@ void InputHandler_Xbox::GetDevicesAndDescriptions(vector<InputDevice>& vDevicesO
void InputHandler_Xbox::getHandles() void InputHandler_Xbox::getHandles()
{ {
for(unsigned i = 0; i < NUM_JOYSTICKS; i++)
{
if(joysticks[i] != 0)
XInputClose(joysticks[i]);
}
ZeroMemory( joysticks, sizeof(joysticks) ); ZeroMemory( joysticks, sizeof(joysticks) );
ZeroMemory( lastState, sizeof(lastState) ); ZeroMemory( lastState, sizeof(lastState) );
@@ -190,7 +195,7 @@ void InputHandler_Xbox::getHandles()
{ {
if( devices.dwState & 1 << i) if( devices.dwState & 1 << i)
{ {
if(playersAllocated < NUM_PLAYERS) if(playersAllocated < NUM_JOYSTICKS)
{ {
XINPUT_POLLING_PARAMETERS pollingParameters = {TRUE, TRUE, 0, 8, 8, 0,}; XINPUT_POLLING_PARAMETERS pollingParameters = {TRUE, TRUE, 0, 8, 8, 0,};
joysticks[playersAllocated] = XInputOpen(XDEVICE_TYPE_GAMEPAD, (DWORD)i, XDEVICE_NO_SLOT, &pollingParameters); joysticks[playersAllocated] = XInputOpen(XDEVICE_TYPE_GAMEPAD, (DWORD)i, XDEVICE_NO_SLOT, &pollingParameters);
@@ -6,15 +6,15 @@
#include <xtl.h> #include <xtl.h>
#define NUM_PORTS 4 #define NUM_PORTS 4
#define NUM_PLAYERS 2 #define NUM_JOYSTICKS 2
#define NUM_BUTTONS 8 #define NUM_BUTTONS 8
#define NUM_ANALOG_BUTTONS 8 #define NUM_ANALOG_BUTTONS 8
#define NUM_AXES 4 #define NUM_AXES 4
class InputHandler_Xbox: public InputHandler class InputHandler_Xbox: public InputHandler
{ {
HANDLE joysticks[NUM_PLAYERS]; HANDLE joysticks[NUM_JOYSTICKS];
XINPUT_GAMEPAD lastState[NUM_PLAYERS]; XINPUT_GAMEPAD lastState[NUM_JOYSTICKS];
public: public:
void Update(float fDeltaTime); void Update(float fDeltaTime);