Cleanup
This commit is contained in:
parent
72a979afe4
commit
a1b1bf772e
73
src/arrows.c
73
src/arrows.c
|
@ -29,76 +29,3 @@
|
||||||
static inline int location(Space_t *space, int x, int y, int z) {
|
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);
|
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;
|
|
||||||
}
|
|
||||||
|
|
|
@ -128,7 +128,7 @@ static void *schedulerMain(void *scheduler)
|
||||||
if (ArrowsAcquireNonBlockingLock(args->arrowArray)) {
|
if (ArrowsAcquireNonBlockingLock(args->arrowArray)) {
|
||||||
// Random choice of an arrow
|
// Random choice of an arrow
|
||||||
electedArrow =
|
electedArrow =
|
||||||
&args->arrowArray->array[rand() % args->arrowArray->size];
|
&args->arrowArray->array[rand() % args->arrowArray->size]; // XXX
|
||||||
|
|
||||||
// Find a local area
|
// Find a local area
|
||||||
workArea = findWorkArea(centersList,
|
workArea = findWorkArea(centersList,
|
||||||
|
|
Loading…
Reference in New Issue