void SDL_SYS_JoystickUpdate_Buffered(SDL_Joystick * joystick) { int i; HRESULT result; DWORD numevents; DIDEVICEOBJECTDATA evtbuf[INPUT_QSIZE]; numevents = INPUT_QSIZE; result = IDirectInputDevice2_GetDeviceData(joystick->hwdata->InputDevice, sizeof(DIDEVICEOBJECTDATA), evtbuf, &numevents, 0); if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) { IDirectInputDevice2_Acquire(joystick->hwdata->InputDevice); result = IDirectInputDevice2_GetDeviceData(joystick->hwdata->InputDevice, sizeof(DIDEVICEOBJECTDATA), evtbuf, &numevents, 0); } /* Handle the events or punt */ if (FAILED(result)) return; for (i = 0; i < (int) numevents; ++i) { int j; for (j = 0; j < joystick->hwdata->NumInputs; ++j) { const input_t *in = &joystick->hwdata->Inputs[j]; if (evtbuf[i].dwOfs != in->ofs) continue; switch (in->type) { case AXIS: SDL_PrivateJoystickAxis(joystick, in->num, (Sint16) evtbuf[i].dwData); break; case BUTTON: SDL_PrivateJoystickButton(joystick, in->num, (Uint8) (evtbuf[i]. dwData ? SDL_PRESSED : SDL_RELEASED)); break; case HAT: { Uint8 pos = TranslatePOV(evtbuf[i].dwData); SDL_PrivateJoystickHat(joystick, in->num, pos); } } } } }
static int DX5_CheckInput(_THIS, int timeout, BOOL processInput) { MSG msg; int i; HRESULT result; DWORD event; posted = 0; while ( ! posted && PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) ) { if ( GetMessage(&msg, NULL, 0, 0) > 0 ) { DispatchMessage(&msg); } else { return(-1); } } if ( posted ) { return(1); } if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) { for ( i=0; i<MAX_INPUTS; ++i ) { if ( SDL_DIdev[i] != NULL ) { result = IDirectInputDevice2_Poll(SDL_DIdev[i]); if ( (result == DIERR_INPUTLOST) || (result == DIERR_NOTACQUIRED) ) { if ( SDL_strcmp(inputs[i].name, "mouse") == 0 ) { mouse_lost = 1; } IDirectInputDevice2_Acquire(SDL_DIdev[i]); IDirectInputDevice2_Poll(SDL_DIdev[i]); } } } } event = MsgWaitForMultipleObjects(SDL_DIndev, SDL_DIevt, FALSE, timeout, QS_ALLEVENTS); if ((event >= WAIT_OBJECT_0) && (event < (WAIT_OBJECT_0+SDL_DIndev))) { DWORD numevents; static DIDEVICEOBJECTDATA evtbuf[INPUT_QSIZE]; event -= WAIT_OBJECT_0; numevents = INPUT_QSIZE; result = IDirectInputDevice2_GetDeviceData( SDL_DIdev[event], sizeof(DIDEVICEOBJECTDATA), evtbuf, &numevents, 0); if ( (result == DIERR_INPUTLOST) || (result == DIERR_NOTACQUIRED) ) { if ( SDL_strcmp(inputs[event].name, "mouse") == 0 ) { mouse_lost = 1; } IDirectInputDevice2_Acquire(SDL_DIdev[event]); result = IDirectInputDevice2_GetDeviceData( SDL_DIdev[event], sizeof(DIDEVICEOBJECTDATA), evtbuf, &numevents, 0); } if ( result == DI_OK && processInput ) { (*SDL_DIfun[event])((int)numevents, evtbuf); return(1); } } if ( event != WAIT_TIMEOUT ) { if ( PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) ) { if ( GetMessage(&msg, NULL, 0, 0) > 0 ) { DispatchMessage(&msg); } else { return(-1); } return(1); } } return(0); }
void InputHandler_DInput::UpdateBuffered(DIDevice &device, const RageTimer &tm) { DWORD numevents; DIDEVICEOBJECTDATA evtbuf[INPUT_QSIZE]; numevents = INPUT_QSIZE; HRESULT hr = IDirectInputDevice2_GetDeviceData( device.Device, sizeof(DIDEVICEOBJECTDATA), evtbuf, &numevents, 0); if ( hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED ) return; /* Handle the events */ if ( hr != DI_OK ) { LOG->Trace( hr_ssprintf(hr, "UpdateBuffered: IDirectInputDevice2_GetDeviceData") ); return; } /* XXX: We should check GetConsoleWindow(), to allow input while the console window * is focused. */ if( GetForegroundWindow() != GraphicsWindow::GetHwnd() ) return; for(int i = 0; i < (int) numevents; ++i) { for(unsigned j = 0; j < device.Inputs.size(); ++j) { const input_t &in = device.Inputs[j]; const InputDevice dev = device.dev; if(evtbuf[i].dwOfs != in.ofs) continue; switch(in.type) { case in.KEY: ButtonPressed(DeviceInput(dev, in.num, -1, tm), !!(evtbuf[i].dwData & 0x80)); break; case in.BUTTON: ButtonPressed(DeviceInput(dev, JOY_1 + in.num, -1, tm), !!evtbuf[i].dwData); break; case in.AXIS: { int up = 0, down = 0; switch(in.ofs) { case DIJOFS_X: up = JOY_LEFT; down = JOY_RIGHT; break; case DIJOFS_Y: up = JOY_UP; down = JOY_DOWN; break; case DIJOFS_Z: up = JOY_Z_UP; down = JOY_Z_DOWN; break; case DIJOFS_RX: up = JOY_ROT_UP; down = JOY_ROT_DOWN; break; case DIJOFS_RY: up = JOY_ROT_LEFT; down = JOY_ROT_RIGHT; break; case DIJOFS_RZ: up = JOY_ROT_Z_UP; down = JOY_ROT_Z_DOWN; break; case DIJOFS_SLIDER(0): up = JOY_AUX_1; down = JOY_AUX_2; break; case DIJOFS_SLIDER(1): up = JOY_AUX_3; down = JOY_AUX_4; break; default: LOG->MapLog("unknown input", "Controller '%s' is returning an unknown joystick offset, %i", device.JoystickInst.tszProductName, in.ofs ); continue; } float l = SCALE( int(evtbuf[i].dwData), 0.0f, 100.0f, 0.0f, 1.0f ); ButtonPressed(DeviceInput(dev, up, max(-l,0), tm), int(evtbuf[i].dwData) < -50); ButtonPressed(DeviceInput(dev, down, max(+l,0), tm), int(evtbuf[i].dwData) > 50); break; } case in.HAT: { const int pos = TranslatePOV(evtbuf[i].dwData); ButtonPressed(DeviceInput(dev, JOY_HAT_UP, -1, tm), !!(pos & HAT_UP_MASK)); ButtonPressed(DeviceInput(dev, JOY_HAT_DOWN, -1, tm), !!(pos & HAT_DOWN_MASK)); ButtonPressed(DeviceInput(dev, JOY_HAT_LEFT, -1, tm), !!(pos & HAT_LEFT_MASK)); ButtonPressed(DeviceInput(dev, JOY_HAT_RIGHT, -1, tm), !!(pos & HAT_RIGHT_MASK)); } } } } }
/* This function checks the windows message queue and DirectInput and returns 1 if there was input, 0 if there was no input, or -1 if the application has posted a quit message. */ static int DX5_CheckInput(_THIS, int timeout, BOOL processInput) { MSG msg; int i; HRESULT result; DWORD event; /* Check the normal windows queue (highest preference) */ posted = 0; while ( ! posted && PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) ) { if ( GetMessage(&msg, NULL, 0, 0) > 0 ) { DispatchMessage(&msg); } else { return(-1); } } if ( posted ) { return(1); } /* Pump the DirectInput flow */ if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { for ( i=0; i<SDL_DIndev; ++i ) { result = IDirectInputDevice2_Poll(SDL_DIdev[i]); if ( (result == DIERR_INPUTLOST) || (result == DIERR_NOTACQUIRED) ) { if ( strcmp(inputs[i].name, "mouse") == 0 ) { mouse_lost = 1; } IDirectInputDevice2_Acquire(SDL_DIdev[i]); IDirectInputDevice2_Poll(SDL_DIdev[i]); } } } /* Wait for messages and input events */ event = MsgWaitForMultipleObjects(SDL_DIndev, SDL_DIevt, FALSE, timeout, QS_ALLEVENTS); if ((event >= WAIT_OBJECT_0) && (event < (WAIT_OBJECT_0+SDL_DIndev))) { DWORD numevents; DIDEVICEOBJECTDATA evtbuf[INPUT_QSIZE]; event -= WAIT_OBJECT_0; numevents = INPUT_QSIZE; result = IDirectInputDevice2_GetDeviceData( SDL_DIdev[event], sizeof(DIDEVICEOBJECTDATA), evtbuf, &numevents, 0); if ( (result == DIERR_INPUTLOST) || (result == DIERR_NOTACQUIRED) ) { if ( strcmp(inputs[event].name, "mouse") == 0 ) { mouse_lost = 1; } IDirectInputDevice2_Acquire(SDL_DIdev[event]); result = IDirectInputDevice2_GetDeviceData( SDL_DIdev[event], sizeof(DIDEVICEOBJECTDATA), evtbuf, &numevents, 0); } /* Handle the events */ if ( result == DI_OK && processInput ) { /* Note: This can post multiple events to event queue */ (*SDL_DIfun[event])((int)numevents, evtbuf); return(1); } } if ( event != WAIT_TIMEOUT ) { /* Maybe there was a windows message? */ if ( PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) ) { if ( GetMessage(&msg, NULL, 0, 0) > 0 ) { DispatchMessage(&msg); } else { return(-1); } return(1); } } return(0); }