diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /dmserializers/importsfmv4.cpp | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'dmserializers/importsfmv4.cpp')
| -rw-r--r-- | dmserializers/importsfmv4.cpp | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/dmserializers/importsfmv4.cpp b/dmserializers/importsfmv4.cpp new file mode 100644 index 0000000..278fe12 --- /dev/null +++ b/dmserializers/importsfmv4.cpp @@ -0,0 +1,123 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#include "dmserializers.h" +#include "dmebaseimporter.h" +#include "datamodel/idatamodel.h" +#include "datamodel/dmelement.h" +#include "tier1/KeyValues.h" +#include "tier1/utlbuffer.h" +#include "tier1/utlmap.h" +#include <limits.h> + + +//----------------------------------------------------------------------------- +// Format converter +//----------------------------------------------------------------------------- +class CImportSFMV4 : public CSFMBaseImporter +{ + typedef CSFMBaseImporter BaseClass; +public: + CImportSFMV4( char const *formatName, char const *nextFormatName ); + +private: + virtual bool DoFixup( CDmElement *pSourceRoot ); + + + void FixupElement( CDmElement *pElement ); + // Fixes up all elements + void BuildList( CDmElement *pElement, CUtlRBTree< CDmElement *, int >& list ); +}; + + +//----------------------------------------------------------------------------- +// Singleton instance +//----------------------------------------------------------------------------- +static CImportSFMV4 s_ImportSFMV4( "sfm_v4", "sfm_v5" ); + +void InstallSFMV4Importer( IDataModel *pFactory ) +{ + pFactory->AddLegacyUpdater( &s_ImportSFMV4 ); +} + + +//----------------------------------------------------------------------------- +// Constructor +//----------------------------------------------------------------------------- +CImportSFMV4::CImportSFMV4( char const *formatName, char const *nextFormatName ) : + BaseClass( formatName, nextFormatName ) +{ +} + +// Fixes up all elements +//----------------------------------------------------------------------------- +void CImportSFMV4::FixupElement( CDmElement *pElement ) +{ + if ( !pElement ) + return; + + const char *pType = pElement->GetTypeString(); + + if ( !V_stricmp( pType, "DmeCamera" ) ) + { + CDmAttribute *pOldToneMapScaleAttr = pElement->GetAttribute( "toneMapScale" ); + float fNewBloomScale = pOldToneMapScaleAttr->GetValue<float>( ); + + Assert( !pElement->HasAttribute("bloomScale") ); + + CDmAttribute *pNewBloomScaleAttr = pElement->AddAttribute( "bloomScale", AT_FLOAT ); + pNewBloomScaleAttr->SetValue( fNewBloomScale ); + pOldToneMapScaleAttr->SetValue( 1.0f ); + } +} + +// Fixes up all elements +//----------------------------------------------------------------------------- +void CImportSFMV4::BuildList( CDmElement *pElement, CUtlRBTree< CDmElement *, int >& list ) +{ + if ( !pElement ) + return; + + if ( list.Find( pElement ) != list.InvalidIndex() ) + return; + + list.Insert( pElement ); + + // Descend to bottom of tree, then do fixup coming back up the tree + for ( CDmAttribute *pAttribute = pElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->NextAttribute() ) + { + if ( pAttribute->GetType() == AT_ELEMENT ) + { + CDmElement *pElementAt = pAttribute->GetValueElement<CDmElement>( ); + BuildList( pElementAt, list ); + continue; + } + + if ( pAttribute->GetType() == AT_ELEMENT_ARRAY ) + { + CDmrElementArray<> array( pAttribute ); + int nCount = array.Count(); + for ( int i = 0; i < nCount; ++i ) + { + CDmElement *pChild = array[ i ]; + BuildList( pChild, list ); + } + continue; + } + } +} + +bool CImportSFMV4::DoFixup( CDmElement *pSourceRoot ) +{ + CUtlRBTree< CDmElement *, int > fixlist( 0, 0, DefLessFunc( CDmElement * ) ); + BuildList( pSourceRoot, fixlist ); + for ( int i = fixlist.FirstInorder(); i != fixlist.InvalidIndex() ; i = fixlist.NextInorder( i ) ) + { + // Search and replace in the entire tree! + FixupElement( fixlist[ i ] ); + } + return true; +} |