NetworkedClass::~NetworkedClass()
{
	if( m_pServerClass )
	{
		m_pServerClass->m_bFree = true;
		m_pServerClass->SetupServerClass(PN_NONE);

		unsigned short lookup = m_ServerClassInfoDatabase.Find( m_pNetworkName );
		if ( lookup != m_ServerClassInfoDatabase.InvalidIndex() )
		{
			m_ServerClassInfoDatabase.Remove( m_pNetworkName );
		}
	}

	free( (void *)m_pNetworkName );
	m_pNetworkName = NULL;
}
Beispiel #2
0
void CClassMap::Add( const char *mapname, const char *classname, int size, DISPATCHFUNCTION factory = 0 )
{
	const char *map = Lookup( classname );
	if ( map && !Q_strcasecmp( mapname, map ) )
		return;

	if ( map )
	{
		int index = m_ClassDict.Find( classname );
		Assert( index != m_ClassDict.InvalidIndex() );
		m_ClassDict.RemoveAt( index );
	}

	classentry_t element;
	element.SetMapName( mapname );
	element.factory = factory;
	element.size = size;
	m_ClassDict.Insert( classname, element );
}
Beispiel #3
0
/**
 * Try to look up named sequences in a CUtlDict cache before falling back to the normal LookupSequence.  It's
 * best to avoid the normal LookupSequence when your models have 750+ sequences...
 */
int CCSPlayerAnimState::CalcSequenceIndex( const char *pBaseName, ... )
{
	VPROF( "CCSPlayerAnimState::CalcSequenceIndex" );

	CheckCachedSequenceValidity();

	char szFullName[512];
	va_list marker;
	va_start( marker, pBaseName );
	Q_vsnprintf( szFullName, sizeof( szFullName ), pBaseName, marker );
	va_end( marker );

	int iSequence = m_namedSequence.Find( szFullName );
	if ( iSequence == m_namedSequence.InvalidIndex() )
	{
		iSequence = GetOuter()->LookupSequence( szFullName );
		m_namedSequence.Insert( szFullName, iSequence );
	}
	else
	{
		iSequence = m_namedSequence[iSequence];
	}

#if defined(CLIENT_DLL) && defined(_DEBUG)
	int realSequence = GetOuter()->LookupSequence( szFullName );
	Assert( realSequence == iSequence );
#endif
	
	// Show warnings if we can't find anything here.
	if ( iSequence == -1 )
	{
		static CUtlDict<int,int> dict;
		if ( dict.Find( szFullName ) == -1 )
		{
			dict.Insert( szFullName, 0 );
			Warning( "CalcSequenceIndex: can't find '%s'.\n", szFullName );
		}

		iSequence = 0;
	}

	return iSequence;
}
//-----------------------------------------------------------------------------
// Restore just the render targets (cause we've got video memory again)
//-----------------------------------------------------------------------------
void CTextureManager::RestoreRenderTargets()
{
	// 360 should not have gotten here
	Assert( !IsX360() );

	for ( int i = m_TextureList.First(); i != m_TextureList.InvalidIndex(); i = m_TextureList.Next( i ) )
	{
		if ( m_TextureList[i]->IsRenderTarget() )
		{
			RestoreTexture( m_TextureList[i] );
		}
	}

	if ( m_pFullScreenTexture )
	{
		g_pShaderAPI->SetFullScreenTextureHandle( m_pFullScreenTexture->GetTextureHandle( 0 ) );
	}

	CacheExternalStandardRenderTargets();
}
void CTextureManager::AddTextureAlias( const char *pAlias, const char *pRealName )
{
	if	( (pAlias == NULL) || (pRealName == NULL) )
		return; //invalid alias

	char szCleanName[MAX_PATH];
	int index = m_TextureAliases.Find( NormalizeTextureName( pAlias, szCleanName, sizeof( szCleanName ) ) );

	if	( index != m_TextureAliases.InvalidIndex() )
	{
		AssertMsg( Q_stricmp( pRealName, m_TextureAliases[index] ) == 0, "Trying to use one name to alias two different textures." );
		RemoveTextureAlias( pAlias ); //remove the old alias to make room for the new one.
	}

	size_t iRealNameLength = strlen( pRealName ) + 1;
	char *pRealNameCopy = new char [iRealNameLength];
	memcpy( pRealNameCopy, pRealName, iRealNameLength );

	m_TextureAliases.Insert( szCleanName, pRealNameCopy );
}
//-----------------------------------------------------------------------------
// Reloads all textures
//-----------------------------------------------------------------------------
void CTextureManager::ForceAllTexturesIntoHardware( void )
{
	if ( IsX360() )
		return;

	IMaterial *pMaterial = MaterialSystem()->FindMaterial( "engine/preloadtexture", "texture preload" );
	pMaterial = ((IMaterialInternal *)pMaterial)->GetRealTimeVersion(); //always work with the realtime material internally
	bool bFound;
	IMaterialVar *pBaseTextureVar = pMaterial->FindVar( "$basetexture", &bFound );
	if( !bFound )
	{
		return;
	}

	for ( int i = m_TextureList.First(); i != m_TextureList.InvalidIndex(); i = m_TextureList.Next( i ) )
	{
		// Put the texture back onto the board
		ForceTextureIntoHardware( m_TextureList[i], pMaterial, pBaseTextureVar );
	}
}
void CGECreateServer::AddWeaponSet( const char *group, KeyValues *set )
{
	int grpIdx = m_WeaponSets.Find( group );
	if ( grpIdx == m_WeaponSets.InvalidIndex() )
		grpIdx = m_WeaponSets.Insert( group, new CUtlDict<char*, int>() );

	char *name = new char[32];
	Q_strncpy( name, set->GetString("print_name", "Unnamed"), 32 );
	
	int setIdx = m_WeaponSets[grpIdx]->Find( set->GetName() );
	if ( setIdx != m_WeaponSets[grpIdx]->InvalidIndex() )
	{
		// Replace the existing set with this one
		delete [] m_WeaponSets[grpIdx]->Element(setIdx);
		m_WeaponSets[grpIdx]->RemoveAt(grpIdx);
	}

	// Insert the set
	m_WeaponSets[grpIdx]->Insert( set->GetName(), name );
}
void Draw_DecalSetName( int decal, char *name )
{
	while ( decal >= g_DecalLookup.Count() )
	{
		int idx = g_DecalLookup.AddToTail();
		g_DecalLookup[ idx ] = 0;
	}

	int lookup = g_DecalDictionary.Find( name );
	if ( lookup == g_DecalDictionary.InvalidIndex() )
	{
		DecalEntry entry;
		entry.material = GL_LoadMaterial( name );
		entry.index = decal;

		lookup = g_DecalDictionary.Insert( name, entry );
	}

	g_DecalLookup[ decal ] = lookup;
}
void CTextureManager::RemoveUnusedTextures( void )
{
	int iNext;
	for ( int i = m_TextureList.First(); i != m_TextureList.InvalidIndex(); i = iNext )
	{
		iNext = m_TextureList.Next( i );

#ifdef _DEBUG
		if ( m_TextureList[i]->GetReferenceCount() < 0 )
		{
			Warning( "RemoveUnusedTextures: pTexture->m_referenceCount < 0 for %s\n", m_TextureList[i]->GetName() );
		}
#endif
		if ( m_TextureList[i]->GetReferenceCount() <= 0 )
		{
			ITextureInternal::Destroy( m_TextureList[i] );
			m_TextureList.RemoveAt( i );
		}
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *decalname - 
// Output : int
//-----------------------------------------------------------------------------
int CDecalEmitterSystem::GetDecalIndexForName( char const *decalname )
{
	if ( !decalname  || !decalname[ 0 ] )
		return -1;

	int idx = m_Decals.Find( decalname );
	if ( idx == m_Decals.InvalidIndex() )
		return -1;

	DecalEntry *e = &m_Decals[ idx ];
	Assert( e );
	int count = e->indices.Count();
	if ( count <= 0 )
		return -1;

	float totalweight = 0.0f;
	int slot = 0;

	for ( int i = 0; i < count; i++ )
	{
		int idx = e->indices[ i ];
		DecalListEntry *item = &m_AllDecals[ idx ];
		Assert( item );
		
		if ( !totalweight )
		{
			slot = idx;
		}

		// Always assume very first slot will match
		totalweight += item->weight;
		if ( !totalweight || random->RandomFloat(0,totalweight) < item->weight )
		{
			slot = idx;
		}
	}

	return m_AllDecals[ slot ].precache_index;
}
Beispiel #11
0
void CClassMap::PyAdd( const char *mapname, const char *classname, int size, PyEntityFactory *factory )
{
	if( !factory )
		return;

	const char *map = Lookup( classname );
	if ( map && !Q_strcasecmp( mapname, map ) )
		return;

	if ( map )
	{
		int index = m_ClassDict.Find( classname );
		Assert( index != m_ClassDict.InvalidIndex() );
		m_ClassDict.RemoveAt( index );
	}

	classentry_t element;
	element.SetMapName( mapname );
	element.pyfactory = factory;
	element.size = size;
	m_ClassDict.Insert( classname, element );
}
//-----------------------------------------------------------------------------
// Purpose: Find a free PyServerClass and claim it
//			Send a message to the clients to claim a client class and set it to
//			the right type.
//-----------------------------------------------------------------------------
NetworkedClass::NetworkedClass( const char *pNetworkName, boost::python::object cls_type )
{
	m_pNetworkName = strdup( pNetworkName );
	m_pServerClass = NULL;
	PyServerClass *p;

	// See if there is already an entity with this network name
	unsigned short lookup = m_ServerClassInfoDatabase.Find( pNetworkName );
	if ( lookup != m_ServerClassInfoDatabase.InvalidIndex() )
	{
		Warning("NetworkedClass: %s already added. Replacing with new data. Element name: %s\n", pNetworkName, m_ServerClassInfoDatabase.Element(lookup) );
		p = FindPyServerClass( m_ServerClassInfoDatabase.Element(lookup) );
		if( !p )
		{
			Warning("NetworkedClass: ServerClass %s not found\n", m_ServerClassInfoDatabase.Element(lookup) );
			return;
		}
		if( p->m_pNetworkedClass )
			p->m_pNetworkedClass->m_pServerClass = NULL;
	}
	else
	{
		// Find a free server class and add it to the database
		p = FindFreePyServerClass();
		if( !p ) {
			Warning("Couldn't create PyServerClass %s: Out of free PyServerClasses\n", pNetworkName);
			return;
		}

		lookup = m_ServerClassInfoDatabase.Insert(pNetworkName, p->GetName());
	}

	m_pServerClass = p;
	m_PyClass = cls_type;
	p->m_bFree = false;
	p->m_pNetworkedClass = this;

	SetupServerClass();
}
int CTextureManager::FindNext( int iIndex, ITextureInternal **pTexInternal )
{
	if ( iIndex == -1 && m_TextureList.Count() )
	{
		iIndex = m_TextureList.First();
	}
	else if ( !m_TextureList.Count() || !m_TextureList.IsValidIndex( iIndex ) )
	{
		*pTexInternal = NULL;
		return -1;
	}

	*pTexInternal = m_TextureList[iIndex];

	iIndex = m_TextureList.Next( iIndex );
	if ( iIndex == m_TextureList.InvalidIndex() )
	{
		// end of list
		iIndex = -1;
	}

	return iIndex;
}
NetworkedClass::~NetworkedClass()
{
	unsigned short lookup;

	// Remove pointer
	lookup = m_NetworkClassDatabase.Find( m_pNetworkName );
	if ( lookup != m_NetworkClassDatabase.InvalidIndex() )
	{
		// Only remove if it's our pointer. Otherwise we are already replaced.
		if( m_NetworkClassDatabase.Element( lookup ) == this )
			m_NetworkClassDatabase.RemoveAt( lookup );
	}
	else
	{
		Warning("NetworkedClass destruction: invalid networkclass %s\n", m_pNetworkName);
	}

	if( m_pClientClass )
	{
		m_pClientClass->m_bFree = true;
	}
	free( (void *)m_pNetworkName );
	m_pNetworkName = NULL;
}
void ProcessVCD( CUtlDict< VCDList, int >& database, CUtlSymbol& vcdname )
{
    // vprint( 0, "Processing '%s'\n", g_Analysis.symbols.String( vcdname ) );

    // Load the .vcd
    char fullname[ 512 ];
    Q_snprintf( fullname, sizeof( fullname ), "%s", g_Analysis.symbols.String( vcdname ) );

    LoadScriptFile( fullname );

    CChoreoScene *scene = ChoreoLoadScene( fullname, NULL, &g_TokenProcessor, Con_Printf );
    if ( scene )
    {
        bool first = true;
        // Now iterate the events looking for speak events
        int c = scene->GetNumEvents();
        for ( int i = 0; i < c; i++ )
        {
            CChoreoEvent *e = scene->GetEvent( i );

            if ( e->GetType() == CChoreoEvent::MOVETO )
            {
                SpewMoveto( first, fullname, e );
                first = false;
            }

            if ( e->GetType() != CChoreoEvent::SPEAK )
                continue;

            // Look up sound in sound emitter system
            char const *wavename = soundemitter->GetWavFileForSound( e->GetParameters(), NULL );
            if ( !wavename || !wavename[ 0 ] )
            {
                continue;
            }

            char fullwavename[ 512 ];
            Q_snprintf( fullwavename, sizeof( fullwavename ), "%ssound\\%s",
                        gamedir, wavename );
            Q_FixSlashes( fullwavename );

            // Now add to proper slot
            VCDList *entry = NULL;

            // Add vcd to database
            int slot = database.Find( fullwavename );
            if ( slot == database.InvalidIndex() )
            {
                VCDList nullEntry;
                slot = database.Insert( fullwavename, nullEntry );
            }

            entry = &database[ slot ];
            if ( entry->vcds.Find( vcdname ) == entry->vcds.InvalidIndex() )
            {
                entry->vcds.AddToTail( vcdname );
            }
        }

        if ( vcdonly )
        {
            CheckForOverlappingFlexTracks( scene );
        }
    }

    delete scene;
}
void Correlate( CUtlRBTree< ReferencedFile, int >& referencedfiles, CUtlVector< FileEntry >& contentfiles, const char *modname )
{
	int i;
	int c = contentfiles.Count();
	
	double totalDiskSize = 0;
	double totalReferencedDiskSize = 0;
	double totalWhiteListDiskSize = 0;

	for ( i = 0; i < c; ++i )
	{
		totalDiskSize += contentfiles [ i ].size;
	}

	vprint( 0, "Content tree size on disk %s\n", Q_pretifymem( totalDiskSize, 3 ) );
	
	// Analysis is to walk tree and see which files on disk are referenced in the .lst files
	// Need a fast lookup from file symbol to referenced list
	CUtlRBTree< ReferencedFile, int >	tree( 0, 0, ReferencedFileLessFunc );
	c = referencedfiles.Count();
	for ( i = 0 ; i < c; ++i )
	{
		tree.Insert( referencedfiles[ i ] );
	}

	// Now walk the on disk file and see check off resources which are in referenced
	c = contentfiles.Count();
	int invalidindex = tree.InvalidIndex();
	unsigned int refcounted = 0;
	unsigned int whitelisted = 0;

	filesystem->RemoveFile( CFmtStr( "%swhitelist.lst", g_szReslistDir ), "GAME" );

	for ( i = 0; i < c; ++i )
	{
		FileEntry & entry = contentfiles[ i ];

		ReferencedFile foo;
		foo.sym = entry.sym;

		bool gameref = tree.Find( foo ) != invalidindex;
		char const *fn = g_Analysis.symbols.String( entry.sym );

		bool whitelist = g_WhiteList.Find( entry.sym ) != g_WhiteList.InvalidIndex();

		if ( gameref || whitelist )
		{
			entry.referenced = gameref ? REFERENCED_GAME : REFERENCED_WHITELIST;
			totalReferencedDiskSize += entry.size;
			if ( entry.referenced == REFERENCED_WHITELIST )
			{
				logprint( CFmtStr( "%swhitelist.lst", g_szReslistDir ), "\"%s\\%s\"\n", modname, fn );

				totalWhiteListDiskSize += entry.size;
				++whitelisted;
			}
			++refcounted;
		}
	}

	vprint( 0, "Found %i referenced (%i whitelist) files in tree, %s\n", refcounted, whitelisted, Q_pretifymem( totalReferencedDiskSize, 2 ) );
	vprint( 0, "%s appear unused\n", Q_pretifymem( totalDiskSize - totalReferencedDiskSize, 2 ) );

	// Now sort and dump the unreferenced ones..
	vprint( 0, "Sorting unreferenced files list...\n" );

	CUtlRBTree< FileEntry, int >	unreftree( 0, 0, FileEntryLessFunc );
	for ( i = 0; i < c; ++i )
	{
		FileEntry & entry = contentfiles[ i ];
		if ( entry.referenced != REFERENCED_NO )
			continue;

		unreftree.Insert( entry );
	}

	// Now walk the unref tree in order
	i = unreftree.FirstInorder();
	invalidindex = unreftree.InvalidIndex();
	int index = 0;
	while ( i != invalidindex )
	{
		FileEntry & entry = unreftree[ i ];

		if ( showreferencedfiles )
		{
			vprint( 1, "%6i %12s: %s\n", ++index, Q_pretifymem( entry.size, 2 ), g_Analysis.symbols.String( entry.sym ) );
		}
		
		i = unreftree.NextInorder( i );
	}

	if ( showmapfileusage )
	{
		vprint( 0, "Writing referenced.csv...\n" );

		// Now walk the list of referenced files and print out how many and which maps reference them
		i = tree.FirstInorder();
		invalidindex = tree.InvalidIndex();
		index = 0;
		while ( i != invalidindex )
		{
			ReferencedFile & entry = tree[ i ];

			char ext[ 32 ];
			Q_ExtractFileExtension( g_Analysis.symbols.String( entry.sym ), ext, sizeof( ext ) );

			logprint( "referenced.csv", "\"%s\",\"%s\",%d", g_Analysis.symbols.String( entry.sym ), ext, entry.maplist.Count() );

			int mapcount = entry.maplist.Count();
			for ( int j = 0 ; j < mapcount; ++j )
			{
				char basemap[ 128 ];
				Q_FileBase( g_Analysis.symbols.String( entry.maplist[ j ] ), basemap, sizeof( basemap ) );
				logprint( "referenced.csv", ",\"%s\"", basemap );
			}

			logprint( "referenced.csv", "\n" );
			
			i = tree.NextInorder( i );
		}
	}


	vprint( 0, "\nBuilding directory summary list...\n" );

	// Now build summaries by root branch off of gamedir (e.g., for sound, materials, models, etc.)
	CUtlDict< DirEntry, int > directories;
	invalidindex = directories.InvalidIndex();
	for ( i = 0; i < c; ++i )
	{
		FileEntry & entry = contentfiles[ i ];

		// Get the dir name
		char const *dirname = g_Analysis.symbols.String( entry.sym );

		const char *backslash = strstr( dirname, "\\" );

		char dir[ 256 ];
		if ( !backslash )
		{
			dir[0] = 0;
		}
		else
		{
			Q_strncpy( dir, dirname, backslash - dirname + 1);
		}

		
		int idx = directories.Find( dir );
		if ( idx == invalidindex )
		{
			DirEntry foo;
			idx = directories.Insert( dir, foo );
		}

		DirEntry & de = directories[ idx ];
		de.total += entry.size;
		if ( entry.referenced == REFERENCED_NO )
		{
			de.unreferenced += entry.size;
		}
		if ( entry.referenced == REFERENCED_WHITELIST )
		{
			de.whitelist += entry.size;
		}
	}

	if ( spewdeletions )
	{
		// Spew deletion commands to console
		if ( immediatedelete )
		{
			vprint( 0, "\n\nDeleting files...\n" );
		}
		else
		{
			vprint( 0, "\n\nGenerating deletions.bat\n" );
		}

		i = unreftree.FirstInorder();
		invalidindex = unreftree.InvalidIndex();
		float deletionSize = 0.0f;
		int deletionCount = 0;

		while ( i != invalidindex )
		{
			FileEntry & entry = unreftree[ i ];
			i = unreftree.NextInorder( i );

			// Don't delete stuff that's in the white list
			if ( g_WhiteList.Find( entry.sym ) != g_WhiteList.InvalidIndex() )
			{
				if ( verbose )
				{
					vprint( 0, "whitelist blocked deletion of %s\n", g_Analysis.symbols.String( entry.sym ) );
				}
				continue;
			}

			++deletionCount;
			deletionSize += entry.size;

			if ( immediatedelete ) 
			{
				if ( _chmod( g_Analysis.symbols.String( entry.sym ), _S_IWRITE ) == -1 )
				{
					vprint( 0, "Could not find file %s\n", g_Analysis.symbols.String( entry.sym ) );
				}
				if ( _unlink( g_Analysis.symbols.String( entry.sym ) ) == -1 )
				{
					vprint( 0, "Could not delete file %s\n", g_Analysis.symbols.String( entry.sym ) );
				}

				if ( deletionCount % 1000 == 0 )
				{
					vprint( 0, "...deleted %i files\n", deletionCount );
				}
			}
			else
			{
				logprint( "deletions.bat", "del \"%s\" /f\n",  g_Analysis.symbols.String( entry.sym ) );
			}
		}

		vprint( 0, "\nFile deletion (%d files, %s)\n\n", deletionCount, Q_pretifymem(deletionSize, 2) );
	}

	double grand_total = 0;
	double grand_total_unref = 0;
	double grand_total_white = 0;

	char totalstring[ 20 ];
	char unrefstring[ 20 ];
	char refstring[ 20 ];
	char whiteliststring[ 20 ];

	vprint( 0, "---------------------------------------- Summary ----------------------------------------\n" );

	vprint( 0, "% 15s               % 15s               % 15s               % 15s %12s\n",
		"Referenced",
		"WhiteListed",
		"Unreferenced",
		"Total",
		"Directory" );

	// Now walk the dictionary in order
	i = directories.First();
	while ( i != invalidindex )
	{
		DirEntry & de = directories[ i ];

		double remainder = de.total - de.unreferenced;

		float percent_unref = 0.0f;
		float percent_white = 0.0f;
		if ( de.total > 0 )
		{
			percent_unref = 100.0f * (float)de.unreferenced / (float)de.total;
			percent_white = 100.0f * (float)de.whitelist / (float)de.total;
		}

		Q_strncpy( totalstring, Q_pretifymem( de.total, 2 ), sizeof( totalstring ) );
		Q_strncpy( unrefstring, Q_pretifymem( de.unreferenced, 2 ), sizeof( unrefstring ) );
		Q_strncpy( refstring, Q_pretifymem( remainder, 2 ), sizeof( refstring ) );
		Q_strncpy( whiteliststring, Q_pretifymem( de.whitelist, 2 ), sizeof( whiteliststring ) );

		vprint( 0, "%15s (%8.3f%%)   %15s (%8.3f%%)   %15s (%8.3f%%)   %15s => dir: %s\n",
			refstring, 100.0f - percent_unref, whiteliststring, percent_white, unrefstring, percent_unref, totalstring, directories.GetElementName( i ) );

		grand_total += de.total;
		grand_total_unref += de.unreferenced;
		grand_total_white += de.whitelist;

		i = directories.Next( i );
	}

	Q_strncpy( totalstring, Q_pretifymem( grand_total, 2 ), sizeof( totalstring ) );
	Q_strncpy( unrefstring, Q_pretifymem( grand_total_unref, 2 ), sizeof( unrefstring ) );
	Q_strncpy( refstring, Q_pretifymem( grand_total - grand_total_unref, 2 ), sizeof( refstring ) );
	Q_strncpy( whiteliststring, Q_pretifymem( grand_total_white, 2 ), sizeof( whiteliststring ) );

	double percent_unref = 100.0 * grand_total_unref / grand_total;
	double percent_white = 100.0 * grand_total_white / grand_total;

	vprint( 0, "-----------------------------------------------------------------------------------------\n" );
	vprint( 0, "%15s (%8.3f%%)   %15s (%8.3f%%)   %15s (%8.3f%%)   %15s\n",
		refstring, 100.0f - percent_unref, whiteliststring, percent_white, unrefstring, percent_unref, totalstring );
}
Beispiel #17
0
void Cmd_AddClientCmdCanExecuteVar( const char *pName )
{
	if ( g_ExtraClientCmdCanExecuteCvars.Find( pName ) == g_ExtraClientCmdCanExecuteCvars.InvalidIndex() )
		g_ExtraClientCmdCanExecuteCvars.Insert( pName );
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *filename - 
//-----------------------------------------------------------------------------
void CDecalEmitterSystem::LoadDecalsFromScript( char const *filename )
{
	KeyValues *kv = new KeyValues( filename );
	Assert( kv );
	if ( kv )
	{
		KeyValues *translation = NULL;
#ifndef _XBOX
		if ( kv->LoadFromFile( filesystem, filename ) )
#else
		if ( kv->LoadFromFile( filesystem, filename, "GAME" ) )
#endif
		{
			KeyValues *p = kv;
			while ( p )
			{
				if ( p->GetFirstSubKey() )
				{
					char const *keyname = p->GetName();

					if ( !Q_stricmp( keyname, TRANSLATION_DATA_SECTION ) )
					{
						translation = p;
					}
					else
					{
						DecalEntry entry;

						for ( KeyValues *sub = p->GetFirstSubKey(); sub != NULL; sub = sub->GetNextKey() )
						{
							MEM_ALLOC_CREDIT();

							DecalListEntry decal;
							decal.precache_index = -1;
							decal.name = m_DecalFileNames.AddString( sub->GetName() );
							decal.weight = sub->GetFloat();

							// Add to global list
							int idx = m_AllDecals.AddToTail( decal );

							// Add index only to local list
							entry.indices.AddToTail( idx );
						}

						// Add entry to main dictionary
						m_Decals.Insert( keyname, entry );
					}
				}
				p = p->GetNextKey();
			}
		}
		else
		{
			Msg( "CDecalEmitterSystem::LoadDecalsFromScript:  Unable to load '%s'\n", filename );
		}

		if ( !translation )
		{
			Msg( "CDecalEmitterSystem::LoadDecalsFromScript:  Script '%s' missing section '%s'\n",
				filename,
				TRANSLATION_DATA_SECTION );
		}
		else
		{
			// Now parse game material to entry translation table
			for ( KeyValues *sub = translation->GetFirstSubKey(); sub != NULL; sub = sub->GetNextKey() )
			{
				// Don't add NULL string to list
				if ( !Q_stricmp( sub->GetString(), "" ) )
					continue;

				int idx = m_Decals.Find( sub->GetString() );
				if ( idx != m_Decals.InvalidIndex() )
				{
					m_GameMaterialTranslation.Insert( sub->GetName(), idx );
				}
				else
				{
					Msg( "CDecalEmitterSystem::LoadDecalsFromScript:  Translation for game material type '%s' references unknown decal '%s'\n",
						sub->GetName(), sub->GetString() );
				}
			}
		}

		kv->deleteThis();
	}
}
//-----------------------------------------------------------------------------
// Purpose: A CPointTemplate has asked us to reconnect all the entity I/O links
//			inside it's templates. Go through the keys and add look for values
//			that match a name within the group's entity	names. Append %d to any
//			found values, which will later be filled out by a unique identifier
//			whenever the template is instanced.
//-----------------------------------------------------------------------------
void Templates_ReconnectIOForGroup( CPointTemplate *pGroup )
{
	int iCount = pGroup->GetNumTemplates();
	if ( !iCount )
		return;

	// First assemble a list of the targetnames of all the templates in the group.
	// We need to store off the original names here, because we're going to change
	// them as we go along.
	CUtlVector< grouptemplate_t > GroupTemplates;
	int i;
	for ( i = 0; i < iCount; i++ )
	{
		grouptemplate_t newGroupTemplate;
		newGroupTemplate.iIndex = pGroup->GetTemplateIndexForTemplate(i);
		newGroupTemplate.pMapDataParser = new CEntityMapData( g_Templates[ newGroupTemplate.iIndex ]->pszMapData, g_Templates[ newGroupTemplate.iIndex ]->iMapDataLength );
		Assert( newGroupTemplate.pMapDataParser );
		newGroupTemplate.pMapDataParser->ExtractValue( "targetname", newGroupTemplate.pszName );
		newGroupTemplate.bChangeTargetname = false;

		GroupTemplates.AddToTail( newGroupTemplate );
	}

	if (pGroup->AllowNameFixup())
	{
		char keyName[MAPKEY_MAXLENGTH];
		char value[MAPKEY_MAXLENGTH];
		char valueclipped[MAPKEY_MAXLENGTH];
		
		// Now go through all the entities in the group and parse their mapdata keyvalues.
		// We're looking for any values that match targetnames of any of the group entities.
		for ( i = 0; i < iCount; i++ )
		{
			// We need to know what instance of each key we're changing.
			// Store a table of the count of the keys we've run into.
			CUtlDict< int, int > KeyInstanceCount;
			CEntityMapData *mapData = GroupTemplates[i].pMapDataParser;

			// Loop through our keys
			if ( !mapData->GetFirstKey(keyName, value) )
				continue;

			do 
			{
				// Ignore targetnames
				if ( !stricmp( keyName, "targetname" ) )
					continue;

				// Add to the count for this 
				int idx = KeyInstanceCount.Find( keyName );
				if ( idx == KeyInstanceCount.InvalidIndex() )
				{
					idx = KeyInstanceCount.Insert( keyName, 0 );
				}
				KeyInstanceCount[idx]++;

				// Entity I/O values are stored as "Targetname,<data>", so we need to see if there's a ',' in the string
				char *sValue = value;
				// FIXME: This is very brittle. Any key with a , will not be found.
				char *s = strchr( value, ',' );
				if ( s )
				{
					// Grab just the targetname of the receiver
					Q_strncpy( valueclipped, value, (s - value+1) );
					sValue = valueclipped;
				}

				// Loop through our group templates
				for ( int iTName = 0; iTName < iCount; iTName++ )
				{
					char *pName = GroupTemplates[iTName].pszName;
					if ( stricmp( pName, sValue ) )
						continue;

					if ( template_debug.GetInt() )
					{
						Msg("Template Connection Found: Key %s (\"%s\") in entity named \"%s\"(%d) matches entity %d's targetname\n", keyName, sValue, GroupTemplates[i].pszName, i, iTName );
					}

					char newvalue[MAPKEY_MAXLENGTH];

					// Get the current key instance. (-1 because it's this one we're changing)
					int nKeyInstance = KeyInstanceCount[idx] - 1;

					// Add our IO value to the targetname
					// We need to append it if this isn't an Entity I/O value, or prepend it to the ',' if it is
					if ( s )
					{
						Q_strncpy( newvalue, valueclipped, MAPKEY_MAXLENGTH );
						Q_strncat( newvalue, ENTITYIO_FIXUP_STRING, sizeof(newvalue), COPY_ALL_CHARACTERS );
						Q_strncat( newvalue, s, sizeof(newvalue), COPY_ALL_CHARACTERS );
						mapData->SetValue( keyName, newvalue, nKeyInstance );
					}
					else
					{
						Q_strncpy( newvalue, sValue, MAPKEY_MAXLENGTH );
						Q_strncat( newvalue, ENTITYIO_FIXUP_STRING, sizeof(newvalue), COPY_ALL_CHARACTERS );
						mapData->SetValue( keyName, newvalue, nKeyInstance );
					}
					
					// Remember we changed this targetname
					GroupTemplates[iTName].bChangeTargetname = true;

					// Set both entity's flags telling them their template needs fixup when it's spawned
					g_Templates[ GroupTemplates[i].iIndex ]->bNeedsEntityIOFixup = true;
					g_Templates[ GroupTemplates[iTName].iIndex ]->bNeedsEntityIOFixup = true;
				}
			} 
			while ( mapData->GetNextKey(keyName, value) );
		}

		// Now change targetnames for all entities that need them changed
		for ( i = 0; i < iCount; i++ )
		{
			char value[MAPKEY_MAXLENGTH];

			if ( GroupTemplates[i].bChangeTargetname )
			{
				CEntityMapData *mapData = GroupTemplates[i].pMapDataParser;
				mapData->ExtractValue( "targetname", value );
				Q_strncat( value, ENTITYIO_FIXUP_STRING, sizeof(value), COPY_ALL_CHARACTERS );
				mapData->SetValue( "targetname", value );
			}
		}
	}

	// Delete our group parsers
	for ( i = 0; i < iCount; i++ )
	{
		delete GroupTemplates[i].pMapDataParser;
	}
	GroupTemplates.Purge();
}
Beispiel #20
0
void CClassMap::PyRemove( const char *classname )
{
	int index = m_ClassDict.Find( classname );
	Assert( index != m_ClassDict.InvalidIndex() );
	m_ClassDict.RemoveAt( index );
}
Beispiel #21
0
//-----------------------------------------------------------------------------
// Purpose: 
// Output : ITEM_FILE_INFO_HANDLE
//-----------------------------------------------------------------------------
ITEM_FILE_INFO_HANDLE GetInvalidItemInfoHandle( void )
{
	return (ITEM_FILE_INFO_HANDLE)m_ItemInfoDatabase.InvalidIndex();
}
void CTextureManager::SetExcludedTextures( const char *pScriptName )
{
	// clear all exisiting texture's exclusion
	for ( int i = m_TextureExcludes.First(); i != m_TextureExcludes.InvalidIndex(); i = m_TextureExcludes.Next( i ) )
	{
		ITextureInternal *pTexture = FindTexture( m_TextureExcludes.GetElementName( i ) );
		if ( pTexture )
		{
			pTexture->MarkAsExcluded( false, 0 );
		}
	}
	m_TextureExcludes.RemoveAll();

	MEM_ALLOC_CREDIT();

	// get optional script
	CUtlBuffer excludeBuffer( 0, 0, CUtlBuffer::TEXT_BUFFER );
	if ( g_pFullFileSystem->ReadFile( pScriptName, NULL, excludeBuffer ) )
	{
		char szToken[MAX_PATH];
		while ( 1 )
		{
			// must support spaces in names without quotes
			// have to brute force parse up to a valid line
			while ( 1 )
			{
				excludeBuffer.EatWhiteSpace();
				if ( !excludeBuffer.EatCPPComment() )
				{
					// not a comment
					break;
				}
			}
			excludeBuffer.GetLine( szToken, sizeof( szToken ) );
			int tokenLength = strlen( szToken );
			if ( !tokenLength )
			{
				// end of list
				break;
			}

			// remove all trailing whitespace
			while ( tokenLength > 0 )
			{
				tokenLength--;
				if ( isgraph( szToken[tokenLength] ) )
				{
					break;
				}
				szToken[tokenLength] = '\0';
			}

			// first optional token may be a dimension limit hint
			int nDimensionsLimit = 0;
			char *pTextureName = szToken;
			if ( pTextureName[0] != 0 && isdigit( pTextureName[0] ) )
			{
				nDimensionsLimit = atoi( pTextureName );
				
				// skip forward to name
				for ( ;; )
				{
					char ch = *pTextureName;
					if ( !ch || ( !isdigit( ch ) && !isspace( ch ) ) )
					{
						break;
					}
					pTextureName++;
				}
			}

			char szCleanName[MAX_PATH];
			NormalizeTextureName( pTextureName, szCleanName, sizeof( szCleanName ) );

			if ( m_TextureExcludes.Find( szCleanName ) != m_TextureExcludes.InvalidIndex() )
			{
				// avoid duplicates
				continue;
			}

			m_TextureExcludes.Insert( szCleanName, nDimensionsLimit );

			// set any existing texture's exclusion
			// textures that don't exist yet will get caught during their creation path
			ITextureInternal *pTexture = FindTexture( szCleanName );
			if ( pTexture )
			{
				pTexture->MarkAsExcluded( ( nDimensionsLimit == 0 ), nDimensionsLimit );
			}
		}
	}
}
void CTextureManager::Shutdown()
{
	FreeStandardRenderTargets();

	// These checks added because it's possible for shutdown to be called before the material system is 
	// fully initialized.
	if ( m_pWhiteTexture )
	{
		m_pWhiteTexture->DecrementReferenceCount();
		m_pWhiteTexture = NULL;
	}

	if ( m_pBlackTexture )
	{
		m_pBlackTexture->DecrementReferenceCount();
		m_pBlackTexture = NULL;
	}

	if ( m_pGreyTexture )
	{
		m_pGreyTexture->DecrementReferenceCount();
		m_pGreyTexture = NULL;
	}

	if ( m_pGreyAlphaZeroTexture )
	{
		m_pGreyAlphaZeroTexture->DecrementReferenceCount();
		m_pGreyAlphaZeroTexture = NULL;
	}

	if ( m_pNormalizationCubemap )
	{
		m_pNormalizationCubemap->DecrementReferenceCount();
		m_pNormalizationCubemap = NULL;
	}

	if ( m_pSignedNormalizationCubemap )
	{
		m_pSignedNormalizationCubemap->DecrementReferenceCount();
		m_pSignedNormalizationCubemap = NULL;
	}

	if ( m_pShadowNoise2D )
	{
		m_pShadowNoise2D->DecrementReferenceCount();
		m_pShadowNoise2D = NULL;
	}

	if ( m_pIdentityLightWarp )
	{
		m_pIdentityLightWarp->DecrementReferenceCount();
		m_pIdentityLightWarp = NULL;
	}

	if ( m_pErrorTexture )
	{
		m_pErrorTexture->DecrementReferenceCount();
		m_pErrorTexture = NULL;
	}

	ReleaseTextures();

	if ( m_pErrorRegen )
	{
		m_pErrorRegen->Release();
		m_pErrorRegen = NULL;
	}

	for ( int i = m_TextureList.First(); i != m_TextureList.InvalidIndex(); i = m_TextureList.Next( i ) )
	{
		ITextureInternal::Destroy( m_TextureList[i] );
	}
	m_TextureList.RemoveAll();

	for( int i = m_TextureAliases.First(); i != m_TextureAliases.InvalidIndex(); i = m_TextureAliases.Next( i ) )
	{
		delete []m_TextureAliases[i];
	}
	m_TextureAliases.RemoveAll();

	m_TextureExcludes.RemoveAll();
}
//-----------------------------------------------------------------------------
// Purpose: 
// Output : WEAPON_FILE_INFO_HANDLE
//-----------------------------------------------------------------------------
WEAPON_FILE_INFO_HANDLE GetInvalidWeaponInfoHandle( void )
{
	return (WEAPON_FILE_INFO_HANDLE)m_WeaponInfoDatabase.InvalidIndex();
}
//-----------------------------------------------------------------------------
// Purpose: 
// Output : PLAYERCLASS_FILE_INFO_HANDLE
//-----------------------------------------------------------------------------
PLAYERCLASS_FILE_INFO_HANDLE GetInvalidPlayerClassInfoHandle( void )
{
	return (PLAYERCLASS_FILE_INFO_HANDLE)m_PlayerClassInfoDatabase.InvalidIndex();
}
// Compute master/slave, count, endtime info for close captioning data
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CChoreoChannel::ReconcileCloseCaption()
{
	// Create a dictionary based on the combined token name
	CUtlDict< EventGroup, int > validSpeakEventsGroupedByName;

	int i;
	// Sort items
	int c = GetNumEvents();
	for ( i = 0; i < c; i++ )
	{
		CChoreoEvent *e = GetEvent( i );
		Assert( e );
		if ( e->GetType() != CChoreoEvent::SPEAK )
			continue;

		CChoreoEvent::CLOSECAPTION type;

		type = e->GetCloseCaptionType();
		if ( type == CChoreoEvent::CC_DISABLED )
		{
			e->SetUsingCombinedFile( false );
			e->SetRequiredCombinedChecksum( 0 );
			e->SetNumSlaves( 0 );
			e->SetLastSlaveEndTime( 0.0f );
			continue;
		}

		char const *name = e->GetCloseCaptionToken();
		if ( !name || !name[0] )
		{
			// Fixup invalid slave tag
			if ( type == CChoreoEvent::CC_SLAVE )
			{
				e->SetCloseCaptionType( CChoreoEvent::CC_MASTER );
				e->SetUsingCombinedFile( false );
				e->SetRequiredCombinedChecksum( 0 );
				e->SetNumSlaves( 0 );
				e->SetLastSlaveEndTime( 0.0f );
			}
			continue;
		}
	
		int idx = validSpeakEventsGroupedByName.Find( name );
		if ( idx == validSpeakEventsGroupedByName.InvalidIndex() )
		{
			EventGroup eg;
			eg.timeSortedEvents.Insert( e );
			validSpeakEventsGroupedByName.Insert( name, eg );
		}
		else
		{
			EventGroup & eg = validSpeakEventsGroupedByName[ idx ];
			eg.timeSortedEvents.Insert( e );
		}
	}

	c = validSpeakEventsGroupedByName.Count();
	// Now walk list of events by group
	if ( !c )
	{
		return;
	}

	for ( i = 0; i < c; ++i )
	{
		EventGroup & eg = validSpeakEventsGroupedByName[ i ];
		int sortedEventInGroup = eg.timeSortedEvents.Count();
		// If there's only one, just mark it valid
		if ( sortedEventInGroup <= 1 )
		{
			CChoreoEvent *e = eg.timeSortedEvents[ 0 ];
			Assert( e );
			// Make sure it's the master
			e->SetCloseCaptionType( CChoreoEvent::CC_MASTER );
			// Since it's by itself, can't be using "combined" file
			e->SetUsingCombinedFile( false );
			e->SetRequiredCombinedChecksum( 0 );
			e->SetNumSlaves( 0 );
			e->SetLastSlaveEndTime( 0.0f );
			continue;
		}

		// Okay, read them back in of start time
		int j = eg.timeSortedEvents.FirstInorder();
		CChoreoEvent *master = NULL;
		while ( j != eg.timeSortedEvents.InvalidIndex() )
		{
			CChoreoEvent *e = eg.timeSortedEvents[ j ];
			if ( !master )
			{
				master = e;
				e->SetCloseCaptionType( CChoreoEvent::CC_MASTER );
				//e->SetUsingCombinedFile( true );
				e->SetRequiredCombinedChecksum( 0 );
				e->SetNumSlaves( sortedEventInGroup - 1 );
				e->SetLastSlaveEndTime( e->GetEndTime() );
			}
			else
			{
				// Keep bumping out the end time
				master->SetLastSlaveEndTime( e->GetEndTime() );
				e->SetCloseCaptionType( CChoreoEvent::CC_SLAVE );
				e->SetUsingCombinedFile( master->IsUsingCombinedFile() );
				e->SetRequiredCombinedChecksum( 0 );
				e->SetLastSlaveEndTime( 0.0f );
			}

			j = eg.timeSortedEvents.NextInorder( j );
		}
	}
}