Esempio n. 1
0
/*
 * Checks to see if the haptic device and joystick and in reality the same.
 */
int
SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
{
    if ((joystick->hwdata->bXInputHaptic == haptic->hwdata->bXInputHaptic) && (haptic->hwdata->userid == joystick->hwdata->userid)) {
        return 1;
    } else {
        HRESULT ret;
        DIDEVICEINSTANCE hap_instance, joy_instance;

        hap_instance.dwSize = sizeof(DIDEVICEINSTANCE);
        joy_instance.dwSize = sizeof(DIDEVICEINSTANCE);

        /* Get the device instances. */
        ret = IDirectInputDevice8_GetDeviceInfo(haptic->hwdata->device,
                                            &hap_instance);
        if (FAILED(ret)) {
            return 0;
        }
        ret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice,
                                                &joy_instance);
        if (FAILED(ret)) {
            return 0;
        }

        if (DI_GUIDIsSame(&hap_instance.guidInstance, &joy_instance.guidInstance))
            return 1;
    }

    return 0;
}
Esempio n. 2
0
/*
 * Opens a SDL_Haptic from a SDL_Joystick.
 */
int
SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
{
    int i;
    HRESULT idret;
    DIDEVICEINSTANCE joy_instance;
    joy_instance.dwSize = sizeof(DIDEVICEINSTANCE);

    /* Since it comes from a joystick we have to try to match it with a haptic device on our haptic list. */
    if (joystick->hwdata->bXInputDevice) {
        const Uint8 userid = joystick->hwdata->userid;
        for (i=0; i<SDL_numhaptics; i++) {
            if ((SDL_hapticlist[i].bXInputHaptic) && (SDL_hapticlist[i].userid == userid)) {
                SDL_assert(joystick->hwdata->bXInputHaptic);
                haptic->index = i;
                return SDL_SYS_HapticOpenFromXInput(haptic, SDL_hapticlist[haptic->index].userid);
            }
        }
    } else {
        for (i=0; i<SDL_numhaptics; i++) {
            idret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice, &joy_instance);
            if (FAILED(idret)) {
                return -1;
            }
            if (DI_GUIDIsSame(&SDL_hapticlist[i].instance.guidInstance,
                              &joy_instance.guidInstance)) {
                haptic->index = i;
                return SDL_SYS_HapticOpenFromDevice8(haptic, joystick->hwdata->InputDevice, SDL_TRUE);
            }
        }
    }
    /* No match to our haptic list */
    return -1;
}
Esempio n. 3
0
int
SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
{
    SDL_hapticlist_item *item;
    int index = 0;
    HRESULT ret;
    DIDEVICEINSTANCE joy_instance;

    joy_instance.dwSize = sizeof(DIDEVICEINSTANCE);
    ret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice, &joy_instance);
    if (FAILED(ret)) {
        return -1;
    }

    /* Since it comes from a joystick we have to try to match it with a haptic device on our haptic list. */
    for (item = SDL_hapticlist; item != NULL; item = item->next) {
        if (!item->bXInputHaptic && DI_GUIDIsSame(&item->instance.guidInstance, &joy_instance.guidInstance)) {
            haptic->index = index;
            return SDL_DINPUT_HapticOpenFromDevice(haptic, joystick->hwdata->InputDevice, SDL_TRUE);
        }
        ++index;
    }

    SDL_SetError("Couldn't find joystick in haptic device list");
    return -1;
}
Esempio n. 4
0
int
SDL_DINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
{
    HRESULT ret;
    DIDEVICEINSTANCE hap_instance, joy_instance;

    hap_instance.dwSize = sizeof(DIDEVICEINSTANCE);
    joy_instance.dwSize = sizeof(DIDEVICEINSTANCE);

    /* Get the device instances. */
    ret = IDirectInputDevice8_GetDeviceInfo(haptic->hwdata->device,
        &hap_instance);
    if (FAILED(ret)) {
        return 0;
    }
    ret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice,
        &joy_instance);
    if (FAILED(ret)) {
        return 0;
    }

    return DI_GUIDIsSame(&hap_instance.guidInstance, &joy_instance.guidInstance);
}