Пример #1
0
int InitDInput(void) {
    HRESULT ddrval;

    ddrval = DirectInputCreateEx(fceu_hInstance, DIRECTINPUT_VERSION, &IID_IDirectInput7, (LPVOID*)&lpDI, 0);
    if (ddrval != DI_OK) {
        FCEUD_PrintError("DirectInput: Error creating DirectInput object.");
        return 0;
    }
    return 1;
}
Пример #2
0
static HRESULT WINAPI DI8CF_CreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj) {
    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;

    TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
    if( IsEqualGUID( &IID_IDirectInput8A, riid ) || IsEqualGUID( &IID_IDirectInput8W, riid ) || IsEqualGUID( &IID_IUnknown, riid )) {
        return DirectInputCreateEx(0, DIRECTINPUT_VERSION, riid, ppobj, pOuter);
    }

    ERR("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);    
    return E_NOINTERFACE;
}
Пример #3
0
Joystick::Joystick()
: x(0), y(0), z(0), p(0), r(0), w(0), t(0)
{
	if (!joystick)
	joystick = this;

	select      =   1;
	rudder      =   0;
	throttle    =   1;
	sensitivity =  25;
	dead_zone   = 100;

	for (int i = 0; i < MotionController::MaxActions; i++)
	action[i] = false;

	for (int i = 0; i < KEY_MAP_SIZE; i++)
	map[i] = 0;

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			hat[i][j] = false;
		}
	}

	map_axis[0] = KEY_JOY_AXIS_X;
	map_axis[1] = KEY_JOY_AXIS_Y;
	map_axis[2] = KEY_JOY_AXIS_RZ;
	map_axis[3] = KEY_JOY_AXIS_S0;

	inv_axis[0] = false;
	inv_axis[1] = false;
	inv_axis[2] = false;
	inv_axis[3] = false;

	if (MachineInfo::GetDirectXVersion() < MachineInfo::DX_7) {
		Print("Joystick: DI7 not found, using multimedia library\n");
		pdi  = 0;
		pdev = 0;
	}

	else if (!pdi) {
		HRESULT hr = DirectInputCreateEx(Game::GetHINST(), 
		DIRECTINPUT_VERSION, 
		IID_IDirectInput7, 
		(void**)&pdi,
		NULL); 
		if FAILED(hr) { 
			DirectInputError("Failed to initialize DI7", hr);
			pdi  = 0;
			pdev = 0;
		}
		else {
Пример #4
0
bool directinput::Create(HINSTANCE appInst) {
	HRESULT status = DirectInputCreateEx(appInst,
		DIRECTINPUT_VERSION,
		IID_IDirectInput7,
		(LPVOID *)&directInputHandle,
		NULL);

	if(FAILED(status)) {
		directInputHandle = NULL;
		return false;
	}

	return true;
}
Пример #5
0
static HRESULT WINAPI DICF_CreateInstance(
    LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
) {
    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;

    TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
    if ( IsEqualGUID( &IID_IDirectInputA, riid ) ||
            IsEqualGUID( &IID_IDirectInputW, riid ) ||
            IsEqualGUID( &IID_IDirectInput2A, riid ) ||
            IsEqualGUID( &IID_IDirectInput2W, riid ) ||
            IsEqualGUID( &IID_IDirectInput7A, riid ) ||
            IsEqualGUID( &IID_IDirectInput7W, riid ) ||
            IsEqualGUID( &IID_IDirectInput8A, riid ) ||
            IsEqualGUID( &IID_IDirectInput8W, riid ) ) {
        /* FIXME: reuse already created dinput if present? */
        return DirectInputCreateEx(0,0,riid,ppobj,pOuter);
    }

    FIXME("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);
    return E_NOINTERFACE;
}
Пример #6
0
static void internal_initialise_input_system ( void )
{

	unsigned int
		ret;

	//
	// We always need to create the DirectInput device - the joystick always uses it.
	//
#ifdef _WIN32
	ret = DirectInputCreateEx ( application_instance, DIRECTINPUT_VERSION, &IID_IDirectInput7, &direct_input, NULL );

	if ( ret != DI_OK )
	{

		debug_fatal ( "Unable to create DirectInput" );
	}
#endif
	initialise_keyboard ();

	initialise_mouse ();

	register_exit_function ( deinitialise_input_system );
}
Пример #7
0
bool CDirectInput::Create (void)
{
    if (!m_Ready)
    {
        // Create the directinput object
        HRESULT hRet = DirectInputCreateEx (m_hInstance, DIRECTINPUT_VERSION, IID_IDirectInput7, (void**)&m_pDI, NULL); 
        
        // If it failed
        if (hRet != DI_OK)
        {
            // Log failure
            theLog.WriteLine ("DirectInput     => !!! Could not create DirectInput object.");
            theLog.WriteLine ("DirectInput     => !!! DirectInput error is : %s.", GetDirectInputError(hRet));

            // Get out
            return false;
        }
        // If it was successful
        else
        {
            // Log success
            theLog.WriteLine ("DirectInput     => DirectInput object was created successfully.");
        }

        hRet = m_pDI->CreateDeviceEx (GUID_SysKeyboard, IID_IDirectInputDevice7, (void**)&m_pKeyboard, NULL); 

        if (hRet != DI_OK)
        {
            // Log failure
            theLog.WriteLine ("DirectInput     => !!! Could not create keyboard.");
            theLog.WriteLine ("DirectInput     => !!! DirectInput error is : %s.", GetDirectInputError(hRet));

            // Get out
            return false;
        }
        else
        {
            // Log success
            theLog.WriteLine ("DirectInput     => Keyboard was created.");
        }

        // Set the keyboard data format
        hRet = m_pKeyboard->SetDataFormat (&c_dfDIKeyboard);
    
        // If it failed
        if (hRet != DI_OK)
        {
            // Log failure
            theLog.WriteLine ("DirectInput     => !!! Could not set data format (keyboard).");
            theLog.WriteLine ("DirectInput     => !!! DirectInput error is : %s.", GetDirectInputError(hRet));

            // Get out
            return false;
        }

        // Set the keyboard's cooperative level
        hRet = m_pKeyboard->SetCooperativeLevel (m_hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); 
    
        // If it failed
        if (hRet != DI_OK)
        {
            // Log failure
            theLog.WriteLine ("DirectInput     => !!! Could not set cooperative level (keyboard).");
            theLog.WriteLine ("DirectInput     => !!! DirectInput error is : %s.", GetDirectInputError(hRet));

            // Get out
            return false;
        }
    
        // Reset the keyboard state
        ZeroMemory (m_KeyState, MAX_KEYS);
        
        // The keyboard is not opened yet
        m_KeyboardOpened = false;

        // We need this variable to get information about each key of the keyboard
        DIDEVICEOBJECTINSTANCE DeviceObjectInstance;

        // Scan the keys the keyboard could have
        for (int Key = 0 ; Key < MAX_KEYS ; Key++)
        {       
            // Initialize the device object instance and get the key's information
            ZeroMemory (&DeviceObjectInstance, sizeof (DIDEVICEOBJECTINSTANCE));
            DeviceObjectInstance.dwSize = sizeof (DIDEVICEOBJECTINSTANCE);
            HRESULT hRet = m_pKeyboard->GetObjectInfo (&DeviceObjectInstance, Key, DIPH_BYOFFSET);
            ASSERT (hRet == DI_OK || hRet == DIERR_OBJECTNOTFOUND);

            // Store the key's real name, that is to say the name given by Windows
            strcpy (m_KeyRealName[Key], (hRet != DIERR_OBJECTNOTFOUND ? DeviceObjectInstance.tszName : "Key does not exist"));
        }

        // Prepare the friendly name for each key
        MakeKeyFriendlyNames ();

        // Prepare the structure to pass when enumerating the devices
        SEnumParam EnumParam;
        EnumParam.pDI = m_pDI;
        
        // Create all joysticks that are installed in Windows
        hRet = m_pDI->EnumDevices (DIDEVTYPE_JOYSTICK, CreateInputDevice, &EnumParam, DIEDFL_ALLDEVICES);
        
        // Assert it's not an unexpected return value
        ASSERT (hRet == DI_OK);

        // The EnumParam contains the input devices, browse them
        for (unsigned int Index = 0 ; Index < EnumParam.pDevices.size() ; Index++)
        {
            LPDIRECTINPUTDEVICE7 pDevice = EnumParam.pDevices[Index];

            // Set the joystick data format
            hRet = pDevice->SetDataFormat (&c_dfDIJoystick);
    
            // If it failed
            if (hRet != DI_OK)
            {
                // Log failure
                theLog.WriteLine ("DirectInput     => !!! Could not set data format (joystick).");
                theLog.WriteLine ("DirectInput     => !!! DirectInput error is : %s.", GetDirectInputError(hRet));

                // Get out
                return false;
            }

            // Set the joystick cooperative level
            hRet = pDevice->SetCooperativeLevel (m_hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); 
    
            // If it failed
            if (hRet != DI_OK)
            {
                // Log failure
                theLog.WriteLine ("DirectInput     => !!! Could not set cooperative level (joystick).");
                theLog.WriteLine ("DirectInput     => !!! DirectInput error is : %s.", GetDirectInputError(hRet));

                // Get out
                return false;
            }

            // We need to prepare this in order to set the joystick dead zone
	        DIPROPDWORD PropertyDword;
	        PropertyDword.diph.dwSize = sizeof(PropertyDword);
	        PropertyDword.diph.dwHeaderSize = sizeof(PropertyDword.diph);
	        PropertyDword.diph.dwObj = 0;									// Apply to the
	        PropertyDword.diph.dwHow = DIPH_DEVICE;							// entire device
	        PropertyDword.dwData = 10000 * JOYSTICK_DEAD_ZONE / 100;

	        // Set the property
	        hRet = pDevice->SetProperty (DIPROP_DEADZONE, &PropertyDword.diph);

	        // Assert it's not an unexpected error
	        ASSERT (hRet == DI_OK || hRet == DI_PROPNOEFFECT);

            // We need to prepare this in order to set the joystick range
	        DIPROPRANGE PropertyRange;
	        PropertyRange.diph.dwSize = sizeof(PropertyRange);
	        PropertyRange.diph.dwHeaderSize = sizeof(PropertyRange.diph);
	        PropertyRange.diph.dwObj = 0;									// Apply to the
	        PropertyRange.diph.dwHow = DIPH_DEVICE;							// entire device
	        PropertyRange.lMin = JOYSTICK_MINIMUM_AXIS;
            PropertyRange.lMax = JOYSTICK_MAXIMUM_AXIS;

	        // Set the property
	        hRet = pDevice->SetProperty (DIPROP_RANGE, &PropertyRange.diph);

	        // Assert it's not an unexpected error
	        ASSERT (hRet == DI_OK || hRet == DI_PROPNOEFFECT);
            
            // Allocate memory for a joystick
            SJoystick *pJoystick = new SJoystick;
         
            // If allocation failed
            if (pJoystick == NULL)
            {
                // Log failure
                theLog.WriteLine ("DirectInput     => !!! Could not allocate memory for a joystick.");
            
                // Get out
                return false;
            }

            // Reset the joystick state
            ZeroMemory (&pJoystick->State, sizeof(pJoystick->State));
            
            // The joystick is not opened yet
            pJoystick->Opened = false;

            // Set the joystick's directinput device
            pJoystick->pDevice = pDevice;
            
            // Add the joystick to the container
            m_pJoysticks.push_back (pJoystick);

            // Log we added one joystick
            theLog.WriteLine ("DirectInput     => One joystick was created.");
        }

        m_Ready = true;
    }

    // Everything went right
    return true;
}
Пример #8
0
int Game_Init(void *parms,  int num_parms)
{
// this function is where you do all the initialization 
// for your game

int index;         // looping var
char filename[80]; // used to build up files names

// initialize directdraw
DDraw_Init(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP);


#if 0 // directinput7 method

// first create the direct input object
if (DirectInputCreateEx(main_instance,DIRECTINPUT_VERSION,IID_IDirectInput7, (void **)&lpdi,NULL)!=DI_OK)
   return(0);

// create a keyboard device  //////////////////////////////////
if (lpdi->CreateDeviceEx(GUID_SysKeyboard, IID_IDirectInputDevice7, (void **)&lpdikey, NULL)!=DI_OK)
   return(0);

#endif


// first create the direct input object
if (DirectInput8Create(main_instance,DIRECTINPUT_VERSION,IID_IDirectInput8, (void **)&lpdi,NULL)!=DI_OK)
   return(0);

// create a keyboard device  //////////////////////////////////
if (lpdi->CreateDevice(GUID_SysKeyboard, &lpdikey, NULL)!=DI_OK)
   return(0);


// set cooperation level
if (lpdikey->SetCooperativeLevel(main_window_handle, 
                 DISCL_NONEXCLUSIVE | DISCL_BACKGROUND)!=DI_OK)
    return(0);

// set data format
if (lpdikey->SetDataFormat(&c_dfDIKeyboard)!=DI_OK)
   return(0);

// acquire the keyboard
if (lpdikey->Acquire()!=DI_OK)
   return(0);

///////////////////////////////////////////////////////////

// load the background
Load_Bitmap_File(&bitmap8bit, "REACTOR.BMP");

// set the palette to background image palette
Set_Palette(bitmap8bit.palette);

// create and load the reactor bitmap image
Create_Bitmap(&reactor, 0,0, 640, 480);
Load_Image_Bitmap(&reactor,&bitmap8bit,0,0,BITMAP_EXTRACT_MODE_ABS);
Unload_Bitmap_File(&bitmap8bit);

// now let's load in all the frames for the skelaton!!!

// create skelaton bob
if (!Create_BOB(&skelaton,0,0,56,72,32,
           BOB_ATTR_VISIBLE | BOB_ATTR_MULTI_ANIM,DDSCAPS_SYSTEMMEMORY))
   return(0);

// load the frames in 8 directions, 4 frames each
// each set of frames has a walk and a fire, frame sets
// are loaded in counter clockwise order looking down
// from a birds eys view or the x-z plane
for (int direction = 0; direction < 8; direction++)
    { 
    // build up file name
    sprintf(filename,"SKELSP%d.BMP",direction);

    // load in new bitmap file
    Load_Bitmap_File(&bitmap8bit,filename);
 
    Load_Frame_BOB(&skelaton,&bitmap8bit,0+direction*4,0,0,BITMAP_EXTRACT_MODE_CELL);  
    Load_Frame_BOB(&skelaton,&bitmap8bit,1+direction*4,1,0,BITMAP_EXTRACT_MODE_CELL);  
    Load_Frame_BOB(&skelaton,&bitmap8bit,2+direction*4,2,0,BITMAP_EXTRACT_MODE_CELL);  
    Load_Frame_BOB(&skelaton,&bitmap8bit,3+direction*4,0,1,BITMAP_EXTRACT_MODE_CELL);  

    // unload the bitmap file
    Unload_Bitmap_File(&bitmap8bit);

    // set the animation sequences for skelaton
    Load_Animation_BOB(&skelaton,direction,4,skelaton_anims[direction]);

    } // end for direction

// set up stating state of skelaton
Set_Animation_BOB(&skelaton, 0);
Set_Anim_Speed_BOB(&skelaton, 4);
Set_Vel_BOB(&skelaton, 0,0);
Set_Pos_BOB(&skelaton, 0, 128);

// set clipping rectangle to screen extents so mouse cursor
// doens't mess up at edges
RECT screen_rect = {0,0,screen_width,screen_height};
lpddclipper = DDraw_Attach_Clipper(lpddsback,1,&screen_rect);

// hide the mouse
ShowCursor(FALSE);

// return success
return(1);

} // end Game_Init
Пример #9
0
/******************************************************************************
 *	DirectInputCreateW (DINPUT.@)
 */
HRESULT WINAPI DirectInputCreateW(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUTW *ppDI, LPUNKNOWN punkOuter)
{
    return DirectInputCreateEx(hinst, dwVersion, &IID_IDirectInput7W, (LPVOID *)ppDI, punkOuter);
}