void CMeshConverter::PopulateNormals(SD3DVertexType* psVertexType, void* pvFirstNewVert, CVertexArray* pcVertexArray)
{
	int							j;
	void*						pvVert;
	int							iNumVerts;
	SFloat3*					psNormal;
	CChannelsAccessorCreator	cCreator;
	CChannelsAccessor*			pcAccessor;

	if (psVertexType->iNormalOffest != -1)
	{
		cCreator.Init(pcVertexArray);
		cCreator.AddAccess(VERTEX_NORMAL_X, VERTEX_NORMAL_Y, VERTEX_NORMAL_Z, PT_float);
		pcAccessor = cCreator.CreateAndKill();

		iNumVerts = pcVertexArray->GetSize();
		pvVert = RemapSinglePointer(pvFirstNewVert, psVertexType->iNormalOffest);
		for (j = 0; j < iNumVerts; j++)
		{
			psNormal = (SFloat3*)pcAccessor->Get(j);
			((SFloat3*)pvVert)->Copy(psNormal);
			((SFloat3*)pvVert)->Normalize();
			pvVert = RemapSinglePointer(pvVert, psVertexType->iD3DVertexSize);
		}

		pcAccessor->Kill();
	}
}
void CMeshConverter::PopulateColours(SD3DVertexType* psVertexType, void* pvFirstNewVert, CVertexArray* pcVertexArray)
{
	int							j;
	void*						pvVert;
	int							iNumVerts;
	int*						piColour;
	CChannelsAccessorCreator	cCreator;
	CChannelsAccessor*			pcAccessor;

	if (psVertexType->iColourOffest != -1)
	{
		cCreator.Init(pcVertexArray);
		cCreator.AddAccess(VERTEX_DIFFUSE_RED, VERTEX_DIFFUSE_GREEN, VERTEX_DIFFUSE_BLUE, VERTEX_OPACITY, PT_uchar);
		pcAccessor = cCreator.CreateAndKill();

		iNumVerts = pcVertexArray->GetSize();
		pvVert = RemapSinglePointer(pvFirstNewVert, psVertexType->iColourOffest);
		for (j = 0; j < iNumVerts; j++)
		{
			piColour = (int*)pcAccessor->Get(j);
			*((int*)pvVert) = *piColour;
			pvVert = RemapSinglePointer(pvVert, psVertexType->iD3DVertexSize);
		}
		pcAccessor->Kill();
	}
}
SIndexedSecondLevelSearch* CIndexedHuge::LoadSecondLevelChunk(int iSecondLevelIndex)
{
	SIndexedSecondLevelSearch*		psIndexedSecondLevelSearch;
	int								iPrevLast;
	int								iSize;

	iSize = (sizeof(SIndexedSecondLevelSearch) + (sizeof(SIndexedThirdLevelSearch*) * miSecondLevelChunkWidth));
	if (!mbSecondLevelCacheFull)
	{
		iPrevLast = miLastSecondLevelChunk;
		miLastSecondLevelChunk = IncrementSecondLevelNumber(miLastSecondLevelChunk);
		if ((miLastSecondLevelChunk != 0) || (iPrevLast == -1))
		{
			psIndexedSecondLevelSearch = (SIndexedSecondLevelSearch*)RemapSinglePointer(mpvSecondLevel, miLastSecondLevelChunk * iSize);
			memset_fast(psIndexedSecondLevelSearch, 0, iSize);

			SetSecondLevelChunk(psIndexedSecondLevelSearch, iSecondLevelIndex);
			return psIndexedSecondLevelSearch;
		}

		mbSecondLevelCacheFull = TRUE;
		miLastSecondLevelChunk--;
	}
	miLastSecondLevelChunk = IncrementSecondLevelNumber(miLastSecondLevelChunk);

	psIndexedSecondLevelSearch = (SIndexedSecondLevelSearch*)RemapSinglePointer(mpvSecondLevel, miLastSecondLevelChunk * iSize);
	EvictSecondLevelChunk(psIndexedSecondLevelSearch);

	SetSecondLevelChunk(psIndexedSecondLevelSearch, iSecondLevelIndex);
	return psIndexedSecondLevelSearch;
}
void TestChannelsAccessorByteAligned(void)
{
	CChannels*					pcChannels;
	CChannelsAccessor*			pcAccessor;
	CChannelsAccessorCreator	cCreator;
	short*						psData;
	short						sData[3];
	int							iData;

	pcChannels = UMalloc(CChannels);
	pcChannels->Init();
	pcChannels->BeginChange();
	pcChannels->SetSize(2);
	pcChannels->AddChannel(CHANNEL_NAME_JACK, PT_short);
	pcChannels->AddChannel(CHANNEL_NAME_BOB, PT_int);
	pcChannels->AddChannel(CHANNEL_NAME_ALICE, PT_short);
	pcChannels->EndChange();

	cCreator.Init(pcChannels);
	cCreator.AddAccess(CHANNEL_NAME_JACK, PT_Undefined);
	cCreator.AddAccess(CHANNEL_NAME_ALICE, PT_Undefined);
	pcAccessor = cCreator.CreateAndKill();
	AssertString("CChannelsAccessorByteAligned", pcAccessor->ClassName());
	sData[0] = 784;
	sData[1] = 602;
	pcAccessor->Set(1, &sData);
	AssertShort(784, *(short*)RemapSinglePointer(pcChannels->GetData(), 8 + 0));
	AssertShort(602, *(short*)RemapSinglePointer(pcChannels->GetData(), 8 + 6));
	psData = (short*)pcAccessor->Get(1);
	AssertShort(784, psData[0]);
	AssertShort(602, psData[1]);
	pcAccessor->Kill();

	cCreator.Init(pcChannels);
	cCreator.AddAccess(CHANNEL_NAME_BOB, PT_Undefined);
	pcAccessor = cCreator.CreateAndKill();
	iData = 999999;
	pcAccessor->Set(1, &iData);
	pcAccessor->Kill();

	cCreator.Init(pcChannels);
	cCreator.AddAccess(CHANNEL_NAME_ALICE, PT_Undefined);
	cCreator.AddAccess(CHANNEL_NAME_BOB, PT_Undefined);
	pcAccessor = cCreator.CreateAndKill();
	AssertString("CChannelsAccessorByteAligned", pcAccessor->ClassName());
	psData = (short*)pcAccessor->Get(1);
	AssertShort(602, psData[0]);
	AssertInt(999999, *(int*)&psData[1]);
	sData[0] = 22172;
	sData[1] = 18432;
	sData[2] = 30812;
	pcAccessor->Set(0, sData);
	AssertInt(2019313664, *(int*)RemapSinglePointer(pcChannels->GetData(), 2));
	AssertShort(22172, *(short*)RemapSinglePointer(pcChannels->GetData(), 6));
	pcAccessor->Kill();
}
Esempio n. 5
0
void TestMapBlockInternals(void)
{
	CMapBlock			cMapBlock;
	int					i;
	int					j;
	int					iKey;
	int*				piData;
	CArrayBlockSorted*	paBlock;
	SMNode**			psNode1;
	SMNode**			psNode2;
	int*				piKey;

	cMapBlock.Init(1024, &CompareInt, TRUE);
	i = 7; j = 43;
	cMapBlock.Put(&i, sizeof(int), &j, sizeof(int));

	i = 9; j = 21;
	cMapBlock.Put(&i, sizeof(int), &j, sizeof(int));
	AssertInt(2, cMapBlock.NumElements());

	paBlock = cMapBlock.GetArray();
	paBlock->InsertHoldingIntoSorted();
	psNode1 = (SMNode**)paBlock->GetInSorted(0);
	psNode2 = (SMNode**)paBlock->GetInSorted(1);
	AssertInt(sizeof(int), (*psNode1)->iDataSize);
	AssertInt(sizeof(int), (*psNode1)->iKeySize);
	AssertPointer(&cMapBlock, (*psNode1)->pcMapBlock);
	AssertInt(sizeof(int), (*psNode2)->iDataSize);
	AssertInt(sizeof(int), (*psNode2)->iKeySize);
	AssertPointer(&cMapBlock, (*psNode2)->pcMapBlock);
	piKey = (int*)RemapSinglePointer(*psNode1, sizeof(SMNode));
	AssertInt(7, *piKey);
	piData = (int*)RemapSinglePointer(piKey, (int)sizeof(int));
	AssertInt(43, *piData);
	piKey = (int*)RemapSinglePointer(*psNode2, sizeof(SMNode));
	AssertInt(9, *piKey);
	piData = (int*)RemapSinglePointer(piKey, (int)sizeof(int));
	AssertInt(21, *piData);

	iKey = 7; piData = NULL;
	cMapBlock.Get(&iKey, (void**)&piData, NULL);
	AssertNotNull(piData);
	AssertInt(43, *piData);

	iKey = 9; piData = NULL;
	cMapBlock.Get(&iKey, (void**)&piData, NULL);
	AssertNotNull(piData);
	AssertInt(21, *piData);

	iKey = 3; piData = NULL;
	cMapBlock.Get(&iKey, (void**)&piData, NULL);
	AssertNull(piData);

	cMapBlock.Kill();
}
void TestChannelsAccessorTypeConvert(void)
{
	CChannels*					pcChannels;
	CChannelsAccessor*			pcAccessor;
	CChannelsAccessorCreator	cCreator;
	float*						pfData;
	float						afData[3];

	pcChannels = UMalloc(CChannels);
	pcChannels->Init();
	pcChannels->BeginChange();
	pcChannels->SetSize(2);
	pcChannels->AddChannel(CHANNEL_NAME_JACK, PT_ushort);
	pcChannels->AddChannel(CHANNEL_NAME_BOB, PT_uint);
	pcChannels->AddChannel(CHANNEL_NAME_ALICE, PT_ushort);
	pcChannels->EndChange();
	pcChannels->Clear();

	cCreator.Init(pcChannels);
	cCreator.AddAccess(CHANNEL_NAME_JACK, PT_float);
	cCreator.AddAccess(CHANNEL_NAME_ALICE, PT_float);
	pcAccessor = cCreator.CreateAndKill();
	AssertString("CChannelsAccessorTypeConvert", pcAccessor->ClassName());
	afData[0] = 1.0f;
	afData[1] = 0.34f;
	pcAccessor->Set(1, afData);
	AssertShortHex((short)0xffff, *(unsigned short*)RemapSinglePointer(pcChannels->GetData(), 8 + 0));
	AssertShortHex(0x5709, *(unsigned short*)RemapSinglePointer(pcChannels->GetData(), 8 + 6));
	pfData = (float*)pcAccessor->Get(1);
	AssertFloat(1.0f, pfData[0], 2);
	AssertFloat(0.34f, pfData[1], 2);
	pcAccessor->Kill();

	cCreator.Init(pcChannels);
	cCreator.AddAccess(CHANNEL_NAME_BOB, PT_float);
	pcAccessor = cCreator.CreateAndKill();
	AssertString("CChannelsAccessorTypeConvert", pcAccessor->ClassName());
	afData[0] = 0.8f;
	pcAccessor->Set(1, afData);
	AssertIntHex(0xcccccd00, *(int*)RemapSinglePointer(pcChannels->GetData(), 8 + 2));
	pcAccessor->Kill();

	cCreator.Init(pcChannels);
	cCreator.AddAccess(CHANNEL_NAME_ALICE, PT_float);
	cCreator.AddAccess(CHANNEL_NAME_BOB, PT_float);
	pcAccessor = cCreator.CreateAndKill();
	AssertString("CChannelsAccessorTypeConvert", pcAccessor->ClassName());
	pfData = (float*)pcAccessor->Get(1);
	AssertFloat(0.34f, pfData[0], 2);
	AssertFloat(0.80f, pfData[1], 2);
	pcAccessor->Kill();
}
Esempio n. 7
0
void CChars::Split(CArrayChars* aszDest, char cSplitter)
{
	int			iPos;
	char*		pszPos;
	int			iMax;

	pszPos = Text();
	iMax = Length();
	for (;;)
	{
		iPos = FindFirstByte(pszPos, cSplitter, iMax);
		if (iPos != -1)
		{
			aszDest->Add(pszPos, 0, iPos);
			iPos++;
			pszPos = (char*)RemapSinglePointer((void*)pszPos, iPos);
			iMax -= iPos;
		}
		else
		{
			aszDest->Add(pszPos, 0, iMax);
			break;
		}
	}
}
Esempio n. 8
0
void CChars::AppendSubString(const char* sz, int iStartInclusive, int iEndExclusive)
{
	const char* pcPosition;

	pcPosition = (char*)RemapSinglePointer((void*)sz, iStartInclusive);
	AppendSubString(pcPosition, iEndExclusive-iStartInclusive);
}
CSerialisedObject* CObjectReader::ReadSerialised(CFileReader* pcReader)
{
	int					iLength;
	CSerialisedObject*	pcSerialised;
	void*				pvOffset;
	BOOL				bResult;

	if (!pcReader->ReadInt(&iLength))
	{
		return NULL;
	}
	if (iLength <= 0)
	{
		return NULL;
	}

	pcSerialised = (CSerialisedObject*)malloc(iLength);
	if (!pcSerialised)
	{
		return NULL;
	}

	pcSerialised->SetLength(iLength);
	iLength -= sizeof(int);

	pvOffset = RemapSinglePointer(pcSerialised, sizeof(int));
	bResult = pcReader->ReadData(pvOffset, iLength);
	if (!bResult)
	{
		free(pcSerialised);
		return NULL;
	}
	return pcSerialised;
}
BOOL CTransientIndexedFile::Remove(OIndex oi)
{
	STransientIndexedPointer*		psPointer;
	int								iIndex;
	BOOL							bExists;
	SOIndexIndexCacheDescriptor*	psCacheDesc;

	//This method looks wrong.
	bExists = mcPointers.Get(oi, &psPointer, &iIndex);
	if (bExists)
	{
		if (psPointer->IsRemoved())
		{
			return FALSE;
		}
		else
		{
			if (psPointer->pvCache)
			{
				psCacheDesc = (SOIndexIndexCacheDescriptor*)RemapSinglePointer(psPointer->pvCache, -(int)sizeof(SOIndexIndexCacheDescriptor));
				mcCache.Invalidate(psCacheDesc);
			}
			psPointer->sIndexedMemory.uiSize = 0;
			return Allocate(psPointer, iIndex);
		}
	}
	else
	{
		return AddRemoved(oi);
	}
}
Esempio n. 11
0
CHollowObject* CObjects::AllocateHollow(unsigned short iNumEmbedded)
{
	CHollowObject*		pcHollow;
	int					iAdditionalBytes;
	void*				pvEmbedded;

	if (iNumEmbedded == 0)
	{
		return NULL;
	}
	if (iNumEmbedded == 1)
	{
		pcHollow = Allocate<CHollowObject>();
		pcHollow->Init(1);
		return pcHollow;
	}
	else
	{
		iAdditionalBytes = sizeof(CHollowEmbeddedObject) * (iNumEmbedded-1);
		pcHollow = Allocate<CHollowObject>(iAdditionalBytes);
		pcHollow->Init(iNumEmbedded);

		pvEmbedded = RemapSinglePointer(pcHollow, sizeof(CHollowObject));
		AppenedHollowEmbeddedObjects(pcHollow, iNumEmbedded, pvEmbedded);

		return pcHollow;
	}
}
SIndexedThirdLevelSearch* CIndexedHuge::GetCachedThirdLevelChunk(int iIndex)
{
	SIndexedThirdLevelSearch*	ps;

	ps = (SIndexedThirdLevelSearch*)RemapSinglePointer(mpvThirdLevel, ((sizeof(SIndexedThirdLevelSearch) + (sizeof(CIndexedDataDescriptor)*miThirdLevelChunkWidth))) * iIndex);
	return ps;
}
Esempio n. 13
0
void* CMemory::Iterate(SMemoryIterator* psIterator)
{
	void*	pv;

	pv = psIterator->pcFreeList->Iterate(&psIterator->sFreeListIterator);
	if (pv == NULL)
	{
		psIterator->pcFreeList = mcFreeLists.GetNext(psIterator->pcFreeList);
		if (psIterator->pcFreeList == NULL)
		{
			return NULL;
		}
		else
		{
			pv = psIterator->pcFreeList->StartIteration(&psIterator->sFreeListIterator);

			if (pv == NULL)
			{
				return Iterate(psIterator);
			}
			else
			{
				return pv;
			}
		}
	}
	else
	{
		return RemapSinglePointer(pv, sizeof(SMemoryAllocation));
	}
}
CIndexedDataDescriptor* CIndexedHuge::GetCachedDescriptor(SIndexedThirdLevelSearch* psIndexedThirdLevelSearch, int iIndex)
{
	CIndexedDataDescriptor*		pc;

	pc = (CIndexedDataDescriptor*)RemapSinglePointer(psIndexedThirdLevelSearch, sizeof(SIndexedThirdLevelSearch) + iIndex * sizeof(CIndexedDataDescriptor));
	return pc;
}
Esempio n. 15
0
void CLogFile::Dump(void)
{
	CChars					sz;
	int						i;
	char*					pvData;
	CLogFileCommandWrite*	psWrite;
	filePos					iLen;

	sz.Init();
	sz.Append("Log File (?");
	sz.Append(")\n------------------\n");
	sz.Append("Commands: ");
	sz.Append(macCommands.NumElements());
	sz.AppendNewLine();

	for (i = 0; i < macCommands.NumElements(); i++)
	{
		macCommands.Get(i, (void**)&pvData);
		sz.Append("   ");
		sz.Append("Write: (");
		psWrite = (CLogFileCommandWrite*)pvData;
		sz.Append(psWrite->iPosition);
		sz.Append(", ");
		sz.Append(psWrite->iSize);
		sz.Append(") ");

		pvData = (char*)RemapSinglePointer(psWrite, sizeof(CLogFileCommandWrite));
		iLen = psWrite->iSize;
		sz.AppendData(pvData, 80);
		sz.AppendNewLine();
	}
	sz.AppendNewLine();
	sz.Dump();
	sz.Kill();
}
Esempio n. 16
0
void* CMemory::Grow(void* pvInitial, unsigned int uiSize)
{
	SMemoryAllocation*	psAlloc;
	CFreeList*	pcList;
	SMemoryFreeListParams*	psParams;
	void*				pvNew;
	SLLANode*			psNode;

	psAlloc = MEMORY_GET_ALLOCATION(pvInitial);
	if (psAlloc->uiSize <= (muiFreeListSizeLimit - sizeof(SMemoryAllocation)))
	{
		psParams = GetFreeListParamsForSize(psAlloc->uiSize);
		if ((uiSize <= psParams->iMaxElementSize) && (uiSize >= psParams->iMinElementSize))
		{
			psAlloc->uiSize = uiSize;
			return pvInitial;
		}
		else
		{
			pcList = (CFreeList*)psAlloc->psFreeListNode->pcList;
			pvNew = Add(uiSize, pcList->GetAlignment(), pcList->GetOffset());
			CopyAllocation(pvNew, pvInitial, uiSize, psAlloc->uiSize);
			DeallocateInFreeList(pcList, psAlloc);
			return pvNew;
		}
	}
	else
	{
		psNode = (SLLANode*)RemapSinglePointer(psAlloc, -((int)sizeof(SLLANode)));
		if (uiSize <= (muiFreeListSizeLimit - sizeof(SMemoryAllocation)))
		{
			pvNew = Add(uiSize, psNode->sAligned.iAlignment, psNode->sAligned.iOffset);
			CopyAllocation(pvNew, pvInitial, uiSize, psAlloc->uiSize);
			DeallocateInLargeList(psAlloc);
			return pvNew;
		}
		else
		{
			psAlloc = (SMemoryAllocation*)mcLargeList.Grow(psAlloc, uiSize);
			psAlloc->uiSize = uiSize;
			psAlloc->psFreeListNode = NULL;
			pvNew = RemapSinglePointer(psAlloc, sizeof(SMemoryAllocation));
			return pvNew;
		}
	}
}
Esempio n. 17
0
void* CNamedIndexes::AllocateInCache(size_t iSize)
{
	CMemoryCacheAllocation		cPreAllocated;
	void*						pvData;
	int							i;
	SMemoryCacheDescriptor*		psMemoryDesc;
	int							iCacheDescriptorSize;
	CNamedIndexesBlock*			pcNamedIndexes;
	void*						pvCacheMem;
	CIndexedFile*				pcFile;
	BOOL						bResult;
	CNamedIndexesBlocks*		pcBlocks;

	cPreAllocated.Init(iSize);
	if (!mcCache.PreAllocate(&cPreAllocated))
	{
		cPreAllocated.Kill();
		return NULL;
	}

	for (i = 0; i < cPreAllocated.NumElements(); i++)
	{
		psMemoryDesc = cPreAllocated.Get(i);
		iCacheDescriptorSize = psMemoryDesc->iDataSize;
		pcBlocks = GetBlockForCacheDescriptorSize(iCacheDescriptorSize);
		if (!pcBlocks)
		{
			return NULL;
		}

		pvCacheMem = RemapSinglePointer(psMemoryDesc, sizeof(SMemoryCacheDescriptor));
		pcNamedIndexes = pcBlocks->GetBlock(pvCacheMem);
		if (!pcNamedIndexes)
		{
			return NULL;
		}

		pcFile = GetOrCreateFile(pcBlocks->GetDataSize(), pcBlocks->GetFileNumber());
		if (!pcFile)
		{
			return NULL;
		}
		pcBlocks->SetFileNumber(pcFile->miFileNumber);

		bResult = pcNamedIndexes->Uncache(pcFile);
		if (!bResult)
		{
			cPreAllocated.Kill();
			return NULL;
		}
	}

	pvData = mcCache.Allocate(&cPreAllocated);

	cPreAllocated.Kill();

	return pvData;
}
Esempio n. 18
0
void CLogFile::CopyWritesToRead(CArrayIntAndPointer* papvOverlapping, filePos iByteSize, void* pvDest)
{
	int						i;
	int						iNumWrites;
	CLogFileCommandWrite*	psWrite;
	int						iIndex;
	void*					pvData;
	filePos					iDestOffset;
	filePos					iSourceOffset;
	void*					pvSource;
	void*					pvNewDest;
	filePos					iLength;

	iNumWrites = papvOverlapping->NumElements();
	for (i = 0; i < iNumWrites; i++)
	{
		papvOverlapping->Get(i, (void**)&psWrite, &iIndex);

		pvData = RemapSinglePointer(psWrite, sizeof(CLogFileCommandWrite));

		iLength = psWrite->iSize;
		if ((psWrite->iPosition + psWrite->iSize) > (miPosition + iByteSize))
		{
			iLength -= (psWrite->iPosition + psWrite->iSize) - (miPosition + iByteSize);
		}

		iSourceOffset = 0;
		iDestOffset = psWrite->iPosition - miPosition;
		if (psWrite->iPosition < miPosition)
		{
			iSourceOffset = miPosition - psWrite->iPosition;
			iDestOffset = 0;
		}

		iLength -= iSourceOffset;

		pvSource = RemapSinglePointer(pvData, (int)iSourceOffset);
		pvNewDest = RemapSinglePointer(pvDest, (int)iDestOffset);

		memcpy_fast(pvNewDest, pvSource, (int)iLength);
	}
}
Esempio n. 19
0
void CopyPoints(CArrayBlock* pasPositions, SFloat3* psPoints, int iStride, int iNumPoints)
{
	int		i;

	for (i = 0; i < iNumPoints; i++)
	{
		pasPositions->Add(psPoints);
		psPoints = (SFloat3*)RemapSinglePointer(psPoints, iStride);
	}

}
Esempio n. 20
0
void* CMemory::AllocateInLargeList(unsigned int uiSize, int iAlignment, int iOffset)
{
	SMemoryAllocation*	psMemoryAllocation;

	psMemoryAllocation = (SMemoryAllocation*)mcLargeList.InsertAfterTail(uiSize + sizeof(SMemoryAllocation), iAlignment, iOffset);
	psMemoryAllocation->uiSize = uiSize;
	psMemoryAllocation->psFreeListNode = NULL;
	psMemoryAllocation->uiAllocCount = muiAllocCount;
	psMemoryAllocation->szDebug[0] = psMemoryAllocation->szDebug[1] = psMemoryAllocation->szDebug[2]= psMemoryAllocation->szDebug[3] = -1;
	return RemapSinglePointer(psMemoryAllocation, sizeof(SMemoryAllocation));
}
Esempio n. 21
0
void* CMemory::AllocateInFreeList(CFreeList* pcFreeList, unsigned int uiElementSize)
{
	SMemoryAllocation*	psMemoryAllocation;
	SFNode*				psNode;

	psMemoryAllocation = (SMemoryAllocation*)pcFreeList->Add(&psNode);
	psMemoryAllocation->uiSize = uiElementSize;
	psMemoryAllocation->psFreeListNode = psNode;
	psMemoryAllocation->uiAllocCount = muiAllocCount;
	psMemoryAllocation->szDebug[0] = psMemoryAllocation->szDebug[1] = psMemoryAllocation->szDebug[2]= psMemoryAllocation->szDebug[3] = -1;
	return RemapSinglePointer(psMemoryAllocation, sizeof(SMemoryAllocation));
}
void CMeshColours::IndexFaceCorners(int* paiDest, int iStride, CArrayInt* paiSourceFaces)
{
	int					i;
	int					iFaceIndex;
	SMeshFaceColour*	psFaceColour;

	//This assumes something else has check that paiSourceFaces actually have corner normals.
	for (i = 0; i < paiSourceFaces->NumElements(); i++)
	{
		iFaceIndex = paiSourceFaces->GetValue(i);
		psFaceColour = mcFaces.Get(iFaceIndex);

		*paiDest = psFaceColour->aiCornerColours[0];
		paiDest = (int*)RemapSinglePointer(paiDest, iStride);

		*paiDest = psFaceColour->aiCornerColours[1];
		paiDest = (int*)RemapSinglePointer(paiDest, iStride);

		*paiDest = psFaceColour->aiCornerColours[2];
		paiDest = (int*)RemapSinglePointer(paiDest, iStride);
	}
}
BOOL CTransientIndexedFile::Allocate(STransientIndexedPointer* psPointer, int iPointerIndex)
{
	SOIndexIndexCacheDescriptor*	psOIndexIndex;
	CMemoryCacheAllocation			cPreAllocated;
	int								i;
	void*							pvData;

	cPreAllocated.Init(psPointer->sIndexedMemory.uiSize);
	if (!mcCache.PreAllocate(&cPreAllocated))
	{
		cPreAllocated.Kill();
		return FALSE;
	}

	for (i = 0; i < cPreAllocated.NumElements(); i++)
	{
		psOIndexIndex = (SOIndexIndexCacheDescriptor*)cPreAllocated.Get(i);
		pvData = RemapSinglePointer(psOIndexIndex, sizeof(SOIndexIndexCacheDescriptor));
		Write(psOIndexIndex->sIndex.iIndex, pvData);
	}

	pvData = mcCache.Allocate(&cPreAllocated);

	if (pvData)
	{
		psOIndexIndex = (SOIndexIndexCacheDescriptor*)RemapSinglePointer(pvData, -(int)(sizeof(SOIndexIndexCacheDescriptor)));
		psOIndexIndex->sIndex.iIndex = iPointerIndex;
		psOIndexIndex->sIndex.oi = psPointer->sIndexedMemory.oi;
		psPointer->pvCache = pvData;
		cPreAllocated.Kill();
		return TRUE;
	}
	else
	{
		cPreAllocated.Kill();
		return FALSE;
	}
}
Esempio n. 24
0
void CChars::Fake(char* sz, int iStartInclusive, int iEndExclusive)
{
	char* pcPosition;

	if (iEndExclusive - iStartInclusive > 0)
	{
		pcPosition = (char*)RemapSinglePointer(sz, iStartInclusive);
		mcText.Fake(pcPosition, iEndExclusive - iStartInclusive + 1);
	}
	else
	{
		mcText.Fake(gszEmptyString.Text(), 1);
	}
}
void CMeshConverter::PopulateUVs(SD3DVertexType* psVertexType, void* pvFirstNewVert, CVertexArray* pcVertexArray)
{
	int							j;
	void*						pvVert;
	int							iNumVerts;
	int							iNumTextures;
	int							k;
	CMeshUVLayer*				pcUVLayer;
	SFloat2*					psUV;
	CChannelsAccessorCreator	cCreator;
	CChannelsAccessor*			pcAccessor;

	if (psVertexType->iUVOffest != -1)
	{
		iNumVerts = pcVertexArray->GetSize();
		iNumTextures = gcD3D.GetVertetFormatTextures(psVertexType->iD3DVertexFormat);

		for (k = 0; k < iNumTextures; k++)
		{
			cCreator.Init(pcVertexArray);
			cCreator.AddAccess(CHANNEL(VP_UVCoord_(k), CT_U), CHANNEL(VP_UVCoord_(k), CT_V), PT_float);
			pcAccessor = cCreator.CreateAndKill();

			pvVert = RemapSinglePointer(pvFirstNewVert, psVertexType->iUVOffest + (k * sizeof(SFloat2)));
			for (j = 0; j < iNumVerts; j++)
			{
				pcUVLayer = mpcMesh->mcUVs.mcLayers.Get(k);
				psUV = (SFloat2*)pcAccessor->Get(j);
				((SFloat2*)pvVert)->Init(psUV->x, psUV->y);

				pvVert = RemapSinglePointer(pvVert, psVertexType->iD3DVertexSize);
			}

			pcAccessor->Kill();
		}
	}
}
void CSingleChannelAccessor::GetConvertTo(int iChannel, EPrimitiveTypes eType, void* pvDest, int iPos)
{
	CChannel*			pcChannel;
	void*				pvData;
	int					iIndex;
	int					iByteSize;
	int					iBitSize;
	BOOL				bSub;

	//Fix the mess that are this function and the one below it.
	pcChannel = mpcChannels->GetChannel(iChannel);
	if (pcChannel)
	{
		pcChannel = mpcChannels->GetChannel(iChannel);
		iIndex = mpcChannels->GetIndexOfChannel(pcChannel);

		if (eType == PT_Undefined)
		{
			eType = pcChannel->eType;
		}

		iByteSize = gcTypeNames.GetByteSize(eType);
		iBitSize = gcTypeNames.GetBitSize(eType);
		if (iByteSize == 0)
		{
			iByteSize = -1;
			bSub = TRUE;
		}
		else
		{
			bSub = FALSE;
		}

		CChannelAccessor::Init(iByteSize, iBitSize, eType, pcChannel->miByteOffset, pcChannel->miByteSize, pcChannel->eType, pcChannel->bReverse, pcChannel->miBitSize, pcChannel->miBitOffset, pcChannel->iChannel);

		bSub |= miChannelByteOffset == -1;
		bSub |= miChannelByteSize == -1;

		if (!bSub)
		{
			pvData = RemapSinglePointer(mpcChannels->GetData(), iPos * mpcChannels->GetByteStride());
			CChannelAccessor::GetAs(eType, mpcChannels->GetData(), pvDest);
		}
		else
		{
			CChannelAccessor::GetAsSub(eType, mpcChannels->GetData(), iPos * mpcChannels->GetBitStride(), pvDest);
		}
	}
}
Esempio n. 27
0
void CObjects::AppenedHollowEmbeddedObjects(CBaseObject* pcHollow, unsigned short iNumEmbedded, void* pvEmbedded) 
{
	CHollowEmbeddedObject	cEmbeddedObject;
	int						i;
	CHollowEmbeddedObject*	pcEmbeddedObject;

	cEmbeddedObject.SetEmbedded(pcHollow);

	for (i = 0; i < iNumEmbedded-1; i++)
	{
		pcEmbeddedObject = (CHollowEmbeddedObject*)pvEmbedded;
		memcpy(pcEmbeddedObject, &cEmbeddedObject, sizeof(CHollowEmbeddedObject));
		pvEmbedded = RemapSinglePointer(pvEmbedded, sizeof(CHollowEmbeddedObject));
	}
}
void TestChannelsAccessorAccessBitty(void)
{
	CChannels*					pcChannels;
	CChannelsAccessor*			pcAccessor;
	CChannelsAccessorCreator	cCreator;
	unsigned char*				pucData;
	unsigned char				aucData[2];

	pcChannels = UMalloc(CChannels);
	pcChannels->Init();
	pcChannels->BeginChange();
	pcChannels->SetSize(1);
	pcChannels->AddChannel(CHANNEL_NAME_JACK, PT_ushort);
	pcChannels->AddChannel(CHANNEL_NAME_BOB, PT_ushort);
	pcChannels->AddChannel(CHANNEL_NAME_ALICE, PT_ushort);
	pcChannels->EndChange();
	pcChannels->Clear();

	cCreator.Init(pcChannels);
	cCreator.AddAccess(CHANNEL_NAME_JACK, PT_sixbits);
	cCreator.AddAccess(CHANNEL_NAME_BOB, PT_sixbits);
	cCreator.AddAccess(CHANNEL_NAME_ALICE, PT_nybble);
	pcAccessor = cCreator.CreateAndKill();
	AssertString("CChannelsAccessorAccessBitty", pcAccessor->ClassName());

	//XX10110010100011
	aucData[0] = 0xa3;
	aucData[1] = 0x2c;
	pcAccessor->Set(0, aucData);
	AssertShortHex((unsigned short)0x8e38, *(unsigned short*)RemapSinglePointer(pcChannels->GetData(), 0 + 0));
	AssertShortHex((unsigned short)0xcb2b, *(unsigned short*)RemapSinglePointer(pcChannels->GetData(), 0 + 2));
	AssertShortHex((unsigned short)0x2222, *(unsigned short*)RemapSinglePointer(pcChannels->GetData(), 0 + 4));
	pucData = (unsigned char*)pcAccessor->Get(0);
	AssertShortHex((unsigned short)0x2ca3, *(unsigned short*)pucData);
	pcAccessor->Kill();
}
Esempio n. 29
0
void* CMemory::StartIteration(SMemoryIterator* psIterator)
{
	void*	pv;

	psIterator->pcFreeList = mcFreeLists.GetHead();
	pv = psIterator->pcFreeList->StartIteration(&psIterator->sFreeListIterator);

	if (pv == NULL)
	{
		return Iterate(psIterator);
	}
	else
	{
		return RemapSinglePointer(pv, sizeof(SMemoryAllocation));
	}
}
void CChannelsAccessorChannelBitty::Set(int iPos, void* pvSource)
{
	int					i;
	CChannelAccessor*	pcAccessor;
	void*				pvDest;
	int					iDestBitPos;

	pvDest = mpcChannels->GetData();
	iDestBitPos = mpcChannels->GetBitStride() * iPos;
	for (i = 0; i < macAccessors.NumElements(); i++)
	{
		pcAccessor = macAccessors.Get(i);
		pcAccessor->SetFromSub(pcAccessor->meAccessType, pvDest, iDestBitPos, pvSource);
		pvSource = RemapSinglePointer(pvSource, pcAccessor->miAccessByteSize);
	}
}