//=-------------------------------------------------------------------------=// // Model management module // // // // Copyright © 2021 The Gem-graph Project // // // // This file is part of gem-graph. // // // // This program is free software: you can redistribute it and/or modify // // it under the terms of the GNU Affero General Public License as // // published by the Free Software Foundation, either version 3 of the // // License, or (at your option) any later version. // // // // This program is distributed in the hope that it will be useful, // // but WITHOUT ANY WARRANTY; without even the implied warranty of // // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // // GNU Affero General Public License for more details. // // // // You should have received a copy of the GNU Affero General Public License // // along with this program. If not, see . // //=-------------------------------------------------------------------------=// #include "../include/base.h" #include "../include/arrows.h" #include "../include/scheduler.h" #define MAX_MODEL_NUMBER 1 #define ARROW_NUMBER 2 #define SITE_NUMBER 2 #define MAX_CYCLES 10 #define MAX_THREAD 0 #define XMAX 30 #define YMAX 0 #define ZMAX 0 #define SPACE_SIZE (XMAX+1) * (YMAX+1) * (ZMAX+1) static Model_t **loadedModel; static int loadedModelIndex; static Model_t **knownModel; static int knownModelIndex; static void ModelPrepareSpace(Space_t *globalDrawingSpace, Model_t *model); static void ModelPrepareArrows(Space_t *globalDrawingSpace, ArrowArray_t *arrowArray, Model_t *model); /* -------------------------------------------------------------------------- */ void ModelSystemInit(void) { loadedModel = (Model_t**) calloc(MAX_MODEL_NUMBER, sizeof(Model_t*)); // XXX read known models from files knownModel = (Model_t**) calloc(MAX_MODEL_NUMBER, sizeof(Model_t)); } void ModelSystemDestroy(void) { free(loadedModel); free(knownModel); } void ModelCreate(Model_t **newModel) // TODO manage deletion and empty slots { knownModel = (Model_t**) realloc(knownModel, ++knownModelIndex * sizeof(Model_t)); knownModel[knownModelIndex] = (Model_t*) calloc(1, sizeof(Model_t)); knownModel[knownModelIndex]->id = knownModelIndex; *newModel = knownModel[knownModelIndex]; knownModel[knownModelIndex]->space_xMax = XMAX; knownModel[knownModelIndex]->space_yMax = YMAX; knownModel[knownModelIndex]->space_zMax = ZMAX; knownModel[knownModelIndex]->nmaxThread = MAX_THREAD; knownModel[knownModelIndex]->nmaxCycles = MAX_CYCLES; knownModel[knownModelIndex]->siteNumber = SITE_NUMBER; } int ModelLoad(int id) // TODO unload ! { // 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)); knownModel[id]->scheduler->nMaxThread = knownModel[id]->nmaxThread; knownModel[id]->scheduler->nMaxCycles = knownModel[id]->nmaxCycles; // Preparing global drawing space ModelPrepareSpace(knownModel[id]->scheduler->globalDrawingSpace, knownModel[id]); knownModel[id]->scheduler->arrowArray = (ArrowArray_t*) calloc(1, sizeof(ArrowArray_t)); ModelPrepareArrows(knownModel[id]->scheduler->globalDrawingSpace, knownModel[id]->scheduler->arrowArray, knownModel[id]); loadedModel[loadedModelIndex] = knownModel[id]; return loadedModelIndex++; } void ModelRun(int id) { // Creating structure for the Scheduler SchedInit(knownModel[id]->scheduler); } void ModelStop(int id) { // Creating structure for the Scheduler knownModel[id]->scheduler->pleaseStop = true; printLog("Model %d stopped!\n", id); } void ModelDelete(Model_t *newModel) { return; } void ModelShutdown(void) { for (int i = 0; i < loadedModelIndex; i++) { ModelStop(i); } } /* -------------------------------------------------------------------------- */ static void ModelPrepareSpace(Space_t *globalDrawingSpace, Model_t *model) { globalDrawingSpace->size = (model->space_xMax+1) * (model->space_yMax+1) * (model->space_zMax+1); globalDrawingSpace->xMax = model->space_xMax; globalDrawingSpace->yMax = model->space_yMax; globalDrawingSpace->zMax = model->space_zMax; globalDrawingSpace->space = (SpaceUnit_t*) calloc(globalDrawingSpace->size, sizeof(SpaceUnit_t)); for (int i = 0; i < globalDrawingSpace->size; i++) { globalDrawingSpace->space[i].nSite = model->siteNumber; globalDrawingSpace->space[i].sites = (Site_t*) calloc(model->siteNumber, sizeof(Site_t)); } } static void ModelPrepareArrows(Space_t *globalDrawingSpace, ArrowArray_t *arrowArray, Model_t *model) { arrowArray->array = (Arrow_t*) calloc(ARROW_NUMBER, sizeof(Arrow_t)); arrowArray->size = ARROW_NUMBER; //XXX hardcoded // Creating some arrows XXX random walking globalDrawingSpace->space[3].sites[1].nArrow = 1; arrowArray->array[0].siteId = 1; arrowArray->array[0].x = 3; globalDrawingSpace->space[4].sites[0].nArrow = 1; arrowArray->array[1].siteId = 0; arrowArray->array[1].x = 4; }