diff options
| author | Jørgen P. Tjernø <[email protected]> | 2013-12-02 19:31:46 -0800 |
|---|---|---|
| committer | Jørgen P. Tjernø <[email protected]> | 2013-12-02 19:46:31 -0800 |
| commit | f56bb35301836e56582a575a75864392a0177875 (patch) | |
| tree | de61ddd39de3e7df52759711950b4c288592f0dc /mp/src/utils/vbsp/materialsub.cpp | |
| parent | Mark some more files as text. (diff) | |
| download | source-sdk-2013-f56bb35301836e56582a575a75864392a0177875.tar.xz source-sdk-2013-f56bb35301836e56582a575a75864392a0177875.zip | |
Fix line endings. WHAMMY.
Diffstat (limited to 'mp/src/utils/vbsp/materialsub.cpp')
| -rw-r--r-- | mp/src/utils/vbsp/materialsub.cpp | 178 |
1 files changed, 89 insertions, 89 deletions
diff --git a/mp/src/utils/vbsp/materialsub.cpp b/mp/src/utils/vbsp/materialsub.cpp index d8eb40df..b02063ef 100644 --- a/mp/src/utils/vbsp/materialsub.cpp +++ b/mp/src/utils/vbsp/materialsub.cpp @@ -1,90 +1,90 @@ -//========= Copyright Valve Corporation, All rights reserved. ============//
-//
-// Purpose: This file loads a KeyValues file containing material name mappings.
-// When the bsp is compiled, all materials listed in the file will
-// be replaced by the second material in the pair.
-//
-//=============================================================================
-
-#include "vbsp.h"
-#include "materialsub.h"
-#include "KeyValues.h"
-#include "tier1/strtools.h"
-
-bool g_ReplaceMaterials = false;
-
-static KeyValues *kv = 0;
-static KeyValues *allMapKeys = 0;
-static KeyValues *curMapKeys = 0;
-
-//-----------------------------------------------------------------------------
-// Purpose: Loads the KeyValues file for materials replacements
-//-----------------------------------------------------------------------------
-void LoadMaterialReplacementKeys( const char *gamedir, const char *mapname )
-{
- // Careful with static variables
- if( kv )
- {
- kv->deleteThis();
- kv = 0;
- }
- if( allMapKeys )
- allMapKeys = 0;
- if( curMapKeys )
- curMapKeys = 0;
-
- Msg( "Loading Replacement Keys\n" );
-
- // Attach the path to the keyValues file
- char path[1024];
- Q_snprintf( path, sizeof( path ), "%scfg\\materialsub.cfg", gamedir );
-
- // Load the keyvalues file
- kv = new KeyValues( "MaterialReplacements" );
-
- Msg( "File path: %s", path );
- if( !kv->LoadFromFile( g_pFileSystem, path ) )
- {
- Msg( "Failed to load KeyValues file!\n" );
- g_ReplaceMaterials = false;
- kv->deleteThis();
- kv = 0;
- return;
- }
-
- // Load global replace keys
- allMapKeys = kv->FindKey( "AllMaps", true );
-
- // Load keys for the current map
- curMapKeys = kv->FindKey( mapname );
-
- allMapKeys->ChainKeyValue( curMapKeys );
-}
-
-//-----------------------------------------------------------------------------
-// Purpose: Deletes all keys
-//-----------------------------------------------------------------------------
-void DeleteMaterialReplacementKeys( void )
-{
- if( kv )
- {
- kv->deleteThis();
- kv = 0;
- }
-}
-
-//-----------------------------------------------------------------------------
-// Purpose: Replace the passed-in material name with a replacement name, if one exists
-//-----------------------------------------------------------------------------
-const char* ReplaceMaterialName( const char *name )
-{
- // Look for the material name in the global and map KeyValues
- // If it's not there, just return the original name
-
- // HACK: This stinks - KeyValues won't take a string with '/' in it.
- // If they did, this could be a simple pointer swap.
- char newName[1024];
- Q_strncpy( newName, name, sizeof( newName ) );
- Q_FixSlashes( newName );
- return allMapKeys->GetString( newName, name );
+//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: This file loads a KeyValues file containing material name mappings. +// When the bsp is compiled, all materials listed in the file will +// be replaced by the second material in the pair. +// +//============================================================================= + +#include "vbsp.h" +#include "materialsub.h" +#include "KeyValues.h" +#include "tier1/strtools.h" + +bool g_ReplaceMaterials = false; + +static KeyValues *kv = 0; +static KeyValues *allMapKeys = 0; +static KeyValues *curMapKeys = 0; + +//----------------------------------------------------------------------------- +// Purpose: Loads the KeyValues file for materials replacements +//----------------------------------------------------------------------------- +void LoadMaterialReplacementKeys( const char *gamedir, const char *mapname ) +{ + // Careful with static variables + if( kv ) + { + kv->deleteThis(); + kv = 0; + } + if( allMapKeys ) + allMapKeys = 0; + if( curMapKeys ) + curMapKeys = 0; + + Msg( "Loading Replacement Keys\n" ); + + // Attach the path to the keyValues file + char path[1024]; + Q_snprintf( path, sizeof( path ), "%scfg\\materialsub.cfg", gamedir ); + + // Load the keyvalues file + kv = new KeyValues( "MaterialReplacements" ); + + Msg( "File path: %s", path ); + if( !kv->LoadFromFile( g_pFileSystem, path ) ) + { + Msg( "Failed to load KeyValues file!\n" ); + g_ReplaceMaterials = false; + kv->deleteThis(); + kv = 0; + return; + } + + // Load global replace keys + allMapKeys = kv->FindKey( "AllMaps", true ); + + // Load keys for the current map + curMapKeys = kv->FindKey( mapname ); + + allMapKeys->ChainKeyValue( curMapKeys ); +} + +//----------------------------------------------------------------------------- +// Purpose: Deletes all keys +//----------------------------------------------------------------------------- +void DeleteMaterialReplacementKeys( void ) +{ + if( kv ) + { + kv->deleteThis(); + kv = 0; + } +} + +//----------------------------------------------------------------------------- +// Purpose: Replace the passed-in material name with a replacement name, if one exists +//----------------------------------------------------------------------------- +const char* ReplaceMaterialName( const char *name ) +{ + // Look for the material name in the global and map KeyValues + // If it's not there, just return the original name + + // HACK: This stinks - KeyValues won't take a string with '/' in it. + // If they did, this could be a simple pointer swap. + char newName[1024]; + Q_strncpy( newName, name, sizeof( newName ) ); + Q_FixSlashes( newName ); + return allMapKeys->GetString( newName, name ); }
\ No newline at end of file |