Implement tyre locking. Cleanup test gameloop

This commit is contained in:
Paul Dino Jones 2024-05-30 20:39:47 +00:00
parent ac215bfed3
commit 557269c9f5
5 changed files with 110 additions and 20 deletions

View File

@ -71,6 +71,44 @@ int sounddev_tyreslip_update(SimDevice* this, SimData* simdata)
}
}
int sounddev_tyrelock_update(SimDevice* this, SimData* simdata)
{
SoundDevice* sounddevice = (void *) this->derived;
double play = 0;
if (simdata->velocity > 0)
{
if (this->tyre == FRONTLEFT || this->tyre == FRONTS || this->tyre == ALLFOUR)
{
play += simdata->wheelspeed[0];
}
if (this->tyre == FRONTRIGHT || this->tyre == FRONTS || this->tyre == ALLFOUR)
{
play += simdata->wheelspeed[1];
}
if (this->tyre == REARLEFT || this->tyre == REARS || this->tyre == ALLFOUR)
{
play += simdata->wheelspeed[2];
}
if (this->tyre == REARRIGHT || this->tyre == REARS || this->tyre == ALLFOUR)
{
play += simdata->wheelspeed[3];
}
}
if (play > 0)
{
sounddevice->sounddata.curr_frequency = 0;
sounddevice->sounddata.curr_duration = 0;
}
else
{
sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency * play;
sounddevice->sounddata.curr_duration = sounddevice->sounddata.duration;
}
}
int sounddev_absbrakes_update(SimDevice* this, SimData* simdata)
{
SoundDevice* sounddevice = (void *) this->derived;
@ -165,6 +203,7 @@ 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 tyrelock_sound_simdevice_vtable = { &sounddev_tyrelock_update, &sounddev_free };
static const vtable absbrakes_sound_simdevice_vtable = { &sounddev_absbrakes_update, &sounddev_free };
SoundDevice* new_sound_device(DeviceSettings* ds) {
@ -192,6 +231,11 @@ SoundDevice* new_sound_device(DeviceSettings* ds) {
this->m.vtable = &tyreslip_sound_simdevice_vtable;
slogi("Initializing sound device for tyre slip vibrations.");
break;
case (EFFECT_TYRELOCK):
this->effecttype = EFFECT_TYRELOCK;
this->m.vtable = &tyrelock_sound_simdevice_vtable;
slogi("Initializing sound device for tyre slip vibrations.");
break;
case (EFFECT_ABSBRAKES):
this->effecttype = EFFECT_ABSBRAKES;
this->m.vtable = &absbrakes_sound_simdevice_vtable;

View File

@ -11,10 +11,11 @@
int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdata)
{
double play = 0;
double playthreshhold = 0;
switch (usbhapticdevice->effecttype)
{
case (EFFECT_TYRESLIP):
playthreshhold = .4;
if (usbhapticdevice->effecttype == EFFECT_TYRESLIP)
{
if (usbhapticdevice->tyre == FRONTLEFT || usbhapticdevice->tyre == FRONTS || usbhapticdevice->tyre == ALLFOUR)
@ -35,6 +36,47 @@ int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdat
}
}
break;
case (EFFECT_TYRELOCK):
if (simdata->velocity > 0)
{
if (usbhapticdevice->tyre == FRONTLEFT || usbhapticdevice->tyre == FRONTS || usbhapticdevice->tyre == ALLFOUR)
{
play += simdata->wheelspeed[0];
}
if (usbhapticdevice->tyre == FRONTRIGHT || usbhapticdevice->tyre == FRONTS || usbhapticdevice->tyre == ALLFOUR)
{
play += simdata->wheelspeed[1];
}
if (usbhapticdevice->tyre == REARLEFT || usbhapticdevice->tyre == REARS || usbhapticdevice->tyre == ALLFOUR)
{
play += simdata->wheelspeed[2];
}
if (usbhapticdevice->tyre == REARRIGHT || usbhapticdevice->tyre == REARS || usbhapticdevice->tyre == ALLFOUR)
{
play += simdata->wheelspeed[3];
}
}
if (usbhapticdevice->effecttype == EFFECT_TYRELOCK)
{
if (usbhapticdevice->tyre == FRONTLEFT || usbhapticdevice->tyre == FRONTS || usbhapticdevice->tyre == ALLFOUR)
{
play += (1.0 - simdata->wheelslip[0]);
}
if (usbhapticdevice->tyre == FRONTRIGHT || usbhapticdevice->tyre == FRONTS || usbhapticdevice->tyre == ALLFOUR)
{
play += (1.0 - simdata->wheelslip[1]);
}
if (usbhapticdevice->tyre == REARLEFT || usbhapticdevice->tyre == REARS || usbhapticdevice->tyre == ALLFOUR)
{
play += (1.0 - simdata->wheelslip[2]);
}
if (usbhapticdevice->tyre == REARRIGHT || usbhapticdevice->tyre == REARS || usbhapticdevice->tyre == ALLFOUR)
{
play += (1.0 - simdata->wheelslip[3]);
}
}
break;
case (EFFECT_ABSBRAKES):
play += simdata->abs;
break;
@ -42,7 +84,7 @@ int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdat
if (play != usbhapticdevice->state)
{
if(play > .40)
if(play > playthreshhold)
{
fprintf(usbhapticdevice->handle, "%i\n", usbhapticdevice->value1);
fflush(usbhapticdevice->handle);
@ -90,9 +132,9 @@ int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* d
{
usbhapticdevice->effecttype = EFFECT_TYRESLIP;
}
if(ds->effect_type == EFFECT_WHEELLOCK)
if(ds->effect_type == EFFECT_TYRELOCK)
{
usbhapticdevice->effecttype = EFFECT_WHEELLOCK;
usbhapticdevice->effecttype = EFFECT_TYRELOCK;
}
return error;

View File

@ -328,6 +328,10 @@ int tester(SimDevice* devices, int numdevices)
simdata->wheelslip[1] = 1;
simdata->wheelslip[2] = 1;
simdata->wheelslip[3] = 1;
simdata->wheelspeed[0] = 100;
simdata->wheelspeed[1] = 100;
simdata->wheelspeed[2] = 100;
simdata->wheelspeed[3] = 100;
sleep(3);
fprintf(stdout, "Setting rpms to 1000\n");
@ -368,10 +372,6 @@ int tester(SimDevice* devices, int numdevices)
{
devices[x].update(&devices[x], simdata);
}
for (int x = 0; x < numdevices; x++)
{
devices[x].update(&devices[x], simdata);
}
sleep(3);
fprintf(stdout, "Setting speed to 100\n");
@ -388,10 +388,6 @@ int tester(SimDevice* devices, int numdevices)
{
devices[x].update(&devices[x], simdata);
}
for (int x = 0; x < numdevices; x++)
{
devices[x].update(&devices[x], simdata);
}
sleep(3);
fprintf(stdout, "Setting speed to 200\n");
@ -402,12 +398,24 @@ int tester(SimDevice* devices, int numdevices)
}
sleep(3);
fprintf(stdout, "Shifting into third gear\n");
simdata->gear = 4;
fprintf(stdout, "Setting Wheelspeed to 0, wheels locked at speed.\n");
simdata->wheelspeed[0] = 0;
simdata->wheelspeed[1] = 0;
simdata->wheelspeed[2] = 0;
simdata->wheelspeed[3] = 0;
for (int x = 0; x < numdevices; x++)
{
devices[x].update(&devices[x], simdata);
}
sleep(3);
simdata->wheelspeed[0] = 100;
simdata->wheelspeed[1] = 100;
simdata->wheelspeed[2] = 100;
simdata->wheelspeed[3] = 100;
fprintf(stdout, "Shifting into third gear\n");
simdata->gear = 4;
for (int x = 0; x < numdevices; x++)
{
devices[x].update(&devices[x], simdata);
@ -436,10 +444,6 @@ int tester(SimDevice* devices, int numdevices)
{
devices[x].update(&devices[x], simdata);
}
for (int x = 0; x < numdevices; x++)
{
devices[x].update(&devices[x], simdata);
}
sleep(3);
fprintf(stdout, "Setting speed to 300\n");

View File

@ -353,7 +353,7 @@ 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_WHEELLOCK)
if (ds->effect_type == EFFECT_TYRESLIP || ds->effect_type == EFFECT_TYRELOCK)
{
gettyre(device_settings, ds);
}

View File

@ -46,7 +46,7 @@ typedef enum
EFFECT_GEARSHIFT = 1,
EFFECT_ABSBRAKES = 2,
EFFECT_TYRESLIP = 3,
EFFECT_WHEELLOCK = 4
EFFECT_TYRELOCK = 4
}
VibrationEffectType;