Beispiel #1
0
void C4ObjResort::Execute() {
  // no order func: resort given objects
  if (!OrderFunc) {
    // no objects given?
    if (!pSortObj || !pObjBefore) return;
    // object to be resorted died or changed category
    if (pSortObj->Status != C4OS_NORMAL || pSortObj->Unsorted) return;
    // exchange
    if (fSortAfter)
      Game.Objects.OrderObjectAfter(pSortObj, pObjBefore);
    else
      Game.Objects.OrderObjectBefore(pSortObj, pObjBefore);
    // done
    return;
  } else if (pSortObj) {
    // sort single object
    SortObject();
    return;
  }
  // get first link to start sorting
  C4ObjectLink *pLnk = Game.Objects.Last;
  if (!pLnk) return;
  // sort all categories given; one by one (sort by category is ensured by
  // C4ObjectList::Add)
  for (int iCat = 1; iCat < C4D_SortLimit; iCat <<= 1)
    if (iCat & Category) {
      // get first link of this category
      while (!(pLnk->Obj->Status && (pLnk->Obj->Category & iCat)))
        if (!(pLnk = pLnk->Prev))
          // no more objects to sort: done
          break;
      // first link found?
      if (pLnk) {
        // get last link of this category
        C4ObjectLink *pNextLnk = pLnk;
        while (!pLnk->Obj->Status || (pNextLnk->Obj->Category & iCat))
          if (!(pNextLnk = pNextLnk->Prev))
            // no more objects: end of list reached
            break;
        // get previous link, which is the last in the list of this category
        C4ObjectLink *pLastLnk;
        if (pNextLnk)
          pLastLnk = pNextLnk->Next;
        else
          pLastLnk = Game.Objects.First;
        // get next valid (there must be at least one: pLnk; so this loop should
        // be safe)
        while (!pLastLnk->Obj->Status) pLastLnk = pLastLnk->Next;
        // now sort this portion of the list
        Sort(pLastLnk, pLnk);
        // start searching at end of this list next time
        // if the end has already been reached: stop here
        if (!(pLnk = pNextLnk)) return;
      }
      // continue with next category
    }
}
CGPGroup *CGPGroup::AddGroup(const char *name)
{
	CGPGroup	*newGroup;

	newGroup = new CGPGroup(name);

	SortObject(newGroup, (CGPObject **)&mSubGroups, (CGPObject **)&mInOrderSubGroups, 
		(CGPObject **)&mCurrentSubGroup);

	return newGroup;
}
CGPValue *CGPGroup::AddPair(const char *name, const char *value)
{
	CGPValue	*newPair;

	newPair = new CGPValue(name, value);

	SortObject(newPair, (CGPObject **)&mPairs, (CGPObject **)&mInOrderPairs, 
		(CGPObject **)&mCurrentPair);

	return newPair;
}
Beispiel #4
0
void CGPGroup::AddGroup(CGPGroup *NewGroup)
{
	SortObject(NewGroup, (CGPObject **)&mSubGroups, (CGPObject **)&mInOrderSubGroups, 
		(CGPObject **)&mCurrentSubGroup);
}
Beispiel #5
0
void CGPGroup::AddPair(CGPValue *NewPair)
{
	SortObject(NewPair, (CGPObject **)&mPairs, (CGPObject **)&mInOrderPairs, 
		(CGPObject **)&mCurrentPair);
}