Original Post
Hi all, i've changed my input class to make use of action mapping. i've used the directx sample ActionBasic as an example. But the function GetDeviceData always returns DIERR_NOTBUFFERED. According to the directX documentation, you have to call the SetProperty function or SetActionMap function to enable buffered data. But i'm calling the SetActionMap function. Can somenone help me? Here's some code:
bool cInputDX9_0::initActionMapping(DWORD genre,IN::sActionMap* eventMap,int numActionsInMap,const char* eventMapName,int numGameActions, GUID guid)
{
if(!DIobject)
{
if(!init())
return false;
}
this->numGameActions = numGameActions;
//Create eventMap
actionMap = new DIACTION[numActionsInMap];
for(int i = 0;i < numActionsInMap;++i)
{
actionMap.uAppData = eventMap.actionID;
actionMap.dwSemantic = eventMap.mappingID;
actionMap.dwFlags = eventMap.flag;
actionMap.lptszActionName = eventMap.actionName.c_str();
actionMap.guidInstance = GUID_NULL;
actionMap.dwObjID = 0;
actionMap.dwHow = 0;
}
ZeroMemory( &actionFormat, sizeof(DIACTIONFORMAT) );
actionFormat.dwSize = sizeof(DIACTIONFORMAT);
actionFormat.dwActionSize = sizeof(DIACTION);
actionFormat.dwDataSize = numActionsInMap * sizeof(DWORD);
actionFormat.guidActionMap = guid;
actionFormat.dwGenre = genre;
actionFormat.dwNumActions = numActionsInMap;
actionFormat.rgoAction = actionMap;
actionFormat.lAxisMin = -99;
actionFormat.lAxisMax = 99;
actionFormat.dwBufferSize = 16;
strcpy(actionFormat.tszActionMap,eventMapName);
if( FAILED(DIobject->EnumDevicesBySemantics( NULL,
&actionFormat,
EnumDevicesCallback,
NULL,
DIEDBSFL_ATTACHEDONLY ) ) )
return false;
return true;
}
BOOL CALLBACK EnumDevicesCallback( LPCDIDEVICEINSTANCE lpddi,
LPDIRECTINPUTDEVICE8 lpdid, DWORD dwFlags,
DWORD dwRemaining, LPVOID pvRef )
{
HRESULT hr;
if( numDevices < maxDevices )
{
// Build the action map against the device
if( FAILED(hr = lpdid->BuildActionMap( &actionFormat, NULL, DIDBAM_DEFAULT )) )
// There was an error while building the action map. Ignore this
// device, and contine with the enumeration
return DIENUM_CONTINUE;
// Inspect the results
for( UINT i=0; i < actionFormat.dwNumActions; i++ )
{
DIACTION *action = &(actionFormat.rgoAction);
if( action->dwHow != DIAH_ERROR && action->dwHow != DIAH_UNMAPPED )
devices[numDevices].mapped[action->uAppData] = TRUE;
}
// Set the action map
if( FAILED(hr = lpdid->SetActionMap( &actionFormat, NULL, DIDSAM_DEFAULT )) )
{
// An error occured while trying the set the action map for the
// current device. Clear the stored values, and continue to the
// next device.
ZeroMemory( devices[numDevices].mapped, sizeof(devices[numDevices].mapped) );
return DIENUM_CONTINUE;
}
// The current device has been successfully mapped. By storing the
// pointer and informing COM that we've added a reference to the
// device, we can use this pointer later when gathering input.
devices[numDevices].pDevice = lpdid;
lpdid->AddRef();
// Store the device's friendly name for display on the chart.
_tcsncat( devices[numDevices].deviceName, lpddi->tszInstanceName, deviceNameLen-5 );
if( _tcslen( lpddi->tszInstanceName ) > deviceNameLen-5 )
_tcscat( devices[numDevices].deviceName, TEXT("...") );
// Store axis absolute/relative flag
DIPROPDWORD dipdw;
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_DEVICE;
hr = lpdid->GetProperty( DIPROP_AXISMODE, &dipdw.diph );
if (SUCCEEDED(hr))
devices[numDevices].axisRelative = ( DIPROPAXISMODE_REL == dipdw.dwData );
//g_bRefChart = TRUE; // Signal a chart resize
numDevices++; // Increment the global device index
}
// Ask for the next device
return DIENUM_CONTINUE;
}
std::vector<unsigned int>* cInputDX9_0::update()
{
HRESULT hr;
for( unsigned int iDevice=0; iDevice < numDevices; iDevice++ )
{
LPDIRECTINPUTDEVICE8 pdidDevice = devices[iDevice].pDevice;
DIDEVICEOBJECTDATA rgdod[10];
DWORD dwItems = 10;
hr = pdidDevice->Acquire();
hr = pdidDevice->Poll();
hr = pdidDevice->GetDeviceData( sizeof(DIDEVICEOBJECTDATA),rgdod, &dwItems, 0 );
switch(hr)
{
case DIERR_INPUTLOST:
break;
case DIERR_INVALIDPARAM:
break;
case DIERR_NOTACQUIRED:
break;
case DIERR_NOTBUFFERED:
break;
case DIERR_NOTINITIALIZED:
break;
default:
int a = 0;
}
if( FAILED(hr) )
continue;
for( DWORD j=0; j<dwItems; j++ )
{
UINT_PTR dwAction = rgdod[j].uAppData;
DWORD dwData = 0;
resActions.push_back(actionMap[j].dwObjID);
}
}
return &resActions
}