示例#1
0
// This should encode the current priority of all primary objectives
short EncodePrimaryObjectiveList (uchar teammask, uchar **buffer)
{
	uchar					*data,*datahead;
	ListNode				lp;
	POData					pod;
	short					size,count=0,team,teams=0;

	// 'teammask' determines which team data we're sending. If no such
	// team exists, there's no reason to send the data. Check for this
	for (team=0; team<NUM_TEAMS; team++)
	{
		if (!TeamInfo[team])
			teammask &= ~(1 << team);
		else if (teammask & (1 << team))
			teams++;
	}

	// Determine size
	size = sizeof(uchar) + sizeof(short);
	lp = PODataList->GetFirstElement();
	while (lp)
	{
		count++;
		lp = lp->GetNext();
	}
	size += count * (sizeof(VU_ID) + sizeof(short)*teams);

	// Write the data
	data = datahead = new uchar[size];
	memcpy(data, &teammask, sizeof(uchar));								data += sizeof(uchar);
	memcpy(data, &count, sizeof(short));								data += sizeof(short);
	lp = PODataList->GetFirstElement();
	while (lp)
	{
		pod = (POData) lp->GetUserData();
		memcpy(data, &pod->objective, sizeof(VU_ID));					data += sizeof(VU_ID);
		for (team=0; team<NUM_TEAMS; team++)
		{
			if (teammask & (1 << team))
			{
				memcpy(data, &pod->player_priority[team], sizeof(short));	
				data += sizeof(short);
			}
		}
		lp = lp->GetNext();
	}
	*buffer = datahead;

	return size;
}
void LinkedList::Remove(void* item)
{
	if (frontNode)
	{
		ListNode* currNode = frontNode;
		do
		{
			if (currNode->GetItem() == item)
			{
				break;
			}
			currNode = currNode->GetNext();
		} while (currNode);
		if (currNode)
		{
			delete currNode;
			numItems--;
			if (numItems == 0)
			{
				frontNode = NULL;
				backNode = NULL;
			}
		}
	}
}
示例#3
0
文件: list.hpp 项目: 0xMF/coreclr
    template <class Type> Type List<Type>::GetNext(LISTNODE &pNode)
    {
        ListNode<Type> *pListNode = (ListNode<Type> *)pNode;

        // Faults if you pass NULL
        _ASSERTE(pNode);

        Type item = pListNode->GetItem();
        pNode = (LISTNODE)(pListNode->GetNext());

        return item;
    }
ListNode* LinkedList::NodeAt(int index)
{
	if (index == 0)
	{
		return frontNode;
	}
	else if (index == numItems - 1)
	{
		return backNode;
	}
	else if (index < numItems)
	{
		int temp = numItems >> 1;
		if (index >= temp)
		{
			int currIndex = numItems - 1;
			ListNode* currNode = backNode;
			do
			{
				currNode = currNode->GetPrevious();
				currIndex--;
			} while (index != currIndex);
			return currNode;
		}
		else
		{
			int currIndex = 0;
			ListNode* currNode = frontNode;
			if (index != currIndex)
			{
				do
				{
					currNode = currNode->GetNext();
					currIndex++;
				} while (index != currIndex);
			}
			return currNode;
		}
	}
示例#5
0
文件: list.hpp 项目: 0xMF/coreclr
    template <class Type> void List<Type>::RemoveAt(LISTNODE pNode)
    {
        ListNode<Type>           *pListNode = (ListNode<Type> *)pNode;
        ListNode<Type>           *pPrevNode = NULL;
        ListNode<Type>           *pNextNode = NULL;

        if (pNode) {
            pPrevNode = pListNode->GetPrev();
            pNextNode = pListNode->GetNext();

            if (pPrevNode) {
                pPrevNode->SetNext(pNextNode);
                if (pNextNode) {
                    pNextNode->SetPrev(pPrevNode);
                }
                else {
                    // We're removing the last node, so we have a new tail
                    _pTail = pPrevNode;
                }
                SAFE_DELETE(pListNode);
            }
            else {
                // No previous, so we are the head of the list
                _pHead = pNextNode;
                if (pNextNode) {
                    pNextNode->SetPrev(NULL);
                }
                else {
                    // No previous, or next. There was only one node.
                    _pHead = NULL;
                    _pTail = NULL;
                }
                SAFE_DELETE(pListNode);
            }

            _iCount--;
        }
    }