From 367c6fed34fcd758bb2e41741231100b24f27dbb Mon Sep 17 00:00:00 2001 From: Paul Dino Jones Date: Fri, 21 Mar 2025 19:45:34 -0400 Subject: [PATCH] Add Suspension travel effect --- src/monocoque/devices/hapticeffect.c | 39 +++++++++++++++++++++++- src/monocoque/devices/sounddevice.c | 44 ++++++++++++++++++++++++++-- src/monocoque/simulatorapi/simapi | 2 +- 3 files changed, 81 insertions(+), 4 deletions(-) diff --git a/src/monocoque/devices/hapticeffect.c b/src/monocoque/devices/hapticeffect.c index 90911ec..268e122 100644 --- a/src/monocoque/devices/hapticeffect.c +++ b/src/monocoque/devices/hapticeffect.c @@ -260,6 +260,8 @@ double slipeffect(SimData* simdata, int effecttype, int tyre, double threshold, slogt("velocities (x,y,z) are %f %f %f", simdata->Xvelocity, simdata->Yvelocity, simdata->Zvelocity); } break; + case EFFECT_SUSPENSION: + break; default: slogd("Unknown effect type"); } @@ -277,7 +279,6 @@ double slipeffect(SimData* simdata, int effecttype, int tyre, double threshold, { case (EFFECT_TYRESLIP): - if (tyre == FRONTLEFT || tyre == FRONTS || tyre == ALLFOUR) { if(wheelslip[0] < -threshold) @@ -386,6 +387,42 @@ double slipeffect(SimData* simdata, int effecttype, int tyre, double threshold, play = 0; } break; + + case (EFFECT_SUSPENSION): + + if (tyre == FRONTLEFT || tyre == FRONTS || tyre == ALLFOUR) + { + if(simdata->suspension[0] > threshold) + { + play += simdata->suspension[0] - threshold; + slogt("suspension is %f", play); + } + } + if (tyre == FRONTRIGHT || tyre == FRONTS || tyre == ALLFOUR) + { + if(simdata->suspension[1] > threshold) + { + play += simdata->suspension[1] - threshold; + slogt("suspension is %f", play); + } + } + if (tyre == REARLEFT || tyre == REARS || tyre == ALLFOUR) + { + if(simdata->suspension[2] > threshold) + { + play += simdata->suspension[2] - threshold; + slogt("suspension is %f", play); + } + } + if (tyre == REARRIGHT || tyre == REARS || tyre == ALLFOUR) + { + if(simdata->suspension[3] > threshold) + { + play += simdata->suspension[3] - threshold; + slogt("suspension is %f", play); + } + } + break; } return play; diff --git a/src/monocoque/devices/sounddevice.c b/src/monocoque/devices/sounddevice.c index 78d2e99..2e3fd48 100644 --- a/src/monocoque/devices/sounddevice.c +++ b/src/monocoque/devices/sounddevice.c @@ -121,6 +121,30 @@ int sounddev_absbrakes_update(SimDevice* this, SimData* simdata) } } +int sounddev_suspension_update(SimDevice* this, SimData* simdata) +{ + SoundDevice* sounddevice = (void *) this->derived; + + double effect = slipeffect(simdata, this->hapticeffect.effecttype, this->hapticeffect.tyre, this->hapticeffect.threshold, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig); + effect = effect * 10; + slogt("Updating sound device output from original suspension travel effect %f", effect); + + if (effect > 0) + { + sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency; + sounddevice->sounddata.curr_amplitude = sounddevice->sounddata.amplitude; + effect = modulate(sounddevice, effect, sounddevice->modulationType); + sounddevice->sounddata.curr_duration = sounddevice->sounddata.duration; + } + else + { + sounddevice->sounddata.curr_frequency = 0; + sounddevice->sounddata.curr_amplitude = 0; + sounddevice->sounddata.curr_duration = 0; + } + +} + int sounddev_gearshift_update(SimDevice* this, SimData* simdata) { SoundDevice* sounddevice = (void *) this->derived; @@ -180,8 +204,8 @@ int sounddev_init(SoundDevice* sounddevice, const char* devname, MonocoqueTyreId sounddevice->sounddata.phase = 0; - sounddevice->sounddata.curr_amplitude = sounddevice->sounddata.amplitude; - sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency; + sounddevice->sounddata.curr_amplitude = 0; + sounddevice->sounddata.curr_frequency = 0; const char* streamname= "Engine"; @@ -219,6 +243,7 @@ static const vtable gear_sound_simdevice_vtable = { &sounddev_gearshift_update, static const vtable tyreslip_sound_simdevice_vtable = { &sounddev_tyreslip_update, &sounddev_free }; static const vtable tyrelock_sound_simdevice_vtable = { &sounddev_tyrelock_update, &sounddev_free }; static const vtable absbrakes_sound_simdevice_vtable = { &sounddev_absbrakes_update, &sounddev_free }; +static const vtable suspension_sound_simdevice_vtable = { &sounddev_suspension_update, &sounddev_free }; SoundDevice* new_sound_device(DeviceSettings* ds, MonocoqueSettings* ms) { @@ -282,6 +307,21 @@ SoundDevice* new_sound_device(DeviceSettings* ds, MonocoqueSettings* ms) { this->m.vtable = &absbrakes_sound_simdevice_vtable; slogi("Initializing sound device for abs vibrations."); break; + + case (EFFECT_SUSPENSION): + this->m.hapticeffect.effecttype = EFFECT_SUSPENSION; + this->m.hapticeffect.threshold = ds->threshold; + + this->m.hapticeffect.threshold = ds->threshold; + slogt("Haptic effect: %i %i on tyre %i", this->m.hapticeffect.effecttype, ds->effect_type, ds->tyre); + this->m.hapticeffect.tyre = ds->tyre; + this->m.hapticeffect.useconfig = ms->useconfig; + this->m.hapticeffect.configcheck = &ms->configcheck; + this->m.hapticeffect.tyrediameterconfig = ms->tyre_diameter_config; + + this->m.vtable = &suspension_sound_simdevice_vtable; + slogi("Initializing sound device for suspension vibrations."); + break; } slogt("Attempting to use sound device %s", ds->sounddevsettings.dev); diff --git a/src/monocoque/simulatorapi/simapi b/src/monocoque/simulatorapi/simapi index f8b0b57..b25aa66 160000 --- a/src/monocoque/simulatorapi/simapi +++ b/src/monocoque/simulatorapi/simapi @@ -1 +1 @@ -Subproject commit f8b0b57de114b5695fdfe4f01e65ca558edfb056 +Subproject commit b25aa66d783ada6ca9656a8abf874e157dcec5d6