From de284948d7b9ba20b40a52dd38a4df939e5b692e Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Wed, 16 Jun 2021 13:06:23 +0200 Subject: [PATCH] space dimension --- include/base.h | 10 +++++----- src/main.c | 26 +++++++++++++++++++------- src/scheduler.c | 9 +++++---- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/include/base.h b/include/base.h index 0f17103..1c51d47 100644 --- a/include/base.h +++ b/include/base.h @@ -30,6 +30,11 @@ #define BASE_H +struct { + size_t size; + int *space; +} typedef IntArray_t; + struct { int x; int y; @@ -60,11 +65,6 @@ struct { SpaceUnit_t *space; } typedef Space_t; -struct { - size_t size; - int *space; -} typedef IntArray_t; - #define LOGMSG "[%s]" #define printLog(FORMAT, ...) printf(LOGMSG " " FORMAT, __func__, ##__VA_ARGS__) diff --git a/src/main.c b/src/main.c index eac0a86..22a1b61 100644 --- a/src/main.c +++ b/src/main.c @@ -26,8 +26,11 @@ #define ARROW_NUMBER 150 #define MAX_CYCLES 15 -#define SPACE_SIZE 10000 #define MAX_THREAD 0 +#define XMAX 1000 +#define YMAX 1000 +#define ZMAX 0 +#define SPACE_SIZE (XMAX+1) * (YMAX+1) * (ZMAX+1) int main(int argc, char **argv) { @@ -53,6 +56,9 @@ int main(int argc, char **argv) scheduler0->globalDrawingSpace->space = (SpaceUnit_t*) calloc(SPACE_SIZE, sizeof(SpaceUnit_t)); scheduler0->globalDrawingSpace->size = SPACE_SIZE; + scheduler0->globalDrawingSpace->xmax = SPACE_SIZE; + scheduler0->globalDrawingSpace->ymax = SPACE_SIZE; + scheduler0->globalDrawingSpace->zmax = SPACE_SIZE; scheduler0->arrowList = (ArrowArray_t*) calloc(1, sizeof(ArrowArray_t)); scheduler0->arrowList->array = @@ -61,12 +67,18 @@ int main(int argc, char **argv) printLog("Populating a random arrow list...\n"); for (int i = 0; i < ARROW_NUMBER; i++) { - scheduler0->arrowList->array[i].x = - rand() % scheduler0->globalDrawingSpace->xmax; - scheduler0->arrowList->array[i].y = - rand() % scheduler0->globalDrawingSpace->ymax; - scheduler0->arrowList->array[i].z = - rand() % scheduler0->globalDrawingSpace->zmax; + + if (scheduler0->globalDrawingSpace->xmax) + scheduler0->arrowList->array[i].x = + rand() % (scheduler0->globalDrawingSpace->xmax + 1); + + if (scheduler0->globalDrawingSpace->ymax) + scheduler0->arrowList->array[i].y = + rand() % (scheduler0->globalDrawingSpace->ymax + 1); + + if (scheduler0->globalDrawingSpace->zmax) + scheduler0->arrowList->array[i].z = + rand() % (scheduler0->globalDrawingSpace->zmax + 1); } scheduler0->nmaxThread = MAX_THREAD; diff --git a/src/scheduler.c b/src/scheduler.c index 281bdef..6002b7b 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -49,15 +49,16 @@ static Center_t *findWorkArea(Center_t *centersList, Arrow_t *electedArrow, { register Center_t *currentCenter, *newCenter; - currentCenter = centersList; + currentCenter = centersList->next; newCenter = (Center_t*) malloc(sizeof(Center_t)); while (currentCenter){ - if ( abs(electedArrow->x - currentCenter->x) <= ruleRadius - || abs(electedArrow->y - currentCenter->y) <= ruleRadius - || abs(electedArrow->z - currentCenter->z) <= ruleRadius + if ( (xmax && (abs(electedArrow->x - currentCenter->x) <= ruleRadius)) + || (ymax && (abs(electedArrow->y - currentCenter->y) <= ruleRadius)) + || (zmax && (abs(electedArrow->z - currentCenter->z) <= ruleRadius)) ){ free(newCenter); + //printLog("Can't find a free area\n"); return NULL; } currentCenter = currentCenter->next;