static void dinput_create_rumble_effects(struct dinput_joypad_data *pad) { DIENVELOPE dienv; DICONSTANTFORCE dicf; LONG direction = 0; DWORD axis = DIJOFS_X; dicf.lMagnitude = 0; dienv.dwSize = sizeof(DIENVELOPE); dienv.dwAttackLevel = 5000; dienv.dwAttackTime = 250000; dienv.dwFadeLevel = 0; dienv.dwFadeTime = 250000; pad->rumble_props.cAxes = 1; pad->rumble_props.dwTriggerButton = DIEB_NOTRIGGER; pad->rumble_props.dwTriggerRepeatInterval = 0; pad->rumble_props.cbTypeSpecificParams = sizeof(DICONSTANTFORCE); pad->rumble_props.dwDuration = INFINITE; pad->rumble_props.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; pad->rumble_props.dwGain = 0; pad->rumble_props.dwSize = sizeof(DIEFFECT); pad->rumble_props.dwStartDelay = 0; pad->rumble_props.lpEnvelope = &dienv; pad->rumble_props.lpvTypeSpecificParams = &dicf; pad->rumble_props.rgdwAxes = &axis; pad->rumble_props.rglDirection = &direction; #ifdef __cplusplus if (IDirectInputDevice8_CreateEffect(pad->joypad, GUID_ConstantForce, &pad->rumble_props, &pad->rumble_iface[0], NULL) != DI_OK) RARCH_WARN("[DINPUT]: Strong rumble unavailable.\n"); #else if (IDirectInputDevice8_CreateEffect(pad->joypad, &GUID_ConstantForce, &pad->rumble_props, &pad->rumble_iface[0], NULL) != DI_OK) RARCH_WARN("[DINPUT]: Strong rumble unavailable.\n"); #endif axis = DIJOFS_Y; #ifdef __cplusplus if (IDirectInputDevice8_CreateEffect(pad->joypad, GUID_ConstantForce, &pad->rumble_props, &pad->rumble_iface[1], NULL) != DI_OK) RARCH_WARN("[DINPUT]: Weak rumble unavailable.\n"); #else if (IDirectInputDevice8_CreateEffect(pad->joypad, &GUID_ConstantForce, &pad->rumble_props, &pad->rumble_iface[1], NULL) != DI_OK) RARCH_WARN("[DINPUT]: Weak rumble unavailable.\n"); #endif }
int SDL_DINPUT_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base) { HRESULT ret; REFGUID type = SDL_SYS_HapticEffectType(base); if (type == NULL) { SDL_SetError("Haptic: Unknown effect type."); return -1; } /* Get the effect. */ if (SDL_SYS_ToDIEFFECT(haptic, &effect->hweffect->effect, base) < 0) { goto err_effectdone; } /* Create the actual effect. */ ret = IDirectInputDevice8_CreateEffect(haptic->hwdata->device, type, &effect->hweffect->effect, &effect->hweffect->ref, NULL); if (FAILED(ret)) { DI_SetError("Unable to create effect", ret); goto err_effectdone; } return 0; err_effectdone: SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, base->type); return -1; }
/* * Creates a new haptic effect. */ int SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base) { HRESULT ret; REFGUID type = SDL_SYS_HapticEffectType(base); if (type == NULL) { goto err_hweffect; } /* Alloc the effect. */ effect->hweffect = (struct haptic_hweffect *) SDL_malloc(sizeof(struct haptic_hweffect)); if (effect->hweffect == NULL) { SDL_OutOfMemory(); goto err_hweffect; } SDL_zerop(effect->hweffect); if (haptic->hwdata->bXInputHaptic) { SDL_assert(base->type == SDL_HAPTIC_SINE); /* should catch this at higher level */ return SDL_SYS_HapticUpdateEffect(haptic, effect, base); } /* Get the effect. */ if (SDL_SYS_ToDIEFFECT(haptic, &effect->hweffect->effect, base) < 0) { goto err_effectdone; } /* Create the actual effect. */ ret = IDirectInputDevice8_CreateEffect(haptic->hwdata->device, type, &effect->hweffect->effect, &effect->hweffect->ref, NULL); if (FAILED(ret)) { DI_SetError("Unable to create effect", ret); goto err_effectdone; } return 0; err_effectdone: SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, base->type); err_hweffect: if (effect->hweffect != NULL) { SDL_free(effect->hweffect); effect->hweffect = NULL; } return -1; }
JNIEXPORT jlong JNICALL Java_net_java_games_input_IDirectInputDevice_nCreatePeriodicEffect(JNIEnv *env, jclass unused, jlong address, jbyteArray effect_guid_array, jint flags, jint duration, jint sample_period, jint gain, jint trigger_button, jint trigger_repeat_interval, jintArray axis_ids_array, jlongArray directions_array, jint envelope_attack_level, jint envelope_attack_time, jint envelope_fade_level, jint envelope_fade_time, jint periodic_magnitude, jint periodic_offset, jint periodic_phase, jint periodic_period, jint start_delay) { LPDIRECTINPUTDEVICE8 lpDevice = (LPDIRECTINPUTDEVICE8)(INT_PTR)address; LPDIRECTINPUTEFFECT lpdiEffect; DIEFFECT effect; GUID effect_guid; jint *axis_ids; jlong *directions; jsize num_axes; jsize num_directions; LONG *directions_long; DWORD *axis_ids_dword; HRESULT res; DIPERIODIC periodic; DIENVELOPE envelope; int i; num_axes = (*env)->GetArrayLength(env, axis_ids_array); num_directions = (*env)->GetArrayLength(env, directions_array); if (num_axes != num_directions) { throwIOException(env, "axis_ids.length != directions.length\n"); return 0; } unwrapGUID(env, effect_guid_array, &effect_guid); if ((*env)->ExceptionOccurred(env)) return 0; axis_ids = (*env)->GetIntArrayElements(env, axis_ids_array, NULL); if (axis_ids == NULL) return 0; directions = (*env)->GetLongArrayElements(env, directions_array, NULL); if (axis_ids == NULL) return 0; axis_ids_dword = (DWORD *)malloc(sizeof(DWORD)*num_axes); if (axis_ids_dword == NULL) { throwIOException(env, "Failed to allocate axes array\n"); return 0; } directions_long = (LONG *)malloc(sizeof(LONG)*num_directions); if (directions_long == NULL) { free(axis_ids_dword); throwIOException(env, "Failed to allocate directions array\n"); return 0; } for (i = 0; i < num_axes; i++) { axis_ids_dword[i] = axis_ids[i]; } for (i = 0; i < num_directions; i++) { directions_long[i] = directions[i]; } envelope.dwSize = sizeof(DIENVELOPE); envelope.dwAttackLevel = envelope_attack_level; envelope.dwAttackTime = envelope_attack_time; envelope.dwFadeLevel = envelope_fade_level; envelope.dwFadeTime = envelope_fade_time; periodic.dwMagnitude = periodic_magnitude; periodic.lOffset = periodic_offset; periodic.dwPhase = periodic_phase; periodic.dwPeriod = periodic_period; effect.dwSize = sizeof(DIEFFECT); effect.dwFlags = flags; effect.dwDuration = duration; effect.dwSamplePeriod = sample_period; effect.dwGain = gain; effect.dwTriggerButton = trigger_button; effect.dwTriggerRepeatInterval = trigger_repeat_interval; effect.cAxes = num_axes; effect.rgdwAxes = axis_ids_dword; effect.rglDirection = directions_long; effect.lpEnvelope = &envelope; effect.cbTypeSpecificParams = sizeof(periodic); effect.lpvTypeSpecificParams = &periodic; effect.dwStartDelay = start_delay; res = IDirectInputDevice8_CreateEffect(lpDevice, &effect_guid, &effect, &lpdiEffect, NULL); (*env)->ReleaseIntArrayElements(env, axis_ids_array, axis_ids, 0); (*env)->ReleaseLongArrayElements(env, directions_array, directions, 0); free(axis_ids_dword); free(directions_long); if (res != DI_OK) { throwIOException(env, "Failed to create effect (0x%x)\n", res); return 0; } return (jlong)(INT_PTR)lpdiEffect; }