示例#1
0
void AddRecipe( int (*function)(CeosSARVolume_t *volume,
                                void *token),
                void *token,
                const char *name )
{

    RecipeFunctionData_t *TempData;

    Link_t *Link;

    TempData = HMalloc( sizeof( RecipeFunctionData_t ) );

    TempData->function = function;
    TempData->token = token;
    TempData->name = name;

    Link = ceos2CreateLink( TempData );

    if( RecipeFunctions == NULL)
    {
        RecipeFunctions = Link;
    } else {
        RecipeFunctions = InsertLink( RecipeFunctions, Link );
    }
}
示例#2
0
void C4ObjectList::Sort()
{
	C4ObjectLink *cLnk;
	bool fSorted;
	// Sort by id
	do
	{
		fSorted = true;
		for (cLnk=First; cLnk && cLnk->Next; cLnk=cLnk->Next)
			if (cLnk->Obj->id > cLnk->Next->Obj->id)
			{
				RemoveLink(cLnk);
				InsertLink(cLnk,cLnk->Next);
				fSorted = false;
				break;
			}
	}
	while (!fSorted);
}
示例#3
0
bool C4ObjectList::Add(C4Object *nObj, SortType eSort, C4ObjectList *pLstSorted)
{
	C4ObjectLink *nLnk;
	if (!nObj || !nObj->Def || !nObj->Status) return false;

#ifdef _DEBUG
	if (eSort==stMain)
	{
		CheckCategorySort();
		if (pLstSorted)
			assert(CheckSort(pLstSorted));
	}
#endif

	// dbg: don't do double links
	assert (!GetLink(nObj));

	// no self-sort
	assert(pLstSorted != this);

	// Allocate new link
	if (!(nLnk=new C4ObjectLink)) return false;
	// Set link
	nLnk->Obj=nObj;

	// Search insert position (default: end of list)
	C4ObjectLink *cLnk = NULL, *cPrev = Last;

	// Should sort?
	if (eSort == stReverse)
	{
		// reverse sort: Add to beginning of list
		cLnk = First; cPrev = NULL;
	}
	else if (eSort)
	{
		// Sort override? Leave default as is.
		bool fUnsorted = nObj->Unsorted;
		if (!fUnsorted)
		{
			// Sort by master list?
			if (pLstSorted)
			{
				cPrev = NULL; cLnk = First;
				while(cLnk && (!cLnk->Obj->Status || cLnk->Obj->Unsorted)) cLnk = cLnk->Next;

#ifndef _DEBUG
				if(cLnk)
#endif
				{
					C4ObjectLink* cLnk2;
					for(cLnk2 = pLstSorted->First; cLnk2; cLnk2 = cLnk2->Next)
					{
						if(cLnk2->Obj->Status && !cLnk2->Obj->Unsorted)
						{
							if(cLnk2->Obj == nObj)
							{
								assert(!cLnk || cLnk->Obj != nObj);
								break;
							}

							if(cLnk && cLnk2->Obj == cLnk->Obj)
							{
								cPrev = cLnk;
								cLnk = cLnk->Next;
								while(cLnk && (!cLnk->Obj->Status || cLnk->Obj->Unsorted)) cLnk = cLnk->Next;
								
#ifndef _DEBUG
								if(!cLnk) break;
#endif
							}
						}
					}

					assert(cLnk2 != NULL);
				}
			}
			else
			{
				// No master list: Find successor by matching Plane / id
				// Sort by matching Plane/id is necessary for inventory shifting.
				// It is not done for static back to allow multiobject outside structure.
				// Unsorted objects are ignored in comparison.
				if (!(nObj->Category & C4D_StaticBack))
					for (cPrev=NULL,cLnk=First; cLnk; cLnk=cLnk->Next)
						if (cLnk->Obj->Status && !cLnk->Obj->Unsorted)
						{
							if (cLnk->Obj->GetPlane() == nObj->GetPlane())
								if (cLnk->Obj->id == nObj->id)
									break;
							cPrev=cLnk;
						}

				// Find successor by relative category
				if(!cLnk)
					for (cPrev=NULL, cLnk=First; cLnk; cLnk=cLnk->Next)
						if (cLnk->Obj->Status && !cLnk->Obj->Unsorted)
						{
							if (cLnk->Obj->GetPlane() <= nObj->GetPlane())
								break;
							cPrev=cLnk;
						}
			}

			cLnk = cPrev ? cPrev->Next : First;
		}
	}

	assert(!cPrev || cPrev->Next == cLnk);
	assert(!cLnk || cLnk->Prev == cPrev);

	// Insert new link after predecessor
	InsertLink(nLnk, cPrev);

#ifdef _DEBUG
	// Debug: Check sort
	if (eSort == stMain)
	{
		CheckCategorySort();
		if (pLstSorted)
			assert(CheckSort(pLstSorted));
	}
#endif

	// Add mass
	Mass+=nObj->Mass;

	return true;
}