forked from Dniel97/segatools
idz, idac, swdc: fixed rumble effect
This commit is contained in:
parent
66317a0054
commit
892eb2b859
1
dist/idac/segatools.ini
vendored
1
dist/idac/segatools.ini
vendored
@ -250,7 +250,6 @@ constantForceStrength=100
|
||||
damperStrength=100
|
||||
|
||||
; Rumble strength, used for road surface effects.
|
||||
; WARNING: THIS WILL CRASH ON FANATEC (maybe even more) WHEELS!
|
||||
rumbleStrength=100
|
||||
; Rumble duration factor from ms to µs, used to scale the duration of the rumble effect.
|
||||
rumbleDuration=1000
|
||||
|
1
dist/idz/segatools.ini
vendored
1
dist/idz/segatools.ini
vendored
@ -240,7 +240,6 @@ constantForceStrength=100
|
||||
damperStrength=100
|
||||
|
||||
; Rumble strength, used for road surface effects.
|
||||
; WARNING: THIS WILL CRASH ON FANATEC (maybe even more) WHEELS!
|
||||
rumbleStrength=100
|
||||
; Rumble duration factor from ms to µs, used to scale the duration of the rumble effect.
|
||||
rumbleDuration=1000
|
1
dist/swdc/segatools.ini
vendored
1
dist/swdc/segatools.ini
vendored
@ -200,7 +200,6 @@ constantForceStrength=100
|
||||
damperStrength=100
|
||||
|
||||
; Rumble strength, used for road surface effects.
|
||||
; WARNING: THIS WILL CRASH ON FANATEC (maybe even more) WHEELS!
|
||||
rumbleStrength=100
|
||||
; Rumble duration factor from ms to µs, used to scale the duration of the rumble effect.
|
||||
rumbleDuration=1000
|
||||
|
@ -64,12 +64,9 @@ HRESULT idac_di_dev_poll(
|
||||
&out->st);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: GetDeviceState error: %08x\n", (int) hr);
|
||||
dprintf("DirectInput: GetDeviceState error: %08x\n", (int)hr);
|
||||
}
|
||||
|
||||
/* JVS lacks a protocol for reporting hardware errors from poll command
|
||||
responses, so this ends up returning zeroed input state instead. */
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
@ -85,24 +82,21 @@ HRESULT idac_di_dev_start(IDirectInputDevice8W *dev, HWND wnd) {
|
||||
DISCL_BACKGROUND | DISCL_EXCLUSIVE);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: SetCooperativeLevel failed: %08x\n", (int) hr);
|
||||
|
||||
dprintf("DirectInput: SetCooperativeLevel failed: %08x\n", (int)hr);
|
||||
return hr;
|
||||
}
|
||||
|
||||
hr = IDirectInputDevice8_SetDataFormat(dev, &c_dfDIJoystick);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: SetDataFormat failed: %08x\n", (int) hr);
|
||||
|
||||
dprintf("DirectInput: SetDataFormat failed: %08x\n", (int)hr);
|
||||
return hr;
|
||||
}
|
||||
|
||||
hr = IDirectInputDevice8_Acquire(dev);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: Acquire failed: %08x\n", (int) hr);
|
||||
|
||||
dprintf("DirectInput: Acquire failed: %08x\n", (int)hr);
|
||||
return hr;
|
||||
}
|
||||
|
||||
@ -168,7 +162,6 @@ void idac_di_ffb_constant_force(uint8_t direction_ffb, uint8_t force)
|
||||
cf.lMagnitude = (direction_ffb == 0) ? -magnitude : magnitude;
|
||||
|
||||
axis = DIJOFS_X;
|
||||
/* Irrelevant as magnitude descripbes the direction */
|
||||
direction = 0;
|
||||
|
||||
memset(&fx, 0, sizeof(fx));
|
||||
@ -184,22 +177,21 @@ void idac_di_ffb_constant_force(uint8_t direction_ffb, uint8_t force)
|
||||
fx.cbTypeSpecificParams = sizeof(cf);
|
||||
fx.lpvTypeSpecificParams = &cf;
|
||||
|
||||
/* Check if the effect already exists */
|
||||
if (idac_di_fx != NULL) {
|
||||
// Try to update the existing effect
|
||||
hr = IDirectInputEffect_SetParameters(idac_di_fx, &fx, DIEP_TYPESPECIFICPARAMS);
|
||||
|
||||
if (SUCCEEDED(hr)) {
|
||||
return;
|
||||
} else {
|
||||
return; // Successfully updated existing effect
|
||||
}
|
||||
else {
|
||||
dprintf("DirectInput: Failed to update constant force feedback, recreating effect: %08x\n", (int)hr);
|
||||
// Stop and release the current effect if updating fails
|
||||
IDirectInputEffect_Stop(idac_di_fx);
|
||||
IDirectInputEffect_Release(idac_di_fx);
|
||||
idac_di_fx = NULL;
|
||||
idac_di_fx = NULL; // Reset the pointer
|
||||
}
|
||||
}
|
||||
|
||||
// Create a new constant force effect
|
||||
/* Create a new constant force effect */
|
||||
IDirectInputEffect *obj;
|
||||
hr = IDirectInputDevice8_CreateEffect(
|
||||
idac_di_dev,
|
||||
@ -209,13 +201,14 @@ void idac_di_ffb_constant_force(uint8_t direction_ffb, uint8_t force)
|
||||
NULL);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: Constant force feedback creation failed: %08x\n", (int) hr);
|
||||
dprintf("DirectInput: Constant force feedback creation failed: %08x\n", (int)hr);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Start the effect */
|
||||
hr = IDirectInputEffect_Start(obj, INFINITE, 0);
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: Constant force feedback start failed: %08x\n", (int) hr);
|
||||
dprintf("DirectInput: Constant force feedback start failed: %08x\n", (int)hr);
|
||||
IDirectInputEffect_Release(obj);
|
||||
return;
|
||||
}
|
||||
@ -239,9 +232,6 @@ void idac_di_ffb_rumble(uint8_t force, uint8_t period)
|
||||
DIPERIODIC pe;
|
||||
HRESULT hr;
|
||||
|
||||
/* Duration in microseconds,
|
||||
Might be totally wrong as especially on FANATEC wheels as this code will
|
||||
crash the game. TODO: Figure out why this effect will crash on FANATEC! */
|
||||
DWORD duration = (DWORD)((double)force * ffb_duration);
|
||||
|
||||
memset(&pe, 0, sizeof(pe));
|
||||
@ -256,7 +246,7 @@ void idac_di_ffb_rumble(uint8_t force, uint8_t period)
|
||||
memset(&fx, 0, sizeof(fx));
|
||||
fx.dwSize = sizeof(fx);
|
||||
fx.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS;
|
||||
fx.dwDuration = duration;
|
||||
fx.dwDuration = INFINITE;
|
||||
fx.dwGain = DI_FFNOMINALMAX;
|
||||
fx.dwTriggerButton = DIEB_NOTRIGGER;
|
||||
fx.dwTriggerRepeatInterval = INFINITE;
|
||||
@ -266,21 +256,21 @@ void idac_di_ffb_rumble(uint8_t force, uint8_t period)
|
||||
fx.cbTypeSpecificParams = sizeof(pe);
|
||||
fx.lpvTypeSpecificParams = &pe;
|
||||
|
||||
/* Check if the effect already exists */
|
||||
if (idac_di_fx_rumble != NULL) {
|
||||
// Try to update the existing effect
|
||||
hr = IDirectInputEffect_SetParameters(idac_di_fx_rumble, &fx, DIEP_TYPESPECIFICPARAMS);
|
||||
|
||||
if (SUCCEEDED(hr)) {
|
||||
return;
|
||||
} else {
|
||||
dprintf("DirectInput: Failed to update periodic force feedback, recreating effect: %08x\n", (int)hr);
|
||||
// Stop and release the current effect if updating fails
|
||||
}
|
||||
else {
|
||||
dprintf("DirectInput: Failed to update rumble feedback, recreating effect: %08x\n", (int)hr);
|
||||
IDirectInputEffect_Stop(idac_di_fx_rumble);
|
||||
IDirectInputEffect_Release(idac_di_fx_rumble);
|
||||
idac_di_fx_rumble = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create a new rumble effect */
|
||||
IDirectInputEffect *obj;
|
||||
hr = IDirectInputDevice8_CreateEffect(
|
||||
idac_di_dev,
|
||||
@ -290,13 +280,14 @@ void idac_di_ffb_rumble(uint8_t force, uint8_t period)
|
||||
NULL);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: Periodic force feedback creation failed: %08x\n", (int) hr);
|
||||
dprintf("DirectInput: Rumble effect creation failed: %08x\n", (int)hr);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Start the effect */
|
||||
hr = IDirectInputEffect_Start(obj, INFINITE, 0);
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: Periodic force feedback start failed: %08x\n", (int) hr);
|
||||
dprintf("DirectInput: Rumble effect start failed: %08x\n", (int)hr);
|
||||
IDirectInputEffect_Release(obj);
|
||||
return;
|
||||
}
|
||||
@ -343,22 +334,20 @@ void idac_di_ffb_damper(uint8_t force)
|
||||
fx.cbTypeSpecificParams = sizeof(cond);
|
||||
fx.lpvTypeSpecificParams = &cond;
|
||||
|
||||
/* Check if the damper effect already exists */
|
||||
if (idac_di_fx_damper != NULL) {
|
||||
// Try to update the existing effect
|
||||
hr = IDirectInputEffect_SetParameters(idac_di_fx_damper, &fx, DIEP_TYPESPECIFICPARAMS);
|
||||
|
||||
if (SUCCEEDED(hr)) {
|
||||
return;
|
||||
} else {
|
||||
dprintf("DirectInput: Failed to update damper force feedback, recreating effect: %08x\n", (int)hr);
|
||||
// Stop and release the current effect if updating fails
|
||||
}
|
||||
else {
|
||||
IDirectInputEffect_Stop(idac_di_fx_damper);
|
||||
IDirectInputEffect_Release(idac_di_fx_damper);
|
||||
idac_di_fx_damper = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Create a new damper force effect
|
||||
/* Create a new damper effect */
|
||||
IDirectInputEffect *obj;
|
||||
hr = IDirectInputDevice8_CreateEffect(
|
||||
idac_di_dev,
|
||||
@ -368,13 +357,12 @@ void idac_di_ffb_damper(uint8_t force)
|
||||
NULL);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: Damper force feedback creation failed: %08x\n", (int) hr);
|
||||
return;
|
||||
}
|
||||
|
||||
hr = IDirectInputEffect_Start(obj, INFINITE, 0);
|
||||
/* Start the effect */
|
||||
hr = IDirectInputEffect_Start(obj, fx.dwDuration, 0);
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: Damper force feedback start failed: %08x\n", (int) hr);
|
||||
IDirectInputEffect_Release(obj);
|
||||
return;
|
||||
}
|
||||
|
@ -64,12 +64,9 @@ HRESULT idz_di_dev_poll(
|
||||
&out->st);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: GetDeviceState error: %08x\n", (int) hr);
|
||||
dprintf("DirectInput: GetDeviceState error: %08x\n", (int)hr);
|
||||
}
|
||||
|
||||
/* JVS lacks a protocol for reporting hardware errors from poll command
|
||||
responses, so this ends up returning zeroed input state instead. */
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
@ -85,24 +82,21 @@ HRESULT idz_di_dev_start(IDirectInputDevice8W *dev, HWND wnd) {
|
||||
DISCL_BACKGROUND | DISCL_EXCLUSIVE);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: SetCooperativeLevel failed: %08x\n", (int) hr);
|
||||
|
||||
dprintf("DirectInput: SetCooperativeLevel failed: %08x\n", (int)hr);
|
||||
return hr;
|
||||
}
|
||||
|
||||
hr = IDirectInputDevice8_SetDataFormat(dev, &c_dfDIJoystick);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: SetDataFormat failed: %08x\n", (int) hr);
|
||||
|
||||
dprintf("DirectInput: SetDataFormat failed: %08x\n", (int)hr);
|
||||
return hr;
|
||||
}
|
||||
|
||||
hr = IDirectInputDevice8_Acquire(dev);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: Acquire failed: %08x\n", (int) hr);
|
||||
|
||||
dprintf("DirectInput: Acquire failed: %08x\n", (int)hr);
|
||||
return hr;
|
||||
}
|
||||
|
||||
@ -168,7 +162,6 @@ void idz_di_ffb_constant_force(uint8_t direction_ffb, uint8_t force)
|
||||
cf.lMagnitude = (direction_ffb == 0) ? -magnitude : magnitude;
|
||||
|
||||
axis = DIJOFS_X;
|
||||
/* Irrelevant as magnitude descripbes the direction */
|
||||
direction = 0;
|
||||
|
||||
memset(&fx, 0, sizeof(fx));
|
||||
@ -184,22 +177,21 @@ void idz_di_ffb_constant_force(uint8_t direction_ffb, uint8_t force)
|
||||
fx.cbTypeSpecificParams = sizeof(cf);
|
||||
fx.lpvTypeSpecificParams = &cf;
|
||||
|
||||
/* Check if the effect already exists */
|
||||
if (idz_di_fx != NULL) {
|
||||
// Try to update the existing effect
|
||||
hr = IDirectInputEffect_SetParameters(idz_di_fx, &fx, DIEP_TYPESPECIFICPARAMS);
|
||||
|
||||
if (SUCCEEDED(hr)) {
|
||||
return;
|
||||
} else {
|
||||
return; // Successfully updated existing effect
|
||||
}
|
||||
else {
|
||||
dprintf("DirectInput: Failed to update constant force feedback, recreating effect: %08x\n", (int)hr);
|
||||
// Stop and release the current effect if updating fails
|
||||
IDirectInputEffect_Stop(idz_di_fx);
|
||||
IDirectInputEffect_Release(idz_di_fx);
|
||||
idz_di_fx = NULL;
|
||||
idz_di_fx = NULL; // Reset the pointer
|
||||
}
|
||||
}
|
||||
|
||||
// Create a new constant force effect
|
||||
/* Create a new constant force effect */
|
||||
IDirectInputEffect *obj;
|
||||
hr = IDirectInputDevice8_CreateEffect(
|
||||
idz_di_dev,
|
||||
@ -209,13 +201,14 @@ void idz_di_ffb_constant_force(uint8_t direction_ffb, uint8_t force)
|
||||
NULL);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: Constant force feedback creation failed: %08x\n", (int) hr);
|
||||
dprintf("DirectInput: Constant force feedback creation failed: %08x\n", (int)hr);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Start the effect */
|
||||
hr = IDirectInputEffect_Start(obj, INFINITE, 0);
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: Constant force feedback start failed: %08x\n", (int) hr);
|
||||
dprintf("DirectInput: Constant force feedback start failed: %08x\n", (int)hr);
|
||||
IDirectInputEffect_Release(obj);
|
||||
return;
|
||||
}
|
||||
@ -239,9 +232,6 @@ void idz_di_ffb_rumble(uint8_t force, uint8_t period)
|
||||
DIPERIODIC pe;
|
||||
HRESULT hr;
|
||||
|
||||
/* Duration in microseconds,
|
||||
Might be totally wrong as especially on FANATEC wheels as this code will
|
||||
crash the game. TODO: Figure out why this effect will crash on FANATEC! */
|
||||
DWORD duration = (DWORD)((double)force * ffb_duration);
|
||||
|
||||
memset(&pe, 0, sizeof(pe));
|
||||
@ -256,7 +246,7 @@ void idz_di_ffb_rumble(uint8_t force, uint8_t period)
|
||||
memset(&fx, 0, sizeof(fx));
|
||||
fx.dwSize = sizeof(fx);
|
||||
fx.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS;
|
||||
fx.dwDuration = duration;
|
||||
fx.dwDuration = INFINITE;
|
||||
fx.dwGain = DI_FFNOMINALMAX;
|
||||
fx.dwTriggerButton = DIEB_NOTRIGGER;
|
||||
fx.dwTriggerRepeatInterval = INFINITE;
|
||||
@ -266,21 +256,21 @@ void idz_di_ffb_rumble(uint8_t force, uint8_t period)
|
||||
fx.cbTypeSpecificParams = sizeof(pe);
|
||||
fx.lpvTypeSpecificParams = &pe;
|
||||
|
||||
/* Check if the effect already exists */
|
||||
if (idz_di_fx_rumble != NULL) {
|
||||
// Try to update the existing effect
|
||||
hr = IDirectInputEffect_SetParameters(idz_di_fx_rumble, &fx, DIEP_TYPESPECIFICPARAMS);
|
||||
|
||||
if (SUCCEEDED(hr)) {
|
||||
return;
|
||||
} else {
|
||||
dprintf("DirectInput: Failed to update periodic force feedback, recreating effect: %08x\n", (int)hr);
|
||||
// Stop and release the current effect if updating fails
|
||||
}
|
||||
else {
|
||||
dprintf("DirectInput: Failed to update rumble feedback, recreating effect: %08x\n", (int)hr);
|
||||
IDirectInputEffect_Stop(idz_di_fx_rumble);
|
||||
IDirectInputEffect_Release(idz_di_fx_rumble);
|
||||
idz_di_fx_rumble = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create a new rumble effect */
|
||||
IDirectInputEffect *obj;
|
||||
hr = IDirectInputDevice8_CreateEffect(
|
||||
idz_di_dev,
|
||||
@ -290,13 +280,14 @@ void idz_di_ffb_rumble(uint8_t force, uint8_t period)
|
||||
NULL);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: Periodic force feedback creation failed: %08x\n", (int) hr);
|
||||
dprintf("DirectInput: Rumble effect creation failed: %08x\n", (int)hr);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Start the effect */
|
||||
hr = IDirectInputEffect_Start(obj, INFINITE, 0);
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: Periodic force feedback start failed: %08x\n", (int) hr);
|
||||
dprintf("DirectInput: Rumble effect start failed: %08x\n", (int)hr);
|
||||
IDirectInputEffect_Release(obj);
|
||||
return;
|
||||
}
|
||||
@ -343,22 +334,20 @@ void idz_di_ffb_damper(uint8_t force)
|
||||
fx.cbTypeSpecificParams = sizeof(cond);
|
||||
fx.lpvTypeSpecificParams = &cond;
|
||||
|
||||
/* Check if the damper effect already exists */
|
||||
if (idz_di_fx_damper != NULL) {
|
||||
// Try to update the existing effect
|
||||
hr = IDirectInputEffect_SetParameters(idz_di_fx_damper, &fx, DIEP_TYPESPECIFICPARAMS);
|
||||
|
||||
if (SUCCEEDED(hr)) {
|
||||
return;
|
||||
} else {
|
||||
dprintf("DirectInput: Failed to update damper force feedback, recreating effect: %08x\n", (int)hr);
|
||||
// Stop and release the current effect if updating fails
|
||||
}
|
||||
else {
|
||||
IDirectInputEffect_Stop(idz_di_fx_damper);
|
||||
IDirectInputEffect_Release(idz_di_fx_damper);
|
||||
idz_di_fx_damper = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Create a new damper force effect
|
||||
/* Create a new damper effect */
|
||||
IDirectInputEffect *obj;
|
||||
hr = IDirectInputDevice8_CreateEffect(
|
||||
idz_di_dev,
|
||||
@ -368,13 +357,12 @@ void idz_di_ffb_damper(uint8_t force)
|
||||
NULL);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: Damper force feedback creation failed: %08x\n", (int) hr);
|
||||
return;
|
||||
}
|
||||
|
||||
hr = IDirectInputEffect_Start(obj, INFINITE, 0);
|
||||
/* Start the effect */
|
||||
hr = IDirectInputEffect_Start(obj, fx.dwDuration, 0);
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: Damper force feedback start failed: %08x\n", (int) hr);
|
||||
IDirectInputEffect_Release(obj);
|
||||
return;
|
||||
}
|
||||
|
@ -64,12 +64,9 @@ HRESULT swdc_di_dev_poll(
|
||||
&out->st);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: GetDeviceState error: %08x\n", (int) hr);
|
||||
dprintf("DirectInput: GetDeviceState error: %08x\n", (int)hr);
|
||||
}
|
||||
|
||||
/* JVS lacks a protocol for reporting hardware errors from poll command
|
||||
responses, so this ends up returning zeroed input state instead. */
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
@ -85,24 +82,21 @@ HRESULT swdc_di_dev_start(IDirectInputDevice8W *dev, HWND wnd) {
|
||||
DISCL_BACKGROUND | DISCL_EXCLUSIVE);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: SetCooperativeLevel failed: %08x\n", (int) hr);
|
||||
|
||||
dprintf("DirectInput: SetCooperativeLevel failed: %08x\n", (int)hr);
|
||||
return hr;
|
||||
}
|
||||
|
||||
hr = IDirectInputDevice8_SetDataFormat(dev, &c_dfDIJoystick);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: SetDataFormat failed: %08x\n", (int) hr);
|
||||
|
||||
dprintf("DirectInput: SetDataFormat failed: %08x\n", (int)hr);
|
||||
return hr;
|
||||
}
|
||||
|
||||
hr = IDirectInputDevice8_Acquire(dev);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: Acquire failed: %08x\n", (int) hr);
|
||||
|
||||
dprintf("DirectInput: Acquire failed: %08x\n", (int)hr);
|
||||
return hr;
|
||||
}
|
||||
|
||||
@ -168,7 +162,6 @@ void swdc_di_ffb_constant_force(uint8_t direction_ffb, uint8_t force)
|
||||
cf.lMagnitude = (direction_ffb == 0) ? -magnitude : magnitude;
|
||||
|
||||
axis = DIJOFS_X;
|
||||
/* Irrelevant as magnitude descripbes the direction */
|
||||
direction = 0;
|
||||
|
||||
memset(&fx, 0, sizeof(fx));
|
||||
@ -184,22 +177,21 @@ void swdc_di_ffb_constant_force(uint8_t direction_ffb, uint8_t force)
|
||||
fx.cbTypeSpecificParams = sizeof(cf);
|
||||
fx.lpvTypeSpecificParams = &cf;
|
||||
|
||||
/* Check if the effect already exists */
|
||||
if (swdc_di_fx != NULL) {
|
||||
// Try to update the existing effect
|
||||
hr = IDirectInputEffect_SetParameters(swdc_di_fx, &fx, DIEP_TYPESPECIFICPARAMS);
|
||||
|
||||
if (SUCCEEDED(hr)) {
|
||||
return;
|
||||
} else {
|
||||
return; // Successfully updated existing effect
|
||||
}
|
||||
else {
|
||||
dprintf("DirectInput: Failed to update constant force feedback, recreating effect: %08x\n", (int)hr);
|
||||
// Stop and release the current effect if updating fails
|
||||
IDirectInputEffect_Stop(swdc_di_fx);
|
||||
IDirectInputEffect_Release(swdc_di_fx);
|
||||
swdc_di_fx = NULL;
|
||||
swdc_di_fx = NULL; // Reset the pointer
|
||||
}
|
||||
}
|
||||
|
||||
// Create a new constant force effect
|
||||
/* Create a new constant force effect */
|
||||
IDirectInputEffect *obj;
|
||||
hr = IDirectInputDevice8_CreateEffect(
|
||||
swdc_di_dev,
|
||||
@ -209,13 +201,14 @@ void swdc_di_ffb_constant_force(uint8_t direction_ffb, uint8_t force)
|
||||
NULL);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: Constant force feedback creation failed: %08x\n", (int) hr);
|
||||
dprintf("DirectInput: Constant force feedback creation failed: %08x\n", (int)hr);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Start the effect */
|
||||
hr = IDirectInputEffect_Start(obj, INFINITE, 0);
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: Constant force feedback start failed: %08x\n", (int) hr);
|
||||
dprintf("DirectInput: Constant force feedback start failed: %08x\n", (int)hr);
|
||||
IDirectInputEffect_Release(obj);
|
||||
return;
|
||||
}
|
||||
@ -239,9 +232,6 @@ void swdc_di_ffb_rumble(uint8_t force, uint8_t period)
|
||||
DIPERIODIC pe;
|
||||
HRESULT hr;
|
||||
|
||||
/* Duration in microseconds,
|
||||
Might be totally wrong as especially on FANATEC wheels as this code will
|
||||
crash the game. TODO: Figure out why this effect will crash on FANATEC! */
|
||||
DWORD duration = (DWORD)((double)force * ffb_duration);
|
||||
|
||||
memset(&pe, 0, sizeof(pe));
|
||||
@ -256,7 +246,7 @@ void swdc_di_ffb_rumble(uint8_t force, uint8_t period)
|
||||
memset(&fx, 0, sizeof(fx));
|
||||
fx.dwSize = sizeof(fx);
|
||||
fx.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS;
|
||||
fx.dwDuration = duration;
|
||||
fx.dwDuration = INFINITE;
|
||||
fx.dwGain = DI_FFNOMINALMAX;
|
||||
fx.dwTriggerButton = DIEB_NOTRIGGER;
|
||||
fx.dwTriggerRepeatInterval = INFINITE;
|
||||
@ -266,21 +256,21 @@ void swdc_di_ffb_rumble(uint8_t force, uint8_t period)
|
||||
fx.cbTypeSpecificParams = sizeof(pe);
|
||||
fx.lpvTypeSpecificParams = &pe;
|
||||
|
||||
/* Check if the effect already exists */
|
||||
if (swdc_di_fx_rumble != NULL) {
|
||||
// Try to update the existing effect
|
||||
hr = IDirectInputEffect_SetParameters(swdc_di_fx_rumble, &fx, DIEP_TYPESPECIFICPARAMS);
|
||||
|
||||
if (SUCCEEDED(hr)) {
|
||||
return;
|
||||
} else {
|
||||
dprintf("DirectInput: Failed to update periodic force feedback, recreating effect: %08x\n", (int)hr);
|
||||
// Stop and release the current effect if updating fails
|
||||
}
|
||||
else {
|
||||
dprintf("DirectInput: Failed to update rumble feedback, recreating effect: %08x\n", (int)hr);
|
||||
IDirectInputEffect_Stop(swdc_di_fx_rumble);
|
||||
IDirectInputEffect_Release(swdc_di_fx_rumble);
|
||||
swdc_di_fx_rumble = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create a new rumble effect */
|
||||
IDirectInputEffect *obj;
|
||||
hr = IDirectInputDevice8_CreateEffect(
|
||||
swdc_di_dev,
|
||||
@ -290,13 +280,14 @@ void swdc_di_ffb_rumble(uint8_t force, uint8_t period)
|
||||
NULL);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: Periodic force feedback creation failed: %08x\n", (int) hr);
|
||||
dprintf("DirectInput: Rumble effect creation failed: %08x\n", (int)hr);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Start the effect */
|
||||
hr = IDirectInputEffect_Start(obj, INFINITE, 0);
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: Periodic force feedback start failed: %08x\n", (int) hr);
|
||||
dprintf("DirectInput: Rumble effect start failed: %08x\n", (int)hr);
|
||||
IDirectInputEffect_Release(obj);
|
||||
return;
|
||||
}
|
||||
@ -343,22 +334,20 @@ void swdc_di_ffb_damper(uint8_t force)
|
||||
fx.cbTypeSpecificParams = sizeof(cond);
|
||||
fx.lpvTypeSpecificParams = &cond;
|
||||
|
||||
/* Check if the damper effect already exists */
|
||||
if (swdc_di_fx_damper != NULL) {
|
||||
// Try to update the existing effect
|
||||
hr = IDirectInputEffect_SetParameters(swdc_di_fx_damper, &fx, DIEP_TYPESPECIFICPARAMS);
|
||||
|
||||
if (SUCCEEDED(hr)) {
|
||||
return;
|
||||
} else {
|
||||
dprintf("DirectInput: Failed to update damper force feedback, recreating effect: %08x\n", (int)hr);
|
||||
// Stop and release the current effect if updating fails
|
||||
}
|
||||
else {
|
||||
IDirectInputEffect_Stop(swdc_di_fx_damper);
|
||||
IDirectInputEffect_Release(swdc_di_fx_damper);
|
||||
swdc_di_fx_damper = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Create a new damper force effect
|
||||
/* Create a new damper effect */
|
||||
IDirectInputEffect *obj;
|
||||
hr = IDirectInputDevice8_CreateEffect(
|
||||
swdc_di_dev,
|
||||
@ -368,13 +357,12 @@ void swdc_di_ffb_damper(uint8_t force)
|
||||
NULL);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: Damper force feedback creation failed: %08x\n", (int) hr);
|
||||
return;
|
||||
}
|
||||
|
||||
hr = IDirectInputEffect_Start(obj, INFINITE, 0);
|
||||
/* Start the effect */
|
||||
hr = IDirectInputEffect_Start(obj, fx.dwDuration, 0);
|
||||
if (FAILED(hr)) {
|
||||
dprintf("DirectInput: Damper force feedback start failed: %08x\n", (int) hr);
|
||||
IDirectInputEffect_Release(obj);
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user