Improved gameloop for serial devices. More simwind hacks
This commit is contained in:
parent
0d4a1fae1c
commit
978c607d66
|
|
@ -2,6 +2,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "simdevice.h"
|
||||
#include "serialdevice.h"
|
||||
|
|
@ -18,7 +19,19 @@ int serialdev_update(SimDevice* this, SimData* simdata)
|
|||
// the arduino will use mph as speed in my code
|
||||
// 255 is a good max top speed in mph
|
||||
double velocity = simdata->velocity;
|
||||
simdata->velocity = simdata->velocity * 0.6213712;
|
||||
if (simdata->velocity > 10)
|
||||
{
|
||||
simdata->velocity = ceil(simdata->velocity * 0.6213712);
|
||||
slogi("trying to set velocity %i", simdata->velocity);
|
||||
}
|
||||
else
|
||||
{
|
||||
simdata->velocity = 0;
|
||||
}
|
||||
if (simdata->velocity >= 255)
|
||||
{
|
||||
simdata->velocity = 255;
|
||||
}
|
||||
|
||||
arduino_update(serialdevice, simdata);
|
||||
simdata->velocity = velocity;
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds)
|
|||
if (sim != NULL)
|
||||
{
|
||||
simdevices[j].initialized = true;
|
||||
simdevices[j].type = SIMDEV_USB;
|
||||
simdevices[j] = sim->m;
|
||||
devices++;
|
||||
}
|
||||
|
|
@ -74,6 +75,7 @@ int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds)
|
|||
{
|
||||
|
||||
simdevices[j].initialized = true;
|
||||
simdevices[j].type = SIMDEV_SOUND;
|
||||
simdevices[j] = sim->m;
|
||||
devices++;
|
||||
}
|
||||
|
|
@ -90,6 +92,7 @@ int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds)
|
|||
{
|
||||
|
||||
simdevices[j].initialized = true;
|
||||
simdevices[j].type = SIMDEV_SERIAL;
|
||||
simdevices[j] = sim->m;
|
||||
devices++;
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@
|
|||
#include "../simulatorapi/simmapper.h"
|
||||
#include "../slog/slog.h"
|
||||
|
||||
#define DEFAULT_UPDATE_RATE 120.0
|
||||
#define DEFAULT_UPDATE_RATE 30.0
|
||||
#define SERIAL_UPDATE_RATE 60.0
|
||||
|
||||
int showstats(SimData* simdata)
|
||||
{
|
||||
|
|
@ -191,6 +192,7 @@ int looper(SimDevice* devices, int numdevices, Simulator simulator)
|
|||
|
||||
double update_rate = DEFAULT_UPDATE_RATE;
|
||||
int t=0;
|
||||
int s=0;
|
||||
int go = true;
|
||||
while (go == true)
|
||||
{
|
||||
|
|
@ -205,7 +207,7 @@ int looper(SimDevice* devices, int numdevices, Simulator simulator)
|
|||
{
|
||||
if (devices[x].type == SIMDEV_SERIAL)
|
||||
{
|
||||
if(t>=update_rate)
|
||||
if(s>=4)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
|
|
@ -220,6 +222,10 @@ int looper(SimDevice* devices, int numdevices, Simulator simulator)
|
|||
{
|
||||
t=0;
|
||||
}
|
||||
if(s>=4)
|
||||
{
|
||||
s=0;
|
||||
}
|
||||
if( poll(&mypoll, 1, 1000.0/update_rate) )
|
||||
{
|
||||
scanf("%c", &ch);
|
||||
|
|
@ -233,6 +239,13 @@ int looper(SimDevice* devices, int numdevices, Simulator simulator)
|
|||
fflush(stdout);
|
||||
tcsetattr(0, TCSANOW, &canonicalmode);
|
||||
|
||||
simdata->velocity = 0;
|
||||
simdata->rpms = 100;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
|
||||
free(simdata);
|
||||
free(simmap);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue