Add attempt at ABS effect. Small refactorings
This commit is contained in:
parent
4530627fc2
commit
8cbc21b1a0
|
|
@ -42,7 +42,7 @@ void getTyreDiameter(SimData* simdata)
|
|||
}
|
||||
|
||||
|
||||
int slipeffect(SimData* simdata, int effecttype, int tyre, double threshold)
|
||||
int slipeffect(SimData* simdata, int effecttype, int tyre, double threshold, int* configcheck)
|
||||
{
|
||||
int play = 0;
|
||||
double wheelslip[4];
|
||||
|
|
@ -60,7 +60,12 @@ int slipeffect(SimData* simdata, int effecttype, int tyre, double threshold)
|
|||
|
||||
if(hasTyreDiameter(simdata)==false)
|
||||
{
|
||||
// check for saved tyre diameter in config file
|
||||
// if not saved version exists get tyre diameter and save it
|
||||
// use config check variable to track if the config check has been performed
|
||||
// avoid many opens of the same file
|
||||
getTyreDiameter(simdata);
|
||||
*configcheck = 1;
|
||||
}
|
||||
if(hasTyreDiameter(simdata)==true)
|
||||
{
|
||||
|
|
@ -152,6 +157,39 @@ int slipeffect(SimData* simdata, int effecttype, int tyre, double threshold)
|
|||
|
||||
break;
|
||||
case (EFFECT_ABSBRAKES):
|
||||
threshold = simdata->abs + threshold;
|
||||
if (tyre == FRONTLEFT || tyre == FRONTS || tyre == ALLFOUR)
|
||||
{
|
||||
if(wheelslip[0] > threshold)
|
||||
{
|
||||
play++;
|
||||
}
|
||||
}
|
||||
if (tyre == FRONTRIGHT || tyre == FRONTS || tyre == ALLFOUR)
|
||||
{
|
||||
if(wheelslip[1] > threshold)
|
||||
{
|
||||
play++;
|
||||
}
|
||||
}
|
||||
if (tyre == REARLEFT || tyre == REARS || tyre == ALLFOUR)
|
||||
{
|
||||
if(wheelslip[2] > threshold)
|
||||
{
|
||||
play++;
|
||||
}
|
||||
}
|
||||
if (tyre == REARRIGHT || tyre == REARS || tyre == ALLFOUR)
|
||||
{
|
||||
if(wheelslip[3] > threshold)
|
||||
{
|
||||
play++;
|
||||
}
|
||||
}
|
||||
if(simdata->abs <= 0)
|
||||
{
|
||||
play = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@
|
|||
|
||||
#include "../simulatorapi/simapi/simapi/simdata.h"
|
||||
|
||||
int slipeffect(SimData* simdata, int effecttype, int tyre, double threshold);
|
||||
int slipeffect(SimData* simdata, int effecttype, int tyre, double threshold, int* configcheck);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds)
|
|||
//simdevices[j].initialized = true;
|
||||
simdevices[j].type = SIMDEV_USB;
|
||||
simdevices[j].tyre = ds[j].tyre;
|
||||
simdevices[j].configcheck = 0;
|
||||
devices++;
|
||||
}
|
||||
else
|
||||
|
|
@ -59,6 +60,7 @@ int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds)
|
|||
simdevices[j].initialized = true;
|
||||
simdevices[j].type = SIMDEV_SOUND;
|
||||
simdevices[j].tyre = ds[j].tyre;
|
||||
simdevices[j].configcheck = 0;
|
||||
devices++;
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -23,7 +23,9 @@ struct SimDevice
|
|||
int id;
|
||||
bool initialized;
|
||||
DeviceType type;
|
||||
// possibly move these to a haptic effect struct
|
||||
MonocoqueTyreIdentifier tyre;
|
||||
int configcheck;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -94,6 +96,7 @@ typedef struct
|
|||
SimDevice m;
|
||||
int id;
|
||||
SoundType type;
|
||||
int configcheck;
|
||||
VibrationEffectType effecttype;
|
||||
double slipthreshold;
|
||||
SoundData sounddata;
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ int sounddev_tyreslip_update(SimDevice* this, SimData* simdata)
|
|||
{
|
||||
SoundDevice* sounddevice = (void *) this->derived;
|
||||
|
||||
int play = slipeffect(simdata, sounddevice->effecttype, this->tyre, sounddevice->slipthreshold);
|
||||
int play = slipeffect(simdata, sounddevice->effecttype, this->tyre, sounddevice->slipthreshold, &this->configcheck);
|
||||
|
||||
if (play > 0)
|
||||
{
|
||||
|
|
@ -60,7 +60,7 @@ int sounddev_tyrelock_update(SimDevice* this, SimData* simdata)
|
|||
{
|
||||
SoundDevice* sounddevice = (void *) this->derived;
|
||||
|
||||
int play = slipeffect(simdata, sounddevice->effecttype, this->tyre, sounddevice->slipthreshold);
|
||||
int play = slipeffect(simdata, sounddevice->effecttype, this->tyre, sounddevice->slipthreshold, &this->configcheck);
|
||||
|
||||
if (play > 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ typedef struct
|
|||
int last_gear;
|
||||
int volume;
|
||||
int frequency;
|
||||
|
||||
double duration;
|
||||
int curr_frequency;
|
||||
double curr_duration;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ int usbdev_update(SimDevice* this, SimData* simdata)
|
|||
tachdev_update(&usbdevice->u.tachdevice, simdata);
|
||||
break;
|
||||
case USBDEV_GENERICHAPTIC :
|
||||
usbhapticdev_update(&usbdevice->u.hapticdevice, simdata);
|
||||
usbhapticdev_update(&usbdevice->u.hapticdevice, simdata, this->tyre, &this->configcheck);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,10 +11,10 @@
|
|||
#include "../../slog/slog.h"
|
||||
|
||||
|
||||
int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdata)
|
||||
int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdata, int tyre, int* configcheck)
|
||||
{
|
||||
|
||||
int play = slipeffect(simdata, usbhapticdevice->effecttype, usbhapticdevice->tyre, usbhapticdevice->threshold);
|
||||
int play = slipeffect(simdata, usbhapticdevice->effecttype, tyre, usbhapticdevice->threshold, configcheck);
|
||||
|
||||
if (play != usbhapticdevice->state)
|
||||
{
|
||||
|
|
@ -45,7 +45,6 @@ int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* d
|
|||
usbhapticdevice->value0 = ds->usbdevsettings.value0;
|
||||
usbhapticdevice->value1 = ds->usbdevsettings.value1;
|
||||
usbhapticdevice->state = usbhapticdevice->value0;
|
||||
usbhapticdevice->tyre = ds->tyre;
|
||||
usbhapticdevice->effecttype = ds->effect_type;
|
||||
usbhapticdevice->threshold = ds->threshold;
|
||||
|
||||
|
|
@ -57,6 +56,10 @@ int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* d
|
|||
{
|
||||
usbhapticdevice->effecttype = EFFECT_TYRELOCK;
|
||||
}
|
||||
if(ds->effect_type == EFFECT_ABSBRAKES)
|
||||
{
|
||||
usbhapticdevice->effecttype = EFFECT_ABSBRAKES;
|
||||
}
|
||||
|
||||
slogi("initializing standalone usb haptic device...");
|
||||
// detection of usb device model
|
||||
|
|
@ -70,14 +73,5 @@ int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* d
|
|||
return error;
|
||||
}
|
||||
|
||||
if(ds->effect_type == EFFECT_TYRESLIP)
|
||||
{
|
||||
usbhapticdevice->effecttype = EFFECT_TYRESLIP;
|
||||
}
|
||||
if(ds->effect_type == EFFECT_TYRELOCK)
|
||||
{
|
||||
usbhapticdevice->effecttype = EFFECT_TYRELOCK;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,14 +22,13 @@ typedef struct
|
|||
int value0;
|
||||
int value1;
|
||||
VibrationEffectType effecttype;
|
||||
MonocoqueTyreIdentifier tyre;
|
||||
FILE* handle;
|
||||
char* dev;
|
||||
}
|
||||
USBGenericHapticDevice;
|
||||
|
||||
|
||||
int usbhapticdev_update(USBGenericHapticDevice* hapticdevice, SimData* simdata);
|
||||
int usbhapticdev_update(USBGenericHapticDevice* hapticdevice, SimData* simdata, int tyre, int* configcheck);
|
||||
int usbhapticdev_init(USBGenericHapticDevice* hapticdevice, DeviceSettings* ds);
|
||||
int usbhapticdev_free(USBGenericHapticDevice* hapticdevice);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue