WIP: (BUG) model run/load/create

This commit is contained in:
Adrien Bourmault 2021-07-02 15:06:11 +02:00
parent 2d34d38a28
commit aa4bd4478c
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
2 changed files with 20 additions and 10 deletions

View File

@ -95,14 +95,17 @@ char *CmdModel(char **argv, Server_t *args)
id = (int) strtol(argv[2] + 3, NULL, 10);
if ((eid = ModelLoad(id)) < 0) {
strcat(buf, "Failed to load model id ");
if (id == 0 && (eid = ModelLoad(id)) <= 0) {
strcat(buf, "Failed to load model id");
tempsize = sprintf(temp, " %d\n", id);
strcat(buf, temp);
goto CmdModelEnd;
}
strcat(buf, "Model loaded with eid ");
strcat(buf, "Model id");
tempsize = sprintf(temp, " %d ", id);
strcat(buf, temp);
strcat(buf, "loaded with eid ");
tempsize = sprintf(temp, " %d\n", eid);
strcat(buf, temp);
goto CmdModelEnd;

View File

@ -46,7 +46,7 @@ static void ModelPrepareArrows(Space_t *globalDrawingSpace,
Model_t *model);
/* -------------------------------------------------------------------------- */
//XXX problem with index and struct
void ModelCreate(Model_t **newModel) // TODO manage deletion and empty slots
{
knownModel =
@ -67,13 +67,17 @@ void ModelCreate(Model_t **newModel) // TODO manage deletion and empty slots
int ModelLoad(int id) // TODO unload !
{
if (id > knownModelIndex) return -1;
if (id <= 0 || id >= knownModelIndex) {
return -1;
}
printLog("Loading model id %d (/%d models)...\n", id, knownModelIndex);
// Creating structure for the Scheduler
knownModel[id]->scheduler = (Scheduler_t*) calloc(1, sizeof(Scheduler_t));
knownModel[id]->scheduler->globalDrawingSpace =
(Space_t*) calloc(1, sizeof(Space_t));
(Space_t*) calloc(1, sizeof(Space_t)); // TODO free this
knownModel[id]->scheduler->nMaxThread = knownModel[id]->nmaxThread;
knownModel[id]->scheduler->nMaxCycles = knownModel[id]->nmaxCycles;
@ -83,13 +87,16 @@ int ModelLoad(int id) // TODO unload !
knownModel[id]);
knownModel[id]->scheduler->arrowArray =
(ArrowArray_t*) calloc(1, sizeof(ArrowArray_t));
(ArrowArray_t*) calloc(1, sizeof(ArrowArray_t)); // TODO free this
ModelPrepareArrows(knownModel[id]->scheduler->globalDrawingSpace,
knownModel[id]->scheduler->arrowArray, knownModel[id]);
loadedModel =
(Model_t**) realloc(loadedModel, ++loadedModelIndex * sizeof(Model_t*));
loadedModel[loadedModelIndex] = knownModel[id];
return loadedModelIndex++;
return loadedModelIndex;
}
void ModelRun(int id)
@ -121,9 +128,9 @@ void ModelShutdown(void)
void ModelSystemInit(void)
{
loadedModel = (Model_t**) calloc(MAX_MODEL_NUMBER, sizeof(Model_t*));
loadedModel = (Model_t**) calloc(1, sizeof(Model_t*));
// XXX read known models from files
knownModel = (Model_t**) calloc(MAX_MODEL_NUMBER, sizeof(Model_t*));
knownModel = (Model_t**) calloc(1, sizeof(Model_t*));
}
void ModelSystemDestroy(void)