Example #1
0
template <class ObjType> ObjType *OpsRTree::Allocator<ObjType>::Allocate()
{
    ObjType *obj;

    // first check the linked list of free objects. If the list is not empty,
    // then remove the head of the list

    if (m_headFreeList != NULL) {
        obj = m_headFreeList;
        m_headFreeList = *reinterpret_cast<ObjType **>(m_headFreeList);
    }

    // else get the next free object from the object pool

    else {
        // get a new block of object if necessary

        if (m_nextObjIndex >= m_blockSize)
            GetNewBlock();

        obj = &m_blockPool[m_nBlocks-1][m_nextObjIndex++];
    }

    return obj;

} // end: Allocate()
Example #2
0
void BuildLine( ULONG  ulRow,
		char*  pchDest )
{

    ULONG	ulIndentation;
    ULONG	ulBufferIndex;
    ULONG	ulDataLeft;
    ULONG	ulNumberOfSpaces;


    ulBufferIndex = 0;
    ulDataLeft = vrgNewLen[ ulRow ];
    ulIndentation = vIndent;
	while( (ulBufferIndex < (ULONG)(vWidth - 1)) && ulDataLeft ) {
	if( ulBlkOffset >= BLOCKSIZE ) {
	    GetNewBlock();
	}
	if ( ulIndentation ) {
	    if( *pData++ == 0x09 ) {
		ulIndentation -= vDisTab - (ulIndentation % vDisTab);
	    }
	    else {
		ulIndentation--;
	    }
	}
	else {
	    if (*pData >= 0x20) {
		*pchDest++ = *pData++;
                ulBufferIndex++;
            }
            else if ( (*pData == 0x0d) || (*pData == 0x0a) ) {
		*pchDest++ = 0x20;
		pData++;
                ulBufferIndex++;
	    }
	    else if( *pData == 0x09 ) {
		ulNumberOfSpaces = vDisTab - ulBufferIndex % vDisTab;
		while( ulNumberOfSpaces && ( ulBufferIndex < (ULONG)( vWidth - 1 ) ) ) {
		    *pchDest++ = 0x20;
		    ulBufferIndex++;
		    ulNumberOfSpaces--;
		}
		pData++;
	    }
	    else {
		*pchDest++ = *pData++;
		ulBufferIndex++;
	    }
	}
	ulDataLeft--;
	ulBlkOffset++;
    }
    pData += ulDataLeft;
    ulBlkOffset += ulDataLeft;
	while( ulBufferIndex < (ULONG)(vWidth -1) ) {
	*pchDest++ = 0x20;
	ulBufferIndex++;
    }
}
Example #3
0
bool KaxCluster::AddFrameInternal(const KaxTrackEntry & track, uint64 timecode, DataBuffer & buffer, KaxBlockGroup * & MyNewBlock, const KaxBlockGroup * PastBlock, const KaxBlockGroup * ForwBlock, LacingType lacing)
{
  if (!bFirstFrameInside) {
    bFirstFrameInside = true;
    MinTimecode = MaxTimecode = timecode;
  } else {
    if (timecode < MinTimecode)
      MinTimecode = timecode;
    if (timecode > MaxTimecode)
      MaxTimecode = timecode;
  }

  MyNewBlock = NULL;

  if (lacing == LACING_NONE || !track.LacingEnabled()) {
    currentNewBlock = NULL;
  }

  // force creation of a new block
  if (currentNewBlock == NULL || uint32(track.TrackNumber()) != uint32(currentNewBlock->TrackNumber()) || PastBlock != NULL || ForwBlock != NULL) {
    KaxBlockGroup & aNewBlock = GetNewBlock();
    MyNewBlock = currentNewBlock = &aNewBlock;
  }

  if (PastBlock != NULL) {
    if (ForwBlock != NULL) {
      if (currentNewBlock->AddFrame(track, timecode, buffer, *PastBlock, *ForwBlock, lacing)) {
        // more data are allowed in this Block
        return true;
      } else {
        currentNewBlock = NULL;
        return false;
      }
    } else {
      if (currentNewBlock->AddFrame(track, timecode, buffer, *PastBlock, lacing)) {
        // more data are allowed in this Block
        return true;
      } else {
        currentNewBlock = NULL;
        return false;
      }
    }
  } else {
    if (currentNewBlock->AddFrame(track, timecode, buffer, lacing)) {
      // more data are allowed in this Block
      return true;
    } else {
      currentNewBlock = NULL;
      return false;
    }
  }
}
Example #4
0
void CMapDiffCollection::LoadMapDiffs()
{
	// Load mapdif* and stadif* Files
	ADDTOCALLSTACK("CMapDiffCollection::LoadMapDiffs");
	if ( m_bLoaded ) // already loaded
		return;

	DWORD dwLength = 0, dwBlockId = 0;
	DWORD dwOffset = 0, dwRead = 0;
	CMapDiffBlock * pMapDiffBlock = NULL;

	for ( int m = 0; m < 256; ++m )
	{
		if ( !g_MapList.IsMapSupported( m ) )
			continue;

		int map = g_MapList.m_mapid[m];

		// Load Mapdif Files
		{
			CGFile * pFileMapdif	= &(g_Install.m_Mapdif[map]);
			CGFile * pFileMapdifl	= &(g_Install.m_Mapdifl[map]);

			// Check that the relevant dif files are available
			if ( pFileMapdif->IsFileOpen() && pFileMapdifl->IsFileOpen() )
			{
				// Make sure that we're at the beginning of the files
				pFileMapdif->SeekToBegin();
				pFileMapdifl->SeekToBegin();

				dwLength = pFileMapdifl->GetLength();
				dwRead = dwOffset = 0;

				for ( ; dwRead < dwLength; dwOffset += sizeof(CUOMapBlock) )
				{
					dwRead += pFileMapdifl->Read( &dwBlockId, sizeof(dwBlockId) );
					pMapDiffBlock = GetNewBlock( dwBlockId, map );

					if ( pMapDiffBlock->m_pTerrainBlock )
						delete pMapDiffBlock->m_pTerrainBlock;

					CUOMapBlock * pTerrain = new CUOMapBlock();
					if ( pFileMapdif->Seek( dwOffset ) != dwOffset )
					{
						g_Log.EventError("Reading mapdif%d.mul FAILED.\n", map);
						delete pTerrain;
						break;
					}
					else if ( pFileMapdif->Read( pTerrain, sizeof(CUOMapBlock) ) != sizeof(CUOMapBlock) )
					{
						g_Log.EventError("Reading mapdif%d.mul FAILED. [index=%lu offset=%lu]\n", map, dwBlockId, dwOffset);
						delete pTerrain;
						break;
					}

					pMapDiffBlock->m_pTerrainBlock = pTerrain;
				}
			}
		} // Mapdif

		// Load Stadif Files
		{
			CGFile * pFileStadif	= &(g_Install.m_Stadif[map]);
			CGFile * pFileStadifl	= &(g_Install.m_Stadifl[map]);
			CGFile * pFileStadifi	= &(g_Install.m_Stadifi[map]);

			// Check that the relevant dif files are available
			if ( !pFileStadif->IsFileOpen() || !pFileStadifl->IsFileOpen() || !pFileStadifi->IsFileOpen() )
				continue;

			// Make sure that we're at the beginning of the files
			pFileStadif->SeekToBegin();
			pFileStadifl->SeekToBegin();
			pFileStadifi->SeekToBegin();

			dwLength = pFileStadifl->GetLength();
			dwRead = dwOffset = 0;
	
			for ( ; dwRead < dwLength; dwOffset += sizeof(CUOIndexRec) )
			{
				dwRead += pFileStadifl->Read( &dwBlockId, sizeof(dwBlockId) );
				
				pMapDiffBlock = GetNewBlock( dwBlockId, map );
				if ( pMapDiffBlock->m_pStaticsBlock )
					delete[] pMapDiffBlock->m_pStaticsBlock;

				pMapDiffBlock->m_iStaticsCount = 0;
				pMapDiffBlock->m_pStaticsBlock = NULL;

				if ( pFileStadifi->Seek( dwOffset ) != dwOffset )
				{
					g_Log.EventError("Reading stadifi%d.mul FAILED.\n", map);
					break;
				}

				CUOIndexRec index;
				if ( pFileStadifi->Read( &index, sizeof(CUOIndexRec)) != sizeof(CUOIndexRec) )
				{
					g_Log.EventError("Reading stadifi%d.mul FAILED. [index=%lu offset=%lu]\n", map, dwBlockId, dwOffset);
					break;
				}
				else if ( !index.HasData() ) // This happens if the block has been intentionally patched to remove statics
				{
					continue;
				}
				else if ((index.GetBlockLength() % sizeof(CUOStaticItemRec)) != 0) // Make sure that the statics block length is valid
				{
					g_Log.EventError("Reading stadifi%d.mul FAILED. [index=%lu offset=%lu length=%lu]\n", map, dwBlockId, dwOffset, index.GetBlockLength());
					break;
				}

				pMapDiffBlock->m_iStaticsCount = index.GetBlockLength()/sizeof(CUOStaticItemRec);
				pMapDiffBlock->m_pStaticsBlock = new CUOStaticItemRec[pMapDiffBlock->m_iStaticsCount];
				if ( !g_Install.ReadMulData(*pFileStadif, index, pMapDiffBlock->m_pStaticsBlock) )
				{
					// This shouldn't happen, if this fails then the block will
					// be left with no statics
					pMapDiffBlock->m_iStaticsCount = 0;
					delete[] pMapDiffBlock->m_pStaticsBlock;
					pMapDiffBlock->m_pStaticsBlock = NULL;
					g_Log.EventError("Reading stadif%d.mul FAILED. [index=%lu offset=%lu]\n", map, dwBlockId, dwOffset);
					break;
				}
			}
		} // Stadif
	}

	m_bLoaded = true;
}