Beispiel #1
0
void CompactTexdataArray( texdatamap_t *pMap )
{
    CUtlVector<char>	oldStringData;
    oldStringData.CopyArray( g_TexDataStringData.Base(), g_TexDataStringData.Count() );
    g_TexDataStringData.RemoveAll();
    CUtlVector<int>		oldStringTable;
    oldStringTable.CopyArray( g_TexDataStringTable.Base(), g_TexDataStringTable.Count() );
    g_TexDataStringTable.RemoveAll();
    CUtlVector<dtexdata_t> oldTexData;
    oldTexData.CopyArray( dtexdata, numtexdata );
    // clear current table and rebuild
    numtexdata = 0;
    for ( int i = 0; i < oldTexData.Count(); i++ )
    {
        // unreferenced, note in map and skip
        if ( !pMap[i].refCount )
        {
            pMap[i].outputIndex = -1;
            continue;
        }
        pMap[i].outputIndex = numtexdata;

        // get old string and re-add to table
        const char *pString = &oldStringData[oldStringTable[oldTexData[i].nameStringTableID]];
        int nameIndex = TexDataStringTable_AddOrFindString( pString );
        // copy old texdata and fixup with new name in compacted table
        dtexdata[numtexdata] = oldTexData[i];
        dtexdata[numtexdata].nameStringTableID = nameIndex;
        numtexdata++;
    }
}
Beispiel #2
0
void DiscoverMacroTextures()
{
    CUtlDict<int,int> tempDict;

    g_FaceMacroTextureInfos.SetSize( numfaces );
    for ( int iFace=0; iFace < numfaces; iFace++ )
    {
        texinfo_t *pTexInfo = &texinfo[dfaces[iFace].texinfo];
        if ( pTexInfo->texdata < 0 )
            continue;

        dtexdata_t *pTexData = &dtexdata[pTexInfo->texdata];
        const char *pMaterialName = &g_TexDataStringData[ g_TexDataStringTable[pTexData->nameStringTableID] ];

        MaterialSystemMaterial_t hMaterial = FindMaterial( pMaterialName, NULL, false );

        const char *pMacroTextureName = GetMaterialVar( hMaterial, "$macro_texture" );
        if ( pMacroTextureName )
        {
            if ( tempDict.Find( pMacroTextureName ) == tempDict.InvalidIndex() )
            {
                Msg( "-- DiscoverMacroTextures: %s\n", pMacroTextureName );
                tempDict.Insert( pMacroTextureName, 0 );
            }

            int stringID = TexDataStringTable_AddOrFindString( pMacroTextureName );
            g_FaceMacroTextureInfos[iFace].m_MacroTextureNameID = (unsigned short)stringID;
        }
        else
        {
            g_FaceMacroTextureInfos[iFace].m_MacroTextureNameID = 0xFFFF;
        }
    }
}
//-----------------------------------------------------------------------------
// Purpose: Finds or adds a texdata for the specified name
// Input  : *pName - texture name
// Output : int index into dtexdata array
//-----------------------------------------------------------------------------
int FindTexData( const char *pName_ )
{
	char *pName = ( char * )_alloca( strlen( pName_ ) + 1 );
	strcpy( pName, pName_ );
	int i, output;
	bool found;
	dtexdata_t *pTexData;
	MaterialSystemMaterial_t matID;

	for ( i = 0; i < numtexdata; i++ )
	{
		char const *tableName = TexDataStringTable_GetString( GetTexData( i )->nameStringTableID );

		if ( !strcmp( pName, tableName ) )
		{
			return i;
		}
	}

	output = numtexdata;
	if ( numtexdata >= MAX_MAP_TEXDATA )
	{
		Error( "MAX_MAP_TEXDATA" );
	}
	pTexData = GetTexData( output );
	numtexdata++;


	// Save the name of the material.
	pTexData->nameStringTableID = TexDataStringTable_AddOrFindString( pName );
	// Get the width, height, view_width, view_height, and reflectivity from the material system.
	matID = FindOriginalMaterial( pName, &found );
	if( matID == MATERIAL_NOT_FOUND || (!found) )
	{
		qprintf( "WARNING: material not found: \"%s\"\n", pName );
		return -1;
	}

	GetMaterialDimensions( matID, &pTexData->width, &pTexData->height );
	pTexData->view_width = pTexData->width;  // undone: what is this?
	pTexData->view_height = pTexData->height;  // undone: what is this?
	
	GetMaterialReflectivity( matID, pTexData->reflectivity.Base() );
	g_SurfaceProperties[output] = GetSurfaceProperties( matID, pName );

#if 0
	Msg( "reflectivity: %f %f %f\n", 
		pTexData->reflectivity[0],
		pTexData->reflectivity[1],
		pTexData->reflectivity[2] );
#endif

	return output;
}
Beispiel #4
0
int AddCloneTexData( dtexdata_t *pExistingTexData, char const *cloneTexDataName )
{
	int existingIndex = pExistingTexData - GetTexData( 0 );
	dtexdata_t *pNewTexData = GetTexData( numtexdata );
	int newIndex = numtexdata;
	numtexdata++;

	*pNewTexData = *pExistingTexData;
	pNewTexData->nameStringTableID = TexDataStringTable_AddOrFindString( cloneTexDataName );
	g_SurfaceProperties[newIndex] = g_SurfaceProperties[existingIndex];

	return newIndex;
}
Beispiel #5
0
//-----------------------------------------------------------------------------
// Purpose: Finds or adds a texdata for the specified name
// Input  : *pName - texture name
// Output : int index into dtexdata array
//-----------------------------------------------------------------------------
int FindOrCreateTexData( const char *pName_ )
{
	char *pName = ( char * )_alloca( strlen( pName_ ) + 1 );
	strcpy( pName, pName_ );

	int nOutput = FindTexData( pName );
	if ( nOutput >= 0 )
		return nOutput;

	// Didn't find it, add a new one
	nOutput = numtexdata;
	if ( numtexdata >= MAX_MAP_TEXDATA )
	{
		Error( "Too many unique texture mappings, max = %d\n", MAX_MAP_TEXDATA );
	}
	dtexdata_t *pTexData = GetTexData( nOutput );
	numtexdata++;

	// Save the name of the material.
	pTexData->nameStringTableID = TexDataStringTable_AddOrFindString( pName );

	// Get the width, height, view_width, view_height, and reflectivity from the material system.
	bool bFound;
	MaterialSystemMaterial_t matID = FindOriginalMaterial( pName, &bFound );
	if ( matID == MATERIAL_NOT_FOUND || (!bFound) )
	{
		qprintf( "WARNING: material not found: \"%s\"\n", pName );
		return nOutput;
	}

	GetMaterialDimensions( matID, &pTexData->width, &pTexData->height );
	pTexData->view_width = pTexData->width;  // undone: what is this?
	pTexData->view_height = pTexData->height;  // undone: what is this?
	
	GetMaterialReflectivity( matID, pTexData->reflectivity.Base() );
	g_SurfaceProperties[nOutput] = GetSurfaceProperties( matID, pName );

#if 0
	Msg( "reflectivity: %f %f %f\n", 
		pTexData->reflectivity[0],
		pTexData->reflectivity[1],
		pTexData->reflectivity[2] );
#endif

	return nOutput;
}
Beispiel #6
0
//-----------------------------------------------------------------------------
// Purpose: Finds or adds a texdata for the specified name ( same as below except
//   instead of finding the named texture, copies the settings from the passed
//  in sourceTexture. )
// Used for creation of one off .vmt files for water surface textures
// Input  : *pName - texture name
// Output : int index into dtexdata array
//-----------------------------------------------------------------------------
int FindAliasedTexData( const char *pName_, dtexdata_t *sourceTexture )
{
	char *pName = ( char * )_alloca( strlen( pName_ ) + 1 );
	strcpy( pName, pName_ );
	strlwr( pName );
	int i, output;
	bool found;
	dtexdata_t *pTexData;
	MaterialSystemMaterial_t matID;

	for ( i = 0; i < numtexdata; i++ )
	{
		if ( !strcmp( pName, TexDataStringTable_GetString( GetTexData( i )->nameStringTableID ) ) )
			return i;
	}


	output = numtexdata;
	if ( numtexdata >= MAX_MAP_TEXDATA )
	{
		Error( "Too many unique texture mappings, max = %d\n", MAX_MAP_TEXDATA );
	}
	pTexData = GetTexData( output );
	numtexdata++;

	// Save the name of the material.
	pTexData->nameStringTableID = TexDataStringTable_AddOrFindString( pName );

	// Get the width, height, view_width, view_height, and reflectivity from the material system.
	matID = FindOriginalMaterial( TexDataStringTable_GetString( sourceTexture->nameStringTableID ), &found, false );
	if( matID == MATERIAL_NOT_FOUND || (!found) )
	{
		qprintf( "WARNING: material not found: \"%s\"\n", pName );
		return -1;
	}

	GetMaterialDimensions( matID, &pTexData->width, &pTexData->height );
	pTexData->view_width = pTexData->width;  // undone: what is this?
	pTexData->view_height = pTexData->height;  // undone: what is this?
	
	GetMaterialReflectivity( matID, pTexData->reflectivity.Base() );
	g_SurfaceProperties[output] = GetSurfaceProperties( matID, pName );

	return output;
}