WIP: Arrows can be created
This commit is contained in:
parent
6125043513
commit
55d3d3f130
|
@ -26,7 +26,7 @@
|
|||
|
||||
<space-param>
|
||||
<dimension>1</dimension>
|
||||
<size>39</size>
|
||||
<size x="12" y="0" z="0"/>
|
||||
<site_multiplicity>2</site_multiplicity>
|
||||
|
||||
</space-param>
|
||||
|
|
|
@ -53,10 +53,13 @@ struct Arrow_t {
|
|||
int y;
|
||||
int z;
|
||||
int siteId;
|
||||
int weight;
|
||||
} typedef Arrow_t;
|
||||
|
||||
struct ArrowArray_t {
|
||||
size_t size;
|
||||
unsigned int freeSlotCount;
|
||||
Arrow_t **freeSlots;
|
||||
pthread_spinlock_t lock;
|
||||
Arrow_t *array;
|
||||
} typedef ArrowArray_t;
|
||||
|
@ -64,6 +67,7 @@ struct ArrowArray_t {
|
|||
struct Site_t {
|
||||
char *label;
|
||||
int nArrow;
|
||||
Arrow_t *arrowsPtr;
|
||||
} typedef Site_t;
|
||||
|
||||
struct SpaceUnit_t {
|
||||
|
|
77
src/arrows.c
77
src/arrows.c
|
@ -20,7 +20,84 @@
|
|||
//=-------------------------------------------------------------------------=//
|
||||
|
||||
#include "../include/base.h"
|
||||
#include "../include/arrows.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
26
src/model.c
26
src/model.c
|
@ -74,6 +74,10 @@ int ModelLoad(int id)
|
|||
(Model_t**) realloc(loadedModel, loadedModelSize * sizeof(Model_t*));
|
||||
|
||||
loadedModel[loadedModelSize-1] = knownModel[id-1];
|
||||
|
||||
// Parse model
|
||||
ParseModelXML(loadedModel[loadedModelSize-1]);
|
||||
|
||||
return loadedModelSize;
|
||||
}
|
||||
|
||||
|
@ -83,10 +87,10 @@ int ModelUnload(int id)
|
|||
if (id > loadedModelSize)
|
||||
return -1;
|
||||
|
||||
if (loadedModel[id-1]->scheduler) {
|
||||
SchedDestroy(loadedModel[id-1]->scheduler);
|
||||
loadedModel[id-1]->scheduler = NULL;
|
||||
}
|
||||
SchedContentDestroy(loadedModel[id-1]->scheduler);
|
||||
|
||||
SchedDestroy(loadedModel[id-1]->scheduler);
|
||||
loadedModel[id-1]->scheduler = NULL;
|
||||
|
||||
// Prevent fragmentation by moving data in the newly freed slot
|
||||
if (id-1 < loadedModelSize) {
|
||||
|
@ -117,21 +121,8 @@ int ModelRun(int id)
|
|||
if (loadedModel[id-1]->isRunning)
|
||||
return 0;
|
||||
|
||||
//
|
||||
loadedModel[id-1]->scheduler->globalDrawingSpace =
|
||||
(Space_t*) calloc(1, sizeof(Space_t));
|
||||
|
||||
loadedModel[id-1]->scheduler->nMaxThread = knownModel[id-1]->nmaxThread;
|
||||
loadedModel[id-1]->scheduler->nMaxCycles = knownModel[id-1]->nmaxCycles;
|
||||
|
||||
// Preparing global drawing space
|
||||
// TODO Load space
|
||||
|
||||
loadedModel[id-1]->scheduler->arrowArray =
|
||||
(ArrowArray_t*) calloc(1, sizeof(ArrowArray_t));
|
||||
|
||||
// TODO Load arrows
|
||||
|
||||
loadedModel[id-1]->scheduler->pleaseStop = false;
|
||||
loadedModel[id-1]->isRunning = true;
|
||||
|
||||
|
@ -156,7 +147,6 @@ int ModelStop(int id)
|
|||
|
||||
// Wait for Shceduler to stop
|
||||
SchedWait(loadedModel[id-1]->scheduler);
|
||||
SchedContentDestroy(loadedModel[id-1]->scheduler);
|
||||
|
||||
// Disable running bit
|
||||
loadedModel[id-1]->isRunning = false;
|
||||
|
|
|
@ -470,9 +470,9 @@ int ParseModelXML(Model_t *model)
|
|||
{(const xmlChar *)"max_cycles", parseStubFieldXML, model},
|
||||
// SPACE
|
||||
{(const xmlChar *)"space_param", parseParentFieldXML, model},
|
||||
{(const xmlChar *)"dimension", parseStubFieldXML, model},
|
||||
{(const xmlChar *)"size", parseStubFieldXML, model},
|
||||
{(const xmlChar *)"site_multiplicity", parseStubFieldXML, model},
|
||||
{(const xmlChar *)"dimension", parseDimensionFieldXML, model},
|
||||
{(const xmlChar *)"size", parseSizeFieldXML, model},
|
||||
{(const xmlChar *)"site_multiplicity", parseSiteMulFieldXML, model},
|
||||
|
||||
// TODO lacking implementation (model side)
|
||||
{(const xmlChar *)"boundaries", parseStubFieldXML, model},
|
||||
|
@ -481,11 +481,10 @@ int ParseModelXML(Model_t *model)
|
|||
{(const xmlChar *)"objects", parseParentFieldXML, model},
|
||||
{(const xmlChar *)"object", parseParentFieldPropsXML, model},
|
||||
|
||||
// SPACE
|
||||
{(const xmlChar *)"space", parseParentFieldPropsXML, model},
|
||||
|
||||
// SAVESTATES
|
||||
{(const xmlChar *)"savestates", parseParentFieldPropsXML, model},
|
||||
// SPACE
|
||||
{(const xmlChar *)"space", parseParentFieldPropsXML, model},
|
||||
|
||||
// TRANSITIONS
|
||||
{(const xmlChar *)"transitions", parseParentFieldPropsXML, model},
|
||||
|
|
Loading…
Reference in New Issue