예제 #1
0
void CXZip::PreloadData()
{
    Assert( IsValid() );

    // Ensure it isn't already preloaded
    if( m_pPreloadedData )
        return;

    // If I don't have a preloaded section, ignore the request.
    if( !m_Header.PreloadBytes || !m_Header.PreloadDirectoryEntries )
        return;

    // Allocate and read the data block in:
#ifndef _X360
    MEM_ALLOC_CREDIT_( "xZip" );
    m_pPreloadedData = malloc( m_Header.PreloadBytes );

    // Just drop out if allocation fails;
    if ( !m_pPreloadedData )
        return;

    m_pRead( m_pPreloadedData, m_nPreloadStart, -1, m_Header.PreloadBytes, m_hUser );
#else
    int nAlignedStart = AlignValue( ( m_nPreloadStart - XBOX_HDD_SECTORSIZE ) + 1, XBOX_HDD_SECTORSIZE );
    int nBytesToRead = AlignValue( ( m_nPreloadStart - nAlignedStart ) + m_Header.PreloadBytes, XBOX_HDD_SECTORSIZE );
    int nBytesBuffer = AlignValue( nBytesToRead, XBOX_HDD_SECTORSIZE );
    byte *pReadData = (byte *)malloc( nBytesBuffer );

    // Just drop out if allocation fails;
    if ( !pReadData )
        return;

    MEM_ALLOC_CREDIT_( "xZip" );
    m_pRead( pReadData, nAlignedStart, nBytesBuffer,nBytesToRead, m_hUser );
    m_pPreloadedData = pReadData + ( m_nPreloadStart - nAlignedStart );
#endif

    // Set up the preload directory:
    m_pPreloadDirectory = (xZipDirectoryEntry_t*)m_pPreloadedData;

    // Swap the preload directory:
    if ( m_bByteSwapped )
    {
        for ( unsigned nDirectoryEntry = 0; nDirectoryEntry < m_Header.PreloadDirectoryEntries; nDirectoryEntry++ )
        {
            m_Swap.SwapFieldsToTargetEndian<xZipDirectoryEntry_t>( &( m_pPreloadDirectory[nDirectoryEntry] ) );
        }
    }

    // Set up the regular 2 preload mapping section:
    m_nRegular2PreloadEntryMapping = (unsigned short*)(((unsigned char*)m_pPreloadDirectory) + ( sizeof(xZipDirectoryEntry_t) * m_Header.PreloadDirectoryEntries ));

    // Swap the regular to preload mapping
    if ( m_bByteSwapped )
    {
        m_Swap.SwapBufferToTargetEndian<short>( (short *)m_nRegular2PreloadEntryMapping,  (short *)m_nRegular2PreloadEntryMapping, m_Header.DirectoryEntries );
    }

}
예제 #2
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CMemoryPool::AddNewBlob()
{
	MEM_ALLOC_CREDIT_(m_pszAllocOwner);

	int sizeMultiplier;

	if( m_GrowMode == GROW_SLOW )
	{
		sizeMultiplier = 1;
	}
	else
	{
		if ( m_GrowMode == GROW_NONE )
		{
			// Can only have one allocation when we're in this mode
			if( m_NumBlobs != 0 )
			{
				Assert( !"CMemoryPool::AddNewBlob: mode == GROW_NONE" );
				return;
			}
		}
		
		// GROW_FAST and GROW_NONE use this.
		sizeMultiplier = m_NumBlobs + 1;
	}

	// maybe use something other than malloc?
	int nElements = m_BlocksPerBlob * sizeMultiplier;
	int blobSize = m_BlockSize * nElements;
	CBlob *pBlob = (CBlob*)malloc( sizeof(CBlob) - 1 + blobSize + ( m_nAlignment - 1 ) );
	Assert( pBlob );
	
	// Link it in at the end of the blob list.
	pBlob->m_NumBytes = blobSize;
	pBlob->m_pNext = &m_BlobHead;
	pBlob->m_pPrev = pBlob->m_pNext->m_pPrev;
	pBlob->m_pNext->m_pPrev = pBlob->m_pPrev->m_pNext = pBlob;

	// setup the free list
	m_pHeadOfFreeList = AlignValue( pBlob->m_Data, m_nAlignment );
	Assert (m_pHeadOfFreeList);

	void **newBlob = (void**)m_pHeadOfFreeList;
	for (int j = 0; j < nElements-1; j++)
	{
		newBlob[0] = (char*)newBlob + m_BlockSize;
		newBlob = (void**)newBlob[0];
	}

	// null terminate list
	newBlob[0] = NULL;
	m_NumBlobs++;
}
//-----------------------------------------------------------------------------
// Creates a texture that's a render target
//-----------------------------------------------------------------------------
ITextureInternal *CTextureManager::CreateRenderTargetTexture( 
	const char *pRTName,	// NULL for auto-generated name
	int w, 
	int h, 
	RenderTargetSizeMode_t sizeMode, 
	ImageFormat fmt, 
	RenderTargetType_t type, 
	unsigned int textureFlags, 
	unsigned int renderTargetFlags )
{
	MEM_ALLOC_CREDIT_( __FILE__ ": Render target" );

	ITextureInternal *pTexture;
	if ( pRTName )
	{
		// caller is re-initing or changing
		pTexture = FindTexture( pRTName );
		if ( pTexture )
		{
			// Changing the underlying render target, but leaving the pointer and refcount
			// alone fixes callers that have exisiting references to this object.
			ITextureInternal::ChangeRenderTarget( pTexture, w, h, sizeMode, fmt, type, 
					textureFlags, renderTargetFlags );

			// download if ready
			pTexture->Download();
			return pTexture;
		}
	}
 
	pTexture = ITextureInternal::CreateRenderTarget( pRTName, w, h, sizeMode, fmt, type, 
											  textureFlags, renderTargetFlags );
	if ( !pTexture )
		return NULL;

	// Add the render target to the list of textures
	// that way it'll get cleaned up correctly in case of a task switch
	m_TextureList.Insert( pTexture->GetName(), pTexture );

	// NOTE: This will download the texture only if the shader api is ready
	pTexture->Download();

	return pTexture;
}
예제 #4
0
char* CXZip::GetEntryFileName( unsigned CRC, char* pDefault )
{
    Assert( IsValid() );

    if( IsRetail() )
    {
        return pDefault;
    }
    else
    {

        // Make sure I have a filename section:
        if( m_Header.FilenameStringsOffset == 0 || m_Header.FilenameEntries == 0 || CRC == 0 )
        {
            return pDefault;
        }

        // If the filename chunk isn't here, load it up:
        if( !m_pFilenames )
        {
            MEM_ALLOC_CREDIT_("xZip");
            m_pFilenames = (xZipFilenameEntry_t*)malloc( m_Header.FilenameStringsLength );
            m_pRead( m_pFilenames, m_Header.FilenameStringsOffset, -1, m_Header.FilenameStringsLength, m_hUser );

            // TODO: Swap!
            for( unsigned int i=0; i< m_Header.FilenameEntries; i++ )
            {
                m_Swap.SwapFieldsToTargetEndian<xZipFilenameEntry_t>(&m_pFilenames[i]);
            }
        }

        // Find this entry in the preload directory
        xZipFilenameEntry_t entry;
        entry.FilenameCRC = CRC;

        xZipFilenameEntry_t* found = (xZipFilenameEntry_t*)bsearch( &entry, m_pFilenames, m_Header.FilenameEntries, sizeof(xZipFilenameEntry_t), xZipFilenameEntry_t::xZipFilenameEntryCompare );

        if( !found )
            return pDefault;

        return (((char*)m_pFilenames) + found->FilenameOffset) - m_Header.FilenameStringsOffset;
    }
}
예제 #5
0
IServerNetworkable *PyEntityFactory::Create( const char *pClassName )
{
	MEM_ALLOC_CREDIT_("Entities");
	CBaseEntity *pEnt = NULL;
	try
	{
		boost::python::object inst = m_PyClass();

		pEnt = boost::python::extract<CBaseEntity *>(inst);
		bool bServerOnly = pEnt->IsEFlagSet(EFL_SERVER_ONLY);
		if( !bServerOnly && g_SetupNetworkTablesOnHold ) {
			pEnt->AddEFlags( EFL_NO_AUTO_EDICT_ATTACH );
		}

		pEnt->SetPyInstance( inst );
		pEnt->PostConstructor( pClassName );
		
		if( !bServerOnly && g_SetupNetworkTablesOnHold )
		{
			EntityInfoOnHold info;
			info.ent = pEnt;
			info.edict = engine->CreateEdict();
			AddSetupNetworkTablesOnHoldEnt(info);
			gEntList.AddNetworkableEntity( pEnt, ENTINDEX(info.edict) );
		}

		return pEnt->NetworkProp();
	}
	catch( bp::error_already_set & )
	{
		Warning("Failed to create entity %s:\n", pClassName );
		PyErr_Print();
		return NULL;
	}
	return NULL;
}