Use new simapi to get sim automatically. Use light version of simapi
This commit is contained in:
parent
257e6d7f8a
commit
3692d31343
|
|
@ -30,7 +30,8 @@ int devfree(SimDevice* simdevices, int numdevices)
|
||||||
slogi("freeing %i simdevices...", numdevices);
|
slogi("freeing %i simdevices...", numdevices);
|
||||||
int devices = 0;
|
int devices = 0;
|
||||||
|
|
||||||
for (int j = 0; j < numdevices; j++)
|
int freed = 0;
|
||||||
|
for (int j = 0; j < 1; j++)
|
||||||
{
|
{
|
||||||
SimDevice simdev = simdevices[j];
|
SimDevice simdev = simdevices[j];
|
||||||
if (simdev.initialized == true)
|
if (simdev.initialized == true)
|
||||||
|
|
@ -39,7 +40,7 @@ int devfree(SimDevice* simdevices, int numdevices)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(simdevices);
|
//free(simdevices);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
@ -15,6 +16,7 @@
|
||||||
#include "../slog/slog.h"
|
#include "../slog/slog.h"
|
||||||
|
|
||||||
#define DEFAULT_UPDATE_RATE 240.0
|
#define DEFAULT_UPDATE_RATE 240.0
|
||||||
|
#define SIM_CHECK_RATE 1.0
|
||||||
|
|
||||||
int showstats(SimData* simdata)
|
int showstats(SimData* simdata)
|
||||||
{
|
{
|
||||||
|
|
@ -165,19 +167,12 @@ int showstats(SimData* simdata)
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
int looper(SimDevice* devices, int numdevices, Simulator simulator)
|
|
||||||
|
int clilooper(SimDevice* devices, int numdevices, Parameters* p, SimData* simdata, SimMap* simmap)
|
||||||
{
|
{
|
||||||
|
|
||||||
slogi("preparing game loop with %i devices...", numdevices);
|
slogi("preparing game loop with %i devices...", numdevices);
|
||||||
SimData* simdata = malloc(sizeof(SimData));
|
|
||||||
SimMap* simmap = malloc(sizeof(SimMap));
|
|
||||||
|
|
||||||
int error = siminit(simdata, simmap, simulator);
|
|
||||||
|
|
||||||
if (error != MONOCOQUE_ERROR_NONE)
|
|
||||||
{
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
slogi("sending initial data to devices");
|
slogi("sending initial data to devices");
|
||||||
simdata->velocity = 16;
|
simdata->velocity = 16;
|
||||||
|
|
@ -204,7 +199,7 @@ int looper(SimDevice* devices, int numdevices, Simulator simulator)
|
||||||
int go = true;
|
int go = true;
|
||||||
while (go == true)
|
while (go == true)
|
||||||
{
|
{
|
||||||
simdatamap(simdata, simmap, simulator);
|
simdatamap(simdata, simmap, p->sim);
|
||||||
showstats(simdata);
|
showstats(simdata);
|
||||||
t++;
|
t++;
|
||||||
s++;
|
s++;
|
||||||
|
|
@ -237,6 +232,67 @@ int looper(SimDevice* devices, int numdevices, Simulator simulator)
|
||||||
devices[x].update(&devices[x], simdata);
|
devices[x].update(&devices[x], simdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int looper(SimDevice* devices, int numdevices, Parameters* p)
|
||||||
|
{
|
||||||
|
|
||||||
|
SimData* simdata = malloc(sizeof(SimData));
|
||||||
|
SimMap* simmap = malloc(sizeof(SimMap));
|
||||||
|
|
||||||
|
struct termios newsettings, canonicalmode;
|
||||||
|
tcgetattr(0, &canonicalmode);
|
||||||
|
newsettings = canonicalmode;
|
||||||
|
newsettings.c_lflag &= (~ICANON & ~ECHO);
|
||||||
|
newsettings.c_cc[VMIN] = 1;
|
||||||
|
newsettings.c_cc[VTIME] = 0;
|
||||||
|
tcsetattr(0, TCSANOW, &newsettings);
|
||||||
|
char ch;
|
||||||
|
struct pollfd mypoll = { STDIN_FILENO, POLLIN|POLLPRI };
|
||||||
|
|
||||||
|
fprintf(stdout, "Searching for sim data... Press q to quit...\n");
|
||||||
|
|
||||||
|
p->simon = false;
|
||||||
|
double update_rate = SIM_CHECK_RATE;
|
||||||
|
int go = true;
|
||||||
|
while (go == true)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (p->simon == false)
|
||||||
|
{
|
||||||
|
getSim(simdata, simmap, &p->simon, &p->sim);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p->simon == true)
|
||||||
|
{
|
||||||
|
clilooper(devices, numdevices, p, simdata, simmap);
|
||||||
|
}
|
||||||
|
if (p->simon == true)
|
||||||
|
{
|
||||||
|
p->simon = false;
|
||||||
|
fprintf(stdout, "Searching for sim data... Press q again to quit...\n");
|
||||||
|
sleep(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if( poll(&mypoll, 1, 1000.0/update_rate) )
|
||||||
|
{
|
||||||
|
scanf("%c", &ch);
|
||||||
|
if(ch == 'q')
|
||||||
|
{
|
||||||
|
go = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stdout, "\n");
|
||||||
|
fflush(stdout);
|
||||||
|
tcsetattr(0, TCSANOW, &canonicalmode);
|
||||||
|
|
||||||
free(simdata);
|
free(simdata);
|
||||||
free(simmap);
|
free(simmap);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,4 @@
|
||||||
#include "../helper/parameters.h"
|
#include "../helper/parameters.h"
|
||||||
|
|
||||||
int tester(SimDevice* devices, int numdevices);
|
int tester(SimDevice* devices, int numdevices);
|
||||||
int looper (SimDevice* devices, int numdevices, Simulator simulator);
|
int looper(SimDevice* devices, int numdevices, Parameters* p);
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ int strtogame(const char* game, MonocoqueSettings* ms)
|
||||||
if (strcicmp(game, "test") == 0)
|
if (strcicmp(game, "test") == 0)
|
||||||
{
|
{
|
||||||
slogd("Setting simulator to Test Data");
|
slogd("Setting simulator to Test Data");
|
||||||
ms->sim_name = SIMULATOR_MONOCOQUE_TEST;
|
ms->sim_name = SIMULATOR_SIMAPI_TEST;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -28,14 +28,6 @@ typedef enum
|
||||||
}
|
}
|
||||||
DeviceSubType;
|
DeviceSubType;
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
SIMULATOR_MONOCOQUE_TEST = 0,
|
|
||||||
SIMULATOR_ASSETTO_CORSA = 1,
|
|
||||||
SIMULATOR_RFACTOR = 2,
|
|
||||||
SIMULATOR_RFACTOR2 = 3
|
|
||||||
}
|
|
||||||
Simulator;
|
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
#ifndef _PARAMETERS_H
|
#ifndef _PARAMETERS_H
|
||||||
#define _PARAMETERS_H
|
#define _PARAMETERS_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include "../simulatorapi/simapi/simapi/simapi.h"
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int program_action;
|
int program_action;
|
||||||
|
|
@ -9,6 +12,9 @@ typedef struct
|
||||||
int max_revs;
|
int max_revs;
|
||||||
int granularity;
|
int granularity;
|
||||||
int verbosity_count;
|
int verbosity_count;
|
||||||
|
|
||||||
|
Simulator sim;
|
||||||
|
bool simon;
|
||||||
}
|
}
|
||||||
Parameters;
|
Parameters;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
error = MONOCOQUE_ERROR_NONE;
|
error = MONOCOQUE_ERROR_NONE;
|
||||||
DeviceSettings settings;
|
DeviceSettings settings;
|
||||||
ds[i] = settings;
|
|
||||||
config_setting_t* config_device = config_setting_get_elem(config_devices, i);
|
config_setting_t* config_device = config_setting_get_elem(config_devices, i);
|
||||||
const char* device_type;
|
const char* device_type;
|
||||||
const char* device_subtype;
|
const char* device_subtype;
|
||||||
|
|
@ -164,12 +164,13 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
if (error == MONOCOQUE_ERROR_NONE)
|
if (error == MONOCOQUE_ERROR_NONE)
|
||||||
{
|
{
|
||||||
error = devsetup(device_type, device_subtype, device_config_file, ms, &ds[i], config_device);
|
error = devsetup(device_type, device_subtype, device_config_file, ms, &settings, config_device);
|
||||||
}
|
}
|
||||||
if (error == MONOCOQUE_ERROR_NONE)
|
if (error == MONOCOQUE_ERROR_NONE)
|
||||||
{
|
{
|
||||||
numdevices++;
|
numdevices++;
|
||||||
}
|
}
|
||||||
|
ds[i] = settings;
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
|
|
@ -183,15 +184,15 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
if (p->program_action == A_PLAY)
|
if (p->program_action == A_PLAY)
|
||||||
{
|
{
|
||||||
slogi("running monocoque in gameloop mode..");
|
//slogi("running monocoque in gameloop mode..");
|
||||||
error = strtogame(p->sim_string, ms);
|
//error = strtogame(p->sim_string, ms);
|
||||||
if (error != MONOCOQUE_ERROR_NONE)
|
//if (error != MONOCOQUE_ERROR_NONE)
|
||||||
{
|
//{
|
||||||
goto cleanup_final;
|
// goto cleanup_final;
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
error = looper(devices, initdevices, ms->sim_name);
|
error = looper(devices, initdevices, p);
|
||||||
if (error == MONOCOQUE_ERROR_NONE)
|
if (error == MONOCOQUE_ERROR_NONE)
|
||||||
{
|
{
|
||||||
slogi("Game loop exited succesfully with error code: %i", error);
|
slogi("Game loop exited succesfully with error code: %i", error);
|
||||||
|
|
|
||||||
|
|
@ -13,4 +13,3 @@ set(simulatorapi_source_files
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(simulatorapi STATIC ${simulatorapi_source_files})
|
add_library(simulatorapi STATIC ${simulatorapi_source_files})
|
||||||
target_compile_definitions(simulatorapi PRIVATE SIMMAP_ALL)
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue