//
// Polyobj_findExplicit
//
// Searches for segs to put into a polyobject in an explicitly provided order.
//
static void Polyobj_findExplicit(polyobj_t *po)
{
// temporary dynamic seg array
segitem_t *segitems = NULL;
size_t numSegItems = 0;
size_t numSegItemsAlloc = 0;
size_t i;
// first loop: save off all segs with polyobject's id number
for (i = 0; i < numsegs; ++i)
{
int polyID, parentID;
if (segs.linedef->special != POLYOBJ_EXPLICIT_LINE)
continue;
Polyobj_GetInfo(segs.linedef->tag, &polyID, &parentID, NULL);
if (polyID == po->id && parentID > 0)
{
if (numSegItems >= numSegItemsAlloc)
{
numSegItemsAlloc = numSegItemsAlloc ? numSegItemsAlloc*2 : 4;
segitems = realloc(segitems, numSegItemsAlloc*sizeof(segitem_t));
}
segitems[numSegItems].seg = &segs;
segitems[numSegItems].num = parentID;
++numSegItems;
}
}
// make sure array isn't empty
if (numSegItems == 0)
{
po->isBad = true;
CONS_Printf("polyobject %d is empty\n", po->id);
return;
}
// sort the array if necessary
if (numSegItems >= 2)
qsort(segitems, numSegItems, sizeof(segitem_t), Polyobj_segCompare);
// second loop: put the sorted segs into the polyobject
for (i = 0; i < numSegItems; ++i)
Polyobj_addSeg(po, segitems.seg);
// free the temporary array
free(segitems);
}