Here is the patch, I have also committed to cvs - not sure how long anonymous cvs is taking to update nowadays.
Index: includes/win32/Win32JoyStick.h
===================================================================
RCS file: /cvsroot/wgois/ois/includes/win32/Win32JoyStick.h,v
retrieving revision 1.7
diff -u -r1.7 Win32JoyStick.h
--- includes/win32/Win32JoyStick.h 31 Aug 2006 02:16:10 -0000 1.7
+++ includes/win32/Win32JoyStick.h 16 Nov 2006 18:35:49 -0000
@@ -74,7 +74,6 @@
//! Mapping
int _AxisNumber;
- std::map<int, int> mAxisMapping;
};
}
Index: src/win32/Win32JoyStick.cpp
===================================================================
RCS file: /cvsroot/wgois/ois/src/win32/Win32JoyStick.cpp,v
retrieving revision 1.19
diff -u -r1.19 Win32JoyStick.cpp
--- src/win32/Win32JoyStick.cpp 18 Sep 2006 01:31:12 -0000 1.19
+++ src/win32/Win32JoyStick.cpp 16 Nov 2006 19:14:55 -0000
@@ -27,7 +27,7 @@
#include "OISEvents.h"
#include "OISException.h"
-#include <iostream>
+#include <cassert>
using namespace OIS;
@@ -115,9 +115,9 @@
numAxes = (short)DIJoyCaps.dwAxes;
numButtons = (short)DIJoyCaps.dwButtons;
numHats = (short)DIJoyCaps.dwPOVs;
-
+
+ //Reset the axis mapping enumeration value
_AxisNumber = 0;
- mAxisMapping.clear();
//Enumerate Force Feedback (if any)
mJoyStick->EnumEffects(DIEnumEffectsCallback, this, DIEFT_ALL);
@@ -129,11 +129,22 @@
//--------------------------------------------------------------------------------------------------//
BOOL CALLBACK Win32JoyStick::DIEnumDeviceObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef)
{
- DIPROPRANGE diprg;
Win32JoyStick* _this = (Win32JoyStick*)pvRef;
- _this->mAxisMapping[lpddoi->dwOfs] = _this->_AxisNumber++;
+ //Setup mappings
+ DIPROPPOINTER diptr;
+ diptr.diph.dwSize = sizeof(DIPROPPOINTER);
+ diptr.diph.dwHeaderSize = sizeof(DIPROPHEADER);
+ diptr.diph.dwHow = DIPH_BYID;
+ diptr.diph.dwObj = lpddoi->dwType;
+ //Add the high bit in so that an axis value of zero does not mean a null userdata
+ diptr.uData = 0x80000000 | _this->_AxisNumber++;
+
+ if (FAILED(_this->mJoyStick->SetProperty(DIPROP_APPDATA, &diptr.diph)))
+ OIS_EXCEPT( E_General, "Win32JoyStick::_DIEnumDeviceObjectsCallback >> Failed to set mapping ptr property" );
+ //Set range
+ DIPROPRANGE diprg;
diprg.diph.dwSize = sizeof(DIPROPRANGE);
diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
diprg.diph.dwHow = DIPH_BYID;
@@ -142,7 +153,7 @@
diprg.lMax = MAX_AXIS;
if (FAILED(_this->mJoyStick->SetProperty(DIPROP_RANGE, &diprg.diph)))
- OIS_EXCEPT( E_General, "Win32JoyStick::_DIEnumDeviceObjectsCallback >> Failed to set property" );
+ OIS_EXCEPT( E_General, "Win32JoyStick::_DIEnumDeviceObjectsCallback >> Failed to set min/max range property" );
//Check if FF Axes
if((lpddoi->dwFlags & DIDOI_FFACTUATOR) != 0 )
@@ -198,7 +209,8 @@
mJoyStick->Poll();
hr = mJoyStick->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), diBuff, &entries, 0 );
//Perhaps the user just tabbed away
- if( FAILED(hr) ) return;
+ if( FAILED(hr) )
+ return;
}
bool axisMoved[24] = {false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,
@@ -208,12 +220,17 @@
//Loop through all the events
for(unsigned int i = 0; i < entries; ++i)
{
- //First check to see if entry is a Axis as enumerated earlier:
- std::map<int, int>::iterator it = mAxisMapping.find( diBuff[i].dwOfs );
- if( it != mAxisMapping.end() )
+ //First check to see if event entry is a Axis we enumerated earlier
+ if( diBuff[i].uAppData > 0 )
{
- int axis = it->second;
- mState.mAxes[axis].abs = (short)diBuff[i].dwData;
+ if( diBuff[i].uAppData == 0xFFFFFFFF )
+ {
+ assert( false && "If you hit this assertion, then your user pointer data got zapped too!" );
+ }
+
+ int axis = 0x7FFFFFFF & diBuff[i].uAppData; //Mask out the high bit
+ assert( axis > 0 && axis < mState.mAxes.size() && "Axis out of range!");
+ mState.mAxes[axis].abs = diBuff[i].dwData;
axisMoved[axis] = true;
}
else