From a1b1bf772e731405387556bce0809cd807d06324 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Wed, 3 Nov 2021 18:44:37 +0100 Subject: [PATCH] Cleanup --- src/arrows.c | 73 ------------------------------------------------- src/scheduler.c | 2 +- 2 files changed, 1 insertion(+), 74 deletions(-) diff --git a/src/arrows.c b/src/arrows.c index 7634932..d24e219 100644 --- a/src/arrows.c +++ b/src/arrows.c @@ -29,76 +29,3 @@ static inline int location(Space_t *space, int x, int y, int z) { return x + y * (space->xMax+1) + z * (space->xMax+1) * (space->zMax+1); } - -Arrow_t *ArrowAdd(Scheduler_t *scheduler, int x, int y, int z, int siteId, - int weight) { - - ArrowArray_t *arrowArray = scheduler->arrowArray; - Space_t *drawingSpace = scheduler->globalDrawingSpace; - Site_t *currentSite = &drawingSpace->space[ - location(drawingSpace, x, y, z) - ].sites[siteId]; - Arrow_t *curArrow; - - // Check if there is a free slot to store the a new arrow - if (arrowArray->freeSlotCount == 0) { - // Realloc array to create free slot - arrowArray->array = realloc(arrowArray->array, arrowArray->size + 1); - curArrow = &arrowArray->array[arrowArray->size + 1]; - arrowArray->size++; - } else { - // Reuse an unused free slot - curArrow = arrowArray->freeSlots[0]; - - // Delete the free slot reference (it's our *PROPERTY* now !) - if (!(memmove(&arrowArray->freeSlots[0], - &arrowArray->freeSlots[0] + sizeof(arrowArray->freeSlots[0]), - arrowArray->freeSlotCount - 1 - ))) - return NULL; - arrowArray->freeSlotCount--; - } - - // Assign values to the new arrow - curArrow->x = x; - curArrow->y = y; - curArrow->z = z; - curArrow->siteId = siteId; - - // Store a reference of this new arrow in space (to find it quickly later) - currentSite->arrowsPtr = curArrow; - currentSite->nArrow++; - - return curArrow; -} - -bool ArrowRemove(Scheduler_t *scheduler, int x, int y, int z, int siteId, - int weight) { - - ArrowArray_t *arrowArray = scheduler->arrowArray; - Space_t *drawingSpace = scheduler->globalDrawingSpace; - Site_t *currentSite = &drawingSpace->space[ - location(drawingSpace, x, y, z) - ].sites[siteId]; - Arrow_t *curArrow; - - // Look for a corresponding arrow in that site - if (currentSite->nArrow) { - // Get an arrow from space unit at siteId - curArrow = currentSite->arrowsPtr; - - // Mark arrow for deletion - arrowArray->freeSlots = - realloc(arrowArray->freeSlots, arrowArray->freeSlotCount + 1); - if (!arrowArray->freeSlots) - return false; - arrowArray->freeSlots[arrowArray->freeSlotCount] = curArrow; - arrowArray->freeSlotCount++; - - currentSite->arrowsPtr = NULL; - - currentSite->nArrow--; - } - - return false; -} diff --git a/src/scheduler.c b/src/scheduler.c index 00dddb4..1b317bd 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -128,7 +128,7 @@ static void *schedulerMain(void *scheduler) if (ArrowsAcquireNonBlockingLock(args->arrowArray)) { // Random choice of an arrow electedArrow = - &args->arrowArray->array[rand() % args->arrowArray->size]; + &args->arrowArray->array[rand() % args->arrowArray->size]; // XXX // Find a local area workArea = findWorkArea(centersList,