Refactor tyre effects to take threshold input from config file. Spell threshold correctly.

This commit is contained in:
Paul Dino Jones 2024-06-05 04:21:39 +00:00
parent 6c17c56813
commit b99773a7ee
9 changed files with 36 additions and 21 deletions

View File

@ -42,7 +42,7 @@ void getTyreDiameter(SimData* simdata)
}
int slipeffect(SimData* simdata, int effecttype, int tyre, double threshhold)
int slipeffect(SimData* simdata, int effecttype, int tyre, double threshold)
{
int play = 0;
double wheelslip[4];
@ -91,28 +91,28 @@ int slipeffect(SimData* simdata, int effecttype, int tyre, double threshhold)
if (tyre == FRONTLEFT || tyre == FRONTS || tyre == ALLFOUR)
{
if(wheelslip[0] < -.5)
if(wheelslip[0] < -threshold)
{
play++;
}
}
if (tyre == FRONTRIGHT || tyre == FRONTS || tyre == ALLFOUR)
{
if(wheelslip[1] < -.5)
if(wheelslip[1] < -threshold)
{
play++;
}
}
if (tyre == REARLEFT || tyre == REARS || tyre == ALLFOUR)
{
if(wheelslip[2] < -.5)
if(wheelslip[2] < -threshold)
{
play++;
}
}
if (tyre == REARRIGHT || tyre == REARS || tyre == ALLFOUR)
{
if(wheelslip[3] < -.5)
if(wheelslip[3] < -threshold)
{
play++;
}
@ -123,28 +123,28 @@ int slipeffect(SimData* simdata, int effecttype, int tyre, double threshhold)
case (EFFECT_TYRELOCK):
if (tyre == FRONTLEFT || tyre == FRONTS || tyre == ALLFOUR)
{
if(wheelslip[0] > .75)
if(wheelslip[0] > threshold)
{
play++;
}
}
if (tyre == FRONTRIGHT || tyre == FRONTS || tyre == ALLFOUR)
{
if(wheelslip[1] > .75)
if(wheelslip[1] > threshold)
{
play++;
}
}
if (tyre == REARLEFT || tyre == REARS || tyre == ALLFOUR)
{
if(wheelslip[2] > .75)
if(wheelslip[2] > threshold)
{
play++;
}
}
if (tyre == REARRIGHT || tyre == REARS || tyre == ALLFOUR)
{
if(wheelslip[3] > .75)
if(wheelslip[3] > threshold)
{
play++;
}

View File

@ -3,6 +3,6 @@
#include "../simulatorapi/simapi/simapi/simdata.h"
int slipeffect(SimData* simdata, int effecttype, int tyre, double threshhold);
int slipeffect(SimData* simdata, int effecttype, int tyre, double threshold);
#endif

View File

@ -95,6 +95,7 @@ typedef struct
int id;
SoundType type;
VibrationEffectType effecttype;
double slipthreshold;
SoundData sounddata;
#ifdef USE_PULSEAUDIO
pa_stream *stream;

View File

@ -14,8 +14,6 @@
#include "../helper/parameters.h"
#include "../slog/slog.h"
#define slipthreshold 0.75
int gear_sound_set(SoundDevice* sounddevice, SimData* simdata)
{
if (sounddevice->sounddata.last_gear != simdata->gear && simdata->gear > 1)
@ -44,7 +42,7 @@ int sounddev_tyreslip_update(SimDevice* this, SimData* simdata)
{
SoundDevice* sounddevice = (void *) this->derived;
int play = slipeffect(simdata, sounddevice->effecttype, this->tyre, slipthreshold);
int play = slipeffect(simdata, sounddevice->effecttype, this->tyre, sounddevice->slipthreshold);
if (play > 0)
{
@ -62,7 +60,7 @@ int sounddev_tyrelock_update(SimDevice* this, SimData* simdata)
{
SoundDevice* sounddevice = (void *) this->derived;
int play = slipeffect(simdata, sounddevice->effecttype, this->tyre, slipthreshold);
int play = slipeffect(simdata, sounddevice->effecttype, this->tyre, sounddevice->slipthreshold);
if (play > 0)
{
@ -110,7 +108,7 @@ int sounddev_free(SimDevice* this)
return 0;
}
int sounddev_init(SoundDevice* sounddevice, const char* devname, int volume, int frequency, int pan, double duration)
int sounddev_init(SoundDevice* sounddevice, const char* devname, int volume, int frequency, int pan, double duration, double threshold)
{
slogi("initializing standalone sound device...");
@ -147,8 +145,15 @@ int sounddev_init(SoundDevice* sounddevice, const char* devname, int volume, int
case (EFFECT_TYRESLIP):
sounddevice->sounddata.duration = duration;
sounddevice->sounddata.curr_duration = duration;
sounddevice->slipthreshold = threshold;
streamname = "TyreSlip";
break;
case (EFFECT_TYRELOCK):
sounddevice->sounddata.duration = duration;
sounddevice->sounddata.curr_duration = duration;
sounddevice->slipthreshold = threshold;
streamname = "TyreLock";
break;
case (EFFECT_ABSBRAKES):
sounddevice->sounddata.duration = duration;
sounddevice->sounddata.curr_duration = duration;
@ -212,7 +217,7 @@ SoundDevice* new_sound_device(DeviceSettings* ds) {
slogt("Attempting to use device %s", ds->sounddevsettings.dev);
int error = sounddev_init(this, ds->sounddevsettings.dev, ds->sounddevsettings.volume, ds->sounddevsettings.frequency, ds->sounddevsettings.pan, ds->sounddevsettings.duration);
int error = sounddev_init(this, ds->sounddevsettings.dev, ds->sounddevsettings.volume, ds->sounddevsettings.frequency, ds->sounddevsettings.pan, ds->sounddevsettings.duration, ds->threshold);
if (error != 0)
{
free(this);

View File

@ -20,6 +20,7 @@ typedef struct
int last_gear;
int volume;
int frequency;
double duration;
int curr_frequency;
double curr_duration;

View File

@ -9,12 +9,11 @@
#include "../../simulatorapi/simapi/simapi/simdata.h"
#include "../../slog/slog.h"
#define slipthreshold 0.75
int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdata)
{
int play = slipeffect(simdata, usbhapticdevice->effecttype, usbhapticdevice->tyre, slipthreshold);
int play = slipeffect(simdata, usbhapticdevice->effecttype, usbhapticdevice->tyre, usbhapticdevice->threshold);
if (play != usbhapticdevice->state)
@ -54,6 +53,7 @@ int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* d
usbhapticdevice->state = usbhapticdevice->value0;
usbhapticdevice->tyre = ds->tyre;
usbhapticdevice->effecttype = ds->effect_type;
usbhapticdevice->threshold = ds->threshold;
usbhapticdevice->handle = fopen(usbhapticdevice->dev, "w");
if(usbhapticdevice->handle == 0)

View File

@ -18,6 +18,7 @@ typedef struct
int id;
HapticType type;
double state;
double threshold;
int value0;
int value1;
VibrationEffectType effecttype;

View File

@ -1,3 +1,4 @@
#include <dirent.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
@ -357,11 +358,13 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
const char* effect;
config_setting_lookup_string(device_settings, "effect", &effect);
strtoeffecttype(effect, ds);
if (ds->effect_type == EFFECT_TYRESLIP || ds->effect_type == EFFECT_TYRELOCK)
if (ds->effect_type == EFFECT_TYRESLIP || ds->effect_type == EFFECT_TYRELOCK || ds->effect_type == EFFECT_ABSBRAKES)
{
gettyre(device_settings, ds);
ds->threshold = .75;
int found = config_setting_lookup_float(device_settings, "threshold", &ds->threshold);
}
if (ds->dev_type == SIMDEV_SOUND)
{
slogi("reading configured sound device settings");

View File

@ -121,13 +121,17 @@ typedef struct
bool is_valid;
DeviceType dev_type;
DeviceSubType dev_subtype;
// to get really fancy move the effect information to it's own structure that would be a member of
// any device settings member structure that can carry an effect
VibrationEffectType effect_type;
MonocoqueTyreIdentifier tyre;
double threshold;
// union?
TachometerSettings tachsettings;
SerialDeviceSettings serialdevsettings;
SoundDeviceSettings sounddevsettings;
USBDeviceSettings usbdevsettings;
MonocoqueTyreIdentifier tyre;
}
DeviceSettings;