Use new simapi to get sim automatically. Use light version of simapi

This commit is contained in:
Paul Dino Jones 2023-07-14 22:11:01 +00:00
parent 257e6d7f8a
commit 3692d31343
8 changed files with 87 additions and 32 deletions

View File

@ -30,7 +30,8 @@ int devfree(SimDevice* simdevices, int numdevices)
slogi("freeing %i simdevices...", numdevices);
int devices = 0;
for (int j = 0; j < numdevices; j++)
int freed = 0;
for (int j = 0; j < 1; j++)
{
SimDevice simdev = simdevices[j];
if (simdev.initialized == true)
@ -39,7 +40,7 @@ int devfree(SimDevice* simdevices, int numdevices)
}
}
free(simdevices);
//free(simdevices);
return 0;
}

View File

@ -1,3 +1,4 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -15,6 +16,7 @@
#include "../slog/slog.h"
#define DEFAULT_UPDATE_RATE 240.0
#define SIM_CHECK_RATE 1.0
int showstats(SimData* simdata)
{
@ -165,19 +167,12 @@ int showstats(SimData* simdata)
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);
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");
simdata->velocity = 16;
@ -204,7 +199,7 @@ int looper(SimDevice* devices, int numdevices, Simulator simulator)
int go = true;
while (go == true)
{
simdatamap(simdata, simmap, simulator);
simdatamap(simdata, simmap, p->sim);
showstats(simdata);
t++;
s++;
@ -237,6 +232,67 @@ int looper(SimDevice* devices, int numdevices, Simulator simulator)
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(simmap);

View File

@ -2,4 +2,4 @@
#include "../helper/parameters.h"
int tester(SimDevice* devices, int numdevices);
int looper (SimDevice* devices, int numdevices, Simulator simulator);
int looper(SimDevice* devices, int numdevices, Parameters* p);

View File

@ -40,7 +40,7 @@ int strtogame(const char* game, MonocoqueSettings* ms)
if (strcicmp(game, "test") == 0)
{
slogd("Setting simulator to Test Data");
ms->sim_name = SIMULATOR_MONOCOQUE_TEST;
ms->sim_name = SIMULATOR_SIMAPI_TEST;
}
else
{

View File

@ -28,14 +28,6 @@ typedef enum
}
DeviceSubType;
typedef enum
{
SIMULATOR_MONOCOQUE_TEST = 0,
SIMULATOR_ASSETTO_CORSA = 1,
SIMULATOR_RFACTOR = 2,
SIMULATOR_RFACTOR2 = 3
}
Simulator;
typedef enum
{

View File

@ -1,6 +1,9 @@
#ifndef _PARAMETERS_H
#define _PARAMETERS_H
#include <stdbool.h>
#include "../simulatorapi/simapi/simapi/simapi.h"
typedef struct
{
int program_action;
@ -9,6 +12,9 @@ typedef struct
int max_revs;
int granularity;
int verbosity_count;
Simulator sim;
bool simon;
}
Parameters;

View File

@ -153,7 +153,7 @@ int main(int argc, char** argv)
{
error = MONOCOQUE_ERROR_NONE;
DeviceSettings settings;
ds[i] = settings;
config_setting_t* config_device = config_setting_get_elem(config_devices, i);
const char* device_type;
const char* device_subtype;
@ -164,12 +164,13 @@ int main(int argc, char** argv)
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)
{
numdevices++;
}
ds[i] = settings;
i++;
@ -183,15 +184,15 @@ int main(int argc, char** argv)
if (p->program_action == A_PLAY)
{
slogi("running monocoque in gameloop mode..");
error = strtogame(p->sim_string, ms);
if (error != MONOCOQUE_ERROR_NONE)
{
goto cleanup_final;
}
//slogi("running monocoque in gameloop mode..");
//error = strtogame(p->sim_string, ms);
//if (error != MONOCOQUE_ERROR_NONE)
//{
// goto cleanup_final;
//}
error = looper(devices, initdevices, ms->sim_name);
error = looper(devices, initdevices, p);
if (error == MONOCOQUE_ERROR_NONE)
{
slogi("Game loop exited succesfully with error code: %i", error);

View File

@ -13,4 +13,3 @@ set(simulatorapi_source_files
)
add_library(simulatorapi STATIC ${simulatorapi_source_files})
target_compile_definitions(simulatorapi PRIVATE SIMMAP_ALL)