bool AddModelNameFromSource( CUtlDict< ModelFile, int >& models, char const *filename, char const *modelname, int offset )
{
	int idx = models.Find( modelname );
	if ( idx != models.InvalidIndex() )
	{
		char shortname[ MAX_PATH ];
		char shortname2[ MAX_PATH ];
		strcpy( shortname, &filename[ offset ] );
		strcpy( shortname2, &models[ idx ].qcfile[ offset ] );

		vprint( 0, "multiple .qc's build %s\n  %s\n  %s\n",
			modelname,
			shortname, 
			shortname2 );
		return false;
	}

	ModelFile mf;
	strcpy( mf.qcfile, filename );
	_strlwr( mf.qcfile );
	mf.version = 0;

	models.Insert( modelname, mf );
	return true;
}
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;
        }
    }
}
char* AllocateUniqueDataTableName( bool bSendTable, const char *pFormat, ... )
{
	// Setup the string.
	va_list marker;
	va_start( marker, pFormat );
	char *pRet = AllocateStringHelper2( pFormat, marker );
	va_end( marker );

	// Make sure it's unique.
#ifdef _DEBUG
	// Have to allocate them here because if they're declared as straight global variables,
	// their constructors won't have been called yet by the time we get in here.
	if ( !g_STDict )
	{
		g_STDict = new CUtlDict<int,int>;
		g_RTDict = new CUtlDict<int,int>;
	}

	CUtlDict<int,int> *pDict = bSendTable ? g_STDict : g_RTDict;
	if ( pDict->Find( pRet ) != pDict->InvalidIndex() )
	{
		// If it hits this, then they have 2 utlvectors in different data tables with the same name and the
		// same size limit. The names of 
		Assert( false );
	}
	pDict->Insert( pRet, 0 );
#endif

	return pRet;
}
//-----------------------------------------------------------------------------
// 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, 
							   const char *pClientModuleName )
{
	m_pClientClass = NULL;
	m_pNetworkName = strdup( pNetworkName );
	m_pyClass = cls_type;
	
	unsigned short lookup = m_NetworkClassDatabase.Find( m_pNetworkName );
	if ( lookup != m_NetworkClassDatabase.InvalidIndex() )
	{
		Warning("NetworkedClass: %s already added, replacing contents...\n", pNetworkName);
		m_pClientClass = m_NetworkClassDatabase[lookup]->m_pClientClass;
		m_NetworkClassDatabase[lookup] = this;
		if( m_pClientClass )
		{
			AttachClientClass( m_pClientClass );
		}
	}
	else
	{
		// New entry, add to database and find if there is an existing ClientClass
		m_NetworkClassDatabase.Insert( m_pNetworkName, this );

		m_pClientClass = FindPyClientClassToNetworkClass( m_pNetworkName );
	}
}
Beispiel #5
0
//-----------------------------------------------------------------------------
// Parse a single metaclass
//-----------------------------------------------------------------------------
bool CPanelMetaClassMgrImp::ParseSingleMetaClass( const char* pFileName,
	const char* pMetaClassName, KeyValues* pMetaClassValues, int keyValueIndex )
{
	// Complain about duplicately defined metaclass names...
	if ( m_MetaClassDict.Find( pMetaClassName ) != m_MetaClassDict.InvalidIndex() )
	{
		Warning( "Meta class %s duplicately defined (file %s)\n", pMetaClassName, pFileName );
		return false;
	}

	// find the type...
	const char* pPanelType = pMetaClassValues->GetString( "type" );
	if (!pPanelType || !pPanelType[0])
	{
		Warning( "Unable to find type of meta class %s in file %s\n", pMetaClassName, pFileName );
		return false;
	}

	unsigned short i = m_PanelTypeDict.Find( pPanelType );
	if (i == m_PanelTypeDict.InvalidIndex())
	{
		Warning( "Type %s of meta class %s undefined!\n", pPanelType, pMetaClassName );
		stackfree(pLwrMetaClass);
		return false;
	}

	// Add it to the metaclass dictionary
	MetaClassDict_t element;
	element.m_TypeIndex = i;
	element.m_KeyValueIndex = keyValueIndex;
	element.m_pKeyValues = pMetaClassValues;
	m_MetaClassDict.Insert( pMetaClassName, element );

	return true;
}
void RegisterScriptedEntity( const char *className )
{
#ifdef CLIENT_DLL
	if ( GetClassMap().FindFactory( className ) )
	{
		return;
	}

	GetClassMap().Add( className, "CBaseScripted", sizeof( CBaseScripted ),
		&CCBaseScriptedFactory, true );
#else
	if ( EntityFactoryDictionary()->FindFactory( className ) )
	{
		return;
	}

	unsigned short lookup = m_EntityFactoryDatabase.Find( className );
	if ( lookup != m_EntityFactoryDatabase.InvalidIndex() )
	{
		return;
	}

	CEntityFactory<CBaseScripted> *pFactory = new CEntityFactory<CBaseScripted>( className );

	lookup = m_EntityFactoryDatabase.Insert( className, pFactory );
	Assert( lookup != m_EntityFactoryDatabase.InvalidIndex() );
#endif
}
void RegisterScriptedWeapon( const char *className )
{
#ifdef CLIENT_DLL
	if ( GetClassMap().FindFactory( className ) )
	{
		return;
	}

	GetClassMap().Add( className, "CHL2MPScriptedWeapon", sizeof( CHL2MPScriptedWeapon ),
		&CCHL2MPScriptedWeaponFactory, true );
#else
	if ( EntityFactoryDictionary()->FindFactory( className ) )
	{
		return;
	}

	unsigned short lookup = m_WeaponFactoryDatabase.Find( className );
	if ( lookup != m_WeaponFactoryDatabase.InvalidIndex() )
	{
		return;
	}

	// Andrew; This fixes months worth of pain and anguish.
	CEntityFactory<CHL2MPScriptedWeapon> *pFactory = new CEntityFactory<CHL2MPScriptedWeapon>( className );

	lookup = m_WeaponFactoryDatabase.Insert( className, pFactory );
	Assert( lookup != m_WeaponFactoryDatabase.InvalidIndex() );
#endif
	// BUGBUG: When attempting to precache weapons registered during runtime,
	// they don't appear as valid registered entities.
	// static CPrecacheRegister precache_weapon_(&CPrecacheRegister::PrecacheFn_Other, className);
}
Beispiel #8
0
void InitMacroTexture( const char *pBSPFilename )
{
	// Get the world bounds (same ones used by minimaps and level designers know how to use).
	int i = 0;
	for (i = 0; i < num_entities; ++i)
	{
		char* pEntity = ValueForKey(&entities[i], "classname");
		if( !strcmp(pEntity, "worldspawn") )
		{
			GetVectorForKey( &entities[i], "world_mins", g_MacroWorldMins );
			GetVectorForKey( &entities[i], "world_maxs", g_MacroWorldMaxs );
			break;
		}
	}

	if ( i == num_entities )
	{
		Warning( "MaskOnMacroTexture: can't find worldspawn" );
		return;
	}


	// Load the macro texture that is mapped onto everything.
	char mapName[512], vtfFilename[512];
	Q_FileBase( pBSPFilename, mapName, sizeof( mapName ) );
	Q_snprintf( vtfFilename, sizeof( vtfFilename ), "materials/macro/%s/base.vtf", mapName );
	g_pGlobalMacroTextureData = LoadMacroTextureFile( vtfFilename );

	
	// Now load the macro texture for each face.
	g_FaceMacroTextures.SetSize( numfaces );
	for ( int iFace=0; iFace < numfaces; iFace++ )
	{
		g_FaceMacroTextures[iFace] = NULL;

		if ( iFace < g_FaceMacroTextureInfos.Count() )
		{
			unsigned short stringID = g_FaceMacroTextureInfos[iFace].m_MacroTextureNameID;
			if ( stringID != 0xFFFF )
			{
				const char *pMacroTextureName = &g_TexDataStringData[ g_TexDataStringTable[stringID] ];
				Q_snprintf( vtfFilename, sizeof( vtfFilename ), "%smaterials/%s.vtf", gamedir, pMacroTextureName );
				
				g_FaceMacroTextures[iFace] = FindMacroTexture( vtfFilename );
				if ( !g_FaceMacroTextures[iFace] )
				{
					g_FaceMacroTextures[iFace] = LoadMacroTextureFile( vtfFilename );
					if ( g_FaceMacroTextures[iFace] )
					{
						g_MacroTextureLookup.Insert( vtfFilename, g_FaceMacroTextures[iFace] );
					}
				}
			}
		}
	}
}
void CClassMap::Add( const char *mapname, const char *classname, int size, DISPATCHFUNCTION factory = 0 )
#endif
{
#if defined ( LUA_SDK )
	for ( int i=m_ClassDict.First(); i != m_ClassDict.InvalidIndex(); i=m_ClassDict.Next( i ) )
	{
		classentry_t *lookup = &m_ClassDict[ i ];
		if ( !lookup )
			continue;

		if ( !Q_stricmp( lookup->GetMapName(), mapname ) )
		{
			m_ClassDict.RemoveAt( i );
		}
	}
#else
	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 );
	}
#endif

	classentry_t element;
	element.SetMapName( mapname );
	element.factory = factory;
	element.size = size;
#if defined ( LUA_SDK )
	element.SetClassName( classname );
	element.scripted = scripted;
	m_ClassDict.Insert( mapname, element );
#else
	m_ClassDict.Insert( classname, element );
#endif
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
PanelAnimationMap *CPanelAnimationDictionary::FindOrAddPanelAnimationMap( char const *className )
{
	PanelAnimationMap *map = FindPanelAnimationMap( className );
	if ( map )
		return map;

	Panel::InitPropertyConverters();

	PanelAnimationMapDictionaryEntry entry;
	entry.map = (PanelAnimationMap *)m_PanelAnimationMapPool.Alloc();
	m_AnimationMaps.Insert( StripNamespace( className ), entry );
	return entry.map;
}
Beispiel #11
0
//-----------------------------------------------------------------------------
// Call this to install a new panel type
//-----------------------------------------------------------------------------
void CPanelMetaClassMgrImp::InstallPanelType( const char* pPanelName, IPanelFactory* pFactory )
{
	Assert( pPanelName && pFactory );
	
	// convert to lowercase
	int len = Q_strlen(pPanelName) + 1;
	char* pTemp = (char*)stackalloc( len );
	Q_strncpy( pTemp, pPanelName, len );
	Q_strnlwr( pTemp, len );

	m_PanelTypeDict.Insert( pTemp, pFactory );

	stackfree( pTemp );
}
Beispiel #12
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *name - 
// Output : FileItemInfo_t
//-----------------------------------------------------------------------------
static ITEM_FILE_INFO_HANDLE FindItemInfo( const char *name )
{
	// Complain about duplicately defined metaclass names...
	unsigned short lookup = m_ItemInfoDatabase.Find( name );
	if ( lookup != m_ItemInfoDatabase.InvalidIndex() )
	{
		return lookup;
	}

	FileItemInfo_t *insert = new FileItemInfo_t; // BOXBOX was CreateWeaponInfo();

	lookup = m_ItemInfoDatabase.Insert( name, insert );
	Assert( lookup != m_ItemInfoDatabase.InvalidIndex() );
	return lookup;
}
ITextureInternal *CTextureManager::FindOrLoadTexture( const char *pTextureName, const char *pTextureGroupName )
{
	ITextureInternal *pTexture = FindTexture( pTextureName );
	if ( !pTexture )
	{
		pTexture = LoadTexture( pTextureName, pTextureGroupName );
		if ( pTexture )
		{
			// insert into the dictionary using the processed texture name
			m_TextureList.Insert( pTexture->GetName(), pTexture );
		}
	}

	return pTexture;
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *name - 
// Output : FilePlayerClassInfo_t
//-----------------------------------------------------------------------------
static PLAYERCLASS_FILE_INFO_HANDLE FindPlayerClassInfoSlot( const char *name )
{
	// Complain about duplicately defined metaclass names...
	unsigned short lookup = m_PlayerClassInfoDatabase.Find( name );
	if ( lookup != m_PlayerClassInfoDatabase.InvalidIndex() )
	{
		return lookup;
	}

	FilePlayerClassInfo_t *insert = CreatePlayerClassInfo();

	lookup = m_PlayerClassInfoDatabase.Insert( name, insert );
	Assert( lookup != m_PlayerClassInfoDatabase.InvalidIndex() );
	return lookup;
}
Beispiel #15
0
//-----------------------------------------------------------------------------
// Loads up a file containing metaclass definitions
//-----------------------------------------------------------------------------
void CPanelMetaClassMgrImp::LoadMetaClassDefinitionFile( const char *pFileName )
{
	MEM_ALLOC_CREDIT();

	// Blat out previous metaclass definitions read in from this file...
	int i = m_MetaClassKeyValues.Find( pFileName );
	if (i != m_MetaClassKeyValues.InvalidIndex() )
	{
		// Blow away the previous keyvalues	from that file
		unsigned short j = m_MetaClassDict.First();
		while ( j != m_MetaClassDict.InvalidIndex() )
		{
			unsigned short next = m_MetaClassDict.Next(j);
			if ( m_MetaClassDict[j].m_KeyValueIndex == i)
			{
				m_MetaClassDict.RemoveAt(j);
			}

			j = next;
		}

		m_MetaClassKeyValues[i]->deleteThis();
		m_MetaClassKeyValues.RemoveAt(i); 
	}

	// Create a new keyvalues entry
	KeyValues* pKeyValues = new KeyValues(pFileName);
	int idx = m_MetaClassKeyValues.Insert( pFileName, pKeyValues );

	// Read in all metaclass definitions...

	// Load the file
	if ( !pKeyValues->LoadFromFile( filesystem, pFileName ) )
	{
		Warning( "Couldn't find metaclass definition file %s\n", pFileName );
		pKeyValues->deleteThis();
		m_MetaClassKeyValues.RemoveAt(idx);
		return;
	}
	else
	{
		// Go ahead and parse the data now
		if ( !ParseMetaClassList( pFileName, pKeyValues, idx ) )
		{
			Warning( "Detected one or more errors parsing %s\n", pFileName );
		}
	}
}
Beispiel #16
0
KeyValues* CacheKeyValuesForFile( const char *pFilename )
{
	MEM_ALLOC_CREDIT();
	int i = g_KeyValuesCache.Find( pFilename );
	if ( i == g_KeyValuesCache.InvalidIndex() )
	{
		KeyValues *rDat = new KeyValues( pFilename );
		rDat->LoadFromFile( filesystem, pFilename, NULL );
		g_KeyValuesCache.Insert( pFilename, rDat );
		return rDat;		
	}
	else
	{
		return g_KeyValuesCache[i];
	}
}
Beispiel #17
0
//-----------------------------------------------------------------------------
// Purpose: Parses the weapon txt files to get the sprites needed.
//-----------------------------------------------------------------------------
void LoadHudTextures( CUtlDict< CHudTexture *, int >& list, char *szFilenameWithoutExtension, const unsigned char *pICEKey )
{
	KeyValues *pTemp, *pTextureSection;

	KeyValues *pKeyValuesData = ReadEncryptedKVFile( filesystem, szFilenameWithoutExtension, pICEKey );
	if ( pKeyValuesData )
	{
		pTextureSection = pKeyValuesData->FindKey( "TextureData" );
		if ( pTextureSection  )
		{
			// Read the sprite data
			pTemp = pTextureSection->GetFirstSubKey();
			while ( pTemp )
			{
				CHudTexture *tex = new CHudTexture();
				// Key Name is the sprite name
				Q_strncpy( tex->szShortName, pTemp->GetName(), sizeof( tex->szShortName ) );

				if ( pTemp->GetString( "font", NULL ) )
				{
					// it's a font-based icon
					tex->bRenderUsingFont = true;
					tex->cCharacterInFont = *(pTemp->GetString("character", ""));
					Q_strncpy( tex->szTextureFile, pTemp->GetString( "font" ), sizeof( tex->szTextureFile ) );
				}
				else
				{
					tex->bRenderUsingFont = false;
					Q_strncpy( tex->szTextureFile, pTemp->GetString( "file" ), sizeof( tex->szTextureFile ) );
					tex->rc.left	= pTemp->GetInt( "x", 0 );
					tex->rc.top		= pTemp->GetInt( "y", 0 );
					tex->rc.right	= pTemp->GetInt( "width", 0 )	+ tex->rc.left;
					tex->rc.bottom	= pTemp->GetInt( "height", 0 )	+ tex->rc.top;
				}

				list.Insert( tex->szShortName, tex );

				pTemp = pTemp->GetNextKey();
			}
		}
	}

	// Failed for some reason. Delete the Key data and abort.
	pKeyValuesData->deleteThis();
}
void RegisterScriptedTrigger( const char *className )
{
	if ( EntityFactoryDictionary()->FindFactory( className ) )
	{
		return;
	}

	unsigned short lookup = m_TriggerFactoryDatabase.Find( className );
	if ( lookup != m_TriggerFactoryDatabase.InvalidIndex() )
	{
		return;
	}

	CEntityFactory<CBaseScriptedTrigger> *pFactory = new CEntityFactory<CBaseScriptedTrigger>( className );

	lookup = m_TriggerFactoryDatabase.Insert( className, pFactory );
	Assert( lookup != m_TriggerFactoryDatabase.InvalidIndex() );
}
//-----------------------------------------------------------------------------
// 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;
}
Beispiel #20
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;
}
Beispiel #21
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 );
}
	virtual void Restore( const SaveRestoreFieldInfo_t &fieldInfo, IRestore *pRestore )
	{
		CUtlDict< ConceptHistory_t, int > *ch = ((CUtlDict< ConceptHistory_t, int > *)fieldInfo.pField);

		int count = pRestore->ReadInt();
		Assert( count >= 0 );
		for ( int i = 0 ; i < count; i++ )
		{
			char conceptname[ 512 ];
			conceptname[ 0 ] = 0;
			ConceptHistory_t history;

			pRestore->StartBlock();
			{
				pRestore->ReadString( conceptname, sizeof( conceptname ), 0 );

				pRestore->ReadAll( &history );

				bool hasresponse = false;

				pRestore->ReadBool( &hasresponse );
				if ( hasresponse )
				{
					history.response = new AI_Response();
					pRestore->ReadAll( history.response );
				}
			}

			pRestore->EndBlock();

			// TODO: Could restore pHistory->criteria pointer here, if it's needed

			// Add to utldict
			if ( conceptname[0] != 0 )
			{
				ch->Insert( conceptname, history );
			}
			else
			{
				Assert( !"Error restoring ConceptHistory_t, discarding!" );
			}
		}
	}
ITextureInternal *CTextureManager::FindTexture( const char *pTextureName )
{
	if ( !pTextureName || pTextureName[0] == 0 )
		return NULL;
	
	char szCleanName[MAX_PATH];
	NormalizeTextureName( pTextureName, szCleanName, sizeof( szCleanName ) );

	int i = m_TextureList.Find( szCleanName );
	if ( i != m_TextureList.InvalidIndex() )
	{
		return m_TextureList[i];
	}

	i = m_TextureAliases.Find( szCleanName );
	if ( i != m_TextureAliases.InvalidIndex() )
	{
		return FindTexture( m_TextureAliases[i] );
	}

	// Special handling: lightmaps
	if ( char const *szLightMapNum = StringAfterPrefix( szCleanName, "[lightmap" ) )
	{
		int iLightMapNum = atoi( szLightMapNum );
		extern CMaterialSystem g_MaterialSystem;
		CMatLightmaps *plm = g_MaterialSystem.GetLightmaps();
		if ( iLightMapNum >= 0 &&
			 iLightMapNum < plm->GetNumLightmapPages() )
		{
			ShaderAPITextureHandle_t hTex = plm->GetLightmapPageTextureHandle( iLightMapNum );
			if ( hTex != INVALID_SHADERAPI_TEXTURE_HANDLE )
			{
				// Establish the lookup linking in the dictionary
				ITextureInternal *pTxInt = ITextureInternal::CreateReferenceTextureFromHandle( pTextureName, TEXTURE_GROUP_LIGHTMAP, hTex );
				m_TextureList.Insert( pTextureName, pTxInt );
				return pTxInt;
			}
		}
	}

	return NULL;
}
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 );
}
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 );
}
Beispiel #26
0
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;
}
//-----------------------------------------------------------------------------
// Creates a procedural texture
//-----------------------------------------------------------------------------
ITextureInternal *CTextureManager::CreateProceduralTexture( 
	const char			*pTextureName, 
	const char			*pTextureGroupName, 
	int					w, 
	int					h, 
	int					d, 
	ImageFormat			fmt, 
	int					nFlags )
{
	ITextureInternal *pNewTexture = ITextureInternal::CreateProceduralTexture( pTextureName, pTextureGroupName, w, h, d, fmt, nFlags );
	if ( !pNewTexture )
		return NULL;

	// Add it to the list of textures so it can be restored, etc.
	m_TextureList.Insert( pNewTexture->GetName(), pNewTexture );

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

	return pNewTexture;
}
//-----------------------------------------------------------------------------
// 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();
}
Beispiel #29
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 );
}
int CBasePlayerAnimState::CalcSequenceIndex( const char *pBaseName, ... )
{
	char szFullName[512];
	va_list marker;
	va_start( marker, pBaseName );
	Q_vsnprintf( szFullName, sizeof( szFullName ), pBaseName, marker );
	va_end( marker );
	int iSequence = GetOuter()->LookupSequence( szFullName );
	
	// 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;
}