From d2e0bebc4e510b69efe7fd996acc135a67b8fcc8 Mon Sep 17 00:00:00 2001 From: Paul Dino Jones Date: Thu, 29 Feb 2024 19:19:57 +0000 Subject: [PATCH] Added preliminary support for tyre slip and abs vibrations --- src/monocoque/devices/simdevice.c | 1 + src/monocoque/devices/simdevice.h | 3 +- src/monocoque/devices/sounddevice.c | 71 +++++++++++++++++++++++++++++ src/monocoque/devices/sounddevice.h | 4 +- src/monocoque/helper/confighelper.c | 39 ++++++++++++++++ src/monocoque/helper/confighelper.h | 17 ++++++- src/monocoque/simulatorapi/simapi | 2 +- 7 files changed, 133 insertions(+), 4 deletions(-) diff --git a/src/monocoque/devices/simdevice.c b/src/monocoque/devices/simdevice.c index 9ab91dc..147bb14 100644 --- a/src/monocoque/devices/simdevice.c +++ b/src/monocoque/devices/simdevice.c @@ -78,6 +78,7 @@ int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds) simdevices[j] = sim->m; simdevices[j].initialized = true; simdevices[j].type = SIMDEV_SOUND; + simdevices[j].tyre = ds[j].tyre; devices++; } else diff --git a/src/monocoque/devices/simdevice.h b/src/monocoque/devices/simdevice.h index 949c696..cd2b323 100644 --- a/src/monocoque/devices/simdevice.h +++ b/src/monocoque/devices/simdevice.h @@ -21,7 +21,7 @@ struct SimDevice int id; bool initialized; DeviceType type; - + MonocoqueTyreIdentifier tyre; }; typedef struct { @@ -96,6 +96,7 @@ SoundDevice; int sounddev_engine_update(SimDevice* this, SimData* simdata); int sounddev_gearshift_update(SimDevice* this, SimData* simdata); +int sounddev_tyreslip_update(SimDevice* this, SimData* simdata); int sounddev_free(SimDevice* this); SoundDevice* new_sound_device(DeviceSettings* ds); diff --git a/src/monocoque/devices/sounddevice.c b/src/monocoque/devices/sounddevice.c index be1f564..4813c31 100644 --- a/src/monocoque/devices/sounddevice.c +++ b/src/monocoque/devices/sounddevice.c @@ -38,6 +38,55 @@ int sounddev_engine_update(SimDevice* this, SimData* simdata) slogt("set engine frequency to %i", sounddevice->sounddata.frequency); } +int sounddev_tyreslip_update(SimDevice* this, SimData* simdata) +{ + SoundDevice* sounddevice = (void *) this->derived; + + double play = 0; + if (this->tyre == FRONTLEFT || this->tyre == FRONTS || this->tyre == ALLFOUR) + { + play += simdata->wheelslip[0]; + } + if (this->tyre == FRONTRIGHT || this->tyre == FRONTS || this->tyre == ALLFOUR) + { + play += simdata->wheelslip[1]; + } + if (this->tyre == REARLEFT || this->tyre == REARS || this->tyre == ALLFOUR) + { + play += simdata->wheelslip[2]; + } + if (this->tyre == REARRIGHT || this->tyre == REARS || this->tyre == ALLFOUR) + { + play += simdata->wheelslip[3]; + } + if (play > 0) + { + sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency * play; + sounddevice->sounddata.curr_duration = sounddevice->sounddata.duration; + } + else + { + sounddevice->sounddata.curr_frequency = 0; + sounddevice->sounddata.curr_duration = 0; + } +} + +int sounddev_absbrakes_update(SimDevice* this, SimData* simdata) +{ + SoundDevice* sounddevice = (void *) this->derived; + + if (simdata->abs > 0) + { + sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency; + sounddevice->sounddata.curr_duration = sounddevice->sounddata.duration; + } + else + { + sounddevice->sounddata.curr_frequency = 0; + sounddevice->sounddata.curr_duration = 0; + } +} + int sounddev_gearshift_update(SimDevice* this, SimData* simdata) { SoundDevice* sounddevice = (void *) this->derived; @@ -90,6 +139,16 @@ int sounddev_init(SoundDevice* sounddevice, const char* devname, int volume, int sounddevice->sounddata.curr_duration = duration; streamname = "Gear"; break; + case (SOUNDEFFECT_TYRESLIP): + sounddevice->sounddata.duration = duration; + sounddevice->sounddata.curr_duration = duration; + streamname = "TyreSlip"; + break; + case (SOUNDEFFECT_ABSBRAKES): + sounddevice->sounddata.duration = duration; + sounddevice->sounddata.curr_duration = duration; + streamname = "ABS"; + break; } #ifdef USE_PULSEAUDIO @@ -105,6 +164,8 @@ int sounddev_init(SoundDevice* sounddevice, const char* devname, int volume, int static const vtable engine_sound_simdevice_vtable = { &sounddev_engine_update, &sounddev_free }; static const vtable gear_sound_simdevice_vtable = { &sounddev_gearshift_update, &sounddev_free }; +static const vtable tyreslip_sound_simdevice_vtable = { &sounddev_tyreslip_update, &sounddev_free }; +static const vtable absbrakes_sound_simdevice_vtable = { &sounddev_absbrakes_update, &sounddev_free }; SoundDevice* new_sound_device(DeviceSettings* ds) { @@ -126,6 +187,16 @@ SoundDevice* new_sound_device(DeviceSettings* ds) { this->m.vtable = &gear_sound_simdevice_vtable; slogi("Initializing sound device for gear shift vibrations."); break; + case (SIMDEVTYPE_TYRESLIP): + this->effecttype = SOUNDEFFECT_TYRESLIP; + this->m.vtable = &tyreslip_sound_simdevice_vtable; + slogi("Initializing sound device for tyre slip vibrations."); + break; + case (SIMDEVTYPE_ABSBRAKES): + this->effecttype = SOUNDEFFECT_ABSBRAKES; + this->m.vtable = &absbrakes_sound_simdevice_vtable; + slogi("Initializing sound device for abs vibrations."); + break; } slogt("Attempting to use device %s", ds->sounddevsettings.dev); diff --git a/src/monocoque/devices/sounddevice.h b/src/monocoque/devices/sounddevice.h index 8019176..ab2783e 100644 --- a/src/monocoque/devices/sounddevice.h +++ b/src/monocoque/devices/sounddevice.h @@ -17,7 +17,9 @@ SoundType; typedef enum { SOUNDEFFECT_ENGINERPM = 0, - SOUNDEFFECT_GEARSHIFT = 1 + SOUNDEFFECT_GEARSHIFT = 1, + SOUNDEFFECT_ABSBRAKES = 2, + SOUNDEFFECT_TYRESLIP = 3 } VibrationEffectType; diff --git a/src/monocoque/helper/confighelper.c b/src/monocoque/helper/confighelper.c index d7e6f18..81d6d4e 100644 --- a/src/monocoque/helper/confighelper.c +++ b/src/monocoque/helper/confighelper.c @@ -91,6 +91,11 @@ int strtodevsubtype(const char* device_subtype, DeviceSettings* ds, int simdev) ds->dev_subtype = SIMDEVTYPE_ABSBRAKES; break; } + if ((strcicmp(device_subtype, "SLIP") == 0) || (strcicmp(device_subtype, "TYRESLIP") == 0)) + { + ds->dev_subtype = SIMDEVTYPE_TYRESLIP; + break; + } default: ds->is_valid = false; slogw("%s does not appear to be a valid device sub type, but attempting to continue with other devices", device_subtype); @@ -274,6 +279,8 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co config_setting_lookup_int(device_settings, "pan", &ds->sounddevsettings.pan); config_setting_lookup_float(device_settings, "duration", &ds->sounddevsettings.duration); + + const char* temp; int found = 0; found = config_setting_lookup_string(device_settings, "devid", &temp); @@ -285,6 +292,38 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co { ds->sounddevsettings.dev = strdup(temp); } + if (ds->dev_subtype == SIMDEVTYPE_TYRESLIP) + { + + found = config_setting_lookup_string(device_settings, "tyre", &temp); + + ds->tyre = ALLFOUR; + + if (strcicmp(temp, "FRONTS") == 0) + { + ds->tyre = FRONTS; + } + if (strcicmp(temp, "REARS") == 0) + { + ds->tyre = REARS; + } + if (strcicmp(temp, "FRONTLEFT") == 0) + { + ds->tyre = FRONTLEFT; + } + if (strcicmp(temp, "FRONTRIGHT") == 0) + { + ds->tyre = FRONTRIGHT; + } + if (strcicmp(temp, "REARLEFT") == 0) + { + ds->tyre = REARLEFT; + } + if (strcicmp(temp, "REARRIGHT") == 0) + { + ds->tyre = REARRIGHT; + } + } } } diff --git a/src/monocoque/helper/confighelper.h b/src/monocoque/helper/confighelper.h index 2478347..240032c 100644 --- a/src/monocoque/helper/confighelper.h +++ b/src/monocoque/helper/confighelper.h @@ -1,6 +1,7 @@ #ifndef _CONFIGHELPER_H #define _CONFIGHELPER_H +#include #include #include @@ -25,7 +26,8 @@ typedef enum SIMDEVTYPE_SIMWIND = 3, SIMDEVTYPE_ENGINESOUND = 4, SIMDEVTYPE_GEARSOUND = 5, - SIMDEVTYPE_ABSBRAKES = 6 + SIMDEVTYPE_ABSBRAKES = 6, + SIMDEVTYPE_TYRESLIP = 7 } DeviceSubType; @@ -52,6 +54,18 @@ typedef enum } MonocoqueError; +typedef enum +{ + FRONTLEFT = 0, + FRONTRIGHT = 1, + REARLEFT = 2, + REARRIGHT = 3, + FRONTS = 4, + REARS = 5, + ALLFOUR = 6 +} +MonocoqueTyreIdentifier; + typedef struct { ProgramAction program_action; @@ -95,6 +109,7 @@ typedef struct TachometerSettings tachsettings; SerialDeviceSettings serialdevsettings; SoundDeviceSettings sounddevsettings; + MonocoqueTyreIdentifier tyre; } DeviceSettings; diff --git a/src/monocoque/simulatorapi/simapi b/src/monocoque/simulatorapi/simapi index 618c6d0..0c9fdd0 160000 --- a/src/monocoque/simulatorapi/simapi +++ b/src/monocoque/simulatorapi/simapi @@ -1 +1 @@ -Subproject commit 618c6d043d88a2d9d04d66c845de2bdbd64b80ca +Subproject commit 0c9fdd01595293984638dbe51519dae08d50949e