Ejemplo n.º 1
0
static void DIJoystick_poll_joysticks(void)
{
	HRESULT hr;
	DWORD	i;
	
	This.m_bCoinSlot = 0;

	for (i = 0; i < This.num_joysticks; i++)
	{
		/* start by clearing the structure, then fill it in if possible */

		ClearJoyState(&This.joysticks[i].dijs);

		if (This.joysticks[i].did == NULL)
			continue;

		if (This.joysticks[i].use_joystick == FALSE)
			continue;

		hr = IDirectInputDevice2_Poll(This.joysticks[i].did);

		hr = IDirectInputDevice2_GetDeviceState(This.joysticks[i].did,sizeof(DIJOYSTATE),
												&This.joysticks[i].dijs);
		if (FAILED(hr))
		{
			if (hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED)
			{
				hr = IDirectInputDevice2_Acquire(This.joysticks[i].did);
			}
			continue;
		}
	}
}
Ejemplo n.º 2
0
void
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
{
    HRESULT result;

    result = IDirectInputDevice2_Poll(joystick->hwdata->InputDevice);
    if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) {
        IDirectInputDevice2_Acquire(joystick->hwdata->InputDevice);
        IDirectInputDevice2_Poll(joystick->hwdata->InputDevice);
    }

    if (joystick->hwdata->buffered)
        SDL_SYS_JoystickUpdate_Buffered(joystick);
    else
        SDL_SYS_JoystickUpdate_Polled(joystick);
}
Ejemplo n.º 3
0
void InputHandler_DInput::PollAndAcquireDevices()
{
	for( unsigned i = 0; i < Devices.size(); ++i )
	{
		HRESULT hr = IDirectInputDevice2_Poll( Devices[i].Device );
		if ( hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED )
		{
			/* This will fail with "access denied" on the keyboard if we don't
			 * have focus. */
			hr = IDirectInputDevice2_Acquire( Devices[i].Device );
			if ( hr != DI_OK )
				continue;

			IDirectInputDevice2_Poll( Devices[i].Device );
		}
	}
}
Ejemplo n.º 4
0
int get_joystick_status(struct wwvi_js_event *wjse)
{
	HRESULT hr;
	DIJOYSTATE2 js;
	int i;

	if (!joystick || !wjse)
		return -1;

	/* poll the device to read the current state  */
	hr = IDirectInputDevice2_Poll(joystick);
	if (FAILED(hr)) {
		/* input stream has been interrupted, re-acquire and try again */
		hr = IDirectInputDevice2_Acquire(joystick);
		while(hr == DIERR_INPUTLOST)
			hr = IDirectInputDevice2_Acquire(joystick);

		/* other errors may occur when the app is minimized
		or in the process of switching, so just try again later */
		if (FAILED(hr))
			return -1;

		/* try to poll again */
		hr = IDirectInputDevice2_Poll(joystick);
		if (FAILED(hr))
			return -1;
	}

	/* get the device state */
	hr = IDirectInputDevice2_GetDeviceState(joystick, sizeof(DIJOYSTATE2), &js);
	if(FAILED(hr))
		return -1;

	/* write out state */
	wjse->stick_x = js.lX;
	wjse->stick_y = js.lY;
	for (i = 0; i < 11; ++i) {
		wjse->button[i] = (js.rgbButtons[i] & 0x80) ? 1 : 0;
	}

	return 0;
}
Ejemplo n.º 5
0
bool joystick_poll( int joysticknum )
{
   HRESULT hRes;
   int i, j, povdir;

   /* joystick doesn't exist */
   if( !lpdiJoystick[joysticknum] )
     return false;

poll:

   /* poll the device */
   hRes = IDirectInputDevice2_Poll(lpdiJoystick[joysticknum]);

   /* not needed or succeeded */
   if ( hRes == DI_NOEFFECT && hRes == DI_OK )
     goto state;

   /* lets look for some errors */
   switch ( hRes )
   {

   // Access to the input device has been lost. It must be reacquired. 
   case DIERR_INPUTLOST:

   // The operation cannot be performed unless the device is acquired. 
   case DIERR_NOTACQUIRED:

     // acquire the device
     hRes = IDirectInputDevice2_Acquire(lpdiJoystick[joysticknum]);

     // must be a deeper issue
     if ( hRes != DI_OK )
       return false;

     // try again
     goto poll;

     break;

   // The object has not been initialized. 
   case DIERR_NOTINITIALIZED:

     // must be a deeper issue
     return false;
     break;

   }

state:

   // get data from the joystick
   hRes = IDirectInputDevice_GetDeviceState( lpdiJoystick[joysticknum],
                                             sizeof(DIJOYSTATE2),
                                             &js[ new_input ][joysticknum]);
   // if we got an error
   if ( hRes == DI_OK )
     goto povs;
   
   // lets check out some errors
   switch (hRes)
   {

   // Access to the input device has been lost. It must be reacquired. 
   case DIERR_INPUTLOST:

   // The operation cannot be performed unless the device is acquired. 
   case DIERR_NOTACQUIRED:

     // acquire the device
     hRes = IDirectInputDevice2_Acquire(lpdiJoystick[joysticknum]);

     // must be a deeper issue
     if ( hRes != DI_OK )
       return false;

     // try again
     goto state;

     break;

   case DIERR_INVALIDPARAM:
   case DIERR_NOTINITIALIZED:
      
     // must be a deeper issue
     return false;
     break;

   // Data is not yet available. 
   case E_PENDING:
     // no data just say ok and get out of here
     return true;
     break;

   }

povs:

   /* who knows what the rest of this does */

   // for each hat switch
   for (i = 0; i < JoystickInfo[joysticknum].NumPOVs; i++)
   {
     povdir = GetPOVMask( js[ new_input ][ joysticknum ].rgdwPOV[ i ] );
     for (j = 0; j < MAX_POV_DIRECTIONS; j++)
		js_pov[ new_input ][ joysticknum ][ i ][ j ] =
        ( povdir & ( 1 << j ) ) ? 0x80 : 0;
   }

   /* everything fine */
   return true;
}
Ejemplo n.º 6
0
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);
}
Ejemplo n.º 7
0
/* joystick_dinput_poll: [primary thread]
 *  Polls the DirectInput joystick devices.
 */
static int joystick_dinput_poll(void)
{
   int n_joy, n_axis, n_but;
   DIJOYSTATE js;
   HRESULT hr;

   for (n_joy = 0; n_joy < dinput_joy_num; n_joy++) {
      /* poll the device */
      IDirectInputDevice2_Poll(dinput_joystick[n_joy].device);

      hr = IDirectInputDevice2_GetDeviceState(dinput_joystick[n_joy].device, sizeof(DIJOYSTATE), &js);

      if (hr == DI_OK) {
	 /* axes */
	 dinput_joystick[n_joy].axis[0] = js.lX;
	 dinput_joystick[n_joy].axis[1] = js.lY;
	 n_axis = 2;

	 if (dinput_joystick[n_joy].caps & JOYCAPS_HASZ) {
            dinput_joystick[n_joy].axis[n_axis] = js.lZ;
            n_axis++;
         }

	 if (dinput_joystick[n_joy].caps & JOYCAPS_HASR) {
            dinput_joystick[n_joy].axis[n_axis] = js.lRz;
            n_axis++;
         }

         /* In versions of the DirectInput joystick API earlier than 8.00, slider
          * data is to be found in the Z axis data member, although the object was
          * reported as a slider during enumeration. 
          *
          * Very few locations seem to describe this "feature". Here is one:
          * http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dx81_vb/directx_vb/Input/VB_Ref/Types/dijoystate2.asp
          *
          * The interesting part is the note at the bottom of the page:
          * " Note: Under Microsoft DirectX 7, sliders on some joysticks could be assigned
          *   to the Z axis, with subsequent code retrieving data from that member. 
          *   Using DirectX 8, those same sliders will be assigned to the slider array. 
          *   This should be taken into account when porting applications to DirectX 8. 
          *   Make any necessary alterations to ensure that slider data is retrieved from 
          *   the slider array. "
          */

         /* For U axis (slider 0), get data from Z axis member if API < 0x0800
          * and if a real Z axis is not present. Otherwise get it from slider 0 member.
          */
	 if (dinput_joystick[n_joy].caps & JOYCAPS_HASU) {
#if DIRECTINPUT_VERSION < 0x0800
	    if (dinput_joystick[n_joy].caps & JOYCAPS_HASZ)
               dinput_joystick[n_joy].axis[n_axis] = js.rglSlider[0];
            else
               dinput_joystick[n_joy].axis[n_axis] = js.lZ;
#else
            dinput_joystick[n_joy].axis[n_axis] = js.rglSlider[0];
#endif
            n_axis++;
         }

         /* For V axis (slider 1), get data from slider 0 member if API < 0x0800
          * and if a real Z axis is not present. Otherwise get it from slider 1 member.
          */
         if (dinput_joystick[n_joy].caps & JOYCAPS_HASV) {
#if DIRECTINPUT_VERSION < 0x0800
	    if (dinput_joystick[n_joy].caps & JOYCAPS_HASZ)
               dinput_joystick[n_joy].axis[n_axis] = js.rglSlider[1];
            else
               dinput_joystick[n_joy].axis[n_axis] = js.rglSlider[0];
#else
            dinput_joystick[n_joy].axis[n_axis] = js.rglSlider[1];
#endif
            n_axis++;
         }

	 /* hat */
         if (dinput_joystick[n_joy].caps & JOYCAPS_HASPOV)
            dinput_joystick[n_joy].hat = js.rgdwPOV[0];

	 /* buttons */
	 for (n_but = 0; n_but < dinput_joystick[n_joy].num_buttons; n_but++)
	    dinput_joystick[n_joy].button[n_but] = ((js.rgbButtons[n_but] & 0x80) != 0);

	 win_update_joystick_status(n_joy, (WINDOWS_JOYSTICK_INFO *)&dinput_joystick[n_joy]);
      }
      else {
         if ((hr == DIERR_NOTACQUIRED) || (hr == DIERR_INPUTLOST)) {
	    /* reacquire device */
	    _TRACE(PREFIX_W "joystick device not acquired or lost\n");
	    wnd_schedule_proc(joystick_dinput_acquire);
         }
         else {
            _TRACE(PREFIX_E "unexpected error while polling the joystick\n");
         }
      }
   }

   return 0;
}
Ejemplo n.º 8
0
/* 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);
}