void Draw_DecalSetName( int decal, char *name ) { while ( decal >= g_DecalLookup.Count() ) { MEM_ALLOC_CREDIT(); int idx = g_DecalLookup.AddToTail(); g_DecalLookup[idx] = g_DecalDictionary.InvalidIndex(); } FileNameHandle_t fnHandle = g_pFileSystem->FindOrAddFileName( name ); int lookup = g_DecalDictionary.Find( fnHandle ); if ( lookup == g_DecalDictionary.InvalidIndex() ) { DecalEntry entry; #ifdef _DEBUG int len = strlen(name) + 1; entry.m_pDebugName = new char[len]; memcpy( entry.m_pDebugName, name, len ); #endif entry.material = GL_LoadMaterial( name, TEXTURE_GROUP_DECAL ); entry.index = decal; lookup = g_DecalDictionary.Insert( fnHandle, entry ); } else { g_DecalDictionary[lookup].index = decal; } g_DecalLookup[decal] = lookup; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void Decal_Shutdown( void ) { for ( int index = g_DecalDictionary.FirstInorder(); index != g_DecalDictionary.InvalidIndex(); index = g_DecalDictionary.NextInorder(index) ) { IMaterial *mat = g_DecalDictionary[index].material; if ( mat ) { GL_UnloadMaterial( mat ); } #ifdef _DEBUG delete[] g_DecalDictionary[index].m_pDebugName; #endif } g_DecalLookup.Purge(); g_DecalDictionary.RemoveAll(); }
// called from cl_parse.cpp // find the server side decal id given it's name. // used for save/restore int Draw_DecalIndexFromName( char *name, bool *found ) { Assert( found ); FileNameHandle_t fnHandle = g_pFileSystem->FindOrAddFileName( name ); int lookup = g_DecalDictionary.Find( fnHandle ); if ( lookup == g_DecalDictionary.InvalidIndex() ) { if ( found ) { *found = false; } return 0; } if ( found ) { *found = true; } return g_DecalDictionary[lookup].index; }
//----------------------------------------------------------------------------- // Purpose: this function will attempt to remap a key's value // Input : pszKey - the name of the key // pszInvalue - the original value // AllowNameRemapping - only do name remapping if this parameter is true. // this is generally only false on the instance level. // Output : returns true if the value changed // pszOutValue - the new value if changed //----------------------------------------------------------------------------- bool GameData::RemapKeyValue( const char *pszKey, const char *pszInValue, char *pszOutValue, TNameFixup NameFixup ) { if ( RemapOperation.Count() == 0 ) { RemapOperation.SetLessFunc( &CUtlType_LessThan ); RemapOperation.Insert( ivAngle, REMAP_ANGLE ); RemapOperation.Insert( ivTargetDest, REMAP_NAME ); RemapOperation.Insert( ivTargetSrc, REMAP_NAME ); RemapOperation.Insert( ivOrigin, REMAP_POSITION ); RemapOperation.Insert( ivAxis, REMAP_ANGLE ); RemapOperation.Insert( ivAngleNegativePitch, REMAP_ANGLE_NEGATIVE_PITCH ); } if ( !m_InstanceClass ) { return false; } GDinputvariable *KVVar = m_InstanceClass->VarForName( pszKey ); if ( !KVVar ) { return false; } GDIV_TYPE KVType = KVVar->GetType(); int KVRemapIndex = RemapOperation.Find( KVType ); if ( KVRemapIndex == RemapOperation.InvalidIndex() ) { return false; } strcpy( pszOutValue, pszInValue ); switch( RemapOperation[ KVRemapIndex ] ) { case REMAP_NAME: if ( KVType != ivInstanceVariable ) { RemapNameField( pszInValue, pszOutValue, NameFixup ); } break; case REMAP_POSITION: { Vector inPoint( 0.0f, 0.0f, 0.0f ), outPoint; sscanf ( pszInValue, "%f %f %f", &inPoint.x, &inPoint.y, &inPoint.z ); VectorTransform( inPoint, m_InstanceMat, outPoint ); sprintf( pszOutValue, "%g %g %g", outPoint.x, outPoint.y, outPoint.z ); } break; case REMAP_ANGLE: if ( m_InstanceAngle.x != 0.0f || m_InstanceAngle.y != 0.0f || m_InstanceAngle.z != 0.0f ) { QAngle inAngles( 0.0f, 0.0f, 0.0f ), outAngles; matrix3x4_t angToWorld, localMatrix; sscanf ( pszInValue, "%f %f %f", &inAngles.x, &inAngles.y, &inAngles.z ); AngleMatrix( inAngles, angToWorld ); MatrixMultiply( m_InstanceMat, angToWorld, localMatrix ); MatrixAngles( localMatrix, outAngles ); sprintf( pszOutValue, "%g %g %g", outAngles.x, outAngles.y, outAngles.z ); } break; case REMAP_ANGLE_NEGATIVE_PITCH: if ( m_InstanceAngle.x != 0.0f || m_InstanceAngle.y != 0.0f || m_InstanceAngle.z != 0.0f ) { QAngle inAngles( 0.0f, 0.0f, 0.0f ), outAngles; matrix3x4_t angToWorld, localMatrix; sscanf ( pszInValue, "%f", &inAngles.x ); // just the pitch inAngles.x = -inAngles.x; AngleMatrix( inAngles, angToWorld ); MatrixMultiply( m_InstanceMat, angToWorld, localMatrix ); MatrixAngles( localMatrix, outAngles ); sprintf( pszOutValue, "%g", -outAngles.x ); // just the pitch } break; } return ( strcmpi( pszInValue, pszOutValue ) != 0 ); }